| 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 "base/atomicops.h" | 8 #include "base/atomicops.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // one or more MediaStreamAudioTracks. | 31 // one or more MediaStreamAudioTracks. |
| 32 class CONTENT_EXPORT ProcessedLocalAudioSource final | 32 class CONTENT_EXPORT ProcessedLocalAudioSource final |
| 33 : NON_EXPORTED_BASE(public MediaStreamAudioSource), | 33 : NON_EXPORTED_BASE(public MediaStreamAudioSource), |
| 34 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) { | 34 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) { |
| 35 public: | 35 public: |
| 36 // |consumer_render_frame_id| references the RenderFrame that will consume the | 36 // |consumer_render_frame_id| references the RenderFrame that will consume the |
| 37 // audio data. Audio parameters and (optionally) a pre-existing audio session | 37 // audio data. Audio parameters and (optionally) a pre-existing audio session |
| 38 // ID are derived from |device_info|. |factory| must outlive this instance. | 38 // ID are derived from |device_info|. |factory| must outlive this instance. |
| 39 ProcessedLocalAudioSource(int consumer_render_frame_id, | 39 ProcessedLocalAudioSource(int consumer_render_frame_id, |
| 40 const StreamDeviceInfo& device_info, | 40 const StreamDeviceInfo& device_info, |
| 41 const blink::WebMediaConstraints& constraints, | |
| 42 const ConstraintsCallback& started_callback, | |
| 43 PeerConnectionDependencyFactory* factory); | 41 PeerConnectionDependencyFactory* factory); |
| 44 | 42 |
| 45 ~ProcessedLocalAudioSource() final; | 43 ~ProcessedLocalAudioSource() final; |
| 46 | 44 |
| 47 // If |source| is an instance of ProcessedLocalAudioSource, return a | 45 // If |source| is an instance of ProcessedLocalAudioSource, return a |
| 48 // type-casted pointer to it. Otherwise, return null. | 46 // type-casted pointer to it. Otherwise, return null. |
| 49 static ProcessedLocalAudioSource* From(MediaStreamAudioSource* source); | 47 static ProcessedLocalAudioSource* From(MediaStreamAudioSource* source); |
| 50 | 48 |
| 51 // Non-browser unit tests cannot provide RenderFrame implementations at | 49 // Non-browser unit tests cannot provide RenderFrame implementations at |
| 52 // run-time. This is used to skip the otherwise mandatory check for a valid | 50 // run-time. This is used to skip the otherwise mandatory check for a valid |
| 53 // render frame ID when the source is started. | 51 // render frame ID when the source is started. |
| 54 void SetAllowInvalidRenderFrameIdForTesting(bool allowed) { | 52 void SetAllowInvalidRenderFrameIdForTesting(bool allowed) { |
| 55 allow_invalid_render_frame_id_for_testing_ = allowed; | 53 allow_invalid_render_frame_id_for_testing_ = allowed; |
| 56 } | 54 } |
| 57 | 55 |
| 58 // Gets/Sets source constraints. Using this is optional, but must be done | 56 // Gets/Sets source constraints. Using this is optional, but must be done |
| 59 // before the first call to ConnectToTrack(). | 57 // before the first call to ConnectToTrack(). |
| 60 const blink::WebMediaConstraints& source_constraints() const { | 58 const blink::WebMediaConstraints& source_constraints() const { |
| 61 return constraints_; | 59 return constraints_; |
| 62 } | 60 } |
| 61 void SetSourceConstraints(const blink::WebMediaConstraints& constraints); |
| 63 | 62 |
| 64 // The following accessors are not valid until after the source is started | 63 // The following accessors are not valid until after the source is started |
| 65 // (when the first track is connected). | 64 // (when the first track is connected). |
| 66 const scoped_refptr<MediaStreamAudioProcessor>& audio_processor() const { | 65 const scoped_refptr<MediaStreamAudioProcessor>& audio_processor() const { |
| 67 return audio_processor_; | 66 return audio_processor_; |
| 68 } | 67 } |
| 69 const scoped_refptr<MediaStreamAudioLevelCalculator::Level>& audio_level() | 68 const scoped_refptr<MediaStreamAudioLevelCalculator::Level>& audio_level() |
| 70 const { | 69 const { |
| 71 return level_calculator_.level(); | 70 return level_calculator_.level(); |
| 72 } | 71 } |
| 73 | 72 |
| 74 // Thread-safe volume accessors used by WebRtcAudioDeviceImpl. | 73 // Thread-safe volume accessors used by WebRtcAudioDeviceImpl. |
| 75 void SetVolume(int volume); | 74 void SetVolume(int volume); |
| 76 int Volume() const; | 75 int Volume() const; |
| 77 int MaxVolume() const; | 76 int MaxVolume() const; |
| 78 | 77 |
| 79 // Audio parameters utilized by the source of the audio capturer. | 78 // Audio parameters utilized by the source of the audio capturer. |
| 80 // TODO(phoglund): Think over the implications of this accessor and if we can | 79 // TODO(phoglund): Think over the implications of this accessor and if we can |
| 81 // remove it. | 80 // remove it. |
| 82 media::AudioParameters GetInputFormat() const; | 81 media::AudioParameters GetInputFormat() const; |
| 83 | 82 |
| 84 protected: | 83 protected: |
| 85 // MediaStreamAudioSource implementation. | 84 // MediaStreamAudioSource implementation. |
| 86 void* GetClassIdentifier() const final; | 85 void* GetClassIdentifier() const final; |
| 87 bool EnsureSourceIsStarted() final; | 86 bool EnsureSourceIsStarted() final; |
| 88 void EnsureSourceIsStopped() final; | 87 void EnsureSourceIsStopped() final; |
| 89 | 88 |
| 90 // AudioCapturerSource::CaptureCallback implementation. | 89 // AudioCapturerSource::CaptureCallback implementation. |
| 91 // Called on the AudioCapturerSource audio thread. | 90 // Called on the AudioCapturerSource audio thread. |
| 92 void OnCaptureStarted() override; | |
| 93 void Capture(const media::AudioBus* audio_source, | 91 void Capture(const media::AudioBus* audio_source, |
| 94 int audio_delay_milliseconds, | 92 int audio_delay_milliseconds, |
| 95 double volume, | 93 double volume, |
| 96 bool key_pressed) override; | 94 bool key_pressed) override; |
| 97 void OnCaptureError(const std::string& message) override; | 95 void OnCaptureError(const std::string& message) override; |
| 98 | 96 |
| 99 private: | 97 private: |
| 100 // Helper function to get the source buffer size based on whether audio | 98 // Helper function to get the source buffer size based on whether audio |
| 101 // processing will take place. | 99 // processing will take place. |
| 102 int GetBufferSize(int sample_rate) const; | 100 int GetBufferSize(int sample_rate) const; |
| 103 | 101 |
| 104 // The RenderFrame that will consume the audio data. Used when creating | 102 // The RenderFrame that will consume the audio data. Used when creating |
| 105 // AudioCapturerSources. | 103 // AudioCapturerSources. |
| 106 const int consumer_render_frame_id_; | 104 const int consumer_render_frame_id_; |
| 107 | 105 |
| 108 PeerConnectionDependencyFactory* const pc_factory_; | 106 PeerConnectionDependencyFactory* const pc_factory_; |
| 109 | 107 |
| 110 // In debug builds, check that all methods that could cause object graph | 108 // In debug builds, check that all methods that could cause object graph |
| 111 // or data flow changes are being called on the main thread. | 109 // or data flow changes are being called on the main thread. |
| 112 base::ThreadChecker thread_checker_; | 110 base::ThreadChecker thread_checker_; |
| 113 | 111 |
| 114 // Cached audio constraints for the capturer. | 112 // Cached audio constraints for the capturer. |
| 115 const blink::WebMediaConstraints constraints_; | 113 blink::WebMediaConstraints constraints_; |
| 116 | |
| 117 // Callback that's called when the audio source has been initialized. | |
| 118 ConstraintsCallback started_callback_; | |
| 119 | 114 |
| 120 // Audio processor doing processing like FIFO, AGC, AEC and NS. Its output | 115 // Audio processor doing processing like FIFO, AGC, AEC and NS. Its output |
| 121 // data is in a unit of 10 ms data chunk. | 116 // data is in a unit of 10 ms data chunk. |
| 122 scoped_refptr<MediaStreamAudioProcessor> audio_processor_; | 117 scoped_refptr<MediaStreamAudioProcessor> audio_processor_; |
| 123 | 118 |
| 124 // The device created by the AudioDeviceFactory in EnsureSourceIsStarted(). | 119 // The device created by the AudioDeviceFactory in EnsureSourceIsStarted(). |
| 125 scoped_refptr<media::AudioCapturerSource> source_; | 120 scoped_refptr<media::AudioCapturerSource> source_; |
| 126 | 121 |
| 127 // Lock used to ensure thread-safe access to |source_| by SetVolume(). | 122 // Lock used to ensure thread-safe access to |source_| by SetVolume(). |
| 128 mutable base::Lock source_lock_; | 123 mutable base::Lock source_lock_; |
| 129 | 124 |
| 130 // Stores latest microphone volume received in a CaptureData() callback. | 125 // Stores latest microphone volume received in a CaptureData() callback. |
| 131 // Range is [0, 255]. | 126 // Range is [0, 255]. |
| 132 base::subtle::Atomic32 volume_; | 127 base::subtle::Atomic32 volume_; |
| 133 | 128 |
| 134 // Used to calculate the signal level that shows in the UI. | 129 // Used to calculate the signal level that shows in the UI. |
| 135 MediaStreamAudioLevelCalculator level_calculator_; | 130 MediaStreamAudioLevelCalculator level_calculator_; |
| 136 | 131 |
| 137 bool allow_invalid_render_frame_id_for_testing_; | 132 bool allow_invalid_render_frame_id_for_testing_; |
| 138 | 133 |
| 139 DISALLOW_COPY_AND_ASSIGN(ProcessedLocalAudioSource); | 134 DISALLOW_COPY_AND_ASSIGN(ProcessedLocalAudioSource); |
| 140 }; | 135 }; |
| 141 | 136 |
| 142 } // namespace content | 137 } // namespace content |
| 143 | 138 |
| 144 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_ | 139 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_ |
| OLD | NEW |