From patchwork Wed Sep 21 20:42:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 670 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp1148028vsd; Wed, 21 Sep 2016 13:42:32 -0700 (PDT) X-Received: by 10.28.134.8 with SMTP id i8mr4636615wmd.59.1474490552393; Wed, 21 Sep 2016 13:42:32 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w1si31326278wjv.42.2016.09.21.13.42.31; Wed, 21 Sep 2016 13:42:32 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D370E689CD4; Wed, 21 Sep 2016 23:42:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pa0-f65.google.com (mail-pa0-f65.google.com [209.85.220.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1CC59689B2D for ; Wed, 21 Sep 2016 23:42:00 +0300 (EEST) Received: by mail-pa0-f65.google.com with SMTP id hi10so2704564pac.2 for ; Wed, 21 Sep 2016 13:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qhAO6aXgRRQxrn14VqeoER52FW+KtOrJRTGxotjQMUE=; b=miU8+UkEZY2B/hUe29Luigxm6b8FiU4hX/sKCzzgRoQAsRJuVH5HmPM3V8T0wSOcur nkF65KexAwsaNlfs6pJXqM0S7rCPWP5coEdDCNHLA/rgIk2YX1l9Nj5RGAQiexMRk7N1 SzO7UquLyHS/HCSFpzay31LSXQZl1MNKpGi3UQbn+wAG1pPSj1S+YzV+u8vEE5paKqlv Qp1BoXAJRGUgJYqx86bZyzPPLghj/oY3UGYo7O9+QSO31a+NiDm6HX7RV64peh98yhId ZbznuiEeoGfMIirAcV8/penMJYkmab53fTkMWgwMuIlfWAloEm2EdZWl8U/EMLqwL3TY hnmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qhAO6aXgRRQxrn14VqeoER52FW+KtOrJRTGxotjQMUE=; b=X8dbbZM1bM8rnoNlgVTEALrESvnDAdBvOSKf4eCsYMHvl2ey3PwMstAAX5WTa+mLbF b64uE7x+auXXfq7qEBTHqlQ4LRXbYCzDf/ur2ShD0fNOx9U3xKzNTpMUq+W9sESVNCLT J5TaT7xHMocuDkydzBwtmbplCfo32BapePeqc5ITiJ+xcTZ+L+SkSbzCnF+oDs7ReL9h azjszYcMO8NeD+XdB/bOpu2mh83JJllgvQnnOTkEbnjBULWqV3JXpQDhih2NNwDiukM8 +EJYKFFs8yRwEo54PAm+pa+ULbIDg+CEcSSyQEdyztzO1IkMc63IXAtUY6IuLv+HScV8 w2yA== X-Gm-Message-State: AE9vXwMSOxnY1CI0O3evbC9oCym2jBDFCvvRIPqtSEi87hastoT6cIL8nFIF8fvsUOhlzA== X-Received: by 10.66.27.137 with SMTP id t9mr22169700pag.11.1474490534544; Wed, 21 Sep 2016 13:42:14 -0700 (PDT) Received: from localhost.localdomain (S0106ac228b6e4f8e.vc.shawcable.net. [24.86.216.51]) by smtp.gmail.com with ESMTPSA id y1sm17746623pfd.90.2016.09.21.13.42.13 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 21 Sep 2016 13:42:14 -0700 (PDT) From: Mark Reid To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Sep 2016 13:42:07 -0700 Message-Id: <20160921204209.8196-3-mindmark@gmail.com> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20160921204209.8196-1-mindmark@gmail.com> References: <20160921204209.8196-1-mindmark@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/4] libavformat/mxfdec: don't assume first stream index to be primary 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: Mark Reid MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavformat/mxfdec.c | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 23591b2..a22b2d6 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1472,6 +1472,14 @@ static int mxf_compute_index_tables(MXFContext *mxf) { int i, j, k, ret, nb_sorted_segments; MXFIndexTableSegment **sorted_segments = NULL; + AVStream *st = NULL; + + for (i = 0; i < mxf->fc->nb_streams; i++) { + if (mxf->fc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_DATA) + continue; + st = mxf->fc->streams[i]; + break; + } if ((ret = mxf_get_sorted_table_segments(mxf, &nb_sorted_segments, &sorted_segments)) || nb_sorted_segments <= 0) { @@ -1541,7 +1549,7 @@ static int mxf_compute_index_tables(MXFContext *mxf) av_log(mxf->fc, AV_LOG_WARNING, "IndexSID %i segment %i has zero IndexDuration and there's more than one segment\n", t->index_sid, k); - if (mxf->fc->nb_streams <= 0) { + if (!st) { av_log(mxf->fc, AV_LOG_WARNING, "no streams?\n"); break; } @@ -1549,7 +1557,7 @@ static int mxf_compute_index_tables(MXFContext *mxf) /* assume the first stream's duration is reasonable * leave index_duration = 0 on further segments in case we have any (unlikely) */ - t->segments[k]->index_duration = mxf->fc->streams[0]->duration; + t->segments[k]->index_duration = st->duration; break; } } @@ -2572,6 +2580,19 @@ static int is_pcm(enum AVCodecID codec_id) return codec_id >= AV_CODEC_ID_PCM_S16LE && codec_id < AV_CODEC_ID_PCM_S24DAUD; } +static AVStream* mxf_get_opatom_stream(MXFContext *mxf) +{ + if (mxf->op != OPAtom) + return NULL; + + for (int i = 0; i < mxf->fc->nb_streams; i++) { + if (mxf->fc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_DATA) + continue; + return mxf->fc->streams[i]; + } + return NULL; +} + /** * Deal with the case where for some audio atoms EditUnitByteCount is * very small (2, 4..). In those cases we should read more than one @@ -2583,13 +2604,13 @@ static void mxf_handle_small_eubc(AVFormatContext *s) /* assuming non-OPAtom == frame wrapped * no sane writer would wrap 2 byte PCM packets with 20 byte headers.. */ - if (mxf->op != OPAtom) + AVStream *st = mxf_get_opatom_stream(mxf); + if (!st) return; /* expect PCM with exactly one index table segment and a small (< 32) EUBC */ - if (s->nb_streams != 1 || - s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || - !is_pcm(s->streams[0]->codecpar->codec_id) || + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || + !is_pcm(st->codecpar->codec_id) || mxf->nb_index_tables != 1 || mxf->index_tables[0].nb_segments != 1 || mxf->index_tables[0].segments[0]->edit_unit_byte_count >= 32) @@ -2614,11 +2635,12 @@ static int mxf_handle_missing_index_segment(MXFContext *mxf) int essence_partition_count = 0; int i, ret; - if (mxf->op != OPAtom) + st = mxf_get_opatom_stream(mxf); + if (!st) return 0; /* TODO: support raw video without an index if they exist */ - if (s->nb_streams != 1 || s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(s->streams[0]->codecpar->codec_id)) + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(st->codecpar->codec_id)) return 0; /* check if file already has a IndexTableSegment */ @@ -2649,7 +2671,6 @@ static int mxf_handle_missing_index_segment(MXFContext *mxf) return ret; } - st = s->streams[0]; segment->type = IndexTableSegment; /* stream will be treated as small EditUnitByteCount */ segment->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3; @@ -3060,12 +3081,12 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) return mxf_read_packet_old(s, pkt); // If we have no streams then we basically are at EOF - if (s->nb_streams < 1) + st = mxf_get_opatom_stream(mxf); + if (!st) return AVERROR_EOF; /* OPAtom - clip wrapped demuxing */ /* NOTE: mxf_read_header() makes sure nb_index_tables > 0 for OPAtom */ - st = s->streams[0]; t = &mxf->index_tables[0]; if (mxf->current_edit_unit >= st->duration) @@ -3095,7 +3116,7 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) if ((size = av_get_packet(s->pb, pkt, size)) < 0) return size; - pkt->stream_index = 0; + pkt->stream_index = st->index; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && t->ptses && mxf->current_edit_unit >= 0 && mxf->current_edit_unit < t->nb_ptses) { @@ -3180,6 +3201,9 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti MXFIndexTable *t; MXFTrack *source_track = st->priv_data; + if(st->codecpar->codec_type == AVMEDIA_TYPE_DATA) + return 0; + /* if audio then truncate sample_time to EditRate */ if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) sample_time = av_rescale_q(sample_time, st->time_base,