Skip to content

Commit

Permalink
Merge pull request #33 from jusa/mer1188
Browse files Browse the repository at this point in the history
Add basic support for Android 5.1.
  • Loading branch information
jusa committed Jul 22, 2015
2 parents c63c9f8 + 50bdc79 commit 3fb96ea
Show file tree
Hide file tree
Showing 9 changed files with 419 additions and 21 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Supported Android versions:
* 4.1.x with Qualcomm extensions (tested with 4.1.2)
* 4.2.x
* 4.4.x
* 5.1

Headers for defining devices and strings for different droid versions are in
src/droid/droid-util-XXX.h
Expand Down
8 changes: 7 additions & 1 deletion src/droid/droid-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,13 @@ pa_sink *pa_droid_sink_new(pa_module *m,
dev_out,
flags,
&config_out,
&u->stream_out);
&u->stream_out
#if DROID_HAL >= 3
/* Go with empty address, should work
* with most devices for now. */
, NULL
#endif
);
pa_droid_hw_module_unlock(u->hw_module);

if (!u->stream_out) {
Expand Down
8 changes: 7 additions & 1 deletion src/droid/droid-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,13 @@ pa_source *pa_droid_source_new(pa_module *m,
u->hw_module->stream_in_id++,
dev_in,
&config_in,
&u->stream);
&u->stream
#if DROID_HAL >= 3
, AUDIO_INPUT_FLAG_NONE /* Default to no input flags */
, NULL /* Don't define address */
, AUDIO_SOURCE_DEFAULT /* Default audio source */
#endif
);
pa_droid_hw_module_unlock(u->hw_module);

if (ret < 0 || !u->stream) {
Expand Down
4 changes: 3 additions & 1 deletion src/droid/droid-util-41qc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef _ANDROID_UTIL_V412_H_
#define _ANDROID_UTIL_V412_H_

#define DROID_HAL 1

#ifdef DROID_DEVICE_SBJ
#define QCOM_HARDWARE
#endif
Expand Down Expand Up @@ -195,7 +197,7 @@ struct string_conversion string_conversion_table_audio_source_fancy[] = {
};

/* Flags */
struct string_conversion string_conversion_table_flag[] = {
struct string_conversion string_conversion_table_output_flag[] = {
STRING_ENTRY(AUDIO_OUTPUT_FLAG_NONE),
STRING_ENTRY(AUDIO_OUTPUT_FLAG_DIRECT),
STRING_ENTRY(AUDIO_OUTPUT_FLAG_PRIMARY),
Expand Down
4 changes: 2 additions & 2 deletions src/droid/droid-util-42.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef _ANDROID_UTIL_V42_H_
#define _ANDROID_UTIL_V42_H_

#define HAL_V2
#define DROID_HAL 2

#include <hardware/audio.h>
#include <hardware_legacy/audio_policy_conf.h>
Expand Down Expand Up @@ -216,7 +216,7 @@ struct string_conversion string_conversion_table_audio_source_fancy[] = {
};

/* Flags */
struct string_conversion string_conversion_table_flag[] = {
struct string_conversion string_conversion_table_output_flag[] = {
STRING_ENTRY(AUDIO_OUTPUT_FLAG_NONE),
STRING_ENTRY(AUDIO_OUTPUT_FLAG_DIRECT),
STRING_ENTRY(AUDIO_OUTPUT_FLAG_PRIMARY),
Expand Down
4 changes: 2 additions & 2 deletions src/droid/droid-util-44.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef _ANDROID_UTIL_V44_H_
#define _ANDROID_UTIL_V44_H_

#define HAL_V2
#define DROID_HAL 2

// Android v4.4 has SPEAKER_DRC_ENABLED_TAG, so might the future versions
#define DROID_HAVE_DRC
Expand Down Expand Up @@ -242,7 +242,7 @@ struct string_conversion string_conversion_table_audio_source_fancy[] = {
};

/* Flags */
struct string_conversion string_conversion_table_flag[] = {
struct string_conversion string_conversion_table_output_flag[] = {
STRING_ENTRY(AUDIO_OUTPUT_FLAG_NONE),
STRING_ENTRY(AUDIO_OUTPUT_FLAG_DIRECT),
STRING_ENTRY(AUDIO_OUTPUT_FLAG_PRIMARY),
Expand Down
342 changes: 342 additions & 0 deletions src/droid/droid-util-51.h

Large diffs are not rendered by default.

56 changes: 46 additions & 10 deletions src/droid/droid-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ static char *list_string(struct string_conversion *list, uint32_t flags) {
char *str = NULL;
char *tmp;

#ifdef HAL_V2
#if DROID_HAL >= 2
if (flags & AUDIO_DEVICE_BIT_IN)
flags &= ~AUDIO_DEVICE_BIT_IN;
#endif

for (unsigned int i = 0; list[i].str; i++) {
#ifdef HAL_V2
#if DROID_HAL >= 2
if (list[i].value & AUDIO_DEVICE_BIT_IN) {
if (popcount(list[i].value & ~AUDIO_DEVICE_BIT_IN) != 1)
continue;
Expand Down Expand Up @@ -171,15 +171,15 @@ char *pa_list_string_input_device(audio_devices_t devices) {

/* Flags */
bool pa_string_convert_flag_num_to_str(audio_output_flags_t value, const char **to_str) {
return string_convert_num_to_str(string_conversion_table_flag, (uint32_t) value, to_str);
return string_convert_num_to_str(string_conversion_table_output_flag, (uint32_t) value, to_str);
}

bool pa_string_convert_flag_str_to_num(const char *str, audio_output_flags_t *to_value) {
return string_convert_str_to_num(string_conversion_table_flag, str, (uint32_t*) to_value);
return string_convert_str_to_num(string_conversion_table_output_flag, str, (uint32_t*) to_value);
}

char *pa_list_string_flags(audio_output_flags_t flags) {
return list_string(string_conversion_table_flag, flags);
return list_string(string_conversion_table_output_flag, flags);
}

bool pa_input_device_default_audio_source(audio_devices_t input_device, audio_source_t *default_source)
Expand Down Expand Up @@ -251,6 +251,14 @@ static bool parse_sampling_rates(const char *fn, const unsigned ln,
while ((entry = pa_split(str, "|", &state))) {
int32_t val;

#if DROID_HAL >= 3
if (pos == 0 && pa_streq(entry, "dynamic")) {
sampling_rates[pos++] = (uint32_t) -1;
pa_xfree(entry);
break;
}
#endif

if (pos == AUDIO_MAX_SAMPLING_RATES) {
pa_log("[%s:%u] Too many sample rate entries (> %d)", fn, ln, AUDIO_MAX_SAMPLING_RATES);
pa_xfree(entry);
Expand Down Expand Up @@ -307,6 +315,14 @@ static bool parse_formats(const char *fn, const unsigned ln,
pa_assert(str);
pa_assert(formats);

#if DROID_HAL >= 3
/* Needs to be probed later */
if (pa_streq(str, "dynamic")) {
*formats = 0;
return true;
}
#endif

count = parse_list(string_conversion_table_format, str, formats, &unknown);

return check_and_log(fn, ln, "formats", count, str, unknown, false);
Expand Down Expand Up @@ -352,7 +368,7 @@ static bool parse_devices(const char *fn, const unsigned ln,
count, str, unknown, must_have_all);
}

static bool parse_flags(const char *fn, const unsigned ln,
static bool parse_output_flags(const char *fn, const unsigned ln,
const char *str, audio_output_flags_t *flags) {
int count;
char *unknown = NULL;
Expand All @@ -361,10 +377,26 @@ static bool parse_flags(const char *fn, const unsigned ln,
pa_assert(str);
pa_assert(flags);

count = parse_list(string_conversion_table_flag, str, flags, &unknown);
count = parse_list(string_conversion_table_output_flag, str, flags, &unknown);

return check_and_log(fn, ln, "flags", count, str, unknown, false);
}

#if DROID_HAL >= 3
static bool parse_input_flags(const char *fn, const unsigned ln,
const char *str, audio_input_flags_t *flags) {
int count;
char *unknown = NULL;

pa_assert(fn);
pa_assert(str);
pa_assert(flags);

count = parse_list(string_conversion_table_input_flag, str, flags, &unknown);

return check_and_log(fn, ln, "flags", count, str, unknown, false);
}
#endif

#define MAX_LINE_LENGTH (1024)

Expand Down Expand Up @@ -622,10 +654,14 @@ bool pa_parse_droid_audio_config(const char *filename, pa_droid_config_audio *co
success = parse_devices(filename, n, value, false, &input->devices, false);
} else if (pa_streq(v, FLAGS_TAG)) {
if (in_output)
success = parse_flags(filename, n, value, &output->flags);
success = parse_output_flags(filename, n, value, &output->flags);
else {
#if DROID_HAL >= 3
success = parse_input_flags(filename, n, value, &input->flags);
#else
pa_log("[%s:%u] failed to parse line - output flags inside input definition", filename, n);
success = false;
#endif
}
} else {
pa_log("[%s:%u] failed to parse line - unknown config entry %s", filename, n, v);
Expand Down Expand Up @@ -914,7 +950,7 @@ static void add_i_ports(pa_droid_mapping *am) {
pa_assert(am);

devices = am->input->devices;
#ifdef HAL_V2
#if DROID_HAL >= 2
devices &= ~AUDIO_DEVICE_BIT_IN;
#endif

Expand All @@ -923,7 +959,7 @@ static void add_i_ports(pa_droid_mapping *am) {

if (devices & cur_device) {

#ifdef HAL_V2
#if DROID_HAL >= 2
#ifndef DROID_DEVICE_MAKO
cur_device |= AUDIO_DEVICE_BIT_IN;
#endif
Expand Down
13 changes: 9 additions & 4 deletions src/droid/droid-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "droid-util-42.h"
#elif ANDROID_VERSION_MAJOR == 4 && ANDROID_VERSION_MINOR == 4
#include "droid-util-44.h"
#elif ANDROID_VERSION_MAJOR == 5 && ANDROID_VERSION_MINOR == 1
#include "droid-util-51.h"
#else
#error "No valid ANDROID_VERSION found."
#endif
Expand Down Expand Up @@ -98,9 +100,9 @@ typedef struct pa_droid_config_output {
const pa_droid_config_hw_module *module;

char name[AUDIO_HARDWARE_MODULE_ID_MAX_LEN];
uint32_t sampling_rates[AUDIO_MAX_SAMPLING_RATES];
uint32_t sampling_rates[AUDIO_MAX_SAMPLING_RATES]; /* (uint32_t) -1 -> dynamic */
audio_channel_mask_t channel_masks; /* 0 -> dynamic */
audio_format_t formats;
audio_format_t formats; /* 0 -> dynamic */
audio_devices_t devices;
audio_output_flags_t flags;
} pa_droid_config_output;
Expand All @@ -109,10 +111,13 @@ typedef struct pa_droid_config_input {
const pa_droid_config_hw_module *module;

char name[AUDIO_HARDWARE_MODULE_ID_MAX_LEN];
uint32_t sampling_rates[AUDIO_MAX_SAMPLING_RATES];
uint32_t sampling_rates[AUDIO_MAX_SAMPLING_RATES]; /* (uint32_t) -1 -> dynamic */
audio_channel_mask_t channel_masks; /* 0 -> dynamic */
audio_format_t formats;
audio_format_t formats; /* 0 -> dynamic */
audio_devices_t devices;
#if DROID_HAL >= 3
audio_input_flags_t flags;
#endif
} pa_droid_config_input;

struct pa_droid_config_hw_module {
Expand Down

0 comments on commit 3fb96ea

Please sign in to comment.