lavfi: add avfilter_copy_frame_props()
authorStefano Sabatini <stefano.sabatini-lala@poste.it>
Sun, 1 May 2011 12:47:05 +0000 (14:47 +0200)
committerAnton Khirnov <anton@khirnov.net>
Sun, 25 Dec 2011 15:18:57 +0000 (16:18 +0100)
avfilter_copy_frame_props() avoids code duplication and increases
robustness.

avplay.c
libavfilter/avfilter.c
libavfilter/avfilter.h
libavfilter/vsrc_buffer.c
libavfilter/vsrc_movie.c

index bf246f2..c217010 100644 (file)
--- a/avplay.c
+++ b/avplay.c
@@ -1649,9 +1649,9 @@ static int input_request_frame(AVFilterLink *link)
     }
     av_free_packet(&pkt);
 
+    avfilter_copy_frame_props(picref, priv->frame);
     picref->pts = pts;
-    picref->pos = pkt.pos;
-    picref->video->pixel_aspect = priv->frame->sample_aspect_ratio;
+
     avfilter_start_frame(link, picref);
     avfilter_draw_slice(link, 0, link->h, 1);
     avfilter_end_frame(link);
index b0304d6..d426591 100644 (file)
@@ -25,6 +25,7 @@
 #include "libavutil/rational.h"
 #include "libavutil/audioconvert.h"
 #include "libavutil/imgutils.h"
+#include "libavcodec/avcodec.h"
 #include "avfilter.h"
 #include "internal.h"
 
@@ -681,3 +682,21 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
     return ret;
 }
 
+int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
+{
+    if (dst->type != AVMEDIA_TYPE_VIDEO)
+        return AVERROR(EINVAL);
+
+    dst->pts    = src->pts;
+    dst->format = src->format;
+
+    dst->video->w                   = src->width;
+    dst->video->h                   = src->height;
+    dst->video->pixel_aspect        = src->sample_aspect_ratio;
+    dst->video->interlaced          = src->interlaced_frame;
+    dst->video->top_field_first     = src->top_field_first;
+    dst->video->key_frame           = src->key_frame;
+    dst->video->pict_type           = src->pict_type;
+
+    return 0;
+}
index e0c664d..a5cc8b2 100644 (file)
@@ -27,6 +27,7 @@
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/rational.h"
+#include "libavcodec/avcodec.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  2
 #define LIBAVFILTER_VERSION_MINOR  13
@@ -862,4 +863,12 @@ static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
                         &f->output_pads, &f->outputs, p);
 }
 
+/**
+ * Copy the frame properties of src to dst, without copying the actual
+ * image data.
+ *
+ * @return 0 on success, a negative number on error.
+ */
+int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
+
 #endif /* AVFILTER_AVFILTER_H */
index 1f0233e..982fed5 100644 (file)
@@ -131,12 +131,9 @@ static int request_frame(AVFilterLink *link)
                   c->frame.data, c->frame.linesize,
                   picref->format, link->w, link->h);
 
+    avfilter_copy_frame_props(picref, &c->frame);
     picref->pts                    = c->pts;
     picref->video->pixel_aspect    = c->pixel_aspect;
-    picref->video->interlaced      = c->frame.interlaced_frame;
-    picref->video->top_field_first = c->frame.top_field_first;
-    picref->video->key_frame       = c->frame.key_frame;
-    picref->video->pict_type       = c->frame.pict_type;
     avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
     avfilter_draw_slice(link, 0, link->h, 1);
     avfilter_end_frame(link);
index a176473..4ac079c 100644 (file)
@@ -240,6 +240,7 @@ static int movie_get_frame(AVFilterLink *outlink)
                 av_image_copy(movie->picref->data, movie->picref->linesize,
                               movie->frame->data,  movie->frame->linesize,
                               movie->picref->format, outlink->w, outlink->h);
+                avfilter_copy_frame_props(movie->picref, movie->frame);
 
                 /* FIXME: use a PTS correction mechanism as that in
                  * ffplay.c when some API will be available for that */
@@ -250,10 +251,6 @@ static int movie_get_frame(AVFilterLink *outlink)
                 movie->picref->pos                    = movie->frame->reordered_opaque;
                 if (!movie->frame->sample_aspect_ratio.num)
                     movie->picref->video->pixel_aspect = st->sample_aspect_ratio;
-                movie->picref->video->interlaced      = movie->frame->interlaced_frame;
-                movie->picref->video->top_field_first = movie->frame->top_field_first;
-                movie->picref->video->key_frame       = movie->frame->key_frame;
-                movie->picref->video->pict_type       = movie->frame->pict_type;
                 av_dlog(outlink->src,
                         "movie_get_frame(): file:'%s' pts:%"PRId64" time:%lf pos:%"PRId64" aspect:%d/%d\n",
                         movie->file_name, movie->picref->pts,