Audio Handler callbacks not called while using capi

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.

Audio Handler callbacks not called while using capi

Postby aleitner » Fri Jul 28, 2023 12:11 pm

I am currently working with the CEF capi and I am struggling with setting up the Audio Handler. Despite everything seeming correctly configured in my client, none of my Audio Handler callbacks are being called, so I'm unsure how to resolve this issue.

Here's a reduced version of my client implementation:

Code: Select all
//... Other code and includes here...

static cef_audio_handler_t* get_audio_handler(cef_client_t* self) {
    custom_client_t* custom_client = (custom_client_t*)self;
    return &custom_client->audio_handler->base;
}

custom_client_t *create_client() {
    custom_client_t *custom_client = (custom_client_t *)calloc(1, sizeof(custom_client_t));

    //... Assignments to other handlers here.

    custom_audio_handler_t* audio_handler = create_custom_audio_handler();
    custom_client->audio_handler = audio_handler;
    client->get_audio_handler = get_audio_handler;   

    return custom_client;
}


And here is the custom audio handler code

Code: Select all
void on_audio_stream_packet(struct _cef_audio_handler_t* self,
        struct _cef_browser_t* browser,
        const float** data,
        int frames,
        int64 pts) {
    fprintf(stderr, "Mmm\n");

void on_audio_stream_started(struct _cef_audio_handler_t* self,
        struct _cef_browser_t* browser,
        const cef_audio_parameters_t* params,
        int channels) {
    fprintf(stderr, "Hi\n");
}

void on_audio_stream_stopped(struct _cef_audio_handler_t* self,
        struct _cef_browser_t* browser) {
    fprintf(stderr, "Bye\n");
}

void on_audio_stream_error(struct _cef_audio_handler_t* self,
        struct _cef_browser_t* browser,
        const cef_string_t* message) {
    fprintf(stderr, "oops\n");
}

custom_audio_handler_t* create_custom_audio_handler() {
    custom_audio_handler_t* handler =
        (custom_audio_handler_t*)calloc(1, sizeof(custom_audio_handler_t));
   
    // Set the size of the base struct and setup the method handlers
    handler->base.base.size = sizeof(cef_audio_handler_t);
    handler->base.on_audio_stream_packet = on_audio_stream_packet;
    handler->base.on_audio_stream_started = on_audio_stream_started;
    handler->base.on_audio_stream_stopped = on_audio_stream_stopped;
    handler->base.on_audio_stream_error = on_audio_stream_error;
   
    fprintf(stderr, "Audio Handler created...\n");

    return handler;
}


I have ensured that the create_custom_audio_handler function is called and the custom_audio_handler_t is appropriately initialized. Despite this, when I play an audio source in the handled CEF browser, none of my callback functions (on_audio_stream_packet, on_audio_stream_started, on_audio_stream_stopped, or on_audio_stream_error) are being called.

Does anyone have any ideas why these callbacks are not being called, or how I can debug them effectively? Any help would be greatly appreciated.
aleitner
Techie
 
Posts: 49
Joined: Fri Jun 16, 2023 12:05 pm

Re: Audio Handler callbacks not called while using capi

Postby aleitner » Mon Jul 31, 2023 3:29 pm

I found the solution. I needed to also set up an additional audio handler

Code: Select all
int get_audio_parameters(struct _cef_audio_handler_t* self,
                         struct _cef_browser_t* browser,
                         cef_audio_parameters_t* params) {
    /* Return value is expected to be a boolean (1 for success and 0 for failure) */
    return 1;
}


And then set this when initializing my handlers

Code: Select all
handler->base.get_audio_parameters = get_audio_parameters;
aleitner
Techie
 
Posts: 49
Joined: Fri Jun 16, 2023 12:05 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 210 guests