Skip to content

Commit

Permalink
wip: rework frame flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jun 5, 2024
1 parent f0d5c9b commit 3e01be4
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions src/modules/html/producer/html_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ struct presentation_frame
bool has_video = false;
bool has_audio = false;

explicit presentation_frame()
explicit presentation_frame(core::draw_frame video = {})
{
if (video) {
frame = std::move(video);
has_video = true;
}
}

presentation_frame(presentation_frame&& other)
Expand Down Expand Up @@ -255,12 +259,13 @@ class html_client
{
if (!try_pop(field)) {
graph_->set_tag(diagnostics::tag_severity::SILENT, "late-frame");
return core::draw_frame::still(last_frame_);
} else {
return last_frame_;
}

return last_frame_;
}

core::draw_frame last_frame() const { return last_frame_; }
core::draw_frame last_frame() const { return core::draw_frame::still(last_frame_); }

bool is_ready() const
{
Expand Down Expand Up @@ -365,10 +370,7 @@ class html_client
core::draw_frame new_frame = core::draw_frame(std::move(frame));
last_generated_frame_ = new_frame;

presentation_frame wrapped_frame;
wrapped_frame.add_video(std::move(new_frame));

frames_.push(std::move(wrapped_frame));
frames_.push(presentation_frame(std::move(new_frame)));
while (frames_.size() > 4) {
frames_.pop();
graph_->set_tag(diagnostics::tag_severity::WARNING, "dropped-frame");
Expand Down Expand Up @@ -483,31 +485,26 @@ class html_client
{
if (!audioResampler_) return;

auto audio = audioResampler_->convert(samples, reinterpret_cast<const void**>(data));
auto audio_frame = core::mutable_frame(this, {}, std::move(audio), core::pixel_format_desc());

{
std::lock_guard<std::mutex> lock(frames_mutex_);
if (frames_.empty()) {
presentation_frame wrapped_frame;
auto audio = audioResampler_->convert(samples, reinterpret_cast<const void**>(data));
auto audio_frame = core::mutable_frame(this, {}, std::move(audio), core::pixel_format_desc());

{
std::lock_guard<std::mutex> lock(frames_mutex_);
if (frames_.empty()) {
presentation_frame wrapped_frame(last_generated_frame_);
wrapped_frame.add_audio(std::move(audio_frame));

frames_.push(std::move(wrapped_frame));
} else {
if (!frames_.back().has_audio) {
frames_.back().add_audio(std::move(audio_frame));
} else {
presentation_frame wrapped_frame(last_generated_frame_);
wrapped_frame.add_audio(std::move(audio_frame));
if (last_generated_frame_) {
wrapped_frame.add_video(last_generated_frame_);
}

frames_.push(std::move(wrapped_frame));
} else {
if (!frames_.back().has_audio) {
frames_.back().add_audio(std::move(audio_frame));
} else {
presentation_frame wrapped_frame;
wrapped_frame.add_audio(std::move(audio_frame));
frames_.push(std::move(wrapped_frame));
}
}

}
}
}
void OnAudioStreamStopped(CefRefPtr<CefBrowser> browser) override { audioResampler_ = nullptr; }
void OnAudioStreamError(CefRefPtr<CefBrowser> browser, const CefString& message) override
Expand Down

0 comments on commit 3e01be4

Please sign in to comment.