summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis de Bethencourt <luisbg@osg.samsung.com>2016-02-17 13:26:02 +0000
committerLuis de Bethencourt <luisbg@osg.samsung.com>2016-02-17 14:18:16 +0000
commitf2f31ec50f08d24fc8859b382a0f895ff330248f (patch)
tree2463b2042d36f844739d01d26f766c63b70c2c6b
parent750b7c72fe8f19bdcbda9d02ffbb1816bdef507b (diff)
downloadgstreamer-plugins-good-f2f31ec50f08d24fc8859b382a0f895ff330248f.tar.gz
rtp: h264/h265: avoid duplication of read_golomb()
There is no need to have two identical implementations of the read_golomb function. https://bugzilla.gnome.org/show_bug.cgi?id=761606
-rw-r--r--gst/rtp/gstrtph264depay.c35
-rw-r--r--gst/rtp/gstrtph265depay.c51
-rw-r--r--gst/rtp/gstrtputils.c25
-rw-r--r--gst/rtp/gstrtputils.h2
4 files changed, 45 insertions, 68 deletions
diff --git a/gst/rtp/gstrtph264depay.c b/gst/rtp/gstrtph264depay.c
index 482fb62f2..234369672 100644
--- a/gst/rtp/gstrtph264depay.c
+++ b/gst/rtp/gstrtph264depay.c
@@ -229,31 +229,6 @@ gst_rtp_h264_depay_negotiate (GstRtpH264Depay * rtph264depay)
}
}
-/* Stolen from bad/gst/mpegtsdemux/payloader_parsers.c */
-/* variable length Exp-Golomb parsing according to H.264 spec 9.1*/
-static gboolean
-read_golomb (GstBitReader * br, guint32 * value)
-{
- guint8 b, leading_zeros = -1;
- *value = 1;
-
- for (b = 0; !b; leading_zeros++) {
- if (!gst_bit_reader_get_bits_uint8 (br, &b, 1))
- return FALSE;
- *value *= 2;
- }
-
- *value = (*value >> 1) - 1;
- if (leading_zeros > 0) {
- guint32 tmp = 0;
- if (!gst_bit_reader_get_bits_uint32 (br, &tmp, leading_zeros))
- return FALSE;
- *value += tmp;
- }
-
- return TRUE;
-}
-
static gboolean
parse_sps (GstMapInfo * map, guint32 * sps_id)
{
@@ -263,7 +238,7 @@ parse_sps (GstMapInfo * map, guint32 * sps_id)
if (map->size < 5)
return FALSE;
- if (!read_golomb (&br, sps_id))
+ if (!gst_rtp_read_golomb (&br, sps_id))
return FALSE;
return TRUE;
@@ -278,9 +253,9 @@ parse_pps (GstMapInfo * map, guint32 * sps_id, guint32 * pps_id)
if (map->size < 2)
return FALSE;
- if (!read_golomb (&br, pps_id))
+ if (!gst_rtp_read_golomb (&br, pps_id))
return FALSE;
- if (!read_golomb (&br, sps_id))
+ if (!gst_rtp_read_golomb (&br, sps_id))
return FALSE;
return TRUE;
@@ -1034,8 +1009,8 @@ gst_rtp_h264_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
/* STAP-A Single-time aggregation packet 5.7.1 */
while (payload_len > 2) {
- /* 1
- * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+ /* 1
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | NALU Size |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
diff --git a/gst/rtp/gstrtph265depay.c b/gst/rtp/gstrtph265depay.c
index 59685b8b4..2bee80bde 100644
--- a/gst/rtp/gstrtph265depay.c
+++ b/gst/rtp/gstrtph265depay.c
@@ -259,31 +259,6 @@ gst_rtp_h265_depay_negotiate (GstRtpH265Depay * rtph265depay)
}
}
-/* Stolen from bad/gst/mpegtsdemux/payloader_parsers.c */
-/* variable length Exp-Golomb parsing according to H.265 spec section 9.2*/
-static gboolean
-read_golomb (GstBitReader * br, guint32 * value)
-{
- guint8 b, leading_zeros = -1;
- *value = 1;
-
- for (b = 0; !b; leading_zeros++) {
- if (!gst_bit_reader_get_bits_uint8 (br, &b, 1))
- return FALSE;
- *value *= 2;
- }
-
- *value = (*value >> 1) - 1;
- if (leading_zeros > 0) {
- guint32 tmp = 0;
- if (!gst_bit_reader_get_bits_uint32 (br, &tmp, leading_zeros))
- return FALSE;
- *value += tmp;
- }
-
- return TRUE;
-}
-
static gboolean
parse_sps (GstMapInfo * map, guint32 * sps_id)
{ /* To parse seq_parameter_set_id */
@@ -293,7 +268,7 @@ parse_sps (GstMapInfo * map, guint32 * sps_id)
if (map->size < 16)
return FALSE;
- if (!read_golomb (&br, sps_id))
+ if (!gst_rtp_read_golomb (&br, sps_id))
return FALSE;
return TRUE;
@@ -308,9 +283,9 @@ parse_pps (GstMapInfo * map, guint32 * sps_id, guint32 * pps_id)
if (map->size < 3)
return FALSE;
- if (!read_golomb (&br, pps_id))
+ if (!gst_rtp_read_golomb (&br, pps_id))
return FALSE;
- if (!read_golomb (&br, sps_id))
+ if (!gst_rtp_read_golomb (&br, sps_id))
return FALSE;
return TRUE;
@@ -394,26 +369,26 @@ gst_rtp_h265_set_src_caps (GstRtpH265Depay * rtph265depay)
gst_bit_reader_init (&br, nalmap.data + 15, nalmap.size - 15);
- read_golomb (&br, &tmp); /* sps_seq_parameter_set_id */
- read_golomb (&br, &chroma_format_idc); /* chroma_format_idc */
+ gst_rtp_read_golomb (&br, &tmp); /* sps_seq_parameter_set_id */
+ gst_rtp_read_golomb (&br, &chroma_format_idc); /* chroma_format_idc */
if (chroma_format_idc == 3)
gst_bit_reader_get_bits_uint8 (&br, &tmp8, 1); /* separate_colour_plane_flag */
- read_golomb (&br, &tmp); /* pic_width_in_luma_samples */
- read_golomb (&br, &tmp); /* pic_height_in_luma_samples */
+ gst_rtp_read_golomb (&br, &tmp); /* pic_width_in_luma_samples */
+ gst_rtp_read_golomb (&br, &tmp); /* pic_height_in_luma_samples */
gst_bit_reader_get_bits_uint8 (&br, &tmp8, 1); /* conformance_window_flag */
if (tmp8) {
- read_golomb (&br, &tmp); /* conf_win_left_offset */
- read_golomb (&br, &tmp); /* conf_win_right_offset */
- read_golomb (&br, &tmp); /* conf_win_top_offset */
- read_golomb (&br, &tmp); /* conf_win_bottom_offset */
+ gst_rtp_read_golomb (&br, &tmp); /* conf_win_left_offset */
+ gst_rtp_read_golomb (&br, &tmp); /* conf_win_right_offset */
+ gst_rtp_read_golomb (&br, &tmp); /* conf_win_top_offset */
+ gst_rtp_read_golomb (&br, &tmp); /* conf_win_bottom_offset */
}
- read_golomb (&br, &bit_depth_luma_minus8); /* bit_depth_luma_minus8 */
- read_golomb (&br, &bit_depth_chroma_minus8); /* bit_depth_chroma_minus8 */
+ gst_rtp_read_golomb (&br, &bit_depth_luma_minus8); /* bit_depth_luma_minus8 */
+ gst_rtp_read_golomb (&br, &bit_depth_chroma_minus8); /* bit_depth_chroma_minus8 */
GST_DEBUG_OBJECT (rtph265depay,
"Ignoring min_spatial_segmentation for now (assuming zero)");
diff --git a/gst/rtp/gstrtputils.c b/gst/rtp/gstrtputils.c
index 2b95c2950..28735af11 100644
--- a/gst/rtp/gstrtputils.c
+++ b/gst/rtp/gstrtputils.c
@@ -95,3 +95,28 @@ gst_rtp_drop_meta (GstElement * element, GstBuffer * buf, GQuark keep_tag)
gst_buffer_foreach_meta (buf, foreach_metadata_drop, &data);
}
+
+/* Stolen from bad/gst/mpegtsdemux/payloader_parsers.c */
+/* variable length Exp-Golomb parsing according to H.265 spec section 9.2*/
+gboolean
+gst_rtp_read_golomb (GstBitReader * br, guint32 * value)
+{
+ guint8 b, leading_zeros = -1;
+ *value = 1;
+
+ for (b = 0; !b; leading_zeros++) {
+ if (!gst_bit_reader_get_bits_uint8 (br, &b, 1))
+ return FALSE;
+ *value *= 2;
+ }
+
+ *value = (*value >> 1) - 1;
+ if (leading_zeros > 0) {
+ guint32 tmp = 0;
+ if (!gst_bit_reader_get_bits_uint32 (br, &tmp, leading_zeros))
+ return FALSE;
+ *value += tmp;
+ }
+
+ return TRUE;
+}
diff --git a/gst/rtp/gstrtputils.h b/gst/rtp/gstrtputils.h
index d0b66fabc..8e142730e 100644
--- a/gst/rtp/gstrtputils.h
+++ b/gst/rtp/gstrtputils.h
@@ -21,12 +21,14 @@
#define __GST_RTP_UTILS_H__
#include <gst/gst.h>
+#include <gst/base/gstbitreader.h>
G_BEGIN_DECLS
void gst_rtp_copy_meta (GstElement * element, GstBuffer *outbuf, GstBuffer *inbuf, GQuark copy_tag);
void gst_rtp_drop_meta (GstElement * element, GstBuffer *buf, GQuark keep_tag);
+gboolean gst_rtp_read_golomb (GstBitReader * br, guint32 * value);
G_END_DECLS