#define DEFAULT_PREBUFFER_SIZE 1024 * 16
SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load);
-SWITCH_MODULE_DEFINITION(mod_local_stream, mod_local_stream_load, NULL, NULL);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_local_stream_shutdown);
+SWITCH_MODULE_DEFINITION(mod_local_stream, mod_local_stream_load, mod_local_stream_shutdown, NULL);
+
struct local_stream_source;
} globals;
static int RUNNING = 1;
+static int THREADS = 0;
struct local_stream_context {
struct local_stream_source *source;
switch_size_t used;
int skip = 0;
+ switch_mutex_lock(globals.mutex);
+ THREADS++;
+ switch_mutex_unlock(globals.mutex);
+
if (!source->prebuf) {
source->prebuf = DEFAULT_PREBUFFER_SIZE;
}
switch_core_destroy_memory_pool(&source->pool);
+ switch_mutex_lock(globals.mutex);
+ THREADS--;
+ switch_mutex_unlock(globals.mutex);
+
return NULL;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_local_stream_shutdown)
{
RUNNING = 0;
- switch_yield(500000);
+ switch_event_unbind_callback(event_handler);
+
+ while(THREADS > 0) {
+ switch_yield(100000);
+ }
+
switch_core_hash_destroy(&globals.source_hash);
return SWITCH_STATUS_SUCCESS;
}