Skip to content

Commit

Permalink
Merge pull request #926 from jeffski/qt-readers-sample-count
Browse files Browse the repository at this point in the history
Add GetSamplesPerFrame to QtTextReader and QtHtmlReader
  • Loading branch information
jonoomph authored Jun 2, 2023
2 parents a6bcd42 + 3b0f1d2 commit b1104d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/QtHtmlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,12 +145,17 @@ void QtHtmlReader::Close()
// Get an openshot::Frame object for a specific frame number of this reader.
std::shared_ptr<Frame> 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<std::recursive_mutex> 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<Frame>(
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);
Expand All @@ -159,12 +165,11 @@ std::shared_ptr<Frame> QtHtmlReader::GetFrame(int64_t requested_frame)
} else {
// return empty frame
auto image_frame = std::make_shared<Frame>(
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
Expand Down
11 changes: 8 additions & 3 deletions src/QtTextReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,12 +163,17 @@ void QtTextReader::Close()
// Get an openshot::Frame object for a specific frame number of this reader.
std::shared_ptr<Frame> 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<std::recursive_mutex> 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<Frame>(
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);
Expand All @@ -176,12 +182,11 @@ std::shared_ptr<Frame> QtTextReader::GetFrame(int64_t requested_frame)
return image_frame;
} else {
// return empty frame
auto image_frame = std::make_shared<Frame>(1, 640, 480, background_color, 0, 2);
auto image_frame = std::make_shared<Frame>(1, 640, 480, background_color, sample_count, info.channels);

// return frame object
return image_frame;
}

}

// Generate JSON string of this object
Expand Down

0 comments on commit b1104d8

Please sign in to comment.