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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 class MEDIA_EXPORT AudioOutputResampler : public AudioOutputDispatcher { | 32 class MEDIA_EXPORT AudioOutputResampler : public AudioOutputDispatcher { |
33 public: | 33 public: |
34 AudioOutputResampler(AudioManager* audio_manager, | 34 AudioOutputResampler(AudioManager* audio_manager, |
35 const AudioParameters& input_params, | 35 const AudioParameters& input_params, |
36 const AudioParameters& output_params, | 36 const AudioParameters& output_params, |
37 const std::string& output_device_id, | 37 const std::string& output_device_id, |
38 const base::TimeDelta& close_delay); | 38 const base::TimeDelta& close_delay); |
39 ~AudioOutputResampler() override; | 39 ~AudioOutputResampler() override; |
40 | 40 |
41 // AudioOutputDispatcher interface. | 41 // AudioOutputDispatcher interface. |
| 42 AudioOutputProxy* CreateStreamProxy() override; |
42 bool OpenStream() override; | 43 bool OpenStream() override; |
43 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, | 44 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, |
44 AudioOutputProxy* stream_proxy) override; | 45 AudioOutputProxy* stream_proxy) override; |
45 void StopStream(AudioOutputProxy* stream_proxy) override; | 46 void StopStream(AudioOutputProxy* stream_proxy) override; |
46 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; | 47 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; |
47 void CloseStream(AudioOutputProxy* stream_proxy) override; | 48 void CloseStream(AudioOutputProxy* stream_proxy) override; |
48 | 49 |
49 private: | 50 private: |
50 // Converts low latency based output parameters into high latency | 51 // Converts low latency based output parameters into high latency |
51 // appropriate output parameters in error situations. | 52 // appropriate output parameters in error situations. |
52 void SetupFallbackParams(); | 53 void SetupFallbackParams(); |
53 | 54 |
54 // Used to reinitialize |dispatcher_|. | 55 // Used to reinitialize |dispatcher_|. |
55 void Reinitialize(); | 56 void Reinitialize(); |
56 | 57 |
57 // Used to initialize |dispatcher_|. | 58 // Used to initialize |dispatcher_|. |
58 void Initialize(); | 59 void Initialize(); |
59 | 60 |
60 // Dispatcher to proxy all AudioOutputDispatcher calls too. | 61 // Dispatcher to proxy all AudioOutputDispatcher calls too. |
61 std::unique_ptr<AudioOutputDispatcherImpl> dispatcher_; | 62 std::unique_ptr<AudioOutputDispatcherImpl> dispatcher_; |
62 | 63 |
63 // Map of outstanding OnMoreDataConverter objects. A new object is created | 64 // Map of outstanding OnMoreDataConverter objects. A new object is created |
64 // on every StartStream() call and destroyed on CloseStream(). | 65 // on every StartStream() call and destroyed on CloseStream(). |
65 typedef std::map<AudioOutputProxy*, OnMoreDataConverter*> CallbackMap; | 66 typedef std::map<AudioOutputProxy*, std::unique_ptr<OnMoreDataConverter>> |
| 67 CallbackMap; |
66 CallbackMap callbacks_; | 68 CallbackMap callbacks_; |
67 | 69 |
68 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly. | 70 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly. |
69 base::TimeDelta close_delay_; | 71 base::TimeDelta close_delay_; |
70 | 72 |
71 // AudioParameters used to setup the output stream; changed upon fallback. | 73 // AudioParameters used to setup the output stream; changed upon fallback. |
72 AudioParameters output_params_; | 74 AudioParameters output_params_; |
73 | 75 |
74 // The original AudioParameters we were constructed with. | 76 // The original AudioParameters we were constructed with. |
75 const AudioParameters original_output_params_; | 77 const AudioParameters original_output_params_; |
76 | 78 |
77 // Whether any streams have been opened through |dispatcher_|, if so we can't | 79 // Whether any streams have been opened through |dispatcher_|, if so we can't |
78 // fallback on future OpenStream() failures. | 80 // fallback on future OpenStream() failures. |
79 bool streams_opened_; | 81 bool streams_opened_; |
80 | 82 |
81 // The reinitialization timer provides a way to recover from temporary failure | 83 // The reinitialization timer provides a way to recover from temporary failure |
82 // states by clearing the dispatcher if all proxies have been closed and none | 84 // states by clearing the dispatcher if all proxies have been closed and none |
83 // have been created within |close_delay_|. Without this, audio may be lost | 85 // have been created within |close_delay_|. Without this, audio may be lost |
84 // to a fake stream indefinitely for transient errors. | 86 // to a fake stream indefinitely for transient errors. |
85 base::Timer reinitialize_timer_; | 87 base::Timer reinitialize_timer_; |
86 | 88 |
| 89 base::WeakPtrFactory<AudioOutputResampler> weak_factory_; |
87 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); | 90 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); |
88 }; | 91 }; |
89 | 92 |
90 } // namespace media | 93 } // namespace media |
91 | 94 |
92 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | 95 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ |
OLD | NEW |