Commit 5c9f7900 authored by Gwenole Beauchesne's avatar Gwenole Beauchesne Committed by Tim-Philipp Müller

codecparsers: h264: record number of emulation prevention bytes in slice_header().

Some hardware video decode acceleration API (VA-API, DXVA) require
a bit count to the first macroblock, minus the number of emulation
prevention bytes. So, instead of having the consumer of the library
scan the slice_header() again, just record that number while parsing.
Signed-off-by: default avatarGwenole Beauchesne <gwenole.beauchesne@intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=671203
parent 0bb5a016
...@@ -167,6 +167,7 @@ typedef struct ...@@ -167,6 +167,7 @@ typedef struct
const guint8 *data; const guint8 *data;
guint size; guint size;
guint n_epb; /* Number of emulation prevention bytes */
guint byte; /* Byte position */ guint byte; /* Byte position */
guint bits_in_cache; /* bitpos in the cache of next bit */ guint bits_in_cache; /* bitpos in the cache of next bit */
guint8 first_byte; guint8 first_byte;
...@@ -178,6 +179,7 @@ nal_reader_init (NalReader * nr, const guint8 * data, guint size) ...@@ -178,6 +179,7 @@ nal_reader_init (NalReader * nr, const guint8 * data, guint size)
{ {
nr->data = data; nr->data = data;
nr->size = size; nr->size = size;
nr->n_epb = 0;
nr->byte = 0; nr->byte = 0;
nr->bits_in_cache = 0; nr->bits_in_cache = 0;
...@@ -211,6 +213,7 @@ nal_reader_read (NalReader * nr, guint nbits) ...@@ -211,6 +213,7 @@ nal_reader_read (NalReader * nr, guint nbits)
((nr->cache & 0xff) == 0)) { ((nr->cache & 0xff) == 0)) {
/* next byte goes unconditionally to the cache, even if it's 0x03 */ /* next byte goes unconditionally to the cache, even if it's 0x03 */
check_three_byte = FALSE; check_three_byte = FALSE;
nr->n_epb++;
goto next_byte; goto next_byte;
} }
nr->cache = (nr->cache << 8) | nr->first_byte; nr->cache = (nr->cache << 8) | nr->first_byte;
...@@ -263,6 +266,12 @@ nal_reader_get_remaining (const NalReader * nr) ...@@ -263,6 +266,12 @@ nal_reader_get_remaining (const NalReader * nr)
return (nr->size - nr->byte) * 8 + nr->bits_in_cache; return (nr->size - nr->byte) * 8 + nr->bits_in_cache;
} }
static inline guint
nal_reader_get_epb_count (const NalReader * nr)
{
return nr->n_epb;
}
#define GST_NAL_READER_READ_BITS(bits) \ #define GST_NAL_READER_READ_BITS(bits) \
static gboolean \ static gboolean \
nal_reader_get_bits_uint##bits (NalReader *nr, guint##bits *val, guint nbits) \ nal_reader_get_bits_uint##bits (NalReader *nr, guint##bits *val, guint nbits) \
...@@ -1882,6 +1891,7 @@ gst_h264_parser_parse_slice_hdr (GstH264NalParser * nalparser, ...@@ -1882,6 +1891,7 @@ gst_h264_parser_parse_slice_hdr (GstH264NalParser * nalparser,
} }
slice->header_size = nal_reader_get_pos (&nr); slice->header_size = nal_reader_get_pos (&nr);
slice->n_emulation_prevention_bytes = nal_reader_get_epb_count (&nr);
return GST_H264_PARSER_OK; return GST_H264_PARSER_OK;
......
...@@ -599,6 +599,9 @@ struct _GstH264SliceHdr ...@@ -599,6 +599,9 @@ struct _GstH264SliceHdr
/* Size of the slice_header() in bits */ /* Size of the slice_header() in bits */
guint header_size; guint header_size;
/* Number of emulation prevention bytes (EPB) in this slice_header() */
guint n_emulation_prevention_bytes;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment