Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 11/21] fftools/ffmpeg_filter: add an AVClass to FilterGraph
Date: Wed, 14 Jun 2023 18:48:58 +0200
Message-ID: <20230614164908.28712-11-anton@khirnov.net> (raw)
In-Reply-To: <20230614164908.28712-1-anton@khirnov.net>

Use it for logging.
---
 fftools/ffmpeg.h        |  1 +
 fftools/ffmpeg_filter.c | 59 +++++++++++++++++++++++++++++------------
 2 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 3c7e819507..8de8e94e31 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -311,6 +311,7 @@ typedef struct OutputFilter {
 } OutputFilter;
 
 typedef struct FilterGraph {
+    const AVClass *class;
     int            index;
 
     AVFilterGraph *graph;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index a2b45a14b8..4f7565e44e 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -41,6 +41,9 @@
 typedef struct FilterGraphPriv {
     FilterGraph fg;
 
+    // name used for logging
+    char log_name[32];
+
     int is_simple;
 
     const char *graph_desc;
@@ -692,7 +695,7 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
 
         ret = configure_filtergraph(fg);
         if (ret < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Error configuring filter graph: %s\n",
+            av_log(fg, AV_LOG_ERROR, "Error configuring filter graph: %s\n",
                    av_err2str(ret));
             exit_program(1);
         }
@@ -775,6 +778,20 @@ void fg_free(FilterGraph **pfg)
     av_freep(pfg);
 }
 
+static const char *fg_item_name(void *obj)
+{
+    const FilterGraphPriv *fgp = obj;
+
+    return fgp->log_name;
+}
+
+static const AVClass fg_class = {
+    .class_name = "FilterGraph",
+    .version    = LIBAVUTIL_VERSION_INT,
+    .item_name  = fg_item_name,
+    .category   = AV_CLASS_CATEGORY_FILTER,
+};
+
 FilterGraph *fg_create(char *graph_desc)
 {
     FilterGraphPriv *fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs);
@@ -784,9 +801,12 @@ FilterGraph *fg_create(char *graph_desc)
     AVFilterGraph *graph;
     int ret = 0;
 
+    fg->class       = &fg_class;
     fg->index      = nb_filtergraphs - 1;
     fgp->graph_desc = graph_desc;
 
+    snprintf(fgp->log_name, sizeof(fgp->log_name), "fc#%d", fg->index);
+
     fgp->frame = av_frame_alloc();
     if (!fgp->frame)
         report_and_exit(AVERROR(ENOMEM));
@@ -850,8 +870,12 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
 
     fgp->is_simple = 1;
 
+    snprintf(fgp->log_name, sizeof(fgp->log_name), "%cf#%d:%d",
+             av_get_media_type_string(ost->type)[0],
+             ost->file_index, ost->index);
+
     if (fg->nb_inputs != 1 || fg->nb_outputs != 1) {
-        av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
+        av_log(fg, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
                "to have exactly 1 input and 1 output. "
                "However, it had %d input(s) and %d output(s). Please adjust, "
                "or use a complex filtergraph (-filter_complex) instead.\n",
@@ -880,7 +904,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
 
     // TODO: support other filter types
     if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
-        av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
+        av_log(fg, AV_LOG_FATAL, "Only video and audio filters supported "
                "currently.\n");
         exit_program(1);
     }
@@ -892,7 +916,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
         int file_idx = strtol(ifp->linklabel, &p, 0);
 
         if (file_idx < 0 || file_idx >= nb_input_files) {
-            av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
+            av_log(fg, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
                    file_idx, fgp->graph_desc);
             exit_program(1);
         }
@@ -910,7 +934,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
             }
         }
         if (!st) {
-            av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
+            av_log(fg, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
                    "matches no streams.\n", p, fgp->graph_desc);
             exit_program(1);
         }
@@ -918,7 +942,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
     } else {
         ist = ist_find_unused(type);
         if (!ist) {
-            av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
+            av_log(fg, AV_LOG_FATAL, "Cannot find a matching stream for "
                    "unlabeled input pad %s\n", ifilter->name);
             exit_program(1);
         }
@@ -927,7 +951,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
 
     ret = ifilter_bind_ist(ifilter, ist);
     if (ret < 0) {
-        av_log(NULL, AV_LOG_ERROR,
+        av_log(fg, AV_LOG_ERROR,
                "Error binding an input stream to complex filtergraph input %s.\n",
                ifilter->name);
         exit_program(1);
@@ -1111,7 +1135,7 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do {                 \
     AVFilterContext *filt_ctx;                                              \
                                                                             \
-    av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi "            \
+    av_log(fg, AV_LOG_INFO, opt_name " is forwarded to lavfi "              \
            "similarly to -af " filter_name "=%s.\n", arg);                  \
                                                                             \
     ret = avfilter_graph_create_filter(&filt_ctx,                           \
@@ -1200,7 +1224,7 @@ static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter,
                                    AVFilterInOut *out)
 {
     if (!ofilter->ost) {
-        av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name);
+        av_log(fg, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name);
         exit_program(1);
     }
 
@@ -1219,7 +1243,8 @@ void check_filter_outputs(void)
         for (n = 0; n < filtergraphs[i]->nb_outputs; n++) {
             OutputFilter *output = filtergraphs[i]->outputs[n];
             if (!output->ost) {
-                av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", output->name);
+                av_log(filtergraphs[i], AV_LOG_FATAL,
+                       "Filter %s has an unconnected output\n", output->name);
                 exit_program(1);
             }
         }
@@ -1261,7 +1286,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
     par->format = AV_PIX_FMT_NONE;
 
     if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-        av_log(NULL, AV_LOG_ERROR, "Cannot connect video filter to audio input\n");
+        av_log(fg, AV_LOG_ERROR, "Cannot connect video filter to audio input\n");
         ret = AVERROR(EINVAL);
         goto fail;
     }
@@ -1376,7 +1401,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
     int64_t tsoffset = 0;
 
     if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_AUDIO) {
-        av_log(NULL, AV_LOG_ERROR, "Cannot connect audio filter to non audio input\n");
+        av_log(fg, AV_LOG_ERROR, "Cannot connect audio filter to non audio input\n");
         return AVERROR(EINVAL);
     }
 
@@ -1685,7 +1710,7 @@ int reap_filters(int flush)
                                                AV_BUFFERSINK_FLAG_NO_REQUEST);
             if (ret < 0) {
                 if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
-                    av_log(NULL, AV_LOG_WARNING,
+                    av_log(fgp, AV_LOG_WARNING,
                            "Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret));
                 } else if (flush && ret == AVERROR_EOF) {
                     if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO)
@@ -1705,7 +1730,7 @@ int reap_filters(int flush)
                 filtered_frame->time_base = tb;
 
                 if (debug_ts)
-                    av_log(NULL, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n",
+                    av_log(fgp, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n",
                            av_ts2str(filtered_frame->pts),
                            av_ts2timestr(filtered_frame->pts, &tb),
                            tb.num, tb.den);
@@ -1896,13 +1921,13 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
 
         ret = reap_filters(0);
         if (ret < 0 && ret != AVERROR_EOF) {
-            av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
+            av_log(fg, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
             return ret;
         }
 
         ret = configure_filtergraph(fg);
         if (ret < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Error reinitializing filters!\n");
+            av_log(fg, AV_LOG_ERROR, "Error reinitializing filters!\n");
             return ret;
         }
     }
@@ -1929,7 +1954,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
     if (ret < 0) {
         av_frame_unref(frame);
         if (ret != AVERROR_EOF)
-            av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
+            av_log(fg, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
         return ret;
     }
 
-- 
2.40.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2023-06-14 16:52 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14 16:48 [FFmpeg-devel] [PATCH 01/21] fftools/ffmpeg_dec: drop always-0 InputStream.prev_sub.ret Anton Khirnov
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 02/21] fftools/ffmpeg_dec: simplify process_subtitle() Anton Khirnov
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 03/21] tests/fate: rename ffmpeg-streamloop to ffmpeg-streamloop-copy Anton Khirnov
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 04/21] tests/fate: add a test for -streamloop with transcoding video+audio Anton Khirnov
2023-06-14 16:57   ` Andreas Rheinhardt
2023-06-16  6:01     ` [FFmpeg-devel] [PATCH 04/21 v2] " Anton Khirnov
2023-06-19 10:52       ` "zhilizhao(赵志立)"
2023-06-19 12:29       ` James Almer
2023-06-19 12:34         ` "zhilizhao(赵志立)"
2023-06-19 13:22           ` James Almer
2023-06-19 13:39             ` Zhao Zhili
2023-06-19 15:48               ` Lynne
2023-06-19 20:33                 ` Martin Storsjö
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 05/21] fftools/ffmpeg_demux: move the loop out of add_input_streams() Anton Khirnov
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 06/21] fftools/ffmpeg_demux: reindent after previous commit Anton Khirnov
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 07/21] fftools/ffmpeg_hw: inline hwaccel_decode_init() into its caller Anton Khirnov
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 08/21] fftools/ffmpeg_dec: remove pointless InputStream.hwaccel_retrieve_data Anton Khirnov
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 09/21] fftools/ffmpeg_dec: move InputStream.hwaccel_pix_fmt to Decoder Anton Khirnov
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 10/21] fftools/ffmpeg_enc: move dup_warning global variable to Encoder Anton Khirnov
2023-06-14 16:48 ` Anton Khirnov [this message]
2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 12/21] fftools/ffmpeg_filter: reject filtergraphs with zero outputs Anton Khirnov
2023-06-14 16:53   ` Paul B Mahol
2023-06-14 17:00     ` Anton Khirnov
2023-06-14 17:11       ` Paul B Mahol
2023-06-14 17:14         ` Anton Khirnov
2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 13/21] fftools/ffmpeg_filter: make configure_filtergraph() static Anton Khirnov
2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 14/21] fftools/ffmpeg_dec: stop using Decoder.pkt Anton Khirnov
2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 15/21] fftools/ffmpeg: attach bits_per_raw_sample information to frames Anton Khirnov
2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 16/21] fftools/ffmpeg_dec: move decoding to a separate thread Anton Khirnov
2023-06-16 20:58   ` Michael Niedermayer
2023-06-17  2:55     ` Anton Khirnov
2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 17/21] fftools/ffmpeg: move fix_sub_duration_heartbeat() to ffmpeg_dec Anton Khirnov
2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 18/21] fftools/ffmpeg_dec: move InputStream.prev_sub to Decoder Anton Khirnov
2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 19/21] fftools/ffmpeg_enc: constify the subtitle passed to enc_subtitle() Anton Khirnov
2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 20/21] fftools/ffmpeg: use AVFrame to pass subtitles from decoders to filters Anton Khirnov
2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 21/21] fftools/ffmpeg: pass subtitle decoder dimensions to sub2video Anton Khirnov
2023-06-18  8:35 ` [FFmpeg-devel] [PATCH 01/21] fftools/ffmpeg_dec: drop always-0 InputStream.prev_sub.ret Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230614164908.28712-11-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git