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 // |
| 5 // THREAD SAFETY |
| 6 // |
| 7 // This class is generally not thread safe. Callers should ensure thread safety. |
| 8 // For instance, the |sink_lock_| in WebAudioSourceProvider synchronizes access |
| 9 // to this object across the main thread (for WebAudio APIs) and the |
| 10 // media thread (for HTMLMediaElement APIs). |
| 11 // |
| 12 // The one exception is protection for |volume_| via |volume_lock_|. This lock |
| 13 // prevents races between SetVolume() (called on any thread) and ProvideInput |
| 14 // (called on audio device thread). See http://crbug.com/588992. |
4 | 15 |
5 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ | 16 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ |
6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ | 17 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ |
7 | 18 |
8 #include <string> | 19 #include <string> |
9 | 20 |
10 #include "base/callback.h" | 21 #include "base/callback.h" |
11 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/synchronization/lock.h" |
12 #include "media/base/audio_converter.h" | 24 #include "media/base/audio_converter.h" |
13 #include "media/base/audio_renderer_sink.h" | 25 #include "media/base/audio_renderer_sink.h" |
14 #include "media/base/output_device.h" | 26 #include "media/base/output_device.h" |
15 #include "url/origin.h" | 27 #include "url/origin.h" |
16 | 28 |
17 namespace media { | 29 namespace media { |
18 | 30 |
19 class AudioRendererMixer; | 31 class AudioRendererMixer; |
20 | 32 |
21 class MEDIA_EXPORT AudioRendererMixerInput | 33 class MEDIA_EXPORT AudioRendererMixerInput |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 74 |
63 // Called by AudioRendererMixer when an error occurs. | 75 // Called by AudioRendererMixer when an error occurs. |
64 void OnRenderError(); | 76 void OnRenderError(); |
65 | 77 |
66 protected: | 78 protected: |
67 ~AudioRendererMixerInput() override; | 79 ~AudioRendererMixerInput() override; |
68 | 80 |
69 private: | 81 private: |
70 friend class AudioRendererMixerInputTest; | 82 friend class AudioRendererMixerInputTest; |
71 | 83 |
| 84 // Protect |volume_|, accessed by separate threads in ProvideInput() and |
| 85 // SetVolume(). |
| 86 base::Lock volume_lock_; |
| 87 |
72 bool started_; | 88 bool started_; |
73 bool playing_; | 89 bool playing_; |
74 double volume_; | 90 double volume_; |
75 | 91 |
76 // AudioConverter::InputCallback implementation. | 92 // AudioConverter::InputCallback implementation. |
77 double ProvideInput(AudioBus* audio_bus, | 93 double ProvideInput(AudioBus* audio_bus, |
78 base::TimeDelta buffer_delay) override; | 94 base::TimeDelta buffer_delay) override; |
79 | 95 |
80 // Callbacks provided during construction which allow AudioRendererMixerInput | 96 // Callbacks provided during construction which allow AudioRendererMixerInput |
81 // to retrieve a mixer during Initialize() and notify when it's done with it. | 97 // to retrieve a mixer during Initialize() and notify when it's done with it. |
(...skipping 26 matching lines...) Expand all Loading... |
108 SwitchOutputDeviceCB pending_switch_callback_; | 124 SwitchOutputDeviceCB pending_switch_callback_; |
109 std::string pending_switch_device_id_; | 125 std::string pending_switch_device_id_; |
110 url::Origin pending_switch_security_origin_; | 126 url::Origin pending_switch_security_origin_; |
111 | 127 |
112 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInput); | 128 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInput); |
113 }; | 129 }; |
114 | 130 |
115 } // namespace media | 131 } // namespace media |
116 | 132 |
117 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ | 133 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ |
OLD | NEW |