MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / Close

Method Close

src/FFmpegReader.cpp:748–839  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

746}
747
748void FFmpegReader::Close() {
749 // Close all objects, if reader is 'open'
750 if (is_open) {
751 // Prevent async calls to the following code
752 const std::lock_guard<std::recursive_mutex> lock(getFrameMutex);
753
754 // Mark as "closed"
755 is_open = false;
756
757 // Keep track of most recent packet
758 AVPacket *recent_packet = packet;
759
760 // Drain any packets from the decoder
761 packet = NULL;
762 int attempts = 0;
763 int max_attempts = 128;
764 while (packet_status.packets_decoded() < packet_status.packets_read() && attempts < max_attempts) {
765 ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::Close (Drain decoder loop)",
766 "packets_read", packet_status.packets_read(),
767 "packets_decoded", packet_status.packets_decoded(),
768 "attempts", attempts);
769 if (packet_status.video_decoded < packet_status.video_read) {
770 ProcessVideoPacket(info.video_length);
771 }
772 if (packet_status.audio_decoded < packet_status.audio_read) {
773 ProcessAudioPacket(info.video_length);
774 }
775 attempts++;
776 }
777
778 // Remove packet
779 if (recent_packet) {
780 RemoveAVPacket(recent_packet);
781 }
782
783 // Close the video codec
784 if (info.has_video) {
785 if(avcodec_is_open(pCodecCtx)) {
786 avcodec_flush_buffers(pCodecCtx);
787 }
788 AV_FREE_CONTEXT(pCodecCtx);
789#if USE_HW_ACCEL
790 if (hw_de_on) {
791 if (hw_device_ctx) {
792 av_buffer_unref(&hw_device_ctx);
793 hw_device_ctx = NULL;
794 }
795 }
796#endif // USE_HW_ACCEL
797 if (img_convert_ctx) {
798 sws_freeContext(img_convert_ctx);
799 img_convert_ctx = nullptr;
800 }
801 if (pFrameRGB_cached) {
802 AV_FREE_FRAME(&pFrameRGB_cached);
803 }
804 }
805

Callers

nothing calls this directly

Calls 5

packets_decodedMethod · 0.80
packets_readMethod · 0.80
AppendDebugMethodMethod · 0.80
resetMethod · 0.80
ClearMethod · 0.45

Tested by

no test coverage detected