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 CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
11 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
12 #include "content/common/media/media_stream_options.h" | 14 #include "content/common/media/media_stream_options.h" |
13 #include "content/renderer/media/media_stream_audio_level_calculator.h" | 15 #include "content/renderer/media/media_stream_audio_level_calculator.h" |
14 #include "content/renderer/media/media_stream_audio_processor.h" | 16 #include "content/renderer/media/media_stream_audio_processor.h" |
15 #include "content/renderer/media/media_stream_audio_source.h" | 17 #include "content/renderer/media/media_stream_audio_source.h" |
16 #include "media/base/audio_capturer_source.h" | 18 #include "media/base/audio_capturer_source.h" |
17 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
(...skipping 11 matching lines...) Expand all Loading... |
29 // video conferencing call). Owns a media::AudioCapturerSource and the | 31 // video conferencing call). Owns a media::AudioCapturerSource and the |
30 // MediaStreamProcessor that modifies its audio. Modified audio is delivered to | 32 // MediaStreamProcessor that modifies its audio. Modified audio is delivered to |
31 // one or more MediaStreamAudioTracks. | 33 // one or more MediaStreamAudioTracks. |
32 class CONTENT_EXPORT ProcessedLocalAudioSource final | 34 class CONTENT_EXPORT ProcessedLocalAudioSource final |
33 : NON_EXPORTED_BASE(public MediaStreamAudioSource), | 35 : NON_EXPORTED_BASE(public MediaStreamAudioSource), |
34 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) { | 36 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) { |
35 public: | 37 public: |
36 // |consumer_render_frame_id| references the RenderFrame that will consume the | 38 // |consumer_render_frame_id| references the RenderFrame that will consume the |
37 // audio data. Audio parameters and (optionally) a pre-existing audio session | 39 // audio data. Audio parameters and (optionally) a pre-existing audio session |
38 // ID are derived from |device_info|. |factory| must outlive this instance. | 40 // ID are derived from |device_info|. |factory| must outlive this instance. |
39 ProcessedLocalAudioSource(int consumer_render_frame_id, | 41 ProcessedLocalAudioSource( |
40 const StreamDeviceInfo& device_info, | 42 int consumer_render_frame_id, |
41 const blink::WebMediaConstraints& constraints, | 43 const StreamDeviceInfo& device_info, |
42 const ConstraintsCallback& started_callback, | 44 const AudioProcessingProperties& audio_processing_properties, |
43 PeerConnectionDependencyFactory* factory); | 45 const ConstraintsCallback& started_callback, |
| 46 PeerConnectionDependencyFactory* factory); |
44 | 47 |
45 ~ProcessedLocalAudioSource() final; | 48 ~ProcessedLocalAudioSource() final; |
46 | 49 |
47 // If |source| is an instance of ProcessedLocalAudioSource, return a | 50 // If |source| is an instance of ProcessedLocalAudioSource, return a |
48 // type-casted pointer to it. Otherwise, return null. | 51 // type-casted pointer to it. Otherwise, return null. |
49 static ProcessedLocalAudioSource* From(MediaStreamAudioSource* source); | 52 static ProcessedLocalAudioSource* From(MediaStreamAudioSource* source); |
50 | 53 |
51 // Non-browser unit tests cannot provide RenderFrame implementations at | 54 // Non-browser unit tests cannot provide RenderFrame implementations at |
52 // run-time. This is used to skip the otherwise mandatory check for a valid | 55 // run-time. This is used to skip the otherwise mandatory check for a valid |
53 // render frame ID when the source is started. | 56 // render frame ID when the source is started. |
54 void SetAllowInvalidRenderFrameIdForTesting(bool allowed) { | 57 void SetAllowInvalidRenderFrameIdForTesting(bool allowed) { |
55 allow_invalid_render_frame_id_for_testing_ = allowed; | 58 allow_invalid_render_frame_id_for_testing_ = allowed; |
56 } | 59 } |
57 | 60 |
58 // Gets/Sets source constraints. Using this is optional, but must be done | 61 const AudioProcessingProperties& audio_processing_properties() const { |
59 // before the first call to ConnectToTrack(). | 62 return audio_processing_properties_; |
60 const blink::WebMediaConstraints& source_constraints() const { | |
61 return constraints_; | |
62 } | 63 } |
63 | 64 |
64 // The following accessors are not valid until after the source is started | 65 // The following accessors are not valid until after the source is started |
65 // (when the first track is connected). | 66 // (when the first track is connected). |
66 const scoped_refptr<MediaStreamAudioProcessor>& audio_processor() const { | 67 const scoped_refptr<MediaStreamAudioProcessor>& audio_processor() const { |
67 return audio_processor_; | 68 return audio_processor_; |
68 } | 69 } |
69 const scoped_refptr<MediaStreamAudioLevelCalculator::Level>& audio_level() | 70 const scoped_refptr<MediaStreamAudioLevelCalculator::Level>& audio_level() |
70 const { | 71 const { |
71 return level_calculator_.level(); | 72 return level_calculator_.level(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // The RenderFrame that will consume the audio data. Used when creating | 105 // The RenderFrame that will consume the audio data. Used when creating |
105 // AudioCapturerSources. | 106 // AudioCapturerSources. |
106 const int consumer_render_frame_id_; | 107 const int consumer_render_frame_id_; |
107 | 108 |
108 PeerConnectionDependencyFactory* const pc_factory_; | 109 PeerConnectionDependencyFactory* const pc_factory_; |
109 | 110 |
110 // In debug builds, check that all methods that could cause object graph | 111 // In debug builds, check that all methods that could cause object graph |
111 // or data flow changes are being called on the main thread. | 112 // or data flow changes are being called on the main thread. |
112 base::ThreadChecker thread_checker_; | 113 base::ThreadChecker thread_checker_; |
113 | 114 |
114 // Cached audio constraints for the capturer. | 115 AudioProcessingProperties audio_processing_properties_; |
115 const blink::WebMediaConstraints constraints_; | |
116 | 116 |
117 // Callback that's called when the audio source has been initialized. | 117 // Callback that's called when the audio source has been initialized. |
118 ConstraintsCallback started_callback_; | 118 ConstraintsCallback started_callback_; |
119 | 119 |
120 // Audio processor doing processing like FIFO, AGC, AEC and NS. Its output | 120 // Audio processor doing processing like FIFO, AGC, AEC and NS. Its output |
121 // data is in a unit of 10 ms data chunk. | 121 // data is in a unit of 10 ms data chunk. |
122 scoped_refptr<MediaStreamAudioProcessor> audio_processor_; | 122 scoped_refptr<MediaStreamAudioProcessor> audio_processor_; |
123 | 123 |
124 // The device created by the AudioDeviceFactory in EnsureSourceIsStarted(). | 124 // The device created by the AudioDeviceFactory in EnsureSourceIsStarted(). |
125 scoped_refptr<media::AudioCapturerSource> source_; | 125 scoped_refptr<media::AudioCapturerSource> source_; |
126 | 126 |
127 // Lock used to ensure thread-safe access to |source_| by SetVolume(). | 127 // Lock used to ensure thread-safe access to |source_| by SetVolume(). |
128 mutable base::Lock source_lock_; | 128 mutable base::Lock source_lock_; |
129 | 129 |
130 // Stores latest microphone volume received in a CaptureData() callback. | 130 // Stores latest microphone volume received in a CaptureData() callback. |
131 // Range is [0, 255]. | 131 // Range is [0, 255]. |
132 base::subtle::Atomic32 volume_; | 132 base::subtle::Atomic32 volume_; |
133 | 133 |
134 // Used to calculate the signal level that shows in the UI. | 134 // Used to calculate the signal level that shows in the UI. |
135 MediaStreamAudioLevelCalculator level_calculator_; | 135 MediaStreamAudioLevelCalculator level_calculator_; |
136 | 136 |
137 bool allow_invalid_render_frame_id_for_testing_; | 137 bool allow_invalid_render_frame_id_for_testing_; |
138 | 138 |
139 DISALLOW_COPY_AND_ASSIGN(ProcessedLocalAudioSource); | 139 DISALLOW_COPY_AND_ASSIGN(ProcessedLocalAudioSource); |
140 }; | 140 }; |
141 | 141 |
142 } // namespace content | 142 } // namespace content |
143 | 143 |
144 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_ | 144 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_ |
OLD | NEW |