From patchwork Fri Mar 11 17:16:47 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: 34705 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp1886914nkb; Fri, 11 Mar 2022 09:17:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCSuqh5PshrarLUSx3hW9FGHabX8qRLVOgjGM3UAyz2rYrYmti1wIWwrJdtZEflLY8MUzb X-Received: by 2002:a17:906:7751:b0:6ce:e3c:81a6 with SMTP id o17-20020a170906775100b006ce0e3c81a6mr9071504ejn.278.1647019038210; Fri, 11 Mar 2022 09:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647019038; cv=none; d=google.com; s=arc-20160816; b=pqHi8vRlR2QcqfZzlLd6OtS2pRB7FwO2Ut0ypVvC3YYr6V3bq+CsbBNgbk/7llin7A BFdnm90bY+zzY20l+UAeexbne+mk5CafSPbwVMbwXDq+S1x3WowuqKaFRc1HeiKluBhY v/BCZr0nRxDLdUQn02Khf4iuA9IEsBIBI5DFaqHCf3n4/1Gqbvx2sMiFjqi3rD8r5/HW edVoYSZ/7gPgr3AIGKiglvYR+G5PnYx2nJ55QWe7yqSYOQAIv3GXkLvUnLxqbg0gmKx9 Ld8KmqI2xgXKVfVJgExbeISNhbJY+pSBIJJ6VhfwHh6qHOpPcSCwL0koK/ZF+5qKn0nm Ygag== 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=VlcySNXHm0hf+Vpm5lH72yw7tFb3BjkWk1+9E3hAtoHXx7Ev+gZ7yuxLR3CAJcCHoP OjWEUYcaExCqEyg222j7LOSHnD50e7pnLjEpC31YljTO8cRAv9nz6XrOaMFy48AJe+Ut LroPd/Me8QnsSOEKfVd5imzWABowBuEOu9za6H1uyZt3OP8s41qDC5ugF2A9ny99/b8m a7yPBWbjIq/hk589i8XB1fiO9vbxEBDG63QmcdMMbjkCFWT3ZvrZ6WeeCrXFceMYD5m9 vWyWdf5+a+BUxY9vR9wRGOPsWvbEgUs0a3p1Dd2iuRvtb0EOBkY2tVq7DPPBDXpBI5Ak 73lA== 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 b7-20020a056402278700b004167d797a16si5626292ede.146.2022.03.11.09.17.16; Fri, 11 Mar 2022 09:17:18 -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 CF50768B0E7; Fri, 11 Mar 2022 19:17:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6522668A318 for ; Fri, 11 Mar 2022 19:17:05 +0200 (EET) Received: by mail-pj1-f47.google.com with SMTP id mv5-20020a17090b198500b001bf2a039831so11603426pjb.5 for ; Fri, 11 Mar 2022 09:17:05 -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=Tm1A0qFraVgyOd7deCAR0ivo8AxsCgbc/q5fTfalPyAumWTUmsNfpaXzWUNzjQixca sGmHPdGT9F8NkzsyDLNw8l+4U9PBHZmiRqxV1MqDU/hBkOXhIeMdjLm16FYDLx2lOb8G ztjGR4YYjh46vQ5J6+sF0OOObqYThaxK7nBP9uFLFS8Jg7VYK4J972fZGoF0Cw4ed790 pfLEV3yioXGlpt6BQ3sUA86PyCmaVKq9Yf9zNB7nT68nd4lYVao7RS0TsrSrfYzgP0WD r3JQ6wi6dQ7l9EtSAa97MTUhHvmng2Pb4sdKNLBfgj2P8Afic7km1p0hFMz2rFPVWsk5 SgOg== X-Gm-Message-State: AOAM532JnwpdJq1UWDDqL2aravaguGbRmwdPQRwYEf3UqKlE5Zr0Foaq 7juoQ4KsxbJBBchi1DDyjrJi7FmrMbM= X-Received: by 2002:a17:90b:250f:b0:1b8:f257:c39 with SMTP id ns15-20020a17090b250f00b001b8f2570c39mr11751889pjb.135.1647019022944; Fri, 11 Mar 2022 09:17: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 i11-20020a63bf4b000000b00380d3454c38sm6179862pgo.13.2022.03.11.09.17.00 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Mar 2022 09:17:02 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Fri, 11 Mar 2022 09:16:58 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Mar 2022 09:16:47 -0800 Message-Id: <20220311171653.17420-1-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: 9Tdl1xR0UewA 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 Fri Mar 11 17:16:48 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: 34706 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp1887097nkb; Fri, 11 Mar 2022 09:17:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQgYctDj7A3YjtjhZ8cGuDDlKtI01l3LWtaZpcU+KQb8tz5BcBuGQS/O12vY2YN7cSMcAg X-Received: by 2002:a17:907:7704:b0:6cf:48ac:b4a8 with SMTP id kw4-20020a170907770400b006cf48acb4a8mr9038084ejc.305.1647019050611; Fri, 11 Mar 2022 09:17:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647019050; cv=none; d=google.com; s=arc-20160816; b=jHvbunBC7to9nbO2xBztoaV8jzGZhko1B/XJgVF+/s+Fz6Onvj1waXjTeJGh9DxONG x2V8PxrIveZVJeQ6+/Vtq1xFGjFGLPM1zJOp10jH7jAJtmSJ3zS3xVV7pTcH5HbGHkf6 9sP4iufPhJtO0Uvwsx2Zp+2CrVpYgfakgAq8unc0Ff/AY830fg43DwqLcLpcwZw1hFDn 3pvTWYetYpcJlQN8iBLGw4v1hQRpnSeUK83kdTnJ50z3Um6mjZ6ZijrU/DGQORzhD03n f132J7V5KX+B0sTkCpDPA5Dr4Dr/T7z6vwRciwhgTp4CDKctotcy2uhjGoaAB1nrnI5k p4/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=bXHQy9vIq/HqVtEpjblDk6YpwIF6biMFinWMgnqEAwA=; b=eHiguOCpWGcGQ2bFeORzxdie4gNqhpRWVVlVJGz8DSWnzS9MqKPL9roApK+gK36TdO mgNsp7+X1L9rsdnp5nly+aRctemc2iB75gWLV4ue5PiyaQUDK/vQgzRwgW1mLzUOaVAt 4zgaTtaSv4e2/16Cy/eKit/JM6ZYe2cQNlDfX10AcmK9UfISAyJXKmopu/necoqHOf7B nFnLcI2MC4NaBpW88Wrfy/KvvjvriIBLA085NW3QEou56s2zwr0FmBPhPcALcraGB1Ai gI6atMpelEkkZU0H2kBwXQBfzgwFRxzx4T1iuih6lpUrvQlAV98SLRC8dyOByow7MmOr Pl3g== 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 g22-20020a170906521600b006b1c4eaf5a0si5132787ejm.756.2022.03.11.09.17.30; Fri, 11 Mar 2022 09:17:30 -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 32A9C68B167; Fri, 11 Mar 2022 19:17:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B713F68B159 for ; Fri, 11 Mar 2022 19:17:19 +0200 (EET) Received: by mail-pg1-f170.google.com with SMTP id o8so7958934pgf.9 for ; Fri, 11 Mar 2022 09:17:19 -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=YeUdpaC6wiAs6nckkkfwE27o+1st3ib+VcX3mkSxJOy2SdnRbzWI9VT/KVHRTvQwY+ U4CULiaW7GoERY7Wd8vBUe2FNEYTY3dYq5AiRnSvwukAVqJ8k+5t839xThp5SigKqm7V YhjXk/H9V0I8ciTk4lpjQ3FfAYDnFk1jZEJ27ovlHp4okX+7QpN+d7EW+n0pcu7WWrSv fHfVESEZSL3qoehbwTGgx9ct5jF1NGRzpB3038WitQVtnngvgDQoHG1CjvKuBd+N/nNv ZiYJxNfGCZ5iClMc/y8oo41YgeWm30t1eStdnFMwQ3GMR8JzlEC7Av3lO6qI0qoXxsMZ a7Rw== X-Gm-Message-State: AOAM533uCZ9d2dEUyqgIOLI5+ne0Zzg84M3utUBocDLPLhBeb1qnstEu FDTs6yfQhDq2+BfxJVxoHfWsLnO7/pI= X-Received: by 2002:a05:6a00:1354:b0:4c9:1e96:d15c with SMTP id k20-20020a056a00135400b004c91e96d15cmr11013994pfu.30.1647019036333; Fri, 11 Mar 2022 09:17: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 i192-20020a636dc9000000b0037c7149fb0asm9334802pgc.89.2022.03.11.09.17.14 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Mar 2022 09:17:16 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Fri, 11 Mar 2022 09:17:12 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Mar 2022 09:16:48 -0800 Message-Id: <20220311171653.17420-2-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220311171653.17420-1-pal@sandflow.com> References: <20220311171653.17420-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: fB3oO6pG/M3z 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 Fri Mar 11 17:16:49 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: 34707 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp1887251nkb; Fri, 11 Mar 2022 09:17:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtEeP03LK8A3vlWz4i2op65mVbmY4Xvsqvx5mFi+jFBQ8ZZ9KkytG8ILAFOw0p7UyvhiQh X-Received: by 2002:a17:907:c1d:b0:6db:67b:a3cc with SMTP id ga29-20020a1709070c1d00b006db067ba3ccmr9180466ejc.356.1647019061800; Fri, 11 Mar 2022 09:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647019061; cv=none; d=google.com; s=arc-20160816; b=YB2l4Y5w816P1/7GRozUkdPz722MWUqQX/IuqPFZ0V05+ZfO6OtiCnZHwLwlILCVfZ lQ0PPMymuypC//8R3hX7D3ykmn3vlLAuM/qg7htP7Nq7Is8PmkqdndNVVvI4anU3pWnD 9HMXYaPsWqB/IKcLfJcD+v+4kXlJmcYaR5GFQ5H794mP6/UzyQQgT+pQpGMtFP/R3eaY CdDWTS8ZhTVJ35AUrUFo2Vlm8EgpHtqkqOT0uqKgLw86U0n1bBhU2dtaGnNTTv9woU+s Zhh2h/2xNqcO5GzQXor8Oahq5uX0/QrduFd0QK9G1gAcDPuEaz7AG0DnztaKvk1gti0X uKQQ== 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=uHCcL72bfx7BT7wts5VgT4bb4lv11iBwhgZDlNJswC3gaUf81nEvtfP98OuFRU9Dnx x8vXOdTHKjqkYjzsJ+mQcyM0qse79QSW/69J2XLaE1qIFMTqLZPNXh0AJDvYjpBy8Ng5 pt0Cvu1BtfJ6jjfvH14xM99k8IrRJl/OLjcZeHJMHmJRM0gnyNaEn9R4wppdQePn644L 2w9Ml11UhqqJO6LoRsv9swvnGyXkCMpxYMfOkaWt9iwiOmAqjybHVGKTUaUn1EFcXDhH 9x7uIXeiw6niTnCNDJ6TVrMTaeluBOSb5ALutIysRSRhCTSzqv2iLMsZV5mX81VMYA9q BmKA== 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 u24-20020a170906655800b006cf042ec574si4969299ejn.557.2022.03.11.09.17.41; Fri, 11 Mar 2022 09:17: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 5EC9068B1A1; Fri, 11 Mar 2022 19:17:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8386C68B1A1 for ; Fri, 11 Mar 2022 19:17:27 +0200 (EET) Received: by mail-pj1-f54.google.com with SMTP id b8so8708635pjb.4 for ; Fri, 11 Mar 2022 09:17:27 -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=Ots6+84cWee9m9/Wi7LGFuVn6EL2bKsCbNKVxhuSWaQzHK14u4ZP6+9hDns7MnQErF RzRWmV0NjjH+D8I8nGU2axiM3ZMlfGIzNfWtel8qEdkcg32dcYgYLzT5MPnAUMB0r/AM eOxP73FySIEQ5+PEjI3aGJzOD+U6tfXr5QxAOuEbI9mLycJ39xPrwCyb5BPshnrCrKPI ET4CxdOJ+2MsvCLrrhKc8KLMXaseIdcrgZAfH4wWcIOREzepyUwmn45MXmWkNfOLto82 iWY7GhvgIGNQBLYs26XgxuEuHErJH3q1BR5JA5MZSpeq2KdSo8erJ13IQLvFk7rDsrcH luTA== X-Gm-Message-State: AOAM530QslcrqEwd6luTepb5cX47xyrhq+pqkNERgybw/wmEmMT79cvj AGgtlg/KZZSvdzJibY6i/Iq61YocFus= X-Received: by 2002:a17:90b:4f4e:b0:1bf:b4e5:f4c0 with SMTP id pj14-20020a17090b4f4e00b001bfb4e5f4c0mr11716367pjb.129.1647019045449; Fri, 11 Mar 2022 09:17:25 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id z12-20020aa7888c000000b004f3fc6d95casm11278732pfe.20.2022.03.11.09.17.23 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Mar 2022 09:17:25 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Fri, 11 Mar 2022 09:17:21 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Mar 2022 09:16:49 -0800 Message-Id: <20220311171653.17420-3-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220311171653.17420-1-pal@sandflow.com> References: <20220311171653.17420-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: ZqNn7Xmsx63M 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 Fri Mar 11 17:16:50 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: 34708 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp1887391nkb; Fri, 11 Mar 2022 09:17:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxidBWmIDGR/6rYnu6ecNbd4wTJGAnXV0zr/eTw6/X1DGEh6XM3aYWFIAk3suYxOCmmFo+u X-Received: by 2002:aa7:cb09:0:b0:413:2be4:c9fa with SMTP id s9-20020aa7cb09000000b004132be4c9famr9828353edt.106.1647019072237; Fri, 11 Mar 2022 09:17:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647019072; cv=none; d=google.com; s=arc-20160816; b=LlWPsKTHfTGdpoSCrAJA3T2wYb/urULyRsFUbWbHwNP2mRY6yuAOg7hzAXFVWYnbV+ 4b9wfpDGMdLaZRGWTAHYvTJ7m4UYOAyTYVsN9thDW+kteLTpjVUsYWtTOXxumbZ2IUwV 6CrsjtabUV5GKtImAdj8jaK0ho9kJ6ukEfB/Zw0QpyqhlbO+r+VEtAvfKXCLcHZjOpl+ OQzT9HYEaYs35AUO95ojriAsdvbTdpwBAqHc3BQ1SzCkmy0/FeB3fEAuFa6NhsL1Lg9S 0CLQcAxSXDfAnfAYHbZJ70e5JPIA0VWlq134wInDurb/66/sw1P5v/Mh5YYVlxDtFO2q /a8w== 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=fgwoQcMuJXRW1xDaDoC403xdzJ/9zoi8mBVTsT36ozY=; b=lTnjpXOGYAJrYtVYKeTWvBO3EEhoj1OrvbQWI7u3rvDrl8lSeJTwTLDhdWnBPY7B4g QG9Pr7mYdy0iZiDEqQdXay3Ztx9V2N6raASzQc9pFhJMTj7hPRJ3LXK3vM3b/pbt6uIR uFLnA4R5WHwP6LqotTa38nwsXK6EvOnZVmF6Xqy3ERNklGrrR1c3cO2opZHlxykBLrLP a5zrEkcukYN8fdXlnuRHTkCDtSLxC34LBYG4hT4HVwirkcqtI2fmzVX5SjNlNVIPlnIa n226rMDXG5Pullv3r0VIe2Bwgw3g7EJ/gtQ5b28IVQxvbFqZP9hGwq/nLYCKTXUITajt pfjA== 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 13-20020a170906058d00b006d13ca5ed5csi5396639ejn.997.2022.03.11.09.17.51; Fri, 11 Mar 2022 09:17:52 -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 6894468B1C8; Fri, 11 Mar 2022 19:17:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5894668B1A5 for ; Fri, 11 Mar 2022 19:17:30 +0200 (EET) Received: by mail-pg1-f180.google.com with SMTP id 27so7948897pgk.10 for ; Fri, 11 Mar 2022 09:17:30 -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=gUcOGhzP9/CeuWzjsmQw5nFvwyBteALnaThn0x+j89o=; b=0sssZqQVJMjKyi+f1jUpqCqDCDlVIyDSClrkfFhj3BLysYP5BujqBtzHcZKsDelfvk xKTUzsLqMd29wkxBfx5CxgiAtKyZ95TaBCjKSH7NBeeBw7Y85BoAW3veKSZqK/23az+z Kd8/bkQ9AvCkDoLmeqpqNh/leoWBcdy9uN8HZCNwwlw1GIqu1XV77fX8kNk9l36j3oNR QrPcQy3yFP3/IGrPZo+qmFLkQSSTVRlaoJHgfr/e4ljb7StQMBb6lidGbUD56ODfGfJP rBdegQfALN5HsLpaSAR32a03hrsUmWlXOK9enLfQzCr+CFK5VP5fWWvgg13L/HdVP16Z 2Oow== X-Gm-Message-State: AOAM532ydi4tADcalzlbqj2UQwdI6PlQTvMmll/6HR1aHct1o84uOm54 Pzs4mjfAKWleIkEJpItsPhFo63+X6Lo= X-Received: by 2002:a65:63d9:0:b0:374:6b38:c6b3 with SMTP id n25-20020a6563d9000000b003746b38c6b3mr9336215pgv.195.1647019048004; Fri, 11 Mar 2022 09:17:28 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id s1-20020a056a00178100b004f731a1a952sm11978524pfg.168.2022.03.11.09.17.26 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Mar 2022 09:17:27 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Fri, 11 Mar 2022 09:17:23 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Mar 2022 09:16:50 -0800 Message-Id: <20220311171653.17420-4-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220311171653.17420-1-pal@sandflow.com> References: <20220311171653.17420-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: aCzL1NxHwg/d From: Pierre-Anthony Lemieux Refactors a function used by avformat/concat and avformat/imf. --- libavformat/internal.h | 20 ++++++++++++++++++++ libavformat/seek.c | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/libavformat/internal.h b/libavformat/internal.h index f24c68703f..5529403a68 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -1023,4 +1023,24 @@ void avpriv_register_devices(const AVOutputFormat * const o[], const AVInputForm */ int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size); +/** + * 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_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 Fri Mar 11 17:16:51 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: 34709 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp1887512nkb; Fri, 11 Mar 2022 09:18:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxA0qmDw7gBYqf7pgp0HbvSZawZQVJGzdYgWDQULUPLUI31GksPriAq7uDhfHJ0E4ERlEMK X-Received: by 2002:a17:907:2d24:b0:6db:aec7:fbad with SMTP id gs36-20020a1709072d2400b006dbaec7fbadmr2547304ejc.663.1647019082274; Fri, 11 Mar 2022 09:18:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647019082; cv=none; d=google.com; s=arc-20160816; b=qYW884VTRGYjJ6INlmaKxjWZtxn4VmmMPhiT35+hwU1wxkoa0O+oiMiXGnVVO3vE7a KWBLcmticf8eleeqkOiDJkoj4kbYv4NQl45gn6y8CZguEK9AXPljcXMUOKjrmuSS28e7 mllYD2CKqBr6gt7AaHy/s31kTvx5XiTd2DWnYaxo4UB3KBqa3spiyS1ln78lXdoxc4PV KraOA6puFJZN16aWje9LFMtPPqoCgbd17rSeEED4qbcvkT46LVvK05gOevnDcsof2jHd oa+XHBj7EE1K+X1zuUmsYtNIUrnN8PSIicaLgTjxiWYQhGBe1k1szFFFQynrJx8Vxhj4 CN5A== 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=cK45xeLfTlIjEHoeKpqv+kB5sCbvPYTVZnkOR7woHeQ=; b=yD1PghRqUJVoCOQEoTVDEHEXfsfaQgE0/9VzMVNKsAsPdI69fWmnumhlPe6QvNb9+b mdVs0hgvIPqiqW/tB2r4kZzbkrQmUw8eR07Xci+dA++6U1mqSuZDOYahcU7JpPVi9BRR WZoh+MbhRy+3ALBGRZAPuQjxGtd5AmK8ZhdpmcjHDRVPE/7nYFHAYYIykGxaICTNEUbn DV7ozwMCNSGCqIttWDWo230mzncTo5UL3aVKG2zOy36jSxT5iSaARG6j1ty5FFABAOWp i80icvssdpYRfAG6bWUBcA0WCw+sDmp/5Id4ArEUWPmgK5FQghaX+YzAI2VQQKuHT4Wq snRw== 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 y9-20020a056402270900b00416a367fdf3si5008117edd.218.2022.03.11.09.18.01; Fri, 11 Mar 2022 09:18:02 -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 6107F68B212; Fri, 11 Mar 2022 19:17:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF6B468B1AD for ; Fri, 11 Mar 2022 19:17:32 +0200 (EET) Received: by mail-pf1-f171.google.com with SMTP id s42so8419582pfg.0 for ; Fri, 11 Mar 2022 09:17:32 -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=LvwfvNlGVHZuhVtg+lmT5bw4ndoYln0ZV2ufauG2Ems=; b=vm7iTSSTlJwRR10OE7Y+E7kYXgC8A4/rKaUNjzxGYBunpmkH/Q2TrapqQnV7EPy/49 /MenFi8sneltxaVnSqJi70g1o/EJa5J6/DT1pfE9Ni5KI3VEqIy7Fu1jYLUyblca9QeH OPMNG0JC+CKsKp60ucS2OMVN5PBqgB4XnklADeksoVMWAwKJjijy5kY5haG/JWMritqM 8D4C4G+r93GANeDmrNdUyushrP8x64io0QR6O8DIRTX7FF+96HBZT/5lVEwv84uw/4Pt Of3kLQlIAl6EHGTYOp1GN+JMIEDJzCYTexU2S/MiTnVJZ2wfDp2+KNyyssPEDZotaY10 us/w== X-Gm-Message-State: AOAM530uU21nmkd4kDjfTtxWOHJZGkC2g7PAxD05BXCxCuKRKGwqzVpi yXcH/WQI6CwBSeTKD1Pl40t3bnOdfEU= X-Received: by 2002:a05:6a00:a2a:b0:4f7:68db:5e60 with SMTP id p42-20020a056a000a2a00b004f768db5e60mr11249941pfh.58.1647019050550; Fri, 11 Mar 2022 09:17:30 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id m8-20020a17090a158800b001bf2cec0377sm14952851pja.3.2022.03.11.09.17.28 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Mar 2022 09:17:30 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Fri, 11 Mar 2022 09:17:26 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Mar 2022 09:16:51 -0800 Message-Id: <20220311171653.17420-5-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220311171653.17420-1-pal@sandflow.com> References: <20220311171653.17420-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: dD7igyE7SzKH 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..cc679dca05 --- /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/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 Fri Mar 11 17:16:52 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: 34711 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp1887854nkb; Fri, 11 Mar 2022 09:18:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZJ7++8Ul4IBm+ZqNxiq40v+FFLcn/9HMbgTfCRMlNlv2i4Vx6WLluCwiS8dbTbAanQmuc X-Received: by 2002:a05:6402:1e8b:b0:3da:58e6:9a09 with SMTP id f11-20020a0564021e8b00b003da58e69a09mr9658278edf.155.1647019103124; Fri, 11 Mar 2022 09:18:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647019103; cv=none; d=google.com; s=arc-20160816; b=IcLNL+JEWgyu7kVmr5H55IV1WScD0YEWoEUk/4s8Z6nExJFwMf6auXQ3rKFQ72g8ts 2feDxyOXmxJTnILWkn4SZ1Pt9ctJd1TYLgCXB1sbp9tJeARbKAJfJ/2igRUL0X0cHFD6 UX6/Wb4D2kl2sOjK7T1NKdt3hogXQ9jny9tCl/0YJyxlOmRjE/XcVO0c3mYxqFR3zPtN jdlrc8rYRO7CCsNmMWnzpq3Rbcsxtuo1bGr9TDSGWVfcUgyNIacUuJ92aw3MIBgpcnbD AEDiihckLoqGkg1wrOKk9AF15E1O4T9Ixmu4WXqCsVoKhgaWvtNmU7LRhdMFRsZB4xlS jpsA== 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=Le101hj89hRPzeslDZQOZhbAPDQrTP9HQVqWnGPhUJz6r//4S6QSrAAphG9XNuyUFh 1SAIcGiWuJu+Z3LGs4OumUr2xCAEAC3SYtpja00qfNGMCo6wrpmmSZEd3bVdesQKfgow Z3EueYmFsIxjG7+Dfm4RRm6Vj9TxDzvYvoUtt9pFgRtsu1TjUclufD6l4Zq9gLO3VKLh 2cSGs0bEJ451Ldh3xb1xfJOtoCZEWpzBVvwTA46NwcFcnZJHA61VsosxKZwKGafk0z/g Tl98MvNM4lNU7nhhg5hbNs/pMCq7HHr8uYCipwZWNx9EgDIo80IZjilFhhHC8meGuggF LBpg== 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 v6-20020a056402348600b004167eee00e7si6089336edc.149.2022.03.11.09.18.22; Fri, 11 Mar 2022 09:18: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 0D8E368B252; Fri, 11 Mar 2022 19:17:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 23E1468B1B5 for ; Fri, 11 Mar 2022 19:17:35 +0200 (EET) Received: by mail-pg1-f176.google.com with SMTP id bc27so7973077pgb.4 for ; Fri, 11 Mar 2022 09:17:35 -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=PD6yaaPaNXe0Ny005qPRbk4aeoRFxFIrbxHW9yUOvmrUAHCz2NpeAGVE2kORVtxtjx Wf3+ruHu5D022B7jQXgjhFq/1y8IbI1YvcdhO0wc/+KG3wYDYXvDvwoa90+cgLB3A8LI 4lXLaaU6Wk3wi8jd9Pl4r0fMj0DAT4sSTgVPbtYMPvImM3GdgiV7ZgCD97/HlPMr6JTu sL2vjmIKTlRAPIJywqbGKjGSanwxduHmVdBwyws5JfNITc2vQmhwDMIos0m+zR6f2QuY VsaqwXsQZTcV0mj2o/hycPgpZgD8LhK0djbbNRJzGlZdl57h8PhDlgYxnVNtHhdKlVVd lFGA== X-Gm-Message-State: AOAM533znlnIA8yu+6Sd172Rf74ZNd5qiBFNlZMton9rH+/amyzswgJo oBoK+T/i+ebNANZXbyr2V3F1wzblDQ4= X-Received: by 2002:a63:3c4:0:b0:380:2287:5f5b with SMTP id 187-20020a6303c4000000b0038022875f5bmr9239181pgd.478.1647019052946; Fri, 11 Mar 2022 09:17:32 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id bh6-20020a056a00308600b004f6aa0367f6sm9618082pfb.118.2022.03.11.09.17.31 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Mar 2022 09:17:32 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Fri, 11 Mar 2022 09:17:29 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Mar 2022 09:16:52 -0800 Message-Id: <20220311171653.17420-6-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220311171653.17420-1-pal@sandflow.com> References: <20220311171653.17420-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: wpy3s9d8s67x 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 Fri Mar 11 17:16:53 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: 34710 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp1887684nkb; Fri, 11 Mar 2022 09:18:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgexvK+sfMDg8y0wf/i3Q7mZPRhI7CdiNIYdT22nghn9m5BuFo1hl2ylnc1R+1iYGwT51y X-Received: by 2002:a17:907:7d8e:b0:6d7:12a2:a962 with SMTP id oz14-20020a1709077d8e00b006d712a2a962mr9552890ejc.565.1647019092684; Fri, 11 Mar 2022 09:18:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647019092; cv=none; d=google.com; s=arc-20160816; b=AYi/Vw82W1DSOtpktsmG0FLu0Gwatb87DuVG/usb0IR4D8Rj8TK46Zifmq6SeJKf65 VGF1Qwtsgjb8qB24UbSvV8xmB1I12ajbmbOehEORdF6QBL9KyED2vNXfyJD5gHfW6si/ EtS1f7WwndhOx9dYRANPJ91H+psbbw8iPQXQT7xmWFz9rAsCAwmqnrZP4gPqZkGwtERI Hks18oa0gk9aMJhqnu2NxjdwlnGlmBMwYtOX5tL4HDO4q84EyB/jOB1FX8qT1wfBjKlO /xuqysVUddL3f7buPFkMFg4oTqbyrw2VkdJE4D/i1epQQEdUVysV8u/aGvAlYBGTw+wX ZpOQ== 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=rjcqwsKKOaiYDdT6/W8+0wlehRMSxX/67p0BSqmO6k4gwLRT21hU6Z1SSVpH1+Nzif vZQzFGcfbfSTyg4riSzVeddYsJQ0u8RL1dOKTVYGjQkO+Hrd8cP7nEoeWi8i6D9MmKeb hN0Gu9ehw9ulojCfTBMI0kxD8FdYkfpj6fNI1X0+uB6yoHNKYoByXhYOIQp2d88z+tYo pRXH40Dd/3ThUV55Mlznc2SeZ7772HPqMNgAbVD33JO+r98eoB2747sV54CBUd0yMozc d3bbOejkdSIEvfn4yMaXandvYfLz0yZt7w7EVHpRxQlCDmiO+gnM5TRl8J1UcZ9Jjfbc 4p0Q== 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 g13-20020a170906538d00b006db0207c412si5350231ejo.9.2022.03.11.09.18.12; Fri, 11 Mar 2022 09:18: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 29C4468B1F5; Fri, 11 Mar 2022 19:17:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D01268B1AD for ; Fri, 11 Mar 2022 19:17:37 +0200 (EET) Received: by mail-pl1-f173.google.com with SMTP id n2so8203397plf.4 for ; Fri, 11 Mar 2022 09:17:37 -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=ZotQSUjSGRvyi6rvnH7nRqxnyWQkOkYXFQpd1wEW1+sL945RlVVeeHxheVMf9hzbNY zofnQBlgCEfmAXAUzKDJuwb9wJoWDlJnRYShI1k1GjNi7JAzpgre49DwMHQReVoY19oM CZ4MbQfk1RoDCkrCHqvUDexC+qSwR2i4yeeFgO11+ve9LlTOBDjxr1BuSXN++3vCJf3V 5hmyECgPEhb0Bbu10MNFd3lxqnr3kFnd99nJtR82ehl8TGLKRxGvj7FkArFCGWS9CO9/ JUsvRF1tBeQ2hSRJsbspF0TwADnuOnBNRLFB9Go95+3rg/yW1OkTlZfKD2w0KRS4gScu oZ2Q== X-Gm-Message-State: AOAM532UshZigQu6U3XwZ3/yfVfH4rJixxhAALczUREPc/bqkBe269Qa A8378itLq42BtiFqMY3Bf7w4ryb5upk= X-Received: by 2002:a17:903:230c:b0:151:93d0:5608 with SMTP id d12-20020a170903230c00b0015193d05608mr11147633plh.167.1647019055354; Fri, 11 Mar 2022 09:17:35 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id f22-20020a056a0022d600b004f7a0b47b0dsm147860pfj.109.2022.03.11.09.17.33 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Mar 2022 09:17:35 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Fri, 11 Mar 2022 09:17:31 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Mar 2022 09:16:53 -0800 Message-Id: <20220311171653.17420-7-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220311171653.17420-1-pal@sandflow.com> References: <20220311171653.17420-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: Zg6OuAC+vSTO 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;