| 2713 | |
| 2714 | |
| 2715 | static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ |
| 2716 | MpegEncContext * const s = &h->s; |
| 2717 | AVCodecContext * const avctx= s->avctx; |
| 2718 | int buf_index=0; |
| 2719 | H264Context *hx; ///< thread context |
| 2720 | int context_count = 0; |
| 2721 | int next_avc= h->is_avc ? 0 : buf_size; |
| 2722 | |
| 2723 | h->max_contexts = avctx->thread_count; |
| 2724 | #if 0 |
| 2725 | int i; |
| 2726 | for(i=0; i<50; i++){ |
| 2727 | av_log(NULL, AV_LOG_ERROR,"%02X ", buf[i]); |
| 2728 | } |
| 2729 | #endif |
| 2730 | if(!(s->flags2 & CODEC_FLAG2_CHUNKS)){ |
| 2731 | h->current_slice = 0; |
| 2732 | if (!s->first_field) |
| 2733 | s->current_picture_ptr= NULL; |
| 2734 | ff_h264_reset_sei(h); |
| 2735 | } |
| 2736 | |
| 2737 | for(;;){ |
| 2738 | int consumed; |
| 2739 | int dst_length; |
| 2740 | int bit_length; |
| 2741 | const uint8_t *ptr; |
| 2742 | int i, nalsize = 0; |
| 2743 | int err; |
| 2744 | |
| 2745 | if(buf_index >= next_avc) { |
| 2746 | if(buf_index >= buf_size) break; |
| 2747 | nalsize = 0; |
| 2748 | for(i = 0; i < h->nal_length_size; i++) |
| 2749 | nalsize = (nalsize << 8) | buf[buf_index++]; |
| 2750 | if(nalsize <= 1 || nalsize > buf_size - buf_index){ |
| 2751 | if(nalsize == 1){ |
| 2752 | buf_index++; |
| 2753 | continue; |
| 2754 | }else{ |
| 2755 | av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize); |
| 2756 | break; |
| 2757 | } |
| 2758 | } |
| 2759 | next_avc= buf_index + nalsize; |
| 2760 | } else { |
| 2761 | // start code prefix search |
| 2762 | for(; buf_index + 3 < next_avc; buf_index++){ |
| 2763 | // This should always succeed in the first iteration. |
| 2764 | if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1) |
| 2765 | break; |
| 2766 | } |
| 2767 | |
| 2768 | if(buf_index+3 >= buf_size) break; |
| 2769 | |
| 2770 | buf_index+=3; |
| 2771 | if(buf_index >= next_avc) continue; |
| 2772 | } |
no test coverage detected