Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: patched-ffmpeg-mt/libavcodec/h264.c

Issue 789004: ffmpeg roll of source to mar 9 version... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/ffmpeg/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder 2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> 3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 * 4 *
5 * This file is part of FFmpeg. 5 * This file is part of FFmpeg.
6 * 6 *
7 * FFmpeg is free software; you can redistribute it and/or 7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version. 10 * version 2.1 of the License, or (at your option) any later version.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 static const uint8_t rem6[52]={ 47 static const uint8_t rem6[52]={
48 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 48 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
49 }; 49 };
50 50
51 static const uint8_t div6[52]={ 51 static const uint8_t div6[52]={
52 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 52 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
53 }; 53 };
54 54
55 void ff_h264_write_back_intra_pred_mode(H264Context *h){ 55 void ff_h264_write_back_intra_pred_mode(H264Context *h){
56 const int mb_xy= h->mb_xy; 56 int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[h->mb_xy];
57 57
58 h->intra4x4_pred_mode[mb_xy][0]= h->intra4x4_pred_mode_cache[7+8*1]; 58 AV_COPY32(mode, h->intra4x4_pred_mode_cache + 4 + 8*4);
59 h->intra4x4_pred_mode[mb_xy][1]= h->intra4x4_pred_mode_cache[7+8*2]; 59 mode[4]= h->intra4x4_pred_mode_cache[7+8*3];
60 h->intra4x4_pred_mode[mb_xy][2]= h->intra4x4_pred_mode_cache[7+8*3]; 60 mode[5]= h->intra4x4_pred_mode_cache[7+8*2];
61 h->intra4x4_pred_mode[mb_xy][3]= h->intra4x4_pred_mode_cache[7+8*4]; 61 mode[6]= h->intra4x4_pred_mode_cache[7+8*1];
62 h->intra4x4_pred_mode[mb_xy][4]= h->intra4x4_pred_mode_cache[4+8*4];
63 h->intra4x4_pred_mode[mb_xy][5]= h->intra4x4_pred_mode_cache[5+8*4];
64 h->intra4x4_pred_mode[mb_xy][6]= h->intra4x4_pred_mode_cache[6+8*4];
65 } 62 }
66 63
67 /** 64 /**
68 * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. 65 * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
69 */ 66 */
70 int ff_h264_check_intra4x4_pred_mode(H264Context *h){ 67 int ff_h264_check_intra4x4_pred_mode(H264Context *h){
71 MpegEncContext * const s = &h->s; 68 MpegEncContext * const s = &h->s;
72 static const int8_t top [12]= {-1, 0,LEFT_DC_PRED,-1,-1,-1,-1,-1, 0}; 69 static const int8_t top [12]= {-1, 0,LEFT_DC_PRED,-1,-1,-1,-1,-1, 0};
73 static const int8_t left[12]= { 0,-1, TOP_DC_PRED, 0,-1,-1,-1, 0,-1,DC_128_P RED}; 70 static const int8_t left[12]= { 0,-1, TOP_DC_PRED, 0,-1,-1,-1, 0,-1,DC_128_P RED};
74 int i; 71 int i;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 src++; length--; 147 src++; length--;
151 #if 0 148 #if 0
152 for(i=0; i<length; i++) 149 for(i=0; i<length; i++)
153 printf("%2X ", src[i]); 150 printf("%2X ", src[i]);
154 #endif 151 #endif
155 152
156 #if HAVE_FAST_UNALIGNED 153 #if HAVE_FAST_UNALIGNED
157 # if HAVE_FAST_64BIT 154 # if HAVE_FAST_64BIT
158 # define RS 7 155 # define RS 7
159 for(i=0; i+1<length; i+=9){ 156 for(i=0; i+1<length; i+=9){
160 if(!((~*(const uint64_t*)(src+i) & (*(const uint64_t*)(src+i) - 0x010001 0001000101ULL)) & 0x8000800080008080ULL)) 157 if(!((~AV_RN64A(src+i) & (AV_RN64A(src+i) - 0x0100010001000101ULL)) & 0x 8000800080008080ULL))
161 # else 158 # else
162 # define RS 3 159 # define RS 3
163 for(i=0; i+1<length; i+=5){ 160 for(i=0; i+1<length; i+=5){
164 if(!((~*(const uint32_t*)(src+i) & (*(const uint32_t*)(src+i) - 0x010001 01U)) & 0x80008080U)) 161 if(!((~AV_RN32A(src+i) & (AV_RN32A(src+i) - 0x01000101U)) & 0x80008080U) )
165 # endif 162 # endif
166 continue; 163 continue;
167 if(i>0 && !src[i]) i--; 164 if(i>0 && !src[i]) i--;
168 while(src[i]) i++; 165 while(src[i]) i++;
169 #else 166 #else
170 # define RS 0 167 # define RS 0
171 for(i=0; i+1<length; i+=2){ 168 for(i=0; i+1<length; i+=2){
172 if(src[i]) continue; 169 if(src[i]) continue;
173 if(i>0 && src[i-1]==0) i--; 170 if(i>0 && src[i-1]==0) i--;
174 #endif 171 #endif
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 x_offset, y_offset, qpix_put, chroma_put); 620 x_offset, y_offset, qpix_put, chroma_put);
624 621
625 if(h->use_weight == 2){ 622 if(h->use_weight == 2){
626 int weight0 = h->implicit_weight[refn0][refn1]; 623 int weight0 = h->implicit_weight[refn0][refn1];
627 int weight1 = 64 - weight0; 624 int weight1 = 64 - weight0;
628 luma_weight_avg( dest_y, tmp_y, h-> mb_linesize, 5, weight0, wei ght1, 0); 625 luma_weight_avg( dest_y, tmp_y, h-> mb_linesize, 5, weight0, wei ght1, 0);
629 chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, 5, weight0, wei ght1, 0); 626 chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, 5, weight0, wei ght1, 0);
630 chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, 5, weight0, wei ght1, 0); 627 chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, 5, weight0, wei ght1, 0);
631 }else{ 628 }else{
632 luma_weight_avg(dest_y, tmp_y, h->mb_linesize, h->luma_log2_weight_d enom, 629 luma_weight_avg(dest_y, tmp_y, h->mb_linesize, h->luma_log2_weight_d enom,
633 h->luma_weight[0][refn0], h->luma_weight[1][refn1], 630 h->luma_weight[refn0][0][0] , h->luma_weight[refn1][ 1][0],
634 h->luma_offset[0][refn0] + h->luma_offset[1][refn1]) ; 631 h->luma_weight[refn0][0][1] + h->luma_weight[refn1][ 1][1]);
635 chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, h->chroma_log2_ weight_denom, 632 chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, h->chroma_log2_ weight_denom,
636 h->chroma_weight[0][refn0][0], h->chroma_weight[1][r efn1][0], 633 h->chroma_weight[refn0][0][0][0] , h->chroma_weight[ refn1][1][0][0],
637 h->chroma_offset[0][refn0][0] + h->chroma_offset[1][ refn1][0]); 634 h->chroma_weight[refn0][0][0][1] + h->chroma_weight[ refn1][1][0][1]);
638 chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, h->chroma_log2_ weight_denom, 635 chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, h->chroma_log2_ weight_denom,
639 h->chroma_weight[0][refn0][1], h->chroma_weight[1][r efn1][1], 636 h->chroma_weight[refn0][0][1][0] , h->chroma_weight[ refn1][1][1][0],
640 h->chroma_offset[0][refn0][1] + h->chroma_offset[1][ refn1][1]); 637 h->chroma_weight[refn0][0][1][1] + h->chroma_weight[ refn1][1][1][1]);
641 } 638 }
642 }else{ 639 }else{
643 int list = list1 ? 1 : 0; 640 int list = list1 ? 1 : 0;
644 int refn = h->ref_cache[list][ scan8[n] ]; 641 int refn = h->ref_cache[list][ scan8[n] ];
645 Picture *ref= &h->ref_list[list][refn]; 642 Picture *ref= &h->ref_list[list][refn];
646 mc_dir_part(h, ref, n, square, chroma_height, delta, list, 643 mc_dir_part(h, ref, n, square, chroma_height, delta, list,
647 dest_y, dest_cb, dest_cr, x_offset, y_offset, 644 dest_y, dest_cb, dest_cr, x_offset, y_offset,
648 qpix_put, chroma_put); 645 qpix_put, chroma_put);
649 646
650 luma_weight_op(dest_y, h->mb_linesize, h->luma_log2_weight_denom, 647 luma_weight_op(dest_y, h->mb_linesize, h->luma_log2_weight_denom,
651 h->luma_weight[list][refn], h->luma_offset[list][refn]); 648 h->luma_weight[refn][list][0], h->luma_weight[refn][list] [1]);
652 if(h->use_weight_chroma){ 649 if(h->use_weight_chroma){
653 chroma_weight_op(dest_cb, h->mb_uvlinesize, h->chroma_log2_weight_de nom, 650 chroma_weight_op(dest_cb, h->mb_uvlinesize, h->chroma_log2_weight_de nom,
654 h->chroma_weight[list][refn][0], h->chroma_offset[l ist][refn][0]); 651 h->chroma_weight[refn][list][0][0], h->chroma_weigh t[refn][list][0][1]);
655 chroma_weight_op(dest_cr, h->mb_uvlinesize, h->chroma_log2_weight_de nom, 652 chroma_weight_op(dest_cr, h->mb_uvlinesize, h->chroma_log2_weight_de nom,
656 h->chroma_weight[list][refn][1], h->chroma_offset[l ist][refn][1]); 653 h->chroma_weight[refn][list][1][0], h->chroma_weigh t[refn][list][1][1]);
657 } 654 }
658 } 655 }
659 } 656 }
660 657
661 static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta, 658 static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta,
662 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, 659 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
663 int x_offset, int y_offset, 660 int x_offset, int y_offset,
664 qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_pu t, 661 qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_pu t,
665 qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_av g, 662 qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_av g,
666 h264_weight_func *weight_op, h264_biweight_func *weig ht_avg, 663 h264_weight_func *weight_op, h264_biweight_func *weig ht_avg,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 av_freep(&h->cbp_table); 787 av_freep(&h->cbp_table);
791 av_freep(&h->mvd_table[0]); 788 av_freep(&h->mvd_table[0]);
792 av_freep(&h->mvd_table[1]); 789 av_freep(&h->mvd_table[1]);
793 av_freep(&h->direct_table); 790 av_freep(&h->direct_table);
794 av_freep(&h->non_zero_count); 791 av_freep(&h->non_zero_count);
795 av_freep(&h->slice_table_base); 792 av_freep(&h->slice_table_base);
796 h->slice_table= NULL; 793 h->slice_table= NULL;
797 av_freep(&h->list_counts); 794 av_freep(&h->list_counts);
798 795
799 av_freep(&h->mb2b_xy); 796 av_freep(&h->mb2b_xy);
800 av_freep(&h->mb2b8_xy); 797 av_freep(&h->mb2br_xy);
801 798
802 for(i = 0; i < MAX_THREADS; i++) { 799 for(i = 0; i < MAX_THREADS; i++) {
803 hx = h->thread_context[i]; 800 hx = h->thread_context[i];
804 if(!hx) continue; 801 if(!hx) continue;
805 av_freep(&hx->top_borders[1]); 802 av_freep(&hx->top_borders[1]);
806 av_freep(&hx->top_borders[0]); 803 av_freep(&hx->top_borders[0]);
807 av_freep(&hx->s.obmc_scratchpad); 804 av_freep(&hx->s.obmc_scratchpad);
808 av_freep(&hx->rbsp_buffer[1]); 805 av_freep(&hx->rbsp_buffer[1]);
809 av_freep(&hx->rbsp_buffer[0]); 806 av_freep(&hx->rbsp_buffer[0]);
810 hx->rbsp_buffer_size[0] = 0; 807 hx->rbsp_buffer_size[0] = 0;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 for(i=0; i<2; i++) 871 for(i=0; i<2; i++)
875 for(x=0; x<64; x++) 872 for(x=0; x<64; x++)
876 h->dequant8_coeff[i][0][x] = 1<<6; 873 h->dequant8_coeff[i][0][x] = 1<<6;
877 } 874 }
878 } 875 }
879 876
880 877
881 int ff_h264_alloc_tables(H264Context *h){ 878 int ff_h264_alloc_tables(H264Context *h){
882 MpegEncContext * const s = &h->s; 879 MpegEncContext * const s = &h->s;
883 const int big_mb_num= s->mb_stride * (s->mb_height+1); 880 const int big_mb_num= s->mb_stride * (s->mb_height+1);
881 const int row_mb_num= 2*s->mb_stride*s->avctx->thread_count;
884 int x,y; 882 int x,y;
885 883
886 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->intra4x4_pred_mode, big_mb_num * 8 * sizeo f(uint8_t), fail) 884 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->intra4x4_pred_mode, row_mb_num * 8 * sizeo f(uint8_t), fail)
887 885
888 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count , big_mb_num * 32 * sizeo f(uint8_t), fail) 886 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count , big_mb_num * 32 * sizeo f(uint8_t), fail)
889 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->slice_table_base , (big_mb_num+s->mb_strid e) * sizeof(*h->slice_table_base), fail) 887 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->slice_table_base , (big_mb_num+s->mb_strid e) * sizeof(*h->slice_table_base), fail)
890 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->cbp_table, big_mb_num * sizeof(uint16_t), f ail) 888 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->cbp_table, big_mb_num * sizeof(uint16_t), f ail)
891 889
892 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->chroma_pred_mode_table, big_mb_num * sizeof (uint8_t), fail) 890 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->chroma_pred_mode_table, big_mb_num * sizeof (uint8_t), fail)
893 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[0], 32*big_mb_num * sizeof(uint16 _t), fail); 891 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[0], 16*row_mb_num * sizeof(uint8_ t), fail);
894 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[1], 32*big_mb_num * sizeof(uint16 _t), fail); 892 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[1], 16*row_mb_num * sizeof(uint8_ t), fail);
895 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->direct_table, 32*big_mb_num * sizeof(uint8_ t) , fail); 893 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->direct_table, 4*big_mb_num * sizeof(uint8_t ) , fail);
896 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->list_counts, big_mb_num * sizeof(uint8_t), fail) 894 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->list_counts, big_mb_num * sizeof(uint8_t), fail)
897 895
898 memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(*h->slic e_table_base)); 896 memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(*h->slic e_table_base));
899 h->slice_table= h->slice_table_base + s->mb_stride*2 + 1; 897 h->slice_table= h->slice_table_base + s->mb_stride*2 + 1;
900 898
901 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2b_xy , big_mb_num * sizeof(uint32_t), f ail); 899 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2b_xy , big_mb_num * sizeof(uint32_t), f ail);
902 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2b8_xy , big_mb_num * sizeof(uint32_t), f ail); 900 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2br_xy , big_mb_num * sizeof(uint32_t), f ail);
903 for(y=0; y<s->mb_height; y++){ 901 for(y=0; y<s->mb_height; y++){
904 for(x=0; x<s->mb_width; x++){ 902 for(x=0; x<s->mb_width; x++){
905 const int mb_xy= x + y*s->mb_stride; 903 const int mb_xy= x + y*s->mb_stride;
906 const int b_xy = 4*x + 4*y*h->b_stride; 904 const int b_xy = 4*x + 4*y*h->b_stride;
907 const int b8_xy= 2*x + 2*y*h->b8_stride;
908 905
909 h->mb2b_xy [mb_xy]= b_xy; 906 h->mb2b_xy [mb_xy]= b_xy;
910 h->mb2b8_xy[mb_xy]= b8_xy; 907 h->mb2br_xy[mb_xy]= 8*(FMO ? mb_xy : (mb_xy % (2*s->mb_stride)));
911 } 908 }
912 } 909 }
913 910
914 s->obmc_scratchpad = NULL; 911 s->obmc_scratchpad = NULL;
915 912
916 if(!h->dequant4_coeff[0]) 913 if(!h->dequant4_coeff[0])
917 init_dequant_tables(h); 914 init_dequant_tables(h);
918 915
919 return 0; 916 return 0;
920 fail: 917 fail:
921 free_tables(h); 918 free_tables(h);
922 return -1; 919 return -1;
923 } 920 }
924 921
925 /** 922 /**
926 * Mimic alloc_tables(), but for every context thread. 923 * Mimic alloc_tables(), but for every context thread.
927 */ 924 */
928 static void clone_tables(H264Context *dst, H264Context *src){ 925 static void clone_tables(H264Context *dst, H264Context *src, int i){
929 dst->intra4x4_pred_mode = src->intra4x4_pred_mode; 926 MpegEncContext * const s = &src->s;
927 dst->intra4x4_pred_mode = src->intra4x4_pred_mode + i*8*2*s->mb_stride ;
930 dst->non_zero_count = src->non_zero_count; 928 dst->non_zero_count = src->non_zero_count;
931 dst->slice_table = src->slice_table; 929 dst->slice_table = src->slice_table;
932 dst->cbp_table = src->cbp_table; 930 dst->cbp_table = src->cbp_table;
933 dst->mb2b_xy = src->mb2b_xy; 931 dst->mb2b_xy = src->mb2b_xy;
934 dst->mb2b8_xy = src->mb2b8_xy; 932 dst->mb2br_xy = src->mb2br_xy;
935 dst->chroma_pred_mode_table = src->chroma_pred_mode_table; 933 dst->chroma_pred_mode_table = src->chroma_pred_mode_table;
936 dst->mvd_table[0] = src->mvd_table[0]; 934 dst->mvd_table[0] = src->mvd_table[0] + i*8*2*s->mb_stride;
937 dst->mvd_table[1] = src->mvd_table[1]; 935 dst->mvd_table[1] = src->mvd_table[1] + i*8*2*s->mb_stride;
938 dst->direct_table = src->direct_table; 936 dst->direct_table = src->direct_table;
939 dst->list_counts = src->list_counts; 937 dst->list_counts = src->list_counts;
940 938
941 dst->s.obmc_scratchpad = NULL; 939 dst->s.obmc_scratchpad = NULL;
942 ff_h264_pred_init(&dst->hpc, src->s.codec_id); 940 ff_h264_pred_init(&dst->hpc, src->s.codec_id);
943 } 941 }
944 942
945 /** 943 /**
946 * Init context 944 * Init context
947 * Allocate buffers which are not shared amongst multiple threads. 945 * Allocate buffers which are not shared amongst multiple threads.
948 */ 946 */
949 static int context_init(H264Context *h){ 947 static int context_init(H264Context *h){
950 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail) 948 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail)
951 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail) 949 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail)
952 950
951 h->ref_cache[0][scan8[5 ]+1] = h->ref_cache[0][scan8[7 ]+1] = h->ref_cache[0 ][scan8[13]+1] =
952 h->ref_cache[1][scan8[5 ]+1] = h->ref_cache[1][scan8[7 ]+1] = h->ref_cache[1 ][scan8[13]+1] = PART_NOT_AVAILABLE;
953
953 return 0; 954 return 0;
954 fail: 955 fail:
955 return -1; // free_tables will clean up for us 956 return -1; // free_tables will clean up for us
956 } 957 }
957 958
959 static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size);
960
958 static av_cold void common_init(H264Context *h){ 961 static av_cold void common_init(H264Context *h){
959 MpegEncContext * const s = &h->s; 962 MpegEncContext * const s = &h->s;
960 963
961 s->width = s->avctx->width; 964 s->width = s->avctx->width;
962 s->height = s->avctx->height; 965 s->height = s->avctx->height;
963 s->codec_id= s->avctx->codec->id; 966 s->codec_id= s->avctx->codec->id;
964 967
965 ff_h264_pred_init(&h->hpc, s->codec_id); 968 ff_h264_pred_init(&h->hpc, s->codec_id);
966 969
967 h->dequant_coeff_pps= -1; 970 h->dequant_coeff_pps= -1;
(...skipping 21 matching lines...) Expand all
989 // set defaults 992 // set defaults
990 // s->decode_mb= ff_h263_decode_mb; 993 // s->decode_mb= ff_h263_decode_mb;
991 s->quarter_sample = 1; 994 s->quarter_sample = 1;
992 if(!avctx->has_b_frames) 995 if(!avctx->has_b_frames)
993 s->low_delay= 1; 996 s->low_delay= 1;
994 997
995 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; 998 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
996 999
997 ff_h264_decode_init_vlc(); 1000 ff_h264_decode_init_vlc();
998 1001
999 if(avctx->extradata_size > 0 && avctx->extradata &&
1000 *(char *)avctx->extradata == 1){
1001 h->is_avc = 1;
1002 h->got_avcC = 0;
1003 } else {
1004 h->is_avc = 0;
1005 }
1006
1007 h->thread_context[0] = h; 1002 h->thread_context[0] = h;
1008 h->outputed_poc = INT_MIN; 1003 h->outputed_poc = INT_MIN;
1009 h->prev_poc_msb= 1<<16; 1004 h->prev_poc_msb= 1<<16;
1005 h->x264_build = -1;
1010 ff_h264_reset_sei(h); 1006 ff_h264_reset_sei(h);
1011 if(avctx->codec_id == CODEC_ID_H264){ 1007 if(avctx->codec_id == CODEC_ID_H264){
1012 if(avctx->ticks_per_frame == 1){ 1008 if(avctx->ticks_per_frame == 1){
1013 s->avctx->time_base.den *=2; 1009 s->avctx->time_base.den *=2;
1014 } 1010 }
1015 avctx->ticks_per_frame = 2; 1011 avctx->ticks_per_frame = 2;
1016 } 1012 }
1013
1014 if(avctx->extradata_size > 0 && avctx->extradata && *(char *)avctx->extradat a == 1){
1015 int i, cnt, nalsize;
1016 unsigned char *p = avctx->extradata;
1017
1018 h->is_avc = 1;
1019
1020 if(avctx->extradata_size < 7) {
1021 av_log(avctx, AV_LOG_ERROR, "avcC too short\n");
1022 return -1;
1023 }
1024 /* sps and pps in the avcC always have length coded with 2 bytes,
1025 so put a fake nal_length_size = 2 while parsing them */
1026 h->nal_length_size = 2;
1027 // Decode sps from avcC
1028 cnt = *(p+5) & 0x1f; // Number of sps
1029 p += 6;
1030 for (i = 0; i < cnt; i++) {
1031 nalsize = AV_RB16(p) + 2;
1032 if(decode_nal_units(h, p, nalsize) < 0) {
1033 av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n" , i);
1034 return -1;
1035 }
1036 p += nalsize;
1037 }
1038 // Decode pps from avcC
1039 cnt = *(p++); // Number of pps
1040 for (i = 0; i < cnt; i++) {
1041 nalsize = AV_RB16(p) + 2;
1042 if(decode_nal_units(h, p, nalsize) != nalsize) {
1043 av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n" , i);
1044 return -1;
1045 }
1046 p += nalsize;
1047 }
1048 // Now store right nal length size, that will be use to parse all other nals
1049 h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1;
1050 } else {
1051 h->is_avc = 0;
1052 if(decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) < 0)
1053 return -1;
1054 }
1055 if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames < h->sps.num_ reorder_frames){
1056 s->avctx->has_b_frames = h->sps.num_reorder_frames;
1057 s->low_delay = 0;
1058 }
1059
1017 return 0; 1060 return 0;
1018 } 1061 }
1019 1062
1020 static void copy_picture_range(Picture **to, Picture **from, int count, MpegEncC ontext *new_base, MpegEncContext *old_base) 1063 static void copy_picture_range(Picture **to, Picture **from, int count, MpegEncC ontext *new_base, MpegEncContext *old_base)
1021 { 1064 {
1022 int i; 1065 int i;
1023 1066
1024 for (i=0; i<count; i++){ 1067 for (i=0; i<count; i++){
1025 to[i] = REBASE_PICTURE(from[i], new_base, old_base); 1068 to[i] = REBASE_PICTURE(from[i], new_base, old_base);
1026 } 1069 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 1108
1066 h->thread_context[0] = h; 1109 h->thread_context[0] = h;
1067 1110
1068 // frame_start may not be called for the next thread (if it's decoding a bottom field) 1111 // frame_start may not be called for the next thread (if it's decoding a bottom field)
1069 // so this has to be allocated here 1112 // so this has to be allocated here
1070 h->s.obmc_scratchpad = av_malloc(16*2*s->linesize + 8*2*s->uvlinesize); 1113 h->s.obmc_scratchpad = av_malloc(16*2*s->linesize + 8*2*s->uvlinesize);
1071 } 1114 }
1072 1115
1073 //extradata/NAL handling 1116 //extradata/NAL handling
1074 h->is_avc = h1->is_avc; 1117 h->is_avc = h1->is_avc;
1075 h->got_avcC = h1->got_avcC;
1076 1118
1077 //SPS/PPS 1119 //SPS/PPS
1078 copy_parameter_set((void**)h->sps_buffers, (void**)h1->sps_buffers, MAX_SPS_ COUNT, sizeof(SPS)); 1120 copy_parameter_set((void**)h->sps_buffers, (void**)h1->sps_buffers, MAX_SPS_ COUNT, sizeof(SPS));
1079 h->sps = h1->sps; 1121 h->sps = h1->sps;
1080 copy_parameter_set((void**)h->pps_buffers, (void**)h1->pps_buffers, MAX_PPS_ COUNT, sizeof(PPS)); 1122 copy_parameter_set((void**)h->pps_buffers, (void**)h1->pps_buffers, MAX_PPS_ COUNT, sizeof(PPS));
1081 h->pps = h1->pps; 1123 h->pps = h1->pps;
1082 1124
1083 //Dequantization matrices 1125 //Dequantization matrices
1084 //FIXME these are big - can they be only copied when PPS changes? 1126 //FIXME these are big - can they be only copied when PPS changes?
1085 copy_fields(h, h1, dequant4_buffer, dequant4_coeff); 1127 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
1086 1128
1087 for(i=0; i<6; i++) 1129 for(i=0; i<6; i++)
1088 h->dequant4_coeff[i] = h->dequant4_buffer[0] + (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]); 1130 h->dequant4_coeff[i] = h->dequant4_buffer[0] + (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
1089 1131
1090 for(i=0; i<2; i++) 1132 for(i=0; i<2; i++)
1091 h->dequant8_coeff[i] = h->dequant8_buffer[0] + (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]); 1133 h->dequant8_coeff[i] = h->dequant8_buffer[0] + (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
1092 1134
1093 h->dequant_coeff_pps = h1->dequant_coeff_pps; 1135 h->dequant_coeff_pps = h1->dequant_coeff_pps;
1094 1136
1095 //POC timing 1137 //POC timing
1096 copy_fields(h, h1, poc_lsb, use_weight); 1138 copy_fields(h, h1, poc_lsb, redundant_pic_count);
1097 1139
1098 //reference lists 1140 //reference lists
1099 copy_fields(h, h1, ref_count, intra_gb); 1141 copy_fields(h, h1, ref_count, intra_gb);
1142 copy_fields(h, h1, short_ref, cabac_init_idc);
1100 1143
1101 copy_picture_range(h->short_ref, h1->short_ref, 32, s, s1); 1144 copy_picture_range(h->short_ref, h1->short_ref, 32, s, s1);
1102 copy_picture_range(h->long_ref, h1->long_ref, 32, s, s1); 1145 copy_picture_range(h->long_ref, h1->long_ref, 32, s, s1);
1103 copy_picture_range(h->delayed_pic, h1->delayed_pic, MAX_DELAYED_PIC_COUNT+2, s, s1); 1146 copy_picture_range(h->delayed_pic, h1->delayed_pic, MAX_DELAYED_PIC_COUNT+2, s, s1);
1104 1147
1105 h->last_slice_type = h1->last_slice_type; 1148 h->last_slice_type = h1->last_slice_type;
1106 1149
1107 if(!s->current_picture_ptr) return 0; 1150 if(!s->current_picture_ptr) return 0;
1108 1151
1109 if(!s->dropable) { 1152 if(!s->dropable) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 AV_COPY128(top_border, src_y + 16*linesize); 1402 AV_COPY128(top_border, src_y + 16*linesize);
1360 1403
1361 if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ 1404 if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
1362 AV_COPY64(top_border+16, src_cb+8*uvlinesize); 1405 AV_COPY64(top_border+16, src_cb+8*uvlinesize);
1363 AV_COPY64(top_border+24, src_cr+8*uvlinesize); 1406 AV_COPY64(top_border+24, src_cr+8*uvlinesize);
1364 } 1407 }
1365 } 1408 }
1366 1409
1367 static inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_c b, uint8_t *src_cr, int linesize, int uvlinesize, int xchg, int simple){ 1410 static inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_c b, uint8_t *src_cr, int linesize, int uvlinesize, int xchg, int simple){
1368 MpegEncContext * const s = &h->s; 1411 MpegEncContext * const s = &h->s;
1369 int temp8, i;
1370 uint64_t temp64;
1371 int deblock_left; 1412 int deblock_left;
1372 int deblock_top; 1413 int deblock_top;
1373 int mb_xy;
1374 int top_idx = 1; 1414 int top_idx = 1;
1375 uint8_t *top_border_m1; 1415 uint8_t *top_border_m1;
1376 uint8_t *top_border; 1416 uint8_t *top_border;
1377 1417
1378 if(!simple && FRAME_MBAFF){ 1418 if(!simple && FRAME_MBAFF){
1379 if(s->mb_y&1){ 1419 if(s->mb_y&1){
1380 if(!MB_MBAFF) 1420 if(!MB_MBAFF)
1381 return; 1421 return;
1382 }else{ 1422 }else{
1383 top_idx = MB_MBAFF ? 0 : 1; 1423 top_idx = MB_MBAFF ? 0 : 1;
1384 } 1424 }
1385 } 1425 }
1386 1426
1387 if(h->deblocking_filter == 2) { 1427 if(h->deblocking_filter == 2) {
1388 mb_xy = h->mb_xy; 1428 deblock_left = h->left_type[0];
1389 deblock_left = h->slice_table[mb_xy] == h->slice_table[mb_xy - 1]; 1429 deblock_top = h->top_type;
1390 deblock_top = h->slice_table[mb_xy] == h->slice_table[h->top_mb_xy];
1391 } else { 1430 } else {
1392 deblock_left = (s->mb_x > 0); 1431 deblock_left = (s->mb_x > 0);
1393 deblock_top = (s->mb_y > !!MB_FIELD); 1432 deblock_top = (s->mb_y > !!MB_FIELD);
1394 } 1433 }
1395 1434
1396 src_y -= linesize + 1; 1435 src_y -= linesize + 1;
1397 src_cb -= uvlinesize + 1; 1436 src_cb -= uvlinesize + 1;
1398 src_cr -= uvlinesize + 1; 1437 src_cr -= uvlinesize + 1;
1399 1438
1400 top_border_m1 = h->top_borders[top_idx][s->mb_x-1]; 1439 top_border_m1 = h->top_borders[top_idx][s->mb_x-1];
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 uint8_t * const ptr= dest[(i&4)>>2] + block_offset[i ]; 1702 uint8_t * const ptr= dest[(i&4)>>2] + block_offset[i ];
1664 ff_svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, ff _h264_chroma_qp[s->qscale + 12] - 12, 2); 1703 ff_svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, ff _h264_chroma_qp[s->qscale + 12] - 12, 2);
1665 } 1704 }
1666 } 1705 }
1667 } 1706 }
1668 } 1707 }
1669 } 1708 }
1670 } 1709 }
1671 if(h->cbp || IS_INTRA(mb_type)) 1710 if(h->cbp || IS_INTRA(mb_type))
1672 s->dsp.clear_blocks(h->mb); 1711 s->dsp.clear_blocks(h->mb);
1673
1674 if(h->deblocking_filter && 0) {
1675 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, simp le);
1676 fill_filter_caches(h, mb_type); //FIXME don't fill stuff which isn't use d by filter_mb
1677 h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb _xy]);
1678 h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb _xy]);
1679 if (!simple && FRAME_MBAFF) {
1680 ff_h264_filter_mb (h, mb_x, mb_y, dest_y, dest_cb, dest_cr, line size, uvlinesize);
1681 } else {
1682 ff_h264_filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, line size, uvlinesize);
1683 }
1684 }
1685 } 1712 }
1686 1713
1687 /** 1714 /**
1688 * Process a macroblock; this case avoids checks for expensive uncommon cases. 1715 * Process a macroblock; this case avoids checks for expensive uncommon cases.
1689 */ 1716 */
1690 static void hl_decode_mb_simple(H264Context *h){ 1717 static void hl_decode_mb_simple(H264Context *h){
1691 hl_decode_mb_internal(h, 1); 1718 hl_decode_mb_internal(h, 1);
1692 } 1719 }
1693 1720
1694 /** 1721 /**
(...skipping 27 matching lines...) Expand all
1722 chroma_def = 1<<h->chroma_log2_weight_denom; 1749 chroma_def = 1<<h->chroma_log2_weight_denom;
1723 1750
1724 for(list=0; list<2; list++){ 1751 for(list=0; list<2; list++){
1725 h->luma_weight_flag[list] = 0; 1752 h->luma_weight_flag[list] = 0;
1726 h->chroma_weight_flag[list] = 0; 1753 h->chroma_weight_flag[list] = 0;
1727 for(i=0; i<h->ref_count[list]; i++){ 1754 for(i=0; i<h->ref_count[list]; i++){
1728 int luma_weight_flag, chroma_weight_flag; 1755 int luma_weight_flag, chroma_weight_flag;
1729 1756
1730 luma_weight_flag= get_bits1(&s->gb); 1757 luma_weight_flag= get_bits1(&s->gb);
1731 if(luma_weight_flag){ 1758 if(luma_weight_flag){
1732 h->luma_weight[list][i]= get_se_golomb(&s->gb); 1759 h->luma_weight[i][list][0]= get_se_golomb(&s->gb);
1733 h->luma_offset[list][i]= get_se_golomb(&s->gb); 1760 h->luma_weight[i][list][1]= get_se_golomb(&s->gb);
1734 if( h->luma_weight[list][i] != luma_def 1761 if( h->luma_weight[i][list][0] != luma_def
1735 || h->luma_offset[list][i] != 0) { 1762 || h->luma_weight[i][list][1] != 0) {
1736 h->use_weight= 1; 1763 h->use_weight= 1;
1737 h->luma_weight_flag[list]= 1; 1764 h->luma_weight_flag[list]= 1;
1738 } 1765 }
1739 }else{ 1766 }else{
1740 h->luma_weight[list][i]= luma_def; 1767 h->luma_weight[i][list][0]= luma_def;
1741 h->luma_offset[list][i]= 0; 1768 h->luma_weight[i][list][1]= 0;
1742 } 1769 }
1743 1770
1744 if(CHROMA){ 1771 if(CHROMA){
1745 chroma_weight_flag= get_bits1(&s->gb); 1772 chroma_weight_flag= get_bits1(&s->gb);
1746 if(chroma_weight_flag){ 1773 if(chroma_weight_flag){
1747 int j; 1774 int j;
1748 for(j=0; j<2; j++){ 1775 for(j=0; j<2; j++){
1749 h->chroma_weight[list][i][j]= get_se_golomb(&s->gb); 1776 h->chroma_weight[i][list][j][0]= get_se_golomb(&s->gb);
1750 h->chroma_offset[list][i][j]= get_se_golomb(&s->gb); 1777 h->chroma_weight[i][list][j][1]= get_se_golomb(&s->gb);
1751 if( h->chroma_weight[list][i][j] != chroma_def 1778 if( h->chroma_weight[i][list][j][0] != chroma_def
1752 || h->chroma_offset[list][i][j] != 0) { 1779 || h->chroma_weight[i][list][j][1] != 0) {
1753 h->use_weight_chroma= 1; 1780 h->use_weight_chroma= 1;
1754 h->chroma_weight_flag[list]= 1; 1781 h->chroma_weight_flag[list]= 1;
1755 } 1782 }
1756 } 1783 }
1757 }else{ 1784 }else{
1758 int j; 1785 int j;
1759 for(j=0; j<2; j++){ 1786 for(j=0; j<2; j++){
1760 h->chroma_weight[list][i][j]= chroma_def; 1787 h->chroma_weight[i][list][j][0]= chroma_def;
1761 h->chroma_offset[list][i][j]= 0; 1788 h->chroma_weight[i][list][j][1]= 0;
1762 } 1789 }
1763 } 1790 }
1764 } 1791 }
1765 } 1792 }
1766 if(h->slice_type_nos != FF_B_TYPE) break; 1793 if(h->slice_type_nos != FF_B_TYPE) break;
1767 } 1794 }
1768 h->use_weight= h->use_weight || h->use_weight_chroma; 1795 h->use_weight= h->use_weight || h->use_weight_chroma;
1769 return 0; 1796 return 0;
1770 } 1797 }
1771 1798
(...skipping 17 matching lines...) Expand all
1789 h->use_weight= 2; 1816 h->use_weight= 2;
1790 h->use_weight_chroma= 2; 1817 h->use_weight_chroma= 2;
1791 h->luma_log2_weight_denom= 5; 1818 h->luma_log2_weight_denom= 5;
1792 h->chroma_log2_weight_denom= 5; 1819 h->chroma_log2_weight_denom= 5;
1793 1820
1794 for(ref0=0; ref0 < h->ref_count[0]; ref0++){ 1821 for(ref0=0; ref0 < h->ref_count[0]; ref0++){
1795 int poc0 = h->ref_list[0][ref0].poc; 1822 int poc0 = h->ref_list[0][ref0].poc;
1796 for(ref1=0; ref1 < h->ref_count[1]; ref1++){ 1823 for(ref1=0; ref1 < h->ref_count[1]; ref1++){
1797 int poc1 = h->ref_list[1][ref1].poc; 1824 int poc1 = h->ref_list[1][ref1].poc;
1798 int td = av_clip(poc1 - poc0, -128, 127); 1825 int td = av_clip(poc1 - poc0, -128, 127);
1826 h->implicit_weight[ref0][ref1] = 32;
1799 if(td){ 1827 if(td){
1800 int tb = av_clip(cur_poc - poc0, -128, 127); 1828 int tb = av_clip(cur_poc - poc0, -128, 127);
1801 int tx = (16384 + (FFABS(td) >> 1)) / td; 1829 int tx = (16384 + (FFABS(td) >> 1)) / td;
1802 int dist_scale_factor = av_clip((tb*tx + 32) >> 6, -1024, 1023) >> 2; 1830 int dist_scale_factor = (tb*tx + 32) >> 8;
1803 if(dist_scale_factor < -64 || dist_scale_factor > 128) 1831 if(dist_scale_factor >= -64 && dist_scale_factor <= 128)
1804 h->implicit_weight[ref0][ref1] = 32;
1805 else
1806 h->implicit_weight[ref0][ref1] = 64 - dist_scale_factor; 1832 h->implicit_weight[ref0][ref1] = 64 - dist_scale_factor;
1807 }else 1833 }
1808 h->implicit_weight[ref0][ref1] = 32;
1809 } 1834 }
1810 } 1835 }
1811 } 1836 }
1812 1837
1813 /** 1838 /**
1814 * instantaneous decoder refresh. 1839 * instantaneous decoder refresh.
1815 */ 1840 */
1816 static void idr(H264Context *h){ 1841 static void idr(H264Context *h){
1817 ff_h264_remove_all_refs(h); 1842 ff_h264_remove_all_refs(h);
1818 h->prev_frame_num= 0; 1843 h->prev_frame_num= 0;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 2124
2100 slice_type= golomb_to_pict_type[ slice_type ]; 2125 slice_type= golomb_to_pict_type[ slice_type ];
2101 if (slice_type == FF_I_TYPE 2126 if (slice_type == FF_I_TYPE
2102 || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) { 2127 || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) {
2103 default_ref_list_done = 1; 2128 default_ref_list_done = 1;
2104 } 2129 }
2105 h->slice_type= slice_type; 2130 h->slice_type= slice_type;
2106 h->slice_type_nos= slice_type & 3; 2131 h->slice_type_nos= slice_type & 3;
2107 2132
2108 s->pict_type= h->slice_type; // to make a few old functions happy, it's wron g though 2133 s->pict_type= h->slice_type; // to make a few old functions happy, it's wron g though
2109 if (s->pict_type == FF_B_TYPE && s0->last_picture_ptr == NULL) {
2110 av_log(h->s.avctx, AV_LOG_ERROR,
2111 "B picture before any references, skipping\n");
2112 return -1;
2113 }
2114 2134
2115 pps_id= get_ue_golomb(&s->gb); 2135 pps_id= get_ue_golomb(&s->gb);
2116 if(pps_id>=MAX_PPS_COUNT){ 2136 if(pps_id>=MAX_PPS_COUNT){
2117 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); 2137 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n");
2118 return -1; 2138 return -1;
2119 } 2139 }
2120 if(!h0->pps_buffers[pps_id]) { 2140 if(!h0->pps_buffers[pps_id]) {
2121 av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\n", pps _id); 2141 av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\n", pps _id);
2122 return -1; 2142 return -1;
2123 } 2143 }
2124 h->pps= *h0->pps_buffers[pps_id]; 2144 h->pps= *h0->pps_buffers[pps_id];
2125 2145
2126 if(!h0->sps_buffers[h->pps.sps_id]) { 2146 if(!h0->sps_buffers[h->pps.sps_id]) {
2127 av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\n", h-> pps.sps_id); 2147 av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\n", h-> pps.sps_id);
2128 return -1; 2148 return -1;
2129 } 2149 }
2130 h->sps = *h0->sps_buffers[h->pps.sps_id]; 2150 h->sps = *h0->sps_buffers[h->pps.sps_id];
2131 2151
2132 if(h == h0 && h->dequant_coeff_pps != pps_id){ 2152 if(h == h0 && h->dequant_coeff_pps != pps_id){
2133 h->dequant_coeff_pps = pps_id; 2153 h->dequant_coeff_pps = pps_id;
2134 init_dequant_tables(h); 2154 init_dequant_tables(h);
2135 } 2155 }
2136 2156
2137 s->mb_width= h->sps.mb_width; 2157 s->mb_width= h->sps.mb_width;
2138 s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); 2158 s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);
2139 2159
2140 h->b_stride= s->mb_width*4; 2160 h->b_stride= s->mb_width*4;
2141 h->b8_stride= s->mb_width*2;
2142 2161
2143 s->width = 16*s->mb_width - 2*FFMIN(h->sps.crop_right, 7); 2162 s->width = 16*s->mb_width - 2*FFMIN(h->sps.crop_right, 7);
2144 if(h->sps.frame_mbs_only_flag) 2163 if(h->sps.frame_mbs_only_flag)
2145 s->height= 16*s->mb_height - 2*FFMIN(h->sps.crop_bottom, 7); 2164 s->height= 16*s->mb_height - 2*FFMIN(h->sps.crop_bottom, 7);
2146 else 2165 else
2147 s->height= 16*s->mb_height - 4*FFMIN(h->sps.crop_bottom, 3); 2166 s->height= 16*s->mb_height - 4*FFMIN(h->sps.crop_bottom, 3);
2148 2167
2149 if (s->context_initialized 2168 if (s->context_initialized
2150 && ( s->width != s->avctx->width || s->height != s->avctx->height)) { 2169 && ( s->width != s->avctx->width || s->height != s->avctx->height)) {
2151 if(h != h0 || s->avctx->active_thread_type&FF_THREAD_FRAME) { 2170 if(h != h0 || s->avctx->active_thread_type&FF_THREAD_FRAME) {
(...skipping 16 matching lines...) Expand all
2168 if(h->sps.video_signal_type_present_flag){ 2187 if(h->sps.video_signal_type_present_flag){
2169 s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL _RANGE_MPEG; 2188 s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL _RANGE_MPEG;
2170 if(h->sps.colour_description_present_flag){ 2189 if(h->sps.colour_description_present_flag){
2171 s->avctx->color_primaries = h->sps.color_primaries; 2190 s->avctx->color_primaries = h->sps.color_primaries;
2172 s->avctx->color_trc = h->sps.color_trc; 2191 s->avctx->color_trc = h->sps.color_trc;
2173 s->avctx->colorspace = h->sps.colorspace; 2192 s->avctx->colorspace = h->sps.colorspace;
2174 } 2193 }
2175 } 2194 }
2176 2195
2177 if(h->sps.timing_info_present_flag){ 2196 if(h->sps.timing_info_present_flag){
2178 s->avctx->time_base= (AVRational){h->sps.num_units_in_tick, h->sps.t ime_scale}; 2197 int64_t den= h->sps.time_scale;
2179 if(h->x264_build > 0 && h->x264_build < 44) 2198 if(h->x264_build < 44U)
2180 s->avctx->time_base.den *= 2; 2199 den *= 2;
2181 av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den, 2200 av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,
2182 s->avctx->time_base.num, s->avctx->time_base.den, 1<<30); 2201 h->sps.num_units_in_tick, den, 1<<30);
2183 } 2202 }
2184 s->avctx->pix_fmt = s->avctx->get_format(s->avctx, s->avctx->codec->pix_ fmts); 2203 s->avctx->pix_fmt = s->avctx->get_format(s->avctx, s->avctx->codec->pix_ fmts);
2185 s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_f mt); 2204 s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_f mt);
2186 2205
2187 if (MPV_common_init(s) < 0) 2206 if (MPV_common_init(s) < 0)
2188 return -1; 2207 return -1;
2189 s->first_field = 0; 2208 s->first_field = 0;
2190 h->prev_interlaced_frame = 1; 2209 h->prev_interlaced_frame = 1;
2191 2210
2192 init_scan_tables(h); 2211 init_scan_tables(h);
2193 ff_h264_alloc_tables(h); 2212 ff_h264_alloc_tables(h);
2194 2213
2195 if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) { 2214 if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) {
2196 if (context_init(h) < 0) 2215 if (context_init(h) < 0)
2197 return -1; 2216 return -1;
2198 } else { 2217 } else {
2199 for(i = 1; i < s->avctx->thread_count; i++) { 2218 for(i = 1; i < s->avctx->thread_count; i++) {
2200 H264Context *c; 2219 H264Context *c;
2201 c = h->thread_context[i] = av_malloc(sizeof(H264Context)); 2220 c = h->thread_context[i] = av_malloc(sizeof(H264Context));
2202 memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); 2221 memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));
2203 memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext )); 2222 memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext ));
2204 c->sps = h->sps; 2223 c->sps = h->sps;
2205 c->pps = h->pps; 2224 c->pps = h->pps;
2206 init_scan_tables(c); 2225 init_scan_tables(c);
2207 clone_tables(c, h); 2226 clone_tables(c, h, i);
2208 } 2227 }
2209 2228
2210 for(i = 0; i < s->avctx->thread_count; i++) 2229 for(i = 0; i < s->avctx->thread_count; i++)
2211 if(context_init(h->thread_context[i]) < 0) 2230 if(context_init(h->thread_context[i]) < 0)
2212 return -1; 2231 return -1;
2213 } 2232 }
2214 } 2233 }
2215 2234
2216 h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); 2235 h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);
2217 2236
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 if(h->slice_type_nos==FF_B_TYPE){ 2407 if(h->slice_type_nos==FF_B_TYPE){
2389 s->next_picture_ptr= &h->ref_list[1][0]; 2408 s->next_picture_ptr= &h->ref_list[1][0];
2390 ff_copy_picture(&s->next_picture, s->next_picture_ptr); 2409 ff_copy_picture(&s->next_picture, s->next_picture_ptr);
2391 } 2410 }
2392 2411
2393 */ 2412 */
2394 2413
2395 if( (h->pps.weighted_pred && h->slice_type_nos == FF_P_TYPE ) 2414 if( (h->pps.weighted_pred && h->slice_type_nos == FF_P_TYPE )
2396 || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) ) 2415 || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) )
2397 pred_weight_table(h); 2416 pred_weight_table(h);
2398 else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE) 2417 else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){
2399 implicit_weight_table(h); 2418 implicit_weight_table(h);
2400 else { 2419 }else {
2401 h->use_weight = 0; 2420 h->use_weight = 0;
2402 for (i = 0; i < 2; i++) { 2421 for (i = 0; i < 2; i++) {
2403 h->luma_weight_flag[i] = 0; 2422 h->luma_weight_flag[i] = 0;
2404 h->chroma_weight_flag[i] = 0; 2423 h->chroma_weight_flag[i] = 0;
2405 } 2424 }
2406 } 2425 }
2407 2426
2408 if(h->nal_ref_idc) 2427 if(h->nal_ref_idc)
2409 ff_h264_decode_ref_pic_marking(h0, &s->gb); 2428 ff_h264_decode_ref_pic_marking(h0, &s->gb);
2410 2429
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 static void loop_filter(H264Context *h){ 2592 static void loop_filter(H264Context *h){
2574 MpegEncContext * const s = &h->s; 2593 MpegEncContext * const s = &h->s;
2575 uint8_t *dest_y, *dest_cb, *dest_cr; 2594 uint8_t *dest_y, *dest_cb, *dest_cr;
2576 int linesize, uvlinesize, mb_x, mb_y; 2595 int linesize, uvlinesize, mb_x, mb_y;
2577 const int end_mb_y= s->mb_y + FRAME_MBAFF; 2596 const int end_mb_y= s->mb_y + FRAME_MBAFF;
2578 const int old_slice_type= h->slice_type; 2597 const int old_slice_type= h->slice_type;
2579 2598
2580 if(h->deblocking_filter) { 2599 if(h->deblocking_filter) {
2581 for(mb_x= 0; mb_x<s->mb_width; mb_x++){ 2600 for(mb_x= 0; mb_x<s->mb_width; mb_x++){
2582 for(mb_y=end_mb_y - FRAME_MBAFF; mb_y<= end_mb_y; mb_y++){ 2601 for(mb_y=end_mb_y - FRAME_MBAFF; mb_y<= end_mb_y; mb_y++){
2583 int list, mb_xy, mb_type; 2602 int mb_xy, mb_type;
2584 mb_xy = h->mb_xy = mb_x + mb_y*s->mb_stride; 2603 mb_xy = h->mb_xy = mb_x + mb_y*s->mb_stride;
2585 h->slice_num= h->slice_table[mb_xy]; 2604 h->slice_num= h->slice_table[mb_xy];
2586 mb_type= s->current_picture.mb_type[mb_xy]; 2605 mb_type= s->current_picture.mb_type[mb_xy];
2587 h->list_count= h->list_counts[mb_xy]; 2606 h->list_count= h->list_counts[mb_xy];
2588 2607
2589 if(FRAME_MBAFF) 2608 if(FRAME_MBAFF)
2590 h->mb_mbaff = h->mb_field_decoding_flag = !!IS_INTERLACED(mb _type); 2609 h->mb_mbaff = h->mb_field_decoding_flag = !!IS_INTERLACED(mb _type);
2591 2610
2592 s->mb_x= mb_x; 2611 s->mb_x= mb_x;
2593 s->mb_y= mb_y; 2612 s->mb_y= mb_y;
(...skipping 24 matching lines...) Expand all
2618 ff_h264_filter_mb (h, mb_x, mb_y, dest_y, dest_cb, dest_ cr, linesize, uvlinesize); 2637 ff_h264_filter_mb (h, mb_x, mb_y, dest_y, dest_cb, dest_ cr, linesize, uvlinesize);
2619 } else { 2638 } else {
2620 ff_h264_filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_ cr, linesize, uvlinesize); 2639 ff_h264_filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_ cr, linesize, uvlinesize);
2621 } 2640 }
2622 } 2641 }
2623 } 2642 }
2624 } 2643 }
2625 h->slice_type= old_slice_type; 2644 h->slice_type= old_slice_type;
2626 s->mb_x= 0; 2645 s->mb_x= 0;
2627 s->mb_y= end_mb_y - FRAME_MBAFF; 2646 s->mb_y= end_mb_y - FRAME_MBAFF;
2647 h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);
2648 h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);
2649 }
2650
2651 static void predict_field_decoding_flag(H264Context *h){
2652 MpegEncContext * const s = &h->s;
2653 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
2654 int mb_type = (h->slice_table[mb_xy-1] == h->slice_num)
2655 ? s->current_picture.mb_type[mb_xy-1]
2656 : (h->slice_table[mb_xy-s->mb_stride] == h->slice_num)
2657 ? s->current_picture.mb_type[mb_xy-s->mb_stride]
2658 : 0;
2659 h->mb_mbaff = h->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0;
2628 } 2660 }
2629 2661
2630 /** 2662 /**
2631 * Draw edges and report progress for the last MB row. 2663 * Draw edges and report progress for the last MB row.
2632 */ 2664 */
2633 static void decode_finish_row(H264Context *h){ 2665 static void decode_finish_row(H264Context *h){
2634 MpegEncContext * const s = &h->s; 2666 MpegEncContext * const s = &h->s;
2635 int top = 16*(s->mb_y >> FIELD_PICTURE); 2667 int top = 16*(s->mb_y >> FIELD_PICTURE);
2636 int height = 16 << FRAME_MBAFF; 2668 int height = 16 << FRAME_MBAFF;
2637 int deblock_border = (16 + 4) << FRAME_MBAFF; 2669 int deblock_border = (16 + 4) << FRAME_MBAFF;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2694 if( ret >= 0 && FRAME_MBAFF ) { //FIXME optimal? or let mb_decode de code 16x32 ? 2726 if( ret >= 0 && FRAME_MBAFF ) { //FIXME optimal? or let mb_decode de code 16x32 ?
2695 s->mb_y++; 2727 s->mb_y++;
2696 2728
2697 ret = ff_h264_decode_mb_cabac(h); 2729 ret = ff_h264_decode_mb_cabac(h);
2698 2730
2699 if(ret>=0) ff_h264_hl_decode_mb(h); 2731 if(ret>=0) ff_h264_hl_decode_mb(h);
2700 s->mb_y--; 2732 s->mb_y--;
2701 } 2733 }
2702 eos = get_cabac_terminate( &h->cabac ); 2734 eos = get_cabac_terminate( &h->cabac );
2703 2735
2736 if((s->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2){
2737 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s- >mb_y, (AC_END|DC_END|MV_END)&part_mask);
2738 return 0;
2739 }
2704 if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) { 2740 if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) {
2705 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytes tream); 2741 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytes tream);
2706 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->m b_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); 2742 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->m b_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
2707 return -1; 2743 return -1;
2708 } 2744 }
2709 2745
2710 if( ++s->mb_x >= s->mb_width ) { 2746 if( ++s->mb_x >= s->mb_width ) {
2711 s->mb_x = 0; 2747 s->mb_x = 0;
2712 loop_filter(h); 2748 loop_filter(h);
2713 decode_finish_row(h); 2749 decode_finish_row(h);
2714 ++s->mb_y; 2750 ++s->mb_y;
2715 if(FIELD_OR_MBAFF_PICTURE) { 2751 if(FIELD_OR_MBAFF_PICTURE) {
2716 ++s->mb_y; 2752 ++s->mb_y;
2753 if(FRAME_MBAFF && s->mb_y < s->mb_height)
2754 predict_field_decoding_flag(h);
2717 } 2755 }
2718 } 2756 }
2719 2757
2720 if( eos || s->mb_y >= s->mb_height ) { 2758 if( eos || s->mb_y >= s->mb_height ) {
2721 tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s ->gb.size_in_bits); 2759 tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s ->gb.size_in_bits);
2722 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s- >mb_y, (AC_END|DC_END|MV_END)&part_mask); 2760 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s- >mb_y, (AC_END|DC_END|MV_END)&part_mask);
2723 return 0; 2761 return 0;
2724 } 2762 }
2725 } 2763 }
2726 2764
(...skipping 18 matching lines...) Expand all
2745 return -1; 2783 return -1;
2746 } 2784 }
2747 2785
2748 if(++s->mb_x >= s->mb_width){ 2786 if(++s->mb_x >= s->mb_width){
2749 s->mb_x=0; 2787 s->mb_x=0;
2750 loop_filter(h); 2788 loop_filter(h);
2751 decode_finish_row(h); 2789 decode_finish_row(h);
2752 ++s->mb_y; 2790 ++s->mb_y;
2753 if(FIELD_OR_MBAFF_PICTURE) { 2791 if(FIELD_OR_MBAFF_PICTURE) {
2754 ++s->mb_y; 2792 ++s->mb_y;
2793 if(FRAME_MBAFF && s->mb_y < s->mb_height)
2794 predict_field_decoding_flag(h);
2755 } 2795 }
2756 if(s->mb_y >= s->mb_height){ 2796 if(s->mb_y >= s->mb_height){
2757 tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb ), s->gb.size_in_bits); 2797 tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb ), s->gb.size_in_bits);
2758 2798
2759 if(get_bits_count(&s->gb) == s->gb.size_in_bits ) { 2799 if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {
2760 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb _x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); 2800 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb _x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
2761 2801
2762 return 0; 2802 return 0;
2763 }else{ 2803 }else{
2764 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb _x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); 2804 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb _x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2929 buf_index+=3; 2969 buf_index+=3;
2930 if(buf_index >= next_avc) continue; 2970 if(buf_index >= next_avc) continue;
2931 } 2971 }
2932 2972
2933 hx = h->thread_context[context_count]; 2973 hx = h->thread_context[context_count];
2934 2974
2935 ptr= ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed, nex t_avc - buf_index); 2975 ptr= ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed, nex t_avc - buf_index);
2936 if (ptr==NULL || dst_length < 0){ 2976 if (ptr==NULL || dst_length < 0){
2937 return -1; 2977 return -1;
2938 } 2978 }
2979 i= buf_index + consumed;
2980 if((s->workaround_bugs & FF_BUG_AUTODETECT) && i+3<next_avc &&
2981 buf[i]==0x00 && buf[i+1]==0x00 && buf[i+2]==0x01 && buf[i+3]==0xE0)
2982 s->workaround_bugs |= FF_BUG_TRUNCATED;
2983
2984 if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){
2939 while(ptr[dst_length - 1] == 0 && dst_length > 0) 2985 while(ptr[dst_length - 1] == 0 && dst_length > 0)
2940 dst_length--; 2986 dst_length--;
2987 }
2941 bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_traili ng(h, ptr + dst_length - 1)); 2988 bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_traili ng(h, ptr + dst_length - 1));
2942 2989
2943 if(s->avctx->debug&FF_DEBUG_STARTCODE){ 2990 if(s->avctx->debug&FF_DEBUG_STARTCODE){
2944 av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", hx-> nal_unit_type, buf_index, buf_size, dst_length); 2991 av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", hx-> nal_unit_type, buf_index, buf_size, dst_length);
2945 } 2992 }
2946 2993
2947 if (h->is_avc && (nalsize != consumed) && nalsize){ 2994 if (h->is_avc && (nalsize != consumed) && nalsize){
2948 av_log(h->s.avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instea d of %d\n", consumed, nalsize); 2995 av_log(h->s.avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instea d of %d\n", consumed, nalsize);
2949 } 2996 }
2950 2997
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
3136 h->delayed_pic[i] = h->delayed_pic[i+1]; 3183 h->delayed_pic[i] = h->delayed_pic[i+1];
3137 3184
3138 if(out){ 3185 if(out){
3139 *data_size = sizeof(AVFrame); 3186 *data_size = sizeof(AVFrame);
3140 *pict= *(AVFrame*)out; 3187 *pict= *(AVFrame*)out;
3141 } 3188 }
3142 3189
3143 return 0; 3190 return 0;
3144 } 3191 }
3145 3192
3146 if(h->is_avc && !h->got_avcC) {
3147 int i, cnt, nalsize;
3148 unsigned char *p = avctx->extradata;
3149 if(avctx->extradata_size < 7) {
3150 av_log(avctx, AV_LOG_ERROR, "avcC too short\n");
3151 return -1;
3152 }
3153 if(*p != 1) {
3154 av_log(avctx, AV_LOG_ERROR, "Unknown avcC version %d\n", *p);
3155 return -1;
3156 }
3157 /* sps and pps in the avcC always have length coded with 2 bytes,
3158 so put a fake nal_length_size = 2 while parsing them */
3159 h->nal_length_size = 2;
3160 // Decode sps from avcC
3161 cnt = *(p+5) & 0x1f; // Number of sps
3162 p += 6;
3163 for (i = 0; i < cnt; i++) {
3164 nalsize = AV_RB16(p) + 2;
3165 if(decode_nal_units(h, p, nalsize) < 0) {
3166 av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n" , i);
3167 return -1;
3168 }
3169 p += nalsize;
3170 }
3171 // Decode pps from avcC
3172 cnt = *(p++); // Number of pps
3173 for (i = 0; i < cnt; i++) {
3174 nalsize = AV_RB16(p) + 2;
3175 if(decode_nal_units(h, p, nalsize) != nalsize) {
3176 av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n" , i);
3177 return -1;
3178 }
3179 p += nalsize;
3180 }
3181 // Now store right nal length size, that will be use to parse all other nals
3182 h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1;
3183 // Do not reparse avcC
3184 h->got_avcC = 1;
3185 }
3186
3187 if(!h->got_avcC && !h->is_avc && s->avctx->extradata_size){
3188 if(decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) < 0)
3189 return -1;
3190 h->got_avcC = 1;
3191 }
3192
3193 buf_index=decode_nal_units(h, buf, buf_size); 3193 buf_index=decode_nal_units(h, buf, buf_size);
3194 if(buf_index < 0) 3194 if(buf_index < 0)
3195 return -1; 3195 return -1;
3196 3196
3197 if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){ 3197 if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){
3198 if (avctx->skip_frame >= AVDISCARD_NONREF || s->hurry_up) return 0; 3198 if (avctx->skip_frame >= AVDISCARD_NONREF || s->hurry_up) return 0;
3199 av_log(avctx, AV_LOG_ERROR, "no frame!\n"); 3199 av_log(avctx, AV_LOG_ERROR, "no frame!\n");
3200 return -1; 3200 return -1;
3201 } 3201 }
3202 3202
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
3471 ff_h264_decode_init, 3471 ff_h264_decode_init,
3472 NULL, 3472 NULL,
3473 ff_h264_decode_end, 3473 ff_h264_decode_end,
3474 decode_frame, 3474 decode_frame,
3475 CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, 3475 CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
3476 .flush= flush_dpb, 3476 .flush= flush_dpb,
3477 .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"), 3477 .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
3478 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_H264, PIX_FMT_NONE}, 3478 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_H264, PIX_FMT_NONE},
3479 }; 3479 };
3480 #endif 3480 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698