I initialize the audio handler when the application starts, but when I pause audio the first time, the reference counter decrements and frees the audio handler. The audio handler is never initialized again and the application crashes. Is there some sort of initializer method I should be setting so that the audio handler gets initialized again when we need a new one?
get_audio_handler
- Code: Select all
static cef_audio_handler_t* get_audio_handler(cef_client_t* self) {
http_cef_client_t* custom_client = (http_cef_client_t*)self;
return &custom_client->audio_handler->base;
}
Client Initializer
- Code: Select all
http_cef_client_t* http_cef_client_init(shm_memory* shm) {
http_cef_client_t* custom_client = (http_cef_client_t *)base_calloc(1, sizeof(http_cef_client_t));
/* Initialize base structure */
cef_client_t* client = &custom_client->base;
client->base.size = sizeof(cef_client_t);
client->base.add_ref = add_ref_generic;
client->base.release = release_generic;
client->base.has_one_ref = has_one_ref_generic;
http_cef_audio_handler_t* audio_handler = http_cef_audio_handler_init(shm);
custom_client->audio_handler = audio_handler;
client->get_audio_handler = get_audio_handler;
return custom_client;
}
Audio Handler Initializer
- Code: Select all
http_cef_audio_handler_t* http_cef_audio_handler_init(shm_memory* shm) {
http_cef_audio_handler_t* handler =
(http_cef_audio_handler_t*)calloc(1, sizeof(http_cef_audio_handler_t));
/* Set the size of the base struct */
handler->base.base.size = sizeof(cef_audio_handler_t);
handler->base.base.add_ref = add_ref_generic;
handler->base.base.release = release_generic;
handler->base.base.has_one_ref = has_one_ref_generic;
/* Setup the method handlers */
handler->base.get_audio_parameters = get_audio_parameters;
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;
/* Assign the shared memory object to the handler */
handler->shm = shm;
return handler;
}