From patchwork Wed Apr 21 12:27:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 27201 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp350132iob; Wed, 21 Apr 2021 05:28:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZSd7Nu7XlcgVg8msnAqTa9mgUK7JuUaiMdSS1UhmRT8C+apbu6Q69XzzMFeUAObghu7Ab X-Received: by 2002:a05:6402:5111:: with SMTP id m17mr18095171edd.175.1619008105793; Wed, 21 Apr 2021 05:28:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619008105; cv=none; d=google.com; s=arc-20160816; b=qvF2a4NUU4cAN1vAVlBsMEIcQnDJg+KK4Ilpe/h7TqYmq14sGoWzLDOaNPFXy9ka6P Gx24rBD1MjglUB45yVMb+8a1GbdFKr5gt2/qE9XI+I4YML47dWEHglEE6rWbpCrweeow 6lx+3+2UnFDAh3htUMxD9q0hvxiqcEVbYBPdnMmTEZw6pB1iJEVqwcBk37WlnS7iZ3ic haQy+ypMRXqTkOXNoV9mAMtbqZ+so8i5itURrcc4HTBVz+nP35TvD4YWHYuWnqUpVfqk gK2g1wIRj89XFalpST5dV96Q/z+Z5HrOArPgLfcpowYAvJOJhk6sSbBVYhZ+R45HftUz nvqA== 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=74eGPAL2ljmRVp3m2PF8wXpVxqUCPsvYD+t2O7lgOo8=; b=K/lj1i0EcQedawAAfBNq5OZ9NnzoDyBEsL6lAqI3SVYqt7rMme5YXjLm7+k3jtdlzW xh53nrtIlnMefBASizJpcPVeYamdNE+2XKvvVLP2JJSl4QJyQbIbIR+Uy5eeQX2UowAa +IPT0NnFYwzJ4HiqOuuXmHdSuPb+OvaOfpg/pdVfzUbA2W3AU6uEaTRxoO3KrMF2VHuQ aBdLI9X5umoh1/FuDLP7LfUKTqNVzyMRPIKFWHA4+eMyrVBHChHh+Cu+0QRYyBrM+YI6 MxMqxS71MFZMmvDzdjnCb62PMRRMtSurHUX3q7WHbPeY5+n4VpbiFDI77Hhar9oHMLDK LKAw== 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 d26si1629444ejt.459.2021.04.21.05.28.25; Wed, 21 Apr 2021 05:28:25 -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 EC3A6689BBC; Wed, 21 Apr 2021 15:27:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0441D6899E4 for ; Wed, 21 Apr 2021 15:27:13 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 13LCRBED006290 for ; Wed, 21 Apr 2021 14:27:12 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 60D58EB5BF; Wed, 21 Apr 2021 14:27:11 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Apr 2021 14:27:03 +0200 Message-Id: <20210421122706.9002-5-george@nsup.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210421122706.9002-1-george@nsup.org> References: <20210421122706.9002-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Wed, 21 Apr 2021 14:27:13 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 4/7] lavf/dump: use a writer. 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: qfzVVKHjE04W Signed-off-by: Nicolas George --- libavformat/avformat.h | 21 +++ libavformat/dump.c | 317 +++++++++++++++++++++-------------------- 2 files changed, 185 insertions(+), 153 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 41482328f6..13e07ee114 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -312,6 +312,7 @@ #include "libavcodec/avcodec.h" #include "libavutil/dict.h" #include "libavutil/log.h" +#include "libavutil/writer.h" #include "avio.h" #include "libavformat/version.h" @@ -2787,6 +2788,26 @@ void av_dump_format(AVFormatContext *ic, const char *url, int is_output); +/** + * Write detailed information about the input or output format, such as + * duration, bitrate, streams, container, programs, metadata, side data, + * codec and time base, to an AVWriter. + * + * @param wr the writer where the format should be written + * @param ic the context to analyze + * @param index index of the stream to dump information about + * @param url the URL to print, such as source or destination file + * @param flags formatting flags, see below + */ +void av_dump_format_to_writer(struct AVWriter wr, + AVFormatContext *ic, int index, + const char *url, unsigned flags); + +/** + * Flag to av_dump_format_to_writer(): + * if set, the cotext is output; if unset, the context is input. + */ +#define AV_DUMP_FORMAT_IS_OUTPUT 1 #define AV_FRAME_FILENAME_FLAGS_MULTIPLE 1 ///< Allow multiple %d diff --git a/libavformat/dump.c b/libavformat/dump.c index 62ef5e9852..245d712504 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -35,6 +35,7 @@ #include "libavutil/spherical.h" #include "libavutil/stereo3d.h" #include "libavutil/timecode.h" +#include "libavutil/writer.h" #include "avformat.h" @@ -119,47 +120,47 @@ void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_paylo } -static void print_fps(double d, const char *postfix) +static void print_fps(AVWriter wr, double d, const char *postfix) { uint64_t v = lrintf(d * 100); if (!v) - av_log(NULL, AV_LOG_INFO, "%1.4f %s", d, postfix); + av_writer_printf(wr, "%1.4f %s", d, postfix); else if (v % 100) - av_log(NULL, AV_LOG_INFO, "%3.2f %s", d, postfix); + av_writer_printf(wr, "%3.2f %s", d, postfix); else if (v % (100 * 1000)) - av_log(NULL, AV_LOG_INFO, "%1.0f %s", d, postfix); + av_writer_printf(wr, "%1.0f %s", d, postfix); else - av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix); + av_writer_printf(wr, "%1.0fk %s", d / 1000, postfix); } -static void dump_metadata(void *ctx, const AVDictionary *m, const char *indent) +static void dump_metadata(AVWriter wr, const AVDictionary *m, const char *indent) { if (m && !(av_dict_count(m) == 1 && av_dict_get(m, "language", NULL, 0))) { const AVDictionaryEntry *tag = NULL; - av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent); + av_writer_printf(wr, "%sMetadata:\n", indent); while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) if (strcmp("language", tag->key)) { const char *p = tag->value; - av_log(ctx, AV_LOG_INFO, + av_writer_printf(wr, "%s %-16s: ", indent, tag->key); while (*p) { char tmp[256]; size_t len = strcspn(p, "\x8\xa\xb\xc\xd"); av_strlcpy(tmp, p, FFMIN(sizeof(tmp), len+1)); - av_log(ctx, AV_LOG_INFO, "%s", tmp); + av_writer_printf(wr, "%s", tmp); p += len; - if (*p == 0xd) av_log(ctx, AV_LOG_INFO, " "); - if (*p == 0xa) av_log(ctx, AV_LOG_INFO, "\n%s %-16s: ", indent, ""); + if (*p == 0xd) av_writer_printf(wr, " "); + if (*p == 0xa) av_writer_printf(wr, "\n%s %-16s: ", indent, ""); if (*p) p++; } - av_log(ctx, AV_LOG_INFO, "\n"); + av_writer_printf(wr, "\n"); } } } /* param change side data*/ -static void dump_paramchange(void *ctx, const AVPacketSideData *sd) +static void dump_paramchange(AVWriter wr, const AVPacketSideData *sd) { int size = sd->size; const uint8_t *data = sd->data; @@ -179,7 +180,7 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd) channels = AV_RL32(data); data += 4; size -= 4; - av_log(ctx, AV_LOG_INFO, "channel count %"PRIu32", ", channels); + av_writer_printf(wr, "channel count %"PRIu32", ", channels); } if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) { if (size < 8) @@ -187,7 +188,7 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd) layout = AV_RL64(data); data += 8; size -= 8; - av_log(ctx, AV_LOG_INFO, + av_writer_printf(wr, "channel layout: %s, ", av_get_channel_name(layout)); } if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { @@ -196,7 +197,7 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd) sample_rate = AV_RL32(data); data += 4; size -= 4; - av_log(ctx, AV_LOG_INFO, "sample_rate %"PRIu32", ", sample_rate); + av_writer_printf(wr, "sample_rate %"PRIu32", ", sample_rate); } if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) { if (size < 8) @@ -207,121 +208,121 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd) height = AV_RL32(data); data += 4; size -= 4; - av_log(ctx, AV_LOG_INFO, "width %"PRIu32" height %"PRIu32, width, height); + av_writer_printf(wr, "width %"PRIu32" height %"PRIu32, width, height); } return; fail: - av_log(ctx, AV_LOG_ERROR, "unknown param\n"); + av_log_writer_log(wr, AV_LOG_ERROR, "unknown param\n"); } /* replaygain side data*/ -static void print_gain(void *ctx, const char *str, int32_t gain) +static void print_gain(AVWriter wr, const char *str, int32_t gain) { - av_log(ctx, AV_LOG_INFO, "%s - ", str); + av_writer_printf(wr, "%s - ", str); if (gain == INT32_MIN) - av_log(ctx, AV_LOG_INFO, "unknown"); + av_writer_printf(wr, "unknown"); else - av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f); - av_log(ctx, AV_LOG_INFO, ", "); + av_writer_printf(wr, "%f", gain / 100000.0f); + av_writer_printf(wr, ", "); } -static void print_peak(void *ctx, const char *str, uint32_t peak) +static void print_peak(AVWriter wr, const char *str, uint32_t peak) { - av_log(ctx, AV_LOG_INFO, "%s - ", str); + av_writer_printf(wr, "%s - ", str); if (!peak) - av_log(ctx, AV_LOG_INFO, "unknown"); + av_writer_printf(wr, "unknown"); else - av_log(ctx, AV_LOG_INFO, "%f", (float) peak / UINT32_MAX); - av_log(ctx, AV_LOG_INFO, ", "); + av_writer_printf(wr, "%f", (float) peak / UINT32_MAX); + av_writer_printf(wr, ", "); } -static void dump_replaygain(void *ctx, const AVPacketSideData *sd) +static void dump_replaygain(AVWriter wr, const AVPacketSideData *sd) { const AVReplayGain *rg; if (sd->size < sizeof(*rg)) { - av_log(ctx, AV_LOG_ERROR, "invalid data\n"); + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data\n"); return; } rg = (const AVReplayGain *)sd->data; - print_gain(ctx, "track gain", rg->track_gain); - print_peak(ctx, "track peak", rg->track_peak); - print_gain(ctx, "album gain", rg->album_gain); - print_peak(ctx, "album peak", rg->album_peak); + print_gain(wr, "track gain", rg->track_gain); + print_peak(wr, "track peak", rg->track_peak); + print_gain(wr, "album gain", rg->album_gain); + print_peak(wr, "album peak", rg->album_peak); } -static void dump_stereo3d(void *ctx, const AVPacketSideData *sd) +static void dump_stereo3d(AVWriter wr, const AVPacketSideData *sd) { const AVStereo3D *stereo; if (sd->size < sizeof(*stereo)) { - av_log(ctx, AV_LOG_ERROR, "invalid data\n"); + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data\n"); return; } stereo = (const AVStereo3D *)sd->data; - av_log(ctx, AV_LOG_INFO, "%s", av_stereo3d_type_name(stereo->type)); + av_writer_printf(wr, "%s", av_stereo3d_type_name(stereo->type)); if (stereo->flags & AV_STEREO3D_FLAG_INVERT) - av_log(ctx, AV_LOG_INFO, " (inverted)"); + av_writer_printf(wr, " (inverted)"); } -static void dump_audioservicetype(void *ctx, const AVPacketSideData *sd) +static void dump_audioservicetype(AVWriter wr, const AVPacketSideData *sd) { const enum AVAudioServiceType *ast = (const enum AVAudioServiceType *)sd->data; if (sd->size < sizeof(*ast)) { - av_log(ctx, AV_LOG_ERROR, "invalid data\n"); + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data\n"); return; } switch (*ast) { case AV_AUDIO_SERVICE_TYPE_MAIN: - av_log(ctx, AV_LOG_INFO, "main"); + av_writer_printf(wr, "main"); break; case AV_AUDIO_SERVICE_TYPE_EFFECTS: - av_log(ctx, AV_LOG_INFO, "effects"); + av_writer_printf(wr, "effects"); break; case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: - av_log(ctx, AV_LOG_INFO, "visually impaired"); + av_writer_printf(wr, "visually impaired"); break; case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: - av_log(ctx, AV_LOG_INFO, "hearing impaired"); + av_writer_printf(wr, "hearing impaired"); break; case AV_AUDIO_SERVICE_TYPE_DIALOGUE: - av_log(ctx, AV_LOG_INFO, "dialogue"); + av_writer_printf(wr, "dialogue"); break; case AV_AUDIO_SERVICE_TYPE_COMMENTARY: - av_log(ctx, AV_LOG_INFO, "commentary"); + av_writer_printf(wr, "commentary"); break; case AV_AUDIO_SERVICE_TYPE_EMERGENCY: - av_log(ctx, AV_LOG_INFO, "emergency"); + av_writer_printf(wr, "emergency"); break; case AV_AUDIO_SERVICE_TYPE_VOICE_OVER: - av_log(ctx, AV_LOG_INFO, "voice over"); + av_writer_printf(wr, "voice over"); break; case AV_AUDIO_SERVICE_TYPE_KARAOKE: - av_log(ctx, AV_LOG_INFO, "karaoke"); + av_writer_printf(wr, "karaoke"); break; default: - av_log(ctx, AV_LOG_WARNING, "unknown"); + av_log_writer_log(wr, AV_LOG_WARNING, "unknown"); break; } } -static void dump_cpb(void *ctx, const AVPacketSideData *sd) +static void dump_cpb(AVWriter wr, const AVPacketSideData *sd) { const AVCPBProperties *cpb = (const AVCPBProperties *)sd->data; if (sd->size < sizeof(*cpb)) { - av_log(ctx, AV_LOG_ERROR, "invalid data\n"); + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data\n"); return; } - av_log(ctx, AV_LOG_INFO, + av_writer_printf(wr, #if FF_API_UNSANITIZED_BITRATES "bitrate max/min/avg: %d/%d/%d buffer size: %d ", #else @@ -330,16 +331,16 @@ static void dump_cpb(void *ctx, const AVPacketSideData *sd) cpb->max_bitrate, cpb->min_bitrate, cpb->avg_bitrate, cpb->buffer_size); if (cpb->vbv_delay == UINT64_MAX) - av_log(ctx, AV_LOG_INFO, "vbv_delay: N/A"); + av_writer_printf(wr, "vbv_delay: N/A"); else - av_log(ctx, AV_LOG_INFO, "vbv_delay: %"PRIu64"", cpb->vbv_delay); + av_writer_printf(wr, "vbv_delay: %"PRIu64"", cpb->vbv_delay); } -static void dump_mastering_display_metadata(void *ctx, const AVPacketSideData *sd) +static void dump_mastering_display_metadata(AVWriter wr, const AVPacketSideData* sd) { const AVMasteringDisplayMetadata *metadata = (const AVMasteringDisplayMetadata *)sd->data; - av_log(ctx, AV_LOG_INFO, "Mastering Display Metadata, " + av_writer_printf(wr, "Mastering Display Metadata, " "has_primaries:%d has_luminance:%d " "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f) " "min_luminance=%f, max_luminance=%f", @@ -354,51 +355,51 @@ static void dump_mastering_display_metadata(void *ctx, const AVPacketSideData *s av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); } -static void dump_content_light_metadata(void *ctx, const AVPacketSideData *sd) +static void dump_content_light_metadata(AVWriter wr, const AVPacketSideData* sd) { const AVContentLightMetadata *metadata = (const AVContentLightMetadata *)sd->data; - av_log(ctx, AV_LOG_INFO, "Content Light Level Metadata, " + av_writer_printf(wr, "Content Light Level Metadata, " "MaxCLL=%d, MaxFALL=%d", metadata->MaxCLL, metadata->MaxFALL); } -static void dump_spherical(void *ctx, const AVCodecParameters *par, +static void dump_spherical(AVWriter wr, const AVCodecParameters *par, const AVPacketSideData *sd) { const AVSphericalMapping *spherical = (const AVSphericalMapping *)sd->data; double yaw, pitch, roll; if (sd->size < sizeof(*spherical)) { - av_log(ctx, AV_LOG_ERROR, "invalid data\n"); + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data\n"); return; } - av_log(ctx, AV_LOG_INFO, "%s ", av_spherical_projection_name(spherical->projection)); + av_writer_printf(wr, "%s ", av_spherical_projection_name(spherical->projection)); yaw = ((double)spherical->yaw) / (1 << 16); pitch = ((double)spherical->pitch) / (1 << 16); roll = ((double)spherical->roll) / (1 << 16); - av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll); + av_writer_printf(wr, "(%f/%f/%f) ", yaw, pitch, roll); if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) { size_t l, t, r, b; av_spherical_tile_bounds(spherical, par->width, par->height, &l, &t, &r, &b); - av_log(ctx, AV_LOG_INFO, + av_writer_printf(wr, "[%"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER"] ", l, t, r, b); } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) { - av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding); + av_writer_printf(wr, "[pad %"PRIu32"] ", spherical->padding); } } -static void dump_dovi_conf(void *ctx, const AVPacketSideData *sd) +static void dump_dovi_conf(AVWriter wr, const AVPacketSideData *sd) { const AVDOVIDecoderConfigurationRecord *dovi = (const AVDOVIDecoderConfigurationRecord *)sd->data; - av_log(ctx, AV_LOG_INFO, "version: %d.%d, profile: %d, level: %d, " + av_writer_printf(wr, "version: %d.%d, profile: %d, level: %d, " "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d", dovi->dv_version_major, dovi->dv_version_minor, dovi->dv_profile, dovi->dv_level, @@ -408,104 +409,105 @@ static void dump_dovi_conf(void *ctx, const AVPacketSideData *sd) dovi->dv_bl_signal_compatibility_id); } -static void dump_s12m_timecode(void *ctx, const AVStream *st, const AVPacketSideData *sd) +static void dump_s12m_timecode(AVWriter wr, const AVStream *st, const AVPacketSideData *sd) { const uint32_t *tc = (const uint32_t *)sd->data; if ((sd->size != sizeof(uint32_t) * 4) || (tc[0] > 3)) { - av_log(ctx, AV_LOG_ERROR, "invalid data\n"); + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data\n"); return; } for (int j = 1; j <= tc[0]; j++) { char tcbuf[AV_TIMECODE_STR_SIZE]; av_timecode_make_smpte_tc_string2(tcbuf, st->avg_frame_rate, tc[j], 0, 0); - av_log(ctx, AV_LOG_INFO, "timecode - %s%s", tcbuf, j != tc[0] ? ", " : ""); + av_writer_printf(wr, "timecode - %s%s", tcbuf, j != tc[0] ? ", " : ""); } } -static void dump_sidedata(void *ctx, const AVStream *st, const char *indent) +static void dump_sidedata(AVWriter wr, const AVStream *st, const char *indent) { int i; if (st->nb_side_data) - av_log(ctx, AV_LOG_INFO, "%sSide data:\n", indent); + av_writer_printf(wr, "%sSide data:\n", indent); for (i = 0; i < st->nb_side_data; i++) { const AVPacketSideData *sd = &st->side_data[i]; - av_log(ctx, AV_LOG_INFO, "%s ", indent); + av_writer_printf(wr, "%s ", indent); switch (sd->type) { case AV_PKT_DATA_PALETTE: - av_log(ctx, AV_LOG_INFO, "palette"); + av_writer_printf(wr, "palette"); break; case AV_PKT_DATA_NEW_EXTRADATA: - av_log(ctx, AV_LOG_INFO, "new extradata"); + av_writer_printf(wr, "new extradata"); break; case AV_PKT_DATA_PARAM_CHANGE: - av_log(ctx, AV_LOG_INFO, "paramchange: "); - dump_paramchange(ctx, sd); + av_writer_printf(wr, "paramchange: "); + dump_paramchange(wr, sd); break; case AV_PKT_DATA_H263_MB_INFO: - av_log(ctx, AV_LOG_INFO, "H.263 macroblock info"); + av_writer_printf(wr, "H.263 macroblock info"); break; case AV_PKT_DATA_REPLAYGAIN: - av_log(ctx, AV_LOG_INFO, "replaygain: "); - dump_replaygain(ctx, sd); + av_writer_printf(wr, "replaygain: "); + dump_replaygain(wr, sd); break; case AV_PKT_DATA_DISPLAYMATRIX: - av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees", + av_writer_printf(wr, "displaymatrix: rotation of %.2f degrees", av_display_rotation_get((const int32_t *)sd->data)); break; case AV_PKT_DATA_STEREO3D: - av_log(ctx, AV_LOG_INFO, "stereo3d: "); - dump_stereo3d(ctx, sd); + av_writer_printf(wr, "stereo3d: "); + dump_stereo3d(wr, sd); break; case AV_PKT_DATA_AUDIO_SERVICE_TYPE: - av_log(ctx, AV_LOG_INFO, "audio service type: "); - dump_audioservicetype(ctx, sd); + av_writer_printf(wr, "audio service type: "); + dump_audioservicetype(wr, sd); break; case AV_PKT_DATA_QUALITY_STATS: - av_log(ctx, AV_LOG_INFO, "quality factor: %"PRId32", pict_type: %c", + av_writer_printf(wr, "quality factor: %"PRId32", pict_type: %c", AV_RL32(sd->data), av_get_picture_type_char(sd->data[4])); break; case AV_PKT_DATA_CPB_PROPERTIES: - av_log(ctx, AV_LOG_INFO, "cpb: "); - dump_cpb(ctx, sd); + av_writer_printf(wr, "cpb: "); + dump_cpb(wr, sd); break; case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: - dump_mastering_display_metadata(ctx, sd); + dump_mastering_display_metadata(wr, sd); break; case AV_PKT_DATA_SPHERICAL: - av_log(ctx, AV_LOG_INFO, "spherical: "); - dump_spherical(ctx, st->codecpar, sd); + av_writer_printf(wr, "spherical: "); + dump_spherical(wr, st->codecpar, sd); break; case AV_PKT_DATA_CONTENT_LIGHT_LEVEL: - dump_content_light_metadata(ctx, sd); + dump_content_light_metadata(wr, sd); break; case AV_PKT_DATA_ICC_PROFILE: - av_log(ctx, AV_LOG_INFO, "ICC Profile"); + av_writer_printf(wr, "ICC Profile"); break; case AV_PKT_DATA_DOVI_CONF: - av_log(ctx, AV_LOG_INFO, "DOVI configuration record: "); - dump_dovi_conf(ctx, sd); + av_writer_printf(wr, "DOVI configuration record: "); + dump_dovi_conf(wr, sd); break; case AV_PKT_DATA_S12M_TIMECODE: - av_log(ctx, AV_LOG_INFO, "SMPTE ST 12-1:2014: "); - dump_s12m_timecode(ctx, st, sd); + av_writer_printf(wr, "SMPTE ST 12-1:2014: "); + dump_s12m_timecode(wr, st, sd); break; default: - av_log(ctx, AV_LOG_INFO, + av_writer_printf(wr, "unknown side data type %d (%d bytes)", sd->type, sd->size); break; } - av_log(ctx, AV_LOG_INFO, "\n"); + av_writer_printf(wr, "\n"); } } /* "user interface" functions */ -static void dump_stream_format(const AVFormatContext *ic, int i, +static void dump_stream_format(AVWriter wr, + const AVFormatContext *ic, int i, int index, int is_output) { char buf[256]; @@ -543,17 +545,17 @@ FF_ENABLE_DEPRECATION_WARNINGS avcodec_string(buf, sizeof(buf), avctx, is_output); avcodec_free_context(&avctx); - av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i); + av_writer_printf(wr, " Stream #%d:%d", index, i); /* the pid is an important information, so we display it */ /* XXX: add a generic system */ if (flags & AVFMT_SHOW_IDS) - av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id); + av_writer_printf(wr, "[0x%x]", st->id); if (lang) - av_log(NULL, AV_LOG_INFO, "(%s)", lang->value); - av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames, + av_writer_printf(wr, "(%s)", lang->value); + av_log_writer_log(wr, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames, st->time_base.num, st->time_base.den); - av_log(NULL, AV_LOG_INFO, ": %s", buf); + av_writer_printf(wr, ": %s", buf); if (st->sample_aspect_ratio.num && av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio)) { @@ -562,7 +564,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->codecpar->width * (int64_t)st->sample_aspect_ratio.num, st->codecpar->height * (int64_t)st->sample_aspect_ratio.den, 1024 * 1024); - av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d", + av_writer_printf(wr, ", SAR %d:%d DAR %d:%d", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den); } @@ -580,80 +582,82 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif if (fps || tbr || tbn || tbc) - av_log(NULL, AV_LOG_INFO, "%s", separator); + av_writer_printf(wr, "%s", separator); if (fps) - print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps"); + print_fps(wr, av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps"); if (tbr) - print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr"); + print_fps(wr, av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr"); if (tbn) - print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn"); + print_fps(wr, 1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn"); #if FF_API_LAVF_AVCTX FF_DISABLE_DEPRECATION_WARNINGS if (tbc) - print_fps(1 / av_q2d(st->codec->time_base), "tbc"); + print_fps(wr, 1 / av_q2d(st->codec->time_base), "tbc"); FF_ENABLE_DEPRECATION_WARNINGS #endif } if (st->disposition & AV_DISPOSITION_DEFAULT) - av_log(NULL, AV_LOG_INFO, " (default)"); + av_writer_printf(wr, " (default)"); if (st->disposition & AV_DISPOSITION_DUB) - av_log(NULL, AV_LOG_INFO, " (dub)"); + av_writer_printf(wr, " (dub)"); if (st->disposition & AV_DISPOSITION_ORIGINAL) - av_log(NULL, AV_LOG_INFO, " (original)"); + av_writer_printf(wr, " (original)"); if (st->disposition & AV_DISPOSITION_COMMENT) - av_log(NULL, AV_LOG_INFO, " (comment)"); + av_writer_printf(wr, " (comment)"); if (st->disposition & AV_DISPOSITION_LYRICS) - av_log(NULL, AV_LOG_INFO, " (lyrics)"); + av_writer_printf(wr, " (lyrics)"); if (st->disposition & AV_DISPOSITION_KARAOKE) - av_log(NULL, AV_LOG_INFO, " (karaoke)"); + av_writer_printf(wr, " (karaoke)"); if (st->disposition & AV_DISPOSITION_FORCED) - av_log(NULL, AV_LOG_INFO, " (forced)"); + av_writer_printf(wr, " (forced)"); if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED) - av_log(NULL, AV_LOG_INFO, " (hearing impaired)"); + av_writer_printf(wr, " (hearing impaired)"); if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED) - av_log(NULL, AV_LOG_INFO, " (visual impaired)"); + av_writer_printf(wr, " (visual impaired)"); if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS) - av_log(NULL, AV_LOG_INFO, " (clean effects)"); + av_writer_printf(wr, " (clean effects)"); if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) - av_log(NULL, AV_LOG_INFO, " (attached pic)"); + av_writer_printf(wr, " (attached pic)"); if (st->disposition & AV_DISPOSITION_TIMED_THUMBNAILS) - av_log(NULL, AV_LOG_INFO, " (timed thumbnails)"); + av_writer_printf(wr, " (timed thumbnails)"); if (st->disposition & AV_DISPOSITION_CAPTIONS) - av_log(NULL, AV_LOG_INFO, " (captions)"); + av_writer_printf(wr, " (captions)"); if (st->disposition & AV_DISPOSITION_DESCRIPTIONS) - av_log(NULL, AV_LOG_INFO, " (descriptions)"); + av_writer_printf(wr, " (descriptions)"); if (st->disposition & AV_DISPOSITION_METADATA) - av_log(NULL, AV_LOG_INFO, " (metadata)"); + av_writer_printf(wr, " (metadata)"); if (st->disposition & AV_DISPOSITION_DEPENDENT) - av_log(NULL, AV_LOG_INFO, " (dependent)"); + av_writer_printf(wr, " (dependent)"); if (st->disposition & AV_DISPOSITION_STILL_IMAGE) - av_log(NULL, AV_LOG_INFO, " (still image)"); - av_log(NULL, AV_LOG_INFO, "\n"); + av_writer_printf(wr, " (still image)"); + av_writer_printf(wr, "\n"); - dump_metadata(NULL, st->metadata, " "); + dump_metadata(wr, st->metadata, " "); - dump_sidedata(NULL, st, " "); + dump_sidedata(wr, st, " "); } -void av_dump_format(AVFormatContext *ic, int index, - const char *url, int is_output) +void av_dump_format_to_writer(AVWriter wr, + AVFormatContext *ic, int index, + const char *url, unsigned flags) { + int is_output = flags & AV_DUMP_FORMAT_IS_OUTPUT; int i; uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL; if (ic->nb_streams && !printed) return; - av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n", + av_writer_printf(wr, "%s #%d, %s, %s '%s':\n", is_output ? "Output" : "Input", index, is_output ? ic->oformat->name : ic->iformat->name, is_output ? "to" : "from", url); - dump_metadata(NULL, ic->metadata, " "); + dump_metadata(wr, ic->metadata, " "); if (!is_output) { - av_log(NULL, AV_LOG_INFO, " Duration: "); + av_writer_printf(wr, " Duration: "); if (ic->duration != AV_NOPTS_VALUE) { int64_t hours, mins, secs, us; int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0); @@ -663,40 +667,40 @@ void av_dump_format(AVFormatContext *ic, int index, secs %= 60; hours = mins / 60; mins %= 60; - av_log(NULL, AV_LOG_INFO, "%02"PRId64":%02"PRId64":%02"PRId64".%02"PRId64"", hours, mins, secs, + av_writer_printf(wr, "%02"PRId64":%02"PRId64":%02"PRId64".%02"PRId64"", hours, mins, secs, (100 * us) / AV_TIME_BASE); } else { - av_log(NULL, AV_LOG_INFO, "N/A"); + av_writer_printf(wr, "N/A"); } if (ic->start_time != AV_NOPTS_VALUE) { int secs, us; - av_log(NULL, AV_LOG_INFO, ", start: "); + av_writer_printf(wr, ", start: "); secs = llabs(ic->start_time / AV_TIME_BASE); us = llabs(ic->start_time % AV_TIME_BASE); - av_log(NULL, AV_LOG_INFO, "%s%d.%06d", + av_writer_printf(wr, "%s%d.%06d", ic->start_time >= 0 ? "" : "-", secs, (int) av_rescale(us, 1000000, AV_TIME_BASE)); } - av_log(NULL, AV_LOG_INFO, ", bitrate: "); + av_writer_printf(wr, ", bitrate: "); if (ic->bit_rate) - av_log(NULL, AV_LOG_INFO, "%"PRId64" kb/s", ic->bit_rate / 1000); + av_writer_printf(wr, "%"PRId64" kb/s", ic->bit_rate / 1000); else - av_log(NULL, AV_LOG_INFO, "N/A"); - av_log(NULL, AV_LOG_INFO, "\n"); + av_writer_printf(wr, "N/A"); + av_writer_printf(wr, "\n"); } if (ic->nb_chapters) av_log(NULL, AV_LOG_INFO, " Chapters:\n"); for (i = 0; i < ic->nb_chapters; i++) { const AVChapter *ch = ic->chapters[i]; - av_log(NULL, AV_LOG_INFO, " Chapter #%d:%d: ", index, i); - av_log(NULL, AV_LOG_INFO, + av_writer_printf(wr, " Chapter #%d:%d: ", index, i); + av_writer_printf(wr, "start %f, ", ch->start * av_q2d(ch->time_base)); - av_log(NULL, AV_LOG_INFO, + av_writer_printf(wr, "end %f\n", ch->end * av_q2d(ch->time_base)); - dump_metadata(NULL, ch->metadata, " "); + dump_metadata(wr, ch->metadata, " "); } if (ic->nb_programs) { @@ -705,23 +709,30 @@ void av_dump_format(AVFormatContext *ic, int index, const AVProgram *program = ic->programs[j]; const AVDictionaryEntry *name = av_dict_get(program->metadata, "name", NULL, 0); - av_log(NULL, AV_LOG_INFO, " Program %d %s\n", program->id, + av_writer_printf(wr, " Program %d %s\n", program->id, name ? name->value : ""); - dump_metadata(NULL, program->metadata, " "); + dump_metadata(wr, program->metadata, " "); for (k = 0; k < program->nb_stream_indexes; k++) { - dump_stream_format(ic, program->stream_index[k], + dump_stream_format(wr, ic, program->stream_index[k], index, is_output); printed[program->stream_index[k]] = 1; } total += program->nb_stream_indexes; } if (total < ic->nb_streams) - av_log(NULL, AV_LOG_INFO, " No Program\n"); + av_writer_printf(wr, " No Program\n"); } for (i = 0; i < ic->nb_streams; i++) if (!printed[i]) - dump_stream_format(ic, i, index, is_output); + dump_stream_format(wr, ic, i, index, is_output); av_free(printed); } + +void av_dump_format(AVFormatContext *ic, int index, + const char *url, int is_output) +{ + av_dump_format_to_writer(av_log_writer(NULL), ic, index, url, + is_output ? AV_DUMP_FORMAT_IS_OUTPUT : 0); +}