Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CEF audio #16

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft

CEF audio #16

wants to merge 36 commits into from

Conversation

deadbeef84
Copy link

No description provided.


void set_audio(caspar::array<int32_t>&& data, int64_t pts)
{
frame.set_audio_data(std::move(data));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
frame.set_audio_data(std::move(data));
frame.audio_data() = std::move(data);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously! Good catch 👍 I'm still not 100% used to the rvalue special functions. That just shows how long it's been since i actually coded c++ on a regular basis before this.

@deadbeef84 deadbeef84 marked this pull request as draft November 20, 2023 12:49
@deadbeef84
Copy link
Author

@niklaspandersson this is waiting for a fix of the initial glitching samples

@deadbeef84 deadbeef84 changed the title Add CefAudioHandler stubs to html_client CEF audio Nov 20, 2023
Julusian added a commit to nrkno/sofie-casparcg-server that referenced this pull request Jan 5, 2024
@Julusian
Copy link

Julusian commented Jan 5, 2024

Thanks for starting on this, this inspired me to take a look at this, and I have reworked this a bit in my own prototype implementation CasparCG#1517.
I have a couple of thoughts on the implementation here


I have a theory on the glitching audio, in some cases inside these bits of code https://github.com/nxtedition/casparcg/blob/cef-audio/src/modules/html/producer/html_producer.cpp#L236-L247 you will need to wrap the returned frame with core::draw_frame::still(...), so mute the audio when a frame is being repeated.

I encountered a similar thing, when pausing/resuming a low framerate video, fixed by adding those calls in https://github.com/CasparCG/server/blob/feat/cef-audio/src/modules/html/producer/html_producer.cpp#L263-L273

The code around here has diverged a bit by now, so may take some thought to translate across


I don't think this implementation is very efficient on memory copying.

By moving the mutable_frame to draw_frame to try_pop

result = (frames_.front().is_empty()) ? core::draw_frame::empty()
: core::draw_frame(std::move(frames_.front().frame));
, that means that the copy from gl buffer to texture is being delayed until try_pop. This delays the copy to being done just before the mixer wants to composite with it, rather than 2-4 frames in advance.

Additionally, I count that for each frame CEF paints, you are copying into a gpu buffer (as before) and then copying from that gpu buffer into last_video_frame_.
Each time a frame is repeated with new audio, you are copying the cached buffer into a new gpu buffer.

I would suggest that instead of this, it would be more efficient to use the layering nature of draw_frame. so that each draw frame returned from the producer contains up to two other draw_frames, one which contains just audio, and one which contains just video. That means it will be kept at one memcpy per video frame produced by cef.

deadbeef84 added a commit that referenced this pull request May 24, 2024
commit 7e2f134
Author: Julian Waller <[email protected]>
Date:   Fri Jan 5 16:36:53 2024 +0000

    chore: format

commit 91e9954
Author: Julian Waller <[email protected]>
Date:   Fri Jan 5 16:34:23 2024 +0000

    wip: rework frame flow

commit 0ce2bfd
Author: Julian Waller <[email protected]>
Date:   Fri Jan 5 16:11:02 2024 +0000

    wip: inspired by #16
Julusian added a commit to CasparCG/server that referenced this pull request Jun 5, 2024
oscarwcl pushed a commit to oscarwcl/casparcg-server that referenced this pull request Sep 27, 2024
deadbeef84 added a commit that referenced this pull request Oct 14, 2024
commit 7e2f134
Author: Julian Waller <[email protected]>
Date:   Fri Jan 5 16:36:53 2024 +0000

    chore: format

commit 91e9954
Author: Julian Waller <[email protected]>
Date:   Fri Jan 5 16:34:23 2024 +0000

    wip: rework frame flow

commit 0ce2bfd
Author: Julian Waller <[email protected]>
Date:   Fri Jan 5 16:11:02 2024 +0000

    wip: inspired by #16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants