author | lianghu.su <lianghu.su@amlogic.com> | 2014-03-04 03:03:04 (GMT) |
---|---|---|
committer | tao.dong <tao.dong@amlogic.com> | 2014-03-14 13:00:25 (GMT) |
commit | ea064590c2e646f2f315a9327b536d79e1c45282 (patch) | |
tree | ba77c3a2948fe05c40ff8ae2704953da6dd79492 | |
parent | 1ef1e7239d2f5f97c0b0fe1c332fdaffbb77b6cc (diff) | |
download | audio-ea064590c2e646f2f315a9327b536d79e1c45282.zip audio-ea064590c2e646f2f315a9327b536d79e1c45282.tar.gz audio-ea064590c2e646f2f315a9327b536d79e1c45282.tar.bz2 |
pd[#87148]:HDMI IN V01 Version:Audio for HDMI IN by wangchenshun
-rwxr-xr-x | audio_hw.c | 46 | ||||
-rwxr-xr-x | hdmi_audio_hw.c | 34 |
2 files changed, 70 insertions, 10 deletions
@@ -433,6 +433,40 @@ OUT: return port; } +static int get_spdif_port(){ + int port = -1, err = 0; + int fd = -1; + unsigned fileSize = 512; + char *read_buf = NULL, *pd = NULL; + static const char *const SOUND_PCM_PATH = "/proc/asound/pcm"; + fd = open(SOUND_PCM_PATH, O_RDONLY); + if (fd < 0) { + ALOGE("ERROR: failed to open config file %s error: %d\n", SOUND_PCM_PATH, errno); + close(fd); + return -EINVAL; + } + + read_buf = (char *)malloc(fileSize); + if (!read_buf) { + ALOGE("Failed to malloc read_buf"); + close(fd); + return -ENOMEM; + } + memset(read_buf, 0x0, fileSize); + err = read(fd, read_buf, fileSize); + if (fd < 0) { + ALOGE("ERROR: failed to read config file %s error: %d\n", SOUND_PCM_PATH, errno); + close(fd); + return -EINVAL; + } + pd = strstr(read_buf, "SPDIF"); + port = *(pd -3) - '0'; + +OUT: + free(read_buf); + close(fd); + return port; +} /* must be called with hw device and output stream mutexes locked */ static int start_output_stream(struct aml_stream_out *out) { @@ -935,8 +969,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, out->echo_reference->write(out->echo_reference, &b); } -#if 1 - if(getprop_bool("media.audiohw.dump")){ +#if 0 FILE *fp1=fopen("/data/audio_out","a+"); if(fp1){ int flen=fwrite((char *)in_buffer,1,out_frames * frame_size,fp1); @@ -945,7 +978,6 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, }else{ LOGFUNC("could not open file:audio_out"); } - } #endif #if 0 if(out->config.rate != DEFAULT_OUT_SAMPLING_RATE) { @@ -1004,9 +1036,6 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, } pthread_mutex_unlock(&adev->lock); } - //if(getprop_bool("media.hw.set")) - memset(buffer,0,bytes); - return bytes; } @@ -1057,11 +1086,14 @@ static int start_input_stream(struct aml_stream_in *in) select_devices(adev); } card = get_aml_card(); + ALOGD("*****get_spdif_port()=%d****",get_spdif_port()); ALOGV("%s(in->requested_rate=%d, in->config.rate=%d)", __FUNCTION__, in->requested_rate, in->config.rate); if (adev->in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET){ port = get_pcm_bt_port(); + } else if(getprop_bool("sys.hdmiIn.Capture")){ + port = get_spdif_port(); } else { port = PORT_MM; } @@ -1625,7 +1657,7 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer, #if 0 FILE *dump_fp = NULL; - dump_fp = fopen("/data/dump_in.pcm", "a+"); + dump_fp = fopen("/data/audio_in.pcm", "a+"); if (dump_fp != NULL) { fwrite(buffer, bytes, 1, dump_fp); fclose(dump_fp); diff --git a/hdmi_audio_hw.c b/hdmi_audio_hw.c index e5b2e5b..9666931 100755 --- a/hdmi_audio_hw.c +++ b/hdmi_audio_hw.c @@ -75,6 +75,9 @@ static unsigned int DEFAULT_OUT_SAMPLING_RATE = 48000; /* sampling rate when using VX port for narrow band */ #define VX_NB_SAMPLING_RATE 8000 +static unsigned int first_write_status; + + struct pcm_config pcm_config_out = { .channels = 2, .rate = MM_FULL_POWER_SAMPLING_RATE, @@ -754,6 +757,7 @@ static int do_output_standby(struct aml_stream_out *out) } out->standby = 1; + first_write_status = 0; } pthread_mutex_unlock(&HdmiStreamState.hdmi_state_mutex); return 0; @@ -910,6 +914,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, volatile char *data_src; short *dataprint; uint i, total_len; + char prop[PROPERTY_VALUE_MAX]; /* acquiring hw device mutex systematically is useful if a low priority thread is waiting * on the output stream mutex - e.g. executing select_mode() while holding the hw device @@ -942,6 +947,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, goto exit; } out->standby = 0; + first_write_status = 0; /* a change in output device may change the microphone selection */ if (adev->active_input && adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) @@ -985,6 +991,17 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, out->echo_reference->write(out->echo_reference, &b); } +#if 0 + FILE *fp=fopen("/data/audio_out.pcm","a+"); + if(fp){ + int flen=fwrite((char *)buffer,1,out_frames * frame_size,fp); + LOGFUNC("flen = %d---outlen=%d ", flen, out_frames * frame_size); + fclose(fp); + }else{ + LOGFUNC("could not open file:audio_out"); + } +#endif + if(out->config.rate != DEFAULT_OUT_SAMPLING_RATE) { total_len = out_frames*frame_size + cached_len; @@ -1017,9 +1034,20 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, if(!out->standby) ret = pcm_write(out->pcm, (void *)output_buffer_bytes, ouput_len); }else{ - if(!out->standby) - ret = pcm_write(out->pcm, (void *)buf, out_frames * frame_size); - //ret = pcm_mmap_write(out->pcm, (void *)buf, out_frames * frame_size); + if(!out->standby){ + property_get("sys.hdmiIn.Capture",prop,"false"); + // ALOGD("****first_write_status=%d***",first_write_status); + if(!strcmp(prop,"true")){ + if(first_write_status < 20){ + first_write_status = first_write_status + 1; + memset((char*)buf,0,bytes); + } + }else{ + first_write_status = 0; + } + ret = pcm_write(out->pcm, (void *)buf, out_frames * frame_size); + //ret = pcm_mmap_write(out->pcm, (void *)buf, out_frames * frame_size); + } } |