summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authortommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 13:26:47 +0000
committertommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 13:26:47 +0000
commitbe1464c45a0150a684b7d8ffdff959804f8a8a2a (patch)
tree4f022f6f90f3734d2a25e63ad1f0ac57f245d152 /content
parent0c24e342443934393d8acb99cceeff264db8ff1e (diff)
downloadchromium_src-be1464c45a0150a684b7d8ffdff959804f8a8a2a.zip
chromium_src-be1464c45a0150a684b7d8ffdff959804f8a8a2a.tar.gz
chromium_src-be1464c45a0150a684b7d8ffdff959804f8a8a2a.tar.bz2
Initialize the shared memory to appease Valgrind.
BUG=138515 TEST=Under valgrind, run: content_unittests --gtest_filter=AudioDeviceTest.* Review URL: https://chromiumcodereview.appspot.com/10806061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147848 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/renderer/media/audio_device.cc3
-rw-r--r--content/renderer/media/audio_device_unittest.cc33
2 files changed, 32 insertions, 4 deletions
diff --git a/content/renderer/media/audio_device.cc b/content/renderer/media/audio_device.cc
index 22fb7fc..9936ebd 100644
--- a/content/renderer/media/audio_device.cc
+++ b/content/renderer/media/audio_device.cc
@@ -273,8 +273,7 @@ void AudioDevice::AudioThreadCallback::Process(int pending_data) {
// TODO(crogers/vrk): Figure out a way to avoid the float -> int -> float
// conversions that happen in the <audio> and WebRTC scenarios.
media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(),
- audio_parameters_.frames_per_buffer(),
- audio_parameters_.bits_per_sample() / 8);
+ num_frames, audio_parameters_.bits_per_sample() / 8);
// Let the host know we are done.
media::SetActualDataSizeInBytes(&shared_memory_, memory_length_,
diff --git a/content/renderer/media/audio_device_unittest.cc b/content/renderer/media/audio_device_unittest.cc
index adf5506..4612ec7 100644
--- a/content/renderer/media/audio_device_unittest.cc
+++ b/content/renderer/media/audio_device_unittest.cc
@@ -111,6 +111,19 @@ ACTION_P(QuitLoop, loop) {
loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
+// Zeros out |number_of_frames| in all channel buffers pointed to by
+// the |audio_data| vector.
+void ZeroAudioData(int number_of_frames,
+ const std::vector<float*>& audio_data) {
+ std::vector<float*>::const_iterator it = audio_data.begin();
+ for (; it != audio_data.end(); ++it) {
+ float* channel = *it;
+ for (int j = 0; j < number_of_frames; ++j) {
+ channel[j] = 0.0f;
+ }
+ }
+}
+
} // namespace.
class AudioDeviceTest : public testing::Test {
@@ -197,7 +210,9 @@ TEST_F(AudioDeviceTest, CreateStream) {
int memory_size = media::TotalSharedMemorySizeInBytes(
default_audio_parameters_.GetBytesPerBuffer());
SharedMemory shared_memory;
- ASSERT_TRUE(shared_memory.CreateAnonymous(memory_size));
+ ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(memory_size));
+ // Initialize the memory.
+ memset(shared_memory.memory(), 0xff, memory_size);
CancelableSyncSocket browser_socket, renderer_socket;
ASSERT_TRUE(CancelableSyncSocket::CreatePair(&browser_socket,
@@ -226,10 +241,24 @@ TEST_F(AudioDeviceTest, CreateStream) {
// writing the interleaved audio data into the shared memory section.
// So, for the sake of this test, we consider the call to Render a sign
// of success and quit the loop.
+
+ // A note on the call to ZeroAudioData():
+ // Valgrind caught a bug in AudioDevice::AudioThreadCallback::Process()
+ // whereby we always interleaved all the frames in the buffer regardless
+ // of how many were actually rendered. So to keep the benefits of that
+ // test, we explicitly pass 0 in here as the number of frames to
+ // ZeroAudioData(). Other tests might want to pass the requested number
+ // by using WithArgs<1, 0>(Invoke(&ZeroAudioData)) and set the return
+ // value accordingly.
+ const int kNumberOfFramesToProcess = 0;
+
EXPECT_CALL(callback_, Render(_, _, _))
.WillOnce(DoAll(
+ WithArgs<0>(Invoke(
+ testing::CreateFunctor(&ZeroAudioData,
+ kNumberOfFramesToProcess))),
QuitLoop(io_loop_.message_loop_proxy()),
- Return(1)));
+ Return(kNumberOfFramesToProcess)));
audio_device->OnStreamCreated(duplicated_memory_handle, audio_device_socket,
memory_size);