Unified · Split
| @@ -443,12 +443,13 @@ void ff_format_io_close(AVFormatContext *s, AVIOContext **pb); · 442 unmodified lines | ||
| 443 | 443 | |
| 444 | 444 | /** |
| 445 | 445 | * Find the next packet in the interleaving queue for the given stream. |
| 446 | − * The packet is not removed from the interleaving queue, but only | |
| 447 | − * a pointer to it is returned. | |
| 446 | + * The pkt parameter is filled in with the queued packet, including | |
| 447 | + * references to the data (which the caller is not allowed to keep or | |
| 448 | + * modify). | |
| 448 | 449 | * |
| 449 | − * @return a pointer to the next packet, or NULL if no packet is queued | |
| 450 | − * for this stream. | |
| 450 | + * @return 0 if a packet was found, a negative value if no packet was found | |
| 451 | 451 | */ |
| 452 | −const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream); | |
| 452 | +int ff_interleaved_peek(AVFormatContext *s, int stream, | |
| 453 | + AVPacket *pkt, int add_offset); | |
| 453 | 454 | |
| 454 | 455 | #endif /* AVFORMAT_INTERNAL_H */ |
| @@ -3262,13 +3262,13 @@ static int mov_flush_fragment(AVFormatContext *s, int force) · 3261 unmodified lines | ||
| 3262 | 3262 | for (i = 0; i < s->nb_streams; i++) { |
| 3263 | 3263 | MOVTrack *track = &mov->tracks[i]; |
| 3264 | 3264 | if (!track->end_reliable) { |
| 3265 | − const AVPacket *next = ff_interleaved_peek(s, i); | |
| 3266 | − if (next) { | |
| 3267 | − track->track_duration = next->dts - track->start_dts; | |
| 3268 | − if (next->pts != AV_NOPTS_VALUE) | |
| 3269 | − track->end_pts = next->pts; | |
| 3265 | + AVPacket pkt; | |
| 3266 | + if (!ff_interleaved_peek(s, i, &pkt, 1)) { | |
| 3267 | + track->track_duration = pkt.dts - track->start_dts; | |
| 3268 | + if (pkt.pts != AV_NOPTS_VALUE) | |
| 3269 | + track->end_pts = pkt.pts; | |
| 3270 | 3270 | else |
| 3271 | − track->end_pts = next->dts; | |
| 3271 | + track->end_pts = pkt.dts; | |
| 3272 | 3272 | } |
| 3273 | 3273 | } |
| 3274 | 3274 | } |
| @@ -357,6 +357,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 356 unmodified lines | ||
| 357 | 357 | static int write_packet(AVFormatContext *s, AVPacket *pkt) |
| 358 | 358 | { |
| 359 | 359 | int ret; |
| 360 | + // If the timestamp offsetting below is adjusted, adjust | |
| 361 | + // ff_interleaved_peek similarly. | |
| 360 | 362 | if (s->avoid_negative_ts > 0) { |
| 361 | 363 | AVRational time_base = s->streams[pkt->stream_index]->time_base; |
| 362 | 364 | int64_t offset = 0; |
| @@ -614,15 +616,27 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, · 251 unmodified lines | ||
| 614 | 616 | } |
| 615 | 617 | } |
| 616 | 618 | |
| 617 | −const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream) | |
| 619 | +int ff_interleaved_peek(AVFormatContext *s, int stream, | |
| 620 | + AVPacket *pkt, int add_offset) | |
| 618 | 621 | { |
| 619 | 622 | AVPacketList *pktl = s->internal->packet_buffer; |
| 620 | 623 | while (pktl) { |
| 621 | − if (pktl->pkt.stream_index == stream) | |
| 622 | − return &pktl->pkt; | |
| 624 | + if (pktl->pkt.stream_index == stream) { | |
| 625 | + *pkt = pktl->pkt; | |
| 626 | + if (add_offset && s->internal->offset != AV_NOPTS_VALUE) { | |
| 627 | + int64_t offset = av_rescale_q(s->internal->offset, | |
| 628 | + s->internal->offset_timebase, | |
| 629 | + s->streams[stream]->time_base); | |
| 630 | + if (pkt->dts != AV_NOPTS_VALUE) | |
| 631 | + pkt->dts += offset; | |
| 632 | + if (pkt->pts != AV_NOPTS_VALUE) | |
| 633 | + pkt->pts += offset; | |
| 634 | + } | |
| 635 | + return 0; | |
| 636 | + } | |
| 623 | 637 | pktl = pktl->next; |
| 624 | 638 | } |
| 625 | − return NULL; | |
| 639 | + return AVERROR(ENOENT); | |
| 626 | 640 | } |
| 627 | 641 | |
| 628 | 642 | /** |