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

Unified Diff: media/audio/win/audio_low_latency_output_win_unittest.cc

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Comments. Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/win/audio_low_latency_output_win.cc ('k') | media/audio/win/audio_output_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/win/audio_low_latency_output_win_unittest.cc
diff --git a/media/audio/win/audio_low_latency_output_win_unittest.cc b/media/audio/win/audio_low_latency_output_win_unittest.cc
index 5a935e58f03e6ffa8d22f68ddfed97774788adae..666d0fdc2e5c4bc2c5e9c23ac4b15f2fbf8e4455 100644
--- a/media/audio/win/audio_low_latency_output_win_unittest.cc
+++ b/media/audio/win/audio_low_latency_output_win_unittest.cc
@@ -44,6 +44,7 @@ static const char kSpeechFile_16b_m_48k[] = "speech_16b_mono_48kHz.raw";
static const char kSpeechFile_16b_m_44k[] = "speech_16b_mono_44kHz.raw";
static const size_t kFileDurationMs = 20000;
static const size_t kNumFileSegments = 2;
+static const int kBitsPerSample = 16;
static const size_t kMaxDeltaSamples = 1000;
static const char* kDeltaTimeMsFileName = "delta_times_ms.txt";
@@ -63,9 +64,8 @@ ACTION_P(QuitLoop, loop) {
class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback {
public:
- MOCK_METHOD3(OnMoreData, uint32(uint8* dest,
- uint32 max_size,
- AudioBuffersState buffers_state));
+ MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus,
+ AudioBuffersState buffers_state));
MOCK_METHOD2(OnError, void(AudioOutputStream* stream, int code));
};
@@ -110,9 +110,8 @@ class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback {
}
// AudioOutputStream::AudioSourceCallback implementation.
- virtual uint32 OnMoreData(uint8* dest,
- uint32 max_size,
- AudioBuffersState buffers_state) {
+ virtual int OnMoreData(AudioBus* audio_bus,
+ AudioBuffersState buffers_state) {
// Store time difference between two successive callbacks in an array.
// These values will be written to a file in the destructor.
int diff = (base::Time::Now() - previous_call_time_).InMilliseconds();
@@ -122,15 +121,20 @@ class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback {
++elements_to_write_;
}
+ int max_size =
+ audio_bus->frames() * audio_bus->channels() * kBitsPerSample / 8;
+
// Use samples read from a data file and fill up the audio buffer
// provided to us in the callback.
if (pos_ + static_cast<int>(max_size) > file_size())
max_size = file_size() - pos_;
+ int frames = max_size / (audio_bus->channels() * kBitsPerSample / 8);
if (max_size) {
- memcpy(dest, file_->GetData() + pos_, max_size);
+ audio_bus->FromInterleaved(
+ file_->GetData() + pos_, frames, kBitsPerSample / 8);
pos_ += max_size;
}
- return max_size;
+ return frames;
}
virtual void OnError(AudioOutputStream* stream, int code) {}
@@ -176,7 +180,7 @@ class AudioOutputStreamWrapper {
audio_man_(audio_manager),
format_(AudioParameters::AUDIO_PCM_LOW_LATENCY),
channel_layout_(CHANNEL_LAYOUT_STEREO),
- bits_per_sample_(16) {
+ bits_per_sample_(kBitsPerSample) {
// Use native/mixing sample rate and 10ms frame size as default.
sample_rate_ = static_cast<int>(
WASAPIAudioOutputStream::HardwareSampleRate(eConsole));
@@ -461,11 +465,10 @@ TEST(WASAPIAudioOutputStreamTest, PacketSizeInMilliseconds) {
AudioBuffersState state(0, bytes_per_packet);
// Wait for the first callback and verify its parameters.
- EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet,
- HasValidDelay(state)))
+ EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(state)))
.WillOnce(DoAll(
QuitLoop(loop.message_loop_proxy()),
- Return(bytes_per_packet)));
+ Return(aosw.samples_per_packet())));
aos->Start(&source);
loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
@@ -500,12 +503,11 @@ TEST(WASAPIAudioOutputStreamTest, PacketSizeInSamples) {
AudioBuffersState state(0, bytes_per_packet);
// Ensure that callbacks start correctly.
- EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet,
- HasValidDelay(state)))
+ EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(state)))
.WillOnce(DoAll(
QuitLoop(loop.message_loop_proxy()),
- Return(bytes_per_packet)))
- .WillRepeatedly(Return(bytes_per_packet));
+ Return(aosw.samples_per_packet())))
+ .WillRepeatedly(Return(aosw.samples_per_packet()));
aos->Start(&source);
loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
@@ -536,12 +538,11 @@ TEST(WASAPIAudioOutputStreamTest, Mono) {
// Set up expected minimum delay estimation.
AudioBuffersState state(0, bytes_per_packet);
- EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet,
- HasValidDelay(state)))
+ EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(state)))
.WillOnce(DoAll(
QuitLoop(loop.message_loop_proxy()),
- Return(bytes_per_packet)))
- .WillRepeatedly(Return(bytes_per_packet));
+ Return(aosw.samples_per_packet())))
+ .WillRepeatedly(Return(aosw.samples_per_packet()));
aos->Start(&source);
loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
@@ -789,12 +790,11 @@ TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt48kHz) {
AudioBuffersState state(0, bytes_per_packet);
// Wait for the first callback and verify its parameters.
- EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet,
- HasValidDelay(state)))
+ EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(state)))
.WillOnce(DoAll(
QuitLoop(loop.message_loop_proxy()),
- Return(bytes_per_packet)))
- .WillRepeatedly(Return(bytes_per_packet));
+ Return(aosw.samples_per_packet())))
+ .WillRepeatedly(Return(aosw.samples_per_packet()));
aos->Start(&source);
loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
@@ -831,12 +831,11 @@ TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt44kHz) {
AudioBuffersState state(0, bytes_per_packet);
// Wait for the first callback and verify its parameters.
- EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet,
- HasValidDelay(state)))
+ EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(state)))
.WillOnce(DoAll(
QuitLoop(loop.message_loop_proxy()),
- Return(bytes_per_packet)))
- .WillRepeatedly(Return(bytes_per_packet));
+ Return(aosw.samples_per_packet())))
+ .WillRepeatedly(Return(aosw.samples_per_packet()));
aos->Start(&source);
loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
« no previous file with comments | « media/audio/win/audio_low_latency_output_win.cc ('k') | media/audio/win/audio_output_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698