[FFmpeg-devel] [PATCH v2 2/3] avdevice/lavfi: use wrapped_avframe

Muhammad Faiz mfcc64 at gmail.com
Sun Nov 15 09:52:54 CET 2015


use wrapped_avframe on both audio and video

remove metadata because it already exists in
the underlying AVFrame

patch attached
-------------- next part --------------
From cd288bce6b433f1e3cbdd29a06e5d6247f7bf33e Mon Sep 17 00:00:00 2001
From: Muhammad Faiz <mfcc64 at gmail.com>
Date: Sun, 15 Nov 2015 09:09:39 +0700
Subject: [PATCH v2 2/3] avdevice/lavfi: use wrapped_avframe

use wrapped_avframe on both audio and video

remove metadata because it already exists in
the underlying AVFrame
---
 libavdevice/lavfi.c   | 63 ++++++---------------------------------------------
 libavdevice/version.h |  2 +-
 2 files changed, 8 insertions(+), 57 deletions(-)

diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index 3453b4d..943aec1 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -311,28 +311,20 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
         st->codec->codec_type = link->type;
         avpriv_set_pts_info(st, 64, link->time_base.num, link->time_base.den);
         if (link->type == AVMEDIA_TYPE_VIDEO) {
-            st->codec->codec_id   = AV_CODEC_ID_RAWVIDEO;
+            st->codec->codec_id   = AV_CODEC_ID_WRAPPED_AVFRAME;
             st->codec->pix_fmt    = link->format;
             st->codec->time_base  = link->time_base;
             st->codec->width      = link->w;
             st->codec->height     = link->h;
             st       ->sample_aspect_ratio =
             st->codec->sample_aspect_ratio = link->sample_aspect_ratio;
-            avctx->probesize = FFMAX(avctx->probesize,
-                                     link->w * link->h *
-                                     av_get_padded_bits_per_pixel(av_pix_fmt_desc_get(link->format)) *
-                                     30);
         } else if (link->type == AVMEDIA_TYPE_AUDIO) {
-            st->codec->codec_id    = av_get_pcm_codec(link->format, -1);
+            st->codec->codec_id    = AV_CODEC_ID_WRAPPED_AVFRAME_AUDIO;
             st->codec->channels    = avfilter_link_get_channels(link);
             st->codec->sample_fmt  = link->format;
             st->codec->sample_rate = link->sample_rate;
             st->codec->time_base   = link->time_base;
             st->codec->channel_layout = link->channel_layout;
-            if (st->codec->codec_id == AV_CODEC_ID_NONE)
-                av_log(avctx, AV_LOG_ERROR,
-                       "Could not find PCM codec for sample format %s.\n",
-                       av_get_sample_fmt_name(link->format));
         }
     }
 
@@ -381,10 +373,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
     double min_pts = DBL_MAX;
     int stream_idx, min_pts_sink_idx = 0;
     AVFrame *frame = lavfi->decoded_frame;
-    AVPicture pict;
-    AVDictionary *frame_metadata;
     int ret, i;
-    int size = 0;
 
     if (lavfi->subcc_packet.size) {
         *pkt = lavfi->subcc_packet;
@@ -429,45 +418,10 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
     av_buffersink_get_frame_flags(lavfi->sinks[min_pts_sink_idx], frame, 0);
     stream_idx = lavfi->sink_stream_map[min_pts_sink_idx];
 
-    if (frame->width /* FIXME best way of testing a video */) {
-        size = avpicture_get_size(frame->format, frame->width, frame->height);
-        if ((ret = av_new_packet(pkt, size)) < 0)
-            return ret;
-
-        memcpy(pict.data,     frame->data,     4*sizeof(frame->data[0]));
-        memcpy(pict.linesize, frame->linesize, 4*sizeof(frame->linesize[0]));
-
-        avpicture_layout(&pict, frame->format, frame->width, frame->height,
-                         pkt->data, size);
-    } else if (av_frame_get_channels(frame) /* FIXME test audio */) {
-        size = frame->nb_samples * av_get_bytes_per_sample(frame->format) *
-                                   av_frame_get_channels(frame);
-        if ((ret = av_new_packet(pkt, size)) < 0)
-            return ret;
-        memcpy(pkt->data, frame->data[0], size);
-    }
-
-    frame_metadata = av_frame_get_metadata(frame);
-    if (frame_metadata) {
-        uint8_t *metadata;
-        AVDictionaryEntry *e = NULL;
-        AVBPrint meta_buf;
-
-        av_bprint_init(&meta_buf, 0, AV_BPRINT_SIZE_UNLIMITED);
-        while ((e = av_dict_get(frame_metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
-            av_bprintf(&meta_buf, "%s", e->key);
-            av_bprint_chars(&meta_buf, '\0', 1);
-            av_bprintf(&meta_buf, "%s", e->value);
-            av_bprint_chars(&meta_buf, '\0', 1);
-        }
-        if (!av_bprint_is_complete(&meta_buf) ||
-            !(metadata = av_packet_new_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,
-                                                 meta_buf.len))) {
-            av_bprint_finalize(&meta_buf, NULL);
-            return AVERROR(ENOMEM);
-        }
-        memcpy(metadata, meta_buf.str, meta_buf.len);
-        av_bprint_finalize(&meta_buf, NULL);
+    if ((ret = av_packet_encode_frame(pkt, frame)) < 0) {
+        av_frame_unref(frame);
+        av_packet_unref(pkt);
+        return ret;
     }
 
     if ((ret = create_subcc_packet(avctx, frame, min_pts_sink_idx)) < 0) {
@@ -477,11 +431,8 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
     }
 
     pkt->stream_index = stream_idx;
-    pkt->pts = frame->pts;
-    pkt->pos = av_frame_get_pkt_pos(frame);
-    pkt->size = size;
     av_frame_unref(frame);
-    return size;
+    return pkt->size;
 }
 
 #define OFFSET(x) offsetof(LavfiContext, x)
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 45c9e8d..b226a76 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVDEVICE_VERSION_MAJOR  57
 #define LIBAVDEVICE_VERSION_MINOR   0
-#define LIBAVDEVICE_VERSION_MICRO 100
+#define LIBAVDEVICE_VERSION_MICRO 101
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
                                                LIBAVDEVICE_VERSION_MINOR, \
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list