| 765 | } |
| 766 | |
| 767 | static int imf_read_packet(AVFormatContext *s, AVPacket *pkt) |
| 768 | { |
| 769 | IMFVirtualTrackResourcePlaybackCtx *resource = NULL; |
| 770 | int ret = 0; |
| 771 | IMFVirtualTrackPlaybackCtx *track; |
| 772 | int64_t delta_ts; |
| 773 | AVStream *st; |
| 774 | AVRational next_timestamp; |
| 775 | |
| 776 | track = get_next_track_with_minimum_timestamp(s); |
| 777 | |
| 778 | if (!track) { |
| 779 | av_log(s, AV_LOG_ERROR, "No track found for playback\n"); |
| 780 | return AVERROR_INVALIDDATA; |
| 781 | } |
| 782 | |
| 783 | av_log(s, AV_LOG_DEBUG, "Found track %d to read at timestamp %lf\n", |
| 784 | track->index, av_q2d(track->current_timestamp)); |
| 785 | |
| 786 | ret = get_resource_context_for_timestamp(s, track, &resource); |
| 787 | if (ret) |
| 788 | return ret; |
| 789 | |
| 790 | ret = av_read_frame(resource->ctx, pkt); |
| 791 | if (ret) |
| 792 | return ret; |
| 793 | |
| 794 | av_log(s, AV_LOG_DEBUG, "Got packet: pts=%" PRId64 ", dts=%" PRId64 |
| 795 | ", duration=%" PRId64 ", stream_index=%d, pos=%" PRId64 |
| 796 | ", time_base=" AVRATIONAL_FORMAT "\n", pkt->pts, pkt->dts, pkt->duration, |
| 797 | pkt->stream_index, pkt->pos, AVRATIONAL_ARG(pkt->time_base)); |
| 798 | |
| 799 | /* IMF resources contain only one stream */ |
| 800 | |
| 801 | if (pkt->stream_index != 0) |
| 802 | return AVERROR_INVALIDDATA; |
| 803 | st = resource->ctx->streams[0]; |
| 804 | |
| 805 | pkt->stream_index = track->index; |
| 806 | |
| 807 | /* adjust the packet PTS and DTS based on the temporal position of the resource within the timeline */ |
| 808 | |
| 809 | ret = imf_time_to_ts(&delta_ts, resource->ts_offset, st->time_base); |
| 810 | |
| 811 | if (!ret) { |
| 812 | if (pkt->pts != AV_NOPTS_VALUE) |
| 813 | pkt->pts += delta_ts; |
| 814 | if (pkt->dts != AV_NOPTS_VALUE) |
| 815 | pkt->dts += delta_ts; |
| 816 | } else { |
| 817 | av_log(s, AV_LOG_WARNING, "Incoherent time stamp " AVRATIONAL_FORMAT |
| 818 | " for time base " AVRATIONAL_FORMAT, |
| 819 | AVRATIONAL_ARG(resource->ts_offset), |
| 820 | AVRATIONAL_ARG(pkt->time_base)); |
| 821 | } |
| 822 | |
| 823 | /* advance the track timestamp by the packet duration */ |
| 824 |
nothing calls this directly
no test coverage detected