From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 3/8] avformat/mov: factorize out setting the output packet properties
Date: Sat, 17 Feb 2024 19:02:37 -0300
Message-ID: <20240217220242.62035-3-jamrial@gmail.com> (raw)
In-Reply-To: <20240217220242.62035-1-jamrial@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
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".
next prev parent reply other threads:[~2024-02-17 22:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-17 22:02 [FFmpeg-devel] [PATCH 1/8] avformat/demux: allow demuxers to output more than one packet per read_packet() call James Almer
2024-02-17 22:02 ` [FFmpeg-devel] [PATCH 2/8] avformat/iamfdec: further split into shareable modules James Almer
2024-02-17 22:02 ` James Almer [this message]
2024-02-17 22:02 ` [FFmpeg-devel] [PATCH 4/8] avformat/mov: make MOVStreamContext refcounted James Almer
2024-02-17 22:02 ` [FFmpeg-devel] [PATCH 5/8] avformat/mov: add support for Immersive Audio Model and Formats in ISOBMFF James Almer
2024-02-17 22:02 ` [FFmpeg-devel] [PATCH 6/8] avformat/iamfenc: further split into shareable modules James Almer
2024-02-17 22:02 ` [FFmpeg-devel] [PATCH 7/8] avformat/movenc: add support for Immersive Audio Model and Formats in ISOBMFF James Almer
2024-02-20 13:37 ` Andreas Rheinhardt
2024-02-20 14:07 ` James Almer
2024-02-20 14:21 ` Andreas Rheinhardt
2024-02-20 14:47 ` James Almer
2024-02-17 22:02 ` [FFmpeg-devel] [PATCH 8/8] fate: add IAMF in mp4 tests James Almer
2024-02-20 13:29 ` James Almer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240217220242.62035-3-jamrial@gmail.com \
--to=jamrial@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git