comparison h264.c @ 11330:e8e5dbbbf9c4 libavcodec

Fix a bunch of bugs ive introduced recently that broke threaded decoding. might also fix issue1788
author michael
date Tue, 02 Mar 2010 02:24:37 +0000
parents cd6fa05ffeb0
children 444401d150d6
comparison
equal deleted inserted replaced
11329:fb56293a501a 11330:e8e5dbbbf9c4
742 742
743 743
744 int ff_h264_alloc_tables(H264Context *h){ 744 int ff_h264_alloc_tables(H264Context *h){
745 MpegEncContext * const s = &h->s; 745 MpegEncContext * const s = &h->s;
746 const int big_mb_num= s->mb_stride * (s->mb_height+1); 746 const int big_mb_num= s->mb_stride * (s->mb_height+1);
747 const int row_mb_num= 2*s->mb_stride*s->avctx->thread_count;
747 int x,y; 748 int x,y;
748 749
749 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t), fail) 750 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->intra4x4_pred_mode, row_mb_num * 8 * sizeof(uint8_t), fail)
750 751
751 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count , big_mb_num * 32 * sizeof(uint8_t), fail) 752 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count , big_mb_num * 32 * sizeof(uint8_t), fail)
752 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base), fail) 753 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base), fail)
753 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->cbp_table, big_mb_num * sizeof(uint16_t), fail) 754 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->cbp_table, big_mb_num * sizeof(uint16_t), fail)
754 755
755 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t), fail) 756 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t), fail)
756 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[0], 16*big_mb_num * sizeof(uint8_t), fail); 757 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[0], 16*row_mb_num * sizeof(uint8_t), fail);
757 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[1], 16*big_mb_num * sizeof(uint8_t), fail); 758 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[1], 16*row_mb_num * sizeof(uint8_t), fail);
758 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->direct_table, 4*big_mb_num * sizeof(uint8_t) , fail); 759 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->direct_table, 4*big_mb_num * sizeof(uint8_t) , fail);
759 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->list_counts, big_mb_num * sizeof(uint8_t), fail) 760 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->list_counts, big_mb_num * sizeof(uint8_t), fail)
760 761
761 memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base)); 762 memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base));
762 h->slice_table= h->slice_table_base + s->mb_stride*2 + 1; 763 h->slice_table= h->slice_table_base + s->mb_stride*2 + 1;
785 } 786 }
786 787
787 /** 788 /**
788 * Mimic alloc_tables(), but for every context thread. 789 * Mimic alloc_tables(), but for every context thread.
789 */ 790 */
790 static void clone_tables(H264Context *dst, H264Context *src){ 791 static void clone_tables(H264Context *dst, H264Context *src, int i){
791 dst->intra4x4_pred_mode = src->intra4x4_pred_mode; 792 MpegEncContext * const s = &src->s;
793 dst->intra4x4_pred_mode = src->intra4x4_pred_mode + i*8*2*s->mb_stride;
792 dst->non_zero_count = src->non_zero_count; 794 dst->non_zero_count = src->non_zero_count;
793 dst->slice_table = src->slice_table; 795 dst->slice_table = src->slice_table;
794 dst->cbp_table = src->cbp_table; 796 dst->cbp_table = src->cbp_table;
795 dst->mb2b_xy = src->mb2b_xy; 797 dst->mb2b_xy = src->mb2b_xy;
796 dst->mb2br_xy = src->mb2br_xy; 798 dst->mb2br_xy = src->mb2br_xy;
797 dst->chroma_pred_mode_table = src->chroma_pred_mode_table; 799 dst->chroma_pred_mode_table = src->chroma_pred_mode_table;
798 dst->mvd_table[0] = src->mvd_table[0]; 800 dst->mvd_table[0] = src->mvd_table[0] + i*8*2*s->mb_stride;
799 dst->mvd_table[1] = src->mvd_table[1]; 801 dst->mvd_table[1] = src->mvd_table[1] + i*8*2*s->mb_stride;
800 dst->direct_table = src->direct_table; 802 dst->direct_table = src->direct_table;
801 dst->list_counts = src->list_counts; 803 dst->list_counts = src->list_counts;
802 804
803 dst->s.obmc_scratchpad = NULL; 805 dst->s.obmc_scratchpad = NULL;
804 ff_h264_pred_init(&dst->hpc, src->s.codec_id); 806 ff_h264_pred_init(&dst->hpc, src->s.codec_id);
809 * Allocate buffers which are not shared amongst multiple threads. 811 * Allocate buffers which are not shared amongst multiple threads.
810 */ 812 */
811 static int context_init(H264Context *h){ 813 static int context_init(H264Context *h){
812 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail) 814 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail)
813 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail) 815 FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail)
816
817 h->ref_cache[0][scan8[5 ]+1] = h->ref_cache[0][scan8[7 ]+1] = h->ref_cache[0][scan8[13]+1] =
818 h->ref_cache[1][scan8[5 ]+1] = h->ref_cache[1][scan8[7 ]+1] = h->ref_cache[1][scan8[13]+1] = PART_NOT_AVAILABLE;
814 819
815 return 0; 820 return 0;
816 fail: 821 fail:
817 return -1; // free_tables will clean up for us 822 return -1; // free_tables will clean up for us
818 } 823 }
869 if(avctx->ticks_per_frame == 1){ 874 if(avctx->ticks_per_frame == 1){
870 s->avctx->time_base.den *=2; 875 s->avctx->time_base.den *=2;
871 } 876 }
872 avctx->ticks_per_frame = 2; 877 avctx->ticks_per_frame = 2;
873 } 878 }
874
875 h->ref_cache[0][scan8[5 ]+1] = h->ref_cache[0][scan8[7 ]+1] = h->ref_cache[0][scan8[13]+1] =
876 h->ref_cache[1][scan8[5 ]+1] = h->ref_cache[1][scan8[7 ]+1] = h->ref_cache[1][scan8[13]+1] = PART_NOT_AVAILABLE;
877
878 879
879 if(avctx->extradata_size > 0 && avctx->extradata && *(char *)avctx->extradata == 1){ 880 if(avctx->extradata_size > 0 && avctx->extradata && *(char *)avctx->extradata == 1){
880 int i, cnt, nalsize; 881 int i, cnt, nalsize;
881 unsigned char *p = avctx->extradata; 882 unsigned char *p = avctx->extradata;
882 883
1824 memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); 1825 memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));
1825 memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext)); 1826 memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));
1826 c->sps = h->sps; 1827 c->sps = h->sps;
1827 c->pps = h->pps; 1828 c->pps = h->pps;
1828 init_scan_tables(c); 1829 init_scan_tables(c);
1829 clone_tables(c, h); 1830 clone_tables(c, h, i);
1830 } 1831 }
1831 1832
1832 for(i = 0; i < s->avctx->thread_count; i++) 1833 for(i = 0; i < s->avctx->thread_count; i++)
1833 if(context_init(h->thread_context[i]) < 0) 1834 if(context_init(h->thread_context[i]) < 0)
1834 return -1; 1835 return -1;