From patchwork Sun Jun 24 22:12:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 9497 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:141:0:0:0:0:0 with SMTP id c62-v6csp3423194jad; Sun, 24 Jun 2018 15:12:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf2sXpkTPNfgN1p3GKhpmMiu/XCQrDEVgSsnxLGiLPOoo9QqyfZTaYt0acnK0jxyf4myD9t X-Received: by 2002:a1c:110a:: with SMTP id 10-v6mr6907524wmr.130.1529878372903; Sun, 24 Jun 2018 15:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529878372; cv=none; d=google.com; s=arc-20160816; b=tYAUgWYhLuzu5byS1FvrJPIGaApMGBOEYXf7mI80k/hIq2ntuodkoWdV26xJKa5N+R AcR6anD41rNAEOkOPVv8XTu096sDaVRaWf4ihEj8NwWWiB87pcufnF2pbmPhobWiOd9M yy+WydbbXFPPeOjme30S2H6koAal4WboMN4N95SEmLJR4e7uoGP9lZu9cpADZ3BjsMpw irn2SsfsqR0SxFDAsmwzyQvdF9h3vLwiQs/PFrEsGGo5vAke9jLWHIQAteDfWndkKDWz N+g8HWhKfx2BDwBUIHexGvsVYOKFRFmDGp+vLmtiff86WhlgQt9w05ZFphCw4Zk/Au4I a8jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=2NlmRYyviy2ewUqN1D3S0mShonp9PgKtm+XQBRyZo68=; b=Id09gofO+fLEs9RIRcQ1ho0W3XRoY6Fda51Vxblp2geGSqL0WkpIgZvmJuVKdnUXo7 a9t97IXa+AZsone8YzSqw/O0uLhFeTC+BYsZJNLOZSPHvRKJ8gAF4n+PU+FokZxCUe1c NRdXmORXGSPtzENfJKyrzRyuwWxNW69355v7PQQbaCwFKVuOyLY4LpM5mHe4qjpBDF1a jhTkuBxnlw4qhZkQQC5ewCssJHO9OXC1cDLwU0DsnZ4cpsWlzfxD37gAnKQkn9Jn9b5M bNkWL2iNublYf1lhsbSFdeRMZcEQnx8bxyPiLZXdZmdw3ZHPEK6Xoy37mXVq10ghDxGH uwwA== 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 o16-v6si3816481wro.383.2018.06.24.15.12.52; Sun, 24 Jun 2018 15:12:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF5C7689E18; Mon, 25 Jun 2018 01:11:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8BE7C6882C1 for ; Mon, 25 Jun 2018 01:11:36 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A8CECE06CF; Mon, 25 Jun 2018 00:12:31 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 74D6vu6oUbhy; Mon, 25 Jun 2018 00:12:30 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B3FE8E1021; Mon, 25 Jun 2018 00:12:29 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 Jun 2018 00:12:22 +0200 Message-Id: <20180624221224.14892-3-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180624221224.14892-1-cus@passwd.hu> References: <20180624221224.14892-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 3/5] avformat/mxfdec: take into account index_edit_rate X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes samples/ffmpeg-bugs/roundup/issue591/02785736.mxf Fixes samples/ffmpeg-bugs/trac/ticket1916/pcm_s24le_to_pcm_s16le.mxf Signed-off-by: Marton Balint --- libavformat/mxfdec.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index fb03cb97f1..8f64bd9501 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1465,11 +1465,13 @@ static int64_t mxf_essence_container_end(MXFContext *mxf, int body_sid) } /* EditUnit -> absolute offset */ -static int mxf_edit_unit_absolute_offset(MXFContext *mxf, MXFIndexTable *index_table, int64_t edit_unit, int64_t *edit_unit_out, int64_t *offset_out, MXFPartition **partition_out, int nag) +static int mxf_edit_unit_absolute_offset(MXFContext *mxf, MXFIndexTable *index_table, int64_t edit_unit, AVRational edit_rate, int64_t *edit_unit_out, int64_t *offset_out, MXFPartition **partition_out, int nag) { int i; int64_t offset_temp = 0; + edit_unit = av_rescale_q(edit_unit, index_table->segments[0]->index_edit_rate, edit_rate); + for (i = 0; i < index_table->nb_segments; i++) { MXFIndexTableSegment *s = index_table->segments[i]; @@ -1498,7 +1500,7 @@ static int mxf_edit_unit_absolute_offset(MXFContext *mxf, MXFIndexTable *index_t } if (edit_unit_out) - *edit_unit_out = edit_unit; + *edit_unit_out = av_rescale_q(edit_unit, edit_rate, s->index_edit_rate); return mxf_absolute_bodysid_offset(mxf, index_table->body_sid, offset_temp, offset_out, partition_out); } else { @@ -1712,6 +1714,13 @@ static int mxf_compute_index_tables(MXFContext *mxf) /* fix zero IndexDurations */ for (k = 0; k < t->nb_segments; k++) { + if (!t->segments[k]->index_edit_rate.num || !t->segments[k]->index_edit_rate.den) { + av_log(mxf->fc, AV_LOG_WARNING, "IndexSID %i segment %i has invalid IndexEditRate\n", + t->index_sid, k); + if (mxf_track) + t->segments[k]->index_edit_rate = mxf_track->edit_rate; + } + if (t->segments[k]->index_duration) continue; @@ -3138,7 +3147,7 @@ static int mxf_get_next_track_edit_unit(MXFContext *mxf, MXFTrack *track, int64_ while (b - a > 1) { m = (a + b) >> 1; - if (mxf_edit_unit_absolute_offset(mxf, t, m, NULL, &offset, NULL, 0) < 0) + if (mxf_edit_unit_absolute_offset(mxf, t, m, track->edit_rate, NULL, &offset, NULL, 0) < 0) return -1; if (offset < current_offset) a = m; @@ -3210,7 +3219,7 @@ static int64_t mxf_set_current_edit_unit(MXFContext *mxf, AVStream *st, int64_t if (!t || track->wrapping == UnknownWrapped) return -1; - if (mxf_edit_unit_absolute_offset(mxf, t, edit_unit + track->edit_units_per_packet, NULL, &next_ofs, NULL, 0) < 0 && + if (mxf_edit_unit_absolute_offset(mxf, t, edit_unit + track->edit_units_per_packet, track->edit_rate, NULL, &next_ofs, NULL, 0) < 0 && (next_ofs = mxf_essence_container_end(mxf, t->body_sid)) <= 0) { av_log(mxf->fc, AV_LOG_ERROR, "unable to compute the size of the last packet\n"); return -1; @@ -3542,7 +3551,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti if (source_track->wrapping == UnknownWrapped) av_log(mxf->fc, AV_LOG_WARNING, "attempted seek in an UnknownWrapped essence\n"); - if ((ret = mxf_edit_unit_absolute_offset(mxf, t, sample_time, &sample_time, &seekpos, &partition, 1)) < 0) + if ((ret = mxf_edit_unit_absolute_offset(mxf, t, sample_time, source_track->edit_rate, &sample_time, &seekpos, &partition, 1)) < 0) return ret; ff_update_cur_dts(s, st, sample_time);