audio: select camcorder snd device according to camera orientation
Add audio parameter indicating use of front or back camera to select
proper input path tuning in camcorder mode.
Also take device orientation for stereo channel swaping.
Bug: 118022272
Test: verified with camera service patch sending camera facing parameter
Change-Id: If24b47d922aeedaaa144f4a5f4cacddce2c9eeaf
(cherry picked from commit 5f4ca9505df8177127c1f1a7d292d684ec30ff50)
(cherry picked from commit 5727439e2f5302a225310f4af3f373e9e8424495)
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9f90d93..9510ea1 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -7643,34 +7643,39 @@
adev->screen_off = true;
}
- if(!audio_extn_is_maxx_audio_enabled()) {
- ret = str_parms_get_int(parms, "rotation", &val);
- if (ret >= 0) {
- bool reverse_speakers = false;
- switch(val) {
- // FIXME: note that the code below assumes that the speakers are
- // in the correct placement relative to the user when the device
- // is rotated 90deg from its default rotation. This assumption
- // is device-specific, not platform-specific like this code.
- case 270:
- reverse_speakers = true;
- break;
- case 0:
- case 90:
- case 180:
- break;
- default:
- ALOGE("%s: unexpected rotation of %d", __func__, val);
- status = -EINVAL;
- }
- if (status == 0) {
- // check and set swap
- // - check if orientation changed and speaker active
- // - set rotation and cache the rotation value
- platform_check_and_set_swap_lr_channels(adev, reverse_speakers);
- }
+ ret = str_parms_get_int(parms, "rotation", &val);
+ if (ret >= 0) {
+ bool reverse_speakers = false;
+ int camera_rotation = CAMERA_ROTATION_LANDSCAPE;
+ switch (val) {
+ // FIXME: note that the code below assumes that the speakers are in the correct placement
+ // relative to the user when the device is rotated 90deg from its default rotation. This
+ // assumption is device-specific, not platform-specific like this code.
+ case 270:
+ reverse_speakers = true;
+ camera_rotation = CAMERA_ROTATION_INVERT_LANDSCAPE;
+ break;
+ case 0:
+ case 180:
+ camera_rotation = CAMERA_ROTATION_PORTRAIT;
+ break;
+ case 90:
+ camera_rotation = CAMERA_ROTATION_LANDSCAPE;
+ break;
+ default:
+ ALOGE("%s: unexpected rotation of %d", __func__, val);
+ status = -EINVAL;
}
- }
+ if (status == 0) {
+ // check and set swap
+ // - check if orientation changed and speaker active
+ // - set rotation and cache the rotation value
+ adev->camera_orientation =
+ (adev->camera_orientation & ~CAMERA_ROTATION_MASK) | camera_rotation;
+ if (!audio_extn_is_maxx_audio_enabled())
+ platform_check_and_set_swap_lr_channels(adev, reverse_speakers);
+ }
+ }
ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_SCO_WB, value, sizeof(value));
if (ret >= 0) {
@@ -7782,6 +7787,32 @@
}
}
+ //FIXME: to be replaced by proper video capture properties API
+ ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_CAMERA_FACING, value, sizeof(value));
+ if (ret >= 0) {
+ int camera_facing = CAMERA_FACING_BACK;
+ if (strcmp(value, AUDIO_PARAMETER_VALUE_FRONT) == 0)
+ camera_facing = CAMERA_FACING_FRONT;
+ else if (strcmp(value, AUDIO_PARAMETER_VALUE_BACK) == 0)
+ camera_facing = CAMERA_FACING_BACK;
+ else {
+ ALOGW("%s: invalid camera facing value: %s", __func__, value);
+ goto done;
+ }
+ adev->camera_orientation =
+ (adev->camera_orientation & ~CAMERA_FACING_MASK) | camera_facing;
+ struct audio_usecase *usecase;
+ struct listnode *node;
+ list_for_each(node, &adev->usecase_list) {
+ usecase = node_to_item(node, struct audio_usecase, list);
+ struct stream_in *in = usecase->stream.in;
+ if (usecase->type == PCM_CAPTURE && in != NULL &&
+ in->source == AUDIO_SOURCE_CAMCORDER && !in->standby) {
+ select_devices(adev, in->usecase);
+ }
+ }
+ }
+
audio_extn_set_parameters(adev, parms);
done:
str_parms_destroy(parms);
@@ -9177,6 +9208,8 @@
adev->mic_break_enabled = property_get_bool("vendor.audio.mic_break", false);
+ adev->camera_orientation = CAMERA_DEFAULT;
+
if ((property_get("vendor.audio_hal.period_multiplier",value,NULL) > 0) ||
(property_get("audio_hal.period_multiplier",value,NULL) > 0)) {
af_period_multiplier = atoi(value);
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 1a04cff..8df4437 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -245,6 +245,33 @@
OFFLOAD_CMD_ERROR, /* offload playback hit some error */
};
+/*
+ * Camera selection indicated via set_parameters "cameraFacing=front|back and
+ * "rotation=0|90|180|270""
+ */
+enum {
+ CAMERA_FACING_BACK = 0x0,
+ CAMERA_FACING_FRONT = 0x1,
+ CAMERA_FACING_MASK = 0x0F,
+ CAMERA_ROTATION_LANDSCAPE = 0x0,
+ CAMERA_ROTATION_INVERT_LANDSCAPE = 0x10,
+ CAMERA_ROTATION_PORTRAIT = 0x20,
+ CAMERA_ROTATION_MASK = 0xF0,
+ CAMERA_BACK_LANDSCAPE = (CAMERA_FACING_BACK|CAMERA_ROTATION_LANDSCAPE),
+ CAMERA_BACK_INVERT_LANDSCAPE = (CAMERA_FACING_BACK|CAMERA_ROTATION_INVERT_LANDSCAPE),
+ CAMERA_BACK_PORTRAIT = (CAMERA_FACING_BACK|CAMERA_ROTATION_PORTRAIT),
+ CAMERA_FRONT_LANDSCAPE = (CAMERA_FACING_FRONT|CAMERA_ROTATION_LANDSCAPE),
+ CAMERA_FRONT_INVERT_LANDSCAPE = (CAMERA_FACING_FRONT|CAMERA_ROTATION_INVERT_LANDSCAPE),
+ CAMERA_FRONT_PORTRAIT = (CAMERA_FACING_FRONT|CAMERA_ROTATION_PORTRAIT),
+
+ CAMERA_DEFAULT = CAMERA_BACK_LANDSCAPE,
+};
+
+//FIXME: to be replaced by proper video capture properties API
+#define AUDIO_PARAMETER_KEY_CAMERA_FACING "cameraFacing"
+#define AUDIO_PARAMETER_VALUE_FRONT "front"
+#define AUDIO_PARAMETER_VALUE_BACK "back"
+
enum {
OFFLOAD_STATE_IDLE,
OFFLOAD_STATE_PLAYING,
@@ -505,6 +532,7 @@
struct audio_device {
struct audio_hw_device device;
+
pthread_mutex_t lock; /* see note below on mutex acquisition order */
pthread_mutex_t cal_lock;
struct mixer *mixer;
@@ -609,6 +637,7 @@
struct listnode active_inputs_list;
struct listnode active_outputs_list;
bool use_old_pspd_mix_ctrl;
+ int camera_orientation; /* CAMERA_BACK_LANDSCAPE ... CAMERA_FRONT_PORTRAIT */
};
int select_devices(struct audio_device *adev,
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index efbd0ae..095028d 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -600,7 +600,7 @@
[SND_DEVICE_IN_BT_SCO_MIC_SWB] = "bt-sco-mic-swb",
[SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = "bt-sco-mic-swb",
[SND_DEVICE_IN_BT_A2DP] = "bt-a2dp-cap",
- [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
+ [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
[SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
[SND_DEVICE_IN_VOICE_DMIC_SB] = "voice-dmic-ef",
[SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
@@ -674,6 +674,11 @@
[SND_DEVICE_IN_LINE] = "line-in",
[SND_DEVICE_IN_HANDSET_6MIC] = "handset-6mic",
[SND_DEVICE_IN_HANDSET_8MIC] = "handset-8mic",
+ [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
+ [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
+ [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
+ [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
+ [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
[SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset",
[SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker",
[SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones",
@@ -845,7 +850,7 @@
[SND_DEVICE_IN_BT_SCO_MIC_SWB] = 38,
[SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = 123,
[SND_DEVICE_IN_BT_A2DP] = 21,
- [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
+ [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 4,
[SND_DEVICE_IN_VOICE_DMIC] = 41,
[SND_DEVICE_IN_VOICE_DMIC_SB] = 167,
[SND_DEVICE_IN_VOICE_DMIC_TMUS] = 89,
@@ -918,6 +923,11 @@
[SND_DEVICE_OUT_VOIP_HANDSET] = 133,
[SND_DEVICE_OUT_VOIP_SPEAKER] = 132,
[SND_DEVICE_OUT_VOIP_HEADPHONES] = 134,
+ [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 4,
+ [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 4,
+ [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 4,
+ [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 4,
+ [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 4,
};
struct name_to_index {
@@ -1061,7 +1071,7 @@
{TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_SWB)},
{TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC)},
{TO_NAME_INDEX(SND_DEVICE_IN_BT_A2DP)},
- {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
+ {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_SB)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
@@ -1133,6 +1143,13 @@
{TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_TX)},
{TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_RX_TX)},
{TO_NAME_INDEX(SND_DEVICE_IN_LINE)},
+ {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
+ {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
+ {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
+ {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
+ {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
+ /* For legacy xml file parsing */
+ {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
};
static char * backend_tag_table[SND_DEVICE_MAX] = {0};
@@ -2078,6 +2095,7 @@
hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB] = strdup("SLIMBUS_0_TX");
hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
+ hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_SB] = strdup("SLIMBUS_0_TX");
hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
@@ -2179,7 +2197,11 @@
hw_interface_table[SND_DEVICE_OUT_VOIP_HANDSET] = strdup("SLIMBUS_0_RX");
hw_interface_table[SND_DEVICE_OUT_VOIP_SPEAKER] = strdup("SLIMBUS_0_RX");
hw_interface_table[SND_DEVICE_OUT_VOIP_HEADPHONES] = strdup("SLIMBUS_6_RX");
-
+ hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
+ hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
+ hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
+ hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
+ hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
/*remove ALAC & APE from DSP decoder list based on software decoder availability*/
@@ -5932,7 +5954,30 @@
} else if (source == AUDIO_SOURCE_CAMCORDER) {
if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
in_device & AUDIO_DEVICE_IN_BACK_MIC) {
-
+ switch (adev->camera_orientation) {
+ case CAMERA_BACK_LANDSCAPE:
+ snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
+ break;
+ case CAMERA_BACK_INVERT_LANDSCAPE:
+ snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
+ break;
+ case CAMERA_BACK_PORTRAIT:
+ snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
+ break;
+ case CAMERA_FRONT_LANDSCAPE:
+ snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
+ break;
+ case CAMERA_FRONT_INVERT_LANDSCAPE:
+ snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
+ break;
+ case CAMERA_FRONT_PORTRAIT:
+ snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
+ break;
+ default:
+ ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
+ snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
+ break;
+ }
if (str_bitwidth == 16) {
if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
(my_data->source_mic_type & SOURCE_DUAL_MIC) &&
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index 6203cf8..41aa346 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -229,7 +229,7 @@
SND_DEVICE_IN_BT_SCO_MIC_SWB,
SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC,
SND_DEVICE_IN_BT_A2DP,
- SND_DEVICE_IN_CAMCORDER_MIC,
+ SND_DEVICE_IN_CAMCORDER_LANDSCAPE,
SND_DEVICE_IN_VOICE_DMIC,
SND_DEVICE_IN_VOICE_DMIC_SB,
SND_DEVICE_IN_VOICE_DMIC_TMUS,
@@ -303,10 +303,16 @@
SND_DEVICE_IN_INCALL_REC_TX,
SND_DEVICE_IN_INCALL_REC_RX_TX,
SND_DEVICE_IN_LINE,
+ SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE,
+ SND_DEVICE_IN_CAMCORDER_PORTRAIT,
+ SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE,
+ SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE,
+ SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT,
SND_DEVICE_IN_END,
SND_DEVICE_MAX = SND_DEVICE_IN_END,
-
+ /* For legacy xml file parsing */
+ SND_DEVICE_IN_CAMCORDER_MIC = SND_DEVICE_IN_CAMCORDER_LANDSCAPE,
};
#define INPUT_SAMPLING_RATE_DSD64 2822400
#define INPUT_SAMPLING_RATE_DSD128 5644800