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

Side by Side Diff: chrome/browser/media/webrtc_browsertest_audio.cc

Issue 1453233002: Improve input handling for WaveAudioHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: More comments, more test cases. Created 5 years, 1 month 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 | « no previous file | media/audio/BUILD.gn » ('j') | media/audio/simple_sources.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/media/webrtc_browsertest_audio.h" 5 #include "chrome/browser/media/webrtc_browsertest_audio.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "media/audio/audio_parameters.h" 9 #include "media/audio/audio_parameters.h"
10 #include "media/audio/audio_power_monitor.h" 10 #include "media/audio/audio_power_monitor.h"
(...skipping 19 matching lines...) Expand all
30 uint8* wav_file_data = new uint8[wav_file_length]; 30 uint8* wav_file_data = new uint8[wav_file_length];
31 size_t read_bytes = wav_file.Read(0, reinterpret_cast<char*>(wav_file_data), 31 size_t read_bytes = wav_file.Read(0, reinterpret_cast<char*>(wav_file_data),
32 wav_file_length); 32 wav_file_length);
33 if (read_bytes != wav_file_length) { 33 if (read_bytes != wav_file_length) {
34 CHECK(false) << "Failed to read all bytes of " << wav_filename.value(); 34 CHECK(false) << "Failed to read all bytes of " << wav_filename.value();
35 return nullptr; 35 return nullptr;
36 } 36 }
37 *file_length = wav_file_length; 37 *file_length = wav_file_length;
38 return scoped_ptr<uint8[]>(wav_file_data); 38 return scoped_ptr<uint8[]>(wav_file_data);
39 } 39 }
40
41 scoped_ptr<media::WavAudioHandler> CreateWavAudioHandler(
42 const base::FilePath& wav_filename, const uint8* wav_file_data,
43 size_t wav_file_length) {
44 base::StringPiece wav_data(reinterpret_cast<const char*>(wav_file_data),
45 wav_file_length);
46 scoped_ptr<media::WavAudioHandler> wav_audio_handler(
47 new media::WavAudioHandler(wav_data));
48
49 return wav_audio_handler.Pass();
50 }
51
52 } // namespace 40 } // namespace
53 41
54 namespace test { 42 namespace test {
55 43
56 float ComputeAudioEnergyForWavFile(const base::FilePath& wav_filename, 44 float ComputeAudioEnergyForWavFile(const base::FilePath& wav_filename,
57 media::AudioParameters* file_parameters) { 45 media::AudioParameters* file_parameters) {
58 // Read the file, and put its data in a scoped_ptr so it gets deleted later. 46 // Read the file, and put its data in a scoped_ptr so it gets deleted later.
59 size_t file_length = 0; 47 size_t file_length = 0;
60 scoped_ptr<uint8[]> wav_file_data = ReadWavFile(wav_filename, &file_length); 48 scoped_ptr<uint8[]> wav_file_data = ReadWavFile(wav_filename, &file_length);
61 scoped_ptr<media::WavAudioHandler> wav_audio_handler = CreateWavAudioHandler( 49 auto wav_audio_handler = media::WavAudioHandler::Create(base::StringPiece(
62 wav_filename, wav_file_data.get(), file_length); 50 reinterpret_cast<const char*>(wav_file_data), file_length));
63 51
64 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create( 52 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(
65 wav_audio_handler->num_channels(), wav_audio_handler->total_frames()); 53 wav_audio_handler->num_channels(), wav_audio_handler->total_frames());
66 base::TimeDelta file_duration = wav_audio_handler->GetDuration(); 54 base::TimeDelta file_duration = wav_audio_handler->GetDuration();
67 55
68 size_t bytes_written; 56 size_t bytes_written;
69 wav_audio_handler->CopyTo(audio_bus.get(), 0, &bytes_written); 57 wav_audio_handler->CopyTo(audio_bus.get(), 0, &bytes_written);
70 CHECK_EQ(bytes_written, wav_audio_handler->data().size()) 58 CHECK_EQ(bytes_written, wav_audio_handler->data().size())
71 << "Expected to write entire file into bus."; 59 << "Expected to write entire file into bus.";
72 60
73 // Set the filter coefficient to the whole file's duration; this will make the 61 // Set the filter coefficient to the whole file's duration; this will make the
74 // power monitor take the entire file into account. 62 // power monitor take the entire file into account.
75 media::AudioPowerMonitor power_monitor(wav_audio_handler->sample_rate(), 63 media::AudioPowerMonitor power_monitor(wav_audio_handler->sample_rate(),
76 file_duration); 64 file_duration);
77 power_monitor.Scan(*audio_bus, audio_bus->frames()); 65 power_monitor.Scan(*audio_bus, audio_bus->frames());
78 66
79 file_parameters->Reset( 67 file_parameters->Reset(
80 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 68 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
81 media::GuessChannelLayout(wav_audio_handler->num_channels()), 69 media::GuessChannelLayout(wav_audio_handler->num_channels()),
82 wav_audio_handler->sample_rate(), wav_audio_handler->bits_per_sample(), 70 wav_audio_handler->sample_rate(), wav_audio_handler->bits_per_sample(),
83 wav_audio_handler->total_frames()); 71 wav_audio_handler->total_frames());
84 file_parameters->set_channels_for_discrete(wav_audio_handler->num_channels()); 72 file_parameters->set_channels_for_discrete(wav_audio_handler->num_channels());
85 73
86 return power_monitor.ReadCurrentPowerAndClip().first; 74 return power_monitor.ReadCurrentPowerAndClip().first;
87 } 75 }
88 76
89 } // namespace test 77 } // namespace test
OLDNEW
« no previous file with comments | « no previous file | media/audio/BUILD.gn » ('j') | media/audio/simple_sources.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698