History

avformat/mov: factorize out setting the output packet properties

James Almer committed 2 years ago

Commit ce7b5191 parent b140b831 file · +64 −49Browse files

Unified · Split

libavformat/mov.c+64−49
@@ -9142,8 +9142,9 @@ static int mov_switch_root(AVFormatContext *s, int64_t target, int index) · 9141 unmodified lines
91429142 return 1;
91439143 }
91449144
9145−static int mov_change_extradata(MOVStreamContext *sc, AVPacket *pkt)
9145+static int mov_change_extradata(AVStream *st, AVPacket *pkt)
91469146 {
9147+ MOVStreamContext *sc = st->priv_data;
91479148 uint8_t *side, *extradata;
91489149 int extradata_size;
91499150
@@ -9153,7 +9154,7 @@ static int mov_change_extradata(MOVStreamContext *sc, AVPacket *pkt) · 3 unmodified lines
91539154 /* Notify the decoder that extradata changed. */
91549155 extradata_size = sc->extradata_size[sc->last_stsd_index];
91559156 extradata = sc->extradata[sc->last_stsd_index];
9156− if (extradata_size > 0 && extradata) {
9157+ if (st->discard != AVDISCARD_ALL && extradata_size > 0 && extradata) {
91579158 side = av_packet_new_side_data(pkt,
91589159 AV_PKT_DATA_NEW_EXTRADATA,
91599160 extradata_size);
@@ -9186,6 +9187,64 @@ static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size) · 26 unmodified lines
91869187 return 0;
91879188 }
91889189
9190+static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *sample,
9191+ int64_t current_index, AVPacket *pkt)
9192+{
9193+ MOVStreamContext *sc = st->priv_data;
9194+
9195+ pkt->stream_index = sc->ffindex;
9196+ pkt->dts = sample->timestamp;
9197+ if (sample->flags & AVINDEX_DISCARD_FRAME) {
9198+ pkt->flags |= AV_PKT_FLAG_DISCARD;
9199+ }
9200+ if (sc->ctts_data && sc->ctts_index < sc->ctts_count) {
9201+ pkt->pts = av_sat_add64(pkt->dts, av_sat_add64(sc->dts_shift, sc->ctts_data[sc->ctts_index].duration));
9202+ /* update ctts context */
9203+ sc->ctts_sample++;
9204+ if (sc->ctts_index < sc->ctts_count &&
9205+ sc->ctts_data[sc->ctts_index].count == sc->ctts_sample) {
9206+ sc->ctts_index++;
9207+ sc->ctts_sample = 0;
9208+ }
9209+ } else {
9210+ int64_t next_dts = (sc->current_sample < ffstream(st)->nb_index_entries) ?
9211+ ffstream(st)->index_entries[sc->current_sample].timestamp : st->duration;
9212+
9213+ if (next_dts >= pkt->dts)
9214+ pkt->duration = next_dts - pkt->dts;
9215+ pkt->pts = pkt->dts;
9216+ }
9217+
9218+ if (sc->sdtp_data && sc->current_sample <= sc->sdtp_count) {
9219+ uint8_t sample_flags = sc->sdtp_data[sc->current_sample - 1];
9220+ uint8_t sample_is_depended_on = (sample_flags >> 2) & 0x3;
9221+ pkt->flags |= sample_is_depended_on == MOV_SAMPLE_DEPENDENCY_NO ? AV_PKT_FLAG_DISPOSABLE : 0;
9222+ }
9223+ pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? AV_PKT_FLAG_KEY : 0;
9224+ pkt->pos = sample->pos;
9225+
9226+ /* Multiple stsd handling. */
9227+ if (sc->stsc_data) {
9228+ if (sc->stsc_data[sc->stsc_index].id > 0 &&
9229+ sc->stsc_data[sc->stsc_index].id - 1 < sc->stsd_count &&
9230+ sc->stsc_data[sc->stsc_index].id - 1 != sc->last_stsd_index) {
9231+ int ret = mov_change_extradata(st, pkt);
9232+ if (ret < 0)
9233+ return ret;
9234+ }
9235+
9236+ /* Update the stsc index for the next sample */
9237+ sc->stsc_sample++;
9238+ if (mov_stsc_index_valid(sc->stsc_index, sc->stsc_count) &&
9239+ mov_get_stsc_samples(sc, sc->stsc_index) == sc->stsc_sample) {
9240+ sc->stsc_index++;
9241+ sc->stsc_sample = 0;
9242+ }
9243+ }
9244+
9245+ return 0;
9246+}
9247+
91899248 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
91909249 {
91919250 MOVContext *mov = s->priv_data;
@@ -9270,56 +9329,12 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) · 78 unmodified lines
92709329 }
92719330 }
92729331
9273− pkt->stream_index = sc->ffindex;
9274− pkt->dts = sample->timestamp;
9275− if (sample->flags & AVINDEX_DISCARD_FRAME) {
9276− pkt->flags |= AV_PKT_FLAG_DISCARD;
9277− }
9278− if (sc->ctts_data && sc->ctts_index < sc->ctts_count) {
9279− pkt->pts = av_sat_add64(pkt->dts, av_sat_add64(sc->dts_shift, sc->ctts_data[sc->ctts_index].duration));
9280− /* update ctts context */
9281− sc->ctts_sample++;
9282− if (sc->ctts_index < sc->ctts_count &&
9283− sc->ctts_data[sc->ctts_index].count == sc->ctts_sample) {
9284− sc->ctts_index++;
9285− sc->ctts_sample = 0;
9286− }
9287− } else {
9288− int64_t next_dts = (sc->current_sample < ffstream(st)->nb_index_entries) ?
9289− ffstream(st)->index_entries[sc->current_sample].timestamp : st->duration;
9332+ ret = mov_finalize_packet(s, st, sample, current_index, pkt);
9333+ if (ret < 0)
9334+ return ret;
92909335
9291− if (next_dts >= pkt->dts)
9292− pkt->duration = next_dts - pkt->dts;
9293− pkt->pts = pkt->dts;
9294− }
92959336 if (st->discard == AVDISCARD_ALL)
92969337 goto retry;
9297− if (sc->sdtp_data && sc->current_sample <= sc->sdtp_count) {
9298− uint8_t sample_flags = sc->sdtp_data[sc->current_sample - 1];
9299− uint8_t sample_is_depended_on = (sample_flags >> 2) & 0x3;
9300− pkt->flags |= sample_is_depended_on == MOV_SAMPLE_DEPENDENCY_NO ? AV_PKT_FLAG_DISPOSABLE : 0;
9301− }
9302− pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? AV_PKT_FLAG_KEY : 0;
9303− pkt->pos = sample->pos;
9304−
9305− /* Multiple stsd handling. */
9306− if (sc->stsc_data) {
9307− if (sc->stsc_data[sc->stsc_index].id > 0 &&
9308− sc->stsc_data[sc->stsc_index].id - 1 < sc->stsd_count &&
9309− sc->stsc_data[sc->stsc_index].id - 1 != sc->last_stsd_index) {
9310− ret = mov_change_extradata(sc, pkt);
9311− if (ret < 0)
9312− return ret;
9313− }
9314−
9315− /* Update the stsc index for the next sample */
9316− sc->stsc_sample++;
9317− if (mov_stsc_index_valid(sc->stsc_index, sc->stsc_count) &&
9318− mov_get_stsc_samples(sc, sc->stsc_index) == sc->stsc_sample) {
9319− sc->stsc_index++;
9320− sc->stsc_sample = 0;
9321− }
9322− }
93239338
93249339 if (mov->aax_mode)
93259340 aax_filter(pkt->data, pkt->size, mov);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t