uint32_t rate = PREFERRED_RATE;
char *npath ;
int devNumber;
-
-
-
-
+ int tmp;
handle->pre_buffer_datalen = 0;
npath = switch_core_strdup(module_pool, path);
- int tmp = handle->samplerate;
+ tmp = handle->samplerate;
if (tmp == 8000 || tmp == 16000 || tmp == 32000 || tmp == 48000) {
rate = tmp;
}
}
npath = switch_mprintf("device-%d at %d",devNumber,rate);
-
-
switch_mutex_lock(globals.mutex);
source = switch_core_hash_find(globals.source_hash, npath);
source->ready = 0;
source->samples = switch_samples_per_packet(source->rate, source->interval);
-
-
switch_mutex_init(&source->mutex, SWITCH_MUTEX_NESTED, source->pool);
-
-
switch_threadattr_create(&thd_attr, source->pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, read_stream_thread, source, source->pool);
-
}
-
}
-
}
switch_mutex_unlock(globals.mutex);
switch_yield(1000000);
if (source) {
/*wait for source to be ready*/
-
- while(source->ready==0){switch_yield(100000);}
-
+ while(source->ready==0) {
+ switch_yield(100000);
+ }
if (switch_thread_rwlock_tryrdlock(source->rwlock) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " error rwlock !\n");
source = NULL;
}
-
}
-
-
if (source) {
status = SWITCH_STATUS_SUCCESS;
handle->private_info = context;
handle->interval = source->interval;
-
switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
if (switch_buffer_create_dynamic(&context->audio_buffer, 512, 1024, 0) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
source->context_list = context;
source->total++;
switch_mutex_unlock(source->mutex);
-
}
}
} else {
status = SWITCH_STATUS_FALSE;
}
-
-
return status;
}
int bytesPerSample = context->source->audio_stream->bytesPerFrame;
size_t need = *len * bytesPerSample;
-
-
if (!context->source->ready) {
*len = 0;
return SWITCH_STATUS_FALSE;