author | chengshun.wang <chengshun.wang@amlogic.com> | 2013-06-21 07:18:18 (GMT) |
---|---|---|
committer | jian.xu <jian.xu@amlogic.com> | 2013-06-21 07:18:18 (GMT) |
commit | 6e55950ca34127dc34c89faf728d9d231efe2d74 (patch) | |
tree | fb02b2572cb6c123990fed781d2ad32d9288d87e | |
parent | 40b52bd75acef9232a11d2b3849ea95862f43a3a (diff) | |
download | audio-6e55950ca34127dc34c89faf728d9d231efe2d74.zip audio-6e55950ca34127dc34c89faf728d9d231efe2d74.tar.gz audio-6e55950ca34127dc34c89faf728d9d231efe2d74.tar.bz2 |
PD #74526:reboot system by plugged usb_audio device, system had no sound in sometimes
-rwxr-xr-x | audio_hw.c | 31 | ||||
-rwxr-xr-x | audio_route.c | 66 | ||||
-rwxr-xr-x | audio_route.h | 2 | ||||
-rwxr-xr-x | usb_audio_hw.c | 56 |
4 files changed, 126 insertions, 29 deletions
@@ -271,7 +271,7 @@ static void select_mode(struct aml_audio_device *adev) select_input_device(adev); return; } - +#if 0 /* type : 0 -> playback, 1 -> capture */ @@ -316,24 +316,16 @@ int get_external_card(int type) return ret; } - +#endif static int check_output_stream(struct aml_stream_out *out) { int ret = 0; unsigned int card = CARD_AMLOGIC_DEFAULT; unsigned int port = PORT_MM; - int ext_card; + + card = get_default_card(); LOGFUNC("*******%s*********", __FUNCTION__); - ext_card = get_external_card(0); - if(ext_card < 0) - { - card = CARD_AMLOGIC_DEFAULT; - } - else - { - card = ext_card; - } out->config.start_threshold = PERIOD_SIZE * 2; out->config.avail_min = 0;//SHORT_PERIOD_SIZE; @@ -369,7 +361,7 @@ static int start_output_stream(struct aml_stream_out *out) } LOGFUNC("%s(adev->out_device=%#x, adev->mode=%d)", __FUNCTION__, adev->out_device, adev->mode); - card = CARD_AMLOGIC_BOARD; + card = get_default_card(); port = PORT_MM; LOGFUNC("------------open on board audio-------"); if(getprop_bool("media.libplayer.wfd")){ @@ -1022,6 +1014,8 @@ static int start_input_stream(struct aml_stream_in *in) adev->in_device |= in->device; select_input_device(adev); } + card = get_default_card(); + port = PORT_MM; ALOGV("%s(in->requested_rate=%d, in->config.rate=%d)", __FUNCTION__, in->requested_rate, in->config.rate); @@ -1097,17 +1091,8 @@ static int check_input_stream(struct aml_stream_in *in) int ret = 0; unsigned int card = CARD_AMLOGIC_BOARD; unsigned int port = 0; - int ext_card; - ext_card = get_external_card(1); - if(ext_card < 0) - { - card = CARD_AMLOGIC_BOARD; - } - else - { - card = ext_card; - } + card = get_default_card(); /* this assumes routing is done previously */ in->pcm = pcm_open(card, port, PCM_IN, &in->config); diff --git a/audio_route.c b/audio_route.c index a4ec8f5..5246a06 100755 --- a/audio_route.c +++ b/audio_route.c @@ -23,6 +23,12 @@ #include <stdbool.h> #include <stdio.h> +#include <fcntl.h> +#include <stdint.h> +#include <sys/time.h> +#include <stdlib.h> + + #include <cutils/log.h> #include <tinyalsa/asoundlib.h> @@ -68,6 +74,61 @@ struct config_parse_state { int level; }; +#define AUDIO_CARD_PATH "/proc/asound/cards" + +int get_default_card() +{ + int err=0; + int fd; + unsigned i=0; + int string_length=10000; + char *read_buf,*buf1; + int card_num[10]; + int card_default=0; + char *str_start; + + fd = open(AUDIO_CARD_PATH, O_RDONLY); + + if (fd <0) { + ALOGE("ERROR: failed to open config file %s error: %d\n", AUDIO_CARD_PATH, errno); + close(fd); + return -EINVAL; + } + + read_buf = (char *)malloc(string_length); + if(read_buf==NULL){ + ALOGD("ERROR: falied to malloc merry for read_buf !"); + close(fd); + return -EINVAL; + } + buf1 = read_buf; + memset(read_buf, 0x0, string_length); + err = read(fd, read_buf, string_length); + while(read_buf){ + i++; + str_start = strstr(read_buf, "SOC-Audio"); + if (str_start == NULL) { + if(i>=2){ + break; + }else{ + ALOGE("ERROR:%s section not found Default card in times %d", "SOC-Audio",i); + break; + } + } + + card_num[i] = atoi(str_start - 21); + read_buf=str_start + strlen("SOC-Audio"); + + } + card_default = card_num[i-1]; + // ALOGD("******get_default_card***card=%d***",card_default); + + read_buf = buf1; + free(read_buf); + read_buf = NULL; + close(fd); + return card_default; +} /* path functions */ static void path_free(struct audio_route *ar) @@ -404,7 +465,7 @@ struct audio_route *audio_route_init(void) FILE *file; int bytes_read; void *buf; - int i; + int i,mixer_card; struct mixer_path *path; struct audio_route *ar; @@ -412,7 +473,8 @@ struct audio_route *audio_route_init(void) if (!ar) goto err_calloc; - ar->mixer = mixer_open(MIXER_CARD); + mixer_card = get_default_card(); + ar->mixer = mixer_open(mixer_card); if (!ar->mixer) { ALOGE("Unable to open the mixer, aborting."); goto err_mixer_open; diff --git a/audio_route.h b/audio_route.h index 31355dd..a30799a 100755 --- a/audio_route.h +++ b/audio_route.h @@ -30,4 +30,6 @@ void reset_mixer_state(struct audio_route *ar); /* Updates the mixer with any changed values */ void update_mixer_state(struct audio_route *ar); +/* get soc-aduio card number in platform */ +int get_default_card(); #endif diff --git a/usb_audio_hw.c b/usb_audio_hw.c index 0383b86..96170f0 100755 --- a/usb_audio_hw.c +++ b/usb_audio_hw.c @@ -97,6 +97,7 @@ struct aml_stream_in { struct aml_audio_device *dev; }; +static int get_usb_card(struct aml_audio_device *dev); int getnumOfRates(char *ratesStr){ int i, size = 0; @@ -410,6 +411,11 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) { struct aml_stream_out *out = (struct aml_stream_out *)stream; struct aml_audio_device *adev = out->dev; + int ret = get_usb_card(adev); + if (ret < 0){ + ALOGE("out_set_parameters*****ERROR: Could not get usb card number"); + } +#if 0 struct str_parms *parms; char value[32]; @@ -429,7 +435,7 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) adev->card_device = atoi(value); pthread_mutex_unlock(&adev->lock); str_parms_destroy(parms); - +#endif return 0; } @@ -670,6 +676,48 @@ static int in_set_gain(struct audio_stream_in *stream, float gain) #define USB_AUDIO_PCM "/proc/asound/usb_audio_info" +static int get_usb_card(struct aml_audio_device *dev) +{ + int card = -1,err=0; + int fd; + struct aml_audio_device *adev = dev; + uint i=0,usbid; + int string_length=32,str_len=8; + char *read_buf, *str; + int card_num; + char *str_start; + fd = open(USB_AUDIO_PCM, O_RDONLY); + + if (fd <0) { + ALOGE("ERROR: failed to open config file %s error: %d\n", USB_AUDIO_PCM, errno); + close(fd); + return -EINVAL; + } + + read_buf = (char *)malloc(string_length); + str = (char*)malloc(str_len); + memset(read_buf, 0x0, string_length); + memset(read_buf, 0x0, str_len); + err = read(fd, read_buf, string_length); + memcpy(str,read_buf,8); + // ALOGD("****str=%s****",str); + + usbid = strtoul(str, NULL, 16); + card = atoi(read_buf + 9); + adev->card = card; + ALOGD("******get_usb_card***card=%d***",adev->card); + adev->card_device= 0; + + free(read_buf); + free(str); + read_buf = NULL; + str = NULL; + close(fd); + return err; + + +} +#if 0 static int get_usb_card(struct aml_stream_in *in){ ALOGD("============get_usb_card============="); int card = -1, err = 0; @@ -701,7 +749,7 @@ static int get_usb_card(struct aml_stream_in *in){ close(fd); return err; } - +#endif static int get_next_buffer(struct resampler_buffer_provider *buffer_provider, struct resampler_buffer* buffer) { @@ -1108,8 +1156,8 @@ static int adev_open_input_stream(struct audio_hw_device *dev, //memcpy(&in->in_config, &pcm_config_in, sizeof(pcm_config_in)); in->dev = adev; in->in_config.rate = in->requested_rate; - - ret = get_usb_card(in); + ret = get_usb_card(adev); + if (ret < 0){ ALOGE("ERROR: Could not get usb card number"); goto err_open; |