Browse code

ffv1: Switch to ThreadFrame

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2013/04/28 05:21:16
Showing 4 changed files
... ...
@@ -49,8 +49,8 @@ av_cold int ffv1_common_init(AVCodecContext *avctx)
49 49
     s->avctx = avctx;
50 50
     s->flags = avctx->flags;
51 51
 
52
-    avcodec_get_frame_defaults(&s->picture);
53
-
52
+    s->picture.f = avcodec_alloc_frame();
53
+    s->last_picture.f = av_frame_alloc();
54 54
     ff_dsputil_init(&s->dsp, avctx);
55 55
 
56 56
     s->width  = avctx->width;
... ...
@@ -192,7 +192,13 @@ av_cold int ffv1_close(AVCodecContext *avctx)
192 192
     FFV1Context *s = avctx->priv_data;
193 193
     int i, j;
194 194
 
195
-    av_frame_unref(&s->last_picture);
195
+    if (s->picture.f)
196
+        ff_thread_release_buffer(avctx, &s->picture);
197
+    av_frame_free(&s->picture.f);
198
+
199
+    if (s->last_picture.f)
200
+        ff_thread_release_buffer(avctx, &s->last_picture);
201
+    av_frame_free(&s->last_picture.f);
196 202
 
197 203
     for (j = 0; j < s->slice_count; j++) {
198 204
         FFV1Context *fs = s->slice_context[j];
... ...
@@ -41,6 +41,7 @@
41 41
 #include "mathops.h"
42 42
 #include "put_bits.h"
43 43
 #include "rangecoder.h"
44
+#include "thread.h"
44 45
 
45 46
 #ifdef __INTEL_COMPILER
46 47
 #undef av_flatten
... ...
@@ -89,7 +90,7 @@ typedef struct FFV1Context {
89 89
     int transparency;
90 90
     int flags;
91 91
     int picture_number;
92
-    AVFrame picture, last_picture;
92
+    ThreadFrame picture, last_picture;
93 93
 
94 94
     AVFrame *cur;
95 95
     int plane_count;
... ...
@@ -38,7 +38,6 @@
38 38
 #include "golomb.h"
39 39
 #include "mathops.h"
40 40
 #include "ffv1.h"
41
-#include "thread.h"
42 41
 
43 42
 static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state,
44 43
                                                int is_signed)
... ...
@@ -734,14 +733,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
734 734
     int buf_size        = avpkt->size;
735 735
     FFV1Context *f      = avctx->priv_data;
736 736
     RangeCoder *const c = &f->slice_context[0]->c;
737
-    ThreadFrame frame = { .f = data };
738 737
     int i, ret;
739 738
     uint8_t keystate = 128;
740 739
     const uint8_t *buf_p;
741
-    AVFrame *const p    = data;
740
+    AVFrame *p;
742 741
 
743
-    f->cur = p;
744
-    f->avctx = avctx;
742
+    if (f->last_picture.f)
743
+        ff_thread_release_buffer(avctx, &f->last_picture);
744
+    FFSWAP(ThreadFrame, f->picture, f->last_picture);
745
+
746
+    f->cur = p = f->picture.f;
745 747
 
746 748
     ff_init_range_decoder(c, buf, buf_size);
747 749
     ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);
... ...
@@ -762,7 +763,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
762 762
         p->key_frame = 0;
763 763
     }
764 764
 
765
-    if ((ret = ff_thread_get_buffer(avctx, &frame, AV_GET_BUFFER_FLAG_REF)) < 0)
765
+    if ((ret = ff_thread_get_buffer(avctx, &f->picture, AV_GET_BUFFER_FLAG_REF)) < 0)
766 766
         return ret;
767 767
 
768 768
     if (avctx->debug & FF_DEBUG_PICT_INFO)
... ...
@@ -818,7 +819,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
818 818
     for (i = f->slice_count - 1; i >= 0; i--) {
819 819
         FFV1Context *fs = f->slice_context[i];
820 820
         int j;
821
-        if (fs->slice_damaged && f->last_picture.data[0]) {
821
+        if (fs->slice_damaged && f->last_picture.f->data[0]) {
822 822
             const uint8_t *src[4];
823 823
             uint8_t *dst[4];
824 824
             for (j = 0; j < 4; j++) {
... ...
@@ -826,11 +827,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
826 826
                 int sv = (j==1 || j==2) ? f->chroma_v_shift : 0;
827 827
                 dst[j] = p->data[j] + p->linesize[j]*
828 828
                          (fs->slice_y>>sv) + (fs->slice_x>>sh);
829
-                src[j] = f->last_picture.data[j] + f->last_picture.linesize[j]*
829
+                src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j]*
830 830
                          (fs->slice_y>>sv) + (fs->slice_x>>sh);
831 831
             }
832 832
             av_image_copy(dst, p->linesize, (const uint8_t **)src,
833
-                          f->last_picture.linesize,
833
+                          f->last_picture.f->linesize,
834 834
                           avctx->pix_fmt,
835 835
                           fs->slice_width,
836 836
                           fs->slice_height);
... ...
@@ -839,10 +840,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
839 839
 
840 840
     f->picture_number++;
841 841
 
842
-    av_frame_unref(&f->last_picture);
843
-    if ((ret = av_frame_ref(&f->last_picture, p)) < 0)
844
-        return ret;
842
+    if (f->last_picture.f)
843
+        ff_thread_release_buffer(avctx, &f->last_picture);
845 844
     f->cur = NULL;
845
+    if ((ret = av_frame_ref(data, f->picture.f)) < 0)
846
+        return ret;
846 847
 
847 848
     *got_frame = 1;
848 849
 
... ...
@@ -794,7 +794,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
794 794
     if ((ret = ffv1_allocate_initial_states(s)) < 0)
795 795
         return ret;
796 796
 
797
-    avctx->coded_frame = &s->picture;
797
+    avctx->coded_frame = s->picture.f;
798 798
     if (!s->transparency)
799 799
         s->plane_count = 2;
800 800
     avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift);
... ...
@@ -939,12 +939,12 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs)
939 939
         put_symbol(c, state, f->plane[j].quant_table_index, 0);
940 940
         av_assert0(f->plane[j].quant_table_index == f->avctx->context_model);
941 941
     }
942
-    if (!f->picture.interlaced_frame)
942
+    if (!f->picture.f->interlaced_frame)
943 943
         put_symbol(c, state, 3, 0);
944 944
     else
945
-        put_symbol(c, state, 1 + !f->picture.top_field_first, 0);
946
-    put_symbol(c, state, f->picture.sample_aspect_ratio.num, 0);
947
-    put_symbol(c, state, f->picture.sample_aspect_ratio.den, 0);
945
+        put_symbol(c, state, 1 + !f->picture.f->top_field_first, 0);
946
+    put_symbol(c, state, f->picture.f->sample_aspect_ratio.num, 0);
947
+    put_symbol(c, state, f->picture.f->sample_aspect_ratio.den, 0);
948 948
 }
949 949
 
950 950
 static int encode_slice(AVCodecContext *c, void *arg)
... ...
@@ -955,7 +955,7 @@ static int encode_slice(AVCodecContext *c, void *arg)
955 955
     int height       = fs->slice_height;
956 956
     int x            = fs->slice_x;
957 957
     int y            = fs->slice_y;
958
-    AVFrame *const p = &f->picture;
958
+    AVFrame *const p = f->picture.f;
959 959
     const int ps     = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step_minus1 + 1;
960 960
 
961 961
     if (p->key_frame)
... ...
@@ -1002,7 +1002,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
1002 1002
 {
1003 1003
     FFV1Context *f      = avctx->priv_data;
1004 1004
     RangeCoder *const c = &f->slice_context[0]->c;
1005
-    AVFrame *const p    = &f->picture;
1005
+    AVFrame *const p    = f->picture.f;
1006 1006
     int used_count      = 0;
1007 1007
     uint8_t keystate    = 128;
1008 1008
     uint8_t *buf_p;
... ...
@@ -1015,7 +1015,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
1015 1015
     ff_init_range_encoder(c, pkt->data, pkt->size);
1016 1016
     ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);
1017 1017
 
1018
-    *p           = *pict;
1018
+    av_frame_ref(p, pict);
1019 1019
     p->pict_type = AV_PICTURE_TYPE_I;
1020 1020
 
1021 1021
     if (avctx->gop_size == 0 || f->picture_number % avctx->gop_size == 0) {