diff options
author | Hongwei Wang <hwwang@google.com> | 2019-01-11 15:13:31 -0800 |
---|---|---|
committer | Hongwei Wang <hwwang@google.com> | 2019-01-28 17:34:00 -0800 |
commit | 2fc86eff3e4e29733ea3ee2446ad2df0286e8939 (patch) | |
tree | 9b5ad77504a2a18fdcc3924d5eb113d44ef27b42 /emulator | |
parent | a7c6734fa0b951fb4fb5a833e7f097de48646d0d (diff) | |
download | device_generic_car-2fc86eff3e4e29733ea3ee2446ad2df0286e8939.tar.gz device_generic_car-2fc86eff3e4e29733ea3ee2446ad2df0286e8939.tar.bz2 device_generic_car-2fc86eff3e4e29733ea3ee2446ad2df0286e8939.zip |
Enables broadcast radio in Car emulator
Also exposes the FM tuner as an audio input device in emulator.
Bug: 118763832
Test: Launch Radio app (with startAudioSource) in emulator
Change-Id: I75732a68382f8453bc858da8de2de32417c63d98
Diffstat (limited to 'emulator')
-rw-r--r-- | emulator/audio/car_emulator_audio.mk | 1 | ||||
-rw-r--r-- | emulator/audio/driver/audio_hw.c | 21 |
2 files changed, 20 insertions, 2 deletions
diff --git a/emulator/audio/car_emulator_audio.mk b/emulator/audio/car_emulator_audio.mk index efe7fa4..bef5c2e 100644 --- a/emulator/audio/car_emulator_audio.mk +++ b/emulator/audio/car_emulator_audio.mk @@ -19,6 +19,7 @@ PRODUCT_PACKAGES += audio.primary.caremu PRODUCT_PROPERTY_OVERRIDES += ro.hardware.audio.primary=caremu PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.broadcastradio.xml:system/etc/permissions/android.hardware.broadcastradio.xml \ frameworks/av/services/audiopolicy/config/a2dp_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/a2dp_audio_policy_configuration.xml \ frameworks/av/services/audiopolicy/config/usb_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/usb_audio_policy_configuration.xml \ frameworks/av/services/audiopolicy/config/r_submix_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/r_submix_audio_policy_configuration.xml \ diff --git a/emulator/audio/driver/audio_hw.c b/emulator/audio/driver/audio_hw.c index 8521f7e..b1297cf 100644 --- a/emulator/audio/driver/audio_hw.c +++ b/emulator/audio/driver/audio_hw.c @@ -727,6 +727,17 @@ static int in_standby(struct audio_stream *stream) { return 0; } +#define STEP (3.14159265 / 180) +// Generates pure tone for FM_TUNER +static int pseudo_pcm_read(void *data, unsigned int count) { + unsigned int length = count / sizeof(short); + short *sdata = (short *)data; + for (int index = 0; index < length; index++) { + sdata[index] = (short)(sin(index * STEP) * 4096); + } + return count; +} + static void *in_read_worker(void *args) { struct generic_stream_in *in = (struct generic_stream_in *)args; struct pcm *pcm = NULL; @@ -819,7 +830,10 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer, size_t byte if (in->worker_standby) { in->worker_standby = false; } - pthread_cond_signal(&in->worker_wake); + // FM_TUNER fills the buffer via pseudo_pcm_read directly + if (in->device != AUDIO_DEVICE_IN_FM_TUNER) { + pthread_cond_signal(&in->worker_wake); + } int64_t current_position; struct timespec current_time; @@ -854,7 +868,10 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer, size_t byte } in->standby_frames_read += frames; - if (popcount(in->req_config.channel_mask) == 1 && + if (in->device == AUDIO_DEVICE_IN_FM_TUNER) { + int read_bytes = pseudo_pcm_read(buffer, bytes); + read_frames = read_bytes / audio_stream_in_frame_size(stream); + } else if (popcount(in->req_config.channel_mask) == 1 && in->pcm_config.channels == 2) { // Need to resample to mono if (in->stereo_to_mono_buf_size < bytes*2) { |