CefAudioHandler, channel layout, and channel count

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CefAudioHandler, channel layout, and channel count

Postby robs » Wed Feb 28, 2024 4:15 pm

Hello,

I'm looking into the CefAudioHandler and have a question regarding the channel count.

I see `CefAudioHandler` has this method that feeds audio data:
Code: Select all
virtual void OnAudioStreamPacket(CefRefPtr<CefBrowser> browser,
                                   const float** data,
                                   int frames,
                                   int64 pts) = 0;


The `data` parameter is an array of pointers to buffers. Presumably the length of this array is determined by the channel_layout passed to the `params` here:
Code: Select all
  virtual void OnAudioStreamStarted(CefRefPtr<CefBrowser> browser,
                                    const CefAudioParameters& params,
                                    int channels) = 0;


So I'd expect that if `params.channel_layout` is `CEF_CHANNEL_LAYOUT_STEREO` then we can treat the `data` array to have a length of 2.

Perhaps in practice `CEF_CHANNEL_LAYOUT_STEREO` will be sent most of the time, but is there a safe way to get the length of the `data` array without needing to write a function that understand how many channels are expected for each of the layout enum values? There are likely many cases where we just want the data and don't necessarily need to know the intention of each of the channels.

There is also, for example, this channel layout:
Code: Select all
  /// Channels are not explicitly mapped to speakers.
  CEF_CHANNEL_LAYOUT_DISCRETE = 29,

for which it is not obvious how to get the length of the `data` array / number of channels.

Perhaps I'm missing something, or maybe this is really a feature request for an additional API that would provide the number of channels. Thanks for any info!

Best,
Rob
robs
Mentor
 
Posts: 70
Joined: Wed Jun 05, 2013 2:22 pm

Re: CefAudioHandler, channel layout, and channel count

Postby robs » Wed Feb 28, 2024 4:48 pm

Okay, I just spotted what I was missing.

Code: Select all
  virtual void OnAudioStreamStarted(CefRefPtr<CefBrowser> browser,
                                    const CefAudioParameters& params,
                                    int channels) = 0;


Somehow I missed that this call provides the number of channels.

Sorry for the noise! Hopefully this post helps someone else in the future.

Best,
Rob
robs
Mentor
 
Posts: 70
Joined: Wed Jun 05, 2013 2:22 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 213 guests

cron