Unified · Split
| @@ -9142,8 +9142,9 @@ static int mov_switch_root(AVFormatContext *s, int64_t target, int index) · 9141 unmodified lines | |||
| 9142 | return 1; | 9142 | return 1; |
| 9143 | } | 9143 | } |
| 9144 | 9144 | ||
| 9145 | static int mov_change_extradata(MOVStreamContext *sc, AVPacket *pkt) | 9145 | static int mov_change_extradata(AVStream *st, AVPacket *pkt) |
| 9146 | { | 9146 | { |
| 9147 | MOVStreamContext *sc = st->priv_data; | ||
| 9147 | uint8_t *side, *extradata; | 9148 | uint8_t *side, *extradata; |
| 9148 | int extradata_size; | 9149 | int extradata_size; |
| 9149 | 9150 | ||
| @@ -9153,7 +9154,7 @@ static int mov_change_extradata(MOVStreamContext *sc, AVPacket *pkt) · 3 unmodified lines | |||
| 9153 | /* Notify the decoder that extradata changed. */ | 9154 | /* Notify the decoder that extradata changed. */ |
| 9154 | extradata_size = sc->extradata_size[sc->last_stsd_index]; | 9155 | extradata_size = sc->extradata_size[sc->last_stsd_index]; |
| 9155 | extradata = sc->extradata[sc->last_stsd_index]; | 9156 | extradata = sc->extradata[sc->last_stsd_index]; |
| 9156 | if (extradata_size > 0 && extradata) { | 9157 | if (st->discard != AVDISCARD_ALL && extradata_size > 0 && extradata) { |
| 9157 | side = av_packet_new_side_data(pkt, | 9158 | side = av_packet_new_side_data(pkt, |
| 9158 | AV_PKT_DATA_NEW_EXTRADATA, | 9159 | AV_PKT_DATA_NEW_EXTRADATA, |
| 9159 | extradata_size); | 9160 | extradata_size); |
| @@ -9186,6 +9187,64 @@ static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size) · 26 unmodified lines | |||
| 9186 | return 0; | 9187 | return 0; |
| 9187 | } | 9188 | } |
| 9188 | 9189 | ||
| 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 | |||
| 9189 | static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) | 9248 | static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) |
| 9190 | { | 9249 | { |
| 9191 | MOVContext *mov = s->priv_data; | 9250 | MOVContext *mov = s->priv_data; |
| @@ -9270,56 +9329,12 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) · 78 unmodified lines | |||
| 9270 | } | 9329 | } |
| 9271 | } | 9330 | } |
| 9272 | 9331 | ||
| 9273 | pkt->stream_index = sc->ffindex; | 9332 | ret = mov_finalize_packet(s, st, sample, current_index, pkt); |
| 9274 | pkt->dts = sample->timestamp; | 9333 | if (ret < 0) |
| 9275 | if (sample->flags & AVINDEX_DISCARD_FRAME) { | 9334 | return ret; |
| 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; | ||
| 9290 | 9335 | ||
| 9291 | if (next_dts >= pkt->dts) | ||
| 9292 | pkt->duration = next_dts - pkt->dts; | ||
| 9293 | pkt->pts = pkt->dts; | ||
| 9294 | } | ||
| 9295 | if (st->discard == AVDISCARD_ALL) | 9336 | if (st->discard == AVDISCARD_ALL) |
| 9296 | goto retry; | 9337 | 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 | } | ||
| 9323 | 9338 | ||
| 9324 | if (mov->aax_mode) | 9339 | if (mov->aax_mode) |
| 9325 | aax_filter(pkt->data, pkt->size, mov); | 9340 | aax_filter(pkt->data, pkt->size, mov); |