diff options
Diffstat (limited to 'avsys-audio-alsa.c')
-rw-r--r-- | avsys-audio-alsa.c | 80 |
1 files changed, 57 insertions, 23 deletions
diff --git a/avsys-audio-alsa.c b/avsys-audio-alsa.c index 7e7916a..4b8072e 100644 --- a/avsys-audio-alsa.c +++ b/avsys-audio-alsa.c @@ -27,14 +27,16 @@ #include "avsys-debug.h" #if defined(_MMFW_I386_ALL_SIMULATOR) -#define AIF2_DEVICE_NAME "default" -#define AIF3_DEVICE_NAME "default" +#define AIF_CP_DEVICE_NAME "default" +#define AIF_BT_DEVICE_NAME "default" +#define AIF_RADIO_DEVICE_NAME "default" #else -#define AIF2_DEVICE_NAME "AIF2" -#define AIF3_DEVICE_NAME "AIF3" +#define AIF_CP_DEVICE_NAME "AIF2" +#define AIF_BT_DEVICE_NAME "AIF3" +#define AIF_RADIO_DEVICE_NAME "AIF4" #endif -int avsys_audio_alsa_open_AIF_device(const int AIF_type, avsys_audio_alsa_aif_handle_t *handle) +int avsys_audio_alsa_open_AIF_device(aif_device_type_t aif_type, avsys_audio_alsa_aif_handle_t *handle) { snd_pcm_t *ahandle = NULL; int err = -1; @@ -46,25 +48,29 @@ int avsys_audio_alsa_open_AIF_device(const int AIF_type, avsys_audio_alsa_aif_ha return AVSYS_STATE_ERR_NULL_POINTER; memset(dev_name, '\0', sizeof(dev_name)); - switch (AIF_type) { - case AIF2_CAPTURE: - strncpy(dev_name, AIF2_DEVICE_NAME, sizeof(dev_name) - 1); + switch (aif_type) { + case AIF_CP_CAPTURE: + strncpy(dev_name, AIF_CP_DEVICE_NAME, sizeof(dev_name) - 1); stream = SND_PCM_STREAM_CAPTURE; break; - case AIF2_PLAYBACK: - strncpy(dev_name, AIF2_DEVICE_NAME, sizeof(dev_name) - 1); + case AIF_CP_PLAYBACK: + strncpy(dev_name, AIF_CP_DEVICE_NAME, sizeof(dev_name) - 1); stream = SND_PCM_STREAM_PLAYBACK; break; - case AIF3_CAPTURE: - strncpy(dev_name, AIF3_DEVICE_NAME, sizeof(dev_name) - 1); + case AIF_BT_CAPTURE: + strncpy(dev_name, AIF_BT_DEVICE_NAME, sizeof(dev_name) - 1); stream = SND_PCM_STREAM_CAPTURE; break; - case AIF3_PLAYBACK: - strncpy(dev_name, AIF3_DEVICE_NAME, sizeof(dev_name) - 1); + case AIF_BT_PLAYBACK: + strncpy(dev_name, AIF_BT_DEVICE_NAME, sizeof(dev_name) - 1); + stream = SND_PCM_STREAM_PLAYBACK; + break; + case AIF_RADIO_PLAYBACK: + strncpy(dev_name, AIF_RADIO_DEVICE_NAME, sizeof(dev_name) - 1); stream = SND_PCM_STREAM_PLAYBACK; break; default: - avsys_critical_r(AVAUDIO, "Invalid AIF device %d\n", AIF_type); + avsys_critical_r(AVAUDIO, "Invalid AIF device %d\n", aif_type); return AVSYS_STATE_ERR_INVALID_MODE; break; } @@ -81,7 +87,7 @@ int avsys_audio_alsa_open_AIF_device(const int AIF_type, avsys_audio_alsa_aif_ha } handle->alsa_handle = (void *)ahandle; - handle->type = AIF_type; + handle->type = aif_type; return AVSYS_STATE_SUCCESS; } @@ -116,7 +122,7 @@ int avsys_audio_alsa_close_AIF_device(avsys_audio_alsa_aif_handle_t* handle) return AVSYS_STATE_SUCCESS; } -int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle) +int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle, aif_rate_t rate) { #if defined(_MMFW_I386_ALL_SIMULATOR) return AVSYS_STATE_SUCCESS; @@ -124,8 +130,8 @@ int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle) int err = 0; snd_pcm_t *ahandle = NULL; snd_pcm_hw_params_t *params; - unsigned int val; - int dir; + unsigned int val = 0; + int dir = 0; avsys_info(AVAUDIO, "%s\n", __func__); if (!handle) @@ -135,14 +141,39 @@ int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle) if (!ahandle) return AVSYS_STATE_ERR_NULL_POINTER; + /* Skip parameter setting to null device. */ + if (snd_pcm_type(ahandle) == SND_PCM_TYPE_NULL) + return AVSYS_STATE_SUCCESS; + /* Allocate a hardware parameters object. */ snd_pcm_hw_params_alloca(¶ms); /* Fill it in with default values. */ - snd_pcm_hw_params_any(ahandle, params); + err = snd_pcm_hw_params_any(ahandle, params); + if (err < 0) { + avsys_error_r(AVAUDIO, "snd_pcm_hw_params_any() : failed! - %s\n", snd_strerror(err)); + return AVSYS_STATE_ERR_INTERNAL; + } /* Set the desired hardware parameters. */ /* Interleaved mode */ - snd_pcm_hw_params_set_access(ahandle, params, SND_PCM_ACCESS_RW_INTERLEAVED); + err = snd_pcm_hw_params_set_access(ahandle, params, SND_PCM_ACCESS_RW_INTERLEAVED); + if (err < 0) { + avsys_error_r(AVAUDIO, "snd_pcm_hw_params_set_access() : failed! - %s\n", snd_strerror(err)); + return AVSYS_STATE_ERR_INTERNAL; + } + + if (rate == AIF_CONF_RATE) { + /* Auto rate by conf */ + avsys_info(AVAUDIO, "Let rate by configuration\n"); + } else { + /* Force input rate */ + avsys_info(AVAUDIO, "Force rate (%d)\n", rate); + err = snd_pcm_hw_params_set_rate(ahandle, params, rate, 0); + if (err < 0) { + avsys_error_r(AVAUDIO, "snd_pcm_hw_params_set_rate() : failed! - %s\n", snd_strerror(err)); + return AVSYS_STATE_ERR_INTERNAL; + } + } err = snd_pcm_hw_params(ahandle, params); if (err < 0) { @@ -168,8 +199,11 @@ int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle) avsys_info(AVAUDIO, "channels = %d\n", val); snd_pcm_hw_params_get_rate(params, &val, &dir); - avsys_info(AVAUDIO, "rate = %d bps\n", val); + avsys_info(AVAUDIO, "rate = %d(%d) Hz\n", val, dir); + + /* Save current rate for later check */ + handle->rate = val; return AVSYS_STATE_SUCCESS; -#endif +#endif /* _MMFW_I386_ALL_SIMULATOR */ } |