|
|
@@ -81,7 +81,7 @@ static int get_device_id(audio_context_t* audio_ctx, int indev, const char* key)
|
|
|
|
|
|
audio_device_t* audio_device = NULL;
|
|
|
|
|
|
- if (0 == indev){
|
|
|
+ if (1 == indev){
|
|
|
device_count = audio_ctx->num_input_dev;
|
|
|
}
|
|
|
else{
|
|
|
@@ -95,7 +95,7 @@ static int get_device_id(audio_context_t* audio_ctx, int indev, const char* key)
|
|
|
else {
|
|
|
audio_device = &audio_ctx->list_output_devices[index];
|
|
|
}
|
|
|
-
|
|
|
+ //audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d audio_device(%d) description is %s.", __FUNCTION__, __LINE__, indev, audio_device->description);
|
|
|
if (audio_device->description && strstr(audio_device->description, key)) {
|
|
|
iret = index;
|
|
|
}
|
|
|
@@ -883,13 +883,17 @@ int audio_stop_playaudio(audio_context_t* audio_ctx)
|
|
|
{
|
|
|
/*assertions*/
|
|
|
assert(audio_ctx != NULL);
|
|
|
- audio_ctx->play_stream_flag = AUDIO_STRM_OFF;
|
|
|
-
|
|
|
- if (0 == pthread_join(audio_ctx->writethreadid, NULL)) {
|
|
|
- audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: (pulse audio) write thread joined success.");
|
|
|
- }
|
|
|
- else {
|
|
|
- audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: (pulse audio) write thread joined failed.");
|
|
|
+ if (AUDIO_STRM_ON == audio_ctx->play_stream_flag){
|
|
|
+ audio_ctx->play_stream_flag = AUDIO_STRM_OFF;
|
|
|
+ if (0 != audio_ctx->writethreadid) {
|
|
|
+ if (0 == pthread_join(audio_ctx->writethreadid, NULL)) {
|
|
|
+ audio_ctx->writethreadid = 0;
|
|
|
+ audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio write thread joined success.", __FUNCTION__, __LINE__);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio write thread joined failed for %s.", __FUNCTION__, __LINE__, strerror(errno));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
@@ -899,15 +903,18 @@ int audio_stop_pulseaudio(audio_context_t* audio_ctx)
|
|
|
{
|
|
|
/*assertions*/
|
|
|
assert(audio_ctx != NULL);
|
|
|
- audio_ctx->stream_flag = AUDIO_STRM_OFF;
|
|
|
-
|
|
|
- if (0 == pthread_join(audio_ctx->readthreadid, NULL)){
|
|
|
- audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: (pulse audio) read thread joined success.");
|
|
|
- }
|
|
|
- else {
|
|
|
- audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: (pulse audio) read thread joined failed.");
|
|
|
+ if (AUDIO_STRM_ON == audio_ctx->stream_flag){
|
|
|
+ audio_ctx->stream_flag = AUDIO_STRM_OFF;
|
|
|
+ if (0 != audio_ctx->readthreadid){
|
|
|
+ if (0 == pthread_join(audio_ctx->readthreadid, NULL)) {
|
|
|
+ audio_ctx->readthreadid = 0;
|
|
|
+ audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio read thread joined success.", __FUNCTION__, __LINE__);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio read thread joined failed for %s.", __FUNCTION__, __LINE__, strerror(errno));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -915,14 +922,15 @@ int audio_stop_pulseaudio(audio_context_t* audio_ctx)
|
|
|
|
|
|
void audio_close_pulseaudio(audio_context_t* audio_ctx)
|
|
|
{
|
|
|
- if (audio_ctx == NULL)
|
|
|
+ if (audio_ctx == NULL) {
|
|
|
return;
|
|
|
-
|
|
|
- if (audio_ctx->play_stream_flag == AUDIO_STRM_ON){
|
|
|
+ }
|
|
|
+
|
|
|
+ if (audio_ctx->play_stream_flag == AUDIO_STRM_ON) {
|
|
|
audio_stop_playaudio(audio_ctx);
|
|
|
}
|
|
|
|
|
|
- if (audio_ctx->stream_flag == AUDIO_STRM_ON){
|
|
|
+ if (audio_ctx->stream_flag == AUDIO_STRM_ON) {
|
|
|
audio_stop_pulseaudio(audio_ctx);
|
|
|
}
|
|
|
|
|
|
@@ -1208,8 +1216,7 @@ on_error:
|
|
|
else if (micspk->opt & AMS_OPT_PLAY) {
|
|
|
uninitialize_speaker(micspk);
|
|
|
}
|
|
|
- else if (micspk->opt & AMS_OPT_RECORD)
|
|
|
- {
|
|
|
+ else if (micspk->opt & AMS_OPT_RECORD){
|
|
|
uninitialize_micro(micspk);
|
|
|
}
|
|
|
audio_log_v(AUDIO_LOG_LEVEL_INFO, "audiowork_proc exit.");
|
|
|
@@ -1242,10 +1249,11 @@ apr_status_t audiomicspkpulse_create(apr_pool_t* pool,
|
|
|
micspk->ply_dev_id = get_device_id(micspk->audio_ctx, 0, ply_dev_key);
|
|
|
|
|
|
if (-1 == micspk->rec_dev_id || -1 == micspk->ply_dev_id) {
|
|
|
+ audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d, get device id failed!", __FUNCTION__, __LINE__);
|
|
|
return APR_EGENERAL;
|
|
|
}
|
|
|
else {
|
|
|
- audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d , rec_dev_id is %d, ply_dev_id is %d.", __FUNCTION__, __LINE__, micspk->rec_dev_id, micspk->ply_dev_id);
|
|
|
+ audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d, rec_dev_id is %d, ply_dev_id is %d.", __FUNCTION__, __LINE__, micspk->rec_dev_id, micspk->ply_dev_id);
|
|
|
}
|
|
|
|
|
|
play_frame_samples = FRAME_TIME * clock / 1000;
|
|
|
@@ -1328,16 +1336,20 @@ void audiomicspkpulse_destroy(audiomicspkpulse_t* micspk)
|
|
|
assert(NULL != micspk);
|
|
|
|
|
|
sem_post(micspk->audio_device_started_sem);
|
|
|
-
|
|
|
+
|
|
|
if (micspk->audio_ctx){
|
|
|
audio_close_pulseaudio(micspk->audio_ctx);
|
|
|
}
|
|
|
|
|
|
- if (micspk->ply_dbuf)
|
|
|
+ if (micspk->ply_dbuf) {
|
|
|
delay_buf_destroy((delay_buf*)micspk->ply_dbuf);
|
|
|
-
|
|
|
- if (micspk->rec_dbuf)
|
|
|
+ micspk->ply_dbuf = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (micspk->rec_dbuf) {
|
|
|
delay_buf_destroy((delay_buf*)micspk->rec_dbuf);
|
|
|
+ micspk->rec_dbuf = NULL;
|
|
|
+ }
|
|
|
|
|
|
if (micspk->opt & AMS_OPT_AS_ENGINE) {
|
|
|
//DeleteCriticalSection(&micspk->engine_lock);
|