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

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

Issue 1904213003: Convert //media/filters from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove include Created 4 years, 8 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/filters/audio_renderer_algorithm.h ('k') | media/filters/chunk_demuxer.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/filters/audio_renderer_algorithm.h"
12
11 #include <stddef.h> 13 #include <stddef.h>
12 #include <stdint.h> 14 #include <stdint.h>
13 15
14 #include <algorithm> // For std::min(). 16 #include <algorithm> // For std::min().
15 #include <cmath> 17 #include <cmath>
18 #include <memory>
16 #include <vector> 19 #include <vector>
17 20
18 #include "base/bind.h" 21 #include "base/bind.h"
19 #include "base/callback.h" 22 #include "base/callback.h"
20 #include "base/macros.h" 23 #include "base/macros.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "media/base/audio_buffer.h" 24 #include "media/base/audio_buffer.h"
23 #include "media/base/audio_bus.h" 25 #include "media/base/audio_bus.h"
24 #include "media/base/channel_layout.h" 26 #include "media/base/channel_layout.h"
25 #include "media/base/test_helpers.h" 27 #include "media/base/test_helpers.h"
26 #include "media/base/timestamp_constants.h" 28 #include "media/base/timestamp_constants.h"
27 #include "media/filters/audio_renderer_algorithm.h"
28 #include "media/filters/wsola_internals.h" 29 #include "media/filters/wsola_internals.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 namespace media { 32 namespace media {
32 33
33 const int kFrameSize = 250; 34 const int kFrameSize = 250;
34 const int kSamplesPerSecond = 3000; 35 const int kSamplesPerSecond = 3000;
35 const int kOutputDurationInSec = 10; 36 const int kOutputDurationInSec = 10;
36 37
37 static void FillWithSquarePulseTrain( 38 static void FillWithSquarePulseTrain(
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 TestPlaybackRate( 166 TestPlaybackRate(
166 playback_rate, kDefaultBufferSize, kDefaultFramesRequested); 167 playback_rate, kDefaultBufferSize, kDefaultFramesRequested);
167 } 168 }
168 169
169 void TestPlaybackRate(double playback_rate, 170 void TestPlaybackRate(double playback_rate,
170 int buffer_size_in_frames, 171 int buffer_size_in_frames,
171 int total_frames_requested) { 172 int total_frames_requested) {
172 int initial_frames_enqueued = frames_enqueued_; 173 int initial_frames_enqueued = frames_enqueued_;
173 int initial_frames_buffered = algorithm_.frames_buffered(); 174 int initial_frames_buffered = algorithm_.frames_buffered();
174 175
175 scoped_ptr<AudioBus> bus = 176 std::unique_ptr<AudioBus> bus =
176 AudioBus::Create(channels_, buffer_size_in_frames); 177 AudioBus::Create(channels_, buffer_size_in_frames);
177 if (playback_rate == 0.0) { 178 if (playback_rate == 0.0) {
178 int frames_written = algorithm_.FillBuffer( 179 int frames_written = algorithm_.FillBuffer(
179 bus.get(), 0, buffer_size_in_frames, playback_rate); 180 bus.get(), 0, buffer_size_in_frames, playback_rate);
180 EXPECT_EQ(0, frames_written); 181 EXPECT_EQ(0, frames_written);
181 return; 182 return;
182 } 183 }
183 184
184 bool expect_muted = (playback_rate < 0.5 || playback_rate > 4); 185 bool expect_muted = (playback_rate < 0.5 || playback_rate > 4);
185 186
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 channels_ = ChannelLayoutToChannelCount(kChannelLayout); 241 channels_ = ChannelLayoutToChannelCount(kChannelLayout);
241 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 242 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
242 kSampleRateHz, kBytesPerSample * 8, kNumFrames); 243 kSampleRateHz, kBytesPerSample * 8, kNumFrames);
243 algorithm_.Initialize(params); 244 algorithm_.Initialize(params);
244 245
245 // A pulse is 6 milliseconds (even number of samples). 246 // A pulse is 6 milliseconds (even number of samples).
246 const int kPulseWidthSamples = 6 * kSampleRateHz / 1000; 247 const int kPulseWidthSamples = 6 * kSampleRateHz / 1000;
247 const int kHalfPulseWidthSamples = kPulseWidthSamples / 2; 248 const int kHalfPulseWidthSamples = kPulseWidthSamples / 2;
248 249
249 // For the ease of implementation get 1 frame every call to FillBuffer(). 250 // For the ease of implementation get 1 frame every call to FillBuffer().
250 scoped_ptr<AudioBus> output = AudioBus::Create(channels_, 1); 251 std::unique_ptr<AudioBus> output = AudioBus::Create(channels_, 1);
251 252
252 // Input buffer to inject pulses. 253 // Input buffer to inject pulses.
253 scoped_refptr<AudioBuffer> input = 254 scoped_refptr<AudioBuffer> input =
254 AudioBuffer::CreateBuffer(kSampleFormatPlanarF32, 255 AudioBuffer::CreateBuffer(kSampleFormatPlanarF32,
255 kChannelLayout, 256 kChannelLayout,
256 channels_, 257 channels_,
257 kSampleRateHz, 258 kSampleRateHz,
258 kPulseWidthSamples); 259 kPulseWidthSamples);
259 260
260 const std::vector<uint8_t*>& channel_data = input->channel_data(); 261 const std::vector<uint8_t*>& channel_data = input->channel_data();
261 262
262 // Fill |input| channels. 263 // Fill |input| channels.
263 FillWithSquarePulseTrain(kHalfPulseWidthSamples, 0, kPulseWidthSamples, 264 FillWithSquarePulseTrain(kHalfPulseWidthSamples, 0, kPulseWidthSamples,
264 reinterpret_cast<float*>(channel_data[0])); 265 reinterpret_cast<float*>(channel_data[0]));
265 FillWithSquarePulseTrain(kHalfPulseWidthSamples, kHalfPulseWidthSamples, 266 FillWithSquarePulseTrain(kHalfPulseWidthSamples, kHalfPulseWidthSamples,
266 kPulseWidthSamples, 267 kPulseWidthSamples,
267 reinterpret_cast<float*>(channel_data[1])); 268 reinterpret_cast<float*>(channel_data[1]));
268 269
269 // A buffer for the output until a complete pulse is created. Then 270 // A buffer for the output until a complete pulse is created. Then
270 // reference pulse is compared with this buffer. 271 // reference pulse is compared with this buffer.
271 scoped_ptr<AudioBus> pulse_buffer = AudioBus::Create( 272 std::unique_ptr<AudioBus> pulse_buffer =
272 channels_, kPulseWidthSamples); 273 AudioBus::Create(channels_, kPulseWidthSamples);
273 274
274 const float kTolerance = 0.000001f; 275 const float kTolerance = 0.000001f;
275 // Equivalent of 4 seconds. 276 // Equivalent of 4 seconds.
276 const int kNumRequestedPulses = kSampleRateHz * 4 / kPulseWidthSamples; 277 const int kNumRequestedPulses = kSampleRateHz * 4 / kPulseWidthSamples;
277 for (int n = 0; n < kNumRequestedPulses; ++n) { 278 for (int n = 0; n < kNumRequestedPulses; ++n) {
278 int num_buffered_frames = 0; 279 int num_buffered_frames = 0;
279 while (num_buffered_frames < kPulseWidthSamples) { 280 while (num_buffered_frames < kPulseWidthSamples) {
280 int num_samples = 281 int num_samples =
281 algorithm_.FillBuffer(output.get(), 0, 1, playback_rate); 282 algorithm_.FillBuffer(output.get(), 0, 1, playback_rate);
282 ASSERT_LE(num_samples, 1); 283 ASSERT_LE(num_samples, 1);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 TestPlaybackRate(1.0); 432 TestPlaybackRate(1.0);
432 TestPlaybackRate(0.5); 433 TestPlaybackRate(0.5);
433 TestPlaybackRate(1.5); 434 TestPlaybackRate(1.5);
434 } 435 }
435 436
436 TEST_F(AudioRendererAlgorithmTest, DotProduct) { 437 TEST_F(AudioRendererAlgorithmTest, DotProduct) {
437 const int kChannels = 3; 438 const int kChannels = 3;
438 const int kFrames = 20; 439 const int kFrames = 20;
439 const int kHalfPulseWidth = 2; 440 const int kHalfPulseWidth = 2;
440 441
441 scoped_ptr<AudioBus> a = AudioBus::Create(kChannels, kFrames); 442 std::unique_ptr<AudioBus> a = AudioBus::Create(kChannels, kFrames);
442 scoped_ptr<AudioBus> b = AudioBus::Create(kChannels, kFrames); 443 std::unique_ptr<AudioBus> b = AudioBus::Create(kChannels, kFrames);
443 444
444 scoped_ptr<float[]> dot_prod(new float[kChannels]); 445 std::unique_ptr<float[]> dot_prod(new float[kChannels]);
445 446
446 FillWithSquarePulseTrain(kHalfPulseWidth, 0, 0, a.get()); 447 FillWithSquarePulseTrain(kHalfPulseWidth, 0, 0, a.get());
447 FillWithSquarePulseTrain(kHalfPulseWidth, 1, 1, a.get()); 448 FillWithSquarePulseTrain(kHalfPulseWidth, 1, 1, a.get());
448 FillWithSquarePulseTrain(kHalfPulseWidth, 2, 2, a.get()); 449 FillWithSquarePulseTrain(kHalfPulseWidth, 2, 2, a.get());
449 450
450 FillWithSquarePulseTrain(kHalfPulseWidth, 0, 0, b.get()); 451 FillWithSquarePulseTrain(kHalfPulseWidth, 0, 0, b.get());
451 FillWithSquarePulseTrain(kHalfPulseWidth, 0, 1, b.get()); 452 FillWithSquarePulseTrain(kHalfPulseWidth, 0, 1, b.get());
452 FillWithSquarePulseTrain(kHalfPulseWidth, 0, 2, b.get()); 453 FillWithSquarePulseTrain(kHalfPulseWidth, 0, 2, b.get());
453 454
454 internal::MultiChannelDotProduct(a.get(), 0, b.get(), 0, kFrames, 455 internal::MultiChannelDotProduct(a.get(), 0, b.get(), 0, kFrames,
455 dot_prod.get()); 456 dot_prod.get());
456 457
457 EXPECT_FLOAT_EQ(kFrames, dot_prod[0]); 458 EXPECT_FLOAT_EQ(kFrames, dot_prod[0]);
458 EXPECT_FLOAT_EQ(0, dot_prod[1]); 459 EXPECT_FLOAT_EQ(0, dot_prod[1]);
459 EXPECT_FLOAT_EQ(-kFrames, dot_prod[2]); 460 EXPECT_FLOAT_EQ(-kFrames, dot_prod[2]);
460 461
461 internal::MultiChannelDotProduct(a.get(), 4, b.get(), 8, kFrames / 2, 462 internal::MultiChannelDotProduct(a.get(), 4, b.get(), 8, kFrames / 2,
462 dot_prod.get()); 463 dot_prod.get());
463 464
464 EXPECT_FLOAT_EQ(kFrames / 2, dot_prod[0]); 465 EXPECT_FLOAT_EQ(kFrames / 2, dot_prod[0]);
465 EXPECT_FLOAT_EQ(0, dot_prod[1]); 466 EXPECT_FLOAT_EQ(0, dot_prod[1]);
466 EXPECT_FLOAT_EQ(-kFrames / 2, dot_prod[2]); 467 EXPECT_FLOAT_EQ(-kFrames / 2, dot_prod[2]);
467 } 468 }
468 469
469 TEST_F(AudioRendererAlgorithmTest, MovingBlockEnergy) { 470 TEST_F(AudioRendererAlgorithmTest, MovingBlockEnergy) {
470 const int kChannels = 2; 471 const int kChannels = 2;
471 const int kFrames = 20; 472 const int kFrames = 20;
472 const int kFramesPerBlock = 3; 473 const int kFramesPerBlock = 3;
473 const int kNumBlocks = kFrames - (kFramesPerBlock - 1); 474 const int kNumBlocks = kFrames - (kFramesPerBlock - 1);
474 scoped_ptr<AudioBus> a = AudioBus::Create(kChannels, kFrames); 475 std::unique_ptr<AudioBus> a = AudioBus::Create(kChannels, kFrames);
475 scoped_ptr<float[]> energies(new float[kChannels * kNumBlocks]); 476 std::unique_ptr<float[]> energies(new float[kChannels * kNumBlocks]);
476 float* ch_left = a->channel(0); 477 float* ch_left = a->channel(0);
477 float* ch_right = a->channel(1); 478 float* ch_right = a->channel(1);
478 479
479 // Fill up both channels. 480 // Fill up both channels.
480 for (int n = 0; n < kFrames; ++n) { 481 for (int n = 0; n < kFrames; ++n) {
481 ch_left[n] = n; 482 ch_left[n] = n;
482 ch_right[n] = kFrames - 1 - n; 483 ch_right[n] = kFrames - 1 - n;
483 } 484 }
484 485
485 internal::MultiChannelMovingBlockEnergies(a.get(), kFramesPerBlock, 486 internal::MultiChannelMovingBlockEnergies(a.get(), kFramesPerBlock,
(...skipping 20 matching lines...) Expand all
506 TEST_F(AudioRendererAlgorithmTest, FullAndDecimatedSearch) { 507 TEST_F(AudioRendererAlgorithmTest, FullAndDecimatedSearch) {
507 const int kFramesInSearchRegion = 12; 508 const int kFramesInSearchRegion = 12;
508 const int kChannels = 2; 509 const int kChannels = 2;
509 float ch_0[] = { 510 float ch_0[] = {
510 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }; 511 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f };
511 float ch_1[] = { 512 float ch_1[] = {
512 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.1f, 1.0f, 0.1f, 0.0f, 0.0f }; 513 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.1f, 1.0f, 0.1f, 0.0f, 0.0f };
513 ASSERT_EQ(sizeof(ch_0), sizeof(ch_1)); 514 ASSERT_EQ(sizeof(ch_0), sizeof(ch_1));
514 ASSERT_EQ(static_cast<size_t>(kFramesInSearchRegion), 515 ASSERT_EQ(static_cast<size_t>(kFramesInSearchRegion),
515 sizeof(ch_0) / sizeof(*ch_0)); 516 sizeof(ch_0) / sizeof(*ch_0));
516 scoped_ptr<AudioBus> search_region = AudioBus::Create(kChannels, 517 std::unique_ptr<AudioBus> search_region =
517 kFramesInSearchRegion); 518 AudioBus::Create(kChannels, kFramesInSearchRegion);
518 float* ch = search_region->channel(0); 519 float* ch = search_region->channel(0);
519 memcpy(ch, ch_0, sizeof(float) * kFramesInSearchRegion); 520 memcpy(ch, ch_0, sizeof(float) * kFramesInSearchRegion);
520 ch = search_region->channel(1); 521 ch = search_region->channel(1);
521 memcpy(ch, ch_1, sizeof(float) * kFramesInSearchRegion); 522 memcpy(ch, ch_1, sizeof(float) * kFramesInSearchRegion);
522 523
523 const int kFramePerBlock = 4; 524 const int kFramePerBlock = 4;
524 float target_0[] = { 1.0f, 1.0f, 1.0f, 0.0f }; 525 float target_0[] = { 1.0f, 1.0f, 1.0f, 0.0f };
525 float target_1[] = { 0.0f, 1.0f, 0.1f, 1.0f }; 526 float target_1[] = { 0.0f, 1.0f, 0.1f, 1.0f };
526 ASSERT_EQ(sizeof(target_0), sizeof(target_1)); 527 ASSERT_EQ(sizeof(target_0), sizeof(target_1));
527 ASSERT_EQ(static_cast<size_t>(kFramePerBlock), 528 ASSERT_EQ(static_cast<size_t>(kFramePerBlock),
528 sizeof(target_0) / sizeof(*target_0)); 529 sizeof(target_0) / sizeof(*target_0));
529 530
530 scoped_ptr<AudioBus> target = AudioBus::Create(kChannels, 531 std::unique_ptr<AudioBus> target =
531 kFramePerBlock); 532 AudioBus::Create(kChannels, kFramePerBlock);
532 ch = target->channel(0); 533 ch = target->channel(0);
533 memcpy(ch, target_0, sizeof(float) * kFramePerBlock); 534 memcpy(ch, target_0, sizeof(float) * kFramePerBlock);
534 ch = target->channel(1); 535 ch = target->channel(1);
535 memcpy(ch, target_1, sizeof(float) * kFramePerBlock); 536 memcpy(ch, target_1, sizeof(float) * kFramePerBlock);
536 537
537 scoped_ptr<float[]> energy_target(new float[kChannels]); 538 std::unique_ptr<float[]> energy_target(new float[kChannels]);
538 539
539 internal::MultiChannelDotProduct(target.get(), 0, target.get(), 0, 540 internal::MultiChannelDotProduct(target.get(), 0, target.get(), 0,
540 kFramePerBlock, energy_target.get()); 541 kFramePerBlock, energy_target.get());
541 542
542 ASSERT_EQ(3.f, energy_target[0]); 543 ASSERT_EQ(3.f, energy_target[0]);
543 ASSERT_EQ(2.01f, energy_target[1]); 544 ASSERT_EQ(2.01f, energy_target[1]);
544 545
545 const int kNumCandidBlocks = kFramesInSearchRegion - (kFramePerBlock - 1); 546 const int kNumCandidBlocks = kFramesInSearchRegion - (kFramePerBlock - 1);
546 scoped_ptr<float[]> energy_candid_blocks(new float[kNumCandidBlocks * 547 std::unique_ptr<float[]> energy_candid_blocks(
547 kChannels]); 548 new float[kNumCandidBlocks * kChannels]);
548 549
549 internal::MultiChannelMovingBlockEnergies( 550 internal::MultiChannelMovingBlockEnergies(
550 search_region.get(), kFramePerBlock, energy_candid_blocks.get()); 551 search_region.get(), kFramePerBlock, energy_candid_blocks.get());
551 552
552 // Check the energy of the candidate blocks of the first channel. 553 // Check the energy of the candidate blocks of the first channel.
553 ASSERT_FLOAT_EQ(0, energy_candid_blocks[0]); 554 ASSERT_FLOAT_EQ(0, energy_candid_blocks[0]);
554 ASSERT_FLOAT_EQ(0, energy_candid_blocks[2]); 555 ASSERT_FLOAT_EQ(0, energy_candid_blocks[2]);
555 ASSERT_FLOAT_EQ(1, energy_candid_blocks[4]); 556 ASSERT_FLOAT_EQ(1, energy_candid_blocks[4]);
556 ASSERT_FLOAT_EQ(2, energy_candid_blocks[6]); 557 ASSERT_FLOAT_EQ(2, energy_candid_blocks[6]);
557 ASSERT_FLOAT_EQ(3, energy_candid_blocks[8]); 558 ASSERT_FLOAT_EQ(3, energy_candid_blocks[8]);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 WsolaTest(0.6); 636 WsolaTest(0.6);
636 } 637 }
637 638
638 TEST_F(AudioRendererAlgorithmTest, WsolaSpeedup) { 639 TEST_F(AudioRendererAlgorithmTest, WsolaSpeedup) {
639 WsolaTest(1.6); 640 WsolaTest(1.6);
640 } 641 }
641 642
642 TEST_F(AudioRendererAlgorithmTest, FillBufferOffset) { 643 TEST_F(AudioRendererAlgorithmTest, FillBufferOffset) {
643 Initialize(); 644 Initialize();
644 645
645 scoped_ptr<AudioBus> bus = AudioBus::Create(channels_, kFrameSize); 646 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels_, kFrameSize);
646 647
647 // Verify that the first half of |bus| remains zero and the last half is 648 // Verify that the first half of |bus| remains zero and the last half is
648 // filled appropriately at normal, above normal, below normal, and muted 649 // filled appropriately at normal, above normal, below normal, and muted
649 // rates. 650 // rates.
650 const int kHalfSize = kFrameSize / 2; 651 const int kHalfSize = kFrameSize / 2;
651 const float kAudibleRates[] = {1.0f, 2.0f, 0.5f}; 652 const float kAudibleRates[] = {1.0f, 2.0f, 0.5f};
652 for (size_t i = 0; i < arraysize(kAudibleRates); ++i) { 653 for (size_t i = 0; i < arraysize(kAudibleRates); ++i) {
653 SCOPED_TRACE(kAudibleRates[i]); 654 SCOPED_TRACE(kAudibleRates[i]);
654 bus->Zero(); 655 bus->Zero();
655 656
(...skipping 14 matching lines...) Expand all
670 const int frames_filled = 671 const int frames_filled =
671 algorithm_.FillBuffer(bus.get(), kHalfSize, kHalfSize, kMutedRates[i]); 672 algorithm_.FillBuffer(bus.get(), kHalfSize, kHalfSize, kMutedRates[i]);
672 ASSERT_EQ(kHalfSize, frames_filled); 673 ASSERT_EQ(kHalfSize, frames_filled);
673 ASSERT_FALSE(VerifyAudioData(bus.get(), 0, kHalfSize, 0)); 674 ASSERT_FALSE(VerifyAudioData(bus.get(), 0, kHalfSize, 0));
674 ASSERT_TRUE(VerifyAudioData(bus.get(), kHalfSize, kHalfSize, 0)); 675 ASSERT_TRUE(VerifyAudioData(bus.get(), kHalfSize, kHalfSize, 0));
675 FillAlgorithmQueue(); 676 FillAlgorithmQueue();
676 } 677 }
677 } 678 }
678 679
679 } // namespace media 680 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/audio_renderer_algorithm.h ('k') | media/filters/chunk_demuxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698