From patchwork Fri Apr 5 16:11:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 47838 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1069739pzd; Fri, 5 Apr 2024 09:14:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCULNSJdsvmfoTreU5YFevZTm4TbClQwcYii0LTAP5l2qjKY1UWs5p9ikIJmosPeSkMfY11uRIIX7FVt+kZcykcu2dnpZAj6M0a/dw== X-Google-Smtp-Source: AGHT+IFdIiYuDUfHQ6AJIlGdaQ0srFi3hCR8qAawBoSsgm3QeAH5/HTojxNhbIfeTeUNtNM8sVFj X-Received: by 2002:a17:906:fccc:b0:a51:7c31:24a7 with SMTP id qx12-20020a170906fccc00b00a517c3124a7mr2466027ejb.5.1712333683340; Fri, 05 Apr 2024 09:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712333683; cv=none; d=google.com; s=arc-20160816; b=RKmvGQvD6mHVQmlXtTsMOwvf7lvoXAwGGRMl+bZAOtcUjPXwV7aEDwIAkz3L5ZtDsw 4NVTDJn42UAvJzR8d7r5aH1AqrfOOTRB2cNPDLcaZRIVFakmFyZw7vH8HKB5uMYH0QGd Y5ykPOdm7vYbcjrc3ItLjHK2+v9AyuaM64YI/7GBAEMbwha86KBrZD/1wjyZQGC7yNde N3by/q2a+8F6cUhOXaQnwe1FRqjcFKmpIlVChM9kiI/EreqfzN44NuWIsiPn0COezpNG kpMvOzLYQp8nQfo9JV9xRGYMtv7Er0SV+oUPrP6kaSClmTdm//nvhkcFHwfvCP6Qm1Rn 7ghA== 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:dkim-signature:delivered-to; bh=IAO+1aWp6e/oav7shEnaFe+mKD91/nts3IDUkA0TrsA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=bUSySJ7e3VRg/fzk7Gv1zMbDJHIt3PKFShDauUI6JuDRegyWK3xm0Sshz/5VMx0VJG 5wZYJkpLwKq0Rb0CPA4YtyOS7WmPmKTKtrcl6EjyQLDhSJruCMAnqxZJd5YYMWvyRljy fqwME/z0cFtPc2ch1Pi23gljmxMxMGyeLU5x/qtaqv69Iwxixl0HFZmsD+K4dorHJmYB h3hXTHW/o347U+8LkBli9zA/f9Vwimvf4R3gCtTxbs8Q6xf0DQarx333UiOoH/pjqZoW DL5Ve8EmDmvAPy+UXCKASWCfibPMA1r6bu4/gy6FaCIJxDoPqpwfXM1zYb1t5eBSf/Sd z1bg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=hCmES+iY; 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 z22-20020a1709060ad600b00a4e6c0b39casi823969ejf.30.2024.04.05.09.14.16; Fri, 05 Apr 2024 09:14:43 -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; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=hCmES+iY; 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 7647E68D234; Fri, 5 Apr 2024 19:13:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3BA2168D15D for ; Fri, 5 Apr 2024 19:13:10 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=hCmES+iY; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 01BEE4D78 for ; Fri, 5 Apr 2024 18:13:06 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ZMpf4tEyyhkq for ; Fri, 5 Apr 2024 18:13:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1712333582; bh=LqeWBf3jrvlD3bUN0mTqjs72nlHByuX8HLo8m+d69Xg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hCmES+iYVlTciiD2vv5DP2ETlk5OCs9bkC1qBreVdBQLsZa/VyFBUez+zQgdmR6dU Fyk42ksFl1IOpmOvdCYL60NJ/+j26r6lmm9I7s3VTYQu06208S3cXlBs0BFIIt7Y/V sgDNdqyL7Wb32+XvL9k5IqQuF/C+S5cn4uU71sJZ9/4rmugovZ26VGapOM+hMBb46D xmMG/rPka3Z1Xd3eaha5wbLqBPckAV9uxc08/lcmAg1vddJUZL5kP2G43wzUPyhGm+ gJqUuZthWQ0SNXdhG3N4WgCTLBD6Dcwc0AA6xxPRa5nd+9E/6yzuZV/S5pykURamKQ U8CPDHKvvefOw== 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 mail1.khirnov.net (Postfix) with ESMTPS id 6232C4D8A for ; Fri, 5 Apr 2024 18:13:02 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3B4AC3A157E for ; Fri, 5 Apr 2024 18:12:56 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Apr 2024 18:11:58 +0200 Message-ID: <20240405161212.26167-17-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240405161212.26167-1-anton@khirnov.net> References: <20240405161212.26167-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/31] fftools/ffmpeg_filter: add an AVClass to OutputFilter 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: YVIJ4ZKNn6DO Use it for logging where appropriate, avoid logging to OutputStream as we do not own it. This is a step towards decoupling filtering from encoding. --- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_filter.c | 68 +++++++++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 3c196c25e5..786f925bc6 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -302,6 +302,8 @@ typedef struct InputFilter { } InputFilter; typedef struct OutputFilter { + const AVClass *class; + struct OutputStream *ost; struct FilterGraph *graph; uint8_t *name; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index ffbc13eb70..840502bd62 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -188,6 +188,9 @@ typedef struct OutputFilterPriv { int index; + void *log_parent; + char log_name[32]; + char *name; AVFilterContext *filter; @@ -629,7 +632,21 @@ static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in) avfilter_pad_get_name(pads, inout->pad_idx)); } -static OutputFilter *ofilter_alloc(FilterGraph *fg) +static const char *ofilter_item_name(void *obj) +{ + OutputFilterPriv *ofp = obj; + return ofp->log_name; +} + +static const AVClass ofilter_class = { + .class_name = "OutputFilter", + .version = LIBAVUTIL_VERSION_INT, + .item_name = ofilter_item_name, + .parent_log_context_offset = offsetof(OutputFilterPriv, log_parent), + .category = AV_CLASS_CATEGORY_FILTER, +}; + +static OutputFilter *ofilter_alloc(FilterGraph *fg, enum AVMediaType type) { OutputFilterPriv *ofp; OutputFilter *ofilter; @@ -639,10 +656,16 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg) return NULL; ofilter = &ofp->ofilter; + ofilter->class = &ofilter_class; + ofp->log_parent = fg; ofilter->graph = fg; + ofilter->type = type; ofp->format = -1; ofp->index = fg->nb_outputs - 1; + snprintf(ofp->log_name, sizeof(ofp->log_name), "%co%d", + av_get_media_type_string(type)[0], ofp->index); + return ofilter; } @@ -790,6 +813,14 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, if (!ofp->name) return AVERROR(EINVAL); + if (fgp->is_simple) { + // for simple filtergraph there is just one output, + // so use only graph-level information for logging + ofp->log_parent = NULL; + av_strlcpy(ofp->log_name, fgp->log_name, sizeof(ofp->log_name)); + } else + av_strlcatf(ofp->log_name, sizeof(ofp->log_name), "->%s", ofp->name); + switch (ofilter->type) { case AVMEDIA_TYPE_VIDEO: ofp->width = opts->width; @@ -1025,7 +1056,9 @@ int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch) } for (AVFilterInOut *cur = outputs; cur; cur = cur->next) { - OutputFilter *const ofilter = ofilter_alloc(fg); + const enum AVMediaType type = avfilter_pad_get_type(cur->filter_ctx->output_pads, + cur->pad_idx); + OutputFilter *const ofilter = ofilter_alloc(fg, type); if (!ofilter) { ret = AVERROR(ENOMEM); @@ -1035,8 +1068,6 @@ int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch) ofilter->linklabel = cur->name; cur->name = NULL; - ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads, - cur->pad_idx); ofilter->name = describe_filter_link(fg, cur, 0); if (!ofilter->name) { ret = AVERROR(ENOMEM); @@ -1400,7 +1431,7 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \ AVFilterContext *filt_ctx; \ \ - av_log(fg, AV_LOG_INFO, opt_name " is forwarded to lavfi " \ + av_log(ofilter, AV_LOG_INFO, opt_name " is forwarded to lavfi " \ "similarly to -af " filter_name "=%s.\n", arg); \ \ ret = avfilter_graph_create_filter(&filt_ctx, \ @@ -1929,7 +1960,7 @@ static int choose_out_timebase(OutputFilterPriv *ofp, AVFrame *frame) // apply -enc_time_base if (ofp->enc_timebase.num == ENC_TIME_BASE_DEMUX && (fd->dec.tb.num <= 0 || fd->dec.tb.den <= 0)) { - av_log(ofilter->ost, AV_LOG_ERROR, + av_log(ofp, AV_LOG_ERROR, "Demuxing timebase not available - cannot use it for encoding\n"); return AVERROR(EINVAL); } @@ -1956,7 +1987,7 @@ static int choose_out_timebase(OutputFilterPriv *ofp, AVFrame *frame) if (fps->vsync_method == VSYNC_CFR || fps->vsync_method == VSYNC_VSCFR) { if (!fr.num && !fps->framerate_max.num) { fr = (AVRational){25, 1}; - av_log(ofilter->ost, AV_LOG_WARNING, + av_log(ofp, AV_LOG_WARNING, "No information " "about the input framerate is available. Falling " "back to a default value of 25fps. Use the -r option " @@ -2039,7 +2070,6 @@ static void video_sync_process(OutputFilterPriv *ofp, AVFrame *frame, int64_t *nb_frames, int64_t *nb_frames_prev) { OutputFilter *ofilter = &ofp->ofilter; - OutputStream *ost = ofilter->ost; FPSConvContext *fps = &ofp->fps; double delta0, delta, sync_ipts, duration; @@ -2078,9 +2108,9 @@ static void video_sync_process(OutputFilterPriv *ofp, AVFrame *frame, #endif ) { if (delta0 < -0.6) { - av_log(ost, AV_LOG_VERBOSE, "Past duration %f too large\n", -delta0); + av_log(ofp, AV_LOG_VERBOSE, "Past duration %f too large\n", -delta0); } else - av_log(ost, AV_LOG_DEBUG, "Clipping frame in rate conversion by %f\n", -delta0); + av_log(ofp, AV_LOG_DEBUG, "Clipping frame in rate conversion by %f\n", -delta0); sync_ipts = ofp->next_pts; duration += delta0; delta0 = 0; @@ -2089,7 +2119,7 @@ static void video_sync_process(OutputFilterPriv *ofp, AVFrame *frame, switch (fps->vsync_method) { case VSYNC_VSCFR: if (fps->frame_number == 0 && delta0 >= 0.5) { - av_log(ost, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0)); + av_log(ofp, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0)); delta = duration; delta0 = 0; ofp->next_pts = llrint(sync_ipts); @@ -2133,23 +2163,23 @@ finish: if (*nb_frames_prev == 0 && fps->last_dropped) { atomic_fetch_add(&ofilter->nb_frames_drop, 1); - av_log(ost, AV_LOG_VERBOSE, + av_log(ofp, AV_LOG_VERBOSE, "*** dropping frame %"PRId64" at ts %"PRId64"\n", fps->frame_number, fps->last_frame->pts); } if (*nb_frames > (*nb_frames_prev && fps->last_dropped) + (*nb_frames > *nb_frames_prev)) { uint64_t nb_frames_dup; if (*nb_frames > dts_error_threshold * 30) { - av_log(ost, AV_LOG_ERROR, "%"PRId64" frame duplication too large, skipping\n", *nb_frames - 1); + av_log(ofp, AV_LOG_ERROR, "%"PRId64" frame duplication too large, skipping\n", *nb_frames - 1); atomic_fetch_add(&ofilter->nb_frames_drop, 1); *nb_frames = 0; return; } nb_frames_dup = atomic_fetch_add(&ofilter->nb_frames_dup, *nb_frames - (*nb_frames_prev && fps->last_dropped) - (*nb_frames > *nb_frames_prev)); - av_log(ost, AV_LOG_VERBOSE, "*** %"PRId64" dup!\n", *nb_frames - 1); + av_log(ofp, AV_LOG_VERBOSE, "*** %"PRId64" dup!\n", *nb_frames - 1); if (nb_frames_dup > fps->dup_warning) { - av_log(ost, AV_LOG_WARNING, "More than %"PRIu64" frames duplicated\n", fps->dup_warning); + av_log(ofp, AV_LOG_WARNING, "More than %"PRIu64" frames duplicated\n", fps->dup_warning); fps->dup_warning *= 10; } } @@ -2191,7 +2221,7 @@ static int close_output(OutputFilterPriv *ofp, FilterGraphThread *fgt) av_assert0(!frame->buf[0]); - av_log(ofp->ofilter.ost, AV_LOG_WARNING, + av_log(ofp, AV_LOG_WARNING, "No filtered frames for output stream, trying to " "initialize anyway.\n"); @@ -2308,7 +2338,7 @@ static int fg_output_step(OutputFilterPriv *ofp, FilterGraphThread *fgt, } else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { return 1; } else if (ret < 0) { - av_log(fgp, AV_LOG_WARNING, + av_log(ofp, AV_LOG_WARNING, "Error in retrieving a frame from the filtergraph: %s\n", av_err2str(ret)); return ret; @@ -2322,7 +2352,7 @@ static int fg_output_step(OutputFilterPriv *ofp, FilterGraphThread *fgt, frame->time_base = av_buffersink_get_time_base(filter); if (debug_ts) - av_log(fgp, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n", + av_log(ofp, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n", av_ts2str(frame->pts), av_ts2timestr(frame->pts, &frame->time_base), frame->time_base.num, frame->time_base.den); @@ -2330,7 +2360,7 @@ static int fg_output_step(OutputFilterPriv *ofp, FilterGraphThread *fgt, if (!ofp->tb_out_locked) { ret = choose_out_timebase(ofp, frame); if (ret < 0) { - av_log(ost, AV_LOG_ERROR, "Could not choose an output time base\n"); + av_log(ofp, AV_LOG_ERROR, "Could not choose an output time base\n"); av_frame_unref(frame); return ret; }