From patchwork Wed Jun 14 16:48:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42079 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp191859pzb; Wed, 14 Jun 2023 09:52:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ70qBfkDq8VazzmDP1HNb/UoabIOcNvCjQFbo1HEtTB+0BuLayWGzQUHOCA7kpDL49HcpVh X-Received: by 2002:a19:6445:0:b0:4f3:9868:bee4 with SMTP id b5-20020a196445000000b004f39868bee4mr8612932lfj.32.1686761579707; Wed, 14 Jun 2023 09:52:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686761579; cv=none; d=google.com; s=arc-20160816; b=nIjbkfu8434pHTwMHnSnH7xZXh3g3OlLMvnnQhR3fp5Y6UMnkfG7iZSr/NNiY64Pjv TCav1cleD8kk4GDgsGrqSARiEspjDJPfc5NPzG3/V0KdZ/ljC+jnGcRy+cLh8QmQqG+G mhZaFN6Nat1dKBBLGh2QHBeqAePe1snfeu/rPlV8Gnt2/0kIyPaXzIVCZySEMLjxIBUZ lHn4fk/2ezQe1yxW1UqC8yxTF4p1SfsfNQCqn/8PWjUyegDNa5yCanyWf96LDUTaPXnp Bl5WRt8CCU9f0Ewn2DYMktYxCeBlb0OmLJGTazurd+oGOT/m2ZswQV8MMx/JIa6qB3xm jQOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=62FlVfbrkzsayrOhGsmkdfNwzuVoK8TDCPXRtuO+0SQ=; b=KzljV2TX0DIpID6Adz4SAS3Y9u4EXzfFuMHl3GXTWMMRGrEoPurRJnZ7zGEZiGE9rZ CuTTaK41IMGzIRVQCKktjhol+UKeDz5OMgerLgDEspEf1JYEbkA8cOBQLtrEj8RWd8hZ pTwB4IgzrD6ZMjTPVBiAQ1nDl1bT4+76Du3OXt0acUdD2iVHSsjQUjmkCZ9l4t4+JaUm CeIO1/NlMPZFSI2sEhvh4DYnKTOxsBLG0uyR5O9cgMinx/2mDRdc45I6EHspfDgXEF+G LWgaEHFCuY4Cy10LcYEkA6hT3MLCxCUSBf9GWu4zICjmPPxhwn5GKc8/a4VONQIGmkjg 88nQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z24-20020aa7cf98000000b00518740a7553si2560153edx.276.2023.06.14.09.52.59; Wed, 14 Jun 2023 09:52:59 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 153DC68C505; Wed, 14 Jun 2023 19:50:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E9BF68C35F for ; Wed, 14 Jun 2023 19:50:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1F25D2404F8 for ; Wed, 14 Jun 2023 18:49:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id uWReyzCGmjSs for ; Wed, 14 Jun 2023 18:49:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id ED60A2406CB for ; Wed, 14 Jun 2023 18:49:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9C8C13A08D4 for ; Wed, 14 Jun 2023 18:49:47 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Jun 2023 18:48:58 +0200 Message-Id: <20230614164908.28712-11-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614164908.28712-1-anton@khirnov.net> References: <20230614164908.28712-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/21] fftools/ffmpeg_filter: add an AVClass to FilterGraph X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: LxcL8LqITvjn 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; }