History

avcodec/vp8: Convert to ProgressFrame API

Andreas Rheinhardt committed 4 years ago

Commit d48d7bc1 parent d74102e4 files · +40 −74Browse files

Unified · Split

4 files
  1. libavcodec/pthread_frame.c +1 −1
  2. libavcodec/vp8.c +34 −70
  3. libavcodec/vp8.h +3 −2
  4. libavcodec/webp.c +2 −1
libavcodec/pthread_frame.c+1−1
@@ -986,7 +986,7 @@ int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags) · 985 unmodified lines
986986 /* Hint: It is possible for this function to be called with codecs
987987 * that don't support frame threading at all, namely in case
988988 * a frame-threaded decoder shares code with codecs that are not.
989− * This currently affects non-MPEG-4 mpegvideo codecs and and VP7.
989+ * This currently affects non-MPEG-4 mpegvideo codecs.
990990 * The following check will always be true for them. */
991991 if (!(avctx->active_thread_type & FF_THREAD_FRAME))
992992 return ff_get_buffer(avctx, f->f, flags);
libavcodec/vp8.c+34−70
@@ -35,9 +35,9 @@ · 34 unmodified lines
3535 #include "hwaccel_internal.h"
3636 #include "hwconfig.h"
3737 #include "mathops.h"
38+#include "progressframe.h"
3839 #include "refstruct.h"
3940 #include "thread.h"
40−#include "threadframe.h"
4141 #include "vp8.h"
4242 #include "vp89_rac.h"
4343 #include "vp8data.h"
@@ -103,9 +103,9 @@ static void free_buffers(VP8Context *s) · 59 unmodified lines
103103
104104 static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref)
105105 {
106− int ret;
107− if ((ret = ff_thread_get_ext_buffer(s->avctx, &f->tf,
108− ref ? AV_GET_BUFFER_FLAG_REF : 0)) < 0)
106+ int ret = ff_progress_frame_get_buffer(s->avctx, &f->tf,
107+ ref ? AV_GET_BUFFER_FLAG_REF : 0);
108+ if (ret < 0)
109109 return ret;
110110 if (!(f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height)))
111111 goto fail;
@@ -117,7 +117,7 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) · 5 unmodified lines
117117
118118 fail:
119119 ff_refstruct_unref(&f->seg_map);
120− ff_thread_release_ext_buffer(&f->tf);
120+ ff_progress_frame_unref(&f->tf);
121121 return ret;
122122 }
123123
@@ -125,26 +125,9 @@ static void vp8_release_frame(VP8Frame *f) · 1 unmodified line
125125 {
126126 ff_refstruct_unref(&f->seg_map);
127127 ff_refstruct_unref(&f->hwaccel_picture_private);
128− ff_thread_release_ext_buffer(&f->tf);
128+ ff_progress_frame_unref(&f->tf);
129129 }
130130
131−#if CONFIG_VP8_DECODER
132−static int vp8_ref_frame(VP8Frame *dst, const VP8Frame *src)
133−{
134− int ret;
135−
136− vp8_release_frame(dst);
137−
138− if ((ret = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0)
139− return ret;
140− ff_refstruct_replace(&dst->seg_map, src->seg_map);
141− ff_refstruct_replace(&dst->hwaccel_picture_private,
142− src->hwaccel_picture_private);
143−
144− return 0;
145−}
146−#endif /* CONFIG_VP8_DECODER */
147−
148131 static void vp8_decode_flush_impl(AVCodecContext *avctx, int free_mem)
149132 {
150133 VP8Context *s = avctx->priv_data;
@@ -184,7 +167,7 @@ static VP8Frame *vp8_find_free_buffer(VP8Context *s) · 33 unmodified lines
184167 av_log(s->avctx, AV_LOG_FATAL, "Ran out of free frames!\n");
185168 abort();
186169 }
187− if (frame->tf.f->buf[0])
170+ if (frame->tf.f)
188171 vp8_release_frame(frame);
189172
190173 return frame;
@@ -1830,7 +1813,7 @@ static const uint8_t subpel_idx[3][8] = { · 1639 unmodified lines
18301813 */
18311814 static av_always_inline
18321815 void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst,
1833− const ThreadFrame *ref, const VP8mv *mv,
1816+ const ProgressFrame *ref, const VP8mv *mv,
18341817 int x_off, int y_off, int block_w, int block_h,
18351818 int width, int height, ptrdiff_t linesize,
18361819 vp8_mc_func mc_func[3][3])
@@ -1847,7 +1830,7 @@ void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst, · 10 unmodified lines
18471830 y_off += mv->y >> 2;
18481831
18491832 // edge emulation
1850− ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 4, 0);
1833+ ff_progress_frame_await(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 4);
18511834 src += y_off * linesize + x_off;
18521835 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
18531836 y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {
@@ -1863,7 +1846,7 @@ void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst, · 9 unmodified lines
18631846 }
18641847 mc_func[my_idx][mx_idx](dst, linesize, src, src_linesize, block_h, mx, my);
18651848 } else {
1866− ff_thread_await_progress(ref, (3 + y_off + block_h) >> 4, 0);
1849+ ff_progress_frame_await(ref, (3 + y_off + block_h) >> 4);
18671850 mc_func[0][0](dst, linesize, src + y_off * linesize + x_off,
18681851 linesize, block_h, 0, 0);
18691852 }
@@ -1888,7 +1871,7 @@ void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst, · 18 unmodified lines
18881871 */
18891872 static av_always_inline
18901873 void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1,
1891− uint8_t *dst2, const ThreadFrame *ref, const VP8mv *mv,
1874+ uint8_t *dst2, const ProgressFrame *ref, const VP8mv *mv,
18921875 int x_off, int y_off, int block_w, int block_h,
18931876 int width, int height, ptrdiff_t linesize,
18941877 vp8_mc_func mc_func[3][3])
@@ -1905,7 +1888,7 @@ void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, · 10 unmodified lines
19051888 // edge emulation
19061889 src1 += y_off * linesize + x_off;
19071890 src2 += y_off * linesize + x_off;
1908− ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3, 0);
1891+ ff_progress_frame_await(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3);
19091892 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
19101893 y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {
19111894 s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
@@ -1930,7 +1913,7 @@ void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, · 18 unmodified lines
19301913 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
19311914 }
19321915 } else {
1933− ff_thread_await_progress(ref, (3 + y_off + block_h) >> 3, 0);
1916+ ff_progress_frame_await(ref, (3 + y_off + block_h) >> 3);
19341917 mc_func[0][0](dst1, linesize, src1 + y_off * linesize + x_off, linesize, block_h, 0, 0);
19351918 mc_func[0][0](dst2, linesize, src2 + y_off * linesize + x_off, linesize, block_h, 0, 0);
19361919 }
@@ -1938,7 +1921,7 @@ void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, · 1 unmodified line
19381921
19391922 static av_always_inline
19401923 void vp8_mc_part(VP8Context *s, VP8ThreadData *td, uint8_t *const dst[3],
1941− const ThreadFrame *ref_frame, int x_off, int y_off,
1924+ const ProgressFrame *ref_frame, int x_off, int y_off,
19421925 int bx_off, int by_off, int block_w, int block_h,
19431926 int width, int height, const VP8mv *mv)
19441927 {
@@ -2003,7 +1986,7 @@ void inter_predict(VP8Context *s, VP8ThreadData *td, uint8_t *const dst[3], · 58 unmodified lines
20031986 {
20041987 int x_off = mb_x << 4, y_off = mb_y << 4;
20051988 int width = 16 * s->mb_width, height = 16 * s->mb_height;
2006− const ThreadFrame *ref = &s->framep[mb->ref_frame]->tf;
1989+ const ProgressFrame *ref = &s->framep[mb->ref_frame]->tf;
20071990 const VP8mv *bmv = mb->bmv;
20081991
20091992 switch (mb->partitioning) {
@@ -2423,7 +2406,7 @@ static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void · 413 unmodified lines
24232406 // if we re-use the same map.
24242407 if (prev_frame && s->segmentation.enabled &&
24252408 !s->segmentation.update_map)
2426− ff_thread_await_progress(&prev_frame->tf, mb_y, 0);
2409+ ff_progress_frame_await(&prev_frame->tf, mb_y);
24272410 mb = s->macroblocks + (s->mb_height - mb_y - 1) * 2;
24282411 memset(mb - 1, 0, sizeof(*mb)); // zero left macroblock
24292412 AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED * 0x01010101);
@@ -2631,7 +2614,7 @@ int vp78_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata, int jobnr, · 201 unmodified lines
26312614 td->mv_bounds.mv_max.y -= 64 * num_jobs;
26322615
26332616 if (avctx->active_thread_type == FF_THREAD_FRAME)
2634− ff_thread_report_progress(&curframe->tf, mb_y, 0);
2617+ ff_progress_frame_report(&curframe->tf, mb_y);
26352618 }
26362619
26372620 return 0;
@@ -2699,7 +2682,7 @@ int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, · 61 unmodified lines
26992682
27002683 // release no longer referenced frames
27012684 for (i = 0; i < 5; i++)
2702− if (s->frames[i].tf.f->buf[0] &&
2685+ if (s->frames[i].tf.f &&
27032686 &s->frames[i] != prev_frame &&
27042687 &s->frames[i] != s->framep[VP8_FRAME_PREVIOUS] &&
27052688 &s->frames[i] != s->framep[VP8_FRAME_GOLDEN] &&
@@ -2728,14 +2711,14 @@ int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, · 22 unmodified lines
27282711 goto err;
27292712 }
27302713
2714+ if ((ret = vp8_alloc_frame(s, curframe, referenced)) < 0)
2715+ goto err;
27312716 if (s->keyframe)
27322717 curframe->tf.f->flags |= AV_FRAME_FLAG_KEY;
27332718 else
27342719 curframe->tf.f->flags &= ~AV_FRAME_FLAG_KEY;
27352720 curframe->tf.f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I
27362721 : AV_PICTURE_TYPE_P;
2737− if ((ret = vp8_alloc_frame(s, curframe, referenced)) < 0)
2738− goto err;
27392722
27402723 // check if golden and altref are swapped
27412724 if (s->update_altref != VP8_FRAME_NONE)
@@ -2792,7 +2775,7 @@ int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, · 50 unmodified lines
27922775 // if we re-use the same map.
27932776 if (prev_frame && s->segmentation.enabled &&
27942777 !s->segmentation.update_map)
2795− ff_thread_await_progress(&prev_frame->tf, 1, 0);
2778+ ff_progress_frame_await(&prev_frame->tf, 1);
27962779 if (is_vp7)
27972780 ret = vp7_decode_mv_mb_modes(avctx, curframe, prev_frame);
27982781 else
@@ -2823,7 +2806,7 @@ int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, · 24 unmodified lines
28232806 num_jobs);
28242807 }
28252808
2826− ff_thread_report_progress(&curframe->tf, INT_MAX, 0);
2809+ ff_progress_frame_report(&curframe->tf, INT_MAX);
28272810 memcpy(&s->framep[0], &s->next_framep[0], sizeof(s->framep[0]) * 4);
28282811
28292812 skip_decode:
@@ -2860,24 +2843,8 @@ static int vp7_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 30 unmodified lines
28602843
28612844 av_cold int ff_vp8_decode_free(AVCodecContext *avctx)
28622845 {
2863− VP8Context *s = avctx->priv_data;
2864− int i;
2865−
28662846 vp8_decode_flush_impl(avctx, 1);
2867− for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++)
2868− av_frame_free(&s->frames[i].tf.f);
2869−
2870− return 0;
2871−}
28722847
2873−static av_cold int vp8_init_frames(VP8Context *s)
2874−{
2875− int i;
2876− for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++) {
2877− s->frames[i].tf.f = av_frame_alloc();
2878− if (!s->frames[i].tf.f)
2879− return AVERROR(ENOMEM);
2880− }
28812848 return 0;
28822849 }
28832850
@@ -2885,7 +2852,6 @@ static av_always_inline · 1 unmodified line
28852852 int vp78_decode_init(AVCodecContext *avctx, int is_vp7)
28862853 {
28872854 VP8Context *s = avctx->priv_data;
2888− int ret;
28892855
28902856 s->avctx = avctx;
28912857 s->pix_fmt = AV_PIX_FMT_NONE;
@@ -2909,11 +2875,6 @@ int vp78_decode_init(AVCodecContext *avctx, int is_vp7) · 17 unmodified lines
29092875 /* does not change for VP8 */
29102876 memcpy(s->prob[0].scan, ff_zigzag_scan, sizeof(s->prob[0].scan));
29112877
2912− if ((ret = vp8_init_frames(s)) < 0) {
2913− ff_vp8_decode_free(avctx);
2914− return ret;
2915− }
2916−
29172878 return 0;
29182879 }
29192880
@@ -2931,13 +2892,20 @@ av_cold int ff_vp8_decode_init(AVCodecContext *avctx) · 11 unmodified lines
29312892
29322893 #if CONFIG_VP8_DECODER
29332894 #if HAVE_THREADS
2895+static void vp8_replace_frame(VP8Frame *dst, const VP8Frame *src)
2896+{
2897+ ff_progress_frame_replace(&dst->tf, &src->tf);
2898+ ff_refstruct_replace(&dst->seg_map, src->seg_map);
2899+ ff_refstruct_replace(&dst->hwaccel_picture_private,
2900+ src->hwaccel_picture_private);
2901+}
2902+
29342903 #define REBASE(pic) ((pic) ? (pic) - &s_src->frames[0] + &s->frames[0] : NULL)
29352904
29362905 static int vp8_decode_update_thread_context(AVCodecContext *dst,
29372906 const AVCodecContext *src)
29382907 {
29392908 VP8Context *s = dst->priv_data, *s_src = src->priv_data;
2940− int i;
29412909
29422910 if (s->macroblocks_base &&
29432911 (s_src->mb_width != s->mb_width || s_src->mb_height != s->mb_height)) {
@@ -2952,13 +2920,8 @@ static int vp8_decode_update_thread_context(AVCodecContext *dst, · 8 unmodified lines
29522920 s->lf_delta = s_src->lf_delta;
29532921 memcpy(s->sign_bias, s_src->sign_bias, sizeof(s->sign_bias));
29542922
2955− for (i = 0; i < FF_ARRAY_ELEMS(s_src->frames); i++) {
2956− if (s_src->frames[i].tf.f->buf[0]) {
2957− int ret = vp8_ref_frame(&s->frames[i], &s_src->frames[i]);
2958− if (ret < 0)
2959− return ret;
2960− }
2961− }
2923+ for (int i = 0; i < FF_ARRAY_ELEMS(s_src->frames); i++)
2924+ vp8_replace_frame(&s->frames[i], &s_src->frames[i]);
29622925
29632926 s->framep[0] = REBASE(s_src->next_framep[0]);
29642927 s->framep[1] = REBASE(s_src->next_framep[1]);
@@ -2982,6 +2945,7 @@ const FFCodec ff_vp7_decoder = { · 17 unmodified lines
29822945 FF_CODEC_DECODE_CB(vp7_decode_frame),
29832946 .p.capabilities = AV_CODEC_CAP_DR1,
29842947 .flush = vp8_decode_flush,
2948+ .caps_internal = FF_CODEC_CAP_USES_PROGRESSFRAMES,
29852949 };
29862950 #endif /* CONFIG_VP7_DECODER */
29872951
@@ -2997,7 +2961,7 @@ const FFCodec ff_vp8_decoder = { · 9 unmodified lines
29972961 FF_CODEC_DECODE_CB(ff_vp8_decode_frame),
29982962 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
29992963 AV_CODEC_CAP_SLICE_THREADS,
3000− .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS,
2964+ .caps_internal = FF_CODEC_CAP_USES_PROGRESSFRAMES,
30012965 .flush = vp8_decode_flush,
30022966 UPDATE_THREAD_CONTEXT(vp8_decode_update_thread_context),
30032967 .hw_configs = (const AVCodecHWConfigInternal *const []) {
libavcodec/vp8.h+3−2
@@ -31,8 +31,9 @@ · 30 unmodified lines
3131 #include "libavutil/mem_internal.h"
3232 #include "libavutil/thread.h"
3333
34+#include "avcodec.h"
3435 #include "h264pred.h"
35−#include "threadframe.h"
36+#include "progressframe.h"
3637 #include "videodsp.h"
3738 #include "vp8dsp.h"
3839 #include "vpx_rac.h"
@@ -150,7 +151,7 @@ typedef struct VP8ThreadData { · 111 unmodified lines
150151 } VP8ThreadData;
151152
152153 typedef struct VP8Frame {
153− ThreadFrame tf;
154+ ProgressFrame tf;
154155 uint8_t *seg_map; ///< RefStruct reference
155156
156157 void *hwaccel_picture_private; ///< RefStruct reference
libavcodec/webp.c+2−1
@@ -1571,5 +1571,6 @@ const FFCodec ff_webp_decoder = { · 1570 unmodified lines
15711571 FF_CODEC_DECODE_CB(webp_decode_frame),
15721572 .close = webp_decode_close,
15731573 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1574− .caps_internal = FF_CODEC_CAP_ICC_PROFILES,
1574+ .caps_internal = FF_CODEC_CAP_ICC_PROFILES |
1575+ FF_CODEC_CAP_USES_PROGRESSFRAMES,
15751576 };

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