| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "media/audio/audio_debug_recording_helper.h" |
| 13 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_manager.h" | 15 #include "media/audio/audio_manager.h" |
| 15 #include "media/audio/audio_output_dispatcher_impl.h" | 16 #include "media/audio/audio_output_dispatcher_impl.h" |
| 16 #include "media/base/audio_parameters.h" | 17 #include "media/base/audio_parameters.h" |
| 17 | 18 |
| 18 namespace media { | 19 namespace media { |
| 19 | 20 |
| 20 class OnMoreDataConverter; | 21 class OnMoreDataConverter; |
| 21 | 22 |
| 22 // AudioOutputResampler is a browser-side resampling and buffering solution | 23 // AudioOutputResampler is a browser-side resampling and buffering solution |
| 23 // which ensures audio data is always output at given parameters. See the | 24 // which ensures audio data is always output at given parameters. See the |
| 24 // AudioConverter class for details on the conversion process. | 25 // AudioConverter class for details on the conversion process. |
| 25 // | 26 // |
| 26 // AOR works by intercepting the AudioSourceCallback provided to StartStream() | 27 // AOR works by intercepting the AudioSourceCallback provided to StartStream() |
| 27 // and redirecting it through an AudioConverter instance. | 28 // and redirecting it through an AudioConverter instance. |
| 28 // | 29 // |
| 29 // AOR will automatically fall back from AUDIO_PCM_LOW_LATENCY to | 30 // AOR will automatically fall back from AUDIO_PCM_LOW_LATENCY to |
| 30 // AUDIO_PCM_LINEAR if the output device fails to open at the requested output | 31 // AUDIO_PCM_LINEAR if the output device fails to open at the requested output |
| 31 // parameters. If opening still fails, it will fallback to AUDIO_FAKE. | 32 // parameters. If opening still fails, it will fallback to AUDIO_FAKE. |
| 32 class MEDIA_EXPORT AudioOutputResampler : public AudioOutputDispatcher { | 33 class MEDIA_EXPORT AudioOutputResampler : public AudioOutputDispatcher { |
| 33 public: | 34 public: |
| 35 // Callback type to register an AudioDebugRecorder. |
| 36 using RegisterDebugRecordingSourceCallback = |
| 37 base::RepeatingCallback<std::unique_ptr<AudioDebugRecorder>( |
| 38 const AudioParameters&)>; |
| 39 |
| 34 AudioOutputResampler(AudioManager* audio_manager, | 40 AudioOutputResampler(AudioManager* audio_manager, |
| 35 const AudioParameters& input_params, | 41 const AudioParameters& input_params, |
| 36 const AudioParameters& output_params, | 42 const AudioParameters& output_params, |
| 37 const std::string& output_device_id, | 43 const std::string& output_device_id, |
| 38 const base::TimeDelta& close_delay); | 44 base::TimeDelta close_delay, |
| 45 const RegisterDebugRecordingSourceCallback& |
| 46 register_debug_recording_source_callback); |
| 39 ~AudioOutputResampler() override; | 47 ~AudioOutputResampler() override; |
| 40 | 48 |
| 41 // AudioOutputDispatcher interface. | 49 // AudioOutputDispatcher interface. |
| 42 AudioOutputProxy* CreateStreamProxy() override; | 50 AudioOutputProxy* CreateStreamProxy() override; |
| 43 bool OpenStream() override; | 51 bool OpenStream() override; |
| 44 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, | 52 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, |
| 45 AudioOutputProxy* stream_proxy) override; | 53 AudioOutputProxy* stream_proxy) override; |
| 46 void StopStream(AudioOutputProxy* stream_proxy) override; | 54 void StopStream(AudioOutputProxy* stream_proxy) override; |
| 47 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; | 55 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; |
| 48 void CloseStream(AudioOutputProxy* stream_proxy) override; | 56 void CloseStream(AudioOutputProxy* stream_proxy) override; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // Whether any streams have been opened through |dispatcher_|, if so we can't | 91 // Whether any streams have been opened through |dispatcher_|, if so we can't |
| 84 // fallback on future OpenStream() failures. | 92 // fallback on future OpenStream() failures. |
| 85 bool streams_opened_; | 93 bool streams_opened_; |
| 86 | 94 |
| 87 // The reinitialization timer provides a way to recover from temporary failure | 95 // The reinitialization timer provides a way to recover from temporary failure |
| 88 // states by clearing the dispatcher if all proxies have been closed and none | 96 // states by clearing the dispatcher if all proxies have been closed and none |
| 89 // have been created within |close_delay_|. Without this, audio may be lost | 97 // have been created within |close_delay_|. Without this, audio may be lost |
| 90 // to a fake stream indefinitely for transient errors. | 98 // to a fake stream indefinitely for transient errors. |
| 91 base::Timer reinitialize_timer_; | 99 base::Timer reinitialize_timer_; |
| 92 | 100 |
| 101 // Callback for registering a debug recording source. |
| 102 RegisterDebugRecordingSourceCallback |
| 103 register_debug_recording_source_callback_; |
| 104 |
| 93 base::WeakPtrFactory<AudioOutputResampler> weak_factory_; | 105 base::WeakPtrFactory<AudioOutputResampler> weak_factory_; |
| 94 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); | 106 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); |
| 95 }; | 107 }; |
| 96 | 108 |
| 97 } // namespace media | 109 } // namespace media |
| 98 | 110 |
| 99 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | 111 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ |
| OLD | NEW |