From 36e70cf306f69977aa5d61b7617e80e3c20501e1 Mon Sep 17 00:00:00 2001 From: Lianlian Zhu Date: Sun, 19 Feb 2017 14:35:24 +0000 Subject: PD#137760: audio: fixed tv blocked by audiotack 1) prevent tv makes too many audiotracks to block mediaserver. 2) when close device, release raw audio track at the same time. Change-Id: I402ef39b6b898b0b7a06668535c515a4e604357d Signed-off-by: Zhe Wang --- diff --git a/libTVaudio/audio/aml_audio.c b/libTVaudio/audio/aml_audio.c index fe5c32b..9ce0dd3 100644 --- a/libTVaudio/audio/aml_audio.c +++ b/libTVaudio/audio/aml_audio.c @@ -974,6 +974,10 @@ static int release_audiotrack(struct aml_stream_out *out) { if (ret < 0) { ALOGE("%s, Delete audio track is fail!\n", __FUNCTION__); } + ret = release_raw_audio_track(); + if (ret < 0) { + ALOGE("%s, Delete raw audio track is fail!\n", __FUNCTION__); + } set_amaudio2_enable(0); pthread_mutex_unlock(&out->lock); return 0; @@ -1336,6 +1340,10 @@ static int aml_device_close(struct aml_dev *device) { free(in->delay_buf.start_add); } + omx_codec_close(); + omx_codec_dts_close(); + omx_started = 0; + if (out->output_device == CC_OUT_USE_ALSA) { alsa_out_close(out); } else if (out->output_device == CC_OUT_USE_AMAUDIO) { @@ -1345,9 +1353,6 @@ static int aml_device_close(struct aml_dev *device) { release_audiotrack(out); } - omx_codec_close(); - omx_codec_dts_close(); - omx_started = 0; tmp_buffer_release (&DDP_out_buffer); tmp_buffer_release (&DD_out_buffer); tmp_buffer_release (&android_out_buffer); @@ -1745,6 +1750,10 @@ static void* aml_audio_threadloop(void *data __unused) { ALOGD("%s, set aml_Audio_ThreadExecFlag as 0.\n", __FUNCTION__); } + if (gpAmlDevice != NULL) { + aml_device_close(gpAmlDevice); + } + ALOGD("%s, exiting...\n", __FUNCTION__); return ((void *) 0); } @@ -1877,7 +1886,6 @@ int aml_audio_close(void) { exit_pthread_for_android_check(gpAmlDevice->android_check_ThreadID); gpAmlDevice->android_check_ThreadID = 0; - aml_device_close(gpAmlDevice); clrDevice(gpAmlDevice); gpAmlDevice = NULL; diff --git a/libTVaudio/audio/android_out.cpp b/libTVaudio/audio/android_out.cpp index 23e7087..9e61156 100644 --- a/libTVaudio/audio/android_out.cpp +++ b/libTVaudio/audio/android_out.cpp @@ -206,13 +206,16 @@ static int RawAudioTrackInit(audio_format_t aformat,int sr) int ret; ALOGD("%s, entering...,aformat %x,sr %d\n", __FUNCTION__,aformat,sr); //raw here - gmpAudioTracker_raw = new AudioTrack(); - if (gmpAudioTracker_raw == NULL) { - ALOGE("%s, new gmpAudioTracker_raw failed.\n", __FUNCTION__); - return -1; + if (gmpAudioTracker_raw != NULL) { + gmpAudioTracker_raw = gmpAudioTracker_raw.get(); + } else { + gmpAudioTracker_raw = new AudioTrack(); + if (gmpAudioTracker_raw == NULL) { + ALOGE("%s, new gmpAudioTracker_raw failed.\n", __FUNCTION__); + return -1; + } + gmpAudioTracker_raw = gmpAudioTracker_raw.get(); } - glpTracker_raw = gmpAudioTracker_raw.get(); - Status = glpTracker_raw->set(AUDIO_STREAM_MUSIC, sr, aformat, AUDIO_CHANNEL_OUT_STEREO, 0, (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO) @@ -254,13 +257,16 @@ static int AudioTrackInit(void) { I2S_state = 0; - gmpAudioTracker = new AudioTrack(); - if (gmpAudioTracker == NULL) { - ALOGE("%s, new AudioTrack failed.\n", __FUNCTION__); - return -1; + if (gmpAudioTracker != NULL) { + glpTracker = gmpAudioTracker.get(); + } else { + gmpAudioTracker = new AudioTrack(); + if (gmpAudioTracker == NULL) { + ALOGE("%s, new AudioTrack failed.\n", __FUNCTION__); + return -1; + } + glpTracker = gmpAudioTracker.get(); } - glpTracker = gmpAudioTracker.get(); - Status = glpTracker->set(AUDIO_STREAM_MUSIC, 48000, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 0, AUDIO_OUTPUT_FLAG_NONE, -- cgit