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

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

Issue 1477533002: Remove kint16max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint8max
Patch Set: includes Created 5 years 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
« no previous file with comments | « base/files/file_util_win.cc ('k') | media/base/audio_buffer_unittest.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 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 <stdint.h>
6
7 #include <limits>
8
6 #include "base/logging.h" 9 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
8 #include "base/time/time.h" 11 #include "base/time/time.h"
9 #include "media/base/audio_buffer.h" 12 #include "media/base/audio_buffer.h"
10 #include "media/base/audio_buffer_queue.h" 13 #include "media/base/audio_buffer_queue.h"
11 #include "media/base/audio_bus.h" 14 #include "media/base/audio_bus.h"
12 #include "media/base/test_helpers.h" 15 #include "media/base/test_helpers.h"
13 #include "media/base/timestamp_constants.h" 16 #include "media/base/timestamp_constants.h"
14 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
15 18
(...skipping 30 matching lines...) Expand all
46 step, 49 step,
47 frames, 50 frames,
48 kNoTimestamp()); 51 kNoTimestamp());
49 } 52 }
50 53
51 TEST(AudioBufferQueueTest, AppendAndClear) { 54 TEST(AudioBufferQueueTest, AppendAndClear) {
52 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; 55 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO;
53 AudioBufferQueue buffer; 56 AudioBufferQueue buffer;
54 EXPECT_EQ(0, buffer.frames()); 57 EXPECT_EQ(0, buffer.frames());
55 buffer.Append( 58 buffer.Append(
56 MakeTestBuffer<uint8>(kSampleFormatU8, channel_layout, 10, 1, 8)); 59 MakeTestBuffer<uint8_t>(kSampleFormatU8, channel_layout, 10, 1, 8));
57 EXPECT_EQ(8, buffer.frames()); 60 EXPECT_EQ(8, buffer.frames());
58 buffer.Clear(); 61 buffer.Clear();
59 EXPECT_EQ(0, buffer.frames()); 62 EXPECT_EQ(0, buffer.frames());
60 buffer.Append( 63 buffer.Append(
61 MakeTestBuffer<uint8>(kSampleFormatU8, channel_layout, 20, 1, 8)); 64 MakeTestBuffer<uint8_t>(kSampleFormatU8, channel_layout, 20, 1, 8));
62 EXPECT_EQ(8, buffer.frames()); 65 EXPECT_EQ(8, buffer.frames());
63 } 66 }
64 67
65 TEST(AudioBufferQueueTest, MultipleAppend) { 68 TEST(AudioBufferQueueTest, MultipleAppend) {
66 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; 69 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO;
67 AudioBufferQueue buffer; 70 AudioBufferQueue buffer;
68 buffer.Append( 71 buffer.Append(
69 MakeTestBuffer<uint8>(kSampleFormatU8, channel_layout, 10, 1, 8)); 72 MakeTestBuffer<uint8_t>(kSampleFormatU8, channel_layout, 10, 1, 8));
70 EXPECT_EQ(8, buffer.frames()); 73 EXPECT_EQ(8, buffer.frames());
71 buffer.Append( 74 buffer.Append(
72 MakeTestBuffer<uint8>(kSampleFormatU8, channel_layout, 10, 1, 8)); 75 MakeTestBuffer<uint8_t>(kSampleFormatU8, channel_layout, 10, 1, 8));
73 EXPECT_EQ(16, buffer.frames()); 76 EXPECT_EQ(16, buffer.frames());
74 buffer.Append( 77 buffer.Append(
75 MakeTestBuffer<uint8>(kSampleFormatU8, channel_layout, 10, 1, 8)); 78 MakeTestBuffer<uint8_t>(kSampleFormatU8, channel_layout, 10, 1, 8));
76 EXPECT_EQ(24, buffer.frames()); 79 EXPECT_EQ(24, buffer.frames());
77 buffer.Append( 80 buffer.Append(
78 MakeTestBuffer<uint8>(kSampleFormatU8, channel_layout, 10, 1, 8)); 81 MakeTestBuffer<uint8_t>(kSampleFormatU8, channel_layout, 10, 1, 8));
79 EXPECT_EQ(32, buffer.frames()); 82 EXPECT_EQ(32, buffer.frames());
80 buffer.Append( 83 buffer.Append(
81 MakeTestBuffer<uint8>(kSampleFormatU8, channel_layout, 10, 1, 8)); 84 MakeTestBuffer<uint8_t>(kSampleFormatU8, channel_layout, 10, 1, 8));
82 EXPECT_EQ(40, buffer.frames()); 85 EXPECT_EQ(40, buffer.frames());
83 } 86 }
84 87
85 TEST(AudioBufferQueueTest, IteratorCheck) { 88 TEST(AudioBufferQueueTest, IteratorCheck) {
86 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; 89 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO;
87 const int channels = ChannelLayoutToChannelCount(channel_layout); 90 const int channels = ChannelLayoutToChannelCount(channel_layout);
88 AudioBufferQueue buffer; 91 AudioBufferQueue buffer;
89 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100); 92 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
90 93
91 // Append 40 frames in 5 buffers. Intersperse ReadFrames() to make the 94 // Append 40 frames in 5 buffers. Intersperse ReadFrames() to make the
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 187 }
185 188
186 TEST(AudioBufferQueueTest, ReadU8) { 189 TEST(AudioBufferQueueTest, ReadU8) {
187 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0; 190 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
188 const int channels = ChannelLayoutToChannelCount(channel_layout); 191 const int channels = ChannelLayoutToChannelCount(channel_layout);
189 const int frames = 4; 192 const int frames = 4;
190 AudioBufferQueue buffer; 193 AudioBufferQueue buffer;
191 194
192 // Add 4 frames of data. 195 // Add 4 frames of data.
193 buffer.Append( 196 buffer.Append(
194 MakeTestBuffer<uint8>(kSampleFormatU8, channel_layout, 128, 1, frames)); 197 MakeTestBuffer<uint8_t>(kSampleFormatU8, channel_layout, 128, 1, frames));
195 198
196 // Read all 4 frames from the buffer. 199 // Read all 4 frames from the buffer.
197 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); 200 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
198 EXPECT_EQ(frames, buffer.ReadFrames(frames, 0, bus.get())); 201 EXPECT_EQ(frames, buffer.ReadFrames(frames, 0, bus.get()));
199 EXPECT_EQ(0, buffer.frames()); 202 EXPECT_EQ(0, buffer.frames());
200 VerifyBus(bus.get(), 0, frames, bus->frames(), 0, 1.0f / 127.0f); 203 VerifyBus(bus.get(), 0, frames, bus->frames(), 0, 1.0f / 127.0f);
201 } 204 }
202 205
203 TEST(AudioBufferQueueTest, ReadS16) { 206 TEST(AudioBufferQueueTest, ReadS16) {
204 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 207 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
205 const int channels = ChannelLayoutToChannelCount(channel_layout); 208 const int channels = ChannelLayoutToChannelCount(channel_layout);
206 AudioBufferQueue buffer; 209 AudioBufferQueue buffer;
207 210
208 // Add 24 frames of data. 211 // Add 24 frames of data.
209 buffer.Append( 212 buffer.Append(
210 MakeTestBuffer<int16>(kSampleFormatS16, channel_layout, 1, 1, 4)); 213 MakeTestBuffer<int16_t>(kSampleFormatS16, channel_layout, 1, 1, 4));
211 buffer.Append( 214 buffer.Append(
212 MakeTestBuffer<int16>(kSampleFormatS16, channel_layout, 9, 1, 20)); 215 MakeTestBuffer<int16_t>(kSampleFormatS16, channel_layout, 9, 1, 20));
213 EXPECT_EQ(24, buffer.frames()); 216 EXPECT_EQ(24, buffer.frames());
214 217
215 // Read 6 frames from the buffer. 218 // Read 6 frames from the buffer.
216 const int frames = 6; 219 const int frames = 6;
217 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, buffer.frames()); 220 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, buffer.frames());
218 EXPECT_EQ(frames, buffer.ReadFrames(frames, 0, bus.get())); 221 EXPECT_EQ(frames, buffer.ReadFrames(frames, 0, bus.get()));
219 EXPECT_EQ(18, buffer.frames()); 222 EXPECT_EQ(18, buffer.frames());
220 VerifyBus(bus.get(), 0, 4, 4, 1.0f / kint16max, 1.0f / kint16max); 223 VerifyBus(bus.get(), 0, 4, 4, 1.0f / std::numeric_limits<int16_t>::max(),
221 VerifyBus(bus.get(), 4, 2, 20, 9.0f / kint16max, 1.0f / kint16max); 224 1.0f / std::numeric_limits<int16_t>::max());
225 VerifyBus(bus.get(), 4, 2, 20, 9.0f / std::numeric_limits<int16_t>::max(),
226 1.0f / std::numeric_limits<int16_t>::max());
222 } 227 }
223 228
224 TEST(AudioBufferQueueTest, ReadS32) { 229 TEST(AudioBufferQueueTest, ReadS32) {
225 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 230 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
226 const int channels = ChannelLayoutToChannelCount(channel_layout); 231 const int channels = ChannelLayoutToChannelCount(channel_layout);
227 AudioBufferQueue buffer; 232 AudioBufferQueue buffer;
228 233
229 // Add 24 frames of data. 234 // Add 24 frames of data.
230 buffer.Append( 235 buffer.Append(
231 MakeTestBuffer<int32>(kSampleFormatS32, channel_layout, 1, 1, 4)); 236 MakeTestBuffer<int32_t>(kSampleFormatS32, channel_layout, 1, 1, 4));
232 buffer.Append( 237 buffer.Append(
233 MakeTestBuffer<int32>(kSampleFormatS32, channel_layout, 9, 1, 20)); 238 MakeTestBuffer<int32_t>(kSampleFormatS32, channel_layout, 9, 1, 20));
234 EXPECT_EQ(24, buffer.frames()); 239 EXPECT_EQ(24, buffer.frames());
235 240
236 // Read 6 frames from the buffer. 241 // Read 6 frames from the buffer.
237 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100); 242 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
238 EXPECT_EQ(6, buffer.ReadFrames(6, 0, bus.get())); 243 EXPECT_EQ(6, buffer.ReadFrames(6, 0, bus.get()));
239 EXPECT_EQ(18, buffer.frames()); 244 EXPECT_EQ(18, buffer.frames());
240 VerifyBus(bus.get(), 0, 4, 4, 1.0f / kint32max, 1.0f / kint32max); 245 VerifyBus(bus.get(), 0, 4, 4, 1.0f / std::numeric_limits<int32_t>::max(),
241 VerifyBus(bus.get(), 4, 2, 20, 9.0f / kint32max, 1.0f / kint32max); 246 1.0f / std::numeric_limits<int32_t>::max());
247 VerifyBus(bus.get(), 4, 2, 20, 9.0f / std::numeric_limits<int32_t>::max(),
248 1.0f / std::numeric_limits<int32_t>::max());
242 249
243 // Read the next 2 frames. 250 // Read the next 2 frames.
244 EXPECT_EQ(2, buffer.ReadFrames(2, 0, bus.get())); 251 EXPECT_EQ(2, buffer.ReadFrames(2, 0, bus.get()));
245 EXPECT_EQ(16, buffer.frames()); 252 EXPECT_EQ(16, buffer.frames());
246 VerifyBus(bus.get(), 0, 2, 20, 11.0f / kint32max, 1.0f / kint32max); 253 VerifyBus(bus.get(), 0, 2, 20, 11.0f / std::numeric_limits<int32_t>::max(),
254 1.0f / std::numeric_limits<int32_t>::max());
247 } 255 }
248 256
249 TEST(AudioBufferQueueTest, ReadF32Planar) { 257 TEST(AudioBufferQueueTest, ReadF32Planar) {
250 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 258 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
251 const int channels = ChannelLayoutToChannelCount(channel_layout); 259 const int channels = ChannelLayoutToChannelCount(channel_layout);
252 AudioBufferQueue buffer; 260 AudioBufferQueue buffer;
253 261
254 // Add 14 frames of data. 262 // Add 14 frames of data.
255 buffer.Append(MakeTestBuffer<float>( 263 buffer.Append(MakeTestBuffer<float>(
256 kSampleFormatPlanarF32, channel_layout, 1.0f, 1.0f, 4)); 264 kSampleFormatPlanarF32, channel_layout, 1.0f, 1.0f, 4));
257 buffer.Append(MakeTestBuffer<float>( 265 buffer.Append(MakeTestBuffer<float>(
258 kSampleFormatPlanarF32, channel_layout, 50.0f, 1.0f, 10)); 266 kSampleFormatPlanarF32, channel_layout, 50.0f, 1.0f, 10));
259 EXPECT_EQ(14, buffer.frames()); 267 EXPECT_EQ(14, buffer.frames());
260 268
261 // Read 6 frames from the buffer. 269 // Read 6 frames from the buffer.
262 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100); 270 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
263 EXPECT_EQ(6, buffer.ReadFrames(6, 0, bus.get())); 271 EXPECT_EQ(6, buffer.ReadFrames(6, 0, bus.get()));
264 EXPECT_EQ(8, buffer.frames()); 272 EXPECT_EQ(8, buffer.frames());
265 VerifyBus(bus.get(), 0, 4, 4, 1, 1); 273 VerifyBus(bus.get(), 0, 4, 4, 1, 1);
266 VerifyBus(bus.get(), 4, 2, 10, 50, 1); 274 VerifyBus(bus.get(), 4, 2, 10, 50, 1);
267 } 275 }
268 276
269 TEST(AudioBufferQueueTest, ReadS16Planar) { 277 TEST(AudioBufferQueueTest, ReadS16Planar) {
270 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 278 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
271 const int channels = ChannelLayoutToChannelCount(channel_layout); 279 const int channels = ChannelLayoutToChannelCount(channel_layout);
272 AudioBufferQueue buffer; 280 AudioBufferQueue buffer;
273 281
274 // Add 24 frames of data. 282 // Add 24 frames of data.
275 buffer.Append( 283 buffer.Append(
276 MakeTestBuffer<int16>(kSampleFormatPlanarS16, channel_layout, 1, 1, 4)); 284 MakeTestBuffer<int16_t>(kSampleFormatPlanarS16, channel_layout, 1, 1, 4));
277 buffer.Append( 285 buffer.Append(MakeTestBuffer<int16_t>(kSampleFormatPlanarS16, channel_layout,
278 MakeTestBuffer<int16>(kSampleFormatPlanarS16, channel_layout, 5, 1, 20)); 286 5, 1, 20));
279 EXPECT_EQ(24, buffer.frames()); 287 EXPECT_EQ(24, buffer.frames());
280 288
281 // Read 6 frames from the buffer. 289 // Read 6 frames from the buffer.
282 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100); 290 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
283 EXPECT_EQ(6, buffer.ReadFrames(6, 0, bus.get())); 291 EXPECT_EQ(6, buffer.ReadFrames(6, 0, bus.get()));
284 EXPECT_EQ(18, buffer.frames()); 292 EXPECT_EQ(18, buffer.frames());
285 VerifyBus(bus.get(), 0, 4, 4, 1.0f / kint16max, 1.0f / kint16max); 293 VerifyBus(bus.get(), 0, 4, 4, 1.0f / std::numeric_limits<int16_t>::max(),
286 VerifyBus(bus.get(), 4, 2, 20, 5.0f / kint16max, 1.0f / kint16max); 294 1.0f / std::numeric_limits<int16_t>::max());
295 VerifyBus(bus.get(), 4, 2, 20, 5.0f / std::numeric_limits<int16_t>::max(),
296 1.0f / std::numeric_limits<int16_t>::max());
287 } 297 }
288 298
289 TEST(AudioBufferQueueTest, ReadManyChannels) { 299 TEST(AudioBufferQueueTest, ReadManyChannels) {
290 const ChannelLayout channel_layout = CHANNEL_LAYOUT_OCTAGONAL; 300 const ChannelLayout channel_layout = CHANNEL_LAYOUT_OCTAGONAL;
291 const int channels = ChannelLayoutToChannelCount(channel_layout); 301 const int channels = ChannelLayoutToChannelCount(channel_layout);
292 AudioBufferQueue buffer; 302 AudioBufferQueue buffer;
293 303
294 // Add 76 frames of data. 304 // Add 76 frames of data.
295 buffer.Append( 305 buffer.Append(
296 MakeTestBuffer<float>(kSampleFormatF32, channel_layout, 0.0f, 1.0f, 6)); 306 MakeTestBuffer<float>(kSampleFormatF32, channel_layout, 0.0f, 1.0f, 6));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 EXPECT_EQ(5, buffer.PeekFrames(5, 10, 0, bus1.get())); 348 EXPECT_EQ(5, buffer.PeekFrames(5, 10, 0, bus1.get()));
339 VerifyBus(bus1.get(), 0, 5, bus1->frames(), 40, 1); 349 VerifyBus(bus1.get(), 0, 5, bus1->frames(), 40, 1);
340 350
341 // Peek to the end of the buffer. 351 // Peek to the end of the buffer.
342 EXPECT_EQ(30, buffer.frames()); 352 EXPECT_EQ(30, buffer.frames());
343 EXPECT_EQ(30, buffer.PeekFrames(60, 0, 0, bus1.get())); 353 EXPECT_EQ(30, buffer.PeekFrames(60, 0, 0, bus1.get()));
344 EXPECT_EQ(30, buffer.PeekFrames(30, 0, 0, bus1.get())); 354 EXPECT_EQ(30, buffer.PeekFrames(30, 0, 0, bus1.get()));
345 } 355 }
346 356
347 } // namespace media 357 } // namespace media
OLDNEW
« no previous file with comments | « base/files/file_util_win.cc ('k') | media/base/audio_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698