Remove some useless parameters from audio_messages.h.
|segment_count| is passed from the renderer in the
AudioInputHostMsg_CreateStream_Config, and just echoed back to the
renderer. This is completely unnecessary. |length| is already known
to the renderer, and thus it doesn't need be passed from the browser.
Convenience functions ComputeAudio{In,Out}putBufferSize are
introduced to safely compute the required size of the shared memory
for given audio parameters.
BUG=653861
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Id192d16001c873867fedba52be9b52c2672890ab
Reviewed-on: https://chromium-review.googlesource.com/623089
Commit-Queue: Max Morin <[email protected]>
Reviewed-by: Chris Palmer <[email protected]>
Reviewed-by: Bill Budge <[email protected]>
Cr-Commit-Position: refs/heads/master@{#499179}
diff --git a/ppapi/proxy/audio_input_resource.cc b/ppapi/proxy/audio_input_resource.cc
index cca80b7..0137440 100644
--- a/ppapi/proxy/audio_input_resource.cc
+++ b/ppapi/proxy/audio_input_resource.cc
@@ -183,9 +183,17 @@
base::SyncSocket::Handle socket_handle) {
socket_.reset(new base::CancelableSyncSocket(socket_handle));
shared_memory_.reset(new base::SharedMemory(shared_memory_handle, false));
- shared_memory_size_ = shared_memory_size;
DCHECK(!shared_memory_->memory());
+ // Ensure that the allocated memory is enough for the audio bus and buffer
+ // parameters. Note that there might be slightly more allocated memory as
+ // some shared memory implementations round up to the closest 2^n when
+ // allocating.
+ // Example: DCHECK_GE(8208, 8192 + 16) for |sample_frame_count_| = 2048.
+ shared_memory_size_ = media::ComputeAudioInputBufferSize(
+ kAudioInputChannels, sample_frame_count_, 1u);
+ DCHECK_GE(shared_memory_size, shared_memory_size_);
+
// If we fail to map the shared memory into the caller's address space we
// might as well fail here since nothing will work if this is the case.
CHECK(shared_memory_->Map(shared_memory_size_));
@@ -196,14 +204,6 @@
audio_bus_ = media::AudioBus::WrapMemory(
kAudioInputChannels, sample_frame_count_, buffer->audio);
- // Ensure that the size of the created audio bus matches the allocated
- // size in shared memory.
- // Example: DCHECK_EQ(8208 - 16, 8192) for |sample_frame_count_| = 2048.
- const uint32_t audio_bus_size_bytes = media::AudioBus::CalculateMemorySize(
- audio_bus_->channels(), audio_bus_->frames());
- DCHECK_EQ(shared_memory_size_ - sizeof(media::AudioInputBufferParameters),
- audio_bus_size_bytes);
-
// Create an extra integer audio buffer for user audio data callbacks.
// Data in shared memory will be copied to this buffer, after interleaving
// and truncation, before each input callback to match the format expected