From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7C8D9437A8 for ; Thu, 28 Jul 2022 18:25:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E2C2668B986; Thu, 28 Jul 2022 21:25:19 +0300 (EEST) Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F2DAF68B8C4 for ; Thu, 28 Jul 2022 21:25:13 +0300 (EEST) Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-32269d60830so28438807b3.2 for ; Thu, 28 Jul 2022 11:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc; bh=3YqqP9uFJniXTlFXeV8xFgE3iXCl8Vbzt01/+VitIxQ=; b=B01DRx8DDYzmBEWTk6gmXPIuGQoDbq+g+opmoIc5qsHr+isJzw/RJ8a7uQe/swAzbb Kv41eeDAUoPlGJLOKgQmLmsNlEfLta+oYO6DEo5JZbtAoUi637l9jFzWDeKcbsvml77l HSWuepw0bQ1Yqy8T5N4eJbLrrggj9fM4yvBdIxzCv1XCWUhuC30lpfMkcVwo3ivejl3D LhVTe9JcVyJtaNjfCiMVGtEUznoa+PfaEs7hAkEdqYNRkZhku0o0GXDaKXIz53Fuclum QBJ4SF7898ePB/COBAr4LeBCSO4xqjuCWydU8ZzM6cxB9SnOrzEituba9YeuM0pqoTyT Vj1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc; bh=3YqqP9uFJniXTlFXeV8xFgE3iXCl8Vbzt01/+VitIxQ=; b=493shKEIFpLGmFLSDLFuuMoV2Rlyezo/iJRKh1hjxDSuMWi9jAoZ3iFNMEaNM2kSHD 8Dxch+1ddTCUhdNwzzf5b36ai/9kDHkEhlzTsg2QkZxcoJSMNCRRDkB791RqyLIplIre u/IZmyiUHMCkdDMuJyj7nHK7QsGz8wEDEEvM/Hy8JJocwgNqubQZ/FLF62654IPPX5sq SGoqkU84aacWDoP3cfWuJ9KPidKKCh3SsfD9Ju/9o98TAoLF+bjmdRWjTBLG3jm4I3qV 3AWlHO4M2PA3r9A4gKW6d+8XdNA3UEJeZNppIKfAfQ7GsTH2exrKSKXs+A5YMz2zjndC yZZQ== X-Gm-Message-State: AJIora8eqGksyOW8//gojQx4DdeAQJ/d1Kct0yKb3KI7UW8aiOxcFkmM wF4tNYNEi8GpjgWk0HvNwnuta9NN57HUqVZomstEZ6iUgP/onA== X-Google-Smtp-Source: AGRyM1vhCQdefGxWmuijpTX7VgTz2csk/YY0quZtzE72giS9lGFqdrKN95c66eeYiH1dj/87CEuZWFcA0Z4Wr0rvHKU= X-Received: by 2002:a81:f93:0:b0:31f:531c:5499 with SMTP id 141-20020a810f93000000b0031f531c5499mr11677161ywp.509.1659032711970; Thu, 28 Jul 2022 11:25:11 -0700 (PDT) MIME-Version: 1.0 References: <20220727161202.2764806-1-vigneshv@google.com> In-Reply-To: From: Vignesh Venkatasubramanian Date: Thu, 28 Jul 2022 11:25:00 -0700 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Wed, Jul 27, 2022 at 12:40 PM Andreas Rheinhardt wrote: > > Vignesh Venkatasubramanian: > > Stores the item ids of all the items found in the file and > > processes the primary item at the end of the meta box. This patch > > does not change any behavior. It sets up the code for parsing > > alpha channel (and possibly images with 'grid') in follow up > > patches. > > > > Signed-off-by: Vignesh Venkatasubramanian > > --- > > libavformat/isom.h | 4 ++ > > libavformat/mov.c | 146 ++++++++++++++++++++++++++++----------------- > > 2 files changed, 95 insertions(+), 55 deletions(-) > > > > diff --git a/libavformat/isom.h b/libavformat/isom.h > > index f05c2d9c28..d8b262e915 100644 > > --- a/libavformat/isom.h > > +++ b/libavformat/isom.h > > @@ -318,6 +318,10 @@ typedef struct MOVContext { > > uint32_t max_stts_delta; > > int is_still_picture_avif; > > int primary_item_id; > > + int *avif_item_ids; > > + int avif_item_ids_size; > > + int *avif_extent_lengths; > > + int64_t *avif_extent_offsets; > > Why are these three different buffers instead of one buffer of struct { > int avif_item_ids; int avif_extent_lengths; int64_t avif_extent_offsets;}? > Ah good point. Updated to use a struct and a size field. > > } MOVContext; > > > > int ff_mp4_read_descr_len(AVIOContext *pb); > > diff --git a/libavformat/mov.c b/libavformat/mov.c > > index a09a762d91..fc6a691da4 100644 > > --- a/libavformat/mov.c > > +++ b/libavformat/mov.c > > @@ -4698,6 +4698,69 @@ static int mov_read_custom(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > return ret; > > } > > > > +static int avif_add_stream(MOVContext *c, int item_id) > > +{ > > + MOVStreamContext *sc; > > + AVStream *st; > > + int item_index = -1; > > + for (int i = 0; i < c->avif_item_ids_size; i++) > > + if (c->avif_item_ids[i] == item_id) { > > + item_index = i; > > + break; > > + } > > + if (item_index < 0) > > + return AVERROR_INVALIDDATA; > > + st = avformat_new_stream(c->fc, NULL); > > + if (!st) > > + return AVERROR(ENOMEM); > > + st->id = c->fc->nb_streams; > > + sc = av_mallocz(sizeof(MOVStreamContext)); > > + if (!sc) > > + return AVERROR(ENOMEM); > > + > > + st->priv_data = sc; > > + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; > > + st->codecpar->codec_id = AV_CODEC_ID_AV1; > > + sc->ffindex = st->index; > > + c->trak_index = st->index; > > + st->avg_frame_rate.num = st->avg_frame_rate.den = 1; > > + st->time_base.num = st->time_base.den = 1; > > + st->nb_frames = 1; > > + sc->time_scale = 1; > > + sc = st->priv_data; > > + sc->pb = c->fc->pb; > > + sc->pb_is_copied = 1; > > + > > + // Populate the necessary fields used by mov_build_index. > > + sc->stsc_count = 1; > > + sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data)); > > + if (!sc->stsc_data) > > + return AVERROR(ENOMEM); > > + sc->stsc_data[0].first = 1; > > + sc->stsc_data[0].count = 1; > > + sc->stsc_data[0].id = 1; > > + sc->chunk_count = 1; > > + sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets)); > > + if (!sc->chunk_offsets) > > + return AVERROR(ENOMEM); > > + sc->sample_count = 1; > > + sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes)); > > + if (!sc->sample_sizes) > > + return AVERROR(ENOMEM); > > + sc->stts_count = 1; > > + sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data)); > > + if (!sc->stts_data) > > + return AVERROR(ENOMEM); > > + sc->stts_data[0].count = 1; > > + // Not used for still images. But needed by mov_build_index. > > + sc->stts_data[0].duration = 0; > > + sc->sample_sizes[0] = c->avif_extent_lengths[item_index]; > > + sc->chunk_offsets[0] = c->avif_extent_offsets[item_index]; > > + > > + mov_build_index(c, st); > > + return 0; > > +} > > + > > static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > { > > while (atom.size > 8) { > > @@ -4707,9 +4770,23 @@ static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > tag = avio_rl32(pb); > > atom.size -= 4; > > if (tag == MKTAG('h','d','l','r')) { > > + int ret; > > avio_seek(pb, -8, SEEK_CUR); > > atom.size += 8; > > - return mov_read_default(c, pb, atom); > > + if ((ret = mov_read_default(c, pb, atom)) < 0) > > + return ret; > > + if (c->is_still_picture_avif) { > > + int ret; > > + // Add a stream for the YUV planes (primary item). > > + if ((ret = avif_add_stream(c, c->primary_item_id)) < 0) > > + return ret; > > + // For still AVIF images, the meta box contains all the > > + // necessary information that would generally be provided by the > > + // moov box. So simply mark that we have found the moov box so > > + // that parsing can continue. > > + c->found_moov = 1; > > + } > > + return ret; > > } > > } > > return 0; > > @@ -7478,8 +7555,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > int item_count, extent_count; > > uint64_t base_offset, extent_offset, extent_length; > > uint8_t value; > > - AVStream *st; > > - MOVStreamContext *sc; > > > > if (!c->is_still_picture_avif) { > > // * For non-avif, we simply ignore the iloc box. > > @@ -7493,27 +7568,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > return 0; > > } > > > > - st = avformat_new_stream(c->fc, NULL); > > - if (!st) > > - return AVERROR(ENOMEM); > > - st->id = c->fc->nb_streams; > > - sc = av_mallocz(sizeof(MOVStreamContext)); > > - if (!sc) > > - return AVERROR(ENOMEM); > > - > > - st->priv_data = sc; > > - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; > > - st->codecpar->codec_id = AV_CODEC_ID_AV1; > > - sc->ffindex = st->index; > > - c->trak_index = st->index; > > - st->avg_frame_rate.num = st->avg_frame_rate.den = 1; > > - st->time_base.num = st->time_base.den = 1; > > - st->nb_frames = 1; > > - sc->time_scale = 1; > > - sc = st->priv_data; > > - sc->pb = c->fc->pb; > > - sc->pb_is_copied = 1; > > - > > version = avio_r8(pb); > > avio_rb24(pb); // flags. > > > > @@ -7529,34 +7583,22 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > } > > item_count = (version < 2) ? avio_rb16(pb) : avio_rb32(pb); > > > > - // Populate the necessary fields used by mov_build_index. > > - sc->stsc_count = 1; > > - sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data)); > > - if (!sc->stsc_data) > > + c->avif_item_ids = av_malloc_array(item_count, sizeof(*c->avif_item_ids)); > > + if (!c->avif_item_ids) > > return AVERROR(ENOMEM); > > - sc->stsc_data[0].first = 1; > > - sc->stsc_data[0].count = 1; > > - sc->stsc_data[0].id = 1; > > - sc->chunk_count = 1; > > - sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets)); > > - if (!sc->chunk_offsets) > > + c->avif_item_ids_size = item_count; > > + c->avif_extent_lengths = av_malloc_array(item_count, sizeof(*c->avif_extent_lengths)); > > + if (!c->avif_extent_lengths) > > return AVERROR(ENOMEM); > > - sc->sample_count = 1; > > - sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes)); > > - if (!sc->sample_sizes) > > + c->avif_extent_offsets = av_malloc_array(item_count, sizeof(*c->avif_extent_offsets)); > > + if (!c->avif_extent_offsets) > > return AVERROR(ENOMEM); > > - sc->stts_count = 1; > > - sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data)); > > - if (!sc->stts_data) > > - return AVERROR(ENOMEM); > > - sc->stts_data[0].count = 1; > > - // Not used for still images. But needed by mov_build_index. > > - sc->stts_data[0].duration = 0; > > > > for (int i = 0; i < item_count; i++) { > > int item_id = (version < 2) ? avio_rb16(pb) : avio_rb32(pb); > > if (avio_feof(pb)) > > return AVERROR_INVALIDDATA; > > + c->avif_item_ids[i] = item_id; > > if (version > 0) > > avio_rb16(pb); // construction_method. > > avio_rb16(pb); // data_reference_index. > > @@ -7572,20 +7614,11 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > if (rb_size(pb, &extent_offset, offset_size) < 0 || > > rb_size(pb, &extent_length, length_size) < 0) > > return AVERROR_INVALIDDATA; > > - if (item_id == c->primary_item_id) { > > - sc->sample_sizes[0] = extent_length; > > - sc->chunk_offsets[0] = base_offset + extent_offset; > > - } > > + c->avif_extent_lengths[i] = extent_length; > > + c->avif_extent_offsets[i] = base_offset + extent_offset; > > } > > } > > > > - mov_build_index(c, st); > > - > > - // For still AVIF images, the iloc box contains all the necessary > > - // information that would generally be provided by the moov box. So simply > > - // mark that we have found the moov box so that parsing can continue. > > - c->found_moov = 1; > > - > > return atom.size; > > } > > > > @@ -8189,6 +8222,9 @@ static int mov_read_close(AVFormatContext *s) > > > > av_freep(&mov->aes_decrypt); > > av_freep(&mov->chapter_tracks); > > + av_freep(&mov->avif_item_ids); > > + av_freep(&mov->avif_extent_lengths); > > + av_freep(&mov->avif_extent_offsets); > > > > return 0; > > } > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". -- Vignesh _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".