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