[FFmpeg-devel,2/2] tools/uncoded_frame: remove usage of avfilter_link_get_channels()

Submitted by Nicolas George on Jan. 6, 2018, 1:20 p.m.

Details

Message ID 20180106132054.GA3277148@phare.normalesup.org
State New
Headers show

Commit Message

Nicolas George Jan. 6, 2018, 1:20 p.m.
James Almer (2018-01-05):
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  tools/uncoded_frame.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/uncoded_frame.c b/tools/uncoded_frame.c
> index 3ca2ba4bbe..c044741701 100644
> --- a/tools/uncoded_frame.c
> +++ b/tools/uncoded_frame.c
> @@ -178,7 +178,7 @@ int main(int argc, char **argv)
>              break;
>          case AVMEDIA_TYPE_AUDIO:
>              st->stream->codec->channel_layout = st->link->channel_layout;
> -            st->stream->codec->channels = avfilter_link_get_channels(st->link);
> +            st->stream->codec->channels = st->link->channels;
>              st->stream->codec->sample_rate = st->link->sample_rate;
>              st->stream->codec->sample_fmt = st->link->format;
>              st->stream->codec->codec_id =

Counter-proposal attached. With the evolution of lavfi, AVFilterLink
should have been made private entirely, but it never happened. Still,
the API to do without it exists.

Regards,

Patch hide | download patch | download mbox

From 6abecbd60f63a3a235e64d2c9a29d8d2e191a399 Mon Sep 17 00:00:00 2001
From: Nicolas George <george@nsup.org>
Date: Sat, 6 Jan 2018 14:14:04 +0100
Subject: [PATCH] tools/uncoded_frame: use buffersink accessors.

No longer access buffersink's link structure directly.

Signed-off-by: Nicolas George <george@nsup.org>
---
 tools/uncoded_frame.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/tools/uncoded_frame.c b/tools/uncoded_frame.c
index 3ca2ba4bbe..f346b21916 100644
--- a/tools/uncoded_frame.c
+++ b/tools/uncoded_frame.c
@@ -11,7 +11,6 @@  typedef struct {
     AVFormatContext *mux;
     AVStream *stream;
     AVFilterContext *sink;
-    AVFilterLink *link;
 } Stream;
 
 static int create_sink(Stream *st, AVFilterGraph *graph,
@@ -36,7 +35,6 @@  static int create_sink(Stream *st, AVFilterGraph *graph,
     ret = avfilter_link(f, idx, st->sink, 0);
     if (ret < 0)
         return ret;
-    st->link = st->sink->inputs[0];
     return 0;
 }
 
@@ -163,24 +161,24 @@  int main(int argc, char **argv)
             av_log(NULL, AV_LOG_ERROR, "Failed to create output stream\n");
             goto fail;
         }
-        st->stream->codec->codec_type = st->link->type;
+        st->stream->codec->codec_type = av_buffersink_get_type(st->sink);
         st->stream->time_base = st->stream->codec->time_base =
-            st->link->time_base;
-        switch (st->link->type) {
+            av_buffersink_get_time_base(st->sink);
+        switch (av_buffersink_get_type(st->sink)) {
         case AVMEDIA_TYPE_VIDEO:
             st->stream->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
             st->stream->avg_frame_rate =
             st->stream->  r_frame_rate = av_buffersink_get_frame_rate(st->sink);
-            st->stream->codec->width               = st->link->w;
-            st->stream->codec->height              = st->link->h;
-            st->stream->codec->sample_aspect_ratio = st->link->sample_aspect_ratio;
-            st->stream->codec->pix_fmt             = st->link->format;
+            st->stream->codec->width               = av_buffersink_get_w(st->sink);
+            st->stream->codec->height              = av_buffersink_get_h(st->sink);
+            st->stream->codec->sample_aspect_ratio = av_buffersink_get_sample_aspect_ratio(st->sink);
+            st->stream->codec->pix_fmt             = av_buffersink_get_format(st->sink);
             break;
         case AVMEDIA_TYPE_AUDIO:
-            st->stream->codec->channel_layout = st->link->channel_layout;
-            st->stream->codec->channels = avfilter_link_get_channels(st->link);
-            st->stream->codec->sample_rate = st->link->sample_rate;
-            st->stream->codec->sample_fmt = st->link->format;
+            st->stream->codec->channel_layout = av_buffersink_get_channel_layout(st->sink);
+            st->stream->codec->channels       = av_buffersink_get_channels(st->sink);
+            st->stream->codec->sample_rate    = av_buffersink_get_sample_rate(st->sink);
+            st->stream->codec->sample_fmt     = av_buffersink_get_format(st->sink);
             st->stream->codec->codec_id =
                 av_get_pcm_codec(st->stream->codec->sample_fmt, -1);
             break;
@@ -240,7 +238,7 @@  int main(int argc, char **argv)
                 }
                 if (frame->pts != AV_NOPTS_VALUE)
                     frame->pts = av_rescale_q(frame->pts,
-                                              st->link  ->time_base,
+                                              av_buffersink_get_time_base(st->sink),
                                               st->stream->time_base);
                 ret = av_interleaved_write_uncoded_frame(st->mux,
                                                          st->stream->index,
-- 
2.15.1