From patchwork Mon Feb 21 06:02:24 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: 34424 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp3105504nkx; Sun, 20 Feb 2022 22:03:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHE5rNl7hmM187mGUN7HaSlF7DB2OGWQn2WWqv6WzmnTWrqPn96uWQM7+Lvtz9hgCO4NYN X-Received: by 2002:aa7:c3d5:0:b0:40f:b885:8051 with SMTP id l21-20020aa7c3d5000000b0040fb8858051mr19758943edr.395.1645423381340; Sun, 20 Feb 2022 22:03:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645423381; cv=none; d=google.com; s=arc-20160816; b=DjStbJtaO3Pj/z5Hqc5BBDqTDP1AAYAchny0F1E8pto2vJ/PTwUIKnW/gAEQvszAB9 Id4/Sw9IyAqFmi44TIC5ussqxNCKWRNSoYPOfx13aIb8CRfZoCeS5EzndgpGckC2Mzin yqUOcXKPPrv7OKHJrc+spHjqJ+TMqaitnx9Jol5wGjdKvT6TvtNVIx1CTlzgbqlpu8By tfcAA8FsC3FNTCbNugDIP5WuOtmyPuhLVItchQKMrwm6RpFWiaGWrgIAjhXqCDVv0IvP JFVOn5oRrxhMCO9v4MIYLJoUAF3eZJA6UTq9RDAPwMwYq1zDyapL9szVnvALilsTnTEo nTDw== 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=nvHycvUVEncYqRA0ih2ERecrsqQwy2QfPkE2qgZMFQHX/HmncTW7syztuycPYrh4lg L/K2qjb3r46azp9Ja+hBq1RUnkiylfXFLLEH2zO30qk6wVoJ057RiQoPGznQsME/uNw8 RVZCei3nxyuB7l0JaRo23AxDiT/rSM9iO8pX0CqTWX+aA6fcSoc1MtqNfO8wKBIKQuHo KF5LgI+UeqEHLe+WOJxP+mk0+ZixEAUuSrEUk5/AoVp31oVHrgAsrmdI/7FAGZCU1hNT 1K5UFwrLRKWDkbkx77Iy/R/rcNtoCcRuVIduMSFS/LV+m7vCa0JZFq5IDMvqg3uVY/e9 EU3A== 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 s15si4779849edx.609.2022.02.20.22.03.00; Sun, 20 Feb 2022 22:03:01 -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 978AB680529; Mon, 21 Feb 2022 08:02:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DB1E568A596 for ; Mon, 21 Feb 2022 08:02:49 +0200 (EET) Received: by mail-pg1-f174.google.com with SMTP id d16so13395491pgd.9 for ; Sun, 20 Feb 2022 22:02:49 -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=aSD7qq/ifbpSHDhVVTGlYY+vorwGFNlj0snPmJqNzCV7nLHjRpIdYxp2bD2o8Io240 2GmUK5AGt5NE3uoepqlB5fdHN40GqLF6q49WjdCaIhXrOFCDoYeG1B/JVsZ9YnWWzD11 PqRpZ5x0WQFW7ZKN9t+8vNZ+50DKmPTYsLNJnfZE3aN5LPbdifhlPsvoPAf5DoT1nIWZ eMLtNlj99U1VAeo53cJ+F0BdMltcqvXW7cTM18cJGIdlh3nRcYjt3kpJGTu5/QJ7L2ds Tg4Ep8RWDwdtzpGkBMgVPGZbPxe679wCuvcVgAfLRTv8LB3bw33lWy862Y69QG9KJwgu K6GQ== X-Gm-Message-State: AOAM531YzPvepHCrZnBR0V3o/FM3cYgnhmBdnGLBnROgISEKNLJrnvHY dyHuXgIhxnxTI/I01v/bv2HF0gNaC7g= X-Received: by 2002:a05:6a00:2387:b0:4e0:5414:da5c with SMTP id f7-20020a056a00238700b004e05414da5cmr18625248pfc.85.1645423367371; Sun, 20 Feb 2022 22:02:47 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id g63sm10780633pfb.65.2022.02.20.22.02.45 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Feb 2022 22:02:47 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sun, 20 Feb 2022 22:02:34 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Feb 2022 22:02:24 -0800 Message-Id: <20220221060230.6665-1-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: fnoQ93JVDzQV 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 Feb 21 06:02:25 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: 34425 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp3105601nkx; Sun, 20 Feb 2022 22:03:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKPTvhmyrZnAklvU5qGlRPnFW6uxv2lcvhE3sD/RjMRZJhJVh7Veb5To8gqV2E4zKO/CvM X-Received: by 2002:a17:906:3a18:b0:6cd:ba45:995f with SMTP id z24-20020a1709063a1800b006cdba45995fmr15116015eje.328.1645423392604; Sun, 20 Feb 2022 22:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645423392; cv=none; d=google.com; s=arc-20160816; b=so+wKnmO9RMKI+yNrboPw/MjGpru+f4OkrGsWmJlROVBm5pcrcDPVtDPKXVpy2vebK FyOiYmgkK4z7gZJXXKJu+5I1WVLCpN74rnpDIPrYfjdq31FOKsmtQnQ94PH7W/iVzPnP M59kwKcCX4WcP9OAQC9XK7gWtcKWQ17D/rd31XDb1wmIrtvY3thX/48pEaNwWc73ugWn USaeJSVaXR52i4lZNQmFrySvVk6rwBSFPc9zrNAUZPoWTyPa5llq+t38vBZT7vBWExX0 vBVEf19kvp36Pqc1hm33JSnUPWzeM8FjlOmaCzL5d2xiXuZyE++a1jnhXa4vXAEouczM kTow== 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=TDNP4JLtVMIAS2bU6dBkyGVvh+l7IE14XlKF8GLXyDATjtFmwD6g+Uzo7QZMoUVOSK nMl0Y6kBt/+ZOzJLeMRGcNCPZbHR3LJsR2Qgpy9yoZR6GtAmZ8zxwqo+zCO+ovwl3TK3 HlS5395Zua/lRx7kTwCTQQFKzimrr9TQ2pzHJUHvnCxMtHmqt71jY/uhDBZnNPoRE9uy 8PJ8wBqPW18pR3aOXR89LHQovZZpCRbIsqpKiZfAd8rMIvKmjeX4cYS1J9Sobe3lmEX9 KeebBJna66OjWa5K75qSSRq25DN5+oDog5ToFnzJ5npzEWIgKWGmuJd93ipEsr2VxBFI 9pDA== 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 t19si3655925ejc.940.2022.02.20.22.03.12; Sun, 20 Feb 2022 22:03:12 -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 BD9B268AA6A; Mon, 21 Feb 2022 08:02:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1124F68A948 for ; Mon, 21 Feb 2022 08:02:52 +0200 (EET) Received: by mail-pj1-f43.google.com with SMTP id cp23-20020a17090afb9700b001bbfe0fbe94so4546466pjb.3 for ; Sun, 20 Feb 2022 22:02:51 -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=uPAcPJPnGk1VxdaVN+So5xCEvrKty12IZqVhMEJMp76efz/0IFsczO+CS0mV04dw5U qidRpZuZeuqJ71/ruDq8qVOF8Ovr88n0he0TaQNfnKvsE6SvEKbr8n9QYF9eAkPnGArX TZ3qMR99HwnyWiac8B6orq/s6NlmKet4Ft1afMuaO7LywVO1bNSCObcHHtOvBjZj4tOK 9JmcPuQ4vkuhQvBvnhoVKPBdclgadUO6ovmVI48e1CJPc1BE+Ia0iGVMaGIDwwgKmK5j lbMmZ28QuUx4vAF/4u0JLWUliOvRGH3x4m/I0FZ2AFNPZnLV8/aIJxk5csv0qIEK3UTy erSQ== X-Gm-Message-State: AOAM5309LGIZ8y3XOxVPfRzErh9BvVXspWTKmjyD2WzciO3LoZHia5sJ PRCqlpyTHCzxPyxMVgeHpzldEO5jxOE= X-Received: by 2002:a17:90b:b15:b0:1b1:de14:80f with SMTP id bf21-20020a17090b0b1500b001b1de14080fmr20114594pjb.47.1645423370038; Sun, 20 Feb 2022 22:02:50 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id x14sm16818108pgc.60.2022.02.20.22.02.48 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Feb 2022 22:02:49 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sun, 20 Feb 2022 22:02:36 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Feb 2022 22:02:25 -0800 Message-Id: <20220221060230.6665-2-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220221060230.6665-1-pal@sandflow.com> References: <20220221060230.6665-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: 4ttao2b47jvA 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 Feb 21 06:02:26 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: 34426 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp3105680nkx; Sun, 20 Feb 2022 22:03:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIL7ub5oVi7Sbxmuh3FAEjuW563Y6kz6pMYTCUj71wmewKbirA4pXjGuHzXP+i4SrQtRzA X-Received: by 2002:a17:906:2b4c:b0:6cf:740f:7719 with SMTP id b12-20020a1709062b4c00b006cf740f7719mr14643417ejg.569.1645423402997; Sun, 20 Feb 2022 22:03:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645423402; cv=none; d=google.com; s=arc-20160816; b=dUbQpAMozVXU/1D0rJq+EZuhqltzEH2nhDv4driCYj5YO1l4JBV1WDInnzQhGfMlpx BCQ6a/hvIGQmhZ5PeOh4HuCIsRCp2kPTEJV6x8g4BWxsEQN/cNxfG3JLU32HKyQ59oe/ QyFnNvzPMGmxgXHOCxkLN1djs/60hbo07jILgdmznxilI8V+/IZfEkwpCfNuIcCjSgDW un5MW2gZN8HwFVU4+5nnsDAWX+aVkUoMsdTfPXo9dRnv3GZRXb88iyBzAb/midTZLBzP OoSVTqjR+DW5dGAv57Rl8xmfkomxj6B24wU1MbaGRx3QISBVYXlOwNyoIdBh/JAOCu8C 8xoQ== 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=XqXhxuB8evNhZg7ibE0q+MFJq/q9EuOVjpr9GQhcYKl9ENmntqo305zMYI9ggUwNub 4lv6Zsn40AtQrqWi5+mzhdS0t28/XtzEUiKNeCV63szUnu6K/wIpgScTms3q5fwIdtVW LTwTOSDZekG/ucak3dsIT0Kaf92PsnONIRXHr1h1XVeaLYLibhc1uGAY6OUxUtF3s34t j0zir9k4CUbcW5skkF5TCoytG9L0FSlsmvIfe/ZApzuSJQNv7gu9XroIsIYme76/VYQh 8m7o8XiGhRQfveBhVgUipbBJDFimcmYpqJYEbzup8ACODEGi7KGjGvMEWOj10UQo4ks2 FsPg== 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 g12si10033861edy.112.2022.02.20.22.03.22; Sun, 20 Feb 2022 22:03:22 -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 C8DF868A6E0; Mon, 21 Feb 2022 08:03:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5557468AD9E for ; Mon, 21 Feb 2022 08:02:54 +0200 (EET) Received: by mail-pl1-f177.google.com with SMTP id l8so12039881pls.7 for ; Sun, 20 Feb 2022 22:02:54 -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=cMafIMdWrcNtgGqqvM2+QWQV20tNJVZmFseR1Zay1OCb/nsy4hAb49m1CqCU78JwDB jbec4GygtQ6R+xwOeRAKWI7PFMvh9cFZTdpOzxWeAPyK3pO+2pVTds6RZXX8kLzOQy3g y17vCYuovHzPun+AWd0PouNablLYTkHZLeksmHkz1nzPea0mZEYbPSZSgrIsF2SMherJ XJUQTTQN5z8isng18w1dUnREmHeVfJoKdvshSZ3O42ib9UJxqcGcTx3cHa6lZRpZ05GT zuJp75ffbnXLWTm6+vjCS9iRnRdSDZPXYw4Uoezo0Py2T4hONEf1DcnQHeI3y+VHmcXj dnNA== X-Gm-Message-State: AOAM532K7PWES1zpGemZNiO2c/EYDM2RyRl84hK7Gpgbn+JQ6FeUFbI2 6kI6TtR4NoXw8K8+jzxIICmjKDJ2ZjA= X-Received: by 2002:a17:90a:7405:b0:1b8:bb04:b62 with SMTP id a5-20020a17090a740500b001b8bb040b62mr20031621pjg.83.1645423372426; Sun, 20 Feb 2022 22:02:52 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id m14sm17183767pgd.75.2022.02.20.22.02.50 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Feb 2022 22:02:52 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sun, 20 Feb 2022 22:02:39 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Feb 2022 22:02:26 -0800 Message-Id: <20220221060230.6665-3-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220221060230.6665-1-pal@sandflow.com> References: <20220221060230.6665-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: KLuseJmlBnGa 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 Feb 21 06:02:27 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: 34427 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp3105787nkx; Sun, 20 Feb 2022 22:03:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxaKQB1IkG+TRzDZ5FIFj5SDaZP56jOekBdaIBD9zc6DxODzyzii9wET9MLV9aOIUInTOeE X-Received: by 2002:a17:906:facf:b0:6cd:ed0e:ed7 with SMTP id lu15-20020a170906facf00b006cded0e0ed7mr14508049ejb.376.1645423413636; Sun, 20 Feb 2022 22:03:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645423413; cv=none; d=google.com; s=arc-20160816; b=wY2YFtaH3o9Px62H0Y7Ka5m+g9DBLzn/M20yhupXt61SxgDCh5ipOaq2hZl3BNEr9c wDRU+weTRLiPf/DIPvU57KJmO48cqLlLdsXHJ9PiK05YFOR+ue2h5ogBqJ0J3XlU+vei 1ONA3bvKz/qE6gWn/z10YhyOuHE1JGlvJ4kNPGDO0/5JjpuaFHb0vi8Ao3lFxEV0yZGr Puk9wLKJLX0YyEUvwIYsyotq91PCgFlDi9KlhxRPEOierWydoPxIraFJFG2kT3LtvdEO 86D9wCgmeZNu4GCv1muyPz98XIYdAkDKi1p1QV7W/u9lK3pEaxxHqDspcwUVlmM6Xkno XPWg== 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=PCfgKKfbKFpt+X3vQGQsuc+ohCbVjZVlNtpjgsiJ5Sg=; b=UnmCB6F8nZeIPTksjnAf7DbSEhDNqly4r6xcMVz+51+m8C82SXxcNbKApLE828NcYQ Ws12Xuw0E6pl9na5oMQlZUyEGVaoynXa3wnIaDjXvt1QsCuL5Ko3mWS0BoJN7dcUBNNJ xrhTW4OGi0K8HImb7EH+pu9YuBxqTyhpeOa2q2aWHvD8fjfM61XT5kbJzNsWRTyppt17 E/FPd+KeoV+N2gj4rZGyOuJnfM0Cp5lGevXS65ArzTL3g1BJfrTJxClJa0AJ4oxehD+R KOYi7qM7pYTW6r8f9q5fazir7DXrpnX6XjmGV3wxpIpyQp5kkRXXTiEu7vG4pppzjCPm 16pA== 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 da15si10408055edb.462.2022.02.20.22.03.33; Sun, 20 Feb 2022 22:03:33 -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 BA7C468AE4E; Mon, 21 Feb 2022 08:03:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C420468B0B8 for ; Mon, 21 Feb 2022 08:02:56 +0200 (EET) Received: by mail-pj1-f44.google.com with SMTP id v4so14195627pjh.2 for ; Sun, 20 Feb 2022 22:02:56 -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=p+jBEihliCU3ULiQwgU1G7R9hr0S5soLD9WYjFytmsw=; b=vvBGnHlq4qH1/Z9qvTotCIE85LSGpVBQbTuPanb51vXKjQZg12UYqSgWbpgoqc3HVx 4oxb2pvgLHshNVTCym3UMfvX1loY6wgPuJBovVTrFl35/RewZ+nS/BSg63lzQayaySAr rMytbr4m1HcQme7y2YWORlbNVIxu77EZr4P9CwYQqcNgPt4XerC+Eoxfh3dcx+bc8svu SjfRpPMpBJGh5NUQYbIUSToYjRFjvzKrWTZCcfmNLt0NYJ17vhxX1L9AfEzY2LhzIMre QY59EAZc1Qq808/mZERWBv4UFfChAYFQYazsWOjOJBulKpIdeQo2RWIhZ/fWtyRI5pQH 9a1w== X-Gm-Message-State: AOAM531H4+bGPSyu8n/tOnHPdH8OIRLYElDzQbamAvkMNv0AUVB/3rEa 1hiqKf+Q0wDYwtxm56vkEfhbuuVLV20= X-Received: by 2002:a17:903:292:b0:14e:e31c:b8c2 with SMTP id j18-20020a170903029200b0014ee31cb8c2mr17614692plr.153.1645423374831; Sun, 20 Feb 2022 22:02:54 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id ip8sm6151126pjb.6.2022.02.20.22.02.53 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Feb 2022 22:02:54 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sun, 20 Feb 2022 22:02:41 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Feb 2022 22:02:27 -0800 Message-Id: <20220221060230.6665-4-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220221060230.6665-1-pal@sandflow.com> References: <20220221060230.6665-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/7] avutil/mathematics: add av_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: r2Q5FM+9OCas From: Pierre-Anthony Lemieux Refactors a function used by avformat/concat and avformat/imf. --- libavutil/mathematics.c | 10 ++++++++++ libavutil/mathematics.h | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c index f4e541fa24..2c7f57b950 100644 --- a/libavutil/mathematics.c +++ b/libavutil/mathematics.c @@ -212,3 +212,13 @@ int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t i return av_sat_add64(av_rescale_q(old + 1, inc_tb, ts_tb), ts - old_ts); } } + +void av_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); +} diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h index 64d4137a60..eb8a3f4002 100644 --- a/libavutil/mathematics.h +++ b/libavutil/mathematics.h @@ -161,6 +161,27 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const; int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd) av_const; +/** + * 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 av_rescale_interval(AVRational tb_in, AVRational tb_out, + int64_t *min_ts, int64_t *ts, int64_t *max_ts); + + /** * Compare two timestamps each in its own time base. * From patchwork Mon Feb 21 06:02:28 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: 34428 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp3105863nkx; Sun, 20 Feb 2022 22:03:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwuRjizZyxWfO9JXjZYINCz6ZS4NRRB5Rm9GiF59bVTpkKGz2Q0EHmv/BcjA6NSoUKOrOeE X-Received: by 2002:a17:907:76ac:b0:6ce:72b5:7b7c with SMTP id jw12-20020a17090776ac00b006ce72b57b7cmr14320727ejc.735.1645423423883; Sun, 20 Feb 2022 22:03:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645423423; cv=none; d=google.com; s=arc-20160816; b=WI+CUfU0ReX8zGe6H4VwMRL7LbQuva+4lk/Sz/E2XyNW7nWah/oUcdUddD/jVQx7vH bAPubQk0wHloOga9uViRDNkY3AUF/lDQsFh5n50lsegXtyIUbFrw5C6gihYcTq918lea TWXsTfXVPrCNN450pKcB0nQKlIwACg3OB3LYLOVkgRS9ksNX8yQ+Q0sM+oaariXnZsWR pK9Mibiq4xbwOJcqEtrUsnh1W/SCP0xplozZJ4ZbOqpH4+M/0XRiEedsW8uxADKMVMGb u8hjjcnh85WyO8imFXYNDcIw2CgVnOb816pJHK8ChF/aW/td3SQ0KrAIaMCOw8yKaALH SnTg== 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=CIeq2m6w7bO0cTI3EA0V3Rxhiml9At7KnYmqcE4fwDI=; b=KDCUapvSU7PGSVxuJqN0yyXcHBKemD5JhKcvt3TBY5BTpvJhc50cJsU55dXWsMoufW kGaV2a5XYb6lE9OEFD6Eq0wWTIWINzXXDVrVm74BYb2gB8LWIEicWSxzCMo+t82iy+jb 7RMJfXQRZzJI3lXab8CqO6sU2KwF07HsWpIMEXH9CeBV10OqK1c9Hx1jAeakmC85K8xa ZzuGcwYv5jfGM/bINoqK8mPdGwgToOCflgRlKjA4+6oOx6FDUbRahExV4WpiOJiHY8Bp TxWo/Pq8wAob3QsItumGPPf0DgWhumJmBhpikIPsHWeXhSstwBpmiyeM+Td3RnNIM/u3 KiWw== 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 u10si10298398edy.107.2022.02.20.22.03.43; Sun, 20 Feb 2022 22:03:43 -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 BF75368B121; Mon, 21 Feb 2022 08:03:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1454968B124 for ; Mon, 21 Feb 2022 08:02:59 +0200 (EET) Received: by mail-pj1-f42.google.com with SMTP id cp23-20020a17090afb9700b001bbfe0fbe94so4546736pjb.3 for ; Sun, 20 Feb 2022 22:02:58 -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=jE8X3uh7Crf7ivRonNUOoyPjSiUOCVQODh1AGwYsir8=; b=Ka31BJF8l/RSXn4elLcXtIS33L+HSJLIKNouI3qf/FIimOkrXYYxG2q3th7zoRjHVG fyaNv7QI4eTMVGnopXWxDdj4SyiWdoDMmgUGt4qrxY26ItG0zzT+w/BRNVJTxtXko/vg 3p2xdrrqzBlmAZa2x7nXK7+V4c1a/y7y/fU3/02Iwyotf/1wOjx7DWHpbpcu86W1L9Zp bPTjZmFP2/TtnpSQ0pB7AE+yGbm0AvHn8HQ71z38I5mcKcStcv48YqQS+P1TgNOAlQkf sitP8/TiKl0V6pgsGKTjiUAubNNula+zaV24KyYlzgs//Ytpl4naM3oJ/U1O5fO7m00z 2xfQ== X-Gm-Message-State: AOAM533ypFM2oZGJIZiGIVGsFC363DFRGEgXtJw/B/kj8XmwnXZcoog+ BuIkGZSi1kiswwC7bLk5sc5RM/sq0ko= X-Received: by 2002:a17:90a:5b06:b0:1b8:b705:470b with SMTP id o6-20020a17090a5b0600b001b8b705470bmr19615061pji.168.1645423377226; Sun, 20 Feb 2022 22:02:57 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id e20sm9610220pfv.42.2022.02.20.22.02.55 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Feb 2022 22:02:56 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sun, 20 Feb 2022 22:02:44 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Feb 2022 22:02:28 -0800 Message-Id: <20220221060230.6665-5-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220221060230.6665-1-pal@sandflow.com> References: <20220221060230.6665-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 5/7] avutil/tests: add test for avutil/mathematics 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: FOVRXTuTnMNg From: Pierre-Anthony Lemieux --- libavutil/Makefile | 1 + libavutil/tests/.gitignore | 1 + libavutil/tests/mathematics.c | 57 +++++++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 5 +++ 4 files changed, 64 insertions(+) create mode 100644 libavutil/tests/mathematics.c diff --git a/libavutil/Makefile b/libavutil/Makefile index d17876df1a..d1c002e43f 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -239,6 +239,7 @@ TESTPROGS = adler32 \ lfg \ lls \ log \ + mathematics \ md5 \ murmur3 \ opt \ diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore index 9d90827954..aba94af388 100644 --- a/libavutil/tests/.gitignore +++ b/libavutil/tests/.gitignore @@ -30,6 +30,7 @@ /lls /log /lzo +/mathematics /md5 /murmur3 /opt diff --git a/libavutil/tests/mathematics.c b/libavutil/tests/mathematics.c new file mode 100644 index 0000000000..45a82617aa --- /dev/null +++ b/libavutil/tests/mathematics.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 "libavutil/mathematics.h" + +int main(void) +{ + int64_t ts_min; + int64_t ts; + int64_t ts_max; + + ts_min = 10; + ts = 20; + ts_max = 30; + + av_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; + + av_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; + + av_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/libavutil.mak b/tests/fate/libavutil.mak index 1ec9ed00ad..92b9b82aa8 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -166,6 +166,11 @@ FATE_LIBAVUTIL += fate-opt fate-opt: libavutil/tests/opt$(EXESUF) fate-opt: CMD = run libavutil/tests/opt$(EXESUF) +FATE_LIBAVUTIL += fate-mathematics +fate-mathematics: libavutil/tests/mathematics$(EXESUF) +fate-mathematics: CMD = run libavutil/tests/mathematics$(EXESUF) +fate-mathematics: CMP = null + FATE_LIBAVUTIL += $(FATE_LIBAVUTIL-yes) FATE-$(CONFIG_AVUTIL) += $(FATE_LIBAVUTIL) fate-libavutil: $(FATE_LIBAVUTIL) From patchwork Mon Feb 21 06:02:29 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: 34429 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp3105963nkx; Sun, 20 Feb 2022 22:03:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxp02L/BG5VN1q/hmyGxsunprbI+3bhloSB2/JcCXueDJlnzGZnc6HV9JYlob7M+LAYWX+I X-Received: by 2002:a17:906:3e84:b0:6cf:cd36:6316 with SMTP id a4-20020a1709063e8400b006cfcd366316mr14471555ejj.581.1645423434540; Sun, 20 Feb 2022 22:03:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645423434; cv=none; d=google.com; s=arc-20160816; b=YKpVNNsrmDI+nsei/WG0++M5wpRc0OFwSG9uxSz82yzL8flJE/Glu3IPx8CcRLh/V6 VSYjrw8aRjqknwvpkdKJrEwaQhyz1uS4ew7GUnTLPWcSR3zjVx6f96bJ4KoB0DmwaT1q 16lG2AMX7Yxjm+HnuCvaNU23rottD5BbZkyxgFW1B8mZcHvBLJm3z3oAY0m6AE01wkkA hScB2pyI5JKxCchRhe4zWgAWJsJTGI/Dc/L/khxTHhWg1Xes9yBFkH7TWzS4mC7B0DPs Z0LcUXXzS2/b20G8h2RouRUtAY1HhUC4qK25/Lt7KztdfNtaX1zv8K83p70wzWA1z2sO cekw== 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=mU4Dbrd1DBxLELwz3kn8Vs/FcN1Zyi57QhXkYaro3Yo=; b=K75hSXab5HLE3c6+Vhy2kzO1oZ1g7viCgcclsi0uHW75jG+RqsghrJ4V8MnCTnBjAI lghL6RGzQIYzVaP6LyafpeJFgSHrAfVtCIpAKCssn4v/bCX1KTkuEtUNk4xNzEILnUKL Wt5sHsHyku4q7V+/KgpJiQs4L1hSub9x7YchjCDreZ7zuN1ew2WIJLSL9Nl/5NQF5HaJ kBLVK/vCmwmCKJyEp/Cmtk4mRmPDa/zSaCqJ89Ww5m9ZHSf2k00DK6w47r5ni2cRXfnR z92zPojM+0NQtOB9gMPHGaBgfXZOWTKIHbek+1DPdL1lTaUia/cocT7/Hmk1fi7MwOn7 iGfg== 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 n8si12992501edx.400.2022.02.20.22.03.54; Sun, 20 Feb 2022 22:03:54 -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 C143A68A81B; Mon, 21 Feb 2022 08:03:08 +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 8E30168B13D for ; Mon, 21 Feb 2022 08:03:01 +0200 (EET) Received: by mail-pj1-f50.google.com with SMTP id m22so333017pja.0 for ; Sun, 20 Feb 2022 22:03:01 -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=9pvOn/n5aSCyCuMStVk9ge0QR6f3t/3nkGNqje/Yl24=; b=IHHh1ut73gvqii9Ax89xsQGLpmymfI1ft7WKNeokxh+GIz6tR5VtiyOg/mbFZqlnsn +iDoTvJvBGuGj+hUx4FogJQjgRT2U/1YPRjS05dO7nzS636rrVnVpFjw8dLsWdgBziim aJZEuuY/Qi+D96oqAeZNO2m+IhITJenIJbmkWkYbrPnfRo3l3yfAY1KcdCmjxalDyGL7 uef+aNT/dDJnvgO3+BYCWgiiLdVjIzcP9EeoB2NxJsJCVtawnHvwjTBD7y7wt5ytbpQI PK9pmmt/+I0oq8iGVCRdniweypJ0hQ1wDVHy+SWBZdAG17fqpwWRjPmd7p/Ma7HKem6c t9tg== X-Gm-Message-State: AOAM532UqVJiwxvlqEEEvkKzSwM1hoPueQnMdz472LBfsyUG7JN+bGwb 3tQLnDUVb0YFVlMOsFXqb1N2dskmK3c= X-Received: by 2002:a17:902:7c94:b0:14d:77d2:a72e with SMTP id y20-20020a1709027c9400b0014d77d2a72emr18348095pll.153.1645423379682; Sun, 20 Feb 2022 22:02:59 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id k21sm6050786pff.25.2022.02.20.22.02.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Feb 2022 22:02:59 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sun, 20 Feb 2022 22:02:46 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Feb 2022 22:02:29 -0800 Message-Id: <20220221060230.6665-6-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220221060230.6665-1-pal@sandflow.com> References: <20220221060230.6665-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 6/7] avformat/imf: refactor to use av_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: S+/RWJSb20F3 From: Pierre-Anthony Lemieux --- libavformat/imfdec.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index ac212b05e1..bc27e3cc2a 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -69,6 +69,7 @@ #include "libavutil/avstring.h" #include "libavutil/bprint.h" #include "libavutil/intreadwrite.h" +#include "libavutil/mathematics.h" #include "libavutil/opt.h" #include "mxf.h" #include "url.h" @@ -904,14 +905,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 +930,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); + av_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); + av_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 Feb 21 06:02:30 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: 34430 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp3106046nkx; Sun, 20 Feb 2022 22:04:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfQhjyiAGPtC74XEfOR3cnuNXXlgM2+YdeEXJspz+xIxPS7kP22G96+2mWZww/6UrMIIZm X-Received: by 2002:a50:e08c:0:b0:407:cdc6:809e with SMTP id f12-20020a50e08c000000b00407cdc6809emr19510028edl.162.1645423444057; Sun, 20 Feb 2022 22:04:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645423444; cv=none; d=google.com; s=arc-20160816; b=JatZQLrdKh/ANQtqIEyzU7eEPAA+KaQ1gKPvZrKYF9QhGWYEo8xbqqvbGHRbZohogb ZF/4fTTiMql1oCDHxDY7U89lNTAk5nRGAh8NTgimURTDDb7AArhPkaeqmOpyr0Q8dpoP rJ2nMYrvChYTfvQCBQpCU+8b0NCEhYgZhm/KKd5CeHb3P7lk+ZxbnWz79nJ6tCydwUxU +3nr8eYNhmV+7J7eJWFwjh2k9W3v90j6LBpXAITVhVCks8ifsYYbY62QiQyVkwreTy5y MvX2cuiINRciR78tSs2iQgA66PZbmwbaH5AQWGfn8uzfGP1oiQVJun7sdY8cImoLpEBW kNEg== 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=A7BlkH/uFogLoqlhKySf+kPRbPscLODBelC3cd6lWM4=; b=kZsFryB2nWL8BpBaxmisGgTOEvMnlKceyyxTw/Fp/a5/Zm7tja7GQaRAvFIs9ot8rI SpS4GSaNPR5fXTkpZd8wiMd/9/rrTEcLTs+GncAwR4SsJLi7eGHG3aFfsL/VwrwraPfs UydbDW8Ig7gyJbxDy2qGMcGlyFBKiRl50s+lxW8a2yoWueWzle4M3kPzuV1m9rx8yt9b J5YlqFgRF6BsKKepGnspwGeONpNSEBvV7o+9zX3aPszY+Rz6lgwtz6FuYo34RQ9T23Cu grMfualtRrBcRwRxjajzYmA9+cViNJOb9kPQjQW0K8QU7mvCFsQNCY/UE9YWeVmrz3iu KL6g== 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 o3si10411630edi.560.2022.02.20.22.04.03; Sun, 20 Feb 2022 22:04:04 -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 B3D9768B161; Mon, 21 Feb 2022 08:03:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E98DA68B148 for ; Mon, 21 Feb 2022 08:03:03 +0200 (EET) Received: by mail-pl1-f174.google.com with SMTP id u12so12016306plf.13 for ; Sun, 20 Feb 2022 22:03:03 -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=jroqvSxaCglERAn03KjWSCqKytpoF/lZZOCVm82M1L8=; b=0MGoIMRY36T3EWlzGPpwAzGcOIgpdkX0xDtjz2mtxGC1N5IFPGU0Z07QdWzJZetWRy wtVRgNxd9/AWoz0bTSSWkEYpVIjZ8/ZfkeYI1pYelfLF6zAKylTXoyXseEVh1Ax7oQcs 977UVTc2+hOxw9tLhesIOt5BkTiqwbnCM6yxWt0MBnQ7crtQ3E+H2A8oNgvzMPjUeFqv NTDvt9VF4btCqVauWptL0FxH63PDQJ9I6my+yijJSTbhnN/x8H0qV+OJ80jrLSU9YwEj zfzSggw/gQ+SxEwS/N2h1dcsWdhXVFwIl+wTvgPONYjKAZwkY6sK08hvWBPxM7zNGVHs fX3A== X-Gm-Message-State: AOAM5316vLs5OOxS09LUmAqHfvYKRsYAR/OZme5XZwwLnAy0+9yrBvXp Sqt2HROfqcnglDLiy/S018ebE/8kLjA= X-Received: by 2002:a17:902:9a0a:b0:14a:199:bc5c with SMTP id v10-20020a1709029a0a00b0014a0199bc5cmr17268578plp.10.1645423382049; Sun, 20 Feb 2022 22:03:02 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id e20sm9610626pfv.42.2022.02.20.22.03.00 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Feb 2022 22:03:01 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sun, 20 Feb 2022 22:02:48 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Feb 2022 22:02:30 -0800 Message-Id: <20220221060230.6665-7-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220221060230.6665-1-pal@sandflow.com> References: <20220221060230.6665-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 7/7] avformat/concat: refactor to use av_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: t3R9kYpkJafi From: Pierre-Anthony Lemieux --- libavformat/concatdec.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index 0603c6e254..3ddbe833c9 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -22,6 +22,7 @@ #include "libavutil/avassert.h" #include "libavutil/bprint.h" #include "libavutil/intreadwrite.h" +#include "libavutil/mathematics.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "libavutil/timestamp.h" @@ -816,16 +817,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 +829,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); + av_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 +844,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); + av_rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q, + &min_ts, &ts, &max_ts); } left = 0;