libavcodec/h264_parser.c:155: error: Null Dereference
  pointer `h->gb.buffer` last assigned on line 152 could be null and is dereferenced by call to `ff_h264_decode_seq_parameter_set()` at line 155, column 13.

libavcodec/h264_parser.c:109:1: start of procedure parse_nal_units()
107.  * @param buf_size size of the buffer.
108.  */
109. static inline int parse_nal_units(AVCodecParserContext *s,
     ^
110.                                   AVCodecContext *avctx,
111.                                   const uint8_t *buf, int buf_size)

libavcodec/h264_parser.c:113:5: 
111.                                   const uint8_t *buf, int buf_size)
112. {
113.     H264Context *h = s->priv_data;
         ^
114.     const uint8_t *buf_end = buf + buf_size;
115.     unsigned int pps_id;

libavcodec/h264_parser.c:114:5: 
112. {
113.     H264Context *h = s->priv_data;
114.     const uint8_t *buf_end = buf + buf_size;
         ^
115.     unsigned int pps_id;
116.     unsigned int slice_type;

libavcodec/h264_parser.c:117:5: 
115.     unsigned int pps_id;
116.     unsigned int slice_type;
117.     int state = -1;
         ^
118.     const uint8_t *ptr;
119. 

libavcodec/h264_parser.c:121:5: 
119. 
120.     /* set some sane default values */
121.     s->pict_type = AV_PICTURE_TYPE_I;
         ^
122.     s->key_frame = 0;
123. 

libavcodec/h264_parser.c:122:5: 
120.     /* set some sane default values */
121.     s->pict_type = AV_PICTURE_TYPE_I;
122.     s->key_frame = 0;
         ^
123. 
124.     h->avctx= avctx;

libavcodec/h264_parser.c:124:5: 
122.     s->key_frame = 0;
123. 
124.     h->avctx= avctx;
         ^
125.     h->sei_recovery_frame_cnt = -1;
126.     h->sei_dpb_output_delay         =  0;

libavcodec/h264_parser.c:125:5: 
123. 
124.     h->avctx= avctx;
125.     h->sei_recovery_frame_cnt = -1;
         ^
126.     h->sei_dpb_output_delay         =  0;
127.     h->sei_cpb_removal_delay        = -1;

libavcodec/h264_parser.c:126:5: 
124.     h->avctx= avctx;
125.     h->sei_recovery_frame_cnt = -1;
126.     h->sei_dpb_output_delay         =  0;
         ^
127.     h->sei_cpb_removal_delay        = -1;
128.     h->sei_buffering_period_present =  0;

libavcodec/h264_parser.c:127:5: 
125.     h->sei_recovery_frame_cnt = -1;
126.     h->sei_dpb_output_delay         =  0;
127.     h->sei_cpb_removal_delay        = -1;
         ^
128.     h->sei_buffering_period_present =  0;
129. 

libavcodec/h264_parser.c:128:5: 
126.     h->sei_dpb_output_delay         =  0;
127.     h->sei_cpb_removal_delay        = -1;
128.     h->sei_buffering_period_present =  0;
         ^
129. 
130.     if (!buf_size)

libavcodec/h264_parser.c:130:10: Taking false branch
128.     h->sei_buffering_period_present =  0;
129. 
130.     if (!buf_size)
              ^
131.         return 0;
132. 

libavcodec/h264_parser.c:236:5: Loop condition is true. Entering loop body
234.         }
235.         buf += consumed;
236.     }
         ^
237.     /* didn't find a picture! */
238.     av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\n");

libavcodec/h264_parser.c:135:9: Skipping avpriv_find_start_code(): empty list of specs
133.     for(;;) {
134.         int src_length, dst_length, consumed;
135.         buf = avpriv_find_start_code(buf, buf_end, &state);
             ^
136.         if(buf >= buf_end)
137.             break;

libavcodec/h264_parser.c:136:12: Taking false branch
134.         int src_length, dst_length, consumed;
135.         buf = avpriv_find_start_code(buf, buf_end, &state);
136.         if(buf >= buf_end)
                ^
137.             break;
138.         --buf;

libavcodec/h264_parser.c:138:9: 
136.         if(buf >= buf_end)
137.             break;
138.         --buf;
             ^
139.         src_length = buf_end - buf;
140.         switch (state & 0x1f) {

libavcodec/h264_parser.c:139:9: 
137.             break;
138.         --buf;
139.         src_length = buf_end - buf;
             ^
140.         switch (state & 0x1f) {
141.         case NAL_SLICE:

libavcodec/h264_parser.c:140:9: 
138.         --buf;
139.         src_length = buf_end - buf;
140.         switch (state & 0x1f) {
             ^
141.         case NAL_SLICE:
142.         case NAL_IDR_SLICE:

libavcodec/h264_parser.c:141:9: Switch condition is true. Entering switch case
139.         src_length = buf_end - buf;
140.         switch (state & 0x1f) {
141.         case NAL_SLICE:
             ^
142.         case NAL_IDR_SLICE:
143.             // Do not walk the whole buffer just to decode slice header

libavcodec/h264_parser.c:144:17: Taking false branch
142.         case NAL_IDR_SLICE:
143.             // Do not walk the whole buffer just to decode slice header
144.             if (src_length > 20)
                     ^
145.                 src_length = 20;
146.             break;

libavcodec/h264_parser.c:148:9: Skipping ff_h264_decode_nal(): empty list of specs
146.             break;
147.         }
148.         ptr= ff_h264_decode_nal(h, buf, &dst_length, &consumed, src_length);
             ^
149.         if (ptr==NULL || dst_length < 0)
150.             break;

libavcodec/h264_parser.c:149:13: Taking false branch
147.         }
148.         ptr= ff_h264_decode_nal(h, buf, &dst_length, &consumed, src_length);
149.         if (ptr==NULL || dst_length < 0)
                 ^
150.             break;
151. 

libavcodec/h264_parser.c:149:26: Taking false branch
147.         }
148.         ptr= ff_h264_decode_nal(h, buf, &dst_length, &consumed, src_length);
149.         if (ptr==NULL || dst_length < 0)
                              ^
150.             break;
151. 

libavcodec/h264_parser.c:152:9: 
150.             break;
151. 
152.         init_get_bits(&h->gb, ptr, 8*dst_length);
             ^
153.         switch(h->nal_unit_type) {
154.         case NAL_SPS:

libavcodec/get_bits.h:375:1: start of procedure init_get_bits()
  373.  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
  374.  */
  375. static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
       ^
  376.                                 int bit_size)
  377. {

libavcodec/get_bits.h:379:5: 
  377. {
  378.     int buffer_size;
  379.     int ret = 0;
           ^
  380. 
  381.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {

libavcodec/get_bits.h:381:9: Taking true branch
  379.     int ret = 0;
  380. 
  381.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
               ^
  382.         buffer_size = bit_size = 0;
  383.         buffer      = NULL;

libavcodec/get_bits.h:382:9: 
  380. 
  381.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
  382.         buffer_size = bit_size = 0;
               ^
  383.         buffer      = NULL;
  384.         ret         = AVERROR_INVALIDDATA;

libavcodec/get_bits.h:383:9: 
  381.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
  382.         buffer_size = bit_size = 0;
  383.         buffer      = NULL;
               ^
  384.         ret         = AVERROR_INVALIDDATA;
  385.     }

libavcodec/get_bits.h:384:9: 
  382.         buffer_size = bit_size = 0;
  383.         buffer      = NULL;
  384.         ret         = AVERROR_INVALIDDATA;
               ^
  385.     }
  386. 

libavcodec/get_bits.h:387:5: 
  385.     }
  386. 
  387.     buffer_size = (bit_size + 7) >> 3;
           ^
  388. 
  389.     s->buffer             = buffer;

libavcodec/get_bits.h:389:5: 
  387.     buffer_size = (bit_size + 7) >> 3;
  388. 
  389.     s->buffer             = buffer;
           ^
  390.     s->size_in_bits       = bit_size;
  391. #if !UNCHECKED_BITSTREAM_READER

libavcodec/get_bits.h:390:5: 
  388. 
  389.     s->buffer             = buffer;
  390.     s->size_in_bits       = bit_size;
           ^
  391. #if !UNCHECKED_BITSTREAM_READER
  392.     s->size_in_bits_plus8 = bit_size + 8;

libavcodec/get_bits.h:392:5: 
  390.     s->size_in_bits       = bit_size;
  391. #if !UNCHECKED_BITSTREAM_READER
  392.     s->size_in_bits_plus8 = bit_size + 8;
           ^
  393. #endif
  394.     s->buffer_end         = buffer + buffer_size;

libavcodec/get_bits.h:394:5: 
  392.     s->size_in_bits_plus8 = bit_size + 8;
  393. #endif
  394.     s->buffer_end         = buffer + buffer_size;
           ^
  395.     s->index              = 0;
  396. 

libavcodec/get_bits.h:395:5: 
  393. #endif
  394.     s->buffer_end         = buffer + buffer_size;
  395.     s->index              = 0;
           ^
  396. 
  397.     return ret;

libavcodec/get_bits.h:397:5: 
  395.     s->index              = 0;
  396. 
  397.     return ret;
           ^
  398. }
  399. 

libavcodec/get_bits.h:398:1: return from a call to init_get_bits
  396. 
  397.     return ret;
  398. }
       ^
  399. 
  400. /**

libavcodec/h264_parser.c:153:9: 
151. 
152.         init_get_bits(&h->gb, ptr, 8*dst_length);
153.         switch(h->nal_unit_type) {
             ^
154.         case NAL_SPS:
155.             ff_h264_decode_seq_parameter_set(h);

libavcodec/h264_parser.c:154:9: Switch condition is true. Entering switch case
152.         init_get_bits(&h->gb, ptr, 8*dst_length);
153.         switch(h->nal_unit_type) {
154.         case NAL_SPS:
             ^
155.             ff_h264_decode_seq_parameter_set(h);
156.             break;

libavcodec/h264_parser.c:155:13: 
153.         switch(h->nal_unit_type) {
154.         case NAL_SPS:
155.             ff_h264_decode_seq_parameter_set(h);
                 ^
156.             break;
157.         case NAL_PPS:

libavcodec/h264_ps.c:298:1: start of procedure ff_h264_decode_seq_parameter_set()
  296. }
  297. 
  298. int ff_h264_decode_seq_parameter_set(H264Context *h){
       ^
  299.     int profile_idc, level_idc, constraint_set_flags = 0;
  300.     unsigned int sps_id;

libavcodec/h264_ps.c:299:5: 
  297. 
  298. int ff_h264_decode_seq_parameter_set(H264Context *h){
  299.     int profile_idc, level_idc, constraint_set_flags = 0;
           ^
  300.     unsigned int sps_id;
  301.     int i, log2_max_frame_num_minus4;

libavcodec/h264_ps.c:304:5: Skipping get_bits(): empty list of specs
  302.     SPS *sps;
  303. 
  304.     profile_idc= get_bits(&h->gb, 8);
           ^
  305.     constraint_set_flags |= get_bits1(&h->gb) << 0;   //constraint_set0_flag
  306.     constraint_set_flags |= get_bits1(&h->gb) << 1;   //constraint_set1_flag

libavcodec/h264_ps.c:305:5: 
  303. 
  304.     profile_idc= get_bits(&h->gb, 8);
  305.     constraint_set_flags |= get_bits1(&h->gb) << 0;   //constraint_set0_flag
           ^
  306.     constraint_set_flags |= get_bits1(&h->gb) << 1;   //constraint_set1_flag
  307.     constraint_set_flags |= get_bits1(&h->gb) << 2;   //constraint_set2_flag

libavcodec/get_bits.h:271:1: start of procedure get_bits1()
    269. }
    270. 
    271. static inline unsigned int get_bits1(GetBitContext *s)
         ^
    272. {
    273.     unsigned int index = s->index;

libavcodec/get_bits.h:273:5: 
    271. static inline unsigned int get_bits1(GetBitContext *s)
    272. {
    273.     unsigned int index = s->index;
             ^
    274.     uint8_t result     = s->buffer[index >> 3];
    275. #ifdef BITSTREAM_READER_LE

libavcodec/get_bits.h:274:5: 
    272. {
    273.     unsigned int index = s->index;
    274.     uint8_t result     = s->buffer[index >> 3];
             ^
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;

libavcodec/get_bits.h:276:5: 
    274.     uint8_t result     = s->buffer[index >> 3];
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;
             ^
    277.     result  &= 1;
    278. #else

libavcodec/get_bits.h:277:5: 
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;
    277.     result  &= 1;
             ^
    278. #else
    279.     result <<= index & 7;

libavcodec/get_bits.h:283:9: Taking true branch
    281. #endif
    282. #if !UNCHECKED_BITSTREAM_READER
    283.     if (s->index < s->size_in_bits_plus8)
                 ^
    284. #endif
    285.         index++;

libavcodec/get_bits.h:285:9: 
    283.     if (s->index < s->size_in_bits_plus8)
    284. #endif
    285.         index++;
                 ^
    286.     s->index = index;
    287. 

libavcodec/get_bits.h:286:5: 
    284. #endif
    285.         index++;
    286.     s->index = index;
             ^
    287. 
    288.     return result;

libavcodec/get_bits.h:288:5: 
    286.     s->index = index;
    287. 
    288.     return result;
             ^
    289. }
    290. 

libavcodec/get_bits.h:289:1: return from a call to get_bits1
    287. 
    288.     return result;
    289. }
         ^
    290. 
    291. static inline unsigned int show_bits1(GetBitContext *s)

libavcodec/h264_ps.c:306:5: 
  304.     profile_idc= get_bits(&h->gb, 8);
  305.     constraint_set_flags |= get_bits1(&h->gb) << 0;   //constraint_set0_flag
  306.     constraint_set_flags |= get_bits1(&h->gb) << 1;   //constraint_set1_flag
           ^
  307.     constraint_set_flags |= get_bits1(&h->gb) << 2;   //constraint_set2_flag
  308.     constraint_set_flags |= get_bits1(&h->gb) << 3;   //constraint_set3_flag

libavcodec/get_bits.h:271:1: start of procedure get_bits1()
    269. }
    270. 
    271. static inline unsigned int get_bits1(GetBitContext *s)
         ^
    272. {
    273.     unsigned int index = s->index;

libavcodec/get_bits.h:273:5: 
    271. static inline unsigned int get_bits1(GetBitContext *s)
    272. {
    273.     unsigned int index = s->index;
             ^
    274.     uint8_t result     = s->buffer[index >> 3];
    275. #ifdef BITSTREAM_READER_LE

libavcodec/get_bits.h:274:5: 
    272. {
    273.     unsigned int index = s->index;
    274.     uint8_t result     = s->buffer[index >> 3];
             ^
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;

libavcodec/get_bits.h:276:5: 
    274.     uint8_t result     = s->buffer[index >> 3];
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;
             ^
    277.     result  &= 1;
    278. #else

libavcodec/get_bits.h:277:5: 
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;
    277.     result  &= 1;
             ^
    278. #else
    279.     result <<= index & 7;

libavcodec/get_bits.h:283:9: Taking true branch
    281. #endif
    282. #if !UNCHECKED_BITSTREAM_READER
    283.     if (s->index < s->size_in_bits_plus8)
                 ^
    284. #endif
    285.         index++;

libavcodec/get_bits.h:285:9: 
    283.     if (s->index < s->size_in_bits_plus8)
    284. #endif
    285.         index++;
                 ^
    286.     s->index = index;
    287. 

libavcodec/get_bits.h:286:5: 
    284. #endif
    285.         index++;
    286.     s->index = index;
             ^
    287. 
    288.     return result;

libavcodec/get_bits.h:288:5: 
    286.     s->index = index;
    287. 
    288.     return result;
             ^
    289. }
    290. 

libavcodec/get_bits.h:289:1: return from a call to get_bits1
    287. 
    288.     return result;
    289. }
         ^
    290. 
    291. static inline unsigned int show_bits1(GetBitContext *s)

libavcodec/h264_ps.c:307:5: 
  305.     constraint_set_flags |= get_bits1(&h->gb) << 0;   //constraint_set0_flag
  306.     constraint_set_flags |= get_bits1(&h->gb) << 1;   //constraint_set1_flag
  307.     constraint_set_flags |= get_bits1(&h->gb) << 2;   //constraint_set2_flag
           ^
  308.     constraint_set_flags |= get_bits1(&h->gb) << 3;   //constraint_set3_flag
  309.     get_bits(&h->gb, 4); // reserved

libavcodec/get_bits.h:271:1: start of procedure get_bits1()
    269. }
    270. 
    271. static inline unsigned int get_bits1(GetBitContext *s)
         ^
    272. {
    273.     unsigned int index = s->index;

libavcodec/get_bits.h:273:5: 
    271. static inline unsigned int get_bits1(GetBitContext *s)
    272. {
    273.     unsigned int index = s->index;
             ^
    274.     uint8_t result     = s->buffer[index >> 3];
    275. #ifdef BITSTREAM_READER_LE

libavcodec/get_bits.h:274:5: 
    272. {
    273.     unsigned int index = s->index;
    274.     uint8_t result     = s->buffer[index >> 3];
             ^
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;

libavcodec/get_bits.h:276:5: 
    274.     uint8_t result     = s->buffer[index >> 3];
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;
             ^
    277.     result  &= 1;
    278. #else

libavcodec/get_bits.h:277:5: 
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;
    277.     result  &= 1;
             ^
    278. #else
    279.     result <<= index & 7;

libavcodec/get_bits.h:283:9: Taking true branch
    281. #endif
    282. #if !UNCHECKED_BITSTREAM_READER
    283.     if (s->index < s->size_in_bits_plus8)
                 ^
    284. #endif
    285.         index++;

libavcodec/get_bits.h:285:9: 
    283.     if (s->index < s->size_in_bits_plus8)
    284. #endif
    285.         index++;
                 ^
    286.     s->index = index;
    287. 

libavcodec/get_bits.h:286:5: 
    284. #endif
    285.         index++;
    286.     s->index = index;
             ^
    287. 
    288.     return result;

libavcodec/get_bits.h:288:5: 
    286.     s->index = index;
    287. 
    288.     return result;
             ^
    289. }
    290. 

libavcodec/get_bits.h:289:1: return from a call to get_bits1
    287. 
    288.     return result;
    289. }
         ^
    290. 
    291. static inline unsigned int show_bits1(GetBitContext *s)

libavcodec/h264_ps.c:308:5: 
  306.     constraint_set_flags |= get_bits1(&h->gb) << 1;   //constraint_set1_flag
  307.     constraint_set_flags |= get_bits1(&h->gb) << 2;   //constraint_set2_flag
  308.     constraint_set_flags |= get_bits1(&h->gb) << 3;   //constraint_set3_flag
           ^
  309.     get_bits(&h->gb, 4); // reserved
  310.     level_idc= get_bits(&h->gb, 8);

libavcodec/get_bits.h:271:1: start of procedure get_bits1()
    269. }
    270. 
    271. static inline unsigned int get_bits1(GetBitContext *s)
         ^
    272. {
    273.     unsigned int index = s->index;

libavcodec/get_bits.h:273:5: 
    271. static inline unsigned int get_bits1(GetBitContext *s)
    272. {
    273.     unsigned int index = s->index;
             ^
    274.     uint8_t result     = s->buffer[index >> 3];
    275. #ifdef BITSTREAM_READER_LE

libavcodec/get_bits.h:274:5: 
    272. {
    273.     unsigned int index = s->index;
    274.     uint8_t result     = s->buffer[index >> 3];
             ^
    275. #ifdef BITSTREAM_READER_LE
    276.     result >>= index & 7;

static inline int parse_nal_units(AVCodecParserContext *s,
                                  AVCodecContext *avctx,
                                  const uint8_t *buf, int buf_size)
{
    H264Context *h = s->priv_data;
    const uint8_t *buf_end = buf + buf_size;
    unsigned int pps_id;
    unsigned int slice_type;
    int state = -1;
    const uint8_t *ptr;
    s->pict_type = AV_PICTURE_TYPE_I;
    s->key_frame = 0;
    h->avctx= avctx;
    h->sei_recovery_frame_cnt = -1;
    h->sei_dpb_output_delay         =  0;
    h->sei_cpb_removal_delay        = -1;
    h->sei_buffering_period_present =  0;
    if (!buf_size)
        return 0;
    for(;;) {
        int src_length, dst_length, consumed;
        buf = avpriv_find_start_code(buf, buf_end, &state);
        if(buf >= buf_end)
            break;
        --buf;
        src_length = buf_end - buf;
        switch (state & 0x1f) {
        case NAL_SLICE:
        case NAL_IDR_SLICE:
            if (src_length > 20)
                src_length = 20;
            break;
        }
        ptr= ff_h264_decode_nal(h, buf, &dst_length, &consumed, src_length);
        if (ptr==NULL || dst_length < 0)
            break;
        init_get_bits(&h->gb, ptr, 8*dst_length);
        switch(h->nal_unit_type) {
        case NAL_SPS:
            ff_h264_decode_seq_parameter_set(h);
            break;
        case NAL_PPS:
            ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits);
            break;
        case NAL_SEI:
            ff_h264_decode_sei(h);
            break;
        case NAL_IDR_SLICE:
            s->key_frame = 1;
        case NAL_SLICE:
            get_ue_golomb(&h->gb);
            slice_type = get_ue_golomb_31(&h->gb);
            s->pict_type = golomb_to_pict_type[slice_type % 5];
            if (h->sei_recovery_frame_cnt >= 0) {
                s->key_frame = 1;
            }
            pps_id= get_ue_golomb(&h->gb);
            if(pps_id>=MAX_PPS_COUNT) {
                av_log(h->avctx, AV_LOG_ERROR, "pps_id out of range\n");
                return -1;
            }
            if(!h->pps_buffers[pps_id]) {
                av_log(h->avctx, AV_LOG_ERROR, "non-existing PPS referenced\n");
                return -1;
            }
            h->pps= *h->pps_buffers[pps_id];
            if(!h->sps_buffers[h->pps.sps_id]) {
                av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS referenced\n");
                return -1;
            }
            h->sps = *h->sps_buffers[h->pps.sps_id];
            h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num);
            avctx->profile = ff_h264_get_profile(&h->sps);
            avctx->level   = h->sps.level_idc;
            if(h->sps.frame_mbs_only_flag){
                h->picture_structure= PICT_FRAME;
            }else{
                if(get_bits1(&h->gb)) {
                    h->picture_structure= PICT_TOP_FIELD + get_bits1(&h->gb);
                } else {
                    h->picture_structure= PICT_FRAME;
                }
            }
            if(h->sps.pic_struct_present_flag) {
                switch (h->sei_pic_struct) {
                    case SEI_PIC_STRUCT_TOP_FIELD:
                    case SEI_PIC_STRUCT_BOTTOM_FIELD:
                        s->repeat_pict = 0;
                        break;
                    case SEI_PIC_STRUCT_FRAME:
                    case SEI_PIC_STRUCT_TOP_BOTTOM:
                    case SEI_PIC_STRUCT_BOTTOM_TOP:
                        s->repeat_pict = 1;
                        break;
                    case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
                    case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
                        s->repeat_pict = 2;
                        break;
                    case SEI_PIC_STRUCT_FRAME_DOUBLING:
                        s->repeat_pict = 3;
                        break;
                    case SEI_PIC_STRUCT_FRAME_TRIPLING:
                        s->repeat_pict = 5;
                        break;
                    default:
                        s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;
                        break;
                }
            } else {
                s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;
            }
            return 0;
        }
        buf += consumed;
    }
    av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\n");
    return -1;
}
['static inline int parse_nal_units(AVCodecParserContext *s,\n                                  AVCodecContext *avctx,\n                                  const uint8_t *buf, int buf_size)\n{\n    H264Context *h = s->priv_data;\n    const uint8_t *buf_end = buf + buf_size;\n    unsigned int pps_id;\n    unsigned int slice_type;\n    int state = -1;\n    const uint8_t *ptr;\n    s->pict_type = AV_PICTURE_TYPE_I;\n    s->key_frame = 0;\n    h->avctx= avctx;\n    h->sei_recovery_frame_cnt = -1;\n    h->sei_dpb_output_delay         =  0;\n    h->sei_cpb_removal_delay        = -1;\n    h->sei_buffering_period_present =  0;\n    if (!buf_size)\n        return 0;\n    for(;;) {\n        int src_length, dst_length, consumed;\n        buf = avpriv_find_start_code(buf, buf_end, &state);\n        if(buf >= buf_end)\n            break;\n        --buf;\n        src_length = buf_end - buf;\n        switch (state & 0x1f) {\n        case NAL_SLICE:\n        case NAL_IDR_SLICE:\n            if (src_length > 20)\n                src_length = 20;\n            break;\n        }\n        ptr= ff_h264_decode_nal(h, buf, &dst_length, &consumed, src_length);\n        if (ptr==NULL || dst_length < 0)\n            break;\n        init_get_bits(&h->gb, ptr, 8*dst_length);\n        switch(h->nal_unit_type) {\n        case NAL_SPS:\n            ff_h264_decode_seq_parameter_set(h);\n            break;\n        case NAL_PPS:\n            ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits);\n            break;\n        case NAL_SEI:\n            ff_h264_decode_sei(h);\n            break;\n        case NAL_IDR_SLICE:\n            s->key_frame = 1;\n        case NAL_SLICE:\n            get_ue_golomb(&h->gb);\n            slice_type = get_ue_golomb_31(&h->gb);\n            s->pict_type = golomb_to_pict_type[slice_type % 5];\n            if (h->sei_recovery_frame_cnt >= 0) {\n                s->key_frame = 1;\n            }\n            pps_id= get_ue_golomb(&h->gb);\n            if(pps_id>=MAX_PPS_COUNT) {\n                av_log(h->avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n                return -1;\n            }\n            if(!h->pps_buffers[pps_id]) {\n                av_log(h->avctx, AV_LOG_ERROR, "non-existing PPS referenced\\n");\n                return -1;\n            }\n            h->pps= *h->pps_buffers[pps_id];\n            if(!h->sps_buffers[h->pps.sps_id]) {\n                av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS referenced\\n");\n                return -1;\n            }\n            h->sps = *h->sps_buffers[h->pps.sps_id];\n            h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num);\n            avctx->profile = ff_h264_get_profile(&h->sps);\n            avctx->level   = h->sps.level_idc;\n            if(h->sps.frame_mbs_only_flag){\n                h->picture_structure= PICT_FRAME;\n            }else{\n                if(get_bits1(&h->gb)) {\n                    h->picture_structure= PICT_TOP_FIELD + get_bits1(&h->gb);\n                } else {\n                    h->picture_structure= PICT_FRAME;\n                }\n            }\n            if(h->sps.pic_struct_present_flag) {\n                switch (h->sei_pic_struct) {\n                    case SEI_PIC_STRUCT_TOP_FIELD:\n                    case SEI_PIC_STRUCT_BOTTOM_FIELD:\n                        s->repeat_pict = 0;\n                        break;\n                    case SEI_PIC_STRUCT_FRAME:\n                    case SEI_PIC_STRUCT_TOP_BOTTOM:\n                    case SEI_PIC_STRUCT_BOTTOM_TOP:\n                        s->repeat_pict = 1;\n                        break;\n                    case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:\n                    case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:\n                        s->repeat_pict = 2;\n                        break;\n                    case SEI_PIC_STRUCT_FRAME_DOUBLING:\n                        s->repeat_pict = 3;\n                        break;\n                    case SEI_PIC_STRUCT_FRAME_TRIPLING:\n                        s->repeat_pict = 5;\n                        break;\n                    default:\n                        s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;\n                        break;\n                }\n            } else {\n                s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;\n            }\n            return 0;\n        }\n        buf += consumed;\n    }\n    av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\\n");\n    return -1;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n                                int bit_size)\n{\n    int buffer_size;\n    int ret = 0;\n    if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n        buffer_size = bit_size = 0;\n        buffer      = NULL;\n        ret         = AVERROR_INVALIDDATA;\n    }\n    buffer_size = (bit_size + 7) >> 3;\n    s->buffer             = buffer;\n    s->size_in_bits       = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n    s->size_in_bits_plus8 = bit_size + 8;\n#endif\n    s->buffer_end         = buffer + buffer_size;\n    s->index              = 0;\n    return ret;\n}', 'int ff_h264_decode_seq_parameter_set(H264Context *h){\n    int profile_idc, level_idc, constraint_set_flags = 0;\n    unsigned int sps_id;\n    int i, log2_max_frame_num_minus4;\n    SPS *sps;\n    profile_idc= get_bits(&h->gb, 8);\n    constraint_set_flags |= get_bits1(&h->gb) << 0;\n    constraint_set_flags |= get_bits1(&h->gb) << 1;\n    constraint_set_flags |= get_bits1(&h->gb) << 2;\n    constraint_set_flags |= get_bits1(&h->gb) << 3;\n    get_bits(&h->gb, 4);\n    level_idc= get_bits(&h->gb, 8);\n    sps_id= get_ue_golomb_31(&h->gb);\n    if(sps_id >= MAX_SPS_COUNT) {\n        av_log(h->avctx, AV_LOG_ERROR, "sps_id (%d) out of range\\n", sps_id);\n        return -1;\n    }\n    sps= av_mallocz(sizeof(SPS));\n    if(sps == NULL)\n        return -1;\n    sps->time_offset_length = 24;\n    sps->profile_idc= profile_idc;\n    sps->constraint_set_flags = constraint_set_flags;\n    sps->level_idc= level_idc;\n    memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4));\n    memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8));\n    sps->scaling_matrix_present = 0;\n    if (sps->profile_idc == 100 || sps->profile_idc == 110 ||\n        sps->profile_idc == 122 || sps->profile_idc == 244 ||\n        sps->profile_idc ==  44 || sps->profile_idc ==  83 ||\n        sps->profile_idc ==  86 || sps->profile_idc == 118 ||\n        sps->profile_idc == 128 || sps->profile_idc == 144) {\n        sps->chroma_format_idc= get_ue_golomb_31(&h->gb);\n        if(sps->chroma_format_idc > 3) {\n            av_log(h->avctx, AV_LOG_ERROR, "chroma_format_idc (%u) out of range\\n", sps->chroma_format_idc);\n            goto fail;\n        } else if(sps->chroma_format_idc == 3) {\n            sps->residual_color_transform_flag = get_bits1(&h->gb);\n        }\n        sps->bit_depth_luma   = get_ue_golomb(&h->gb) + 8;\n        sps->bit_depth_chroma = get_ue_golomb(&h->gb) + 8;\n        sps->transform_bypass = get_bits1(&h->gb);\n        decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8);\n    }else{\n        sps->chroma_format_idc= 1;\n        sps->bit_depth_luma   = 8;\n        sps->bit_depth_chroma = 8;\n    }\n    log2_max_frame_num_minus4 = get_ue_golomb(&h->gb);\n    if (log2_max_frame_num_minus4 < MIN_LOG2_MAX_FRAME_NUM - 4 ||\n        log2_max_frame_num_minus4 > MAX_LOG2_MAX_FRAME_NUM - 4) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "log2_max_frame_num_minus4 out of range (0-12): %d\\n",\n               log2_max_frame_num_minus4);\n        goto fail;\n    }\n    sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;\n    sps->poc_type= get_ue_golomb_31(&h->gb);\n    if(sps->poc_type == 0){\n        sps->log2_max_poc_lsb= get_ue_golomb(&h->gb) + 4;\n    } else if(sps->poc_type == 1){\n        sps->delta_pic_order_always_zero_flag= get_bits1(&h->gb);\n        sps->offset_for_non_ref_pic= get_se_golomb(&h->gb);\n        sps->offset_for_top_to_bottom_field= get_se_golomb(&h->gb);\n        sps->poc_cycle_length                = get_ue_golomb(&h->gb);\n        if((unsigned)sps->poc_cycle_length >= FF_ARRAY_ELEMS(sps->offset_for_ref_frame)){\n            av_log(h->avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\\n", sps->poc_cycle_length);\n            goto fail;\n        }\n        for(i=0; i<sps->poc_cycle_length; i++)\n            sps->offset_for_ref_frame[i]= get_se_golomb(&h->gb);\n    }else if(sps->poc_type != 2){\n        av_log(h->avctx, AV_LOG_ERROR, "illegal POC type %d\\n", sps->poc_type);\n        goto fail;\n    }\n    sps->ref_frame_count= get_ue_golomb_31(&h->gb);\n    if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){\n        av_log(h->avctx, AV_LOG_ERROR, "too many reference frames\\n");\n        goto fail;\n    }\n    sps->gaps_in_frame_num_allowed_flag= get_bits1(&h->gb);\n    sps->mb_width = get_ue_golomb(&h->gb) + 1;\n    sps->mb_height= get_ue_golomb(&h->gb) + 1;\n    if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 ||\n       av_image_check_size(16*sps->mb_width, 16*sps->mb_height, 0, h->avctx)){\n        av_log(h->avctx, AV_LOG_ERROR, "mb_width/height overflow\\n");\n        goto fail;\n    }\n    sps->frame_mbs_only_flag= get_bits1(&h->gb);\n    if(!sps->frame_mbs_only_flag)\n        sps->mb_aff= get_bits1(&h->gb);\n    else\n        sps->mb_aff= 0;\n    sps->direct_8x8_inference_flag= get_bits1(&h->gb);\n    if(!sps->frame_mbs_only_flag && !sps->direct_8x8_inference_flag){\n        av_log(h->avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\\n");\n        goto fail;\n    }\n#ifndef ALLOW_INTERLACE\n    if(sps->mb_aff)\n        av_log(h->avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\\n");\n#endif\n    sps->crop= get_bits1(&h->gb);\n    if(sps->crop){\n        int crop_left   = get_ue_golomb(&h->gb);\n        int crop_right  = get_ue_golomb(&h->gb);\n        int crop_top    = get_ue_golomb(&h->gb);\n        int crop_bottom = get_ue_golomb(&h->gb);\n        if (h->avctx->flags2 & CODEC_FLAG2_IGNORE_CROP) {\n            av_log(h->avctx, AV_LOG_DEBUG, "discarding sps cropping, original "\n                   "values are l:%u r:%u t:%u b:%u\\n", crop_left, crop_right,\n                   crop_top, crop_bottom);\n            sps->crop_left   =\n            sps->crop_right  =\n            sps->crop_top    =\n            sps->crop_bottom = 0;\n        } else {\n            int vsub = (sps->chroma_format_idc == 1) ? 1 : 0;\n            int hsub = (sps->chroma_format_idc == 1 || sps->chroma_format_idc == 2) ? 1 : 0;\n            int step_x = 1 << hsub;\n            int step_y = (2 - sps->frame_mbs_only_flag) << vsub;\n            if (crop_left & (0x1F >> (sps->bit_depth_luma > 8)) &&\n                !(h->avctx->flags & CODEC_FLAG_UNALIGNED)) {\n                crop_left &= ~(0x1F >> (sps->bit_depth_luma > 8));\n                av_log(h->avctx, AV_LOG_WARNING, "Reducing left cropping to %d "\n                       "chroma samples to preserve alignment.\\n",\n                       crop_left);\n            }\n            sps->crop_left   = crop_left   * step_x;\n            sps->crop_right  = crop_right  * step_x;\n            sps->crop_top    = crop_top    * step_y;\n            sps->crop_bottom = crop_bottom * step_y;\n        }\n    }else{\n        sps->crop_left  =\n        sps->crop_right =\n        sps->crop_top   =\n        sps->crop_bottom= 0;\n        sps->crop = 0;\n    }\n    sps->vui_parameters_present_flag= get_bits1(&h->gb);\n    if( sps->vui_parameters_present_flag )\n        if (decode_vui_parameters(h, sps) < 0)\n            goto fail;\n    if(!sps->sar.den)\n        sps->sar.den= 1;\n    if(h->avctx->debug&FF_DEBUG_PICT_INFO){\n        static const char csp[4][5] = { "Gray", "420", "422", "444" };\n        av_log(h->avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d\\n",\n               sps_id, sps->profile_idc, sps->level_idc,\n               sps->poc_type,\n               sps->ref_frame_count,\n               sps->mb_width, sps->mb_height,\n               sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"),\n               sps->direct_8x8_inference_flag ? "8B8" : "",\n               sps->crop_left, sps->crop_right,\n               sps->crop_top, sps->crop_bottom,\n               sps->vui_parameters_present_flag ? "VUI" : "",\n               csp[sps->chroma_format_idc],\n               sps->timing_info_present_flag ? sps->num_units_in_tick : 0,\n               sps->timing_info_present_flag ? sps->time_scale : 0\n               );\n    }\n    sps->new = 1;\n    av_free(h->sps_buffers[sps_id]);\n    h->sps_buffers[sps_id] = sps;\n    h->sps                 = *sps;\n    h->current_sps_id      = sps_id;\n    return 0;\nfail:\n    av_free(sps);\n    return -1;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n    unsigned int index = s->index;\n    uint8_t result     = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n    result >>= index & 7;\n    result  &= 1;\n#else\n    result <<= index & 7;\n    result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n    if (s->index < s->size_in_bits_plus8)\n#endif\n        index++;\n    s->index = index;\n    return result;\n}']