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

Side by Side Diff: media/filters/audio_renderer_algorithm_base_unittest.cc

Issue 9114020: Remove task.h and finish base::Bind() migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 8 years, 11 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 | « media/audio/pulse/pulse_output.h ('k') | media/tools/tile_render_bench/tile_render_bench.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // The format of these tests are to enqueue a known amount of data and then 5 // The format of these tests are to enqueue a known amount of data and then
6 // request the exact amount we expect in order to dequeue the known amount of 6 // request the exact amount we expect in order to dequeue the known amount of
7 // data. This ensures that for any rate we are consuming input data at the 7 // data. This ensures that for any rate we are consuming input data at the
8 // correct rate. We always pass in a very large destination buffer with the 8 // correct rate. We always pass in a very large destination buffer with the
9 // expectation that FillBuffer() will fill as much as it can but no more. 9 // expectation that FillBuffer() will fill as much as it can but no more.
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "media/base/data_buffer.h" 13 #include "media/base/data_buffer.h"
14 #include "media/filters/audio_renderer_algorithm_base.h" 14 #include "media/filters/audio_renderer_algorithm_base.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using ::testing::AnyNumber; 18 using ::testing::AnyNumber;
19 19
20 namespace media { 20 namespace media {
21 21
22 static const int kChannels = 1; 22 static const int kChannels = 1;
23 static const int kSampleRate = 1000; 23 static const int kSampleRate = 1000;
24 static const int kSampleBits = 8; 24 static const int kSampleBits = 8;
25 static void DoNothing() {}
26 25
27 TEST(AudioRendererAlgorithmBaseTest, FillBuffer_NormalRate) { 26 TEST(AudioRendererAlgorithmBaseTest, FillBuffer_NormalRate) {
28 // When playback rate == 1.0f: straight copy of whatever is in |queue_|. 27 // When playback rate == 1.0f: straight copy of whatever is in |queue_|.
29 AudioRendererAlgorithmBase algorithm; 28 AudioRendererAlgorithmBase algorithm;
30 algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 1.0f, 29 algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 1.0f,
31 base::Bind(&DoNothing)); 30 base::Bind(&base::DoNothing));
32 31
33 // Enqueue a buffer of any size since it doesn't matter. 32 // Enqueue a buffer of any size since it doesn't matter.
34 const size_t kDataSize = 1024; 33 const size_t kDataSize = 1024;
35 algorithm.EnqueueBuffer(new DataBuffer(new uint8[kDataSize], kDataSize)); 34 algorithm.EnqueueBuffer(new DataBuffer(new uint8[kDataSize], kDataSize));
36 EXPECT_EQ(kDataSize, algorithm.QueueSize()); 35 EXPECT_EQ(kDataSize, algorithm.QueueSize());
37 36
38 // Read the same sized amount. 37 // Read the same sized amount.
39 scoped_array<uint8> data(new uint8[kDataSize]); 38 scoped_array<uint8> data(new uint8[kDataSize]);
40 EXPECT_EQ(kDataSize, algorithm.FillBuffer(data.get(), kDataSize)); 39 EXPECT_EQ(kDataSize, algorithm.FillBuffer(data.get(), kDataSize));
41 EXPECT_EQ(0u, algorithm.QueueSize()); 40 EXPECT_EQ(0u, algorithm.QueueSize());
42 } 41 }
43 42
44 TEST(AudioRendererAlgorithmBaseTest, FillBuffer_DoubleRate) { 43 TEST(AudioRendererAlgorithmBaseTest, FillBuffer_DoubleRate) {
45 // When playback rate > 1.0f: input is read faster than output is written. 44 // When playback rate > 1.0f: input is read faster than output is written.
46 AudioRendererAlgorithmBase algorithm; 45 AudioRendererAlgorithmBase algorithm;
47 algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 2.0f, 46 algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 2.0f,
48 base::Bind(&DoNothing)); 47 base::Bind(&base::DoNothing));
49 48
50 // First parameter is the input buffer size, second parameter is how much data 49 // First parameter is the input buffer size, second parameter is how much data
51 // we expect to consume in order to have no data left in the |algorithm|. 50 // we expect to consume in order to have no data left in the |algorithm|.
52 // 51 //
53 // For rate == 0.5f, reading half the input size should consume all enqueued 52 // For rate == 0.5f, reading half the input size should consume all enqueued
54 // data. 53 // data.
55 const size_t kBufferSize = 16 * 1024; 54 const size_t kBufferSize = 16 * 1024;
56 scoped_array<uint8> data(new uint8[kBufferSize]); 55 scoped_array<uint8> data(new uint8[kBufferSize]);
57 const size_t kTestData[][2] = { 56 const size_t kTestData[][2] = {
58 { algorithm.window_size_, algorithm.window_size_ / 2}, 57 { algorithm.window_size_, algorithm.window_size_ / 2},
(...skipping 11 matching lines...) Expand all
70 ASSERT_LE(kExpectedSize, kBufferSize); 69 ASSERT_LE(kExpectedSize, kBufferSize);
71 EXPECT_EQ(kExpectedSize, algorithm.FillBuffer(data.get(), kBufferSize)); 70 EXPECT_EQ(kExpectedSize, algorithm.FillBuffer(data.get(), kBufferSize));
72 EXPECT_EQ(0u, algorithm.QueueSize()); 71 EXPECT_EQ(0u, algorithm.QueueSize());
73 } 72 }
74 } 73 }
75 74
76 TEST(AudioRendererAlgorithmBaseTest, FillBuffer_HalfRate) { 75 TEST(AudioRendererAlgorithmBaseTest, FillBuffer_HalfRate) {
77 // When playback rate < 1.0f: input is read slower than output is written. 76 // When playback rate < 1.0f: input is read slower than output is written.
78 AudioRendererAlgorithmBase algorithm; 77 AudioRendererAlgorithmBase algorithm;
79 algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 0.5f, 78 algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 0.5f,
80 base::Bind(&DoNothing)); 79 base::Bind(&base::DoNothing));
81 80
82 // First parameter is the input buffer size, second parameter is how much data 81 // First parameter is the input buffer size, second parameter is how much data
83 // we expect to consume in order to have no data left in the |algorithm|. 82 // we expect to consume in order to have no data left in the |algorithm|.
84 // 83 //
85 // For rate == 0.5f, reading double the input size should consume all enqueued 84 // For rate == 0.5f, reading double the input size should consume all enqueued
86 // data. 85 // data.
87 const size_t kBufferSize = 16 * 1024; 86 const size_t kBufferSize = 16 * 1024;
88 scoped_array<uint8> data(new uint8[kBufferSize]); 87 scoped_array<uint8> data(new uint8[kBufferSize]);
89 const size_t kTestData[][2] = { 88 const size_t kTestData[][2] = {
90 { algorithm.window_size_, algorithm.window_size_ * 2 }, 89 { algorithm.window_size_, algorithm.window_size_ * 2 },
(...skipping 11 matching lines...) Expand all
102 ASSERT_LE(kExpectedSize, kBufferSize); 101 ASSERT_LE(kExpectedSize, kBufferSize);
103 EXPECT_EQ(kExpectedSize, algorithm.FillBuffer(data.get(), kBufferSize)); 102 EXPECT_EQ(kExpectedSize, algorithm.FillBuffer(data.get(), kBufferSize));
104 EXPECT_EQ(0u, algorithm.QueueSize()); 103 EXPECT_EQ(0u, algorithm.QueueSize());
105 } 104 }
106 } 105 }
107 106
108 TEST(AudioRendererAlgorithmBaseTest, FillBuffer_QuarterRate) { 107 TEST(AudioRendererAlgorithmBaseTest, FillBuffer_QuarterRate) {
109 // When playback rate is very low the audio is simply muted. 108 // When playback rate is very low the audio is simply muted.
110 AudioRendererAlgorithmBase algorithm; 109 AudioRendererAlgorithmBase algorithm;
111 algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 0.25f, 110 algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 0.25f,
112 base::Bind(&DoNothing)); 111 base::Bind(&base::DoNothing));
113 112
114 // First parameter is the input buffer size, second parameter is how much data 113 // First parameter is the input buffer size, second parameter is how much data
115 // we expect to consume in order to have no data left in the |algorithm|. 114 // we expect to consume in order to have no data left in the |algorithm|.
116 // 115 //
117 // For rate == 0.25f, reading four times the input size should consume all 116 // For rate == 0.25f, reading four times the input size should consume all
118 // enqueued data but without executing OLA. 117 // enqueued data but without executing OLA.
119 const size_t kBufferSize = 16 * 1024; 118 const size_t kBufferSize = 16 * 1024;
120 scoped_array<uint8> data(new uint8[kBufferSize]); 119 scoped_array<uint8> data(new uint8[kBufferSize]);
121 const size_t kTestData[][2] = { 120 const size_t kTestData[][2] = {
122 { algorithm.window_size_, algorithm.window_size_ * 4}, 121 { algorithm.window_size_, algorithm.window_size_ * 4},
123 { algorithm.window_size_ / 2, algorithm.window_size_ * 2}, 122 { algorithm.window_size_ / 2, algorithm.window_size_ * 2},
124 { 1u, 4u }, 123 { 1u, 4u },
125 { 0u, 0u }, 124 { 0u, 0u },
126 }; 125 };
127 126
128 for (size_t i = 0u; i < arraysize(kTestData); ++i) { 127 for (size_t i = 0u; i < arraysize(kTestData); ++i) {
129 const size_t kDataSize = kTestData[i][0]; 128 const size_t kDataSize = kTestData[i][0];
130 algorithm.EnqueueBuffer(new DataBuffer(new uint8[kDataSize], kDataSize)); 129 algorithm.EnqueueBuffer(new DataBuffer(new uint8[kDataSize], kDataSize));
131 EXPECT_EQ(kDataSize, algorithm.QueueSize()); 130 EXPECT_EQ(kDataSize, algorithm.QueueSize());
132 131
133 const size_t kExpectedSize = kTestData[i][1]; 132 const size_t kExpectedSize = kTestData[i][1];
134 ASSERT_LE(kExpectedSize, kBufferSize); 133 ASSERT_LE(kExpectedSize, kBufferSize);
135 EXPECT_EQ(kExpectedSize, algorithm.FillBuffer(data.get(), kBufferSize)); 134 EXPECT_EQ(kExpectedSize, algorithm.FillBuffer(data.get(), kBufferSize));
136 EXPECT_EQ(0u, algorithm.QueueSize()); 135 EXPECT_EQ(0u, algorithm.QueueSize());
137 } 136 }
138 } 137 }
139 138
140 } // namespace media 139 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/pulse_output.h ('k') | media/tools/tile_render_bench/tile_render_bench.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698