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
1190 clock_gettime1190 clock_gettime
1191 closesocket1191 closesocket
1192 cmov1192 cmov
1193 CommandLineToArgvW
1193 cpuid1194 cpuid
1194 dcbzl1195 dcbzl
1195 dev_bktr_ioctl_bt848_h1196 dev_bktr_ioctl_bt848_h
@@ -3182,7 +3183,8 @@ check_func nanosleep || { check_func nanosleep -lrt && add_extralibs -lrt; } · 1986 unmodified lines
3182check_func clock_gettime || { check_func clock_gettime -lrt && add_extralibs -lrt; }3183check_func clock_gettime || { check_func clock_gettime -lrt && add_extralibs -lrt; }
3183check_func fcntl3184check_func fcntl
3184check_func fork3185check_func fork
3185check_func getaddrinfo $network_extralibs3186check_func getaddrinfo $network_extralibs ||
3187 check_func_headers ws2tcpip.h getaddrinfo $network_extralibs
3186check_func gethrtime3188check_func gethrtime
3187check_func getopt3189check_func getopt
3188check_func getrusage3190check_func getrusage
@@ -3207,6 +3209,7 @@ check_func_headers conio.h kbhit · 18 unmodified lines
3207check_func_headers windows.h PeekNamedPipe3209check_func_headers windows.h PeekNamedPipe
3208check_func_headers io.h setmode3210check_func_headers io.h setmode
3209check_func_headers lzo/lzo1x.h lzo1x_999_compress3211check_func_headers lzo/lzo1x.h lzo1x_999_compress
3212check_lib2 "windows.h shellapi.h" CommandLineToArgvW -lshell32
3210check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi3213check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
3211check_func_headers windows.h GetProcessAffinityMask3214check_func_headers windows.h GetProcessAffinityMask
3212check_func_headers windows.h GetProcessTimes3215check_func_headers windows.h GetProcessTimes
doc/APIchanges+9−6
@@ -57,29 +57,32 @@ API changes, most recent first: · 56 unmodified lines
572012-03-26 - a67d9cf - lavfi 2.66.100572012-03-26 - a67d9cf - lavfi 2.66.100
58 Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions.58 Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions.
59 59
602012-06-22 - xxxxxxx - lavu 51.34.0602012-07-10 - 5fade8a - lavu 51.37.0
61 Add av_malloc_array() and av_mallocz_array()
62
632012-06-22 - d3d3a32 - lavu 51.34.0
61 Add av_usleep()64 Add av_usleep()
62 65
632012-06-20 - ae0a301 - lavu 51.33.0662012-06-20 - ae0a301 - lavu 51.33.0
64 Move av_gettime() to libavutil, add libavutil/time.h67 Move av_gettime() to libavutil, add libavutil/time.h
65 68
662012-xx-xx - xxxxxxx - lavr 0.0.3692012-06-09 - 3971be0 - lavr 0.0.3
67 Add a parameter to avresample_build_matrix() for Dolby/DPLII downmixing.70 Add a parameter to avresample_build_matrix() for Dolby/DPLII downmixing.
68 71
692012-xx-xx - xxxxxxx - lavfi 2.23.0 - avfilter.h722012-06-12 - 9baeff9 - lavfi 2.23.0 - avfilter.h
70 Add AVFilterContext.nb_inputs/outputs. Deprecate73 Add AVFilterContext.nb_inputs/outputs. Deprecate
71 AVFilterContext.input/output_count.74 AVFilterContext.input/output_count.
72 75
732012-xx-xx - xxxxxxx - lavfi 2.22.0 - avfilter.h762012-06-12 - 84b9fbe - lavfi 2.22.0 - avfilter.h
74 Add avfilter_pad_get_type() and avfilter_pad_get_name(). Those77 Add avfilter_pad_get_type() and avfilter_pad_get_name(). Those
75 should now be used instead of accessing AVFilterPad members78 should now be used instead of accessing AVFilterPad members
76 directly.79 directly.
77 80
782012-xx-xx - xxxxxxx - lavu 51.32.0 - audioconvert.h812012-06-12 - b0f0dfc - lavu 51.32.0 - audioconvert.h
79 Add av_get_channel_layout_channel_index(), av_get_channel_name()82 Add av_get_channel_layout_channel_index(), av_get_channel_name()
80 and av_channel_layout_extract_channel().83 and av_channel_layout_extract_channel().
81 84
822012-05-25 - e0e0793 - lavu 51.31.0 - opt.h852012-05-25 - 154486f - lavu 51.31.0 - opt.h
83 Add av_opt_set_bin()86 Add av_opt_set_bin()
84 87
852012-05-15 - lavfi 2.17.0882012-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
1013static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){1013static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){
1014 const int b_stride= s->b_width << s->block_max_depth;1014 const int b_stride= s->b_width << s->block_max_depth;
1015 BlockNode *block= &s->block[mb_x + mb_y * b_stride];1015 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];
1017 unsigned value;1017 unsigned value;
1018 int rd, index;1018 int rd, index;
1019 1019
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
1020 assert(mb_x>=0 && mb_y>=0);1028 assert(mb_x>=0 && mb_y>=0);
1021 assert(mb_x<b_stride);1029 assert(mb_x<b_stride);
1022 assert(((mb_x|mb_y)&1) == 0);1030 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
3956 s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;3956 s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
3957 for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0;3957 for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0;
3958 if (idx_mbmode <= 5) { // 1-MV3958 if (idx_mbmode <= 5) { // 1-MV
3959 dmv_x = dmv_y = 0;3959 dmv_x = dmv_y = pred_flag = 0;
3960 if (idx_mbmode & 1) {3960 if (idx_mbmode & 1) {
3961 get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);3961 get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
3962 }3962 }
libavcodec/vp8.c+418−202
@@ -4,6 +4,7 @@ · 3 unmodified lines
4 * Copyright (C) 2010 David Conrad4 * Copyright (C) 2010 David Conrad
5 * Copyright (C) 2010 Ronald S. Bultje5 * Copyright (C) 2010 Ronald S. Bultje
6 * Copyright (C) 2010 Jason Garrett-Glaser6 * Copyright (C) 2010 Jason Garrett-Glaser
7 * Copyright (C) 2012 Daniel Kang
7 *8 *
8 * This file is part of FFmpeg.9 * This file is part of FFmpeg.
9 *10 *
@@ -36,11 +37,16 @@ · 26 unmodified lines
36 37
37static void free_buffers(VP8Context *s)38static void free_buffers(VP8Context *s)
38{39{
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);
39 av_freep(&s->macroblocks_base);47 av_freep(&s->macroblocks_base);
40 av_freep(&s->filter_strength);
41 av_freep(&s->intra4x4_pred_mode_top);48 av_freep(&s->intra4x4_pred_mode_top);
42 av_freep(&s->top_nnz);49 av_freep(&s->top_nnz);
43 av_freep(&s->edge_emu_buffer);
44 av_freep(&s->top_border);50 av_freep(&s->top_border);
45 51
46 s->macroblocks = NULL;52 s->macroblocks = NULL;
@@ -108,6 +114,9 @@ static void vp8_decode_flush(AVCodecContext *avctx) · 61 unmodified lines
108 114
109static int update_dimensions(VP8Context *s, int width, int height)115static int update_dimensions(VP8Context *s, int width, int height)
110{116{
117 AVCodecContext *avctx = s->avctx;
118 int i;
119
111 if (width != s->avctx->width || ((width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) && s->macroblocks_base ||120 if (width != s->avctx->width || ((width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) && s->macroblocks_base ||
112 height != s->avctx->height) {121 height != s->avctx->height) {
113 if (av_image_check_size(width, height, 0, s->avctx))122 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
121 s->mb_width = (s->avctx->coded_width +15) / 16;130 s->mb_width = (s->avctx->coded_width +15) / 16;
122 s->mb_height = (s->avctx->coded_height+15) / 16;131 s->mb_height = (s->avctx->coded_height+15) / 16;
123 132
124 s->macroblocks_base = av_mallocz((s->mb_width+s->mb_height*2+1)*sizeof(*s->macroblocks));133 s->mb_layout = (avctx->active_thread_type == FF_THREAD_SLICE) && (FFMIN(s->num_coeff_partitions, avctx->thread_count) > 1);
125 s->filter_strength = av_mallocz(s->mb_width*sizeof(*s->filter_strength));134 if (!s->mb_layout) { // Frame threading and one thread
126 s->intra4x4_pred_mode_top = av_mallocz(s->mb_width*4);135 s->macroblocks_base = av_mallocz((s->mb_width+s->mb_height*2+1)*sizeof(*s->macroblocks));
127 s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz));136 s->intra4x4_pred_mode_top = av_mallocz(s->mb_width*4);
128 s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_border));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 }
129 151
130 if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_top ||152 if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||
131 !s->top_nnz || !s->top_border)153 (!s->intra4x4_pred_mode_top && !s->mb_layout))
132 return AVERROR(ENOMEM);154 return AVERROR(ENOMEM);
133 155
134 s->macroblocks = s->macroblocks_base + 1;156 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
332 memset(&s->segmentation, 0, sizeof(s->segmentation));354 memset(&s->segmentation, 0, sizeof(s->segmentation));
333 }355 }
334 356
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
341 ff_vp56_init_range_decoder(c, buf, header_size);357 ff_vp56_init_range_decoder(c, buf, header_size);
342 buf += header_size;358 buf += header_size;
343 buf_size -= header_size;359 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
366 return AVERROR_INVALIDDATA;382 return AVERROR_INVALIDDATA;
367 }383 }
368 384
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
369 get_quants(s);391 get_quants(s);
370 392
371 if (!s->keyframe) {393 if (!s->keyframe) {
@@ -468,19 +490,26 @@ const uint8_t *get_submv_prob(uint32_t left, uint32_t top) · 96 unmodified lines
468 * @returns the number of motion vectors parsed (2, 4 or 16)490 * @returns the number of motion vectors parsed (2, 4 or 16)
469 */491 */
470static av_always_inline492static av_always_inline
471int decode_splitmvs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb)493int decode_splitmvs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb, int layout)
472{494{
473 int part_idx;495 int part_idx;
474 int n, num;496 int n, num;
475 VP8Macroblock *top_mb = &mb[2];497 VP8Macroblock *top_mb;
476 VP8Macroblock *left_mb = &mb[-1];498 VP8Macroblock *left_mb = &mb[-1];
477 const uint8_t *mbsplits_left = vp8_mbsplits[left_mb->partitioning],499 const uint8_t *mbsplits_left = vp8_mbsplits[left_mb->partitioning],
478 *mbsplits_top = vp8_mbsplits[top_mb->partitioning],500 *mbsplits_top,
479 *mbsplits_cur, *firstidx;501 *mbsplits_cur, *firstidx;
480 VP56mv *top_mv = top_mb->bmv;502 VP56mv *top_mv;
481 VP56mv *left_mv = left_mb->bmv;503 VP56mv *left_mv = left_mb->bmv;
482 VP56mv *cur_mv = mb->bmv;504 VP56mv *cur_mv = mb->bmv;
483 505
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
484 if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[0])) {513 if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[0])) {
485 if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[1])) {514 if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[1])) {
486 part_idx = VP8_SPLITMVMODE_16x8 + vp56_rac_get_prob(c, vp8_mbsplit_prob[2]);515 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
532}561}
533 562
534static av_always_inline563static av_always_inline
535void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y)564void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, int layout)
536{565{
537 VP8Macroblock *mb_edge[3] = { mb + 2 /* top */,566 VP8Macroblock *mb_edge[3] = { 0 /* top */,
538 mb - 1 /* left */,567 mb - 1 /* left */,
539 mb + 1 /* top-left */ };568 0 /* top-left */ };
540 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };569 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
541 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT };570 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT };
542 int idx = CNT_ZERO;571 int idx = CNT_ZERO;
@@ -546,6 +575,15 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y) · 3 unmodified lines
546 uint8_t cnt[4] = { 0 };575 uint8_t cnt[4] = { 0 };
547 VP56RangeCoder *c = &s->c;576 VP56RangeCoder *c = &s->c;
548 577
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
549 AV_ZERO32(&near_mv[0]);587 AV_ZERO32(&near_mv[0]);
550 AV_ZERO32(&near_mv[1]);588 AV_ZERO32(&near_mv[1]);
551 AV_ZERO32(&near_mv[2]);589 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
600 638
601 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) {639 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) {
602 mb->mode = VP8_MVMODE_SPLIT;640 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];
604 } else {642 } else {
605 mb->mv.y += read_mv_component(c, s->prob->mvc[0]);643 mb->mv.y += read_mv_component(c, s->prob->mvc[0]);
606 mb->mv.x += read_mv_component(c, s->prob->mvc[1]);644 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
622}660}
623 661
624static av_always_inline662static av_always_inline
625void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c,663void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
626 int mb_x, int keyframe)664 int mb_x, int keyframe, int layout)
627{665{
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 }
629 if (keyframe) {672 if (keyframe) {
630 int x, y;673 int x, y;
631 uint8_t* const top = s->intra4x4_pred_mode_top + 4 * mb_x;674 uint8_t* top;
632 uint8_t* const left = s->intra4x4_pred_mode_left;675 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;
633 for (y = 0; y < 4; y++) {680 for (y = 0; y < 4; y++) {
634 for (x = 0; x < 4; x++) {681 for (x = 0; x < 4; x++) {
635 const uint8_t *ctx;682 const uint8_t *ctx;
@@ -647,7 +694,8 @@ void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c, · 11 unmodified lines
647}694}
648 695
649static av_always_inline696static av_always_inline
650void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_t *segment, uint8_t *ref)697void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y,
698 uint8_t *segment, uint8_t *ref, int layout)
651{699{
652 VP56RangeCoder *c = &s->c;700 VP56RangeCoder *c = &s->c;
653 701
@@ -656,7 +704,7 @@ void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_ · 2 unmodified lines
656 *segment = vp56_rac_get_prob(c, s->prob->segmentid[1+bit]) + 2*bit;704 *segment = vp56_rac_get_prob(c, s->prob->segmentid[1+bit]) + 2*bit;
657 } else if (s->segmentation.enabled)705 } else if (s->segmentation.enabled)
658 *segment = ref ? *ref : *segment;706 *segment = ref ? *ref : *segment;
659 s->segment = *segment;707 mb->segment = *segment;
660 708
661 mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;709 mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;
662 710
@@ -664,14 +712,17 @@ void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_ · 1 unmodified line
664 mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_intra, vp8_pred16x16_prob_intra);712 mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_intra, vp8_pred16x16_prob_intra);
665 713
666 if (mb->mode == MODE_I4x4) {714 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);
668 } else {716 } else {
669 const uint32_t modes = vp8_pred4x4_mode[mb->mode] * 0x01010101u;717 const uint32_t modes = vp8_pred4x4_mode[mb->mode] * 0x01010101u;
670 AV_WN32A(s->intra4x4_pred_mode_top + 4 * mb_x, modes);718 if (s->mb_layout == 1)
671 AV_WN32A(s->intra4x4_pred_mode_left, modes);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);
672 }723 }
673 724
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);
675 mb->ref_frame = VP56_FRAME_CURRENT;726 mb->ref_frame = VP56_FRAME_CURRENT;
676 } else if (vp56_rac_get_prob_branchy(c, s->prob->intra)) {727 } else if (vp56_rac_get_prob_branchy(c, s->prob->intra)) {
677 // inter MB, 16.2728 // 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
683 s->ref_count[mb->ref_frame-1]++;734 s->ref_count[mb->ref_frame-1]++;
684 735
685 // motion vectors, 16.3736 // motion vectors, 16.3
686 decode_mvs(s, mb, mb_x, mb_y);737 decode_mvs(s, mb, mb_x, mb_y, layout);
687 } else {738 } else {
688 // intra MB, 16.1739 // intra MB, 16.1
689 mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16);740 mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16);
690 741
691 if (mb->mode == MODE_I4x4)742 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);
693 744
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);
695 mb->ref_frame = VP56_FRAME_CURRENT;746 mb->ref_frame = VP56_FRAME_CURRENT;
696 mb->partitioning = VP8_SPLITMVMODE_NONE;747 mb->partitioning = VP8_SPLITMVMODE_NONE;
697 AV_ZERO32(&mb->bmv[0]);748 AV_ZERO32(&mb->bmv[0]);
@@ -787,28 +838,28 @@ int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16], · 89 unmodified lines
787}838}
788 839
789static av_always_inline840static av_always_inline
790void decode_mb_coeffs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,841void decode_mb_coeffs(VP8Context *s, VP8ThreadData *td, VP56RangeCoder *c, VP8Macroblock *mb,
791 uint8_t t_nnz[9], uint8_t l_nnz[9])842 uint8_t t_nnz[9], uint8_t l_nnz[9])
792{843{
793 int i, x, y, luma_start = 0, luma_ctx = 3;844 int i, x, y, luma_start = 0, luma_ctx = 3;
794 int nnz_pred, nnz, nnz_total = 0;845 int nnz_pred, nnz, nnz_total = 0;
795 int segment = s->segment;846 int segment = mb->segment;
796 int block_dc = 0;847 int block_dc = 0;
797 848
798 if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {849 if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {
799 nnz_pred = t_nnz[8] + l_nnz[8];850 nnz_pred = t_nnz[8] + l_nnz[8];
800 851
801 // decode DC values and do hadamard852 // 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,
803 s->qmat[segment].luma_dc_qmul);854 s->qmat[segment].luma_dc_qmul);
804 l_nnz[8] = t_nnz[8] = !!nnz;855 l_nnz[8] = t_nnz[8] = !!nnz;
805 if (nnz) {856 if (nnz) {
806 nnz_total += nnz;857 nnz_total += nnz;
807 block_dc = 1;858 block_dc = 1;
808 if (nnz == 1)859 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);
810 else861 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);
812 }863 }
813 luma_start = 1;864 luma_start = 1;
814 luma_ctx = 0;865 luma_ctx = 0;
@@ -818,10 +869,10 @@ void decode_mb_coeffs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb, · 3 unmodified lines
818 for (y = 0; y < 4; y++)869 for (y = 0; y < 4; y++)
819 for (x = 0; x < 4; x++) {870 for (x = 0; x < 4; x++) {
820 nnz_pred = l_nnz[y] + t_nnz[x];871 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,
822 nnz_pred, s->qmat[segment].luma_qmul);873 nnz_pred, s->qmat[segment].luma_qmul);
823 // nnz+block_dc may be one more than the actual last index, but we don't care874 // 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;
825 t_nnz[x] = l_nnz[y] = !!nnz;876 t_nnz[x] = l_nnz[y] = !!nnz;
826 nnz_total += nnz;877 nnz_total += nnz;
827 }878 }
@@ -833,9 +884,9 @@ void decode_mb_coeffs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb, · 5 unmodified lines
833 for (y = 0; y < 2; y++)884 for (y = 0; y < 2; y++)
834 for (x = 0; x < 2; x++) {885 for (x = 0; x < 2; x++) {
835 nnz_pred = l_nnz[i+2*y] + t_nnz[i+2*x];886 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,
837 nnz_pred, s->qmat[segment].chroma_qmul);888 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;
839 t_nnz[i+2*x] = l_nnz[i+2*y] = !!nnz;890 t_nnz[i+2*x] = l_nnz[i+2*y] = !!nnz;
840 nnz_total += nnz;891 nnz_total += nnz;
841 }892 }
@@ -980,8 +1031,8 @@ int check_intra_pred4x4_mode_emuedge(int mode, int mb_x, int mb_y, int *copy_buf · 138 unmodified lines
980}1031}
981 1032
982static av_always_inline1033static av_always_inline
983void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,1034void intra_predict(VP8Context *s, VP8ThreadData *td, uint8_t *dst[3],
984 int mb_x, int mb_y)1035 VP8Macroblock *mb, int mb_x, int mb_y)
985{1036{
986 AVCodecContext *avctx = s->avctx;1037 AVCodecContext *avctx = s->avctx;
987 int x, y, mode, nnz;1038 int x, y, mode, nnz;
@@ -989,7 +1040,7 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 1 unmodified line
989 1040
990 // for the first row, we need to run xchg_mb_border to init the top edge to 1271041 // for the first row, we need to run xchg_mb_border to init the top edge to 127
991 // otherwise, skip it if we aren't going to deblock1042 // 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)
993 xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],1044 xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],
994 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,1045 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
995 s->filter.simple, 1);1046 s->filter.simple, 1);
@@ -1003,7 +1054,7 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 7 unmodified lines
1003 s->hpc.pred16x16[mode](dst[0], s->linesize);1054 s->hpc.pred16x16[mode](dst[0], s->linesize);
1004 } else {1055 } else {
1005 uint8_t *ptr = dst[0];1056 uint8_t *ptr = dst[0];
1006 uint8_t *intra4x4 = s->intra4x4_pred_mode_mb;1057 uint8_t *intra4x4 = mb->intra4x4_pred_mode_mb;
1007 uint8_t tr_top[4] = { 127, 127, 127, 127 };1058 uint8_t tr_top[4] = { 127, 127, 127, 127 };
1008 1059
1009 // all blocks on the right edge of the macroblock use bottom edge1060 // 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
1019 }1070 }
1020 1071
1021 if (mb->skip)1072 if (mb->skip)
1022 AV_ZERO128(s->non_zero_count_cache);1073 AV_ZERO128(td->non_zero_count_cache);
1023 1074
1024 for (y = 0; y < 4; y++) {1075 for (y = 0; y < 4; y++) {
1025 uint8_t *topright = ptr + 4 - s->linesize;1076 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
1072 AV_COPY32(ptr+4*x+s->linesize*3, copy_dst+36);1123 AV_COPY32(ptr+4*x+s->linesize*3, copy_dst+36);
1073 }1124 }
1074 1125
1075 nnz = s->non_zero_count_cache[y][x];1126 nnz = td->non_zero_count_cache[y][x];
1076 if (nnz) {1127 if (nnz) {
1077 if (nnz == 1)1128 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);
1079 else1130 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);
1081 }1132 }
1082 topright += 4;1133 topright += 4;
1083 }1134 }
@@ -1088,14 +1139,14 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 4 unmodified lines
1088 }1139 }
1089 1140
1090 if (avctx->flags & CODEC_FLAG_EMU_EDGE) {1141 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);
1092 } else {1143 } 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);
1094 }1145 }
1095 s->hpc.pred8x8[mode](dst[1], s->uvlinesize);1146 s->hpc.pred8x8[mode](dst[1], s->uvlinesize);
1096 s->hpc.pred8x8[mode](dst[2], s->uvlinesize);1147 s->hpc.pred8x8[mode](dst[2], s->uvlinesize);
1097 1148
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)
1099 xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],1150 xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],
1100 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,1151 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
1101 s->filter.simple, 0);1152 s->filter.simple, 0);
@@ -1125,7 +1176,8 @@ static const uint8_t subpel_idx[3][8] = { · 23 unmodified lines
1125 * @param mc_func motion compensation function pointers (bilinear or sixtap MC)1176 * @param mc_func motion compensation function pointers (bilinear or sixtap MC)
1126 */1177 */
1127static av_always_inline1178static av_always_inline
1128void vp8_mc_luma(VP8Context *s, uint8_t *dst, AVFrame *ref, const VP56mv *mv,1179void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst,
1180 AVFrame *ref, const VP56mv *mv,
1129 int x_off, int y_off, int block_w, int block_h,1181 int x_off, int y_off, int block_w, int block_h,
1130 int width, int height, int linesize,1182 int width, int height, int linesize,
1131 vp8_mc_func mc_func[3][3])1183 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
1145 src += y_off * linesize + x_off;1197 src += y_off * linesize + x_off;
1146 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||1198 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
1147 y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {1199 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,
1149 block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my],1201 block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my],
1150 x_off - mx_idx, y_off - my_idx, width, height);1202 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;
1152 }1204 }
1153 mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my);1205 mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my);
1154 } else {1206 } else {
@@ -1175,8 +1227,8 @@ void vp8_mc_luma(VP8Context *s, uint8_t *dst, AVFrame *ref, const VP56mv *mv, · 20 unmodified lines
1175 * @param mc_func motion compensation function pointers (bilinear or sixtap MC)1227 * @param mc_func motion compensation function pointers (bilinear or sixtap MC)
1176 */1228 */
1177static av_always_inline1229static av_always_inline
1178void vp8_mc_chroma(VP8Context *s, uint8_t *dst1, uint8_t *dst2, AVFrame *ref,1230void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, uint8_t *dst2,
1179 const VP56mv *mv, int x_off, int y_off,1231 AVFrame *ref, const VP56mv *mv, int x_off, int y_off,
1180 int block_w, int block_h, int width, int height, int linesize,1232 int block_w, int block_h, int width, int height, int linesize,
1181 vp8_mc_func mc_func[3][3])1233 vp8_mc_func mc_func[3][3])
1182{1234{
@@ -1195,16 +1247,16 @@ void vp8_mc_chroma(VP8Context *s, uint8_t *dst1, uint8_t *dst2, AVFrame *ref, · 12 unmodified lines
1195 ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3, 0);1247 ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3, 0);
1196 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||1248 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
1197 y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {1249 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,
1199 block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my],1251 block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my],
1200 x_off - mx_idx, y_off - my_idx, width, height);1252 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;
1202 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);1254 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
1203 1255
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,
1205 block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my],1257 block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my],
1206 x_off - mx_idx, y_off - my_idx, width, height);1258 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;
1208 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);1260 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
1209 } else {1261 } else {
1210 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);1262 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
1218}1270}
1219 1271
1220static av_always_inline1272static av_always_inline
1221void vp8_mc_part(VP8Context *s, uint8_t *dst[3],1273void vp8_mc_part(VP8Context *s, VP8ThreadData *td, uint8_t *dst[3],
1222 AVFrame *ref_frame, int x_off, int y_off,1274 AVFrame *ref_frame, int x_off, int y_off,
1223 int bx_off, int by_off,1275 int bx_off, int by_off,
1224 int block_w, int block_h,1276 int block_w, int block_h,
@@ -1227,7 +1279,7 @@ void vp8_mc_part(VP8Context *s, uint8_t *dst[3], · 2 unmodified lines
1227 VP56mv uvmv = *mv;1279 VP56mv uvmv = *mv;
1228 1280
1229 /* Y */1281 /* 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,
1231 ref_frame, mv, x_off + bx_off, y_off + by_off,1283 ref_frame, mv, x_off + bx_off, y_off + by_off,
1232 block_w, block_h, width, height, s->linesize,1284 block_w, block_h, width, height, s->linesize,
1233 s->put_pixels_tab[block_w == 8]);1285 s->put_pixels_tab[block_w == 8]);
@@ -1241,7 +1293,7 @@ void vp8_mc_part(VP8Context *s, uint8_t *dst[3], · 7 unmodified lines
1241 bx_off >>= 1; by_off >>= 1;1293 bx_off >>= 1; by_off >>= 1;
1242 width >>= 1; height >>= 1;1294 width >>= 1; height >>= 1;
1243 block_w >>= 1; block_h >>= 1;1295 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,
1245 dst[2] + by_off * s->uvlinesize + bx_off, ref_frame,1297 dst[2] + by_off * s->uvlinesize + bx_off, ref_frame,
1246 &uvmv, x_off + bx_off, y_off + by_off,1298 &uvmv, x_off + bx_off, y_off + by_off,
1247 block_w, block_h, width, height, s->uvlinesize,1299 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
1272 * Apply motion vectors to prediction buffer, chapter 18.1324 * Apply motion vectors to prediction buffer, chapter 18.
1273 */1325 */
1274static av_always_inline1326static av_always_inline
1275void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,1327void inter_predict(VP8Context *s, VP8ThreadData *td, uint8_t *dst[3],
1276 int mb_x, int mb_y)1328 VP8Macroblock *mb, int mb_x, int mb_y)
1277{1329{
1278 int x_off = mb_x << 4, y_off = mb_y << 4;1330 int x_off = mb_x << 4, y_off = mb_y << 4;
1279 int width = 16*s->mb_width, height = 16*s->mb_height;1331 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
1282 1334
1283 switch (mb->partitioning) {1335 switch (mb->partitioning) {
1284 case VP8_SPLITMVMODE_NONE:1336 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,
1286 0, 0, 16, 16, width, height, &mb->mv);1338 0, 0, 16, 16, width, height, &mb->mv);
1287 break;1339 break;
1288 case VP8_SPLITMVMODE_4x4: {1340 case VP8_SPLITMVMODE_4x4: {
@@ -1292,7 +1344,7 @@ void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 3 unmodified lines
1292 /* Y */1344 /* Y */
1293 for (y = 0; y < 4; y++) {1345 for (y = 0; y < 4; y++) {
1294 for (x = 0; x < 4; x++) {1346 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,
1296 ref, &bmv[4*y + x],1348 ref, &bmv[4*y + x],
1297 4*x + x_off, 4*y + y_off, 4, 4,1349 4*x + x_off, 4*y + y_off, 4, 4,
1298 width, height, s->linesize,1350 width, height, s->linesize,
@@ -1318,7 +1370,7 @@ void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 19 unmodified lines
1318 uvmv.x &= ~7;1370 uvmv.x &= ~7;
1319 uvmv.y &= ~7;1371 uvmv.y &= ~7;
1320 }1372 }
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,
1322 dst[2] + 4*y*s->uvlinesize + x*4, ref, &uvmv,1374 dst[2] + 4*y*s->uvlinesize + x*4, ref, &uvmv,
1323 4*x + x_off, 4*y + y_off, 4, 4,1375 4*x + x_off, 4*y + y_off, 4, 4,
1324 width, height, s->uvlinesize,1376 width, height, s->uvlinesize,
@@ -1328,51 +1380,52 @@ void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, · 3 unmodified lines
1328 break;1380 break;
1329 }1381 }
1330 case VP8_SPLITMVMODE_16x8:1382 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,
1332 0, 0, 16, 8, width, height, &bmv[0]);1384 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,
1334 0, 8, 16, 8, width, height, &bmv[1]);1386 0, 8, 16, 8, width, height, &bmv[1]);
1335 break;1387 break;
1336 case VP8_SPLITMVMODE_8x16:1388 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,
1338 0, 0, 8, 16, width, height, &bmv[0]);1390 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,
1340 8, 0, 8, 16, width, height, &bmv[1]);1392 8, 0, 8, 16, width, height, &bmv[1]);
1341 break;1393 break;
1342 case VP8_SPLITMVMODE_8x8:1394 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,
1344 0, 0, 8, 8, width, height, &bmv[0]);1396 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,
1346 8, 0, 8, 8, width, height, &bmv[1]);1398 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,
1348 0, 8, 8, 8, width, height, &bmv[2]);1400 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,
1350 8, 8, 8, 8, width, height, &bmv[3]);1402 8, 8, 8, 8, width, height, &bmv[3]);
1351 break;1403 break;
1352 }1404 }
1353}1405}
1354 1406
1355static av_always_inline void idct_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb)1407static av_always_inline void idct_mb(VP8Context *s, VP8ThreadData *td,
1408 uint8_t *dst[3], VP8Macroblock *mb)
1356{1409{
1357 int x, y, ch;1410 int x, y, ch;
1358 1411
1359 if (mb->mode != MODE_I4x4) {1412 if (mb->mode != MODE_I4x4) {
1360 uint8_t *y_dst = dst[0];1413 uint8_t *y_dst = dst[0];
1361 for (y = 0; y < 4; y++) {1414 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]);
1363 if (nnz4) {1416 if (nnz4) {
1364 if (nnz4&~0x01010101) {1417 if (nnz4&~0x01010101) {
1365 for (x = 0; x < 4; x++) {1418 for (x = 0; x < 4; x++) {
1366 if ((uint8_t)nnz4 == 1)1419 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);
1368 else if((uint8_t)nnz4 > 1)1421 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);
1370 nnz4 >>= 8;1423 nnz4 >>= 8;
1371 if (!nnz4)1424 if (!nnz4)
1372 break;1425 break;
1373 }1426 }
1374 } else {1427 } 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);
1376 }1429 }
1377 }1430 }
1378 y_dst += 4*s->linesize;1431 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
1380 }1433 }
1381 1434
1382 for (ch = 0; ch < 2; ch++) {1435 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]);
1384 if (nnz4) {1437 if (nnz4) {
1385 uint8_t *ch_dst = dst[1+ch];1438 uint8_t *ch_dst = dst[1+ch];
1386 if (nnz4&~0x01010101) {1439 if (nnz4&~0x01010101) {
1387 for (y = 0; y < 2; y++) {1440 for (y = 0; y < 2; y++) {
1388 for (x = 0; x < 2; x++) {1441 for (x = 0; x < 2; x++) {
1389 if ((uint8_t)nnz4 == 1)1442 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);
1391 else if((uint8_t)nnz4 > 1)1444 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);
1393 nnz4 >>= 8;1446 nnz4 >>= 8;
1394 if (!nnz4)1447 if (!nnz4)
1395 goto chroma_idct_end;1448 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
1397 ch_dst += 4*s->uvlinesize;1450 ch_dst += 4*s->uvlinesize;
1398 }1451 }
1399 } else {1452 } 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);
1401 }1454 }
1402 }1455 }
1403chroma_idct_end: ;1456chroma_idct_end: ;
@@ -1409,7 +1462,7 @@ static av_always_inline void filter_level_for_mb(VP8Context *s, VP8Macroblock *m · 5 unmodified lines
1409 int interior_limit, filter_level;1462 int interior_limit, filter_level;
1410 1463
1411 if (s->segmentation.enabled) {1464 if (s->segmentation.enabled) {
1412 filter_level = s->segmentation.filter_level[s->segment];1465 filter_level = s->segmentation.filter_level[mb->segment];
1413 if (!s->segmentation.absolute_vals)1466 if (!s->segmentation.absolute_vals)
1414 filter_level += s->filter.level;1467 filter_level += s->filter.level;
1415 } else1468 } else
@@ -1535,51 +1588,277 @@ static av_always_inline void filter_mb_simple(VP8Context *s, uint8_t *dst, VP8Fi · 119 unmodified lines
1535 }1588 }
1536}1589}
1537 1590
1538static void filter_mb_row(VP8Context *s, AVFrame *curframe, int mb_y)1591static void release_queued_segmaps(VP8Context *s, int is_close)
1539{1592{
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)
1600static 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
1666static 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;
1541 uint8_t *dst[3] = {1677 uint8_t *dst[3] = {
1542 curframe->data[0] + 16*mb_y*s->linesize,1678 curframe->data[0] + 16*mb_y*s->linesize,
1543 curframe->data[1] + 8*mb_y*s->uvlinesize,1679 curframe->data[1] + 8*mb_y*s->uvlinesize,
1544 curframe->data[2] + 8*mb_y*s->uvlinesize1680 curframe->data[2] + 8*mb_y*s->uvlinesize
1545 };1681 };
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);
1547 1761
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);
1551 dst[0] += 16;1762 dst[0] += 16;
1552 dst[1] += 8;1763 dst[1] += 8;
1553 dst[2] += 8;1764 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 }
1554 }1773 }
1555}1774}
1556 1775
1557static void filter_mb_row_simple(VP8Context *s, AVFrame *curframe, int mb_y)1776static void vp8_filter_mb_row(AVCodecContext *avctx, void *tdata,
1777 int jobnr, int threadnr)
1558{1778{
1559 VP8FilterStrength *f = s->filter_strength;1779 VP8Context *s = avctx->priv_data;
1560 uint8_t *dst = curframe->data[0] + 16*mb_y*s->linesize;1780 VP8ThreadData *td = &s->thread_data[threadnr];
1561 int mb_x;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 };
1562 1790
1563 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {1791 if (s->mb_layout == 1)
1564 backup_mb_border(s->top_border[mb_x+1], dst, NULL, NULL, s->linesize, 0, 1);1792 mb = s->macroblocks_base + ((s->mb_width+1)*(mb_y + 1) + 1);
1565 filter_mb_simple(s, dst, f++, mb_x, mb_y);1793 else
1566 dst += 16;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);
1567 }1827 }
1568}1828}
1569 1829
1570static void release_queued_segmaps(VP8Context *s, int is_close)1830static int vp8_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata,
1831 int jobnr, int threadnr)
1571{1832{
1572 int leave_behind = is_close ? 0 : !s->maps_are_invalid;1833 VP8Context *s = avctx->priv_data;
1573 while (s->num_maps_to_be_freed > leave_behind)1834 VP8ThreadData *td = &s->thread_data[jobnr];
1574 av_freep(&s->segmentation_maps[--s->num_maps_to_be_freed]);1835 VP8ThreadData *next_td = NULL, *prev_td = NULL;
1575 s->maps_are_invalid = 0;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;
1576}1855}
1577 1856
1578static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,1857static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
1579 AVPacket *avpkt)1858 AVPacket *avpkt)
1580{1859{
1581 VP8Context *s = avctx->priv_data;1860 VP8Context *s = avctx->priv_data;
1582 int ret, mb_x, mb_y, i, y, referenced;1861 int ret, i, referenced, num_jobs;
1583 enum AVDiscard skip_thresh;1862 enum AVDiscard skip_thresh;
1584 AVFrame *av_uninit(curframe), *prev_frame;1863 AVFrame *av_uninit(curframe), *prev_frame;
1585 1864
@@ -1670,13 +1949,16 @@ static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 84 unmodified lines
1670 s->linesize = curframe->linesize[0];1949 s->linesize = curframe->linesize[0];
1671 s->uvlinesize = curframe->linesize[1];1950 s->uvlinesize = curframe->linesize[1];
1672 1951
1673 if (!s->edge_emu_buffer)1952 if (!s->thread_data[0].edge_emu_buffer)
1674 s->edge_emu_buffer = av_malloc(21*s->linesize);1953 for (i = 0; i < MAX_THREADS; i++)
1954 s->thread_data[i].edge_emu_buffer = av_malloc(21*s->linesize);
1675 1955
1676 memset(s->top_nnz, 0, s->mb_width*sizeof(*s->top_nnz));1956 memset(s->top_nnz, 0, s->mb_width*sizeof(*s->top_nnz));
1677
1678 /* Zero macroblock structures for top/top-left prediction from outside the frame. */1957 /* 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);
1680 1962
1681 // top edge of 127 for intra prediction1963 // top edge of 127 for intra prediction
1682 if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {1964 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
1684 memset(s->top_border[1]-1, 127, s->mb_width*sizeof(*s->top_border)+1);1966 memset(s->top_border[1]-1, 127, s->mb_width*sizeof(*s->top_border)+1);
1685 }1967 }
1686 memset(s->ref_count, 0, sizeof(s->ref_count));1968 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);
1734 1969
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);
1739 1970
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);
1741 1975
1742 if (!mb->skip) {1976 if (s->mb_layout == 1)
1743 idct_mb(s, dst, mb);1977 vp8_decode_mv_mb_modes(avctx, curframe, prev_frame);
1744 } else {
1745 AV_ZERO64(s->left_nnz);
1746 AV_WN64(s->top_nnz[mb_x], 0); // array of 9, so unaligned
1747 1978
1748 // Reset DC block predictors if they would exist if the mb had coefficients1979 if (avctx->active_thread_type == FF_THREAD_FRAME)
1749 if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {1980 num_jobs = 1;
1750 s->left_nnz[8] = 0;1981 else
1751 s->top_nnz[mb_x][8] = 0;1982 num_jobs = FFMIN(s->num_coeff_partitions, avctx->thread_count);
1752 }1983 s->num_jobs = num_jobs;
1753 }1984 s->curframe = curframe;
1754 1985 s->prev_frame = prev_frame;
1755 if (s->deblock_filter)1986 s->mv_min.y = -MARGIN;
1756 filter_level_for_mb(s, mb, &s->filter_strength[mb_x]);1987 s->mv_max.y = ((s->mb_height - 1) << 6) + MARGIN;
1757 1988 for (i = 0; i < MAX_THREADS; i++) {
1758 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_GOLDEN2);1989 s->thread_data[i].thread_mb_pos = 0;
1759 1990 s->thread_data[i].wait_mb_pos = INT_MAX;
1760 dst[0] += 16;1991 }
1761 dst[1] += 8;1992 avctx->execute2(avctx, vp8_decode_mb_row_sliced, s->thread_data, NULL, num_jobs);
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 }
1777 1993
1778 ff_thread_report_progress(curframe, INT_MAX, 0);1994 ff_thread_report_progress(curframe, INT_MAX, 0);
1779 memcpy(&s->framep[0], &s->next_framep[0], sizeof(s->framep[0]) * 4);1995 memcpy(&s->framep[0], &s->next_framep[0], sizeof(s->framep[0]) * 4);
@@ -1862,7 +2078,7 @@ AVCodec ff_vp8_decoder = { · 82 unmodified lines
1862 .init = vp8_decode_init,2078 .init = vp8_decode_init,
1863 .close = vp8_decode_free,2079 .close = vp8_decode_free,
1864 .decode = vp8_decode_frame,2080 .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,
1866 .flush = vp8_decode_flush,2082 .flush = vp8_decode_flush,
1867 .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"),2083 .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"),
1868 .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp8_decode_init_thread_copy),2084 .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp8_decode_init_thread_copy),
libavcodec/vp8.h+50−27
@@ -4,6 +4,7 @@ · 3 unmodified lines
4 * Copyright (C) 2010 David Conrad4 * Copyright (C) 2010 David Conrad
5 * Copyright (C) 2010 Ronald S. Bultje5 * Copyright (C) 2010 Ronald S. Bultje
6 * Copyright (C) 2010 Jason Garrett-Glaser6 * Copyright (C) 2010 Jason Garrett-Glaser
7 * Copyright (C) 2012 Daniel Kang
7 *8 *
8 * This file is part of FFmpeg.9 * This file is part of FFmpeg.
9 *10 *
@@ -29,6 +30,11 @@ · 19 unmodified lines
29#include "vp56data.h"30#include "vp56data.h"
30#include "vp8dsp.h"31#include "vp8dsp.h"
31#include "h264pred.h"32#include "h264pred.h"
33#if HAVE_PTHREADS
34#include <pthread.h>
35#elif HAVE_W32THREADS
36#include "w32pthreads.h"
37#endif
32 38
33#define VP8_MAX_QUANT 12739#define VP8_MAX_QUANT 127
34 40
@@ -79,15 +85,51 @@ typedef struct { · 44 unmodified lines
79 uint8_t mode;85 uint8_t mode;
80 uint8_t ref_frame;86 uint8_t ref_frame;
81 uint8_t partitioning;87 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];
82 VP56mv mv;92 VP56mv mv;
83 VP56mv bmv[16];93 VP56mv bmv[16];
84} VP8Macroblock;94} VP8Macroblock;
85 95
86typedef struct {96typedef 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
126typedef struct {
127 VP8ThreadData *thread_data;
87 AVCodecContext *avctx;128 AVCodecContext *avctx;
88 AVFrame *framep[4];129 AVFrame *framep[4];
89 AVFrame *next_framep[4];130 AVFrame *next_framep[4];
90 uint8_t *edge_emu_buffer;131 AVFrame *curframe;
132 AVFrame *prev_frame;
91 133
92 uint16_t mb_width; /* number of horizontal MB */134 uint16_t mb_width; /* number of horizontal MB */
93 uint16_t mb_height; /* number of vertical MB */135 uint16_t mb_height; /* number of vertical MB */
@@ -97,8 +139,6 @@ typedef struct { · 3 unmodified lines
97 uint8_t keyframe;139 uint8_t keyframe;
98 uint8_t deblock_filter;140 uint8_t deblock_filter;
99 uint8_t mbskip_enabled;141 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
102 uint8_t profile;142 uint8_t profile;
103 VP56mv mv_min;143 VP56mv mv_min;
104 VP56mv mv_max;144 VP56mv mv_max;
@@ -126,7 +166,6 @@ typedef struct { · 21 unmodified lines
126 } filter;166 } filter;
127 167
128 VP8Macroblock *macroblocks;168 VP8Macroblock *macroblocks;
129 VP8FilterStrength *filter_strength;
130 169
131 uint8_t *intra4x4_pred_mode_top;170 uint8_t *intra4x4_pred_mode_top;
132 uint8_t intra4x4_pred_mode_left[4];171 uint8_t intra4x4_pred_mode_left[4];
@@ -167,33 +206,10 @@ typedef struct { · 34 unmodified lines
167 int8_t ref[4];206 int8_t ref[4];
168 } lf_delta;207 } lf_delta;
169 208
170 /**
171 * Cache of the top row needed for intra prediction
172 * 16 for luma, 8 for each chroma plane
173 */
174 uint8_t (*top_border)[16+8+8];209 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 */
182 uint8_t (*top_nnz)[9];210 uint8_t (*top_nnz)[9];
183 DECLARE_ALIGNED(8, uint8_t, left_nnz)[9];
184 211
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];
193 VP56RangeCoder c; ///< header context, includes mb modes and motion vectors212 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];
197 213
198 /**214 /**
199 * These are all of the updatable probabilities for binary decisions.215 * These are all of the updatable probabilities for binary decisions.
@@ -246,6 +262,13 @@ typedef struct { · 46 unmodified lines
246 uint8_t *segmentation_maps[5];262 uint8_t *segmentation_maps[5];
247 int num_maps_to_be_freed;263 int num_maps_to_be_freed;
248 int maps_are_invalid;264 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;
249} VP8Context;272} VP8Context;
250 273
251#endif /* AVCODEC_VP8_H */274#endif /* AVCODEC_VP8_H */
libavutil/mem.h+35−2
@@ -64,9 +64,9 @@ · 63 unmodified lines
64#endif64#endif
65 65
66#if AV_GCC_VERSION_AT_LEAST(4,3)66#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__)))
68#else68#else
69 #define av_alloc_size(n)69 #define av_alloc_size(...)
70#endif70#endif
71 71
72/**72/**
@@ -79,6 +79,22 @@ · 6 unmodified lines
79 */79 */
80void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);80void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
81 81
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 */
91av_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
82/**98/**
83 * Allocate or reallocate a block of memory.99 * Allocate or reallocate a block of memory.
84 * If ptr is NULL and size > 0, allocate a new block. If100 * 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
135 */151 */
136void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;152void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
137 153
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 */
164av_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
138/**171/**
139 * Duplicate the string s.172 * Duplicate the string s.
140 * @param s string to be duplicated173 * @param s string to be duplicated
libavutil/version.h+1−1
@@ -39,7 +39,7 @@ · 38 unmodified lines
39 */39 */
40 40
41#define LIBAVUTIL_VERSION_MAJOR 5141#define LIBAVUTIL_VERSION_MAJOR 51
42#define LIBAVUTIL_VERSION_MINOR 6442#define LIBAVUTIL_VERSION_MINOR 65
43#define LIBAVUTIL_VERSION_MICRO 10043#define LIBAVUTIL_VERSION_MICRO 100
44 44
45#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \45#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