History

Merge remote-tracking branch 'qatar/master'

* qatar/master: configure: Check for CommandLineToArgvW vc1dec: Do not use random pred_flag if motion vector data is skipped vp8: Enclose pthread function calls in ifdefs snow: refactor code to work around a compiler bug in MSVC. vp8: Include the thread headers before using the pthread types configure: Check for getaddrinfo in ws2tcpip.h, too vp8: implement sliced threading vp8: move data from VP8Context->VP8Macroblock vp8: refactor decoding a single mb_row doc: update api changes with the right commit hashes mem: introduce av_malloc_array and av_mallocz_array Conflicts: configure doc/APIchanges libavcodec/vp8.c libavutil/mem.h libavutil/version.h

Michael Niedermayer committed 14 years ago

Commit fbe02452 parents 9a1963f b4675d08 files · +527 −241Browse files

Unified · Split

8 files
  1. configure +4 −1
  2. doc/APIchanges +9 −6
  3. libavcodec/snowenc.c +9 −1
  4. libavcodec/vc1dec.c +1 −1
  5. libavcodec/vp8.c +418 −202
  6. libavcodec/vp8.h +50 −27
  7. libavutil/mem.h +35 −2
  8. libavutil/version.h +1 −1
configure+4−1
@@ -1190,6 +1190,7 @@ HAVE_LIST=" · 1189 unmodified lines
11901190 clock_gettime
11911191 closesocket
11921192 cmov
1193+ CommandLineToArgvW
11931194 cpuid
11941195 dcbzl
11951196 dev_bktr_ioctl_bt848_h
@@ -3182,7 +3183,8 @@ check_func nanosleep || { check_func nanosleep -lrt && add_extralibs -lrt; } · 1986 unmodified lines
31823183 check_func clock_gettime || { check_func clock_gettime -lrt && add_extralibs -lrt; }
31833184 check_func fcntl
31843185 check_func fork
3185−check_func getaddrinfo $network_extralibs
3186+check_func getaddrinfo $network_extralibs ||
3187+ check_func_headers ws2tcpip.h getaddrinfo $network_extralibs
31863188 check_func gethrtime
31873189 check_func getopt
31883190 check_func getrusage
@@ -3207,6 +3209,7 @@ check_func_headers conio.h kbhit · 18 unmodified lines
32073209 check_func_headers windows.h PeekNamedPipe
32083210 check_func_headers io.h setmode
32093211 check_func_headers lzo/lzo1x.h lzo1x_999_compress
3212+check_lib2 "windows.h shellapi.h" CommandLineToArgvW -lshell32
32103213 check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
32113214 check_func_headers windows.h GetProcessAffinityMask
32123215 check_func_headers windows.h GetProcessTimes
doc/APIchanges+9−6
@@ -57,29 +57,32 @@ API changes, most recent first: · 56 unmodified lines
5757 2012-03-26 - a67d9cf - lavfi 2.66.100
5858 Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions.
5959
60−2012-06-22 - xxxxxxx - lavu 51.34.0
60+2012-07-10 - 5fade8a - lavu 51.37.0
61+ Add av_malloc_array() and av_mallocz_array()
62+
63+2012-06-22 - d3d3a32 - lavu 51.34.0
6164 Add av_usleep()
6265
6366 2012-06-20 - ae0a301 - lavu 51.33.0
6467 Move av_gettime() to libavutil, add libavutil/time.h
6568
66−2012-xx-xx - xxxxxxx - lavr 0.0.3
69+2012-06-09 - 3971be0 - lavr 0.0.3
6770 Add a parameter to avresample_build_matrix() for Dolby/DPLII downmixing.
6871
69−2012-xx-xx - xxxxxxx - lavfi 2.23.0 - avfilter.h
72+2012-06-12 - 9baeff9 - lavfi 2.23.0 - avfilter.h
7073 Add AVFilterContext.nb_inputs/outputs. Deprecate
7174 AVFilterContext.input/output_count.
7275
73−2012-xx-xx - xxxxxxx - lavfi 2.22.0 - avfilter.h
76+2012-06-12 - 84b9fbe - lavfi 2.22.0 - avfilter.h
7477 Add avfilter_pad_get_type() and avfilter_pad_get_name(). Those
7578 should now be used instead of accessing AVFilterPad members
7679 directly.
7780
78−2012-xx-xx - xxxxxxx - lavu 51.32.0 - audioconvert.h
81+2012-06-12 - b0f0dfc - lavu 51.32.0 - audioconvert.h
7982 Add av_get_channel_layout_channel_index(), av_get_channel_name()
8083 and av_channel_layout_extract_channel().
8184
82−2012-05-25 - e0e0793 - lavu 51.31.0 - opt.h
85+2012-05-25 - 154486f - lavu 51.31.0 - opt.h
8386 Add av_opt_set_bin()
8487
8588 2012-05-15 - lavfi 2.17.0
libavcodec/snowenc.c+9−1
@@ -1013,10 +1013,18 @@ static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y · 1012 unmodified lines
10131013 static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){
10141014 const int b_stride= s->b_width << s->block_max_depth;
10151015 BlockNode *block= &s->block[mb_x + mb_y * b_stride];
1016− BlockNode backup[4]= {block[0], block[1], block[b_stride], block[b_stride+1]};
1016+ BlockNode backup[4];
10171017 unsigned value;
10181018 int rd, index;
10191019
1020+ /* We don't initialize backup[] during variable declaration, because
1021+ * that fails to compile on MSVC: "cannot convert from 'BlockNode' to
1022+ * 'int16_t'". */
1023+ backup[0] = block[0];
1024+ backup[1] = block[1];
1025+ backup[2] = block[b_stride];
1026+ backup[3] = block[b_stride + 1];
1027+
10201028 assert(mb_x>=0 && mb_y>=0);
10211029 assert(mb_x<b_stride);
10221030 assert(((mb_x|mb_y)&1) == 0);
libavcodec/vc1dec.c+1−1
@@ -3956,7 +3956,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v) · 3955 unmodified lines
39563956 s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
39573957 for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0;
39583958 if (idx_mbmode <= 5) { // 1-MV
3959− dmv_x = dmv_y = 0;
3959+ dmv_x = dmv_y = pred_flag = 0;
39603960 if (idx_mbmode & 1) {
39613961 get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
39623962 }
libavcodec/vp8.c+418−202
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 * Copyright (C) 2010 David Conrad
55 * Copyright (C) 2010 Ronald S. Bultje
66 * Copyright (C) 2010 Jason Garrett-Glaser
7+ * Copyright (C) 2012 Daniel Kang
78 *
89 * This file is part of FFmpeg.
910 *
@@ -36,11 +37,16 @@ · 26 unmodified lines
3637
3738 static void free_buffers(VP8Context *s)
3839 {
40+ int i;
41+ if (s->thread_data)
42+ for (i = 0; i < MAX_THREADS; i++) {
43+ av_freep(&s->thread_data[i].filter_strength);
44+ av_freep(&s->thread_data[i].edge_emu_buffer);
45+ }
46+ av_freep(&s->thread_data);
3947 av_freep(&s->macroblocks_base);
40− av_freep(&s->filter_strength);
4148 av_freep(&s->intra4x4_pred_mode_top);
4249 av_freep(&s->top_nnz);
43− av_freep(&s->edge_emu_buffer);
4450 av_freep(&s->top_border);
4551
4652 s->macroblocks = NULL;
@@ -108,6 +114,9 @@ static void vp8_decode_flush(AVCodecContext *avctx) · 61 unmodified lines
108114
109115 static int update_dimensions(VP8Context *s, int width, int height)
110116 {
117+ AVCodecContext *avctx = s->avctx;
118+ int i;
119+
111120 if (width != s->avctx->width || ((width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) && s->macroblocks_base ||
112121 height != s->avctx->height) {
113122 if (av_image_check_size(width, height, 0, s->avctx))
@@ -121,14 +130,27 @@ static int update_dimensions(VP8Context *s, int width, int height) · 7 unmodified lines
121130 s->mb_width = (s->avctx->coded_width +15) / 16;
122131 s->mb_height = (s->avctx->coded_height+15) / 16;
123132
124− s->macroblocks_base = av_mallocz((s->mb_width+s->mb_height*2+1)*sizeof(*s->macroblocks));
125− s->filter_strength = av_mallocz(s->mb_width*sizeof(*s->filter_strength));
126− s->intra4x4_pred_mode_top = av_mallocz(s->mb_width*4);
127− s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz));
128− s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_border));
133+ s->mb_layout = (avctx->active_thread_type == FF_THREAD_SLICE) && (FFMIN(s->num_coeff_partitions, avctx->thread_count) > 1);
134+ if (!s->mb_layout) { // Frame threading and one thread
135+ s->macroblocks_base = av_mallocz((s->mb_width+s->mb_height*2+1)*sizeof(*s->macroblocks));
136+ s->intra4x4_pred_mode_top = av_mallocz(s->mb_width*4);
137+ }
138+ else // Sliced threading
139+ s->macroblocks_base = av_mallocz((s->mb_width+2)*(s->mb_height+2)*sizeof(*s->macroblocks));
140+ s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz));
141+ s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_border));
142+ s->thread_data = av_mallocz(MAX_THREADS*sizeof(VP8ThreadData));
143+
144+ for (i = 0; i < MAX_THREADS; i++) {
145+ s->thread_data[i].filter_strength = av_mallocz(s->mb_width*sizeof(*s->thread_data[0].filter_strength));
146+#if HAVE_THREADS
147+ pthread_mutex_init(&s->thread_data[i].lock, NULL);
148+ pthread_cond_init(&s->thread_data[i].cond, NULL);
149+#endif
150+ }
129151
130− if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_top ||
131− !s->top_nnz || !s->top_border)
152+ if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||
153+ (!s->intra4x4_pred_mode_top && !s->mb_layout))
132154 return AVERROR(ENOMEM);
133155
134156 s->macroblocks = s->macroblocks_base + 1;
@@ -332,12 +354,6 @@ static int decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size) · 197 unmodified lines
332354 memset(&s->segmentation, 0, sizeof(s->segmentation));
333355 }
334356
335− if (!s->macroblocks_base || /* first frame */
336− width != s->avctx->width || height != s->avctx->height || (width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) {
337− if ((ret = update_dimensions(s, width, height)) < 0)
338− return ret;
339− }
340−
341357 ff_vp56_init_range_decoder(c, buf, header_size);
342358 buf += header_size;
343359 buf_size -= header_size;
@@ -366,6 +382,12 @@ static int decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size) · 22 unmodified lines
366382 return AVERROR_INVALIDDATA;
367383 }
368384
385+ if (!s->macroblocks_base || /* first frame */
386+ width != s->avctx->width || height != s->avctx->height || (width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) {
387+ if ((ret = update_dimensions(s, width, height)) < 0)
388+ return ret;
389+ }
390+
369391 get_quants(s);
370392
371393 if (!s->keyframe) {
@@ -468,19 +490,26 @@ const uint8_t *get_submv_prob(uint32_t left, uint32_t top) · 96 unmodified lines
468490 * @returns the number of motion vectors parsed (2, 4 or 16)
469491 */
470492 static av_always_inline
471−int decode_splitmvs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb)
493+int decode_splitmvs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb, int layout)
472494 {
473495 int part_idx;
474496 int n, num;
475− VP8Macroblock *top_mb = &mb[2];
497+ VP8Macroblock *top_mb;
476498 VP8Macroblock *left_mb = &mb[-1];
477499 const uint8_t *mbsplits_left = vp8_mbsplits[left_mb->partitioning],
478− *mbsplits_top = vp8_mbsplits[top_mb->partitioning],
500+ *mbsplits_top,
479501 *mbsplits_cur, *firstidx;
480− VP56mv *top_mv = top_mb->bmv;
502+ VP56mv *top_mv;
481503 VP56mv *left_mv = left_mb->bmv;
482504 VP56mv *cur_mv = mb->bmv;
483505
506+ if (!layout) // layout is inlined, s->mb_layout is not
507+ top_mb = &mb[2];
508+ else
509+ top_mb = &mb[-s->mb_width-1];
510+ mbsplits_top = vp8_mbsplits[top_mb->partitioning];
511+ top_mv = top_mb->bmv;
512+
484513 if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[0])) {
485514 if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[1])) {
486515 part_idx = VP8_SPLITMVMODE_16x8 + vp56_rac_get_prob(c, vp8_mbsplit_prob[2]);
@@ -532,11 +561,11 @@ int decode_splitmvs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb) · 45 unmodified lines
532561 }
533562
534563 static av_always_inline
535−void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y)
564+void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, int layout)
536565 {
537− VP8Macroblock *mb_edge[3] = { mb + 2 /* top */,
566+ VP8Macroblock *mb_edge[3] = { 0 /* top */,
538567 mb - 1 /* left */,
539− mb + 1 /* top-left */ };
568+ 0 /* top-left */ };
540569 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
541570 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT };
542571 int idx = CNT_ZERO;
@@ -546,6 +575,15 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y) · 3 unmodified lines
546575 uint8_t cnt[4] = { 0 };
547576 VP56RangeCoder *c = &s->c;
548577
578+ if (!layout) { // layout is inlined (s->mb_layout is not)
579+ mb_edge[0] = mb + 2;
580+ mb_edge[2] = mb + 1;
581+ }
582+ else {
583+ mb_edge[0] = mb - s->mb_width-1;
584+ mb_edge[2] = mb - s->mb_width-2;
585+ }
586+
549587 AV_ZERO32(&near_mv[0]);
550588 AV_ZERO32(&near_mv[1]);
551589 AV_ZERO32(&near_mv[2]);
@@ -600,7 +638,7 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y) · 48 unmodified lines
600638
601639 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) {
602640 mb->mode = VP8_MVMODE_SPLIT;
603− mb->mv = mb->bmv[decode_splitmvs(s, c, mb) - 1];
641+ mb->mv = mb->bmv[decode_splitmvs(s, c, mb, layout) - 1];
604642 } else {
605643 mb->mv.y += read_mv_component(c, s->prob->mvc[0]);
606644 mb->mv.x += read_mv_component(c, s->prob->mvc[1]);
@@ -622,14 +660,23 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y) · 15 unmodified lines
622660 }
623661
624662 static av_always_inline
625−void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c,
626− int mb_x, int keyframe)
663+void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
664+ int mb_x, int keyframe, int layout)
627665 {
628− uint8_t *intra4x4 = s->intra4x4_pred_mode_mb;
666+ uint8_t *intra4x4 = mb->intra4x4_pred_mode_mb;
667+
668+ if (layout == 1) {
669+ VP8Macroblock *mb_top = mb - s->mb_width - 1;
670+ memcpy(mb->intra4x4_pred_mode_top, mb_top->intra4x4_pred_mode_top, 4);
671+ }
629672 if (keyframe) {
630673 int x, y;
631− uint8_t* const top = s->intra4x4_pred_mode_top + 4 * mb_x;
674+ uint8_t* top;
632675 uint8_t* const left = s->intra4x4_pred_mode_left;
676+ if (layout == 1)
677+ top = mb->intra4x4_pred_mode_top;
678+ else
679+ top = s->intra4x4_pred_mode_top + 4 * mb_x;
633680 for (y = 0; y < 4; y++) {
634681 for (x = 0; x < 4; x++) {
635682 const uint8_t *ctx;
@@ -647,7 +694,8 @@ void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c, · 11 unmodified lines
647694 }
648695
649696 static av_always_inline
650−void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_t *segment, uint8_t *ref)
697+void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y,
698+ uint8_t *segment, uint8_t *ref, int layout)
651699 {
652700 VP56RangeCoder *c = &s->c;
653701
@@ -656,7 +704,7 @@ void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_ · 2 unmodified lines
656704 *segment = vp56_rac_get_prob(c, s->prob->segmentid[1+bit]) + 2*bit;
657705 } else if (s->segmentation.enabled)
658706 *segment = ref ? *ref : *segment;
659− s->segment = *segment;
707+ mb->segment = *segment;
660708
661709 mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;
662710
@@ -664,14 +712,17 @@ void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_ · 1 unmodified line
664712 mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_intra, vp8_pred16x16_prob_intra);
665713
666714 if (mb->mode == MODE_I4x4) {
667− decode_intra4x4_modes(s, c, mb_x, 1);
715+ decode_intra4x4_modes(s, c, mb, mb_x, 1, layout);
668716 } else {
669717 const uint32_t modes = vp8_pred4x4_mode[mb->mode] * 0x01010101u;
670− AV_WN32A(s->intra4x4_pred_mode_top + 4 * mb_x, modes);
671− AV_WN32A(s->intra4x4_pred_mode_left, modes);
718+ if (s->mb_layout == 1)
719+ AV_WN32A(mb->intra4x4_pred_mode_top, modes);
720+ else
721+ AV_WN32A(s->intra4x4_pred_mode_top + 4 * mb_x, modes);
722+ AV_WN32A( s->intra4x4_pred_mode_left, modes);
672723 }
673724
674− s->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, vp8_pred8x8c_prob_intra);
725+ mb->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, vp8_pred8x8c_prob_intra);
675726 mb->ref_frame = VP56_FRAME_CURRENT;
676727 } else if (vp56_rac_get_prob_branchy(c, s->prob->intra)) {
677728 // inter MB, 16.2
@@ -683,15 +734,15 @@ void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_ · 5 unmodified lines
683734 s->ref_count[mb->ref_frame-1]++;
684735
685736 // motion vectors, 16.3
686− decode_mvs(s, mb, mb_x, mb_y);
737+ decode_mvs(s, mb, mb_x, mb_y, layout);
687738 } else {
688739 // intra MB, 16.1
689740 mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16);
690741
691742 if (mb->mode == MODE_I4x4)
692− decode_intra4x4_modes(s, c, mb_x, 0);
743+ decode_intra4x4_modes(s, c, mb, mb_x, 0, layout);
693744
694− s->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, s->prob->pred8x8c);
745+ mb->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, s->prob->pred8x8c);
695746 mb->ref_frame = VP56_FRAME_CURRENT;
696747 mb->partitioning = VP8_SPLITMVMODE_NONE;
697748 AV_ZERO32(&mb->bmv[0]);
@@ -787,28 +838,28 @@ int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16], · 89 unmodified lines
787838 }
788839
789840 static av_always_inline
790−void decode_mb_coeffs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
841+void decode_mb_coeffs(VP8Context *s, VP8ThreadData *td, VP56RangeCoder *c, VP8Macroblock *mb,
791842 uint8_t t_nnz[9], uint8_t l_nnz[9])
792843 {
793844 int i, x, y, luma_start = 0, luma_ctx = 3;
794845 int nnz_pred, nnz, nnz_total = 0;
795− int segment = s->segment;
846+ int segment = mb->segment;
796847 int block_dc = 0;
797848
798849 if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {
799850 nnz_pred = t_nnz[8] + l_nnz[8];
800851
801852 // decode DC values and do hadamard
802− nnz = decode_block_coeffs(c, s->block_dc, s->prob->token[1], 0, nnz_pred,
853+ nnz = decode_block_coeffs(c, td->block_dc, s->prob->token[1], 0, nnz_pred,
803854 s->qmat[segment].luma_dc_qmul);
804855 l_nnz[8] = t_nnz[8] = !!nnz;
805856 if (nnz) {
806857 nnz_total += nnz;
807858 block_dc = 1;
808859 if (nnz == 1)
809− s->vp8dsp.vp8_luma_dc_wht_dc(s->block, s->block_dc);
860+ s->vp8dsp.vp8_luma_dc_wht_dc(td->block, td->block_dc);
810861 else
811− s->vp8dsp.vp8_luma_dc_wht(s->block, s->block_dc);
862+ s->vp8dsp.vp8_luma_dc_wht(td->block, td->block_dc);
812863 }
813864 luma_start = 1;
814865 luma_ctx = 0;
@@ -818,10 +869,10 @@ void decode_mb_coeffs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb, · 3 unmodified lines
818869 for (y = 0; y < 4; y++)
819870 for (x = 0; x < 4; x++) {
820871 nnz_pred = l_nnz[y] + t_nnz[x];
821− nnz = decode_block_coeffs(c, s->block[y][x], s->prob->token[luma_ctx], luma_start,
872+ nnz = decode_block_coeffs(c, td->block[y][x], s->prob->token[luma_ctx], luma_start,
822873 nnz_pred, s->qmat[segment].luma_qmul);
823874 // nnz+block_dc may be one more than the actual last index, but we don't care
824− s->non_zero_count_cache[y][x] = nnz + block_dc;
875+ td->non_zero_count_cache[y][x] = nnz + block_dc;
825876 t_nnz[x] = l_nnz[y] = !!nnz;
826877 nnz_total += nnz;
827878 }
@@ -833,9 +884,9 @@ void decode_mb_coeffs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb, · 5 unmodified lines
833884 for (y = 0; y < 2; y++)
834885 for (x = 0; x < 2; x++) {
835886 nnz_pred = l_nnz[i+2*y] + t_nnz[i+2*x];
836− nnz = decode_block_coeffs(c, s->block[i][(y<<1)+x], s->prob->token[2], 0,
887+ nnz = decode_block_coeffs(c, td->block[i][(y<<1)+x], s->prob->token[2], 0,
837888 nnz_pred, s->qmat[segment].chroma_qmul);
838− s->non_zero_count_cache[i][(y<<1)+x] = nnz;
889+ td->non_zero_count_cache[i][(y<<1)+x] = nnz;
839890 t_nnz[i+2*x] = l_nnz[i+2*y] = !!nnz;
840891 nnz_total += nnz;
841892 }
@@ -980,8 +1031,8 @@ int check_intra_pred4x4_mode_emuedge(int mode, int mb_x, int mb_y, int *copy_buf · 138 unmodified lines
9801031 }
9811032
9821033 static av_always_inline
983−void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,
984− int mb_x, int mb_y)
1034+void intra_predict(VP8Context *s, VP8ThreadData *td, uint8_t *dst[3],
1035+ VP8Macroblock *mb, int mb_x, int mb_y)
9851036 {
9861037 AVCodecContext *avctx = s->avctx;
9871038 int x, y, mode, nnz;
@@ -989,7 +1040,7 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 1 unmodified line
9891040
9901041 // for the first row, we need to run xchg_mb_border to init the top edge to 127
9911042 // otherwise, skip it if we aren't going to deblock
992− if (!(avctx->flags & CODEC_FLAG_EMU_EDGE && !mb_y) && (s->deblock_filter || !mb_y))
1043+ if (!(avctx->flags & CODEC_FLAG_EMU_EDGE && !mb_y) && (s->deblock_filter || !mb_y) && td->thread_nr == 0)
9931044 xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],
9941045 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
9951046 s->filter.simple, 1);
@@ -1003,7 +1054,7 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 7 unmodified lines
10031054 s->hpc.pred16x16[mode](dst[0], s->linesize);
10041055 } else {
10051056 uint8_t *ptr = dst[0];
1006− uint8_t *intra4x4 = s->intra4x4_pred_mode_mb;
1057+ uint8_t *intra4x4 = mb->intra4x4_pred_mode_mb;
10071058 uint8_t tr_top[4] = { 127, 127, 127, 127 };
10081059
10091060 // all blocks on the right edge of the macroblock use bottom edge
@@ -1019,7 +1070,7 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 9 unmodified lines
10191070 }
10201071
10211072 if (mb->skip)
1022− AV_ZERO128(s->non_zero_count_cache);
1073+ AV_ZERO128(td->non_zero_count_cache);
10231074
10241075 for (y = 0; y < 4; y++) {
10251076 uint8_t *topright = ptr + 4 - s->linesize;
@@ -1072,12 +1123,12 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 46 unmodified lines
10721123 AV_COPY32(ptr+4*x+s->linesize*3, copy_dst+36);
10731124 }
10741125
1075− nnz = s->non_zero_count_cache[y][x];
1126+ nnz = td->non_zero_count_cache[y][x];
10761127 if (nnz) {
10771128 if (nnz == 1)
1078− s->vp8dsp.vp8_idct_dc_add(ptr+4*x, s->block[y][x], s->linesize);
1129+ s->vp8dsp.vp8_idct_dc_add(ptr+4*x, td->block[y][x], s->linesize);
10791130 else
1080− s->vp8dsp.vp8_idct_add(ptr+4*x, s->block[y][x], s->linesize);
1131+ s->vp8dsp.vp8_idct_add(ptr+4*x, td->block[y][x], s->linesize);
10811132 }
10821133 topright += 4;
10831134 }
@@ -1088,14 +1139,14 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 4 unmodified lines
10881139 }
10891140
10901141 if (avctx->flags & CODEC_FLAG_EMU_EDGE) {
1091− mode = check_intra_pred8x8_mode_emuedge(s->chroma_pred_mode, mb_x, mb_y);
1142+ mode = check_intra_pred8x8_mode_emuedge(mb->chroma_pred_mode, mb_x, mb_y);
10921143 } else {
1093− mode = check_intra_pred8x8_mode(s->chroma_pred_mode, mb_x, mb_y);
1144+ mode = check_intra_pred8x8_mode(mb->chroma_pred_mode, mb_x, mb_y);
10941145 }
10951146 s->hpc.pred8x8[mode](dst[1], s->uvlinesize);
10961147 s->hpc.pred8x8[mode](dst[2], s->uvlinesize);
10971148
1098− if (!(avctx->flags & CODEC_FLAG_EMU_EDGE && !mb_y) && (s->deblock_filter || !mb_y))
1149+ if (!(avctx->flags & CODEC_FLAG_EMU_EDGE && !mb_y) && (s->deblock_filter || !mb_y) && td->thread_nr == 0)
10991150 xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],
11001151 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
11011152 s->filter.simple, 0);
@@ -1125,7 +1176,8 @@ static const uint8_t subpel_idx[3][8] = { · 23 unmodified lines
11251176 * @param mc_func motion compensation function pointers (bilinear or sixtap MC)
11261177 */
11271178 static av_always_inline
1128−void vp8_mc_luma(VP8Context *s, uint8_t *dst, AVFrame *ref, const VP56mv *mv,
1179+void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst,
1180+ AVFrame *ref, const VP56mv *mv,
11291181 int x_off, int y_off, int block_w, int block_h,
11301182 int width, int height, int linesize,
11311183 vp8_mc_func mc_func[3][3])
@@ -1145,10 +1197,10 @@ void vp8_mc_luma(VP8Context *s, uint8_t *dst, AVFrame *ref, const VP56mv *mv, · 13 unmodified lines
11451197 src += y_off * linesize + x_off;
11461198 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
11471199 y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {
1148− s->dsp.emulated_edge_mc(s->edge_emu_buffer, src - my_idx * linesize - mx_idx, linesize,
1200+ s->dsp.emulated_edge_mc(td->edge_emu_buffer, src - my_idx * linesize - mx_idx, linesize,
11491201 block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my],
11501202 x_off - mx_idx, y_off - my_idx, width, height);
1151− src = s->edge_emu_buffer + mx_idx + linesize * my_idx;
1203+ src = td->edge_emu_buffer + mx_idx + linesize * my_idx;
11521204 }
11531205 mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my);
11541206 } else {
@@ -1175,8 +1227,8 @@ void vp8_mc_luma(VP8Context *s, uint8_t *dst, AVFrame *ref, const VP56mv *mv, · 20 unmodified lines
11751227 * @param mc_func motion compensation function pointers (bilinear or sixtap MC)
11761228 */
11771229 static av_always_inline
1178−void vp8_mc_chroma(VP8Context *s, uint8_t *dst1, uint8_t *dst2, AVFrame *ref,
1179− const VP56mv *mv, int x_off, int y_off,
1230+void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, uint8_t *dst2,
1231+ AVFrame *ref, const VP56mv *mv, int x_off, int y_off,
11801232 int block_w, int block_h, int width, int height, int linesize,
11811233 vp8_mc_func mc_func[3][3])
11821234 {
@@ -1195,16 +1247,16 @@ void vp8_mc_chroma(VP8Context *s, uint8_t *dst1, uint8_t *dst2, AVFrame *ref, · 12 unmodified lines
11951247 ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3, 0);
11961248 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
11971249 y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {
1198− s->dsp.emulated_edge_mc(s->edge_emu_buffer, src1 - my_idx * linesize - mx_idx, linesize,
1250+ s->dsp.emulated_edge_mc(td->edge_emu_buffer, src1 - my_idx * linesize - mx_idx, linesize,
11991251 block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my],
12001252 x_off - mx_idx, y_off - my_idx, width, height);
1201− src1 = s->edge_emu_buffer + mx_idx + linesize * my_idx;
1253+ src1 = td->edge_emu_buffer + mx_idx + linesize * my_idx;
12021254 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
12031255
1204− s->dsp.emulated_edge_mc(s->edge_emu_buffer, src2 - my_idx * linesize - mx_idx, linesize,
1256+ s->dsp.emulated_edge_mc(td->edge_emu_buffer, src2 - my_idx * linesize - mx_idx, linesize,
12051257 block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my],
12061258 x_off - mx_idx, y_off - my_idx, width, height);
1207− src2 = s->edge_emu_buffer + mx_idx + linesize * my_idx;
1259+ src2 = td->edge_emu_buffer + mx_idx + linesize * my_idx;
12081260 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
12091261 } else {
12101262 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
@@ -1218,7 +1270,7 @@ void vp8_mc_chroma(VP8Context *s, uint8_t *dst1, uint8_t *dst2, AVFrame *ref, · 7 unmodified lines
12181270 }
12191271
12201272 static av_always_inline
1221−void vp8_mc_part(VP8Context *s, uint8_t *dst[3],
1273+void vp8_mc_part(VP8Context *s, VP8ThreadData *td, uint8_t *dst[3],
12221274 AVFrame *ref_frame, int x_off, int y_off,
12231275 int bx_off, int by_off,
12241276 int block_w, int block_h,
@@ -1227,7 +1279,7 @@ void vp8_mc_part(VP8Context *s, uint8_t *dst[3], · 2 unmodified lines
12271279 VP56mv uvmv = *mv;
12281280
12291281 /* Y */
1230− vp8_mc_luma(s, dst[0] + by_off * s->linesize + bx_off,
1282+ vp8_mc_luma(s, td, dst[0] + by_off * s->linesize + bx_off,
12311283 ref_frame, mv, x_off + bx_off, y_off + by_off,
12321284 block_w, block_h, width, height, s->linesize,
12331285 s->put_pixels_tab[block_w == 8]);
@@ -1241,7 +1293,7 @@ void vp8_mc_part(VP8Context *s, uint8_t *dst[3], · 7 unmodified lines
12411293 bx_off >>= 1; by_off >>= 1;
12421294 width >>= 1; height >>= 1;
12431295 block_w >>= 1; block_h >>= 1;
1244− vp8_mc_chroma(s, dst[1] + by_off * s->uvlinesize + bx_off,
1296+ vp8_mc_chroma(s, td, dst[1] + by_off * s->uvlinesize + bx_off,
12451297 dst[2] + by_off * s->uvlinesize + bx_off, ref_frame,
12461298 &uvmv, x_off + bx_off, y_off + by_off,
12471299 block_w, block_h, width, height, s->uvlinesize,
@@ -1272,8 +1324,8 @@ static av_always_inline void prefetch_motion(VP8Context *s, VP8Macroblock *mb, i · 24 unmodified lines
12721324 * Apply motion vectors to prediction buffer, chapter 18.
12731325 */
12741326 static av_always_inline
1275−void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,
1276− int mb_x, int mb_y)
1327+void inter_predict(VP8Context *s, VP8ThreadData *td, uint8_t *dst[3],
1328+ VP8Macroblock *mb, int mb_x, int mb_y)
12771329 {
12781330 int x_off = mb_x << 4, y_off = mb_y << 4;
12791331 int width = 16*s->mb_width, height = 16*s->mb_height;
@@ -1282,7 +1334,7 @@ void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 2 unmodified lines
12821334
12831335 switch (mb->partitioning) {
12841336 case VP8_SPLITMVMODE_NONE:
1285− vp8_mc_part(s, dst, ref, x_off, y_off,
1337+ vp8_mc_part(s, td, dst, ref, x_off, y_off,
12861338 0, 0, 16, 16, width, height, &mb->mv);
12871339 break;
12881340 case VP8_SPLITMVMODE_4x4: {
@@ -1292,7 +1344,7 @@ void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 3 unmodified lines
12921344 /* Y */
12931345 for (y = 0; y < 4; y++) {
12941346 for (x = 0; x < 4; x++) {
1295− vp8_mc_luma(s, dst[0] + 4*y*s->linesize + x*4,
1347+ vp8_mc_luma(s, td, dst[0] + 4*y*s->linesize + x*4,
12961348 ref, &bmv[4*y + x],
12971349 4*x + x_off, 4*y + y_off, 4, 4,
12981350 width, height, s->linesize,
@@ -1318,7 +1370,7 @@ void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 19 unmodified lines
13181370 uvmv.x &= ~7;
13191371 uvmv.y &= ~7;
13201372 }
1321− vp8_mc_chroma(s, dst[1] + 4*y*s->uvlinesize + x*4,
1373+ vp8_mc_chroma(s, td, dst[1] + 4*y*s->uvlinesize + x*4,
13221374 dst[2] + 4*y*s->uvlinesize + x*4, ref, &uvmv,
13231375 4*x + x_off, 4*y + y_off, 4, 4,
13241376 width, height, s->uvlinesize,
@@ -1328,51 +1380,52 @@ void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 3 unmodified lines
13281380 break;
13291381 }
13301382 case VP8_SPLITMVMODE_16x8:
1331− vp8_mc_part(s, dst, ref, x_off, y_off,
1383+ vp8_mc_part(s, td, dst, ref, x_off, y_off,
13321384 0, 0, 16, 8, width, height, &bmv[0]);
1333− vp8_mc_part(s, dst, ref, x_off, y_off,
1385+ vp8_mc_part(s, td, dst, ref, x_off, y_off,
13341386 0, 8, 16, 8, width, height, &bmv[1]);
13351387 break;
13361388 case VP8_SPLITMVMODE_8x16:
1337− vp8_mc_part(s, dst, ref, x_off, y_off,
1389+ vp8_mc_part(s, td, dst, ref, x_off, y_off,
13381390 0, 0, 8, 16, width, height, &bmv[0]);
1339− vp8_mc_part(s, dst, ref, x_off, y_off,
1391+ vp8_mc_part(s, td, dst, ref, x_off, y_off,
13401392 8, 0, 8, 16, width, height, &bmv[1]);
13411393 break;
13421394 case VP8_SPLITMVMODE_8x8:
1343− vp8_mc_part(s, dst, ref, x_off, y_off,
1395+ vp8_mc_part(s, td, dst, ref, x_off, y_off,
13441396 0, 0, 8, 8, width, height, &bmv[0]);
1345− vp8_mc_part(s, dst, ref, x_off, y_off,
1397+ vp8_mc_part(s, td, dst, ref, x_off, y_off,
13461398 8, 0, 8, 8, width, height, &bmv[1]);
1347− vp8_mc_part(s, dst, ref, x_off, y_off,
1399+ vp8_mc_part(s, td, dst, ref, x_off, y_off,
13481400 0, 8, 8, 8, width, height, &bmv[2]);
1349− vp8_mc_part(s, dst, ref, x_off, y_off,
1401+ vp8_mc_part(s, td, dst, ref, x_off, y_off,
13501402 8, 8, 8, 8, width, height, &bmv[3]);
13511403 break;
13521404 }
13531405 }
13541406
1355−static av_always_inline void idct_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb)
1407+static av_always_inline void idct_mb(VP8Context *s, VP8ThreadData *td,
1408+ uint8_t *dst[3], VP8Macroblock *mb)
13561409 {
13571410 int x, y, ch;
13581411
13591412 if (mb->mode != MODE_I4x4) {
13601413 uint8_t *y_dst = dst[0];
13611414 for (y = 0; y < 4; y++) {
1362− uint32_t nnz4 = AV_RL32(s->non_zero_count_cache[y]);
1415+ uint32_t nnz4 = AV_RL32(td->non_zero_count_cache[y]);
13631416 if (nnz4) {
13641417 if (nnz4&~0x01010101) {
13651418 for (x = 0; x < 4; x++) {
13661419 if ((uint8_t)nnz4 == 1)
1367− s->vp8dsp.vp8_idct_dc_add(y_dst+4*x, s->block[y][x], s->linesize);
1420+ s->vp8dsp.vp8_idct_dc_add(y_dst+4*x, td->block[y][x], s->linesize);
13681421 else if((uint8_t)nnz4 > 1)
1369− s->vp8dsp.vp8_idct_add(y_dst+4*x, s->block[y][x], s->linesize);
1422+ s->vp8dsp.vp8_idct_add(y_dst+4*x, td->block[y][x], s->linesize);
13701423 nnz4 >>= 8;
13711424 if (!nnz4)
13721425 break;
13731426 }
13741427 } else {
1375− s->vp8dsp.vp8_idct_dc_add4y(y_dst, s->block[y], s->linesize);
1428+ s->vp8dsp.vp8_idct_dc_add4y(y_dst, td->block[y], s->linesize);
13761429 }
13771430 }
13781431 y_dst += 4*s->linesize;
@@ -1380,16 +1433,16 @@ static av_always_inline void idct_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblo · 1 unmodified line
13801433 }
13811434
13821435 for (ch = 0; ch < 2; ch++) {
1383− uint32_t nnz4 = AV_RL32(s->non_zero_count_cache[4+ch]);
1436+ uint32_t nnz4 = AV_RL32(td->non_zero_count_cache[4+ch]);
13841437 if (nnz4) {
13851438 uint8_t *ch_dst = dst[1+ch];
13861439 if (nnz4&~0x01010101) {
13871440 for (y = 0; y < 2; y++) {
13881441 for (x = 0; x < 2; x++) {
13891442 if ((uint8_t)nnz4 == 1)
1390− s->vp8dsp.vp8_idct_dc_add(ch_dst+4*x, s->block[4+ch][(y<<1)+x], s->uvlinesize);
1443+ s->vp8dsp.vp8_idct_dc_add(ch_dst+4*x, td->block[4+ch][(y<<1)+x], s->uvlinesize);
13911444 else if((uint8_t)nnz4 > 1)
1392− s->vp8dsp.vp8_idct_add(ch_dst+4*x, s->block[4+ch][(y<<1)+x], s->uvlinesize);
1445+ s->vp8dsp.vp8_idct_add(ch_dst+4*x, td->block[4+ch][(y<<1)+x], s->uvlinesize);
13931446 nnz4 >>= 8;
13941447 if (!nnz4)
13951448 goto chroma_idct_end;
@@ -1397,7 +1450,7 @@ static av_always_inline void idct_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblo · 1 unmodified line
13971450 ch_dst += 4*s->uvlinesize;
13981451 }
13991452 } else {
1400− s->vp8dsp.vp8_idct_dc_add4uv(ch_dst, s->block[4+ch], s->uvlinesize);
1453+ s->vp8dsp.vp8_idct_dc_add4uv(ch_dst, td->block[4+ch], s->uvlinesize);
14011454 }
14021455 }
14031456 chroma_idct_end: ;
@@ -1409,7 +1462,7 @@ static av_always_inline void filter_level_for_mb(VP8Context *s, VP8Macroblock *m · 5 unmodified lines
14091462 int interior_limit, filter_level;
14101463
14111464 if (s->segmentation.enabled) {
1412− filter_level = s->segmentation.filter_level[s->segment];
1465+ filter_level = s->segmentation.filter_level[mb->segment];
14131466 if (!s->segmentation.absolute_vals)
14141467 filter_level += s->filter.level;
14151468 } else
@@ -1535,51 +1588,277 @@ static av_always_inline void filter_mb_simple(VP8Context *s, uint8_t *dst, VP8Fi · 119 unmodified lines
15351588 }
15361589 }
15371590
1538−static void filter_mb_row(VP8Context *s, AVFrame *curframe, int mb_y)
1591+static void release_queued_segmaps(VP8Context *s, int is_close)
15391592 {
1540− VP8FilterStrength *f = s->filter_strength;
1593+ int leave_behind = is_close ? 0 : !s->maps_are_invalid;
1594+ while (s->num_maps_to_be_freed > leave_behind)
1595+ av_freep(&s->segmentation_maps[--s->num_maps_to_be_freed]);
1596+ s->maps_are_invalid = 0;
1597+}
1598+
1599+#define MARGIN (16 << 2)
1600+static void vp8_decode_mv_mb_modes(AVCodecContext *avctx, AVFrame *curframe,
1601+ AVFrame *prev_frame)
1602+{
1603+ VP8Context *s = avctx->priv_data;
1604+ int mb_x, mb_y;
1605+
1606+ s->mv_min.y = -MARGIN;
1607+ s->mv_max.y = ((s->mb_height - 1) << 6) + MARGIN;
1608+ for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1609+ VP8Macroblock *mb = s->macroblocks_base + ((s->mb_width+1)*(mb_y + 1) + 1);
1610+ int mb_xy = mb_y*s->mb_width;
1611+
1612+ AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED*0x01010101);
1613+
1614+ s->mv_min.x = -MARGIN;
1615+ s->mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
1616+ for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
1617+ if (mb_y == 0)
1618+ AV_WN32A((mb-s->mb_width-1)->intra4x4_pred_mode_top, DC_PRED*0x01010101);
1619+ decode_mb_mode(s, mb, mb_x, mb_y, curframe->ref_index[0] + mb_xy,
1620+ prev_frame && prev_frame->ref_index[0] ? prev_frame->ref_index[0] + mb_xy : NULL, 1);
1621+ s->mv_min.x -= 64;
1622+ s->mv_max.x -= 64;
1623+ }
1624+ s->mv_min.y -= 64;
1625+ s->mv_max.y -= 64;
1626+ }
1627+}
1628+
1629+#if HAVE_THREADS
1630+#define check_thread_pos(td, otd, mb_x_check, mb_y_check)\
1631+ do {\
1632+ int tmp = (mb_y_check << 16) | (mb_x_check & 0xFFFF);\
1633+ if (otd->thread_mb_pos < tmp) {\
1634+ pthread_mutex_lock(&otd->lock);\
1635+ td->wait_mb_pos = tmp;\
1636+ do {\
1637+ if (otd->thread_mb_pos >= tmp)\
1638+ break;\
1639+ pthread_cond_wait(&otd->cond, &otd->lock);\
1640+ } while (1);\
1641+ td->wait_mb_pos = INT_MAX;\
1642+ pthread_mutex_unlock(&otd->lock);\
1643+ }\
1644+ } while(0);
1645+
1646+#define update_pos(td, mb_y, mb_x)\
1647+ do {\
1648+ int pos = (mb_y << 16) | (mb_x & 0xFFFF);\
1649+ int sliced_threading = (avctx->active_thread_type == FF_THREAD_SLICE) && (num_jobs > 1);\
1650+ int is_null = (next_td == NULL) || (prev_td == NULL);\
1651+ int pos_check = (is_null) ? 1 :\
1652+ (next_td != td && pos >= next_td->wait_mb_pos) ||\
1653+ (prev_td != td && pos >= prev_td->wait_mb_pos);\
1654+ td->thread_mb_pos = pos;\
1655+ if (sliced_threading && pos_check) {\
1656+ pthread_mutex_lock(&td->lock);\
1657+ pthread_cond_broadcast(&td->cond);\
1658+ pthread_mutex_unlock(&td->lock);\
1659+ }\
1660+ } while(0);
1661+#else
1662+#define check_thread_pos(td, otd, mb_x_check, mb_y_check)
1663+#define update_pos(td, mb_y, mb_x)
1664+#endif
1665+
1666+static void vp8_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
1667+ int jobnr, int threadnr)
1668+{
1669+ VP8Context *s = avctx->priv_data;
1670+ VP8ThreadData *prev_td, *next_td, *td = &s->thread_data[threadnr];
1671+ int mb_y = td->thread_mb_pos>>16;
1672+ int i, y, mb_x, mb_xy = mb_y*s->mb_width;
1673+ int num_jobs = s->num_jobs;
1674+ AVFrame *curframe = s->curframe, *prev_frame = s->prev_frame;
1675+ VP56RangeCoder *c = &s->coeff_partition[mb_y & (s->num_coeff_partitions-1)];
1676+ VP8Macroblock *mb;
15411677 uint8_t *dst[3] = {
15421678 curframe->data[0] + 16*mb_y*s->linesize,
15431679 curframe->data[1] + 8*mb_y*s->uvlinesize,
15441680 curframe->data[2] + 8*mb_y*s->uvlinesize
15451681 };
1546− int mb_x;
1682+ if (mb_y == 0) prev_td = td;
1683+ else prev_td = &s->thread_data[(jobnr + num_jobs - 1)%num_jobs];
1684+ if (mb_y == s->mb_height-1) next_td = td;
1685+ else next_td = &s->thread_data[(jobnr + 1)%num_jobs];
1686+ if (s->mb_layout == 1)
1687+ mb = s->macroblocks_base + ((s->mb_width+1)*(mb_y + 1) + 1);
1688+ else {
1689+ mb = s->macroblocks + (s->mb_height - mb_y - 1)*2;
1690+ memset(mb - 1, 0, sizeof(*mb)); // zero left macroblock
1691+ AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED*0x01010101);
1692+ }
1693+
1694+ memset(td->left_nnz, 0, sizeof(td->left_nnz));
1695+ // left edge of 129 for intra prediction
1696+ if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
1697+ for (i = 0; i < 3; i++)
1698+ for (y = 0; y < 16>>!!i; y++)
1699+ dst[i][y*curframe->linesize[i]-1] = 129;
1700+ if (mb_y == 1) {
1701+ s->top_border[0][15] = s->top_border[0][23] = s->top_border[0][31] = 129;
1702+ }
1703+ }
1704+
1705+ s->mv_min.x = -MARGIN;
1706+ s->mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
1707+
1708+ for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
1709+ // Wait for previous thread to read mb_x+2, and reach mb_y-1.
1710+ if (prev_td != td) {
1711+ if (threadnr != 0) {
1712+ check_thread_pos(td, prev_td, mb_x+1, mb_y-1);
1713+ } else {
1714+ check_thread_pos(td, prev_td, (s->mb_width+3) + (mb_x+1), mb_y-1);
1715+ }
1716+ }
1717+
1718+ s->dsp.prefetch(dst[0] + (mb_x&3)*4*s->linesize + 64, s->linesize, 4);
1719+ s->dsp.prefetch(dst[1] + (mb_x&7)*s->uvlinesize + 64, dst[2] - dst[1], 2);
1720+
1721+ if (!s->mb_layout)
1722+ decode_mb_mode(s, mb, mb_x, mb_y, curframe->ref_index[0] + mb_xy,
1723+ prev_frame && prev_frame->ref_index[0] ? prev_frame->ref_index[0] + mb_xy : NULL, 0);
1724+
1725+ prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_PREVIOUS);
1726+
1727+ if (!mb->skip)
1728+ decode_mb_coeffs(s, td, c, mb, s->top_nnz[mb_x], td->left_nnz);
1729+
1730+ if (mb->mode <= MODE_I4x4)
1731+ intra_predict(s, td, dst, mb, mb_x, mb_y);
1732+ else
1733+ inter_predict(s, td, dst, mb, mb_x, mb_y);
1734+
1735+ prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_GOLDEN);
1736+
1737+ if (!mb->skip) {
1738+ idct_mb(s, td, dst, mb);
1739+ } else {
1740+ AV_ZERO64(td->left_nnz);
1741+ AV_WN64(s->top_nnz[mb_x], 0); // array of 9, so unaligned
1742+
1743+ // Reset DC block predictors if they would exist if the mb had coefficients
1744+ if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {
1745+ td->left_nnz[8] = 0;
1746+ s->top_nnz[mb_x][8] = 0;
1747+ }
1748+ }
1749+
1750+ if (s->deblock_filter)
1751+ filter_level_for_mb(s, mb, &td->filter_strength[mb_x]);
1752+
1753+ if (s->deblock_filter && num_jobs != 1 && threadnr == num_jobs-1) {
1754+ if (s->filter.simple)
1755+ backup_mb_border(s->top_border[mb_x+1], dst[0], NULL, NULL, s->linesize, 0, 1);
1756+ else
1757+ backup_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, 0);
1758+ }
1759+
1760+ prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_GOLDEN2);
15471761
1548− for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1549− backup_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, 0);
1550− filter_mb(s, dst, f++, mb_x, mb_y);
15511762 dst[0] += 16;
15521763 dst[1] += 8;
15531764 dst[2] += 8;
1765+ s->mv_min.x -= 64;
1766+ s->mv_max.x -= 64;
1767+
1768+ if (mb_x == s->mb_width+1) {
1769+ update_pos(td, mb_y, s->mb_width+3);
1770+ } else {
1771+ update_pos(td, mb_y, mb_x);
1772+ }
15541773 }
15551774 }
15561775
1557−static void filter_mb_row_simple(VP8Context *s, AVFrame *curframe, int mb_y)
1776+static void vp8_filter_mb_row(AVCodecContext *avctx, void *tdata,
1777+ int jobnr, int threadnr)
15581778 {
1559− VP8FilterStrength *f = s->filter_strength;
1560− uint8_t *dst = curframe->data[0] + 16*mb_y*s->linesize;
1561− int mb_x;
1779+ VP8Context *s = avctx->priv_data;
1780+ VP8ThreadData *td = &s->thread_data[threadnr];
1781+ int mb_x, mb_y = td->thread_mb_pos>>16, num_jobs = s->num_jobs;
1782+ AVFrame *curframe = s->curframe;
1783+ VP8Macroblock *mb;
1784+ VP8ThreadData *prev_td, *next_td;
1785+ uint8_t *dst[3] = {
1786+ curframe->data[0] + 16*mb_y*s->linesize,
1787+ curframe->data[1] + 8*mb_y*s->uvlinesize,
1788+ curframe->data[2] + 8*mb_y*s->uvlinesize
1789+ };
15621790
1563− for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1564− backup_mb_border(s->top_border[mb_x+1], dst, NULL, NULL, s->linesize, 0, 1);
1565− filter_mb_simple(s, dst, f++, mb_x, mb_y);
1566− dst += 16;
1791+ if (s->mb_layout == 1)
1792+ mb = s->macroblocks_base + ((s->mb_width+1)*(mb_y + 1) + 1);
1793+ else
1794+ mb = s->macroblocks + (s->mb_height - mb_y - 1)*2;
1795+
1796+ if (mb_y == 0) prev_td = td;
1797+ else prev_td = &s->thread_data[(jobnr + num_jobs - 1)%num_jobs];
1798+ if (mb_y == s->mb_height-1) next_td = td;
1799+ else next_td = &s->thread_data[(jobnr + 1)%num_jobs];
1800+
1801+ for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb++) {
1802+ VP8FilterStrength *f = &td->filter_strength[mb_x];
1803+ if (prev_td != td) {
1804+ check_thread_pos(td, prev_td, (mb_x+1) + (s->mb_width+3), mb_y-1);
1805+ }
1806+ if (next_td != td)
1807+ if (next_td != &s->thread_data[0]) {
1808+ check_thread_pos(td, next_td, mb_x+1, mb_y+1);
1809+ }
1810+
1811+ if (num_jobs == 1) {
1812+ if (s->filter.simple)
1813+ backup_mb_border(s->top_border[mb_x+1], dst[0], NULL, NULL, s->linesize, 0, 1);
1814+ else
1815+ backup_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, 0);
1816+ }
1817+
1818+ if (s->filter.simple)
1819+ filter_mb_simple(s, dst[0], f, mb_x, mb_y);
1820+ else
1821+ filter_mb(s, dst, f, mb_x, mb_y);
1822+ dst[0] += 16;
1823+ dst[1] += 8;
1824+ dst[2] += 8;
1825+
1826+ update_pos(td, mb_y, (s->mb_width+3) + mb_x);
15671827 }
15681828 }
15691829
1570−static void release_queued_segmaps(VP8Context *s, int is_close)
1830+static int vp8_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata,
1831+ int jobnr, int threadnr)
15711832 {
1572− int leave_behind = is_close ? 0 : !s->maps_are_invalid;
1573− while (s->num_maps_to_be_freed > leave_behind)
1574− av_freep(&s->segmentation_maps[--s->num_maps_to_be_freed]);
1575− s->maps_are_invalid = 0;
1833+ VP8Context *s = avctx->priv_data;
1834+ VP8ThreadData *td = &s->thread_data[jobnr];
1835+ VP8ThreadData *next_td = NULL, *prev_td = NULL;
1836+ AVFrame *curframe = s->curframe;
1837+ int mb_y, num_jobs = s->num_jobs;
1838+ td->thread_nr = threadnr;
1839+ for (mb_y = jobnr; mb_y < s->mb_height; mb_y += num_jobs) {
1840+ if (mb_y >= s->mb_height) break;
1841+ td->thread_mb_pos = mb_y<<16;
1842+ vp8_decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr);
1843+ if (s->deblock_filter)
1844+ vp8_filter_mb_row(avctx, tdata, jobnr, threadnr);
1845+ update_pos(td, mb_y, INT_MAX & 0xFFFF);
1846+
1847+ s->mv_min.y -= 64;
1848+ s->mv_max.y -= 64;
1849+
1850+ if (avctx->active_thread_type == FF_THREAD_FRAME)
1851+ ff_thread_report_progress(curframe, mb_y, 0);
1852+ }
1853+
1854+ return 0;
15761855 }
15771856
15781857 static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
15791858 AVPacket *avpkt)
15801859 {
15811860 VP8Context *s = avctx->priv_data;
1582− int ret, mb_x, mb_y, i, y, referenced;
1861+ int ret, i, referenced, num_jobs;
15831862 enum AVDiscard skip_thresh;
15841863 AVFrame *av_uninit(curframe), *prev_frame;
15851864
@@ -1670,13 +1949,16 @@ static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 84 unmodified lines
16701949 s->linesize = curframe->linesize[0];
16711950 s->uvlinesize = curframe->linesize[1];
16721951
1673− if (!s->edge_emu_buffer)
1674− s->edge_emu_buffer = av_malloc(21*s->linesize);
1952+ if (!s->thread_data[0].edge_emu_buffer)
1953+ for (i = 0; i < MAX_THREADS; i++)
1954+ s->thread_data[i].edge_emu_buffer = av_malloc(21*s->linesize);
16751955
16761956 memset(s->top_nnz, 0, s->mb_width*sizeof(*s->top_nnz));
1677−
16781957 /* Zero macroblock structures for top/top-left prediction from outside the frame. */
1679− memset(s->macroblocks + s->mb_height*2 - 1, 0, (s->mb_width+1)*sizeof(*s->macroblocks));
1958+ if (!s->mb_layout)
1959+ memset(s->macroblocks + s->mb_height*2 - 1, 0, (s->mb_width+1)*sizeof(*s->macroblocks));
1960+ if (!s->mb_layout && s->keyframe)
1961+ memset(s->intra4x4_pred_mode_top, DC_PRED, s->mb_width*4);
16801962
16811963 // top edge of 127 for intra prediction
16821964 if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
@@ -1684,96 +1966,30 @@ static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 1 unmodified line
16841966 memset(s->top_border[1]-1, 127, s->mb_width*sizeof(*s->top_border)+1);
16851967 }
16861968 memset(s->ref_count, 0, sizeof(s->ref_count));
1687− if (s->keyframe)
1688− memset(s->intra4x4_pred_mode_top, DC_PRED, s->mb_width*4);
1689−
1690−#define MARGIN (16 << 2)
1691− s->mv_min.y = -MARGIN;
1692− s->mv_max.y = ((s->mb_height - 1) << 6) + MARGIN;
1693−
1694− for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1695− VP56RangeCoder *c = &s->coeff_partition[mb_y & (s->num_coeff_partitions-1)];
1696− VP8Macroblock *mb = s->macroblocks + (s->mb_height - mb_y - 1)*2;
1697− int mb_xy = mb_y*s->mb_width;
1698− uint8_t *dst[3] = {
1699− curframe->data[0] + 16*mb_y*s->linesize,
1700− curframe->data[1] + 8*mb_y*s->uvlinesize,
1701− curframe->data[2] + 8*mb_y*s->uvlinesize
1702− };
1703−
1704− memset(mb - 1, 0, sizeof(*mb)); // zero left macroblock
1705− memset(s->left_nnz, 0, sizeof(s->left_nnz));
1706− AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED*0x01010101);
1707−
1708− // left edge of 129 for intra prediction
1709− if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
1710− for (i = 0; i < 3; i++)
1711− for (y = 0; y < 16>>!!i; y++)
1712− dst[i][y*curframe->linesize[i]-1] = 129;
1713− if (mb_y == 1) // top left edge is also 129
1714− s->top_border[0][15] = s->top_border[0][23] = s->top_border[0][31] = 129;
1715− }
1716−
1717− s->mv_min.x = -MARGIN;
1718− s->mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
1719− if (prev_frame && s->segmentation.enabled && !s->segmentation.update_map)
1720− ff_thread_await_progress(prev_frame, mb_y, 0);
1721−
1722− for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
1723− /* Prefetch the current frame, 4 MBs ahead */
1724− s->dsp.prefetch(dst[0] + (mb_x&3)*4*s->linesize + 64, s->linesize, 4);
1725− s->dsp.prefetch(dst[1] + (mb_x&7)*s->uvlinesize + 64, dst[2] - dst[1], 2);
1726−
1727− decode_mb_mode(s, mb, mb_x, mb_y, curframe->ref_index[0] + mb_xy,
1728− prev_frame && prev_frame->ref_index[0] ? prev_frame->ref_index[0] + mb_xy : NULL);
1729−
1730− prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_PREVIOUS);
1731−
1732− if (!mb->skip)
1733− decode_mb_coeffs(s, c, mb, s->top_nnz[mb_x], s->left_nnz);
17341969
1735− if (mb->mode <= MODE_I4x4)
1736− intra_predict(s, dst, mb, mb_x, mb_y);
1737− else
1738− inter_predict(s, dst, mb, mb_x, mb_y);
17391970
1740− prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_GOLDEN);
1971+ // Make sure the previous frame has read its segmentation map,
1972+ // if we re-use the same map.
1973+ if (prev_frame && s->segmentation.enabled && !s->segmentation.update_map)
1974+ ff_thread_await_progress(prev_frame, 1, 0);
17411975
1742− if (!mb->skip) {
1743− idct_mb(s, dst, mb);
1744− } else {
1745− AV_ZERO64(s->left_nnz);
1746− AV_WN64(s->top_nnz[mb_x], 0); // array of 9, so unaligned
1976+ if (s->mb_layout == 1)
1977+ vp8_decode_mv_mb_modes(avctx, curframe, prev_frame);
17471978
1748− // Reset DC block predictors if they would exist if the mb had coefficients
1749− if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {
1750− s->left_nnz[8] = 0;
1751− s->top_nnz[mb_x][8] = 0;
1752− }
1753− }
1754−
1755− if (s->deblock_filter)
1756− filter_level_for_mb(s, mb, &s->filter_strength[mb_x]);
1757−
1758− prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_GOLDEN2);
1759−
1760− dst[0] += 16;
1761− dst[1] += 8;
1762− dst[2] += 8;
1763− s->mv_min.x -= 64;
1764− s->mv_max.x -= 64;
1765− }
1766− if (s->deblock_filter) {
1767− if (s->filter.simple)
1768− filter_mb_row_simple(s, curframe, mb_y);
1769− else
1770− filter_mb_row(s, curframe, mb_y);
1771− }
1772− s->mv_min.y -= 64;
1773− s->mv_max.y -= 64;
1774−
1775− ff_thread_report_progress(curframe, mb_y, 0);
1776− }
1979+ if (avctx->active_thread_type == FF_THREAD_FRAME)
1980+ num_jobs = 1;
1981+ else
1982+ num_jobs = FFMIN(s->num_coeff_partitions, avctx->thread_count);
1983+ s->num_jobs = num_jobs;
1984+ s->curframe = curframe;
1985+ s->prev_frame = prev_frame;
1986+ s->mv_min.y = -MARGIN;
1987+ s->mv_max.y = ((s->mb_height - 1) << 6) + MARGIN;
1988+ for (i = 0; i < MAX_THREADS; i++) {
1989+ s->thread_data[i].thread_mb_pos = 0;
1990+ s->thread_data[i].wait_mb_pos = INT_MAX;
1991+ }
1992+ avctx->execute2(avctx, vp8_decode_mb_row_sliced, s->thread_data, NULL, num_jobs);
17771993
17781994 ff_thread_report_progress(curframe, INT_MAX, 0);
17791995 memcpy(&s->framep[0], &s->next_framep[0], sizeof(s->framep[0]) * 4);
@@ -1862,7 +2078,7 @@ AVCodec ff_vp8_decoder = { · 82 unmodified lines
18622078 .init = vp8_decode_init,
18632079 .close = vp8_decode_free,
18642080 .decode = vp8_decode_frame,
1865− .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
2081+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS | CODEC_CAP_SLICE_THREADS,
18662082 .flush = vp8_decode_flush,
18672083 .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"),
18682084 .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp8_decode_init_thread_copy),
libavcodec/vp8.h+50−27
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 * Copyright (C) 2010 David Conrad
55 * Copyright (C) 2010 Ronald S. Bultje
66 * Copyright (C) 2010 Jason Garrett-Glaser
7+ * Copyright (C) 2012 Daniel Kang
78 *
89 * This file is part of FFmpeg.
910 *
@@ -29,6 +30,11 @@ · 19 unmodified lines
2930 #include "vp56data.h"
3031 #include "vp8dsp.h"
3132 #include "h264pred.h"
33+#if HAVE_PTHREADS
34+#include <pthread.h>
35+#elif HAVE_W32THREADS
36+#include "w32pthreads.h"
37+#endif
3238
3339 #define VP8_MAX_QUANT 127
3440
@@ -79,15 +85,51 @@ typedef struct { · 44 unmodified lines
7985 uint8_t mode;
8086 uint8_t ref_frame;
8187 uint8_t partitioning;
88+ uint8_t chroma_pred_mode;
89+ uint8_t segment;
90+ uint8_t intra4x4_pred_mode_mb[16];
91+ uint8_t intra4x4_pred_mode_top[4];
8292 VP56mv mv;
8393 VP56mv bmv[16];
8494 } VP8Macroblock;
8595
8696 typedef struct {
97+#if HAVE_THREADS
98+ pthread_mutex_t lock;
99+ pthread_cond_t cond;
100+#endif
101+ int thread_nr;
102+ int thread_mb_pos; // (mb_y << 16) | (mb_x & 0xFFFF)
103+ int wait_mb_pos; // What the current thread is waiting on.
104+ uint8_t *edge_emu_buffer;
105+ /**
106+ * For coeff decode, we need to know whether the above block had non-zero
107+ * coefficients. This means for each macroblock, we need data for 4 luma
108+ * blocks, 2 u blocks, 2 v blocks, and the luma dc block, for a total of 9
109+ * per macroblock. We keep the last row in top_nnz.
110+ */
111+ DECLARE_ALIGNED(8, uint8_t, left_nnz)[9];
112+ /**
113+ * This is the index plus one of the last non-zero coeff
114+ * for each of the blocks in the current macroblock.
115+ * So, 0 -> no coeffs
116+ * 1 -> dc-only (special transform)
117+ * 2+-> full transform
118+ */
119+ DECLARE_ALIGNED(16, uint8_t, non_zero_count_cache)[6][4];
120+ DECLARE_ALIGNED(16, DCTELEM, block)[6][4][16];
121+ DECLARE_ALIGNED(16, DCTELEM, block_dc)[16];
122+ VP8FilterStrength *filter_strength;
123+} VP8ThreadData;
124+
125+#define MAX_THREADS 8
126+typedef struct {
127+ VP8ThreadData *thread_data;
87128 AVCodecContext *avctx;
88129 AVFrame *framep[4];
89130 AVFrame *next_framep[4];
90− uint8_t *edge_emu_buffer;
131+ AVFrame *curframe;
132+ AVFrame *prev_frame;
91133
92134 uint16_t mb_width; /* number of horizontal MB */
93135 uint16_t mb_height; /* number of vertical MB */
@@ -97,8 +139,6 @@ typedef struct { · 3 unmodified lines
97139 uint8_t keyframe;
98140 uint8_t deblock_filter;
99141 uint8_t mbskip_enabled;
100− uint8_t segment; ///< segment of the current macroblock
101− uint8_t chroma_pred_mode; ///< 8x8c pred mode of the current macroblock
102142 uint8_t profile;
103143 VP56mv mv_min;
104144 VP56mv mv_max;
@@ -126,7 +166,6 @@ typedef struct { · 21 unmodified lines
126166 } filter;
127167
128168 VP8Macroblock *macroblocks;
129− VP8FilterStrength *filter_strength;
130169
131170 uint8_t *intra4x4_pred_mode_top;
132171 uint8_t intra4x4_pred_mode_left[4];
@@ -167,33 +206,10 @@ typedef struct { · 34 unmodified lines
167206 int8_t ref[4];
168207 } lf_delta;
169208
170− /**
171− * Cache of the top row needed for intra prediction
172− * 16 for luma, 8 for each chroma plane
173− */
174209 uint8_t (*top_border)[16+8+8];
175−
176− /**
177− * For coeff decode, we need to know whether the above block had non-zero
178− * coefficients. This means for each macroblock, we need data for 4 luma
179− * blocks, 2 u blocks, 2 v blocks, and the luma dc block, for a total of 9
180− * per macroblock. We keep the last row in top_nnz.
181− */
182210 uint8_t (*top_nnz)[9];
183− DECLARE_ALIGNED(8, uint8_t, left_nnz)[9];
184211
185− /**
186− * This is the index plus one of the last non-zero coeff
187− * for each of the blocks in the current macroblock.
188− * So, 0 -> no coeffs
189− * 1 -> dc-only (special transform)
190− * 2+-> full transform
191− */
192− DECLARE_ALIGNED(16, uint8_t, non_zero_count_cache)[6][4];
193212 VP56RangeCoder c; ///< header context, includes mb modes and motion vectors
194− DECLARE_ALIGNED(16, DCTELEM, block)[6][4][16];
195− DECLARE_ALIGNED(16, DCTELEM, block_dc)[16];
196− uint8_t intra4x4_pred_mode_mb[16];
197213
198214 /**
199215 * These are all of the updatable probabilities for binary decisions.
@@ -246,6 +262,13 @@ typedef struct { · 46 unmodified lines
246262 uint8_t *segmentation_maps[5];
247263 int num_maps_to_be_freed;
248264 int maps_are_invalid;
265+ int num_jobs;
266+ /**
267+ * This describes the macroblock memory layout.
268+ * 0 -> Only width+height*2+1 macroblocks allocated (frame/single thread).
269+ * 1 -> Macroblocks for entire frame alloced (sliced thread).
270+ */
271+ int mb_layout;
249272 } VP8Context;
250273
251274 #endif /* AVCODEC_VP8_H */
libavutil/mem.h+35−2
@@ -64,9 +64,9 @@ · 63 unmodified lines
6464 #endif
6565
6666 #if AV_GCC_VERSION_AT_LEAST(4,3)
67− #define av_alloc_size(n) __attribute__((alloc_size(n)))
67+ #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
6868 #else
69− #define av_alloc_size(n)
69+ #define av_alloc_size(...)
7070 #endif
7171
7272 /**
@@ -79,6 +79,22 @@ · 6 unmodified lines
7979 */
8080 void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
8181
82+/**
83+ * Helper function to allocate a block of size * nmemb bytes with
84+ * using av_malloc()
85+ * @param nmemb Number of elements
86+ * @param size Size of the single element
87+ * @return Pointer to the allocated block, NULL if the block cannot
88+ * be allocated.
89+ * @see av_malloc()
90+ */
91+av_alloc_size(1,2) static inline void *av_malloc_array(size_t nmemb, size_t size)
92+{
93+ if (size <= 0 || nmemb >= INT_MAX / size)
94+ return NULL;
95+ return av_malloc(nmemb * size);
96+}
97+
8298 /**
8399 * Allocate or reallocate a block of memory.
84100 * If ptr is NULL and size > 0, allocate a new block. If
@@ -135,6 +151,23 @@ void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1); · 50 unmodified lines
135151 */
136152 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
137153
154+/**
155+ * Helper function to allocate a block of size * nmemb bytes with
156+ * using av_mallocz()
157+ * @param nmemb Number of elements
158+ * @param size Size of the single element
159+ * @return Pointer to the allocated block, NULL if the block cannot
160+ * be allocated.
161+ * @see av_mallocz()
162+ * @see av_malloc_array()
163+ */
164+av_alloc_size(1,2) static inline void *av_mallocz_array(size_t nmemb, size_t size)
165+{
166+ if (size <= 0 || nmemb >= INT_MAX / size)
167+ return NULL;
168+ return av_mallocz(nmemb * size);
169+}
170+
138171 /**
139172 * Duplicate the string s.
140173 * @param s string to be duplicated
libavutil/version.h+1−1
@@ -39,7 +39,7 @@ · 38 unmodified lines
3939 */
4040
4141 #define LIBAVUTIL_VERSION_MAJOR 51
42−#define LIBAVUTIL_VERSION_MINOR 64
42+#define LIBAVUTIL_VERSION_MINOR 65
4343 #define LIBAVUTIL_VERSION_MICRO 100
4444
4545 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t