| 781 | } |
| 782 | |
| 783 | void FramesDecoderGpu::SendLastPacket(bool flush) { |
| 784 | LOG_LINE << "SendLastPacket: flush=" << flush << " piped_pts_size=" << piped_pts_.size() |
| 785 | << " buffered_frames=" << NumBufferedFrames() << " next_frame_idx=" << next_frame_idx_ |
| 786 | << std::endl; |
| 787 | |
| 788 | flush_ = flush; |
| 789 | CUVIDSOURCEDATAPACKET *packet = &nvdecode_state_->packet; |
| 790 | memset(packet, 0, sizeof(CUVIDSOURCEDATAPACKET)); |
| 791 | packet->payload = nullptr; |
| 792 | packet->payload_size = 0; |
| 793 | packet->flags = CUVID_PKT_ENDOFSTREAM; |
| 794 | |
| 795 | // Send end of stream and process any remaining frames |
| 796 | CUDA_CALL(cuvidParseVideoData(nvdecode_state_->parser, packet)); |
| 797 | |
| 798 | if (!flush) { |
| 799 | // Process any remaining buffered frames in order |
| 800 | bool found_frame; |
| 801 | do { |
| 802 | found_frame = false; |
| 803 | for (auto &frame : frame_buffer_) { |
| 804 | if (frame.pts_ != -1 && HasIndex() && frame.pts_ == index_[next_frame_idx_].pts) { |
| 805 | LOG_LINE << "Processing remaining buffered frame pts=" << frame.pts_ << " for index " |
| 806 | << next_frame_idx_ << std::endl; |
| 807 | frame.pts_ = -1; |
| 808 | ++next_frame_idx_; |
| 809 | found_frame = true; |
| 810 | break; |
| 811 | } |
| 812 | } |
| 813 | } while (found_frame && next_frame_idx_ < NumFrames()); |
| 814 | } |
| 815 | |
| 816 | flush_ = false; |
| 817 | |
| 818 | if (flush) { |
| 819 | LOG_LINE << "Flushing decoder state" << std::endl; |
| 820 | // Clear frames buffer |
| 821 | for (size_t i = 0; i < frame_buffer_.size(); ++i) { |
| 822 | frame_buffer_[i].pts_ = -1; |
| 823 | } |
| 824 | |
| 825 | // Clear piped pts |
| 826 | while (piped_pts_.size() > 0) { |
| 827 | piped_pts_.pop(); |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | BufferedFrame& FramesDecoderGpu::FindEmptySlot() { |
| 833 | for (auto &frame : frame_buffer_) { |