From 5ee38518da10bdca6ffbc428a35dad64f4a214aa Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Wed, 27 Jul 2022 15:33:40 -0500 Subject: [PATCH] Experimental: Adding some fsanitize flags, a new example exe, a mutex on FFmpegReader::Close, and some additional clean-up code on AddImage (when a previous image exists) --- examples/Example.cpp | 43 ++++--------------------------------------- src/CMakeLists.txt | 4 ++++ src/FFmpegReader.cpp | 8 +++++++- src/Frame.cpp | 4 ++++ 4 files changed, 19 insertions(+), 40 deletions(-) diff --git a/examples/Example.cpp b/examples/Example.cpp index a903c0af..eaaa3abc 100644 --- a/examples/Example.cpp +++ b/examples/Example.cpp @@ -23,50 +23,15 @@ using namespace openshot; int main(int argc, char* argv[]) { - // Types for storing time durations in whole and fractional milliseconds - using ms = std::chrono::milliseconds; - using s = std::chrono::seconds; - using double_ms = std::chrono::duration; - // FFmpeg Reader performance test - const auto total_1 = std::chrono::high_resolution_clock::now(); - FFmpegReader r9("/home/jonathan/Videos/sintel_trailer-1080p.mp4"); + FFmpegReader r9("/home/jonathan/Downloads/pts-test-files/broken-files/lady-talking-1.mp4"); r9.Open(); - for (long int frame = 1; frame <= 1000; frame++) + for (long int frame = 1; frame <= r9.info.video_length; frame++) { - const auto time1 = std::chrono::high_resolution_clock::now(); + std::cout << "Requesting Frame: #: " << frame << std::endl; std::shared_ptr f = r9.GetFrame(frame); - const auto time2 = std::chrono::high_resolution_clock::now(); - std::cout << "FFmpegReader: " << frame - << " (" << double_ms(time2 - time1).count() << " ms)\n"; } - const auto total_2 = std::chrono::high_resolution_clock::now(); - auto total_sec = std::chrono::duration_cast(total_2 - total_1); - std::cout << "FFmpegReader TOTAL: " << total_sec.count() << " ms\n"; r9.Close(); - - // Timeline Reader performance test - Timeline tm(r9.info); - Clip *c = new Clip(&r9); - tm.AddClip(c); - tm.Open(); - - const auto total_3 = std::chrono::high_resolution_clock::now(); - for (long int frame = 1; frame <= 1000; frame++) - { - const auto time1 = std::chrono::high_resolution_clock::now(); - std::shared_ptr f = tm.GetFrame(frame); - const auto time2 = std::chrono::high_resolution_clock::now(); - std::cout << "Timeline: " << frame - << " (" << double_ms(time2 - time1).count() << " ms)\n"; - } - const auto total_4 = std::chrono::high_resolution_clock::now(); - total_sec = std::chrono::duration_cast(total_4 - total_3); - std::cout << "Timeline TOTAL: " << total_sec.count() << " ms\n"; - tm.Close(); - - std::cout << "Completed successfully!\n"; - - return 0; + exit(0); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7043e746..66140b07 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,8 @@ if (POLICY CMP0057) endif() ############### PROFILING ################# +#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address") +#set (CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address") #set(PROFILER "/usr/lib/x86_64-linux-gnu/libprofiler.so.0") #set(PROFILER "/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4") @@ -177,6 +179,8 @@ if(NOT TARGET OpenShot::Audio) endif() target_link_libraries(openshot PUBLIC OpenShot::Audio) +#find_package(FindAsan) + ### ### ImageMagick ### diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index e29c3ec0..35c6bf5e 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -584,6 +584,8 @@ void FFmpegReader::Open() { void FFmpegReader::Close() { // Close all objects, if reader is 'open' if (is_open) { + const std::lock_guard lock(processingMutex); + // Mark as "closed" is_open = false; ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::Close (Start)"); @@ -1335,7 +1337,7 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) { // Determine required buffer size and allocate buffer const int bytes_per_pixel = 4; - int buffer_size = width * height * bytes_per_pixel; + int buffer_size = (width * height * bytes_per_pixel) + 128; buffer = new unsigned char[buffer_size](); // Copy picture data from one AVFrame (or AVPicture) to another one. @@ -2135,6 +2137,10 @@ void FFmpegReader::CheckWorkingFrames(int64_t requested_frame) { } } + + // Clear vector of frames + working_frames.clear(); + working_frames.shrink_to_fit(); } // Check for the correct frames per second (FPS) value by scanning the 1st few seconds of video packets. diff --git a/src/Frame.cpp b/src/Frame.cpp index b7e5e721..cc95673a 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -753,6 +753,10 @@ void Frame::AddImage( int new_width, int new_height, int bytes_per_pixel, QImage::Format type, const unsigned char *pixels_) { + if (has_image_data) { + // Delete the previous QImage + image.reset(); + } // Create new image object from pixel data auto new_image = std::make_shared(