author | Jian Xu <jian.xu@amlogic.com> | 2016-04-19 02:52:11 (GMT) |
---|---|---|
committer | Gerrit Code Review <gituser@git.myamlogic.com> | 2016-04-19 02:52:12 (GMT) |
commit | 2197e53eb991ea1f36ecb0261089c2e8ff22b43c (patch) | |
tree | ce9c01ef50853c5c06b703017bac27c32adea37c | |
parent | f0d3d67e92632e17658ed6045a80824fff649a28 (diff) | |
parent | d2c32761754d6cc654d275917bf5343e5efcf69a (diff) | |
download | audio-2197e53eb991ea1f36ecb0261089c2e8ff22b43c.zip audio-2197e53eb991ea1f36ecb0261089c2e8ff22b43c.tar.gz audio-2197e53eb991ea1f36ecb0261089c2e8ff22b43c.tar.bz2 |
Merge "PD#121836: add HDMI/AV/ATV audio delay interface" into l-amlogic
-rw-r--r-- | libTVaudio/audio/aml_audio.c | 78 | ||||
-rw-r--r-- | libTVaudio/audio/aml_audio.h | 2 | ||||
-rw-r--r-- | libTVaudio/audio/audio_amaudio.cpp | 13 | ||||
-rw-r--r-- | libTVaudio/audio/audio_usb_check.cpp | 13 | ||||
-rw-r--r-- | libTVaudio/audio_amaudio.h | 2 |
5 files changed, 106 insertions, 2 deletions
diff --git a/libTVaudio/audio/aml_audio.c b/libTVaudio/audio/aml_audio.c index 181caac..7a01406 100644 --- a/libTVaudio/audio/aml_audio.c +++ b/libTVaudio/audio/aml_audio.c @@ -90,6 +90,9 @@ struct aml_stream_in { int max_bytes; void *temp_buffer; void *write_buffer; + int delay_time; + int last_delay_time; + struct circle_buffer delay_buf; }; struct aml_stream_out { @@ -148,6 +151,15 @@ static struct aml_dev gmAmlDevice = { .max_bytes = 0, .temp_buffer = NULL, .write_buffer = NULL, + .delay_time = 0, + .last_delay_time = 0, + .delay_buf = { + .lock = PTHREAD_MUTEX_INITIALIZER, + .start_add = NULL, + .rd = NULL, + .wr = NULL, + .size = 0, + }, }, .out = { @@ -1146,6 +1158,14 @@ static int set_output_deviceID(int deviceID) { return 0; } +static int get_output_deviceID(void) { + if (gpAmlDevice == NULL) { + ALOGE("%s, aml audio is not open, must open it first!\n", __FUNCTION__); + return -1; + } + return gpAmlDevice->output_deviceID; +} + static int aml_device_init(struct aml_dev *device) { int ret; @@ -1261,6 +1281,10 @@ static int aml_device_close(struct aml_dev *device) { alsa_in_close(in); + if (in->delay_buf.size != 0) { + free(in->delay_buf.start_add); + } + if (out->output_device == CC_OUT_USE_ALSA) { alsa_out_close(out); } else if (out->output_device == CC_OUT_USE_AMAUDIO) { @@ -1485,7 +1509,7 @@ static int check_audio_type(struct aml_stream_out *out) { ALOGI("DD+ passthrough flag changed from %d to %d\n",digital_raw_enable,digtal_out); need_reset_config = 1; } - else if (digtal_out > 0 && digital_raw_enable == 0) { + else if (digtal_out > 0 && digital_raw_enable == 0) { ALOGI("PCM output changed to RAW pass through\n"); need_reset_config = 1; } @@ -1510,6 +1534,45 @@ static int audio_effect_process(short* buffer, int frame_size) { return output_size; } +static int set_delay(struct aml_stream_in *in, int frame_size) { + unsigned char *buffer_ptr = NULL; + int delay_buffer_size = in->delay_time * 192; + int buffer_size = delay_buffer_size + frame_size; + + if (in->delay_buf.size < buffer_size) { + in->delay_buf.start_add = (char *)realloc( + in->delay_buf.start_add, buffer_size * sizeof(char)); + if (!in->delay_buf.start_add) { + ALOGE("realloc delay buffer failed\n"); + return -1; + } + memset(in->delay_buf.start_add, 0, in->delay_buf.size); + in->delay_buf.size = buffer_size; + in->delay_buf.rd = in->delay_buf.start_add; + in->delay_buf.wr = in->delay_buf.start_add + delay_buffer_size; + ALOGI("realloc delay buffer size %d byte\n", buffer_size); + } + + if (in->last_delay_time != in->delay_time) { + in->delay_buf.wr = in->delay_buf.rd + delay_buffer_size; + if (in->delay_buf.wr >= (in->delay_buf.start_add + in->delay_buf.size)) + in->delay_buf.wr -= in->delay_buf.size; + in->last_delay_time = in->delay_time; + } + + write_to_buffer(in->delay_buf.wr, in->temp_buffer, frame_size, + in->delay_buf.start_add, in->delay_buf.size); + in->delay_buf.wr = update_pointer(in->delay_buf.wr, frame_size, + in->delay_buf.start_add, in->delay_buf.size); + + read_from_buffer(in->delay_buf.rd, in->temp_buffer, frame_size, + in->delay_buf.start_add, in->delay_buf.size); + in->delay_buf.rd = update_pointer(in->delay_buf.rd, frame_size, + in->delay_buf.start_add, in->delay_buf.size); + + return 0; +} + static void* aml_audio_threadloop(void *data __unused) { struct aml_stream_in *in = NULL; struct aml_stream_out *out = NULL; @@ -1552,6 +1615,9 @@ static void* aml_audio_threadloop(void *data __unused) { } else { if (check_audio_type(out) == MUTE) memset((char *) in->temp_buffer, 0, output_size); + if (in->delay_time != 0 && get_output_deviceID() == 0) { + set_delay(in, output_size); + } write_to_buffer((char *) in->write_buffer, (char *) in->temp_buffer, output_size, (char *) start_temp_buffer, TEMP_BUFFER_SIZE); @@ -1866,6 +1932,16 @@ int set_right_gain(int right_gain) { return 0; } +int set_audio_delay(int delay_ms) { + gpAmlDevice->in.delay_time = delay_ms; + ALOGI("Set audio delay time %d ms!\n", delay_ms); + return 0; +} + +int get_audio_delay(void) { + return gpAmlDevice->in.delay_time; +} + int SetDumpDataFlag(int tmp_flag) { int tmp_val; tmp_val = gDumpDataFlag; diff --git a/libTVaudio/audio/aml_audio.h b/libTVaudio/audio/aml_audio.h index adc45e6..e0cd909 100644 --- a/libTVaudio/audio/aml_audio.h +++ b/libTVaudio/audio/aml_audio.h @@ -70,6 +70,8 @@ int set_right_gain(int right_gain); int buffer_read(struct circle_buffer *tmp, char* buffer, size_t bytes); int buffer_write(struct circle_buffer *tmp, char* buffer, size_t bytes); int set_output_record_enable(int enable); +int set_audio_delay(int delay_ms); +int get_audio_delay(void); #ifdef __cplusplus } diff --git a/libTVaudio/audio/audio_amaudio.cpp b/libTVaudio/audio/audio_amaudio.cpp index 59d2f72..a3105d5 100644 --- a/libTVaudio/audio/audio_amaudio.cpp +++ b/libTVaudio/audio/audio_amaudio.cpp @@ -24,8 +24,19 @@ #define LOG_TAG "LibAudioCtl" +int amSetAudioDelay(int delay_ms) { + return set_audio_delay(delay_ms); +} + +int amGetAudioDelay(void) { + return get_audio_delay(); +} + int amAudioOpen(unsigned int sr, int input_device, int output_device) { - return aml_audio_open(sr, input_device, output_device); + int ret; + ret = aml_audio_open(sr, input_device, output_device); + ret |= set_audio_delay(60); + return ret; } int amAudioClose(void) { diff --git a/libTVaudio/audio/audio_usb_check.cpp b/libTVaudio/audio/audio_usb_check.cpp index a1316d5..705e59f 100644 --- a/libTVaudio/audio/audio_usb_check.cpp +++ b/libTVaudio/audio/audio_usb_check.cpp @@ -7,8 +7,10 @@ #include <sys/prctl.h> #include <media/AudioSystem.h> #include <media/AudioParameter.h> +#include <cutils/properties.h> #include "audio_usb_check.h" +#include "aml_audio.h" #define LOG_TAG "aml_audio" @@ -82,6 +84,16 @@ static int GetStreamVolume(void) { return 0; } +static int SetAudioDelay(void) { + char value[PROPERTY_VALUE_MAX]; + if (property_get("media.TV.audio.delay", value, NULL) > 0) { + int delay = atoi(value); + if (delay > 0 && get_audio_delay() != delay) + set_audio_delay(delay); + } + return 0; +} + } static int running_flag = 0; @@ -91,6 +103,7 @@ void* android_check_threadloop(void *data __unused) { while (running_flag) { android::GetStreamVolume(); android::GetDeviceID(); + android::SetAudioDelay(); usleep(100*1000); } //ALOGI("Exit thread loop for android check!\n"); diff --git a/libTVaudio/audio_amaudio.h b/libTVaudio/audio_amaudio.h index b440904..e3262b1 100644 --- a/libTVaudio/audio_amaudio.h +++ b/libTVaudio/audio_amaudio.h @@ -3,6 +3,8 @@ #include "audio/aml_audio.h" +int amSetAudioDelay(int delay_ms); +int amGetAudioDelay(void); int amAudioOpen(unsigned int sr, int input_device, int output_device); int amAudioClose(void); int amAudioSetInputSr(unsigned int sr, int input_device, int output_device); |