summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2022-02-01 15:31:47 -0800
committerJean-Michel Trivi <jmtrivi@google.com>2022-02-02 08:27:24 -0800
commit71834f37757318e6cabce5d7627846f356435ed7 (patch)
tree60c2f9ccb5e6b2d50ffb309ebf8d8e543df5e897
parentb0bcbf421f762b1ee18dd73efd63b56453a1a3f5 (diff)
downloadlibhardware-71834f37757318e6cabce5d7627846f356435ed7.tar.gz
r_submix module: pipe size changes with sample rate
Adapt the pipe size based on the sample rate. Behavior is unchanged for the default sample rate (48kHz), size is adjusted by the ratio relative to the default rate. Bug: 141604269 Test: atest AudioHostTest#testTwoChannelCapturingMediaConversion Change-Id: I0ba45af18ef02dc0ef77d480e1203d2cd1db9864
-rw-r--r--modules/audio_remote_submix/audio_hw.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/modules/audio_remote_submix/audio_hw.cpp b/modules/audio_remote_submix/audio_hw.cpp
index 42d3b98d..f96854b5 100644
--- a/modules/audio_remote_submix/audio_hw.cpp
+++ b/modules/audio_remote_submix/audio_hw.cpp
@@ -63,7 +63,7 @@ namespace android {
#endif // SUBMIX_VERBOSE_LOGGING
// NOTE: This value will be rounded up to the nearest power of 2 by MonoPipe().
-#define DEFAULT_PIPE_SIZE_IN_FRAMES (1024*4)
+#define DEFAULT_PIPE_SIZE_IN_FRAMES (1024*4) // size at default sample rate
// Value used to divide the MonoPipe() buffer into segments that are written to the source and
// read from the sink. The maximum latency of the device is the size of the MonoPipe's buffer
// the minimum latency is the MonoPipe buffer size divided by this value.
@@ -208,6 +208,11 @@ static bool sample_rate_supported(const uint32_t sample_rate)
return return_value;
}
+static size_t pipe_size_in_frames(const uint32_t sample_rate)
+{
+ return DEFAULT_PIPE_SIZE_IN_FRAMES * ((float) sample_rate / DEFAULT_SAMPLE_RATE_HZ);
+}
+
// Determine whether the specified sample rate is supported, if it is return the specified sample
// rate, otherwise return the default sample rate for the submix module.
static uint32_t get_supported_sample_rate(uint32_t sample_rate)
@@ -1289,8 +1294,10 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
// Store a pointer to the device from the output stream.
out->dev = rsxadev;
// Initialize the pipe.
- ALOGV("adev_open_output_stream(): about to create pipe at index %d", route_idx);
- submix_audio_device_create_pipe_l(rsxadev, config, DEFAULT_PIPE_SIZE_IN_FRAMES,
+ const size_t pipeSizeInFrames = pipe_size_in_frames(config->sample_rate);
+ ALOGI("adev_open_output_stream(): about to create pipe at index %d, rate %u, pipe size %zu",
+ route_idx, config->sample_rate, pipeSizeInFrames);
+ submix_audio_device_create_pipe_l(rsxadev, config, pipeSizeInFrames,
DEFAULT_PIPE_PERIOD_COUNT, NULL, out, address, route_idx);
#if LOG_STREAMS_TO_FILES
out->log_fd = open(LOG_STREAM_OUT_FILENAME, O_CREAT | O_TRUNC | O_WRONLY,
@@ -1419,7 +1426,8 @@ static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
const size_t frame_size_in_bytes = audio_channel_count_from_in_mask(config->channel_mask) *
audio_bytes_per_sample(config->format);
if (max_buffer_period_size_frames == 0) {
- max_buffer_period_size_frames = DEFAULT_PIPE_SIZE_IN_FRAMES;
+ max_buffer_period_size_frames =
+ pipe_size_in_frames(get_supported_sample_rate(config->sample_rate));;
}
const size_t buffer_size = max_buffer_period_size_frames * frame_size_in_bytes;
SUBMIX_ALOGV("adev_get_input_buffer_size() returns %zu bytes, %zu frames",
@@ -1532,8 +1540,10 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
in->read_error_count = 0;
// Initialize the pipe.
- ALOGV("adev_open_input_stream(): about to create pipe");
- submix_audio_device_create_pipe_l(rsxadev, config, DEFAULT_PIPE_SIZE_IN_FRAMES,
+ const size_t pipeSizeInFrames = pipe_size_in_frames(config->sample_rate);
+ ALOGI("adev_open_input_stream(): about to create pipe at index %d, rate %u, pipe size %zu",
+ route_idx, config->sample_rate, pipeSizeInFrames);
+ submix_audio_device_create_pipe_l(rsxadev, config, pipeSizeInFrames,
DEFAULT_PIPE_PERIOD_COUNT, in, NULL, address, route_idx);
sp <MonoPipe> sink = rsxadev->routes[route_idx].rsxSink;