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

Side by Side Diff: media/audio/audio_debug_file_writer_unittest.cc

Issue 2582703003: Audio output debug recording. (Closed)
Patch Set: Code review. Created 3 years, 9 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/audio/audio_debug_file_writer.cc ('k') | media/audio/audio_debug_recording_helper.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "base/sys_byteorder.h" 12 #include "base/sys_byteorder.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "media/audio/audio_debug_file_writer.h" 14 #include "media/audio/audio_debug_file_writer.h"
15 #include "media/base/audio_bus.h" 15 #include "media/base/audio_bus.h"
16 #include "media/base/audio_sample_types.h"
16 #include "media/base/test_helpers.h" 17 #include "media/base/test_helpers.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace media { 20 namespace media {
20 21
21 namespace { 22 namespace {
22 23
23 static const uint16_t kBytesPerSample = sizeof(uint16_t); 24 static const uint16_t kBytesPerSample = sizeof(uint16_t);
24 static const uint16_t kPcmEncoding = 1; 25 static const uint16_t kPcmEncoding = 1;
25 static const size_t kWavHeaderSize = 44; 26 static const size_t kWavHeaderSize = 44;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 161
161 callback.Run(); 162 callback.Run();
162 } 163 }
163 164
164 void DoDebugRecording() { 165 void DoDebugRecording() {
165 // Write tasks are posted to |file_thread_|. 166 // Write tasks are posted to |file_thread_|.
166 for (int i = 0; i < writes_; ++i) { 167 for (int i = 0; i < writes_; ++i) {
167 std::unique_ptr<AudioBus> bus = 168 std::unique_ptr<AudioBus> bus =
168 AudioBus::Create(params_.channels(), params_.frames_per_buffer()); 169 AudioBus::Create(params_.channels(), params_.frames_per_buffer());
169 170
170 bus->FromInterleaved( 171 bus->FromInterleaved<media::SignedInt16SampleTypeTraits>(
171 source_interleaved_.get() + 172 source_interleaved_.get() +
172 i * params_.channels() * params_.frames_per_buffer(), 173 i * params_.channels() * params_.frames_per_buffer(),
173 params_.frames_per_buffer(), kBytesPerSample); 174 params_.frames_per_buffer());
174 175
175 debug_writer_->Write(std::move(bus)); 176 debug_writer_->Write(std::move(bus));
176 } 177 }
177 } 178 }
178 179
179 void WaitForRecordingCompletion() { 180 void WaitForRecordingCompletion() {
180 WaitableMessageLoopEvent event; 181 WaitableMessageLoopEvent event;
181 182
182 // Post a task to the file thread indicating that all the writes are done. 183 // Post a task to the file thread indicating that all the writes are done.
183 file_thread_.task_runner()->PostTask( 184 file_thread_.task_runner()->PostTask(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 238
238 private: 239 private:
239 DISALLOW_COPY_AND_ASSIGN(AudioDebugFileWriterTest); 240 DISALLOW_COPY_AND_ASSIGN(AudioDebugFileWriterTest);
240 }; 241 };
241 242
242 class AudioDebugFileWriterBehavioralTest : public AudioDebugFileWriterTest {}; 243 class AudioDebugFileWriterBehavioralTest : public AudioDebugFileWriterTest {};
243 244
244 TEST_P(AudioDebugFileWriterTest, WaveRecordingTest) { 245 TEST_P(AudioDebugFileWriterTest, WaveRecordingTest) {
245 debug_writer_.reset( 246 debug_writer_.reset(
246 new AudioDebugFileWriter(params_, file_thread_.task_runner())); 247 new AudioDebugFileWriter(params_, file_thread_.task_runner()));
248 RecordAndVerifyOnce();
249 }
247 250
248 RecordAndVerifyOnce(); 251 TEST_P(AudioDebugFileWriterTest, GetFileNameExtension) {
252 debug_writer_.reset(
253 new AudioDebugFileWriter(params_, file_thread_.task_runner()));
254 EXPECT_EQ(FILE_PATH_LITERAL("wav"),
255 base::FilePath::StringType(debug_writer_->GetFileNameExtension()));
249 } 256 }
250 257
251 TEST_P(AudioDebugFileWriterBehavioralTest, 258 TEST_P(AudioDebugFileWriterBehavioralTest,
252 DeletedBeforeRecordingFinishedOnFileThread) { 259 DeletedBeforeRecordingFinishedOnFileThread) {
253 debug_writer_.reset( 260 debug_writer_.reset(
254 new AudioDebugFileWriter(params_, file_thread_.task_runner())); 261 new AudioDebugFileWriter(params_, file_thread_.task_runner()));
255 262
256 base::FilePath file_path; 263 base::FilePath file_path;
257 EXPECT_TRUE(base::CreateTemporaryFile(&file_path)); 264 EXPECT_TRUE(base::CreateTemporaryFile(&file_path));
258 265
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 AudioDebugFileWriterBehavioralTest, 361 AudioDebugFileWriterBehavioralTest,
355 // Using 10ms frames per buffer everywhere. 362 // Using 10ms frames per buffer everywhere.
356 testing::Values( 363 testing::Values(
357 // No writes. 364 // No writes.
358 std::tr1::make_tuple(ChannelLayout::CHANNEL_LAYOUT_MONO, 365 std::tr1::make_tuple(ChannelLayout::CHANNEL_LAYOUT_MONO,
359 44100, 366 44100,
360 44100 / 100, 367 44100 / 100,
361 100))); 368 100)));
362 369
363 } // namespace media 370 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_debug_file_writer.cc ('k') | media/audio/audio_debug_recording_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698