diff options
author | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-18 20:49:14 +0000 |
---|---|---|
committer | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-18 20:51:14 +0000 |
commit | 17d5186cef8688997c98457d2eeea86e4060023c (patch) | |
tree | f35299a66f6700e75a72300af93655bc028d458d /media | |
parent | 0ce108b7f87098120a1188d5d1dce826c7d11575 (diff) | |
download | chromium_src-17d5186cef8688997c98457d2eeea86e4060023c.zip chromium_src-17d5186cef8688997c98457d2eeea86e4060023c.tar.gz chromium_src-17d5186cef8688997c98457d2eeea86e4060023c.tar.bz2 |
Remove AudioBuffersState class.
The AudioBuffersState object doesn't appear to be necessary anymore.
Most code either completely ignores this information or doesn't actually
care about the difference between pending_bytes and hardware_delay_bytes.
Also usually only one of the 2 fields was actually being used at a time.
This change removes the class and simply uses an int that represent the
total number of delay bytes.
BUG=125685
Review URL: https://codereview.chromium.org/467833002
Cr-Commit-Position: refs/heads/master@{#290359}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290359 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
35 files changed, 82 insertions, 177 deletions
diff --git a/media/audio/BUILD.gn b/media/audio/BUILD.gn index e6ac957..0f48af0 100644 --- a/media/audio/BUILD.gn +++ b/media/audio/BUILD.gn @@ -36,8 +36,6 @@ if (!linux_link_pulseaudio) { source_set("audio") { sources = [ "agc_audio_stream.h", - "audio_buffers_state.cc", - "audio_buffers_state.h", "audio_device_name.cc", "audio_device_name.h", "audio_device_thread.cc", diff --git a/media/audio/alsa/alsa_output.cc b/media/audio/alsa/alsa_output.cc index 690d738..bb03825 100644 --- a/media/audio/alsa/alsa_output.cc +++ b/media/audio/alsa/alsa_output.cc @@ -360,7 +360,7 @@ void AlsaPcmOutputStream::BufferPacket(bool* source_exhausted) { scoped_refptr<media::DataBuffer> packet = new media::DataBuffer(packet_size_); int frames_filled = RunDataCallback( - audio_bus_.get(), AudioBuffersState(0, hardware_delay)); + audio_bus_.get(), hardware_delay); size_t packet_size = frames_filled * bytes_per_frame_; DCHECK_LE(packet_size, packet_size_); @@ -740,11 +740,11 @@ bool AlsaPcmOutputStream::IsOnAudioThread() const { } int AlsaPcmOutputStream::RunDataCallback(AudioBus* audio_bus, - AudioBuffersState buffers_state) { + int total_bytes_delay) { TRACE_EVENT0("audio", "AlsaPcmOutputStream::RunDataCallback"); if (source_callback_) - return source_callback_->OnMoreData(audio_bus, buffers_state); + return source_callback_->OnMoreData(audio_bus, total_bytes_delay); return 0; } diff --git a/media/audio/alsa/alsa_output.h b/media/audio/alsa/alsa_output.h index 1805645..6a2817c 100644 --- a/media/audio/alsa/alsa_output.h +++ b/media/audio/alsa/alsa_output.h @@ -154,7 +154,7 @@ class MEDIA_EXPORT AlsaPcmOutputStream : public AudioOutputStream { // is passed into the output stream, but ownership is not transfered which // requires a synchronization on access of the |source_callback_| to avoid // using a deleted callback. - int RunDataCallback(AudioBus* audio_bus, AudioBuffersState buffers_state); + int RunDataCallback(AudioBus* audio_bus, int total_bytes_delay); void RunErrorCallback(int code); // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to diff --git a/media/audio/alsa/alsa_output_unittest.cc b/media/audio/alsa/alsa_output_unittest.cc index 8b0aeae..3b6592b 100644 --- a/media/audio/alsa/alsa_output_unittest.cc +++ b/media/audio/alsa/alsa_output_unittest.cc @@ -644,10 +644,7 @@ TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Underrun) { .WillOnce(Return(SND_PCM_STATE_XRUN)); EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) .WillRepeatedly(Return(0)); // Buffer is full. - EXPECT_CALL(mock_callback, - OnMoreData(_, AllOf( - Field(&AudioBuffersState::pending_bytes, 0), - Field(&AudioBuffersState::hardware_delay_bytes, 0)))) + EXPECT_CALL(mock_callback, OnMoreData(_, 0)) .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); bool source_exhausted; diff --git a/media/audio/android/audio_android_unittest.cc b/media/audio/android/audio_android_unittest.cc index 177953d..d333237 100644 --- a/media/audio/android/audio_android_unittest.cc +++ b/media/audio/android/audio_android_unittest.cc @@ -123,7 +123,7 @@ static void CheckDeviceNames(const AudioDeviceNames& device_names) { } // We clear the data bus to ensure that the test does not cause noise. -static int RealOnMoreData(AudioBus* dest, AudioBuffersState buffers_state) { +static int RealOnMoreData(AudioBus* dest, int total_bytes_delay) { dest->Zero(); return dest->frames(); } @@ -178,7 +178,7 @@ class FileAudioSource : public AudioOutputStream::AudioSourceCallback { // Use samples read from a data file and fill up the audio buffer // provided to us in the callback. virtual int OnMoreData(AudioBus* audio_bus, - AudioBuffersState buffers_state) OVERRIDE { + int total_bytes_delay) OVERRIDE { bool stop_playing = false; int max_size = audio_bus->frames() * audio_bus->channels() * kBytesPerSample; @@ -354,7 +354,7 @@ class FullDuplexAudioSinkSource // AudioOutputStream::AudioSourceCallback implementation virtual int OnMoreData(AudioBus* dest, - AudioBuffersState buffers_state) OVERRIDE { + int total_bytes_delay) OVERRIDE { const int size_in_bytes = (params_.bits_per_sample() / 8) * dest->frames() * dest->channels(); EXPECT_EQ(size_in_bytes, params_.GetBytesPerBuffer()); diff --git a/media/audio/android/opensles_output.cc b/media/audio/android/opensles_output.cc index 41c03c7..4ac0af2 100644 --- a/media/audio/android/opensles_output.cc +++ b/media/audio/android/opensles_output.cc @@ -326,7 +326,7 @@ void OpenSLESOutputStream::FillBufferQueueNoLock() { // delay estimation. const uint32 hardware_delay = buffer_size_bytes_; int frames_filled = callback_->OnMoreData( - audio_bus_.get(), AudioBuffersState(0, hardware_delay)); + audio_bus_.get(), hardware_delay); if (frames_filled <= 0) { // Audio source is shutting down, or halted on error. return; diff --git a/media/audio/audio_buffers_state.cc b/media/audio/audio_buffers_state.cc deleted file mode 100644 index 6c4f950..0000000 --- a/media/audio/audio_buffers_state.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/audio/audio_buffers_state.h" - -namespace media { - -AudioBuffersState::AudioBuffersState() - : pending_bytes(0), - hardware_delay_bytes(0) { -} - -AudioBuffersState::AudioBuffersState(int pending_bytes, - int hardware_delay_bytes) - : pending_bytes(pending_bytes), - hardware_delay_bytes(hardware_delay_bytes) { -} - -} // namespace media diff --git a/media/audio/audio_buffers_state.h b/media/audio/audio_buffers_state.h deleted file mode 100644 index 79244ae..0000000 --- a/media/audio/audio_buffers_state.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_AUDIO_AUDIO_BUFFERS_STATE_H_ -#define MEDIA_AUDIO_AUDIO_BUFFERS_STATE_H_ - -#include "media/base/media_export.h" - -namespace media { - -// AudioBuffersState struct stores current state of audio buffers. -// It is used for audio synchronization. -struct MEDIA_EXPORT AudioBuffersState { - AudioBuffersState(); - AudioBuffersState(int pending_bytes, int hardware_delay_bytes); - - int total_bytes() { - return pending_bytes + hardware_delay_bytes; - } - - // Number of bytes we currently have in our software buffer. - int pending_bytes; - - // Number of bytes that have been written to the device, but haven't - // been played yet. - int hardware_delay_bytes; -}; - -} // namespace media - -#endif // MEDIA_AUDIO_AUDIO_BUFFERS_STATE_H_ diff --git a/media/audio/audio_io.h b/media/audio/audio_io.h index 1e1eba4..cb0ca59 100644 --- a/media/audio/audio_io.h +++ b/media/audio/audio_io.h @@ -6,7 +6,6 @@ #define MEDIA_AUDIO_AUDIO_IO_H_ #include "base/basictypes.h" -#include "media/audio/audio_buffers_state.h" #include "media/base/audio_bus.h" // Low-level audio output support. To make sound there are 3 objects involved: @@ -58,10 +57,10 @@ class MEDIA_EXPORT AudioOutputStream { class MEDIA_EXPORT AudioSourceCallback { public: // Provide more data by fully filling |dest|. The source will return - // the number of frames it filled. |buffers_state| contains current state - // of the buffers, and can be used by the source to calculate delay. + // the number of frames it filled. |total_bytes_delay| contains current + // number of bytes of delay buffered by the AudioOutputStream. virtual int OnMoreData(AudioBus* dest, - AudioBuffersState buffers_state) = 0; + int total_bytes_delay) = 0; // There was an error while playing a buffer. Audio source cannot be // destroyed yet. No direct action needed by the AudioStream, but it is diff --git a/media/audio/audio_low_latency_input_output_unittest.cc b/media/audio/audio_low_latency_input_output_unittest.cc index 5632896..0a572c9 100644 --- a/media/audio/audio_low_latency_input_output_unittest.cc +++ b/media/audio/audio_low_latency_input_output_unittest.cc @@ -226,23 +226,14 @@ class FullDuplexAudioSinkSource // AudioOutputStream::AudioSourceCallback. virtual int OnMoreData(AudioBus* audio_bus, - AudioBuffersState buffers_state) OVERRIDE { + int total_bytes_delay) OVERRIDE { base::AutoLock lock(lock_); // Update one component in the AudioDelayState for the packet // which is about to be played out. if (output_elements_to_write_ < kMaxDelayMeasurements) { - int output_delay_bytes = buffers_state.hardware_delay_bytes; -#if defined(OS_WIN) - // Special fix for Windows in combination with Wave where the - // pending bytes field of the audio buffer state is used to - // report the delay. - if (!CoreAudioUtil::IsSupported()) { - output_delay_bytes = buffers_state.pending_bytes; - } -#endif delay_states_[output_elements_to_write_].output_delay_ms = - BytesToMilliseconds(output_delay_bytes); + BytesToMilliseconds(total_bytes_delay); ++output_elements_to_write_; } diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index fb01254..845af9a 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -290,7 +290,7 @@ void AudioOutputController::DoReportError() { } int AudioOutputController::OnMoreData(AudioBus* dest, - AudioBuffersState buffers_state) { + int total_bytes_delay) { TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() @@ -304,7 +304,7 @@ int AudioOutputController::OnMoreData(AudioBus* dest, const int frames = dest->frames(); sync_reader_->UpdatePendingBytes( - buffers_state.total_bytes() + frames * params_.GetBytesPerFrame()); + total_bytes_delay + frames * params_.GetBytesPerFrame()); #if defined(AUDIO_POWER_MONITORING) power_monitor_.Scan(*dest, frames); diff --git a/media/audio/audio_output_controller.h b/media/audio/audio_output_controller.h index 0b02ee2..795b4cf 100644 --- a/media/audio/audio_output_controller.h +++ b/media/audio/audio_output_controller.h @@ -149,7 +149,7 @@ class MEDIA_EXPORT AudioOutputController // AudioSourceCallback implementation. virtual int OnMoreData(AudioBus* dest, - AudioBuffersState buffers_state) OVERRIDE; + int total_bytes_delay) OVERRIDE; virtual void OnError(AudioOutputStream* stream) OVERRIDE; // AudioDeviceListener implementation. When called AudioOutputController will diff --git a/media/audio/audio_output_controller_unittest.cc b/media/audio/audio_output_controller_unittest.cc index 125763c..a4ecdb8 100644 --- a/media/audio/audio_output_controller_unittest.cc +++ b/media/audio/audio_output_controller_unittest.cc @@ -192,7 +192,7 @@ class AudioOutputControllerTest : public testing::Test { scoped_ptr<AudioBus> dest = AudioBus::Create(params_); ASSERT_TRUE(!!mock_stream_.callback()); const int frames_read = - mock_stream_.callback()->OnMoreData(dest.get(), AudioBuffersState()); + mock_stream_.callback()->OnMoreData(dest.get(), 0); EXPECT_LT(0, frames_read); EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]); } diff --git a/media/audio/audio_output_proxy_unittest.cc b/media/audio/audio_output_proxy_unittest.cc index b8f23ac..5f0ab06 100644 --- a/media/audio/audio_output_proxy_unittest.cc +++ b/media/audio/audio_output_proxy_unittest.cc @@ -25,7 +25,6 @@ using ::testing::NotNull; using ::testing::Return; using ::testing::SetArrayArgument; using media::AudioBus; -using media::AudioBuffersState; using media::AudioInputStream; using media::AudioManager; using media::AudioManagerBase; @@ -125,7 +124,7 @@ class MockAudioManager : public AudioManagerBase { class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { public: - int OnMoreData(AudioBus* audio_bus, AudioBuffersState buffers_state) { + int OnMoreData(AudioBus* audio_bus, int total_bytes_delay) { audio_bus->Zero(); return audio_bus->frames(); } diff --git a/media/audio/audio_output_resampler.cc b/media/audio/audio_output_resampler.cc index 15633bb..6375096 100644 --- a/media/audio/audio_output_resampler.cc +++ b/media/audio/audio_output_resampler.cc @@ -30,7 +30,7 @@ class OnMoreDataConverter // AudioSourceCallback interface. virtual int OnMoreData(AudioBus* dest, - AudioBuffersState buffers_state) OVERRIDE; + int total_bytes_delay) OVERRIDE; virtual void OnError(AudioOutputStream* stream) OVERRIDE; // Sets |source_callback_|. If this is not a new object, then Stop() must be @@ -54,9 +54,9 @@ class OnMoreDataConverter // Source callback. AudioOutputStream::AudioSourceCallback* source_callback_; - // Last AudioBuffersState object received via OnMoreData(), used to correct + // Last |total_bytes_delay| received via OnMoreData(), used to correct // playback delay by ProvideInput() and passed on to |source_callback_|. - AudioBuffersState current_buffers_state_; + int current_total_bytes_delay_; const int input_bytes_per_second_; @@ -327,8 +327,8 @@ void OnMoreDataConverter::Stop() { } int OnMoreDataConverter::OnMoreData(AudioBus* dest, - AudioBuffersState buffers_state) { - current_buffers_state_ = buffers_state; + int total_bytes_delay) { + current_total_bytes_delay_ = total_bytes_delay; audio_converter_.Convert(dest); // Always return the full number of frames requested, ProvideInput() @@ -341,13 +341,12 @@ double OnMoreDataConverter::ProvideInput(AudioBus* dest, // Adjust playback delay to include |buffer_delay|. // TODO(dalecurtis): Stop passing bytes around, it doesn't make sense since // AudioBus is just float data. Use TimeDelta instead. - AudioBuffersState new_buffers_state; - new_buffers_state.pending_bytes = - io_ratio_ * (current_buffers_state_.total_bytes() + + int new_total_bytes_delay = + io_ratio_ * (current_total_bytes_delay_ + buffer_delay.InSecondsF() * input_bytes_per_second_); // Retrieve data from the original callback. - const int frames = source_callback_->OnMoreData(dest, new_buffers_state); + const int frames = source_callback_->OnMoreData(dest, new_total_bytes_delay); // Zero any unfilled frames if anything was filled, otherwise we'll just // return a volume of zero and let AudioConverter drop the output. diff --git a/media/audio/audio_output_resampler.h b/media/audio/audio_output_resampler.h index fa488aa..af7ebf2 100644 --- a/media/audio/audio_output_resampler.h +++ b/media/audio/audio_output_resampler.h @@ -24,8 +24,8 @@ class OnMoreDataConverter; // AudioConverter class for details on the conversion process. // // AOR works by intercepting the AudioSourceCallback provided to StartStream() -// and redirecting it through an AudioConverter instance. AudioBuffersState is -// adjusted for buffer delay caused by the conversion process. +// and redirecting it through an AudioConverter instance. |total_bytes_delay| +// is adjusted for buffer delay caused by the conversion process. // // AOR will automatically fall back from AUDIO_PCM_LOW_LATENCY to // AUDIO_PCM_LINEAR if the output device fails to open at the requested output diff --git a/media/audio/cras/cras_unified.cc b/media/audio/cras/cras_unified.cc index 25af383..232fee1 100644 --- a/media/audio/cras/cras_unified.cc +++ b/media/audio/cras/cras_unified.cc @@ -358,8 +358,7 @@ uint32 CrasUnifiedStream::ReadWriteAudio(size_t frames, total_delay_bytes += GetBytesLatency(latency_ts); int frames_filled = source_callback_->OnMoreData( - output_bus_.get(), - AudioBuffersState(0, total_delay_bytes)); + output_bus_.get(), total_delay_bytes); output_bus_->ToInterleaved(frames_filled, bytes_per_sample, output_samples); @@ -376,7 +375,7 @@ uint32 CrasUnifiedStream::WriteAudio(size_t frames, cras_client_calc_playback_latency(sample_ts, &latency_ts); int frames_filled = source_callback_->OnMoreData( - output_bus_.get(), AudioBuffersState(0, GetBytesLatency(latency_ts))); + output_bus_.get(), GetBytesLatency(latency_ts)); // Note: If this ever changes to output raw float the data must be clipped and // sanitized since it may come from an untrusted source such as NaCl. diff --git a/media/audio/fake_audio_consumer_unittest.cc b/media/audio/fake_audio_consumer_unittest.cc index cb2f75c..ad04cb6 100644 --- a/media/audio/fake_audio_consumer_unittest.cc +++ b/media/audio/fake_audio_consumer_unittest.cc @@ -5,7 +5,6 @@ #include "base/bind.h" #include "base/message_loop/message_loop.h" #include "base/time/time.h" -#include "media/audio/audio_buffers_state.h" #include "media/audio/audio_parameters.h" #include "media/audio/fake_audio_consumer.h" #include "media/audio/simple_sources.h" @@ -30,7 +29,7 @@ class FakeAudioConsumerTest : public testing::Test { virtual ~FakeAudioConsumerTest() {} void ConsumeData(AudioBus* audio_bus) { - source_.OnMoreData(audio_bus, AudioBuffersState()); + source_.OnMoreData(audio_bus, 0); } void RunOnAudioThread() { diff --git a/media/audio/fake_audio_output_stream.cc b/media/audio/fake_audio_output_stream.cc index 0448c23..d5e0d5f 100644 --- a/media/audio/fake_audio_output_stream.cc +++ b/media/audio/fake_audio_output_stream.cc @@ -61,7 +61,7 @@ void FakeAudioOutputStream::GetVolume(double* volume) { void FakeAudioOutputStream::CallOnMoreData(AudioBus* audio_bus) { DCHECK(audio_manager_->GetWorkerTaskRunner()->BelongsToCurrentThread()); - callback_->OnMoreData(audio_bus, AudioBuffersState()); + callback_->OnMoreData(audio_bus, 0); } } // namespace media diff --git a/media/audio/mac/audio_auhal_mac.cc b/media/audio/mac/audio_auhal_mac.cc index 41fc57c..92a1b18 100644 --- a/media/audio/mac/audio_auhal_mac.cc +++ b/media/audio/mac/audio_auhal_mac.cc @@ -228,9 +228,8 @@ void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) { // Supply the input data and render the output data. source_->OnMoreData( dest, - AudioBuffersState(0, - current_hardware_pending_bytes_ + - frame_delay * params_.GetBytesPerFrame())); + current_hardware_pending_bytes_ + + frame_delay * params_.GetBytesPerFrame()); dest->Scale(volume_); } diff --git a/media/audio/mock_audio_source_callback.h b/media/audio/mock_audio_source_callback.h index d24ce44..89814cf 100644 --- a/media/audio/mock_audio_source_callback.h +++ b/media/audio/mock_audio_source_callback.h @@ -16,7 +16,7 @@ class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { virtual ~MockAudioSourceCallback(); MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, - AudioBuffersState buffers_state)); + int total_bytes_delay)); MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); private: diff --git a/media/audio/pulse/pulse_output.cc b/media/audio/pulse/pulse_output.cc index e0a0b42..1048113 100644 --- a/media/audio/pulse/pulse_output.cc +++ b/media/audio/pulse/pulse_output.cc @@ -133,7 +133,7 @@ void PulseAudioOutputStream::FulfillWriteRequest(size_t requested_bytes) { const uint32 hardware_delay = pulse::GetHardwareLatencyInBytes( pa_stream_, params_.sample_rate(), params_.GetBytesPerFrame()); frames_filled = source_callback_->OnMoreData( - audio_bus_.get(), AudioBuffersState(0, hardware_delay)); + audio_bus_.get(), hardware_delay); // Zero any unfilled data so it plays back as silence. if (frames_filled < audio_bus_->frames()) { diff --git a/media/audio/simple_sources.cc b/media/audio/simple_sources.cc index 039029e..2c22e16 100644 --- a/media/audio/simple_sources.cc +++ b/media/audio/simple_sources.cc @@ -29,7 +29,7 @@ SineWaveAudioSource::SineWaveAudioSource(int channels, // The implementation could be more efficient if a lookup table is constructed // but it is efficient enough for our simple needs. int SineWaveAudioSource::OnMoreData(AudioBus* audio_bus, - AudioBuffersState audio_buffers) { + int total_bytes_delay) { base::AutoLock auto_lock(time_lock_); callbacks_++; diff --git a/media/audio/simple_sources.h b/media/audio/simple_sources.h index 6303386..feda33b 100644 --- a/media/audio/simple_sources.h +++ b/media/audio/simple_sources.h @@ -28,7 +28,7 @@ class MEDIA_EXPORT SineWaveAudioSource // Implementation of AudioSourceCallback. virtual int OnMoreData(AudioBus* audio_bus, - AudioBuffersState audio_buffers) OVERRIDE; + int total_bytes_delay) OVERRIDE; virtual void OnError(AudioOutputStream* stream) OVERRIDE; // The number of OnMoreData()+OnMoreIOData() and OnError() calls respectively. diff --git a/media/audio/simple_sources_unittest.cc b/media/audio/simple_sources_unittest.cc index 5ee8686..51cb740 100644 --- a/media/audio/simple_sources_unittest.cc +++ b/media/audio/simple_sources_unittest.cc @@ -26,7 +26,7 @@ TEST(SimpleSources, SineWaveAudioSource) { SineWaveAudioSource source(1, freq, params.sample_rate()); scoped_ptr<AudioBus> audio_bus = AudioBus::Create(params); - source.OnMoreData(audio_bus.get(), AudioBuffersState()); + source.OnMoreData(audio_bus.get(), 0); EXPECT_EQ(1, source.callbacks()); EXPECT_EQ(0, source.errors()); @@ -56,13 +56,13 @@ TEST(SimpleSources, SineWaveAudioCapped) { scoped_ptr<AudioBus> audio_bus = AudioBus::Create(1, 2 * kSampleCap); EXPECT_EQ(source.OnMoreData( - audio_bus.get(), AudioBuffersState()), kSampleCap); + audio_bus.get(), 0), kSampleCap); EXPECT_EQ(1, source.callbacks()); - EXPECT_EQ(source.OnMoreData(audio_bus.get(), AudioBuffersState()), 0); + EXPECT_EQ(source.OnMoreData(audio_bus.get(), 0), 0); EXPECT_EQ(2, source.callbacks()); source.Reset(); EXPECT_EQ(source.OnMoreData( - audio_bus.get(), AudioBuffersState()), kSampleCap); + audio_bus.get(), 0), kSampleCap); EXPECT_EQ(3, source.callbacks()); EXPECT_EQ(0, source.errors()); } diff --git a/media/audio/sounds/audio_stream_handler.cc b/media/audio/sounds/audio_stream_handler.cc index 645fcb3..7e48b2d 100644 --- a/media/audio/sounds/audio_stream_handler.cc +++ b/media/audio/sounds/audio_stream_handler.cc @@ -105,7 +105,7 @@ class AudioStreamHandler::AudioStreamContainer // AudioOutputStream::AudioSourceCallback overrides: // Following methods could be called from *ANY* thread. virtual int OnMoreData(AudioBus* dest, - AudioBuffersState /* state */) OVERRIDE { + int /* total_bytes_delay */) OVERRIDE { base::AutoLock al(state_lock_); size_t bytes_written = 0; diff --git a/media/audio/virtual_audio_input_stream_unittest.cc b/media/audio/virtual_audio_input_stream_unittest.cc index 3aa87b0..c82a9ff 100644 --- a/media/audio/virtual_audio_input_stream_unittest.cc +++ b/media/audio/virtual_audio_input_stream_unittest.cc @@ -67,8 +67,9 @@ class TestAudioSource : public SineWaveAudioSource { virtual ~TestAudioSource() {} virtual int OnMoreData(AudioBus* audio_bus, - AudioBuffersState audio_buffers) OVERRIDE { - const int ret = SineWaveAudioSource::OnMoreData(audio_bus, audio_buffers); + int total_bytes_delay) OVERRIDE { + const int ret = SineWaveAudioSource::OnMoreData(audio_bus, + total_bytes_delay); data_pulled_.Signal(); return ret; } diff --git a/media/audio/virtual_audio_output_stream.cc b/media/audio/virtual_audio_output_stream.cc index 43b83cf..016c2f3 100644 --- a/media/audio/virtual_audio_output_stream.cc +++ b/media/audio/virtual_audio_output_stream.cc @@ -77,7 +77,7 @@ double VirtualAudioOutputStream::ProvideInput(AudioBus* audio_bus, // platform. DCHECK(callback_); - const int frames = callback_->OnMoreData(audio_bus, AudioBuffersState()); + const int frames = callback_->OnMoreData(audio_bus, 0); if (frames < audio_bus->frames()) audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames); 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; diff --git a/media/cast/test/receiver.cc b/media/cast/test/receiver.cc index 65b0e60..7ded86a 100644 --- a/media/cast/test/receiver.cc +++ b/media/cast/test/receiver.cc @@ -316,7 +316,7 @@ class NaivePlayer : public InProcessReceiver, //////////////////////////////////////////////////////////////////// // AudioSourceCallback implementation. - virtual int OnMoreData(AudioBus* dest, AudioBuffersState buffers_state) + virtual int OnMoreData(AudioBus* dest, int total_bytes_delay) OVERRIDE { // Note: This method is being invoked by a separate thread unknown to us // (i.e., outside of CastEnvironment). @@ -329,8 +329,8 @@ class NaivePlayer : public InProcessReceiver, base::AutoLock auto_lock(audio_lock_); // Prune the queue, skipping entries that are too old. - // TODO(miu): Use |buffers_state| to account for audio buffering delays - // upstream. + // TODO(miu): Use |total_bytes_delay| to account for audio buffering + // delays upstream. const base::TimeTicks earliest_time_to_play = cast_env()->Clock()->NowTicks() - max_frame_age_; while (!audio_playout_queue_.empty() && diff --git a/media/cast/test/utility/audio_utility.cc b/media/cast/test/utility/audio_utility.cc index 8dde4dd..094f141 100644 --- a/media/cast/test/utility/audio_utility.cc +++ b/media/cast/test/utility/audio_utility.cc @@ -36,7 +36,7 @@ scoped_ptr<AudioBus> TestAudioBusFactory::NextAudioBus( const int num_samples = static_cast<int>((sample_rate_ * duration) / base::TimeDelta::FromSeconds(1)); scoped_ptr<AudioBus> bus(AudioBus::Create(num_channels_, num_samples)); - source_.OnMoreData(bus.get(), AudioBuffersState()); + source_.OnMoreData(bus.get(), 0); bus->Scale(volume_); return bus.Pass(); } diff --git a/media/media.gyp b/media/media.gyp index 027cb55..5adb828 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -91,8 +91,6 @@ 'audio/android/opensles_output.cc', 'audio/android/opensles_output.h', 'audio/android/opensles_wrapper.cc', - 'audio/audio_buffers_state.cc', - 'audio/audio_buffers_state.h', 'audio/audio_device_name.cc', 'audio/audio_device_name.h', 'audio/audio_device_thread.cc', |