From patchwork Tue Jan 17 13:39:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Rapp X-Patchwork-Id: 2233 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp524022vsb; Tue, 17 Jan 2017 05:40:01 -0800 (PST) X-Received: by 10.28.9.131 with SMTP id 125mr15547218wmj.22.1484660401418; Tue, 17 Jan 2017 05:40:01 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b185si15962277wmc.27.2017.01.17.05.40.00; Tue, 17 Jan 2017 05:40: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 3A7E568A1A1; Tue, 17 Jan 2017 15:39:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from p1002.netstorage.at (p1002.netstorage.at [89.207.146.186]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4BC3168A074 for ; Tue, 17 Jan 2017 15:39:12 +0200 (EET) Received: from mailix (noaport.de [46.237.252.213]) by p1002.netstorage.at (Postfix) with ESMTPA id 4C21E81BD2 for ; Tue, 17 Jan 2017 14:39:21 +0100 (CET) Received: from frogstar-a.kuhnle.local (frogstar-a.kuhnle.local [192.168.0.26]) by mailix with ESMTPA ; Tue, 17 Jan 2017 14:39:20 +0100 From: Tobias Rapp To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 Jan 2017 14:39:19 +0100 Message-Id: <1484660361-21502-3-git-send-email-t.rapp@noa-archive.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484660361-21502-1-git-send-email-t.rapp@noa-archive.com> References: <1484660361-21502-1-git-send-email-t.rapp@noa-archive.com> X-PPP-Message-ID: <20170117133921.32482.31406@p1002.netstorage.at> X-PPP-Vhost: noa-archive.com Subject: [FFmpeg-devel] [PATCH 2/4] avformat/avienc: write chained master index only if std_compliance is normal or below 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" OpenDML specification v1.02 states that entries of a master index chunk shall point to standard or field index chunks. Changed incorrect duration of last master index entry to -1 in case it points to another master index. Propagate error when index write fails. Signed-off-by: Tobias Rapp --- libavformat/avienc.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/libavformat/avienc.c b/libavformat/avienc.c index fd16fff..5d5c02a 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -524,7 +524,13 @@ static int avi_write_header(AVFormatContext *s) return 0; } -static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, int size) +/* Index entry points to standard index */ +#define AVI_UPDATE_ODML_ENTRY_DEFAULT 0x00000000 + +/* Index entry points to another master index */ +#define AVI_UPDATE_ODML_ENTRY_MASTER 0x00000001 + +static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, int size, int flags) { AVIOContext *pb = s->pb; AVIContext *avi = s->priv_data; @@ -544,7 +550,10 @@ static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, avio_wl64(pb, ix); /* qwOffset */ avio_wl32(pb, size); /* dwSize */ ff_parse_specific_params(s->streams[stream_index], &au_byterate, &au_ssize, &au_scale); - if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && au_ssize > 0) { + if (flags & AVI_UPDATE_ODML_ENTRY_MASTER) { + av_assert0(s->strict_std_compliance <= FF_COMPLIANCE_NORMAL); + avio_wl32(pb, -1); /* dwDuration (undefined) */ + } else if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && au_ssize > 0) { uint32_t audio_segm_size = (avist->audio_strm_length - avist->indexes.audio_strm_offset); if ((audio_segm_size % au_ssize > 0) && !avist->sample_requested) { avpriv_request_sample(s, "OpenDML index duration for audio packets with partial frames"); @@ -567,6 +576,12 @@ static int avi_write_ix(AVFormatContext *s) av_assert0(pb->seekable); + if (avi->riff_id >= AVI_MASTER_INDEX_SIZE && s->strict_std_compliance > FF_COMPLIANCE_NORMAL) { + av_log(s, AV_LOG_ERROR, "Invalid riff index %d >= %d\n", + avi->riff_id, AVI_MASTER_INDEX_SIZE); + return AVERROR(EINVAL); + } + for (i = 0; i < s->nb_streams; i++) { AVIStream *avist = s->streams[i]->priv_data; if (avi->riff_id - avist->indexes.master_odml_riff_id_base == AVI_MASTER_INDEX_SIZE) { @@ -574,7 +589,7 @@ static int avi_write_ix(AVFormatContext *s) int size = 8+2+1+1+4+8+4+4+16*AVI_MASTER_INDEX_SIZE; pos = avio_tell(pb); - update_odml_entry(s, i, pos, size); + update_odml_entry(s, i, pos, size, AVI_UPDATE_ODML_ENTRY_MASTER); write_odml_master(s, i); av_assert1(avio_tell(pb) - pos == size); avist->indexes.master_odml_riff_id_base = avi->riff_id - 1; @@ -610,7 +625,7 @@ static int avi_write_ix(AVFormatContext *s) (ie->flags & 0x10 ? 0 : 0x80000000)); } - update_odml_entry(s, i, ix, avio_tell(pb) - ix); + update_odml_entry(s, i, ix, avio_tell(pb) - ix, AVI_UPDATE_ODML_ENTRY_DEFAULT); } return 0; } @@ -801,6 +816,7 @@ static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt) AVIOContext *pb = s->pb; AVIStream *avist = s->streams[stream_index]->priv_data; AVCodecParameters *par = s->streams[stream_index]->codecpar; + int ret; if (pkt->dts != AV_NOPTS_VALUE) avist->last_dts = pkt->dts + pkt->duration; @@ -810,7 +826,8 @@ static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt) // Make sure to put an OpenDML chunk when the file size exceeds the limits if (pb->seekable && (avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) { - avi_write_ix(s); + if ((ret = avi_write_ix(s)) < 0) + return ret; ff_end_tag(pb, avi->movi_list); if (avi->riff_id == 1) @@ -827,7 +844,6 @@ static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt) avist->audio_strm_length += size; if (s->pb->seekable) { - int ret; ret = avi_add_ientry(s, stream_index, NULL, flags, size); if (ret < 0) return ret; @@ -861,7 +877,7 @@ static int avi_write_trailer(AVFormatContext *s) res = avi_write_idx1(s); ff_end_tag(pb, avi->riff_start); } else { - avi_write_ix(s); + res = avi_write_ix(s); ff_end_tag(pb, avi->movi_list); ff_end_tag(pb, avi->riff_start);