am e6499429: Merge commit \'83b47a68\' into manualmerge
* commit 'e64994292cb02fae66f04002e1121d29979503d1':
usb audio: Fix incorrect bytes returned for recording
diff --git a/include/hardware/audio_effect.h b/include/hardware/audio_effect.h
index ee48e4c..41cd2e6 100644
--- a/include/hardware/audio_effect.h
+++ b/include/hardware/audio_effect.h
@@ -344,9 +344,10 @@
// Output:
// returned value: 0 successful operation
// -EINVAL invalid interface handle or
- // invalid command/reply size or format according to command code
- // The return code should be restricted to indicate problems related to the this
- // API specification. Status related to the execution of a particular command should be
+ // invalid command/reply size or format according to
+ // command code
+ // The return code should be restricted to indicate problems related to this API
+ // specification. Status related to the execution of a particular command should be
// indicated as part of the reply field.
//
// *pReplyData updated with command response
@@ -937,11 +938,12 @@
//
// Input:
// uuid: pointer to the effect uuid.
- // sessionId: audio session to which this effect instance will be attached. All effects
- // created with the same session ID are connected in series and process the same signal
- // stream. Knowing that two effects are part of the same effect chain can help the
- // library implement some kind of optimizations.
- // ioId: identifies the output or input stream this effect is directed to at audio HAL.
+ // sessionId: audio session to which this effect instance will be attached.
+ // All effects created with the same session ID are connected in series and process
+ // the same signal stream. Knowing that two effects are part of the same effect
+ // chain can help the library implement some kind of optimizations.
+ // ioId: identifies the output or input stream this effect is directed to in
+ // audio HAL.
// For future use especially with tunneled HW accelerated effects
//
// Input/Output:
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
index ec8a8c0..446281d 100644
--- a/modules/usbaudio/Android.mk
+++ b/modules/usbaudio/Android.mk
@@ -22,8 +22,8 @@
audio_hw.c \
alsa_device_profile.c \
alsa_device_proxy.c \
- logging.c \
- format.c
+ audio_logging.c \
+ audio_format.c
LOCAL_C_INCLUDES += \
external/tinyalsa/include \
$(call include-path-for, audio-utils)
diff --git a/modules/usbaudio/alsa_device_profile.c b/modules/usbaudio/alsa_device_profile.c
index 8e84471..141e06b 100644
--- a/modules/usbaudio/alsa_device_profile.c
+++ b/modules/usbaudio/alsa_device_profile.c
@@ -26,8 +26,8 @@
#include <log/log.h>
#include "alsa_device_profile.h"
-#include "format.h"
-#include "logging.h"
+#include "audio_format.h"
+#include "audio_logging.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
@@ -278,7 +278,8 @@
return num_written;
}
-static unsigned profile_enum_channel_counts(alsa_device_profile* profile, unsigned min, unsigned max)
+static unsigned profile_enum_channel_counts(alsa_device_profile* profile, unsigned min,
+ unsigned max)
{
static const unsigned std_channel_counts[] = {8, 4, 2, 1};
diff --git a/modules/usbaudio/alsa_device_proxy.c b/modules/usbaudio/alsa_device_proxy.c
index 676f288..3d13acd 100644
--- a/modules/usbaudio/alsa_device_proxy.c
+++ b/modules/usbaudio/alsa_device_proxy.c
@@ -24,7 +24,7 @@
#include "alsa_device_proxy.h"
-#include "logging.h"
+#include "audio_logging.h"
#define DEFAULT_PERIOD_SIZE 1024
#define DEFAULT_PERIOD_COUNT 2
@@ -32,7 +32,7 @@
void proxy_prepare(alsa_device_proxy * proxy, alsa_device_profile* profile,
struct pcm_config * config)
{
- ALOGV("proxy_prepare()");
+ ALOGV("proxy_prepare(c:%d, d:%d)", profile->card, profile->device);
proxy->profile = profile;
@@ -70,14 +70,18 @@
ALOGV("proxy_open(card:%d device:%d %s)", profile->card, profile->device,
profile->direction == PCM_OUT ? "PCM_OUT" : "PCM_IN");
+ if (profile->card < 0 || profile->device < 0) {
+ return -EINVAL;
+ }
+
proxy->pcm = pcm_open(profile->card, profile->device, profile->direction, &proxy->alsa_config);
if (proxy->pcm == NULL) {
return -ENOMEM;
}
if (!pcm_is_ready(proxy->pcm)) {
- ALOGE("[%s] proxy_open() pcm_open() failed: %s", LOG_TAG, pcm_get_error(proxy->pcm));
-#ifdef LOG_PCM_PARAMS
+ ALOGE(" proxy_open() pcm_open() failed: %s", pcm_get_error(proxy->pcm));
+#if defined(LOG_PCM_PARAMS)
log_pcm_config(&proxy->alsa_config, "config");
#endif
pcm_close(proxy->pcm);
diff --git a/modules/usbaudio/audio_format.c b/modules/usbaudio/audio_format.c
new file mode 100644
index 0000000..63b1ba8
--- /dev/null
+++ b/modules/usbaudio/audio_format.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "audio_format"
+/*#define LOG_NDEBUG 0*/
+
+#include "audio_format.h"
+
+#include <tinyalsa/asoundlib.h>
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+/*
+ * Maps from bit position in pcm_mask to PCM_ format constants.
+ */
+int8_t const pcm_format_value_map[50] = {
+ PCM_FORMAT_S8, /* 00 - SNDRV_PCM_FORMAT_S8 */
+ PCM_FORMAT_INVALID, /* 01 - SNDRV_PCM_FORMAT_U8 */
+ PCM_FORMAT_S16_LE, /* 02 - SNDRV_PCM_FORMAT_S16_LE */
+ PCM_FORMAT_INVALID, /* 03 - SNDRV_PCM_FORMAT_S16_BE */
+ PCM_FORMAT_INVALID, /* 04 - SNDRV_PCM_FORMAT_U16_LE */
+ PCM_FORMAT_INVALID, /* 05 - SNDRV_PCM_FORMAT_U16_BE */
+ PCM_FORMAT_S24_3LE, /* 06 - SNDRV_PCM_FORMAT_S24_LE */
+ PCM_FORMAT_INVALID, /* 07 - SNDRV_PCM_FORMAT_S24_BE */
+ PCM_FORMAT_INVALID, /* 08 - SNDRV_PCM_FORMAT_U24_LE */
+ PCM_FORMAT_INVALID, /* 09 - SNDRV_PCM_FORMAT_U24_BE */
+ PCM_FORMAT_S32_LE, /* 10 - SNDRV_PCM_FORMAT_S32_LE */
+ PCM_FORMAT_INVALID, /* 11 - SNDRV_PCM_FORMAT_S32_BE */
+ PCM_FORMAT_INVALID, /* 12 - SNDRV_PCM_FORMAT_U32_LE */
+ PCM_FORMAT_INVALID, /* 13 - SNDRV_PCM_FORMAT_U32_BE */
+ PCM_FORMAT_INVALID, /* 14 - SNDRV_PCM_FORMAT_FLOAT_LE */
+ PCM_FORMAT_INVALID, /* 15 - SNDRV_PCM_FORMAT_FLOAT_BE */
+ PCM_FORMAT_INVALID, /* 16 - SNDRV_PCM_FORMAT_FLOAT64_LE */
+ PCM_FORMAT_INVALID, /* 17 - SNDRV_PCM_FORMAT_FLOAT64_BE */
+ PCM_FORMAT_INVALID, /* 18 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE */
+ PCM_FORMAT_INVALID, /* 19 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE */
+ PCM_FORMAT_INVALID, /* 20 - SNDRV_PCM_FORMAT_MU_LAW */
+ PCM_FORMAT_INVALID, /* 21 - SNDRV_PCM_FORMAT_A_LAW */
+ PCM_FORMAT_INVALID, /* 22 - SNDRV_PCM_FORMAT_IMA_ADPCM */
+ PCM_FORMAT_INVALID, /* 23 - SNDRV_PCM_FORMAT_MPEG */
+ PCM_FORMAT_INVALID, /* 24 - SNDRV_PCM_FORMAT_GSM */
+ PCM_FORMAT_INVALID, /* 25 -> 30 (not assigned) */
+ PCM_FORMAT_INVALID,
+ PCM_FORMAT_INVALID,
+ PCM_FORMAT_INVALID,
+ PCM_FORMAT_INVALID,
+ PCM_FORMAT_INVALID,
+ PCM_FORMAT_INVALID, /* 31 - SNDRV_PCM_FORMAT_SPECIAL */
+ PCM_FORMAT_S24_3LE, /* 32 - SNDRV_PCM_FORMAT_S24_3LE */ /* ??? */
+ PCM_FORMAT_INVALID, /* 33 - SNDRV_PCM_FORMAT_S24_3BE */
+ PCM_FORMAT_INVALID, /* 34 - SNDRV_PCM_FORMAT_U24_3LE */
+ PCM_FORMAT_INVALID, /* 35 - SNDRV_PCM_FORMAT_U24_3BE */
+ PCM_FORMAT_INVALID, /* 36 - SNDRV_PCM_FORMAT_S20_3LE */
+ PCM_FORMAT_INVALID, /* 37 - SNDRV_PCM_FORMAT_S20_3BE */
+ PCM_FORMAT_INVALID, /* 38 - SNDRV_PCM_FORMAT_U20_3LE */
+ PCM_FORMAT_INVALID, /* 39 - SNDRV_PCM_FORMAT_U20_3BE */
+ PCM_FORMAT_INVALID, /* 40 - SNDRV_PCM_FORMAT_S18_3LE */
+ PCM_FORMAT_INVALID, /* 41 - SNDRV_PCM_FORMAT_S18_3BE */
+ PCM_FORMAT_INVALID, /* 42 - SNDRV_PCM_FORMAT_U18_3LE */
+ PCM_FORMAT_INVALID, /* 43 - SNDRV_PCM_FORMAT_U18_3BE */
+ PCM_FORMAT_INVALID, /* 44 - SNDRV_PCM_FORMAT_G723_24 */
+ PCM_FORMAT_INVALID, /* 45 - SNDRV_PCM_FORMAT_G723_24_1B */
+ PCM_FORMAT_INVALID, /* 46 - SNDRV_PCM_FORMAT_G723_40 */
+ PCM_FORMAT_INVALID, /* 47 - SNDRV_PCM_FORMAT_G723_40_1B */
+ PCM_FORMAT_INVALID, /* 48 - SNDRV_PCM_FORMAT_DSD_U8 */
+ PCM_FORMAT_INVALID /* 49 - SNDRV_PCM_FORMAT_DSD_U16_LE */
+};
+
+/*
+ * Scans the provided format mask and returns the first non-8 bit sample
+ * format supported by the devices.
+ */
+enum pcm_format get_pcm_format_for_mask(struct pcm_mask* mask)
+{
+ int num_slots = ARRAY_SIZE(mask->bits);
+ int bits_per_slot = sizeof(mask->bits[0]) * 8;
+
+ int table_size = ARRAY_SIZE(pcm_format_value_map);
+
+ int slot_index, bit_index, table_index;
+ table_index = 0;
+ int num_written = 0;
+ for (slot_index = 0; slot_index < num_slots && table_index < table_size; slot_index++) {
+ unsigned bit_mask = 1;
+ for (bit_index = 0; bit_index < bits_per_slot && table_index < table_size; bit_index++) {
+ /* skip any 8-bit formats */
+ if (table_index >= 2 && (mask->bits[slot_index] & bit_mask) != 0) {
+ /* just return the first one which will be at least 16-bit */
+ return (int)pcm_format_value_map[table_index];
+ }
+ bit_mask <<= 1;
+ table_index++;
+ }
+ }
+
+ return PCM_FORMAT_INVALID;
+}
diff --git a/modules/usbaudio/format.h b/modules/usbaudio/audio_format.h
similarity index 74%
rename from modules/usbaudio/format.h
rename to modules/usbaudio/audio_format.h
index e23935e..712ef67 100644
--- a/modules/usbaudio/format.h
+++ b/modules/usbaudio/audio_format.h
@@ -14,14 +14,13 @@
* limitations under the License.
*/
-#ifndef ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_FORMAT_H
-#define ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_FORMAT_H
+#ifndef ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_AUDIO_FORMAT_H
+#define ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_AUDIO_FORMAT_H
#include <system/audio.h>
#include <tinyalsa/asoundlib.h>
-audio_format_t get_format_for_mask(struct pcm_mask* mask);
enum pcm_format get_pcm_format_for_mask(struct pcm_mask* mask);
-#endif /* ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_FORMAT_H */
+#endif /* ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_AUDIO_FORMAT_H */
diff --git a/modules/usbaudio/audio_hw.c b/modules/usbaudio/audio_hw.c
index ad01833..f391b10 100644
--- a/modules/usbaudio/audio_hw.c
+++ b/modules/usbaudio/audio_hw.c
@@ -51,7 +51,7 @@
#include "alsa_device_profile.h"
#include "alsa_device_proxy.h"
-#include "logging.h"
+#include "audio_logging.h"
#define DEFAULT_INPUT_BUFFER_SIZE_MS 20
@@ -184,10 +184,40 @@
return num_in_samples * 2;
}
+/*
+ * Extract the card and device numbers from the supplied key/value pairs.
+ * kvpairs A null-terminated string containing the key/value pairs or card and device.
+ * i.e. "card=1;device=42"
+ * card A pointer to a variable to receive the parsed-out card number.
+ * device A pointer to a variable to receive the parsed-out device number.
+ * NOTE: The variables pointed to by card and device return -1 (undefined) if the
+ * associated key/value pair is not found in the provided string.
+ */
+static void parse_card_device_params(const char *kvpairs, int *card, int *device)
+{
+ struct str_parms * parms = str_parms_create_str(kvpairs);
+ char value[32];
+ int param_val;
+
+ // initialize to "undefined" state.
+ *card = -1;
+ *device = -1;
+
+ param_val = str_parms_get_str(parms, "card", value, sizeof(value));
+ if (param_val >= 0) {
+ *card = atoi(value);
+ }
+
+ param_val = str_parms_get_str(parms, "device", value, sizeof(value));
+ if (param_val >= 0) {
+ *device = atoi(value);
+ }
+
+ str_parms_destroy(parms);
+}
+
static char * device_get_parameters(alsa_device_profile * profile, const char * keys)
{
- ALOGV("usb:audio_hw::device_get_parameters() keys:%s", keys);
-
if (profile->card < 0 || profile->device < 0) {
return strdup("");
}
@@ -311,24 +341,15 @@
struct stream_out *out = (struct stream_out *)stream;
- char value[32];
- int param_val;
int routing = 0;
int ret_value = 0;
int card = -1;
int device = -1;
- struct str_parms * parms = str_parms_create_str(kvpairs);
pthread_mutex_lock(&out->dev->lock);
pthread_mutex_lock(&out->lock);
- param_val = str_parms_get_str(parms, "card", value, sizeof(value));
- if (param_val >= 0)
- card = atoi(value);
-
- param_val = str_parms_get_str(parms, "device", value, sizeof(value));
- if (param_val >= 0)
- device = atoi(value);
+ parse_card_device_params(kvpairs, &card, &device);
if (card >= 0 && device >= 0 && !profile_is_cached_for(out->profile, card, device)) {
/* cannot read pcm device info if playback is active */
@@ -349,7 +370,6 @@
pthread_mutex_unlock(&out->lock);
pthread_mutex_unlock(&out->dev->lock);
- str_parms_destroy(parms);
return ret_value;
}
@@ -480,10 +500,11 @@
audio_output_flags_t flags,
struct audio_config *config,
struct audio_stream_out **stream_out,
- const char *address __unused)
+ const char *address /*__unused*/)
{
- ALOGV("usb:audio_hw::out adev_open_output_stream() handle:0x%X, device:0x%X, flags:0x%X",
- handle, devices, flags);
+ ALOGV("usb:audio_hw::out adev_open_output_stream()"
+ "handle:0x%X, device:0x%X, flags:0x%X, addr:%s",
+ handle, devices, flags, address);
struct audio_device *adev = (struct audio_device *)dev;
@@ -514,13 +535,20 @@
out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
out->dev = adev;
-
+ pthread_mutex_lock(&adev->lock);
out->profile = &adev->out_profile;
// build this to hand to the alsa_device_proxy
struct pcm_config proxy_config;
memset(&proxy_config, 0, sizeof(proxy_config));
+ /* Pull out the card/device pair */
+ parse_card_device_params(address, &(out->profile->card), &(out->profile->device));
+
+ profile_read_device_info(out->profile);
+
+ pthread_mutex_unlock(&adev->lock);
+
int ret = 0;
/* Rate */
@@ -585,8 +613,9 @@
static void adev_close_output_stream(struct audio_hw_device *dev,
struct audio_stream_out *stream)
{
- ALOGV("usb:audio_hw::out adev_close_output_stream()");
struct stream_out *out = (struct stream_out *)stream;
+ ALOGV("usb:audio_hw::out adev_close_output_stream(c:%d d:%d)",
+ out->profile->card, out->profile->device);
/* Close the pcm device */
out_standby(&stream->common);
@@ -691,19 +720,10 @@
int card = -1;
int device = -1;
- struct str_parms * parms = str_parms_create_str(kvpairs);
-
pthread_mutex_lock(&in->dev->lock);
pthread_mutex_lock(&in->lock);
- /* Device Connection Message ("card=1,device=0") */
- param_val = str_parms_get_str(parms, "card", value, sizeof(value));
- if (param_val >= 0)
- card = atoi(value);
-
- param_val = str_parms_get_str(parms, "device", value, sizeof(value));
- if (param_val >= 0)
- device = atoi(value);
+ parse_card_device_params(kvpairs, &card, &device);
if (card >= 0 && device >= 0 && !profile_is_cached_for(in->profile, card, device)) {
/* cannot read pcm device info if playback is active */
@@ -725,8 +745,6 @@
pthread_mutex_unlock(&in->lock);
pthread_mutex_unlock(&in->dev->lock);
- str_parms_destroy(parms);
-
return ret_value;
}
@@ -890,7 +908,7 @@
struct audio_config *config,
struct audio_stream_in **stream_in,
audio_input_flags_t flags __unused,
- const char *address __unused,
+ const char *address /*__unused*/,
audio_source_t source __unused)
{
ALOGV("usb: in adev_open_input_stream() rate:%" PRIu32 ", chanMask:0x%" PRIX32 ", fmt:%" PRIu8,
@@ -921,12 +939,19 @@
in->stream.get_input_frames_lost = in_get_input_frames_lost;
in->dev = (struct audio_device *)dev;
+ pthread_mutex_lock(&in->dev->lock);
in->profile = &in->dev->in_profile;
struct pcm_config proxy_config;
memset(&proxy_config, 0, sizeof(proxy_config));
+ /* Pull out the card/device pair */
+ parse_card_device_params(address, &(in->profile->card), &(in->profile->device));
+
+ profile_read_device_info(in->profile);
+ pthread_mutex_unlock(&in->dev->lock);
+
/* Rate */
if (config->sample_rate == 0) {
proxy_config.rate = config->sample_rate = profile_get_default_sample_rate(in->profile);
diff --git a/modules/usbaudio/logging.c b/modules/usbaudio/audio_logging.c
similarity index 98%
rename from modules/usbaudio/logging.c
rename to modules/usbaudio/audio_logging.c
index 0a05511..77fbd51 100644
--- a/modules/usbaudio/logging.c
+++ b/modules/usbaudio/audio_logging.c
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-#define LOG_TAG "usb_logging"
+#define LOG_TAG "audio_logging"
/*#define LOG_NDEBUG 0*/
#include <string.h>
#include <log/log.h>
-#include "logging.h"
+#include "audio_logging.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
diff --git a/modules/usbaudio/logging.h b/modules/usbaudio/audio_logging.h
similarity index 79%
rename from modules/usbaudio/logging.h
rename to modules/usbaudio/audio_logging.h
index b5640ed..082e8b2 100644
--- a/modules/usbaudio/logging.h
+++ b/modules/usbaudio/audio_logging.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_LOGGING_H
-#define ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_LOGGING_H
+#ifndef ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_AUDIO_LOGGING_H
+#define ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_AUDIO_LOGGING_H
#include <tinyalsa/asoundlib.h>
@@ -23,4 +23,4 @@
void log_pcm_params(struct pcm_params * alsa_hw_params);
void log_pcm_config(struct pcm_config * config, const char* label);
-#endif /* ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_LOGGING_H */
+#endif /* ANDROID_HARDWARE_LIBHARDWARE_MODULES_USBAUDIO_AUDIO_LOGGING_H */
diff --git a/modules/usbaudio/format.c b/modules/usbaudio/format.c
deleted file mode 100644
index 6aac1d3..0000000
--- a/modules/usbaudio/format.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "usb_profile"
-/*#define LOG_NDEBUG 0*/
-
-#include "format.h"
-
-#include <tinyalsa/asoundlib.h>
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
-
-/*
- * Maps from bit position in pcm_mask to AUDIO_ format constants.
- */
-static audio_format_t const format_value_map[] = {
- AUDIO_FORMAT_PCM_8_BIT, /* 00 - SNDRV_PCM_FORMAT_S8 */
- AUDIO_FORMAT_PCM_8_BIT, /* 01 - SNDRV_PCM_FORMAT_U8 */
- AUDIO_FORMAT_PCM_16_BIT, /* 02 - SNDRV_PCM_FORMAT_S16_LE */
- AUDIO_FORMAT_INVALID, /* 03 - SNDRV_PCM_FORMAT_S16_BE */
- AUDIO_FORMAT_INVALID, /* 04 - SNDRV_PCM_FORMAT_U16_LE */
- AUDIO_FORMAT_INVALID, /* 05 - SNDRV_PCM_FORMAT_U16_BE */
- AUDIO_FORMAT_INVALID, /* 06 - SNDRV_PCM_FORMAT_S24_LE */
- AUDIO_FORMAT_INVALID, /* 07 - SNDRV_PCM_FORMAT_S24_BE */
- AUDIO_FORMAT_INVALID, /* 08 - SNDRV_PCM_FORMAT_U24_LE */
- AUDIO_FORMAT_INVALID, /* 09 - SNDRV_PCM_FORMAT_U24_BE */
- AUDIO_FORMAT_PCM_32_BIT, /* 10 - SNDRV_PCM_FORMAT_S32_LE */
- AUDIO_FORMAT_INVALID, /* 11 - SNDRV_PCM_FORMAT_S32_BE */
- AUDIO_FORMAT_INVALID, /* 12 - SNDRV_PCM_FORMAT_U32_LE */
- AUDIO_FORMAT_INVALID, /* 13 - SNDRV_PCM_FORMAT_U32_BE */
- AUDIO_FORMAT_PCM_FLOAT, /* 14 - SNDRV_PCM_FORMAT_FLOAT_LE */
- AUDIO_FORMAT_INVALID, /* 15 - SNDRV_PCM_FORMAT_FLOAT_BE */
- AUDIO_FORMAT_INVALID, /* 16 - SNDRV_PCM_FORMAT_FLOAT64_LE */
- AUDIO_FORMAT_INVALID, /* 17 - SNDRV_PCM_FORMAT_FLOAT64_BE */
- AUDIO_FORMAT_INVALID, /* 18 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE */
- AUDIO_FORMAT_INVALID, /* 19 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE */
- AUDIO_FORMAT_INVALID, /* 20 - SNDRV_PCM_FORMAT_MU_LAW */
- AUDIO_FORMAT_INVALID, /* 21 - SNDRV_PCM_FORMAT_A_LAW */
- AUDIO_FORMAT_INVALID, /* 22 - SNDRV_PCM_FORMAT_IMA_ADPCM */
- AUDIO_FORMAT_INVALID, /* 23 - SNDRV_PCM_FORMAT_MPEG */
- AUDIO_FORMAT_INVALID, /* 24 - SNDRV_PCM_FORMAT_GSM */
- AUDIO_FORMAT_INVALID, /* 25 -> 30 (not assigned) */
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID,
- AUDIO_FORMAT_INVALID, /* 31 - SNDRV_PCM_FORMAT_SPECIAL */
- AUDIO_FORMAT_PCM_24_BIT_PACKED, /* 32 - SNDRV_PCM_FORMAT_S24_3LE */
- AUDIO_FORMAT_INVALID, /* 33 - SNDRV_PCM_FORMAT_S24_3BE */
- AUDIO_FORMAT_INVALID, /* 34 - SNDRV_PCM_FORMAT_U24_3LE */
- AUDIO_FORMAT_INVALID, /* 35 - SNDRV_PCM_FORMAT_U24_3BE */
- AUDIO_FORMAT_INVALID, /* 36 - SNDRV_PCM_FORMAT_S20_3LE */
- AUDIO_FORMAT_INVALID, /* 37 - SNDRV_PCM_FORMAT_S20_3BE */
- AUDIO_FORMAT_INVALID, /* 38 - SNDRV_PCM_FORMAT_U20_3LE */
- AUDIO_FORMAT_INVALID, /* 39 - SNDRV_PCM_FORMAT_U20_3BE */
- AUDIO_FORMAT_INVALID, /* 40 - SNDRV_PCM_FORMAT_S18_3LE */
- AUDIO_FORMAT_INVALID, /* 41 - SNDRV_PCM_FORMAT_S18_3BE */
- AUDIO_FORMAT_INVALID, /* 42 - SNDRV_PCM_FORMAT_U18_3LE */
- AUDIO_FORMAT_INVALID, /* 43 - SNDRV_PCM_FORMAT_U18_3BE */
- AUDIO_FORMAT_INVALID, /* 44 - SNDRV_PCM_FORMAT_G723_24 */
- AUDIO_FORMAT_INVALID, /* 45 - SNDRV_PCM_FORMAT_G723_24_1B */
- AUDIO_FORMAT_INVALID, /* 46 - SNDRV_PCM_FORMAT_G723_40 */
- AUDIO_FORMAT_INVALID, /* 47 - SNDRV_PCM_FORMAT_G723_40_1B */
- AUDIO_FORMAT_INVALID, /* 48 - SNDRV_PCM_FORMAT_DSD_U8 */
- AUDIO_FORMAT_INVALID /* 49 - SNDRV_PCM_FORMAT_DSD_U16_LE */
-};
-
-audio_format_t get_format_for_mask(struct pcm_mask* mask)
-{
- int num_slots = sizeof(mask->bits) / sizeof(mask->bits[0]);
- int bits_per_slot = sizeof(mask->bits[0]) * 8;
-
- int table_size = sizeof(format_value_map) / sizeof(format_value_map[0]);
-
- int slot_index, bit_index, table_index;
- table_index = 0;
- int num_written = 0;
- for (slot_index = 0; slot_index < num_slots; slot_index++) {
- unsigned bit_mask = 1;
- for (bit_index = 0; bit_index < bits_per_slot; bit_index++) {
- /* don't return b-bit formats even if they are supported */
- if (table_index >= 2 && (mask->bits[slot_index] & bit_mask) != 0) {
- /* just return the first one */
- return table_index < table_size
- ? format_value_map[table_index]
- : AUDIO_FORMAT_INVALID;
- }
- bit_mask <<= 1;
- table_index++;
- }
- }
-
- return AUDIO_FORMAT_INVALID;
-}
-
-/*
- * Maps from bit position in pcm_mask to PCM_ format constants.
- */
-int8_t const pcm_format_value_map[50] = {
- PCM_FORMAT_S8, /* 00 - SNDRV_PCM_FORMAT_S8 */
- PCM_FORMAT_INVALID, /* 01 - SNDRV_PCM_FORMAT_U8 */
- PCM_FORMAT_S16_LE, /* 02 - SNDRV_PCM_FORMAT_S16_LE */
- PCM_FORMAT_INVALID, /* 03 - SNDRV_PCM_FORMAT_S16_BE */
- PCM_FORMAT_INVALID, /* 04 - SNDRV_PCM_FORMAT_U16_LE */
- PCM_FORMAT_INVALID, /* 05 - SNDRV_PCM_FORMAT_U16_BE */
- PCM_FORMAT_S24_3LE, /* 06 - SNDRV_PCM_FORMAT_S24_LE */
- PCM_FORMAT_INVALID, /* 07 - SNDRV_PCM_FORMAT_S24_BE */
- PCM_FORMAT_INVALID, /* 08 - SNDRV_PCM_FORMAT_U24_LE */
- PCM_FORMAT_INVALID, /* 09 - SNDRV_PCM_FORMAT_U24_BE */
- PCM_FORMAT_S32_LE, /* 10 - SNDRV_PCM_FORMAT_S32_LE */
- PCM_FORMAT_INVALID, /* 11 - SNDRV_PCM_FORMAT_S32_BE */
- PCM_FORMAT_INVALID, /* 12 - SNDRV_PCM_FORMAT_U32_LE */
- PCM_FORMAT_INVALID, /* 13 - SNDRV_PCM_FORMAT_U32_BE */
- PCM_FORMAT_INVALID, /* 14 - SNDRV_PCM_FORMAT_FLOAT_LE */
- PCM_FORMAT_INVALID, /* 15 - SNDRV_PCM_FORMAT_FLOAT_BE */
- PCM_FORMAT_INVALID, /* 16 - SNDRV_PCM_FORMAT_FLOAT64_LE */
- PCM_FORMAT_INVALID, /* 17 - SNDRV_PCM_FORMAT_FLOAT64_BE */
- PCM_FORMAT_INVALID, /* 18 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE */
- PCM_FORMAT_INVALID, /* 19 - SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE */
- PCM_FORMAT_INVALID, /* 20 - SNDRV_PCM_FORMAT_MU_LAW */
- PCM_FORMAT_INVALID, /* 21 - SNDRV_PCM_FORMAT_A_LAW */
- PCM_FORMAT_INVALID, /* 22 - SNDRV_PCM_FORMAT_IMA_ADPCM */
- PCM_FORMAT_INVALID, /* 23 - SNDRV_PCM_FORMAT_MPEG */
- PCM_FORMAT_INVALID, /* 24 - SNDRV_PCM_FORMAT_GSM */
- PCM_FORMAT_INVALID, /* 25 -> 30 (not assigned) */
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID,
- PCM_FORMAT_INVALID, /* 31 - SNDRV_PCM_FORMAT_SPECIAL */
- PCM_FORMAT_S24_3LE, /* 32 - SNDRV_PCM_FORMAT_S24_3LE */ /* ??? */
- PCM_FORMAT_INVALID, /* 33 - SNDRV_PCM_FORMAT_S24_3BE */
- PCM_FORMAT_INVALID, /* 34 - SNDRV_PCM_FORMAT_U24_3LE */
- PCM_FORMAT_INVALID, /* 35 - SNDRV_PCM_FORMAT_U24_3BE */
- PCM_FORMAT_INVALID, /* 36 - SNDRV_PCM_FORMAT_S20_3LE */
- PCM_FORMAT_INVALID, /* 37 - SNDRV_PCM_FORMAT_S20_3BE */
- PCM_FORMAT_INVALID, /* 38 - SNDRV_PCM_FORMAT_U20_3LE */
- PCM_FORMAT_INVALID, /* 39 - SNDRV_PCM_FORMAT_U20_3BE */
- PCM_FORMAT_INVALID, /* 40 - SNDRV_PCM_FORMAT_S18_3LE */
- PCM_FORMAT_INVALID, /* 41 - SNDRV_PCM_FORMAT_S18_3BE */
- PCM_FORMAT_INVALID, /* 42 - SNDRV_PCM_FORMAT_U18_3LE */
- PCM_FORMAT_INVALID, /* 43 - SNDRV_PCM_FORMAT_U18_3BE */
- PCM_FORMAT_INVALID, /* 44 - SNDRV_PCM_FORMAT_G723_24 */
- PCM_FORMAT_INVALID, /* 45 - SNDRV_PCM_FORMAT_G723_24_1B */
- PCM_FORMAT_INVALID, /* 46 - SNDRV_PCM_FORMAT_G723_40 */
- PCM_FORMAT_INVALID, /* 47 - SNDRV_PCM_FORMAT_G723_40_1B */
- PCM_FORMAT_INVALID, /* 48 - SNDRV_PCM_FORMAT_DSD_U8 */
- PCM_FORMAT_INVALID /* 49 - SNDRV_PCM_FORMAT_DSD_U16_LE */
-};
-
-/*
- * Scans the provided format mask and returns the first non-8 bit sample
- * format supported by the devices.
- */
-enum pcm_format get_pcm_format_for_mask(struct pcm_mask* mask)
-{
- int num_slots = ARRAY_SIZE(mask->bits);
- int bits_per_slot = sizeof(mask->bits[0]) * 8;
-
- int table_size = ARRAY_SIZE(pcm_format_value_map);
-
- int slot_index, bit_index, table_index;
- table_index = 0;
- int num_written = 0;
- for (slot_index = 0; slot_index < num_slots && table_index < table_size; slot_index++) {
- unsigned bit_mask = 1;
- for (bit_index = 0; bit_index < bits_per_slot && table_index < table_size; bit_index++) {
- /* skip any 8-bit formats */
- if (table_index >= 2 && (mask->bits[slot_index] & bit_mask) != 0) {
- /* just return the first one which will be at least 16-bit */
- return (int)pcm_format_value_map[table_index];
- }
- bit_mask <<= 1;
- table_index++;
- }
- }
-
- return PCM_FORMAT_INVALID;
-}