Skip to content

Commit

Permalink
Dynamic HDMI device selection
Browse files Browse the repository at this point in the history
Check for the HDMI device status
and assign the device id

Tracked-On:
  • Loading branch information
gkdeepa committed Aug 12, 2021
1 parent 183d813 commit 2b0e5b4
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions hdmi/tinyaudio_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <stdint.h>
#include <sys/time.h>
#include <stdlib.h>
#include <string.h>

#include <cutils/log.h>
#include <cutils/str_parms.h>
Expand All @@ -73,6 +74,8 @@
#define DEFAULT_DEVICE 3
#define DEFAULT_DEVICE_EHL 7

#define MAX_HDMI_DEVICES 20

/*this is used to avoid starvation*/
#define LATENCY_TO_BUFFER_SIZE_RATIO 2

Expand Down Expand Up @@ -111,6 +114,7 @@ struct pcm_config pcm_config_default = {
.period_count = 4,
.format = PCM_FORMAT_S16_LE,
};
static int parse_hdmi_device_number();

#define CHANNEL_MASK_MAX 3
struct audio_device {
Expand Down Expand Up @@ -228,22 +232,24 @@ static int start_output_stream(struct stream_out *out)
struct audio_device *adev = out->dev;
struct pcm_params *params;
int device = 0;

int check_device =0;
ALOGV("%s enter",__func__);

if ((adev->card < 0) || (adev->device < 0)){
char value[PROPERTY_VALUE_MAX];

/*this will be updated once the hot plug intent
sends these information.*/
/* hard coded assignment of card can be removed with
parse_hdmi_device_number implementation */
adev->card = DEFAULT_CARD;
property_get("ro.vendor.hdmi.audio", value, "0");
if (!strcmp(value,"ehl")) {
adev->device = DEFAULT_DEVICE_EHL;
} else {
adev->device = DEFAULT_DEVICE;
}

adev->device = parse_hdmi_device_number();
ALOGV("%s : Setting default card/ device %d,%d",__func__,adev->card,adev->device);
}

Expand Down Expand Up @@ -419,7 +425,46 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
ALOGV("%s exit",__func__);
return 0;
}
static int parse_hdmi_device_number()
{
struct mixer *mixer;
int card = 0;
struct mixer_ctl *ctl;
enum mixer_ctl_type mixer_type;
unsigned int num_values;
unsigned int i,id;
bool device_status;

ALOGV("%s enter",__func__);
card = get_card_number_by_name("PCH");
mixer = mixer_open(card);
if (!mixer) {
ALOGE(" Failed to open mixer\n");
return -1;
}
for(i=0; i < MAX_HDMI_DEVICES; i++ ) {
char ctl_name[100] = "HDMI/DP,pcm=";
char buffer[10];
sprintf(buffer, "%d", i);
strcat(ctl_name,buffer);
strcat(ctl_name," Jack");
ALOGV("ctl_name %s",ctl_name);
ctl = mixer_get_ctl_by_name(mixer, ctl_name);
if(ctl) {
mixer_type = mixer_ctl_get_type(ctl);
num_values = mixer_ctl_get_num_values(ctl);
device_status = mixer_ctl_get_value(ctl, 1);
ALOGV(" mixer_ctl_get_value %s", mixer_ctl_get_value(ctl, 1) ? "On" : "Off");
}
if(device_status == 1) {
ALOGV("status of device %d is ON",i);
ALOGV("%s exit",__func__);
return i;
}
}
ALOGV("%s exit",__func__);
return DEFAULT_DEVICE;
}
static int parse_channel_map()
{
struct mixer *mixer;
Expand Down

0 comments on commit 2b0e5b4

Please sign in to comment.