diff options
Diffstat (limited to 'media/audio/win')
-rw-r--r-- | media/audio/win/audio_low_latency_output_win.cc | 6 | ||||
-rw-r--r-- | media/audio/win/audio_low_latency_output_win_unittest.cc | 27 | ||||
-rw-r--r-- | media/audio/win/audio_output_win_unittest.cc | 44 | ||||
-rw-r--r-- | media/audio/win/waveout_output_win.cc | 5 |
4 files changed, 30 insertions, 52 deletions
diff --git a/media/audio/win/audio_low_latency_output_win.cc b/media/audio/win/audio_low_latency_output_win.cc index 15cabbaf..99576a6 100644 --- a/media/audio/win/audio_low_latency_output_win.cc +++ b/media/audio/win/audio_low_latency_output_win.cc @@ -498,13 +498,9 @@ bool WASAPIAudioOutputStream::RenderAudioFromSource(UINT64 device_frequency) { // Read a data packet from the registered client source and // deliver a delay estimate in the same callback to the client. - // A time stamp is also stored in the AudioBuffersState. This - // time stamp can be used at the client side to compensate for - // the delay between the usage of the delay value and the time - // of generation. int frames_filled = source_->OnMoreData( - audio_bus_.get(), AudioBuffersState(0, audio_delay_bytes)); + audio_bus_.get(), audio_delay_bytes); uint32 num_filled_bytes = frames_filled * format_.Format.nBlockAlign; DCHECK_LE(num_filled_bytes, packet_size_bytes_); 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 ed03d2b..30fa9ca 100644 --- a/media/audio/win/audio_low_latency_output_win_unittest.cc +++ b/media/audio/win/audio_low_latency_output_win_unittest.cc @@ -52,7 +52,7 @@ MATCHER_P(HasValidDelay, value, "") { // It is difficult to come up with a perfect test condition for the delay // estimation. For now, verify that the produced output delay is always // larger than the selected buffer size. - return arg.hardware_delay_bytes >= value.hardware_delay_bytes; + return arg >= value; } // Used to terminate a loop from a different thread than the loop belongs to. @@ -103,7 +103,7 @@ class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback { // AudioOutputStream::AudioSourceCallback implementation. virtual int OnMoreData(AudioBus* audio_bus, - AudioBuffersState buffers_state) { + int total_bytes_delay) { // Store time difference between two successive callbacks in an array. // These values will be written to a file in the destructor. const base::TimeTicks now_time = base::TimeTicks::Now(); @@ -396,14 +396,11 @@ TEST(WASAPIAudioOutputStreamTest, ValidPacketSize) { EXPECT_TRUE(aos->Open()); // Derive the expected size in bytes of each packet. - uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * - (aosw.bits_per_sample() / 8); - - // Set up expected minimum delay estimation. - AudioBuffersState state(0, bytes_per_packet); + int bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * + (aosw.bits_per_sample() / 8); // Wait for the first callback and verify its parameters. - EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(state))) + EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) .WillOnce(DoAll( QuitLoop(loop.message_loop_proxy()), Return(aosw.samples_per_packet()))); @@ -600,14 +597,11 @@ TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt48kHz) { EXPECT_TRUE(aos->Open()); // Derive the expected size in bytes of each packet. - uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * + int bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * (aosw.bits_per_sample() / 8); - // Set up expected minimum delay estimation. - AudioBuffersState state(0, bytes_per_packet); - // Wait for the first callback and verify its parameters. - EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(state))) + EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) .WillOnce(DoAll( QuitLoop(loop.message_loop_proxy()), Return(aosw.samples_per_packet()))) @@ -641,14 +635,11 @@ TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt44kHz) { EXPECT_TRUE(aos->Open()); // Derive the expected size in bytes of each packet. - uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * + int bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * (aosw.bits_per_sample() / 8); - // Set up expected minimum delay estimation. - AudioBuffersState state(0, bytes_per_packet); - // Wait for the first callback and verify its parameters. - EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(state))) + EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) .WillOnce(DoAll( QuitLoop(loop.message_loop_proxy()), Return(aosw.samples_per_packet()))) diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc index 2902657..6257a60 100644 --- a/media/audio/win/audio_output_win_unittest.cc +++ b/media/audio/win/audio_output_win_unittest.cc @@ -37,7 +37,7 @@ namespace media { static const wchar_t kAudioFile1_16b_m_16K[] = L"media\\test\\data\\sweep02_16b_mono_16KHz.raw"; -static int ClearData(AudioBus* audio_bus, AudioBuffersState buffers_state) { +static int ClearData(AudioBus* audio_bus, int total_bytes_delay) { audio_bus->Zero(); return audio_bus->frames(); } @@ -52,7 +52,7 @@ class TestSourceBasic : public AudioOutputStream::AudioSourceCallback { } // AudioSourceCallback::OnMoreData implementation: virtual int OnMoreData(AudioBus* audio_bus, - AudioBuffersState buffers_state) { + int total_bytes_delay) { ++callback_count_; // Touch the channel memory value to make sure memory is good. audio_bus->Zero(); @@ -89,9 +89,9 @@ class TestSourceLaggy : public TestSourceBasic { : laggy_after_buffer_(laggy_after_buffer), lag_in_ms_(lag_in_ms) { } virtual int OnMoreData(AudioBus* audio_bus, - AudioBuffersState buffers_state) { + int total_bytes_delay) { // Call the base, which increments the callback_count_. - TestSourceBasic::OnMoreData(audio_bus, buffers_state); + TestSourceBasic::OnMoreData(audio_bus, total_bytes_delay); if (callback_count() > kMaxNumBuffers) { ::Sleep(lag_in_ms_); } @@ -520,32 +520,22 @@ TEST(WinAudioTest, PCMWaveStreamPendingBytes) { // pending bytes will go down and eventually read zero. InSequence s; - EXPECT_CALL(source, OnMoreData(NotNull(), - Field(&AudioBuffersState::pending_bytes, 0))) + EXPECT_CALL(source, OnMoreData(NotNull(), 0)) .WillOnce(Invoke(ClearData)); // Note: If AudioManagerWin::NumberOfWaveOutBuffers() ever changes, or if this // test is run on Vista, these expectations will fail. - EXPECT_CALL(source, OnMoreData(NotNull(), - Field(&AudioBuffersState::pending_bytes, - bytes_100_ms))) + EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms)) .WillOnce(Invoke(ClearData)); - EXPECT_CALL(source, OnMoreData(NotNull(), - Field(&AudioBuffersState::pending_bytes, - 2 * bytes_100_ms))) + EXPECT_CALL(source, OnMoreData(NotNull(), 2 * bytes_100_ms)) .WillOnce(Invoke(ClearData)); - EXPECT_CALL(source, OnMoreData(NotNull(), - Field(&AudioBuffersState::pending_bytes, - 2 * bytes_100_ms))) + EXPECT_CALL(source, OnMoreData(NotNull(), 2 * bytes_100_ms)) .Times(AnyNumber()) .WillRepeatedly(Return(0)); - EXPECT_CALL(source, OnMoreData(NotNull(), - Field(&AudioBuffersState::pending_bytes, - bytes_100_ms))) + EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms)) .Times(AnyNumber()) .WillRepeatedly(Return(0)); - EXPECT_CALL(source, OnMoreData(NotNull(), - Field(&AudioBuffersState::pending_bytes, 0))) + EXPECT_CALL(source, OnMoreData(NotNull(), 0)) .Times(AnyNumber()) .WillRepeatedly(Return(0)); @@ -571,8 +561,8 @@ class SyncSocketSource : public AudioOutputStream::AudioSourceCallback { // AudioSourceCallback::OnMoreData implementation: virtual int OnMoreData(AudioBus* audio_bus, - AudioBuffersState buffers_state) { - socket_->Send(&buffers_state, sizeof(buffers_state)); + int total_bytes_delay) { + socket_->Send(&total_bytes_delay, sizeof(total_bytes_delay)); uint32 size = socket_->Receive(data_.get(), data_size_); DCHECK_EQ(static_cast<size_t>(size) % sizeof(*audio_bus_->channel(0)), 0U); audio_bus_->CopyTo(audio_bus); @@ -580,7 +570,7 @@ class SyncSocketSource : public AudioOutputStream::AudioSourceCallback { } virtual int OnMoreIOData(AudioBus* source, AudioBus* dest, - AudioBuffersState buffers_state) { + int total_bytes_delay) { NOTREACHED(); return 0; } @@ -622,13 +612,13 @@ DWORD __stdcall SyncSocketThread(void* context) { SineWaveAudioSource sine(1, ctx.sine_freq, ctx.sample_rate); const int kTwoSecFrames = ctx.sample_rate * 2; - AudioBuffersState buffers_state; + int total_bytes_delay = 0; int times = 0; for (int ix = 0; ix < kTwoSecFrames; ix += ctx.frames) { - if (ctx.socket->Receive(&buffers_state, sizeof(buffers_state)) == 0) + if (ctx.socket->Receive(&total_bytes_delay, sizeof(total_bytes_delay)) == 0) break; - if ((times > 0) && (buffers_state.pending_bytes < 1000)) __debugbreak(); - sine.OnMoreData(audio_bus.get(), buffers_state); + if ((times > 0) && (total_bytes_delay < 1000)) __debugbreak(); + sine.OnMoreData(audio_bus.get(), total_bytes_delay); ctx.socket->Send(data.get(), ctx.packet_size_bytes); ++times; } diff --git a/media/audio/win/waveout_output_win.cc b/media/audio/win/waveout_output_win.cc index 0f54817..4d11e08 100644 --- a/media/audio/win/waveout_output_win.cc +++ b/media/audio/win/waveout_output_win.cc @@ -325,9 +325,10 @@ void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { // return to us how many bytes were used. // TODO(fbarchard): Handle used 0 by queueing more. - // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. + // TODO(sergeyu): Specify correct hardware delay for |total_delay_bytes|. + int total_delay_bytes = pending_bytes_; int frames_filled = callback_->OnMoreData( - audio_bus_.get(), AudioBuffersState(pending_bytes_, 0)); + audio_bus_.get(), total_delay_bytes); uint32 used = frames_filled * audio_bus_->channels() * format_.Format.wBitsPerSample / 8; |