Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: media/base/audio_buffer_queue_unittest.cc

Issue 261333002: Fix AudioBuffer verification tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/audio_buffer_unittest.cc » ('j') | media/base/audio_buffer_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "media/base/audio_buffer.h" 9 #include "media/base/audio_buffer.h"
10 #include "media/base/audio_buffer_queue.h" 10 #include "media/base/audio_buffer_queue.h"
11 #include "media/base/audio_bus.h" 11 #include "media/base/audio_bus.h"
12 #include "media/base/buffers.h" 12 #include "media/base/buffers.h"
13 #include "media/base/test_helpers.h" 13 #include "media/base/test_helpers.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace media { 16 namespace media {
17 17
18 const int kSampleRate = 44100; 18 const int kSampleRate = 44100;
19 19
20 static void VerifyBus(AudioBus* bus, 20 static void VerifyBus(AudioBus* bus,
21 int offset, 21 int offset,
22 int frames, 22 int frames,
23 int buffer_size, 23 int buffer_size,
24 float start, 24 float start,
25 float increment) { 25 float increment) {
26 for (int ch = 0; ch < bus->channels(); ++ch) { 26 for (int ch = 0; ch < bus->channels(); ++ch) {
27 const float v = start + ch * buffer_size * increment; 27 const float v = start + ch * buffer_size * increment;
28 for (int i = offset; i < frames; ++i) { 28 for (int i = offset; i < offset + frames; ++i) {
29 ASSERT_FLOAT_EQ(v + (i - offset) * increment, bus->channel(ch)[i]) 29 ASSERT_FLOAT_EQ(v + (i - offset) * increment, bus->channel(ch)[i])
30 << "i=" << i << ", ch=" << ch; 30 << "i=" << i << ", ch=" << ch;
31 } 31 }
32 } 32 }
33 } 33 }
34 34
35 template <typename T> 35 template <typename T>
36 static scoped_refptr<AudioBuffer> MakeTestBuffer(SampleFormat format, 36 static scoped_refptr<AudioBuffer> MakeTestBuffer(SampleFormat format,
37 ChannelLayout channel_layout, 37 ChannelLayout channel_layout,
38 T start, 38 T start,
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 267 }
268 268
269 TEST(AudioBufferQueueTest, ReadS16Planar) { 269 TEST(AudioBufferQueueTest, ReadS16Planar) {
270 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 270 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
271 const int channels = ChannelLayoutToChannelCount(channel_layout); 271 const int channels = ChannelLayoutToChannelCount(channel_layout);
272 AudioBufferQueue buffer; 272 AudioBufferQueue buffer;
273 273
274 // Add 24 frames of data. 274 // Add 24 frames of data.
275 buffer.Append( 275 buffer.Append(
276 MakeTestBuffer<int16>(kSampleFormatPlanarS16, channel_layout, 1, 1, 4)); 276 MakeTestBuffer<int16>(kSampleFormatPlanarS16, channel_layout, 1, 1, 4));
277 buffer.Append(MakeTestBuffer<int16>( 277 buffer.Append(
278 kSampleFormatPlanarS16, channel_layout, 100, 5, 20)); 278 MakeTestBuffer<int16>(kSampleFormatPlanarS16, channel_layout, 5, 1, 20));
279 EXPECT_EQ(24, buffer.frames()); 279 EXPECT_EQ(24, buffer.frames());
280 280
281 // Read 6 frames from the buffer. 281 // Read 6 frames from the buffer.
282 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100); 282 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
283 EXPECT_EQ(6, buffer.ReadFrames(6, 0, bus.get())); 283 EXPECT_EQ(6, buffer.ReadFrames(6, 0, bus.get()));
284 EXPECT_EQ(18, buffer.frames()); 284 EXPECT_EQ(18, buffer.frames());
285 VerifyBus(bus.get(), 0, 4, 4, 1.0f / kint16max, 1.0f / kint16max); 285 VerifyBus(bus.get(), 0, 4, 4, 1.0f / kint16max, 1.0f / kint16max);
286 VerifyBus(bus.get(), 4, 2, 20, 5.0f / kint16max, 1.0f / kint16max); 286 VerifyBus(bus.get(), 4, 2, 20, 5.0f / kint16max, 1.0f / kint16max);
287 } 287 }
288 288
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 // Read all 10 frames in buffer2. 459 // Read all 10 frames in buffer2.
460 EXPECT_EQ(10, buffer.ReadFrames(10, 0, bus.get())); 460 EXPECT_EQ(10, buffer.ReadFrames(10, 0, bus.get()));
461 EXPECT_EQ(kNoTime, buffer.current_time()); 461 EXPECT_EQ(kNoTime, buffer.current_time());
462 462
463 // Try to read more frames (which don't exist), timestamp should remain. 463 // Try to read more frames (which don't exist), timestamp should remain.
464 EXPECT_EQ(0, buffer.ReadFrames(5, 0, bus.get())); 464 EXPECT_EQ(0, buffer.ReadFrames(5, 0, bus.get()));
465 EXPECT_EQ(kNoTime, buffer.current_time()); 465 EXPECT_EQ(kNoTime, buffer.current_time());
466 } 466 }
467 467
468 } // namespace media 468 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_buffer_unittest.cc » ('j') | media/base/audio_buffer_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698