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

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

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: android Created 4 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
« no previous file with comments | « media/base/audio_buffer_queue_unittest.cc ('k') | media/base/audio_bus.h » ('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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <limits> 7 #include <limits>
8 #include <memory>
8 9
9 #include "media/base/audio_buffer.h" 10 #include "media/base/audio_buffer.h"
10 #include "media/base/audio_bus.h" 11 #include "media/base/audio_bus.h"
11 #include "media/base/test_helpers.h" 12 #include "media/base/test_helpers.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace media { 15 namespace media {
15 16
16 static const int kSampleRate = 48000; 17 static const int kSampleRate = 48000;
17 18
(...skipping 27 matching lines...) Expand all
45 channels, 46 channels,
46 kSampleRate, 47 kSampleRate,
47 0, 48 0,
48 1, 49 1,
49 frames, 50 frames,
50 timestamp); 51 timestamp);
51 EXPECT_EQ(frames, buffer->frame_count()); 52 EXPECT_EQ(frames, buffer->frame_count());
52 EXPECT_EQ(timestamp, buffer->timestamp()); 53 EXPECT_EQ(timestamp, buffer->timestamp());
53 EXPECT_EQ(duration, buffer->duration()); 54 EXPECT_EQ(duration, buffer->duration());
54 55
55 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); 56 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
56 57
57 // Verify all frames before trimming. 58 // Verify all frames before trimming.
58 buffer->ReadFrames(frames, 0, 0, bus.get()); 59 buffer->ReadFrames(frames, 0, 0, bus.get());
59 VerifyBus(bus.get(), frames, 0, 1); 60 VerifyBus(bus.get(), frames, 0, 1);
60 61
61 // Trim 10ms of frames from the middle of the buffer. 62 // Trim 10ms of frames from the middle of the buffer.
62 int trim_start = frames / 2; 63 int trim_start = frames / 2;
63 const int trim_length = kSampleRate / 100; 64 const int trim_length = kSampleRate / 100;
64 const base::TimeDelta trim_duration = base::TimeDelta::FromMilliseconds(10); 65 const base::TimeDelta trim_duration = base::TimeDelta::FromMilliseconds(10);
65 buffer->TrimRange(trim_start, trim_start + trim_length); 66 buffer->TrimRange(trim_start, trim_start + trim_length);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 208 }
208 209
209 TEST(AudioBufferTest, ReadU8) { 210 TEST(AudioBufferTest, ReadU8) {
210 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0; 211 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
211 const int channels = ChannelLayoutToChannelCount(channel_layout); 212 const int channels = ChannelLayoutToChannelCount(channel_layout);
212 const int frames = 10; 213 const int frames = 10;
213 const base::TimeDelta start_time; 214 const base::TimeDelta start_time;
214 scoped_refptr<AudioBuffer> buffer = 215 scoped_refptr<AudioBuffer> buffer =
215 MakeAudioBuffer<uint8_t>(kSampleFormatU8, channel_layout, channels, 216 MakeAudioBuffer<uint8_t>(kSampleFormatU8, channel_layout, channels,
216 kSampleRate, 128, 1, frames, start_time); 217 kSampleRate, 128, 1, frames, start_time);
217 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); 218 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
218 buffer->ReadFrames(frames, 0, 0, bus.get()); 219 buffer->ReadFrames(frames, 0, 0, bus.get());
219 VerifyBus(bus.get(), frames, 0, 1.0f / 127.0f); 220 VerifyBus(bus.get(), frames, 0, 1.0f / 127.0f);
220 221
221 // Now read the same data one frame at a time. 222 // Now read the same data one frame at a time.
222 bus->Zero(); 223 bus->Zero();
223 for (int i = 0; i < frames; ++i) 224 for (int i = 0; i < frames; ++i)
224 buffer->ReadFrames(1, i, i, bus.get()); 225 buffer->ReadFrames(1, i, i, bus.get());
225 VerifyBus(bus.get(), frames, 0, 1.0f / 127.0f); 226 VerifyBus(bus.get(), frames, 0, 1.0f / 127.0f);
226 } 227 }
227 228
228 TEST(AudioBufferTest, ReadS16) { 229 TEST(AudioBufferTest, ReadS16) {
229 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 230 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
230 const int channels = ChannelLayoutToChannelCount(channel_layout); 231 const int channels = ChannelLayoutToChannelCount(channel_layout);
231 const int frames = 10; 232 const int frames = 10;
232 const base::TimeDelta start_time; 233 const base::TimeDelta start_time;
233 scoped_refptr<AudioBuffer> buffer = 234 scoped_refptr<AudioBuffer> buffer =
234 MakeAudioBuffer<int16_t>(kSampleFormatS16, channel_layout, channels, 235 MakeAudioBuffer<int16_t>(kSampleFormatS16, channel_layout, channels,
235 kSampleRate, 1, 1, frames, start_time); 236 kSampleRate, 1, 1, frames, start_time);
236 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); 237 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
237 buffer->ReadFrames(frames, 0, 0, bus.get()); 238 buffer->ReadFrames(frames, 0, 0, bus.get());
238 VerifyBus(bus.get(), frames, 1.0f / std::numeric_limits<int16_t>::max(), 239 VerifyBus(bus.get(), frames, 1.0f / std::numeric_limits<int16_t>::max(),
239 1.0f / std::numeric_limits<int16_t>::max()); 240 1.0f / std::numeric_limits<int16_t>::max());
240 241
241 // Now read the same data one frame at a time. 242 // Now read the same data one frame at a time.
242 bus->Zero(); 243 bus->Zero();
243 for (int i = 0; i < frames; ++i) 244 for (int i = 0; i < frames; ++i)
244 buffer->ReadFrames(1, i, i, bus.get()); 245 buffer->ReadFrames(1, i, i, bus.get());
245 VerifyBus(bus.get(), frames, 1.0f / std::numeric_limits<int16_t>::max(), 246 VerifyBus(bus.get(), frames, 1.0f / std::numeric_limits<int16_t>::max(),
246 1.0f / std::numeric_limits<int16_t>::max()); 247 1.0f / std::numeric_limits<int16_t>::max());
247 } 248 }
248 249
249 TEST(AudioBufferTest, ReadS32) { 250 TEST(AudioBufferTest, ReadS32) {
250 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 251 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
251 const int channels = ChannelLayoutToChannelCount(channel_layout); 252 const int channels = ChannelLayoutToChannelCount(channel_layout);
252 const int frames = 20; 253 const int frames = 20;
253 const base::TimeDelta start_time; 254 const base::TimeDelta start_time;
254 scoped_refptr<AudioBuffer> buffer = 255 scoped_refptr<AudioBuffer> buffer =
255 MakeAudioBuffer<int32_t>(kSampleFormatS32, channel_layout, channels, 256 MakeAudioBuffer<int32_t>(kSampleFormatS32, channel_layout, channels,
256 kSampleRate, 1, 1, frames, start_time); 257 kSampleRate, 1, 1, frames, start_time);
257 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); 258 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
258 buffer->ReadFrames(frames, 0, 0, bus.get()); 259 buffer->ReadFrames(frames, 0, 0, bus.get());
259 VerifyBus(bus.get(), frames, 1.0f / std::numeric_limits<int32_t>::max(), 260 VerifyBus(bus.get(), frames, 1.0f / std::numeric_limits<int32_t>::max(),
260 1.0f / std::numeric_limits<int32_t>::max()); 261 1.0f / std::numeric_limits<int32_t>::max());
261 262
262 // Read second 10 frames. 263 // Read second 10 frames.
263 bus->Zero(); 264 bus->Zero();
264 buffer->ReadFrames(10, 10, 0, bus.get()); 265 buffer->ReadFrames(10, 10, 0, bus.get());
265 VerifyBus(bus.get(), 10, 11.0f / std::numeric_limits<int32_t>::max(), 266 VerifyBus(bus.get(), 10, 11.0f / std::numeric_limits<int32_t>::max(),
266 1.0f / std::numeric_limits<int32_t>::max()); 267 1.0f / std::numeric_limits<int32_t>::max());
267 } 268 }
268 269
269 TEST(AudioBufferTest, ReadF32) { 270 TEST(AudioBufferTest, ReadF32) {
270 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 271 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
271 const int channels = ChannelLayoutToChannelCount(channel_layout); 272 const int channels = ChannelLayoutToChannelCount(channel_layout);
272 const int frames = 20; 273 const int frames = 20;
273 const base::TimeDelta start_time; 274 const base::TimeDelta start_time;
274 scoped_refptr<AudioBuffer> buffer = MakeAudioBuffer<float>(kSampleFormatF32, 275 scoped_refptr<AudioBuffer> buffer = MakeAudioBuffer<float>(kSampleFormatF32,
275 channel_layout, 276 channel_layout,
276 channels, 277 channels,
277 kSampleRate, 278 kSampleRate,
278 1.0f, 279 1.0f,
279 1.0f, 280 1.0f,
280 frames, 281 frames,
281 start_time); 282 start_time);
282 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); 283 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
283 buffer->ReadFrames(10, 0, 0, bus.get()); 284 buffer->ReadFrames(10, 0, 0, bus.get());
284 VerifyBus(bus.get(), 10, 1, 1); 285 VerifyBus(bus.get(), 10, 1, 1);
285 286
286 // Read second 10 frames. 287 // Read second 10 frames.
287 bus->Zero(); 288 bus->Zero();
288 buffer->ReadFrames(10, 10, 0, bus.get()); 289 buffer->ReadFrames(10, 10, 0, bus.get());
289 VerifyBus(bus.get(), 10, 11, 1); 290 VerifyBus(bus.get(), 10, 11, 1);
290 } 291 }
291 292
292 TEST(AudioBufferTest, ReadS16Planar) { 293 TEST(AudioBufferTest, ReadS16Planar) {
293 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 294 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
294 const int channels = ChannelLayoutToChannelCount(channel_layout); 295 const int channels = ChannelLayoutToChannelCount(channel_layout);
295 const int frames = 20; 296 const int frames = 20;
296 const base::TimeDelta start_time; 297 const base::TimeDelta start_time;
297 scoped_refptr<AudioBuffer> buffer = 298 scoped_refptr<AudioBuffer> buffer =
298 MakeAudioBuffer<int16_t>(kSampleFormatPlanarS16, channel_layout, channels, 299 MakeAudioBuffer<int16_t>(kSampleFormatPlanarS16, channel_layout, channels,
299 kSampleRate, 1, 1, frames, start_time); 300 kSampleRate, 1, 1, frames, start_time);
300 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); 301 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
301 buffer->ReadFrames(10, 0, 0, bus.get()); 302 buffer->ReadFrames(10, 0, 0, bus.get());
302 VerifyBus(bus.get(), 10, 1.0f / std::numeric_limits<int16_t>::max(), 303 VerifyBus(bus.get(), 10, 1.0f / std::numeric_limits<int16_t>::max(),
303 1.0f / std::numeric_limits<int16_t>::max()); 304 1.0f / std::numeric_limits<int16_t>::max());
304 305
305 // Read all the frames backwards, one by one. ch[0] should be 20, 19, ... 306 // Read all the frames backwards, one by one. ch[0] should be 20, 19, ...
306 bus->Zero(); 307 bus->Zero();
307 for (int i = frames - 1; i >= 0; --i) 308 for (int i = frames - 1; i >= 0; --i)
308 buffer->ReadFrames(1, i, i, bus.get()); 309 buffer->ReadFrames(1, i, i, bus.get());
309 VerifyBus(bus.get(), frames, 1.0f / std::numeric_limits<int16_t>::max(), 310 VerifyBus(bus.get(), frames, 1.0f / std::numeric_limits<int16_t>::max(),
310 1.0f / std::numeric_limits<int16_t>::max()); 311 1.0f / std::numeric_limits<int16_t>::max());
(...skipping 22 matching lines...) Expand all
333 channels, 334 channels,
334 kSampleRate, 335 kSampleRate,
335 1.0f, 336 1.0f,
336 1.0f, 337 1.0f,
337 frames, 338 frames,
338 start_time); 339 start_time);
339 340
340 // Read all 100 frames from the buffer. F32 is planar, so ch[0] should be 1, 341 // Read all 100 frames from the buffer. F32 is planar, so ch[0] should be 1,
341 // 2, 3, 4, ..., ch[1] should be 101, 102, 103, ..., and so on for all 4 342 // 2, 3, 4, ..., ch[1] should be 101, 102, 103, ..., and so on for all 4
342 // channels. 343 // channels.
343 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100); 344 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
344 buffer->ReadFrames(frames, 0, 0, bus.get()); 345 buffer->ReadFrames(frames, 0, 0, bus.get());
345 VerifyBus(bus.get(), frames, 1, 1); 346 VerifyBus(bus.get(), frames, 1, 1);
346 347
347 // Now read 20 frames from the middle of the buffer. 348 // Now read 20 frames from the middle of the buffer.
348 bus->Zero(); 349 bus->Zero();
349 buffer->ReadFrames(20, 50, 0, bus.get()); 350 buffer->ReadFrames(20, 50, 0, bus.get());
350 VerifyBus(bus.get(), 20, 51, 1); 351 VerifyBus(bus.get(), 20, 51, 1);
351 } 352 }
352 353
353 TEST(AudioBufferTest, EmptyBuffer) { 354 TEST(AudioBufferTest, EmptyBuffer) {
354 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0; 355 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
355 const int channels = ChannelLayoutToChannelCount(channel_layout); 356 const int channels = ChannelLayoutToChannelCount(channel_layout);
356 const int frames = kSampleRate / 100; 357 const int frames = kSampleRate / 100;
357 const base::TimeDelta start_time; 358 const base::TimeDelta start_time;
358 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateEmptyBuffer( 359 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateEmptyBuffer(
359 channel_layout, channels, kSampleRate, frames, start_time); 360 channel_layout, channels, kSampleRate, frames, start_time);
360 EXPECT_EQ(frames, buffer->frame_count()); 361 EXPECT_EQ(frames, buffer->frame_count());
361 EXPECT_EQ(start_time, buffer->timestamp()); 362 EXPECT_EQ(start_time, buffer->timestamp());
362 EXPECT_EQ(base::TimeDelta::FromMilliseconds(10), buffer->duration()); 363 EXPECT_EQ(base::TimeDelta::FromMilliseconds(10), buffer->duration());
363 EXPECT_FALSE(buffer->end_of_stream()); 364 EXPECT_FALSE(buffer->end_of_stream());
364 365
365 // Read all 100 frames from the buffer. All data should be 0. 366 // Read all 100 frames from the buffer. All data should be 0.
366 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); 367 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
367 buffer->ReadFrames(frames, 0, 0, bus.get()); 368 buffer->ReadFrames(frames, 0, 0, bus.get());
368 VerifyBus(bus.get(), frames, 0, 0); 369 VerifyBus(bus.get(), frames, 0, 0);
369 } 370 }
370 371
371 TEST(AudioBufferTest, Trim) { 372 TEST(AudioBufferTest, Trim) {
372 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0; 373 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
373 const int channels = ChannelLayoutToChannelCount(channel_layout); 374 const int channels = ChannelLayoutToChannelCount(channel_layout);
374 const int frames = kSampleRate / 10; 375 const int frames = kSampleRate / 10;
375 const base::TimeDelta start_time; 376 const base::TimeDelta start_time;
376 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); 377 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
377 scoped_refptr<AudioBuffer> buffer = 378 scoped_refptr<AudioBuffer> buffer =
378 MakeAudioBuffer<float>(kSampleFormatPlanarF32, 379 MakeAudioBuffer<float>(kSampleFormatPlanarF32,
379 channel_layout, 380 channel_layout,
380 channels, 381 channels,
381 kSampleRate, 382 kSampleRate,
382 0.0f, 383 0.0f,
383 1.0f, 384 1.0f,
384 frames, 385 frames,
385 start_time); 386 start_time);
386 EXPECT_EQ(frames, buffer->frame_count()); 387 EXPECT_EQ(frames, buffer->frame_count());
387 EXPECT_EQ(start_time, buffer->timestamp()); 388 EXPECT_EQ(start_time, buffer->timestamp());
388 EXPECT_EQ(duration, buffer->duration()); 389 EXPECT_EQ(duration, buffer->duration());
389 390
390 const int ten_ms_of_frames = kSampleRate / 100; 391 const int ten_ms_of_frames = kSampleRate / 100;
391 const base::TimeDelta ten_ms = base::TimeDelta::FromMilliseconds(10); 392 const base::TimeDelta ten_ms = base::TimeDelta::FromMilliseconds(10);
392 393
393 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames); 394 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
394 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get()); 395 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
395 VerifyBus(bus.get(), buffer->frame_count(), 0.0f, 1.0f); 396 VerifyBus(bus.get(), buffer->frame_count(), 0.0f, 1.0f);
396 397
397 // Trim off 10ms of frames from the start. 398 // Trim off 10ms of frames from the start.
398 buffer->TrimStart(ten_ms_of_frames); 399 buffer->TrimStart(ten_ms_of_frames);
399 EXPECT_EQ(start_time + ten_ms, buffer->timestamp()); 400 EXPECT_EQ(start_time + ten_ms, buffer->timestamp());
400 EXPECT_EQ(frames - ten_ms_of_frames, buffer->frame_count()); 401 EXPECT_EQ(frames - ten_ms_of_frames, buffer->frame_count());
401 EXPECT_EQ(duration - ten_ms, buffer->duration()); 402 EXPECT_EQ(duration - ten_ms, buffer->duration());
402 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get()); 403 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
403 VerifyBus(bus.get(), buffer->frame_count(), ten_ms_of_frames, 1.0f); 404 VerifyBus(bus.get(), buffer->frame_count(), ten_ms_of_frames, 1.0f);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 548
548 TEST(AudioBufferTest, ReadFramesInterleavedS16FromPlanarS16) { 549 TEST(AudioBufferTest, ReadFramesInterleavedS16FromPlanarS16) {
549 ReadFramesInterleavedS16Test(kSampleFormatPlanarS16); 550 ReadFramesInterleavedS16Test(kSampleFormatPlanarS16);
550 } 551 }
551 552
552 TEST(AudioBufferTest, ReadFramesInterleavedS16FromPlanarF32) { 553 TEST(AudioBufferTest, ReadFramesInterleavedS16FromPlanarF32) {
553 ReadFramesInterleavedS16Test(kSampleFormatPlanarF32); 554 ReadFramesInterleavedS16Test(kSampleFormatPlanarF32);
554 } 555 }
555 556
556 } // namespace media 557 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_buffer_queue_unittest.cc ('k') | media/base/audio_bus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698