mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 04:22:27 +00:00
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
This commit is contained in:
parent
750b7c72fe
commit
f2f31ec50f
4 changed files with 45 additions and 68 deletions
|
@ -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 |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
|
|
@ -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)");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue