From patchwork Mon Mar 7 22:15:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 34631 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1905248nkx; Mon, 7 Mar 2022 14:16:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxspoYuxmNgVo1eJOSiy//FeErwLa+B/PWBPoPvh2w8QM7pRYLKrQKAP8OMG2hGHA59kOYm X-Received: by 2002:a17:906:c14c:b0:6d7:1278:d80c with SMTP id dp12-20020a170906c14c00b006d71278d80cmr10967265ejc.660.1646691383127; Mon, 07 Mar 2022 14:16:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646691383; cv=none; d=google.com; s=arc-20160816; b=MAnJ5w7dL58g3MaePF7PXgZdCGUVs/xQ8e6n149GlzBf1Bg5KDABPGbNqBYjn0VbLj xGZQo47aesALkfAPeGhU7rL/TlW4KZqbyKOkJvZud9BseSJyr/uWCZ/ZCFVl8aP3rtEb R4UchZWl+8nSjLPhGZxYCvZ4PyoZgFoc/E4flZdaWF1wiv5/szqY9VqmE2aehfzk2vmG MQTAVVaZyLUBNOwI3O7Lw25zumQn63KRJchYgI7YwMVtfTto+whGfNVIMNIUGIfV1g2O IU3pFab3BXDmzjf6cjKe51XeIx1rCWWEpFxRtFyNXlTM6lM7xZEaCXLBWK3n/p3lu4M+ g4Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=H+ryIY1krKWeQYvBRstmGSRZW1NrsQLYoYIYsG9bcp4=; b=gNvgeVqYxk6IRWmYYDC0H8eCIfpDz+H74Mg7avOeuyn0wKcXXrti1yin6UaHwrxjO1 WTxFmX+T3TngK8tKJIDjKdl0Ul/Lz9biaOnvkZggvO5ziogULnrFUsABuuvF7Yy137e+ d4PF2UNGRP/NJ4+n97thY3scwZdVn21Ks8R2d36jvMgXos+qFSZTndKxCeaGypGxC3Fj pDbnivhNMjzbht8q2iGBdnhB40Qr8hL2GoaNEErErk+i5Vv2K4dOSQAJ4s8mUyOtGKqA Vzttw/dP6iBHCKBtRQjM2PaY0lbGUdD6nx5Tfys3eUWX2LBKEXTy3F9TsQvVwf0JHU1o lmyQ== 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 sh20-20020a1709076e9400b006ce6b771f09si7602369ejc.883.2022.03.07.14.16.22; Mon, 07 Mar 2022 14:16:23 -0800 (PST) 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 2B68668B14C; Tue, 8 Mar 2022 00:16:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CB28C68A7A1 for ; Tue, 8 Mar 2022 00:16:11 +0200 (EET) Received: by mail-pf1-f178.google.com with SMTP id g1so15659500pfv.1 for ; Mon, 07 Mar 2022 14:16:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EkUEjmi6TQu1/uHyl90//cqLpXaCxAXM/4hR58KLTQw=; b=biSGcqXuke4EeJU9teMA4NW3ct/xLOJcpBWFU7sYyIlMha5i8Jmi7emRPjy2Vf7xxR CmWAaysG3Md0xVXOnab3faOa8Orb2AE6Ct2ZtDmAHlgSiG1qgrC1Gcj4GH2wVodVEqRm 3WTxuFqAYF0qQph1KTCIX05kAyWMko44zLL+ATzk4JB2mBd1sBMDU36088mnwsIGC7MW 7ah8RQFkmhYZTGjX7ABsHe6bnYs/zgwZFiEAZtzy4Yi6zbJ6jGyW1lOYKeGuTABrZdy8 eG2IPdRkSujPCXpWQ4sLxCkqOczBYxM/d6plvd77iMkUrUuWommm1BYQ7/XdeH68uKrq /FRA== X-Gm-Message-State: AOAM530+bMPwYdZQCwOMvW8O/8ViL4bBYQCymP/4YY4rh2/KO4K6z3FV Z9cv9Y4mhZtvICePM92F1dVx4d8QmO4= X-Received: by 2002:a63:5a4a:0:b0:380:260d:47b0 with SMTP id k10-20020a635a4a000000b00380260d47b0mr7767356pgm.45.1646691369597; Mon, 07 Mar 2022 14:16:09 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id w23-20020a627b17000000b004f6cf170070sm10462543pfc.186.2022.03.07.14.16.07 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 14:16:09 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Mon, 07 Mar 2022 14:15:44 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Mar 2022 14:15:36 -0800 Message-Id: <20220307221542.3265-1-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/7] avformat/imf: relocate static function imf_time_to_ts() 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 0HjugUbDpcFJ From: Pierre-Anthony Lemieux --- libavformat/imfdec.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index 3ce850b75a..b98af020d2 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -154,6 +154,25 @@ static int imf_uri_is_dos_abs_path(const char *string) return 0; } +static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base) +{ + int dst_num; + int dst_den; + AVRational r; + + r = av_div_q(t, time_base); + + if ((av_reduce(&dst_num, &dst_den, r.num, r.den, INT64_MAX) != 1)) + return 1; + + if (dst_den != 1) + return 1; + + *ts = dst_num; + + return 0; +} + /** * Parse a ASSETMAP XML file to extract the UUID-URI mapping of assets. * @param s the current format context, if any (can be NULL). @@ -772,25 +791,6 @@ static int get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac return AVERROR_STREAM_NOT_FOUND; } -static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base) -{ - int dst_num; - int dst_den; - AVRational r; - - r = av_div_q(t, time_base); - - if ((av_reduce(&dst_num, &dst_den, r.num, r.den, INT64_MAX) != 1)) - return 1; - - if (dst_den != 1) - return 1; - - *ts = dst_num; - - return 0; -} - static int imf_read_packet(AVFormatContext *s, AVPacket *pkt) { IMFVirtualTrackResourcePlaybackCtx *resource = NULL; From patchwork Mon Mar 7 22:15:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 34632 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1905351nkx; Mon, 7 Mar 2022 14:16:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdv+aifZxtJYUYrJYX7UUi0zLj9boSmq1FjbD1QOqxyjFrW82TFBU04Bx07bgqsZE/s8CY X-Received: by 2002:a05:6402:1d4f:b0:416:6450:e1b4 with SMTP id dz15-20020a0564021d4f00b004166450e1b4mr2307152edb.79.1646691392263; Mon, 07 Mar 2022 14:16:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646691392; cv=none; d=google.com; s=arc-20160816; b=BuJyQ+w89FNAqYHwgliS6ppo0IS0PwPZRworRApscbXEBvjW6mYFhlwdEl5KOyCik6 YwARxOykptjsBjon8ZWpCBr+ZI3/qN8/XM5hiSZT0oewUeCjNiqLHUpXhkrFXtO7KEZ9 riCyUsMTWTZs0EFkmYsu4i7+jaJe/dkmq8N1wFFE1FgjGXTLhIhER2eCIMD7bhSWg882 7RzHi1L3GFWzE40tIL8xzHH+ImkTobRwJexgWPYi9secwYAdUp1tGaQ9wC5UMYz6dbJ3 y2nlQd4ZJf/wQ+Lr7PKijo8vGPCpwOUt+YVzGiz3Rw7z7pUOHYdiooG2hXaE13hrkfF0 LJLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=bXHQy9vIq/HqVtEpjblDk6YpwIF6biMFinWMgnqEAwA=; b=K2G9q9U2VuMmlMEMUJ/LhqQf9EJku6yhcec92oix7eTzk/uZaCKGSwBerlE2vwOKH/ NH7x9Q1+gd4Dg1DjkXSVDq/zFIK6sLnidWKjsDo9Nhqc9n4LP0EjilZVXrq8Aq46+trQ ucT2SHOyctYDEh0t2TYb61otPRZ6szywfpZ7v9AzqBz0mzYmARISsamXCO+hk1AK7+5r Vshp1zgLGtg8OQAUoSrjX1vtePRWKZPSFuhPu75KKGY75nVDJIE1a14DQ/+hn226g8i8 f4gl8MyJwSbtuziar8ecVRhoHWH6IYAwgBCx7S0UVGBzpmI/r8djZVf77IJwoCwNOGUC 0pdg== 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 5-20020a508e45000000b00411cd1b7b45si10804813edx.172.2022.03.07.14.16.31; Mon, 07 Mar 2022 14:16:32 -0800 (PST) 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 2152668B18B; Tue, 8 Mar 2022 00:16:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F362868B14C for ; Tue, 8 Mar 2022 00:16:13 +0200 (EET) Received: by mail-pf1-f176.google.com with SMTP id g1so15659593pfv.1 for ; Mon, 07 Mar 2022 14:16:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vy2ZRdL08jBVJtXwaLOABsPw163H74v2c1Goe67Dnkc=; b=7g1YnqL35nL9zmoGyIKdlELBvQw6sj6EccXfmQUQS6p82r4+sMxGjcCQ6ONWGwq64c oMJw7yPHJ6R8OTMZVYUW43SbmEsXmYJ/daY0Ojm1lEndxRgeCD/yfW9cUf0NzI7Zoz+P vJV9DPZZ1dFjaKUn18OP2fFOUguae1HVOo17CS8dQxdj9ZmuYzeOVyTI9z0j4FmIxIyd +w4wFc3mrCqNAW20amVOqUt2+Ty5tqlkIeoaEo19d4+OCt43LzzRA8/R0+anQhqR1qX8 gb8Hafxy7b9EqidqjGq8YwxHlCFQVBTUROtggBUHHtqcvHsNFhHZadPa3d4R+NpXHQT6 efbQ== X-Gm-Message-State: AOAM533zCqjSYw9+yQb2cYH/jDhOcpB+y5cA0Hp3fOcLv0KLEUIo6cHX Zy2r8gn+WGch0RD+65pb8tIP1IcxX+8= X-Received: by 2002:a63:4f1e:0:b0:37c:9a79:f20f with SMTP id d30-20020a634f1e000000b0037c9a79f20fmr11532411pgb.532.1646691371967; Mon, 07 Mar 2022 14:16:11 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id ay5-20020a056a00300500b004f6d510af4asm9456566pfb.124.2022.03.07.14.16.10 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 14:16:11 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Mon, 07 Mar 2022 14:15:47 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Mar 2022 14:15:37 -0800 Message-Id: <20220307221542.3265-2-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220307221542.3265-1-pal@sandflow.com> References: <20220307221542.3265-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/7] avformat/imf: add support for input seeking 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Wgzy7bjD/IMD From: Pierre-Anthony Lemieux The IMF demuxer did not implement AVInputFormat::read_seek2(), resulting in inefficient input seeking. Addresses https://trac.ffmpeg.org/ticket/9648 Byte- and frame-seeking are not supported. --- libavformat/imfdec.c | 129 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 102 insertions(+), 27 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index b98af020d2..f208b262c3 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -359,13 +359,15 @@ static IMFAssetLocator *find_asset_map_locator(IMFAssetLocatorMap *asset_map, FF } static int open_track_resource_context(AVFormatContext *s, - IMFVirtualTrackResourcePlaybackCtx *track_resource) + IMFVirtualTrackPlaybackCtx *track, + int32_t resource_index) { IMFContext *c = s->priv_data; int ret = 0; - int64_t entry_point; + int64_t seek_offset = 0; AVDictionary *opts = NULL; AVStream *st; + IMFVirtualTrackResourcePlaybackCtx *track_resource = track->resources + resource_index; if (track_resource->ctx) { av_log(s, @@ -416,32 +418,27 @@ static int open_track_resource_context(AVFormatContext *s, st = track_resource->ctx->streams[0]; - /* Warn if the resource time base does not match the file time base */ - if (av_cmp_q(st->time_base, av_inv_q(track_resource->resource->base.edit_rate))) - av_log(s, - AV_LOG_WARNING, - "Incoherent source stream timebase " AVRATIONAL_FORMAT - "regarding resource edit rate: " AVRATIONAL_FORMAT, - st->time_base.num, - st->time_base.den, - track_resource->resource->base.edit_rate.den, - track_resource->resource->base.edit_rate.num); - - entry_point = av_rescale_q(track_resource->resource->base.entry_point, st->time_base, - av_inv_q(track_resource->resource->base.edit_rate)); - - if (entry_point) { - av_log(s, - AV_LOG_DEBUG, - "Seek at resource %s entry point: %" PRIu32 "\n", - track_resource->locator->absolute_uri, - track_resource->resource->base.entry_point); - ret = avformat_seek_file(track_resource->ctx, 0, entry_point, entry_point, entry_point, 0); + /* Determine the seek offset into the Track File, taking into account: + * - the current timestamp within the virtual track + * - the entry point of the resource + */ + if (imf_time_to_ts(&seek_offset, + av_sub_q(track->current_timestamp, track_resource->ts_offset), + st->time_base)) + av_log(s, AV_LOG_WARNING, "Incoherent stream timebase " AVRATIONAL_FORMAT + "and composition timeline position: " AVRATIONAL_FORMAT "\n", + st->time_base.num, st->time_base.den, + track->current_timestamp.den, track->current_timestamp.num); + + if (seek_offset) { + av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %" PRIi64 "\n", + track_resource->locator->absolute_uri, seek_offset); + ret = avformat_seek_file(track_resource->ctx, 0, seek_offset, seek_offset, seek_offset, 0); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Could not seek at %" PRId64 "on %s: %s\n", - entry_point, + seek_offset, track_resource->locator->absolute_uri, av_err2str(ret)); avformat_close_input(&track_resource->ctx); @@ -584,7 +581,7 @@ static int set_context_streams_from_tracks(AVFormatContext *s) AVStream *first_resource_stream; /* Open the first resource of the track to get stream information */ - ret = open_track_resource_context(s, &c->tracks[i]->resources[0]); + ret = open_track_resource_context(s, c->tracks[i], 0); if (ret) return ret; first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0]; @@ -774,7 +771,7 @@ static int get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac "Switch resource on track %d: re-open context\n", track->index); - ret = open_track_resource_context(s, track->resources + i); + ret = open_track_resource_context(s, track, i); if (ret != 0) return ret; if (track->current_resource_index > 0) @@ -942,6 +939,83 @@ static int imf_probe(const AVProbeData *p) return AVPROBE_SCORE_MAX; } +static void rescale_interval(AVRational tb_in, AVRational tb_out, + int64_t *min_ts, int64_t *ts, int64_t *max_ts) +{ + *ts = av_rescale_q(*ts, tb_in, tb_out); + *min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out, AV_ROUND_UP | AV_ROUND_PASS_MINMAX); + *max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out, AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX); +} + +static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb) +{ + int dst_num; + int dst_den; + int ret; + + ret = av_reduce(&dst_num, &dst_den, ts * in_tb.num * out_tb.den, + in_tb.den * out_tb.num, INT64_MAX); + if (!ret || dst_den != 1) + return 0; + + return 1; +} + +static int imf_seek(AVFormatContext *s, int stream_index, int64_t min_ts, + int64_t ts, int64_t max_ts, int flags) +{ + IMFContext *c = s->priv_data; + uint32_t i; + + if (flags & (AVSEEK_FLAG_BYTE | AVSEEK_FLAG_FRAME)) + return AVERROR(ENOSYS); + + /* rescale timestamps to Composition edit units */ + if (stream_index < 0) + rescale_interval(AV_TIME_BASE_Q, + av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num), + &min_ts, &ts, &max_ts); + else + rescale_interval(s->streams[stream_index]->time_base, + av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num), + &min_ts, &ts, &max_ts); + + /* requested timestamp bounds are too close */ + if (max_ts < min_ts) + return -1; + + /* clamp requested timestamp to provided bounds */ + ts = FFMAX(FFMIN(ts, max_ts), min_ts); + + av_log(s, AV_LOG_DEBUG, "Seeking to Composition Playlist edit unit %" PRIi64 "\n", ts); + + /* set the dts of each stream and temporal offset of each track */ + for (i = 0; i < c->track_count; i++) { + AVStream *st = s->streams[i]; + IMFVirtualTrackPlaybackCtx *t = c->tracks[i]; + int64_t dts; + + if (!coherent_ts(ts, av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num), + st->time_base)) + av_log(s, AV_LOG_WARNING, "Seek position is not coherent across tracks\n"); + + dts = av_rescale(ts, + st->time_base.den * c->cpl->edit_rate.den, + st->time_base.num * c->cpl->edit_rate.num); + + av_log(s, AV_LOG_DEBUG, "Seeking to dts=%" PRId64 " on stream_index=%d\n", + dts, i); + + t->current_timestamp = av_mul_q(av_make_q(dts, 1), st->time_base); + if (t->current_resource_index >= 0) { + avformat_close_input(&t->resources[t->current_resource_index].ctx); + t->current_resource_index = -1; + } + } + + return 0; +} + static const AVOption imf_options[] = { { .name = "assetmaps", @@ -966,7 +1040,7 @@ static const AVClass imf_class = { const AVInputFormat ff_imf_demuxer = { .name = "imf", .long_name = NULL_IF_CONFIG_SMALL("IMF (Interoperable Master Format)"), - .flags = AVFMT_EXPERIMENTAL, + .flags = AVFMT_EXPERIMENTAL | AVFMT_NO_BYTE_SEEK, .flags_internal = FF_FMT_INIT_CLEANUP, .priv_class = &imf_class, .priv_data_size = sizeof(IMFContext), @@ -974,4 +1048,5 @@ const AVInputFormat ff_imf_demuxer = { .read_header = imf_read_header, .read_packet = imf_read_packet, .read_close = imf_close, + .read_seek2 = imf_seek, }; From patchwork Mon Mar 7 22:15:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 34633 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1905458nkx; Mon, 7 Mar 2022 14:16:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7sXxeAxSboBXmXExqy5VxDT2j2kzWAdi7ICvhXQvPPfrxGYFJOkSHIlTM1OsgoC6XxUg4 X-Received: by 2002:a05:6402:2365:b0:415:ed07:70de with SMTP id a5-20020a056402236500b00415ed0770demr13195000eda.150.1646691401400; Mon, 07 Mar 2022 14:16:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646691401; cv=none; d=google.com; s=arc-20160816; b=g4YiR5qqlJvabciJqyeR/05eogSbuaPn9XGJlk0BFVJ5JsgVJKYQ6L8BnY7cO4jI0b s6/Xd8MQHVr13F05830U+3cyrm9ysM06AcnTNSMRPp6M4y/Qo7gSZarY6+9hGqUdTP89 NlVcdb0JpOmOQIOFjcf2AMmCzQPjCtegcVKnBxXX7R5aE3ZOP4rXunjRJRgKWKcLqLU5 PoyzT6oYZqh8nXK2ZQmar1zS4gomGqcrViW1+Q13fEAbSkxWXtabtoacTBcooTdOCMoQ rEaI7NnPctRnoyRNrBWyuR0FBt+G59HlYv5gqwOpo5+N1sh4otbGwiOmecDgeq/vFP8W jp+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=4A4Q1cAMykGFaxfqQQ541vcvinXTv5XxwUWIzH1+GfY=; b=i7uDulPub0Or7pd7HKLXnjjpuSwJyAq2Rv+a73hwNQZNCsk13oTfBGAiThtlRo2MNe +iHkfb0q6h/1lCWjUtQ/asvcwGmFxB2ocFzqlnR8mjdAT4bgw/ZXXOlereWJDwBNdfdM yOKYbn14Uargb1f/mnF+4Zr62LxRY9IB++Ho0fAjcIEw7IfW1T6cvONzYNA3h/csyLwm vmqXda3lMMYEA0AUuJwZv5Hxq7csCTiEqIkDdQmaGq1JVjEoYBv0W0+Y9irV7zi/FcbO L5rg7LYReuBBp8rNC2gdAoQfOb/53eT7reoNDcqgZLldV8MwcnrD1kJRwN3+Wan8XytN 9vwQ== 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 ms24-20020a170907621800b006daff82aca8si4454770ejc.520.2022.03.07.14.16.41; Mon, 07 Mar 2022 14:16:41 -0800 (PST) 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 3F75F68B196; Tue, 8 Mar 2022 00:16:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8131168B18F for ; Tue, 8 Mar 2022 00:16:16 +0200 (EET) Received: by mail-pj1-f45.google.com with SMTP id v1-20020a17090a088100b001bf25f97c6eso766297pjc.0 for ; Mon, 07 Mar 2022 14:16:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TN7H518HNKeCPbdCF0F/reBROPhorrmQ+bsHQZCVUGY=; b=sFRXYhspt8PCCVjooBKAy08IcZbnl9Lk6tfoMMZVB8Q7w+uYhzCAwwz2IjIOSfMJdv YBrrqG3qHVGDpn1WdnhuWiXWQbUAst/6JcEWOZM6lHEuV50ujb+1ilvysNFvgS0BYiax XyyrFLYOIKCOMmg04mpiveF0yrU8w6oipN8kW0wpAIqmePkcGwn+EDo2F3pmLHDW4bxV wNsGQY3v+e/1Xw/ZOC5a/t1rqh2ZEMEzuw1ktK6VjFQkPpg1tsMBeVc9RaRmEFAd7C2C jGO4/+azMop9cvVgGgKGVPj15KC5JZyU2rn09ZR3mXWrpMC3MtaiYNLxGKYfzvc+m05H VEsw== X-Gm-Message-State: AOAM531t4ome2K1KdrmykAusZBs0CAbQuPn9cUe+wB4FVuXe0/rT0kzO wVpJV7h6id2hni61CH8rW+nBV4Eq2Gs= X-Received: by 2002:a17:902:b697:b0:151:4c2e:48be with SMTP id c23-20020a170902b69700b001514c2e48bemr14227042pls.70.1646691374335; Mon, 07 Mar 2022 14:16:14 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id f20-20020a056a001ad400b004f6e8f8f90bsm7838433pfv.109.2022.03.07.14.16.12 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 14:16:14 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Mon, 07 Mar 2022 14:15:49 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Mar 2022 14:15:38 -0800 Message-Id: <20220307221542.3265-3-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220307221542.3265-1-pal@sandflow.com> References: <20220307221542.3265-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/7] avformat/imf: clean-up and reduce logging 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: SfHkcf+5v+wi From: Pierre-Anthony Lemieux --- libavformat/imfdec.c | 93 ++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 64 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index f208b262c3..ac212b05e1 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -203,11 +203,8 @@ static int parse_imf_asset_map_from_xml_dom(AVFormatContext *s, } if (asset_map_element->type != XML_ELEMENT_NODE || av_strcasecmp(asset_map_element->name, "AssetMap")) { - av_log(s, - AV_LOG_ERROR, - "Unable to parse asset map XML - wrong root node name[%s] type[%d]\n", - asset_map_element->name, - (int)asset_map_element->type); + av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - wrong root node name[%s] type[%d]\n", + asset_map_element->name, (int)asset_map_element->type); return AVERROR_INVALIDDATA; } @@ -333,11 +330,8 @@ static int parse_assetmap(AVFormatContext *s, const char *url) ret = parse_imf_asset_map_from_xml_dom(s, doc, &c->asset_locator_map, base_url); if (!ret) - av_log(s, - AV_LOG_DEBUG, - "Found %d assets from %s\n", - c->asset_locator_map.asset_count, - url); + av_log(s, AV_LOG_DEBUG, "Found %d assets from %s\n", + c->asset_locator_map.asset_count, url); xmlFreeDoc(doc); @@ -370,9 +364,7 @@ static int open_track_resource_context(AVFormatContext *s, IMFVirtualTrackResourcePlaybackCtx *track_resource = track->resources + resource_index; if (track_resource->ctx) { - av_log(s, - AV_LOG_DEBUG, - "Input context already opened for %s.\n", + av_log(s, AV_LOG_DEBUG, "Input context already opened for %s.\n", track_resource->locator->absolute_uri); return 0; } @@ -400,11 +392,8 @@ static int open_track_resource_context(AVFormatContext *s, NULL, &opts); if (ret < 0) { - av_log(s, - AV_LOG_ERROR, - "Could not open %s input context: %s\n", - track_resource->locator->absolute_uri, - av_err2str(ret)); + av_log(s, AV_LOG_ERROR, "Could not open %s input context: %s\n", + track_resource->locator->absolute_uri, av_err2str(ret)); goto cleanup; } av_dict_free(&opts); @@ -427,8 +416,7 @@ static int open_track_resource_context(AVFormatContext *s, st->time_base)) av_log(s, AV_LOG_WARNING, "Incoherent stream timebase " AVRATIONAL_FORMAT "and composition timeline position: " AVRATIONAL_FORMAT "\n", - st->time_base.num, st->time_base.den, - track->current_timestamp.den, track->current_timestamp.num); + AVRATIONAL_ARG(st->time_base), AVRATIONAL_ARG(track->current_timestamp)); if (seek_offset) { av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %" PRIi64 "\n", @@ -465,9 +453,7 @@ static int open_track_file_resource(AVFormatContext *s, asset_locator = find_asset_map_locator(&c->asset_locator_map, track_file_resource->track_file_uuid); if (!asset_locator) { - av_log(s, - AV_LOG_ERROR, - "Could not find asset locator for UUID: " FF_IMF_UUID_FORMAT "\n", + av_log(s, AV_LOG_ERROR, "Could not find asset locator for UUID: " FF_IMF_UUID_FORMAT "\n", UID_ARG(track_file_resource->track_file_uuid)); return AVERROR_INVALIDDATA; } @@ -618,9 +604,7 @@ static int open_cpl_tracks(AVFormatContext *s) if (c->cpl->main_image_2d_track) { if ((ret = open_virtual_track(s, c->cpl->main_image_2d_track, track_index++)) != 0) { - av_log(s, - AV_LOG_ERROR, - "Could not open image track " FF_IMF_UUID_FORMAT "\n", + av_log(s, AV_LOG_ERROR, "Could not open image track " FF_IMF_UUID_FORMAT "\n", UID_ARG(c->cpl->main_image_2d_track->base.id_uuid)); return ret; } @@ -628,9 +612,7 @@ static int open_cpl_tracks(AVFormatContext *s) for (uint32_t i = 0; i < c->cpl->main_audio_track_count; i++) { if ((ret = open_virtual_track(s, &c->cpl->main_audio_tracks[i], track_index++)) != 0) { - av_log(s, - AV_LOG_ERROR, - "Could not open audio track " FF_IMF_UUID_FORMAT "\n", + av_log(s, AV_LOG_ERROR, "Could not open audio track " FF_IMF_UUID_FORMAT "\n", UID_ARG(c->cpl->main_audio_tracks[i].base.id_uuid)); return ret; } @@ -706,13 +688,9 @@ static IMFVirtualTrackPlaybackCtx *get_next_track_with_minimum_timestamp(AVForma AVRational minimum_timestamp = av_make_q(INT32_MAX, 1); for (uint32_t i = c->track_count; i > 0; i--) { - av_log(s, - AV_LOG_DEBUG, - "Compare track %d timestamp " AVRATIONAL_FORMAT + av_log(s, AV_LOG_TRACE, "Compare track %d timestamp " AVRATIONAL_FORMAT " to minimum " AVRATIONAL_FORMAT - " (over duration: " AVRATIONAL_FORMAT - ")\n", - i, + " (over duration: " AVRATIONAL_FORMAT ")\n", i, AVRATIONAL_ARG(c->tracks[i - 1]->current_timestamp), AVRATIONAL_ARG(minimum_timestamp), AVRATIONAL_ARG(c->tracks[i - 1]->duration)); @@ -723,12 +701,8 @@ static IMFVirtualTrackPlaybackCtx *get_next_track_with_minimum_timestamp(AVForma } } - av_log(s, - AV_LOG_DEBUG, - "Found next track to read: %d (timestamp: %lf / %lf)\n", - track->index, - av_q2d(track->current_timestamp), - av_q2d(minimum_timestamp)); + av_log(s, AV_LOG_DEBUG, "Found next track to read: %d (timestamp: %lf / %lf)\n", + track->index, av_q2d(track->current_timestamp), av_q2d(minimum_timestamp)); return track; } @@ -742,7 +716,7 @@ static int get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac } av_log(s, - AV_LOG_DEBUG, + AV_LOG_TRACE, "Looking for track %d resource for timestamp = %lf / %lf\n", track->index, av_q2d(track->current_timestamp), @@ -750,15 +724,9 @@ static int get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac for (uint32_t i = 0; i < track->resource_count; i++) { if (av_cmp_q(track->resources[i].end_time, track->current_timestamp) > 0) { - av_log(s, - AV_LOG_DEBUG, - "Found resource %d in track %d to read at timestamp %lf: " - "entry=%" PRIu32 - ", duration=%" PRIu32 - ", editrate=" AVRATIONAL_FORMAT, - i, - track->index, - av_q2d(track->current_timestamp), + av_log(s, AV_LOG_DEBUG, "Found resource %d in track %d to read at timestamp %lf: " + "entry=%" PRIu32 ", duration=%" PRIu32 ", editrate=" AVRATIONAL_FORMAT "\n", + i, track->index, av_q2d(track->current_timestamp), track->resources[i].resource->base.entry_point, track->resources[i].resource->base.duration, AVRATIONAL_ARG(track->resources[i].resource->base.edit_rate)); @@ -766,9 +734,7 @@ static int get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac if (track->current_resource_index != i) { int ret; - av_log(s, - AV_LOG_DEBUG, - "Switch resource on track %d: re-open context\n", + av_log(s, AV_LOG_TRACE, "Switch resource on track %d: re-open context\n", track->index); ret = open_track_resource_context(s, track, i); @@ -804,15 +770,13 @@ static int imf_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; ret = av_read_frame(resource->ctx, pkt); - if (ret) { - av_log(s, AV_LOG_ERROR, "Failed to read frame\n"); + if (ret) return ret; - } av_log(s, AV_LOG_DEBUG, "Got packet: pts=%" PRId64 ", dts=%" PRId64 ", duration=%" PRId64 ", stream_index=%d, pos=%" PRId64 ", time_base=" AVRATIONAL_FORMAT "\n", pkt->pts, pkt->dts, pkt->duration, - pkt->stream_index, pkt->pos, pkt->time_base.num, pkt->time_base.den); + pkt->stream_index, pkt->pos, AVRATIONAL_ARG(pkt->time_base)); /* IMF resources contain only one stream */ @@ -832,9 +796,10 @@ static int imf_read_packet(AVFormatContext *s, AVPacket *pkt) if (pkt->dts != AV_NOPTS_VALUE) pkt->dts += delta_ts; } else { - av_log(s, AV_LOG_WARNING, "Incoherent time stamp " AVRATIONAL_FORMAT " for time base " AVRATIONAL_FORMAT, - resource->ts_offset.num, resource->ts_offset.den, pkt->time_base.num, - pkt->time_base.den); + av_log(s, AV_LOG_WARNING, "Incoherent time stamp " AVRATIONAL_FORMAT + " for time base " AVRATIONAL_FORMAT, + AVRATIONAL_ARG(resource->ts_offset), + AVRATIONAL_ARG(pkt->time_base)); } /* advance the track timestamp by the packet duration */ @@ -857,7 +822,7 @@ static int imf_read_packet(AVFormatContext *s, AVPacket *pkt) if (!ret) pkt->duration = new_pkt_dur; else - av_log(s, AV_LOG_WARNING, "Incoherent time base in packet duration calculation"); + av_log(s, AV_LOG_WARNING, "Incoherent time base in packet duration calculation\n"); /* shrink the packet itself for audio essence */ @@ -882,7 +847,7 @@ static int imf_read_packet(AVFormatContext *s, AVPacket *pkt) av_make_q(1, st->codecpar->sample_rate)); if (ret || skip_samples < 0 || skip_samples > UINT32_MAX) { - av_log(s, AV_LOG_WARNING, "Cannot skip audio samples"); + av_log(s, AV_LOG_WARNING, "Cannot skip audio samples\n"); } else { uint8_t *side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); if (!side_data) @@ -896,7 +861,7 @@ static int imf_read_packet(AVFormatContext *s, AVPacket *pkt) next_timestamp = resource->end_time; } else { - av_log(s, AV_LOG_WARNING, "Non-audio packet duration reduced"); + av_log(s, AV_LOG_WARNING, "Non-audio packet duration reduced\n"); } } From patchwork Mon Mar 7 22:15:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 34634 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1905566nkx; Mon, 7 Mar 2022 14:16:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSdb6CSaX/lyll1jjhtUTPdwaLYKLIOUV8MrsBlzYjq5+VResp1g8jD0lCz5U0+ex5nkTV X-Received: by 2002:a50:e60f:0:b0:415:9509:32a2 with SMTP id y15-20020a50e60f000000b00415950932a2mr13053043edm.235.1646691411279; Mon, 07 Mar 2022 14:16:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646691411; cv=none; d=google.com; s=arc-20160816; b=pBz4it7YIp6iKYZ/+RRYS+s8kbsSyHdVh3b77pND+p+M9l4VuX5vCKaQJ3X85h4GrW 3xeHEgiDyY9JrN2CsJxbJC4pVZjbvhe0+umk6CXz8+FfljYIHY6Tnz7pEr9AQugMwtH8 H749LMzxrKaQw/oBY0WV1eizCpr9G+58Uugj9Brx3zR54Au2e/kmLGfYV19mzfLHTAD7 9nIlsM66Nx7kXv2UWKpQLmTYLtIehOFGJ9uUvJZqDiBXq087fkAkio16g8hfZOr+TUu8 zFoU9FXqjQYjpBUm2o22riPOMOffMy50dwq58nIrqiQkha2XnXeKjv6fK17znwN1y8SU yhQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=iVEBAtSCicEIyOD+IpZCCZUGSgTAEXajly20z8MNumc=; b=exxlpORNK/G5R9K8r2s7TYzuIOLVQz5RKWRM0HULy8Wrf72CJoHrNCToQNkmlrKEiY LZJmKTAfi9fgRm7VbbpFUhiUvBNvsOgwfh5e4bQwOdXMHz02SOhYEMU8aTY3G4gyqVrT 7WyNpkpZoEkho7VGO81oEeKD1Qcsk6hQS7HF3ygX1vnFQGrApc1du2GIG3jjV6z6d01m pHHM/oPcprBjEX4Qg5mDC8gMQfSiFVIlX4BJQ6Wf5iQ9/+q5bcVgyUFIzu3IGnM6GQBS YM2AdNaI47urzUoOK8VUiUhRG99WvS/GwW2ScBe3pGsvJDQhWF1Gu0rr72982dU4fRzQ JUVg== 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 k6-20020a170906054600b006a79e13f94esi8031733eja.294.2022.03.07.14.16.50; Mon, 07 Mar 2022 14:16:51 -0800 (PST) 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 4A17068B19F; Tue, 8 Mar 2022 00:16:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B065268A7A1 for ; Tue, 8 Mar 2022 00:16:18 +0200 (EET) Received: by mail-pf1-f170.google.com with SMTP id t5so15650209pfg.4 for ; Mon, 07 Mar 2022 14:16:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gds4VZe5jtySS56ro4KaO92EQRdmEAgo3tCJoKwzewM=; b=qo/0JMTVxpy9DV6aJryNn2uZKVemzqyFp8l4yH9dCBmTQ1CEGjbOJycsTBXjBPSH7p NKfHfHjdaOuS2dWn4g0eSwqOLaGTi2vpRLvJjoFlhnpkcUCtLXLSX4YC/00MAn+/xTk2 8+LrTiwQsknwIRSZqJLpfN02JtE0GRQ8/CYrkYPVuYBJzL/QstI+5NqoZ+gcl9R84/z5 CEEE57G81Tbbb5e0tjIS0WkBMbFpEljL+1xGPX0Mtl16DCBczc6w4y5RuEb1N8RAzw43 kFdfdZJf5IO/rh4ywbJqYtvXdODx8CK2UPqu31/oyT9s14wUgVbX8QdPAo445Xmdxkpc VZlw== X-Gm-Message-State: AOAM533/Z3LEbjEXHSth40WCTBw9GgOsA9/DmWeERFTs9eWG3z/PZwKA 8VsKMo5dy/dArZMCkOjvDFZUVxDKV00= X-Received: by 2002:a63:6906:0:b0:36c:8493:dadf with SMTP id e6-20020a636906000000b0036c8493dadfmr11726643pgc.80.1646691376727; Mon, 07 Mar 2022 14:16:16 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id g12-20020a056a0023cc00b004f707cc97f9sm4421421pfc.52.2022.03.07.14.16.15 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 14:16:16 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Mon, 07 Mar 2022 14:15:52 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Mar 2022 14:15:39 -0800 Message-Id: <20220307221542.3265-4-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220307221542.3265-1-pal@sandflow.com> References: <20220307221542.3265-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 4/7] avformat/seek: add ff_rescale_interval() function 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: xVrmB6WMJfVo From: Pierre-Anthony Lemieux Refactors a function used by avformat/concat and avformat/imf. --- libavformat/avio_internal.h | 21 +++++++++++++++++++++ libavformat/seek.c | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index 1f5e3d474b..ef2ec7864f 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -23,6 +23,7 @@ #include "url.h" #include "libavutil/log.h" +#include "libavutil/rational.h" extern const AVClass ff_avio_class; @@ -281,4 +282,24 @@ int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, struct AVBPrint *bp); int64_t ff_read_string_to_bprint_overwrite(AVIOContext *s, struct AVBPrint *bp, int64_t max_len); +/** + * Rescales a timestamp and the endpoints of an interval to which the temstamp + * belongs, from a timebase `tb_in` to a timebase `tb_out`. + * + * The upper (lower) bound of the output interval is rounded up (down) such that + * the output interval always falls within the intput interval. The timestamp is + * rounded to the nearest integer and halfway cases away from zero, and can + * therefore fall outside of the output interval. + * + * Useful to simplify the rescaling of the arguments of AVInputFormat::read_seek2() + * + * @param[in] tb_in Timebase of the input `min_ts`, `ts` and `max_ts` + * @param[in] tb_out Timebase of the ouput `min_ts`, `ts` and `max_ts` + * @param[in,out] min_ts Lower bound of the interval + * @param[in,out] ts Timestamp + * @param[in,out] max_ts Upper bound of the interval + */ +void ff_rescale_interval(AVRational tb_in, AVRational tb_out, + int64_t *min_ts, int64_t *ts, int64_t *max_ts); + #endif /* AVFORMAT_AVIO_INTERNAL_H */ diff --git a/libavformat/seek.c b/libavformat/seek.c index 405ca316b3..890aea7f8a 100644 --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -751,3 +751,13 @@ int avformat_flush(AVFormatContext *s) ff_read_frame_flush(s); return 0; } + +void ff_rescale_interval(AVRational tb_in, AVRational tb_out, + int64_t *min_ts, int64_t *ts, int64_t *max_ts) +{ + *ts = av_rescale_q (* ts, tb_in, tb_out); + *min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out, + AV_ROUND_UP | AV_ROUND_PASS_MINMAX); + *max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out, + AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX); +} From patchwork Mon Mar 7 22:15:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 34635 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1905671nkx; Mon, 7 Mar 2022 14:17:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4VH8d9caEyt1k1wrWSbrj6+9K1yiRr0YbiWVEPILa4z/PmySaz84KMPgtJ0lQbsRMAiDH X-Received: by 2002:a50:f68b:0:b0:415:a36c:5c0b with SMTP id d11-20020a50f68b000000b00415a36c5c0bmr12941540edn.272.1646691420783; Mon, 07 Mar 2022 14:17:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646691420; cv=none; d=google.com; s=arc-20160816; b=fKB4chCsb9jPI7fIufVepyqeeRv1WmMveXciEn3Sg0trl/71t87UPGXHkYMqzdd3kh +brIpT8r4MWkN5zhj32sNdbRC3gSjXn5mMFjy8f0JtQy7MQj+mdABrrIobYwOlMN0xNS DOPa0zkO4eyVtm+ge87K69K1RwElj7QSIhsSqpjPRpMkwB3ZVQFL3rjntHgCbQUsTNaB RgBl/HiiFj0L58u3yJyamPCqosrg1aUGLl+AH+oCKUVN0Ox0tkAA2lfZSTMtwNFJW5da /OIXnxeFhQiIPw+hBA5CmMOc0HPZGxCMggBbQzqYLo44ZSgWZ65b2g0Nh05AE+4UjSPY u/6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=2bLUrieanKKB1N6rWACGhMIzs5WgrGmWp1vWqWsVzCQ=; b=NnIVHFOnUfl5CLarltjKOWIZxhTVo0pbC82pVMnUFHNjS1PjGgfC3FeFASHIIhLsc4 XyJLjis2odm9T2wnGOuU0FASGvTn9xmtmW34jKpP/YO58qaFB6vn8oD5F/4pOTTm/Vjm Txg3zn9QnziuDmLKOdt9EtS/jh6GSoKcQXB0YKYFGzlY5IjvyMG1zH2i6M8Ue6QmeAgT up5dDTtAp2pTZAsDq2JgHwMxgAhMjAiSi9cCjVnY3TRCIhLaollIL92bY00MXc+BuV++ K1fqqTn91wATAUtlPN1uhT7tlzT5k3QbZIIew598FCGII7hcJ37CWeNq41pkIlNmN+fr L7cA== 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 hc44-20020a17090716ac00b006d8d52ba7easi10324905ejc.239.2022.03.07.14.17.00; Mon, 07 Mar 2022 14:17:00 -0800 (PST) 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 4C12368B1A8; Tue, 8 Mar 2022 00:16:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 25C9C68A7A1 for ; Tue, 8 Mar 2022 00:16:21 +0200 (EET) Received: by mail-pl1-f171.google.com with SMTP id t19so11738257plr.5 for ; Mon, 07 Mar 2022 14:16:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mhh/yKibK1ghoBoKp4Q8Ihtw/ZH51lTXqJpqVMCtAGQ=; b=CkIPYXpcLVpO2ao+xyAdXHUEDDdio4cOuj2ecmL+RbhFKJ14xDc0MAFXrlpiDvFHuL 9+nzdzC2/qlyRWrUsDMicsTLwhGYXMB3YnVCor5XIlXSsWh0qNorxrXr1cauTj9FpT5U zBwQK+ArJYdUSyao4mbOF7ryNeQv7tHz9S/BD2vdAmO/2suPkpai9owaYyciwM45x8rO Ik29ErrL7ClOjqVwArs5DhqKAP7b30cp4+dF3+1AJqyTVj2Lr+M4naOVUlk5Xa9xB3SF sP+Ra5vsYKwrBD/oOp36xSYWiP5++Bdidifxzu8Sn10XRpUancON1rk2n/Nw3bP8dZrt WKUQ== X-Gm-Message-State: AOAM531gDz+ugu9uweocxaz8ysmH62CCsqmPk/dBKNKLX1zdoO9Z8MlI yFx8a2FFtKw5B3V8wXaUjz2t77t8WG8= X-Received: by 2002:a17:902:e808:b0:151:f87f:3749 with SMTP id u8-20020a170902e80800b00151f87f3749mr2861049plg.24.1646691379100; Mon, 07 Mar 2022 14:16:19 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id pj13-20020a17090b4f4d00b001bf2ff56430sm318595pjb.30.2022.03.07.14.16.17 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 14:16:18 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Mon, 07 Mar 2022 14:15:54 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Mar 2022 14:15:40 -0800 Message-Id: <20220307221542.3265-5-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220307221542.3265-1-pal@sandflow.com> References: <20220307221542.3265-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 5/7] avformat/tests: add test for ff_rescale_interval() 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tVPBNmmON1S/ From: Pierre-Anthony Lemieux --- libavformat/Makefile | 1 + libavformat/tests/.gitignore | 1 + libavformat/tests/seek_utils.c | 57 ++++++++++++++++++++++++++++++++++ tests/fate/libavformat.mak | 5 +++ 4 files changed, 64 insertions(+) create mode 100644 libavformat/tests/seek_utils.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 6566e40cac..3acc939551 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -707,6 +707,7 @@ SKIPHEADERS-$(CONFIG_NETWORK) += network.h rtsp.h TESTPROGS = seek \ url \ + seek_utils # async \ FIFO-MUXER-TESTPROGS-$(CONFIG_NETWORK) += fifo_muxer diff --git a/libavformat/tests/.gitignore b/libavformat/tests/.gitignore index aabf76345e..cdd0cce061 100644 --- a/libavformat/tests/.gitignore +++ b/libavformat/tests/.gitignore @@ -6,3 +6,4 @@ /seek /srtp /url +/seek_utils diff --git a/libavformat/tests/seek_utils.c b/libavformat/tests/seek_utils.c new file mode 100644 index 0000000000..f368578fc4 --- /dev/null +++ b/libavformat/tests/seek_utils.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Pierre-Anthony Lemieux + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavformat/avio_internal.h" + +int main(void) +{ + int64_t ts_min; + int64_t ts; + int64_t ts_max; + + ts_min = 10; + ts = 20; + ts_max = 30; + + ff_rescale_interval(av_make_q(1, 1), av_make_q(10, 1), &ts_min, &ts, &ts_max); + + if (ts_min != 1 || ts != 2 || ts_max != 3) + return 1; + + ts_min = 10; + ts = 32; + ts_max = 32; + + ff_rescale_interval(av_make_q(1, 1), av_make_q(3, 1), &ts_min, &ts, &ts_max); + + if (ts_min != 4 || ts != 11 || ts_max != 10) + return 1; + + ts_min = 10; + ts = 10; + ts_max = 32; + + ff_rescale_interval(av_make_q(1, 1), av_make_q(3, 1), &ts_min, &ts, &ts_max); + + if (ts_min != 4 || ts != 3 || ts_max != 10) + return 1; + + return 0; +} diff --git a/tests/fate/libavformat.mak b/tests/fate/libavformat.mak index 59ff0ebc8d..d2acb4c9e0 100644 --- a/tests/fate/libavformat.mak +++ b/tests/fate/libavformat.mak @@ -26,6 +26,11 @@ FATE_LIBAVFORMAT-$(CONFIG_IMF_DEMUXER) += fate-imf fate-imf: libavformat/tests/imf$(EXESUF) fate-imf: CMD = run libavformat/tests/imf$(EXESUF) +FATE_LIBAVFORMAT += fate-seek_utils +fate-seek_utils: libavformat/tests/seek_utils$(EXESUF) +fate-seek_utils: CMD = run libavformat/tests/seek_utils$(EXESUF) +fate-seek_utils: CMP = null + FATE_LIBAVFORMAT += $(FATE_LIBAVFORMAT-yes) FATE-$(CONFIG_AVFORMAT) += $(FATE_LIBAVFORMAT) fate-libavformat: $(FATE_LIBAVFORMAT) From patchwork Mon Mar 7 22:15:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 34636 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1905780nkx; Mon, 7 Mar 2022 14:17:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSQcnYHWHumXwGb2engMrrcZEEty/ySv7JPxAE/q8xKntdMDtMlDbDiZFKwGfkl6eQB9hS X-Received: by 2002:a05:6402:b87:b0:416:44f5:10d1 with SMTP id cf7-20020a0564020b8700b0041644f510d1mr7295633edb.323.1646691431052; Mon, 07 Mar 2022 14:17:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646691431; cv=none; d=google.com; s=arc-20160816; b=GxgMpL3AmbFa1sgGPUOdyGIWh56ISif9YNefEk2NtaaszorqZR/D0Y2QyfMT2YvTFz AgJqvera8koCQNOWqjUJhYt87ugDNH2d83BzOR+gMQaEB1ubb8pVns5qXXVX74ba3AZC J/7xebUSQRHY/vRpdR1ZopXNPrYuExmIB0fOMVlA+9Lz+W7/ppoNbXqnsWCuOG4NaFnG W3Ka7Rk1f+cjjkxb3Lklif032jfPVnab0Xe+sLmck5mfGQe8gd8TKx2/7vP9CSMyqE7u 569nKD18SNoI8vbPdGlH+0FIGRUXvxai0Qj+n5GraqCimHel8KsY6JvmVm2AzGWqVF9O ow2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=XCUXXmyfBKf1z3nuvGVMphv+mYfOS3qPcNmA7mykuN4=; b=A0pPikS+FN6ZS/oyPAigrW9uUt9PJSsY0jGTQNC21y8xO79Dyeve3VqwnTVraZWnmo WcUnAGIpofI9V19NqanqyLecWOTauEIHnw+yik3U1jq8xjd7TGogVKmO6U9odORmLKKo oHqEJKssftntQCaQrVz0ldA/e7y0lMYvCzHivF8F/xDc5Dz2/rwj2lTl6xl5agZnq+8/ hSaiUeeIF8n2CZWe+cI9BWEK0kUhQwkCIIVPEG84KP8u3rEr/vx6LeBVUib1dRl8QbOs txBc02T+dG9SxYwOupzctXlwrvfIN5r97tqKTUrkfoicB4toa3TBiNqCrBWsZpGepgEE lVZg== 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 ga11-20020a1709070c0b00b006daaccc9629si7732150ejc.517.2022.03.07.14.17.10; Mon, 07 Mar 2022 14:17:11 -0800 (PST) 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 49F4668B1B5; Tue, 8 Mar 2022 00:16:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A297F68B1B0 for ; Tue, 8 Mar 2022 00:16:23 +0200 (EET) Received: by mail-pf1-f169.google.com with SMTP id d187so15626937pfa.10 for ; Mon, 07 Mar 2022 14:16:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rPGMObBRuj26RPvSu+2dG8DtZLw1ENbsXIR+DY1VKWM=; b=FYBUqW8ZvY4DIwn/OY3XOQgZ6f+Ic6oHWgEkt31Cw9+0jrM1X5QWXdYpPAFWlZElGm try8ObSqo4JwtFEULSXCeNPGibSne0T2FCgUAG+cbpC/nTgeM5gJH+UVe++8vPD5IOoQ a5O8jr51suzQUd1nKRSYklORXKqDi9eeiubUWoPgFGIBH56xwnS92DBdoKquqLRNj76V hOA8jdU41qcSb3uFIBJWv3cL5w5XnsN1SWetC5oZhc2v/TBn7mPqIrmiJD7cs40kfkcM TgQoSrGEh9RfI7cG/RObcKOx1GuCMFXFwtbY2YZcMZEASjTbjez6MshWozK63DNK8V75 HkcQ== X-Gm-Message-State: AOAM532XNBOa/h+tlaXSe3/Xu51b6D8o0Mn3LP8Oz8EGVy9+g7w4uHTM lxVA/25z1fLHbEN7JPuNW4QgNApujAg= X-Received: by 2002:a63:7d49:0:b0:378:907d:1fc7 with SMTP id m9-20020a637d49000000b00378907d1fc7mr11543737pgn.252.1646691381573; Mon, 07 Mar 2022 14:16:21 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id x23-20020a63fe57000000b0036490068f12sm12687814pgj.90.2022.03.07.14.16.20 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 14:16:21 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Mon, 07 Mar 2022 14:15:57 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Mar 2022 14:15:41 -0800 Message-Id: <20220307221542.3265-6-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220307221542.3265-1-pal@sandflow.com> References: <20220307221542.3265-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 6/7] avformat/imf: refactor to use ff_rescale_interval() 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: NM86q564cVEP From: Pierre-Anthony Lemieux --- libavformat/imfdec.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index ac212b05e1..a19e431df3 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -904,14 +904,6 @@ static int imf_probe(const AVProbeData *p) return AVPROBE_SCORE_MAX; } -static void rescale_interval(AVRational tb_in, AVRational tb_out, - int64_t *min_ts, int64_t *ts, int64_t *max_ts) -{ - *ts = av_rescale_q(*ts, tb_in, tb_out); - *min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out, AV_ROUND_UP | AV_ROUND_PASS_MINMAX); - *max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out, AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX); -} - static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb) { int dst_num; @@ -937,13 +929,13 @@ static int imf_seek(AVFormatContext *s, int stream_index, int64_t min_ts, /* rescale timestamps to Composition edit units */ if (stream_index < 0) - rescale_interval(AV_TIME_BASE_Q, - av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num), - &min_ts, &ts, &max_ts); + ff_rescale_interval(AV_TIME_BASE_Q, + av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num), + &min_ts, &ts, &max_ts); else - rescale_interval(s->streams[stream_index]->time_base, - av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num), - &min_ts, &ts, &max_ts); + ff_rescale_interval(s->streams[stream_index]->time_base, + av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num), + &min_ts, &ts, &max_ts); /* requested timestamp bounds are too close */ if (max_ts < min_ts) From patchwork Mon Mar 7 22:15:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 34637 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1905877nkx; Mon, 7 Mar 2022 14:17:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjASr7X+88dqNNwmglpDy/46SC/7fl/m6AtsLz2PbZsY8KunPDoy9p4tkWV4tUxiTNpuL9 X-Received: by 2002:a17:906:3ec9:b0:6bb:2eb9:84f with SMTP id d9-20020a1709063ec900b006bb2eb9084fmr10617502ejj.86.1646691441209; Mon, 07 Mar 2022 14:17:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646691441; cv=none; d=google.com; s=arc-20160816; b=blpUe3momxkYU3PIpmQk6vzfTX2jbsdYSELOXqwyCqZQYT60HR2hjbOCz7IM82vVeM YdZNoWjKyvzDam7iZXKpCQQtqRR8d1cM5InrL56bcrMn3GT4DUAdqwz3aIV6WLR1Wy05 k10olyN3ILy5Erd+NuLtXt0/VeGfdgg0A/8vhqN6heuNApKiJM/Ezd35KR/7dkiTM64U VcR5TfqloQQIXepmMjUg9iyRYhgumTt1a+Q3ZMfeZOoF9PQdwFBFimOEpwPdh/ZCOB0T PxytihjJyfMiQdYIIjx4sbwICfi4nKr4fz46sJBoCsVR7oLrKppCiCbF9ThDUe+gBDrq YwOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=adQHsgltQeHS2UnjRjS4TcLvuQRsXl+LhaQUMVUsku4=; b=JujhurZGF1rgJ/oWYEexvFOes1aG92afE0Q0frDjsm65ylT9foo0zoL55LTHn0R8xg bBk79lBFEBtAGLRjdoC0P976mJVSL8TZfQG9CbywONhn2wox8JmqOq84SBvbGqdOg35A 3ziVCU6VQPA3mMb9iio1jAfkV6zLrDcS1Zl/8nRTThZnvQi6TKr7tk9uiHh1sCgp3PzX BCXTHr8ugvBq10MJ68fPjaGYNn0Kr4K0zvCCSQdq60enQ1C3oBpQ5qAhHG9Mu73YnVQl 2lHhr5pYo5TGCFgRclUisZ2BYf4Fz/6cgWN0JuFB9mJNRQ3tx6tenoiejee5vLQDuzL9 kslQ== 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 y15-20020a50d8cf000000b0040f13a5a14bsi10234076edj.95.2022.03.07.14.17.20; Mon, 07 Mar 2022 14:17:21 -0800 (PST) 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 37D0468B1BA; Tue, 8 Mar 2022 00:16:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE09F68B192 for ; Tue, 8 Mar 2022 00:16:25 +0200 (EET) Received: by mail-pj1-f50.google.com with SMTP id mg21-20020a17090b371500b001bef9e4657cso531329pjb.0 for ; Mon, 07 Mar 2022 14:16:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p2eS/ya7SK/Up3j1eIXTbZYev9YJ5Qysfbwmtd5llzE=; b=ELl6zT1vqK0hcvZgy6taQM075tBsqkoIqCwruacEo3gqb4PCGqUgzAKURs0Dw7bt4t cGBC9MsAaRJYHzC8VIVLwZhb4efznhvutfPPy+G2tdEuDq6Wg4/ODoZR2XIushUzdal2 xQDyWmaWFECHWPc6xTvO5KZar5ObOe82orWiVg4lKjf5B6yPs2RlosOmgoUDa4kzKmKv VxHH5NutkFo2a4E6iwWseVksJzDb3rEqGcRquNNK/Vcdin4ptxVuoJiN8KosOn0iu4X3 EP7D+JcP/kQTYW5ZCSRdI65+RbgWmdhotR0N4pico/9UHqWflKcKxZIkB3IN5vL9Rj+D 4chg== X-Gm-Message-State: AOAM532z6+UdRxcV02SkEk/Qv49tUmdKNVkp4MpsDbzs0aTpN8bRFR2+ cVw4P1bTUk5Y4RTYgaV2PpA06S1K4bw= X-Received: by 2002:a17:902:d486:b0:151:8e66:621c with SMTP id c6-20020a170902d48600b001518e66621cmr14226039plg.141.1646691384000; Mon, 07 Mar 2022 14:16:24 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id m12-20020a17090a414c00b001bf6d88870csm322883pjg.55.2022.03.07.14.16.22 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 14:16:23 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Mon, 07 Mar 2022 14:15:59 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Mar 2022 14:15:42 -0800 Message-Id: <20220307221542.3265-7-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220307221542.3265-1-pal@sandflow.com> References: <20220307221542.3265-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 7/7] avformat/concat: refactor to use ff_rescale_interval() 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Act++vjWmIbz From: Pierre-Anthony Lemieux --- libavformat/concatdec.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index 0603c6e254..cfe1329105 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -816,16 +816,6 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) return 0; } -static void rescale_interval(AVRational tb_in, AVRational tb_out, - int64_t *min_ts, int64_t *ts, int64_t *max_ts) -{ - *ts = av_rescale_q (* ts, tb_in, tb_out); - *min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out, - AV_ROUND_UP | AV_ROUND_PASS_MINMAX); - *max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out, - AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX); -} - static int try_seek(AVFormatContext *avf, int stream, int64_t min_ts, int64_t ts, int64_t max_ts, int flags) { @@ -838,8 +828,8 @@ static int try_seek(AVFormatContext *avf, int stream, if (stream >= 0) { if (stream >= cat->avf->nb_streams) return AVERROR(EIO); - rescale_interval(AV_TIME_BASE_Q, cat->avf->streams[stream]->time_base, - &min_ts, &ts, &max_ts); + ff_rescale_interval(AV_TIME_BASE_Q, cat->avf->streams[stream]->time_base, + &min_ts, &ts, &max_ts); } return avformat_seek_file(cat->avf, stream, min_ts, ts, max_ts, flags); } @@ -853,8 +843,8 @@ static int real_seek(AVFormatContext *avf, int stream, if (stream >= 0) { if (stream >= avf->nb_streams) return AVERROR(EINVAL); - rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q, - &min_ts, &ts, &max_ts); + ff_rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q, + &min_ts, &ts, &max_ts); } left = 0;