| 741 | } |
| 742 | |
| 743 | void FFMS_VideoSource::DecodeNextFrame(int64_t &AStartTime, int64_t &Pos) { |
| 744 | AStartTime = -1; |
| 745 | |
| 746 | if (HasPendingDelayedFrames()) |
| 747 | return; |
| 748 | |
| 749 | AVPacket *Packet = av_packet_alloc(); |
| 750 | if (!Packet) |
| 751 | throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_ALLOCATION_FAILED, |
| 752 | "Could not allocate packet."); |
| 753 | |
| 754 | int ret; |
| 755 | if (ResendPacket) { |
| 756 | // If we have a packet previously stashed due to a full input queue, |
| 757 | // send it again. |
| 758 | ret = 0; |
| 759 | av_packet_ref(Packet, StashedPacket); |
| 760 | av_packet_unref(StashedPacket); |
| 761 | } else { |
| 762 | ret = av_read_frame(FormatContext, Packet); |
| 763 | } |
| 764 | while (ret >= 0) { |
| 765 | if (Packet->stream_index != VideoTrack) { |
| 766 | av_packet_unref(Packet); |
| 767 | ret = av_read_frame(FormatContext, Packet); |
| 768 | continue; |
| 769 | } |
| 770 | |
| 771 | if (AStartTime < 0) |
| 772 | AStartTime = Frames.UseDTS ? Packet->dts : Packet->pts; |
| 773 | |
| 774 | if (Pos < 0) |
| 775 | Pos = Packet->pos; |
| 776 | |
| 777 | bool FrameFinished = DecodePacket(Packet); |
| 778 | if (ResendPacket) |
| 779 | av_packet_ref(StashedPacket, Packet); |
| 780 | av_packet_unref(Packet); |
| 781 | if (FrameFinished) { |
| 782 | av_packet_free(&Packet); |
| 783 | return; |
| 784 | } |
| 785 | |
| 786 | if (ResendPacket) { |
| 787 | ret = 0; |
| 788 | av_packet_ref(Packet, StashedPacket); |
| 789 | av_packet_unref(StashedPacket); |
| 790 | } else { |
| 791 | ret = av_read_frame(FormatContext, Packet); |
| 792 | } |
| 793 | } |
| 794 | if (IsIOError(ret)) |
| 795 | throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_FILE_READ, |
| 796 | "Failed to read packet: " + AVErrorToString(ret)); |
| 797 | |
| 798 | // Flush final frames |
| 799 | DecodePacket(Packet); |
| 800 | av_packet_free(&Packet); |
nothing calls this directly
no test coverage detected