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

Side by Side Diff: media/base/audio_push_fifo_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: . 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <limits> 5 #include <limits>
6 #include <memory>
6 #include <vector> 7 #include <vector>
7 8
8 #include "base/bind.h" 9 #include "base/bind.h"
9 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "media/base/audio_bus.h" 12 #include "media/base/audio_bus.h"
12 #include "media/base/audio_push_fifo.h" 13 #include "media/base/audio_push_fifo.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace media { 16 namespace media {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 int GetNumPushTestIterations(int input_chunk_size) const { 50 int GetNumPushTestIterations(int input_chunk_size) const {
50 return 3 * std::max(1, output_chunk_size() / input_chunk_size); 51 return 3 * std::max(1, output_chunk_size() / input_chunk_size);
51 } 52 }
52 53
53 // Repeatedly pushes constant-sized batches of input samples and checks that 54 // Repeatedly pushes constant-sized batches of input samples and checks that
54 // the input data is re-chunked correctly. 55 // the input data is re-chunked correctly.
55 void RunSimpleRechunkTest(int input_chunk_size) { 56 void RunSimpleRechunkTest(int input_chunk_size) {
56 const int num_iterations = GetNumPushTestIterations(input_chunk_size); 57 const int num_iterations = GetNumPushTestIterations(input_chunk_size);
57 58
58 int sample_value = 0; 59 int sample_value = 0;
59 const scoped_ptr<AudioBus> audio_bus = 60 const std::unique_ptr<AudioBus> audio_bus =
60 AudioBus::Create(1, input_chunk_size); 61 AudioBus::Create(1, input_chunk_size);
61 62
62 for (int i = 0; i < num_iterations; ++i) { 63 for (int i = 0; i < num_iterations; ++i) {
63 EXPECT_EQ(GetExpectedOutputChunks(i * input_chunk_size), results_.size()); 64 EXPECT_EQ(GetExpectedOutputChunks(i * input_chunk_size), results_.size());
64 65
65 // Fill audio data with predictable values. 66 // Fill audio data with predictable values.
66 for (int j = 0; j < audio_bus->frames(); ++j) 67 for (int j = 0; j < audio_bus->frames(); ++j)
67 audio_bus->channel(0)[j] = static_cast<float>(sample_value++); 68 audio_bus->channel(0)[j] = static_cast<float>(sample_value++);
68 69
69 fifo_->Push(*audio_bus); 70 fifo_->Push(*audio_bus);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 109 }
109 } 110 }
110 111
111 // Returns a "random" integer in the range [begin,end). 112 // Returns a "random" integer in the range [begin,end).
112 int GetRandomInRange(int begin, int end) { 113 int GetRandomInRange(int begin, int end) {
113 const int len = end - begin; 114 const int len = end - begin;
114 const int rand_offset = (len == 0) ? 0 : (NextRandomInt() % (end - begin)); 115 const int rand_offset = (len == 0) ? 0 : (NextRandomInt() % (end - begin));
115 return begin + rand_offset; 116 return begin + rand_offset;
116 } 117 }
117 118
118 scoped_ptr<AudioPushFifo> fifo_; 119 std::unique_ptr<AudioPushFifo> fifo_;
119 std::vector<OutputChunkResult> results_; 120 std::vector<OutputChunkResult> results_;
120 121
121 private: 122 private:
122 // Called by |fifo_| to deliver another chunk of audio. Sanity checks 123 // Called by |fifo_| to deliver another chunk of audio. Sanity checks
123 // the sample values are as expected, and without any dropped/duplicated, and 124 // the sample values are as expected, and without any dropped/duplicated, and
124 // adds a result to |results_|. 125 // adds a result to |results_|.
125 void ReceiveAndCheckNextChunk(const AudioBus& audio_bus, int frame_delay) { 126 void ReceiveAndCheckNextChunk(const AudioBus& audio_bus, int frame_delay) {
126 OutputChunkResult result; 127 OutputChunkResult result;
127 result.num_frames = audio_bus.frames(); 128 result.num_frames = audio_bus.frames();
128 result.first_sample_value = audio_bus.channel(0)[0]; 129 result.first_sample_value = audio_bus.channel(0)[0];
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // occurred; and 2) there are at least 3 entries in |results_|. 195 // occurred; and 2) there are at least 3 entries in |results_|.
195 const int kMinNumIterations = 30; 196 const int kMinNumIterations = 30;
196 197
197 int sample_value = 0; 198 int sample_value = 0;
198 int frames_pushed_so_far = 0; 199 int frames_pushed_so_far = 0;
199 for (int i = 0; i < kMinNumIterations || results_.size() < 3; ++i) { 200 for (int i = 0; i < kMinNumIterations || results_.size() < 3; ++i) {
200 EXPECT_EQ(GetExpectedOutputChunks(frames_pushed_so_far), results_.size()); 201 EXPECT_EQ(GetExpectedOutputChunks(frames_pushed_so_far), results_.size());
201 202
202 // Create an AudioBus of a random length, populated with sample values. 203 // Create an AudioBus of a random length, populated with sample values.
203 const int input_chunk_size = GetRandomInRange(1, 1920); 204 const int input_chunk_size = GetRandomInRange(1, 1920);
204 const scoped_ptr<AudioBus> audio_bus = 205 const std::unique_ptr<AudioBus> audio_bus =
205 AudioBus::Create(1, input_chunk_size); 206 AudioBus::Create(1, input_chunk_size);
206 for (int j = 0; j < audio_bus->frames(); ++j) 207 for (int j = 0; j < audio_bus->frames(); ++j)
207 audio_bus->channel(0)[j] = static_cast<float>(sample_value++); 208 audio_bus->channel(0)[j] = static_cast<float>(sample_value++);
208 209
209 fifo_->Push(*audio_bus); 210 fifo_->Push(*audio_bus);
210 // Note: AudioPushFifo has just called ReceiveAndCheckNextChunk() zero or 211 // Note: AudioPushFifo has just called ReceiveAndCheckNextChunk() zero or
211 // more times. 212 // more times.
212 213
213 frames_pushed_so_far += input_chunk_size; 214 frames_pushed_so_far += input_chunk_size;
214 } 215 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // 60 ms output chunks at common sample rates. 248 // 60 ms output chunks at common sample rates.
248 960, // 16000 Hz 249 960, // 16000 Hz
249 1323, // 22050 Hz 250 1323, // 22050 Hz
250 2646, // 44100 Hz 251 2646, // 44100 Hz
251 2880 // 48000 Hz 252 2880 // 48000 Hz
252 )); 253 ));
253 254
254 } // namespace 255 } // namespace
255 256
256 } // namespace media 257 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698