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 8B43A496B0 for ; Sat, 17 Feb 2024 22:04:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 18A9B68D2FB; Sun, 18 Feb 2024 00:03:47 +0200 (EET) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0EC4968CFFC for ; Sun, 18 Feb 2024 00:03:40 +0200 (EET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1d7232dcb3eso13719525ad.2 for ; Sat, 17 Feb 2024 14:03:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708207417; x=1708812217; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=PZaXU9V6tyhIgly+syYNmLPyKlc3/KVVXBrekj5m6WY=; b=b7326TquSiV50DxYAJeN3IRDG8WjVJZWBBK4B9OX/GCFMjvTm5QtY++aY5Wk9Fayv5 CB5UElF1v2xgVsFxS0hQhmA4klSra5akC+Q8IgLKwKDaMgGnP5YKCmlbZ5Qj9qRbWfD6 3Y5N9j5K7kStS9b/6FUhXDVlQFtSO07BEbeQGxbqEFkNhKPoFNnTaltJGbevrWUhfrow 62vlHFwYJiZd3W5812I6ThtMhFfZkbnVOLdNWDENdVdtlUiGy4RUnbTjpPrAmZSVrbRg hTYG/csGL/WZjEXt5MBM2sB3Ld4PwPo+RiUJz26b8uisOl5hdnCyP71CU6JTcVMFK/IN UuNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708207417; x=1708812217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PZaXU9V6tyhIgly+syYNmLPyKlc3/KVVXBrekj5m6WY=; b=PD/dzjRGr/ypcLp4iwYKS006pNn/I7jkzaJKzPWuq/HYlFf26vs6L2UnWub9Sj0+CE LG3yZ97i326hPdEr6tiXjOrtnSpgZWRMgipxGSzyLNpKAhX1bPbuY/LWUikpErJu/WDy phuXcE7Q1746i8bnetplFn7qiZmsIAv73fdBu+QIh0CQy9Dyi8koWa4OCpGgs9jWUCRS GR6hh/kTahtHjR7PaEv+krbA838IAw7Vu8v0FguJ3cxzIM8F/yp8ClbKCWVwoSwOd1JZ 4SasD/Z32jjKPbgWX8C5f6oqHoGStKniIYEx1CZyf3BiYiMD1atqCHKzGMq+/HhiXqgr EkhQ== X-Gm-Message-State: AOJu0YwadU7RaQgHAxhN8th5aRxl4c49YzEJp8t547kqww8o9fUWJQ7W 8TrLx+DXdj4VDp1RTcFb8egBEolduOPM6sxSiYbk7e2athNw3eyGmkYkqWG9 X-Google-Smtp-Source: AGHT+IGvBSW5oxE6xL0dWNZH9Sr5zCF3oNWUghySR27p+7zWhj0tDu9TkRy52MSQ8KK1g4hqca9h2A== X-Received: by 2002:a17:903:244e:b0:1da:20c4:5110 with SMTP id l14-20020a170903244e00b001da20c45110mr10585456pls.16.1708207417175; Sat, 17 Feb 2024 14:03:37 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id e6-20020a17090301c600b001d77a0e1374sm1850326plh.151.2024.02.17.14.03.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 14:03:36 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Feb 2024 19:02:37 -0300 Message-ID: <20240217220242.62035-3-jamrial@gmail.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240217220242.62035-1-jamrial@gmail.com> References: <20240217220242.62035-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/8] avformat/mov: factorize out setting the output packet properties 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: Signed-off-by: James Almer --- libavformat/mov.c | 113 ++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 49 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 92304565df..e548f93f17 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -9192,8 +9192,9 @@ static int mov_switch_root(AVFormatContext *s, int64_t target, int index) return 1; } -static int mov_change_extradata(MOVStreamContext *sc, AVPacket *pkt) +static int mov_change_extradata(AVStream *st, AVPacket *pkt) { + MOVStreamContext *sc = st->priv_data; uint8_t *side, *extradata; int extradata_size; @@ -9203,7 +9204,7 @@ static int mov_change_extradata(MOVStreamContext *sc, AVPacket *pkt) /* Notify the decoder that extradata changed. */ extradata_size = sc->extradata_size[sc->last_stsd_index]; extradata = sc->extradata[sc->last_stsd_index]; - if (extradata_size > 0 && extradata) { + if (st->discard != AVDISCARD_ALL && extradata_size > 0 && extradata) { side = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, extradata_size); @@ -9236,6 +9237,64 @@ static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size) return 0; } +static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *sample, + int64_t current_index, AVPacket *pkt) +{ + MOVStreamContext *sc = st->priv_data; + + pkt->stream_index = sc->ffindex; + pkt->dts = sample->timestamp; + if (sample->flags & AVINDEX_DISCARD_FRAME) { + pkt->flags |= AV_PKT_FLAG_DISCARD; + } + if (sc->ctts_data && sc->ctts_index < sc->ctts_count) { + pkt->pts = av_sat_add64(pkt->dts, av_sat_add64(sc->dts_shift, sc->ctts_data[sc->ctts_index].duration)); + /* update ctts context */ + sc->ctts_sample++; + if (sc->ctts_index < sc->ctts_count && + sc->ctts_data[sc->ctts_index].count == sc->ctts_sample) { + sc->ctts_index++; + sc->ctts_sample = 0; + } + } else { + int64_t next_dts = (sc->current_sample < ffstream(st)->nb_index_entries) ? + ffstream(st)->index_entries[sc->current_sample].timestamp : st->duration; + + if (next_dts >= pkt->dts) + pkt->duration = next_dts - pkt->dts; + pkt->pts = pkt->dts; + } + + if (sc->sdtp_data && sc->current_sample <= sc->sdtp_count) { + uint8_t sample_flags = sc->sdtp_data[sc->current_sample - 1]; + uint8_t sample_is_depended_on = (sample_flags >> 2) & 0x3; + pkt->flags |= sample_is_depended_on == MOV_SAMPLE_DEPENDENCY_NO ? AV_PKT_FLAG_DISPOSABLE : 0; + } + pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? AV_PKT_FLAG_KEY : 0; + pkt->pos = sample->pos; + + /* Multiple stsd handling. */ + if (sc->stsc_data) { + if (sc->stsc_data[sc->stsc_index].id > 0 && + sc->stsc_data[sc->stsc_index].id - 1 < sc->stsd_count && + sc->stsc_data[sc->stsc_index].id - 1 != sc->last_stsd_index) { + int ret = mov_change_extradata(st, pkt); + if (ret < 0) + return ret; + } + + /* Update the stsc index for the next sample */ + sc->stsc_sample++; + if (mov_stsc_index_valid(sc->stsc_index, sc->stsc_count) && + mov_get_stsc_samples(sc, sc->stsc_index) == sc->stsc_sample) { + sc->stsc_index++; + sc->stsc_sample = 0; + } + } + + return 0; +} + static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) { MOVContext *mov = s->priv_data; @@ -9320,56 +9379,12 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) } } - pkt->stream_index = sc->ffindex; - pkt->dts = sample->timestamp; - if (sample->flags & AVINDEX_DISCARD_FRAME) { - pkt->flags |= AV_PKT_FLAG_DISCARD; - } - if (sc->ctts_data && sc->ctts_index < sc->ctts_count) { - pkt->pts = av_sat_add64(pkt->dts, av_sat_add64(sc->dts_shift, sc->ctts_data[sc->ctts_index].duration)); - /* update ctts context */ - sc->ctts_sample++; - if (sc->ctts_index < sc->ctts_count && - sc->ctts_data[sc->ctts_index].count == sc->ctts_sample) { - sc->ctts_index++; - sc->ctts_sample = 0; - } - } else { - int64_t next_dts = (sc->current_sample < ffstream(st)->nb_index_entries) ? - ffstream(st)->index_entries[sc->current_sample].timestamp : st->duration; + ret = mov_finalize_packet(s, st, sample, current_index, pkt); + if (ret < 0) + return ret; - if (next_dts >= pkt->dts) - pkt->duration = next_dts - pkt->dts; - pkt->pts = pkt->dts; - } if (st->discard == AVDISCARD_ALL) goto retry; - if (sc->sdtp_data && sc->current_sample <= sc->sdtp_count) { - uint8_t sample_flags = sc->sdtp_data[sc->current_sample - 1]; - uint8_t sample_is_depended_on = (sample_flags >> 2) & 0x3; - pkt->flags |= sample_is_depended_on == MOV_SAMPLE_DEPENDENCY_NO ? AV_PKT_FLAG_DISPOSABLE : 0; - } - pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? AV_PKT_FLAG_KEY : 0; - pkt->pos = sample->pos; - - /* Multiple stsd handling. */ - if (sc->stsc_data) { - if (sc->stsc_data[sc->stsc_index].id > 0 && - sc->stsc_data[sc->stsc_index].id - 1 < sc->stsd_count && - sc->stsc_data[sc->stsc_index].id - 1 != sc->last_stsd_index) { - ret = mov_change_extradata(sc, pkt); - if (ret < 0) - return ret; - } - - /* Update the stsc index for the next sample */ - sc->stsc_sample++; - if (mov_stsc_index_valid(sc->stsc_index, sc->stsc_count) && - mov_get_stsc_samples(sc, sc->stsc_index) == sc->stsc_sample) { - sc->stsc_index++; - sc->stsc_sample = 0; - } - } if (mov->aax_mode) aax_filter(pkt->data, pkt->size, mov); -- 2.43.1 _______________________________________________ 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".