From 3b0f1d29b5ff52b179a18fefee7aeda71626b110 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Sun, 7 May 2023 16:35:26 +1000 Subject: [PATCH] Add GetSamplesPerFrame to QtTextReader and QtHtmlReader --- src/QtHtmlReader.cpp | 11 ++++++++--- src/QtTextReader.cpp | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 8d07f682..8dfb8f8f 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -96,6 +96,7 @@ void QtHtmlReader::Open() // Update image properties info.has_audio = false; info.has_video = true; + info.has_single_image = true; info.file_size = 0; info.vcodec = "QImage"; info.width = width; @@ -144,12 +145,17 @@ void QtHtmlReader::Close() // Get an openshot::Frame object for a specific frame number of this reader. std::shared_ptr QtHtmlReader::GetFrame(int64_t requested_frame) { + // Create a scoped lock, allowing only a single thread to run the following code at one time + const std::lock_guard lock(getFrameMutex); + + auto sample_count = Frame::GetSamplesPerFrame(requested_frame, info.fps, info.sample_rate, info.channels); + if (image) { // Create or get frame object auto image_frame = std::make_shared( requested_frame, image->size().width(), image->size().height(), - background_color, 0, 2); + background_color, sample_count, info.channels); // Add Image data to frame image_frame->AddImage(image); @@ -159,12 +165,11 @@ std::shared_ptr QtHtmlReader::GetFrame(int64_t requested_frame) } else { // return empty frame auto image_frame = std::make_shared( - 1, 640, 480, background_color, 0, 2); + 1, 640, 480, background_color, sample_count, info.channels); // return frame object return image_frame; } - } // Generate JSON string of this object diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index a5c9b0dd..58e2d517 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -114,6 +114,7 @@ void QtTextReader::Open() // Update image properties info.has_audio = false; info.has_video = true; + info.has_single_image = true; info.file_size = 0; info.vcodec = "QImage"; info.width = width; @@ -162,12 +163,17 @@ void QtTextReader::Close() // Get an openshot::Frame object for a specific frame number of this reader. std::shared_ptr QtTextReader::GetFrame(int64_t requested_frame) { + // Create a scoped lock, allowing only a single thread to run the following code at one time + const std::lock_guard lock(getFrameMutex); + + auto sample_count = Frame::GetSamplesPerFrame(requested_frame, info.fps, info.sample_rate, info.channels); + if (image) { // Create or get frame object auto image_frame = std::make_shared( requested_frame, image->size().width(), image->size().height(), - background_color, 0, 2); + background_color, sample_count, info.channels); // Add Image data to frame image_frame->AddImage(image); @@ -176,12 +182,11 @@ std::shared_ptr QtTextReader::GetFrame(int64_t requested_frame) return image_frame; } else { // return empty frame - auto image_frame = std::make_shared(1, 640, 480, background_color, 0, 2); + auto image_frame = std::make_shared(1, 640, 480, background_color, sample_count, info.channels); // return frame object return image_frame; } - } // Generate JSON string of this object