Merge "hal: add line in/out transcode loopback support"

This commit is contained in:
Linux Build Service Account 2018-09-25 07:50:15 -07:00 committed by Gerrit - the friendly Code Review server
commit 777d4acbc8
2 changed files with 58 additions and 47 deletions

View File

@ -66,17 +66,6 @@
#include <sound/compress_offload.h>
#include <system/audio.h>
/*
* Unique patch handle ID = (unique_patch_handle_type << 8 | patch_handle_num)
* Eg : HDMI_IN_SPKR_OUT handles can be 0x1000, 0x1001 and so on..
*/
typedef enum patch_handle_type {
AUDIO_PATCH_HDMI_IN_SPKR_OUT=0x10,
AUDIO_PATCH_SPDIF_IN_SPKR_OUT,
AUDIO_PATCH_MIC_IN_SPKR_OUT,
AUDIO_PATCH_MIC_IN_HDMI_OUT
} patch_handle_type_t;
typedef enum patch_state {
PATCH_INACTIVE,// Patch is not created yet
PATCH_CREATED, // Patch created but not in running state yet, probably due
@ -190,9 +179,12 @@ bool is_supported_sink_device(audio_devices_t sink_device_mask)
/* Get patch type based on source and sink ports configuration */
/* Only ports of type 'DEVICE' are supported */
patch_handle_type_t get_loopback_patch_type(loopback_patch_t* loopback_patch)
audio_patch_handle_t get_loopback_patch_type(loopback_patch_t* loopback_patch)
{
bool is_source_hdmi=false, is_sink_supported=false;
bool is_source_supported = false, is_sink_supported = false;
audio_devices_t source_device = loopback_patch->loopback_source.ext.device.type;
audio_devices_t sink_device = loopback_patch->loopback_sink.ext.device.type;
if (loopback_patch->patch_handle_id != PATCH_HANDLE_INVALID) {
ALOGE("%s, Patch handle already exists", __func__);
return loopback_patch->patch_handle_id;
@ -201,8 +193,8 @@ patch_handle_type_t get_loopback_patch_type(loopback_patch_t* loopback_patch)
if (loopback_patch->loopback_source.role == AUDIO_PORT_ROLE_SOURCE) {
switch (loopback_patch->loopback_source.type) {
case AUDIO_PORT_TYPE_DEVICE :
if ((loopback_patch->loopback_source.config_mask &
AUDIO_PORT_CONFIG_FORMAT) && (loopback_patch->loopback_source.ext.device.type & AUDIO_DEVICE_IN_HDMI)) {
if ((loopback_patch->loopback_source.config_mask & AUDIO_PORT_CONFIG_FORMAT)) {
if (loopback_patch->loopback_source.ext.device.type & AUDIO_DEVICE_IN_HDMI) {
switch (loopback_patch->loopback_source.format) {
case AUDIO_FORMAT_PCM:
case AUDIO_FORMAT_PCM_16_BIT:
@ -211,10 +203,13 @@ patch_handle_type_t get_loopback_patch_type(loopback_patch_t* loopback_patch)
case AUDIO_FORMAT_IEC61937:
case AUDIO_FORMAT_AC3:
case AUDIO_FORMAT_E_AC3:
is_source_hdmi = true;
is_source_supported = true;
break;
}
} else if (loopback_patch->loopback_source.ext.device.type & AUDIO_DEVICE_IN_LINE) {
is_source_supported = true;
}
}
}
break;
default :
break;
@ -247,8 +242,8 @@ patch_handle_type_t get_loopback_patch_type(loopback_patch_t* loopback_patch)
//Unsupported as of now, need to extend for other sink types
}
}
if (is_source_hdmi && is_sink_supported) {
return AUDIO_PATCH_HDMI_IN_SPKR_OUT;
if (is_source_supported && is_sink_supported) {
return source_device | sink_device;
}
ALOGE("%s, Unsupported source or sink port config", __func__);
return loopback_patch->patch_handle_id;
@ -613,7 +608,7 @@ int audio_extn_hw_loopback_create_audio_patch(struct audio_hw_device *dev,
audio_patch_handle_t *handle)
{
int status = 0;
patch_handle_type_t loopback_patch_type=0x0;
audio_patch_handle_t loopback_patch_id = 0x0;
loopback_patch_t loopback_patch, *active_loopback_patch = NULL;
ALOGV("%s : Create audio patch begin", __func__);
@ -656,9 +651,9 @@ int audio_extn_hw_loopback_create_audio_patch(struct audio_hw_device *dev,
audio_port_config));
/* Get loopback patch type based on source and sink ports configuration */
loopback_patch_type = get_loopback_patch_type(active_loopback_patch);
loopback_patch_id = get_loopback_patch_type(active_loopback_patch);
if (loopback_patch_type == PATCH_HANDLE_INVALID) {
if (loopback_patch_id == PATCH_HANDLE_INVALID) {
ALOGE("%s, Unsupported patch type", __func__);
status = -EINVAL;
goto exit_create_patch;
@ -670,8 +665,7 @@ int audio_extn_hw_loopback_create_audio_patch(struct audio_hw_device *dev,
&active_loopback_patch->loopback_sink);
// Lock patch database, create patch handle and add patch handle to the list
active_loopback_patch->patch_handle_id = (loopback_patch_type << 8 |
audio_loopback_mod->patch_db.num_patches);
active_loopback_patch->patch_handle_id = loopback_patch_id;
/* Is usecase transcode loopback? If yes, invoke loopback driver */
if ((active_loopback_patch->loopback_source.type == AUDIO_PORT_TYPE_DEVICE)

View File

@ -95,9 +95,6 @@ const char *log_filename = NULL;
#define TRANSCODE_LOOPBACK_SOURCE_PORT_ID 0x4C00
#define TRANSCODE_LOOPBACK_SINK_PORT_ID 0x4D00
#define DEVICE_SOURCE 0
#define DEVICE_SINK 1
#define MAX_MODULE_NAME_LENGTH 100
#define DEV_NODE_CHECK(node_name,node_id) strncmp(node_name,node_id,strlen(node_name))
@ -110,7 +107,8 @@ typedef enum source_port_type {
SOURCE_PORT_NONE,
SOURCE_PORT_HDMI,
SOURCE_PORT_SPDIF,
SOURCE_PORT_MIC
SOURCE_PORT_MIC,
SOURCE_PORT_BT
} source_port_type_t;
typedef enum source_port_state {
@ -449,12 +447,15 @@ void source_data_event_handler(transcode_loopback_config_t *transcode_loopback_c
{
int status =0;
source_port_type_t source_port_type = transcode_loopback_config->source_port_config.source_port_type;
status = read_and_set_source_config(source_port_type,&transcode_loopback_config->source_config);
if ( status )
{
fprintf(log_file,"\nFailure in source port configuration with status: %d\n", status);
return;
if (source_port_type == SOURCE_PORT_HDMI) {
status = read_and_set_source_config(source_port_type,&transcode_loopback_config->source_config);
if (status) {
fprintf(log_file,"\nFailure in source port configuration with status: %d\n", status);
return;
}
} else {
transcode_loopback_config->source_port_config.source_port_state = SOURCE_PORT_CONFIG_CHANGED;
}
fprintf(log_file,"\nSource port state : %d\n", transcode_loopback_config->source_port_config.source_port_state);
@ -545,17 +546,27 @@ void process_loopback_data(void *ptr)
exit_process_thread = true;
}
void set_device(uint32_t device_type, uint32_t device_id)
void set_device(uint32_t source_device, uint32_t sink_device)
{
transcode_loopback_config_t *transcode_loopback_config = &g_trnscode_loopback_config;
switch( device_type )
{
case DEVICE_SINK:
transcode_loopback_config->sink_config.ext.device.type = device_id;
break;
case DEVICE_SOURCE:
transcode_loopback_config->source_config.ext.device.type = device_id;
break;
transcode_loopback_config->sink_config.ext.device.type = sink_device;
transcode_loopback_config->source_config.ext.device.type = source_device;
switch (source_device) {
case AUDIO_DEVICE_IN_SPDIF:
g_trnscode_loopback_config.source_port_config.source_port_type = SOURCE_PORT_SPDIF;
break;
case AUDIO_DEVICE_IN_BLUETOOTH_A2DP:
g_trnscode_loopback_config.source_port_config.source_port_type = SOURCE_PORT_BT;
break;
case AUDIO_DEVICE_IN_LINE:
g_trnscode_loopback_config.source_port_config.source_port_type = SOURCE_PORT_MIC;
break;
case AUDIO_DEVICE_IN_HDMI:
default:
g_trnscode_loopback_config.source_port_config.source_port_type = SOURCE_PORT_HDMI;
break;
}
}
@ -563,6 +574,7 @@ int main(int argc, char *argv[]) {
int status = 0;
uint32_t play_duration_in_seconds = 600,play_duration_elapsed_msec = 0,play_duration_in_msec = 0, sink_device = 2, volume_in_millibels = 0;
uint32_t source_device = AUDIO_DEVICE_IN_HDMI;
source_port_type_t source_port_type = SOURCE_PORT_NONE;
log_file = stdout;
transcode_loopback_config_t *transcode_loopback_config = NULL;
@ -570,7 +582,8 @@ int main(int argc, char *argv[]) {
struct option long_options[] = {
/* These options set a flag. */
{"sink-device", required_argument, 0, 'd'},
{"sink-device", required_argument, 0, 'o'},
{"source-device", required_argument, 0, 'i'},
{"play-duration", required_argument, 0, 'p'},
{"play-volume", required_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
@ -582,15 +595,18 @@ int main(int argc, char *argv[]) {
while ((opt = getopt_long(argc,
argv,
"-d:p:v:h",
"-o:i:p:v:h",
long_options,
&option_index)) != -1) {
fprintf(log_file, "for argument %c, value is %s\n", opt, optarg);
switch (opt) {
case 'd':
sink_device = atoi(optarg);
case 'o':
sink_device = atoll(optarg);
break;
case 'i':
source_device = atoll(optarg);
break;
case 'p':
play_duration_in_seconds = atoi(optarg);
@ -606,6 +622,7 @@ int main(int argc, char *argv[]) {
}
}
fprintf(log_file, "source %#x sink %#x\n", source_device, sink_device);
fprintf(log_file,"\nTranscode loopback test begin\n");
if (play_duration_in_seconds < 0 | play_duration_in_seconds > 360000) {
fprintf(log_file,
@ -626,7 +643,7 @@ int main(int argc, char *argv[]) {
transcode_loopback_config = &g_trnscode_loopback_config;
/* Set devices */
set_device(DEVICE_SINK,sink_device);
set_device(source_device, sink_device);
/* Load HAL */
fprintf(log_file,"\nLoading HAL for loopback usecase begin\n");