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_manager.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: |
34 AudioOutputResampler(AudioManager* audio_manager, | 35 AudioOutputResampler(AudioManager* audio_manager, |
35 const AudioParameters& input_params, | 36 const AudioParameters& input_params, |
36 const AudioParameters& output_params, | 37 const AudioParameters& output_params, |
37 const std::string& output_device_id, | 38 const std::string& output_device_id, |
38 const base::TimeDelta& close_delay); | 39 base::TimeDelta close_delay, |
| 40 const RegisterDebugRecordingSourceCallback& |
| 41 register_debug_recording_source_callback); |
39 ~AudioOutputResampler() override; | 42 ~AudioOutputResampler() override; |
40 | 43 |
41 // AudioOutputDispatcher interface. | 44 // AudioOutputDispatcher interface. |
42 AudioOutputProxy* CreateStreamProxy() override; | 45 AudioOutputProxy* CreateStreamProxy() override; |
43 bool OpenStream() override; | 46 bool OpenStream() override; |
44 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, | 47 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, |
45 AudioOutputProxy* stream_proxy) override; | 48 AudioOutputProxy* stream_proxy) override; |
46 void StopStream(AudioOutputProxy* stream_proxy) override; | 49 void StopStream(AudioOutputProxy* stream_proxy) override; |
47 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; | 50 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; |
48 void CloseStream(AudioOutputProxy* stream_proxy) override; | 51 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 | 86 // Whether any streams have been opened through |dispatcher_|, if so we can't |
84 // fallback on future OpenStream() failures. | 87 // fallback on future OpenStream() failures. |
85 bool streams_opened_; | 88 bool streams_opened_; |
86 | 89 |
87 // The reinitialization timer provides a way to recover from temporary failure | 90 // 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 | 91 // 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 | 92 // have been created within |close_delay_|. Without this, audio may be lost |
90 // to a fake stream indefinitely for transient errors. | 93 // to a fake stream indefinitely for transient errors. |
91 base::Timer reinitialize_timer_; | 94 base::Timer reinitialize_timer_; |
92 | 95 |
| 96 // Callback for registering debug recording source. |
| 97 RegisterDebugRecordingSourceCallback |
| 98 register_debug_recording_source_callback_; |
| 99 |
93 base::WeakPtrFactory<AudioOutputResampler> weak_factory_; | 100 base::WeakPtrFactory<AudioOutputResampler> weak_factory_; |
94 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); | 101 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); |
95 }; | 102 }; |
96 | 103 |
97 } // namespace media | 104 } // namespace media |
98 | 105 |
99 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | 106 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ |
OLD | NEW |