| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_AUDIO_TRACK_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "content/renderer/media/webrtc_audio_device_impl.h" | |
| 14 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | 13 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
| 15 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" | 14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" |
| 16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 15 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
| 17 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h" | 16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h" |
| 18 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" | 17 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" |
| 19 | 18 |
| 20 namespace cricket { | 19 namespace cricket { |
| 21 class AudioRenderer; | 20 class AudioRenderer; |
| 22 } // namespace cricket | 21 } // namespace cricket |
| 23 | 22 |
| 24 namespace media { | 23 namespace media { |
| 25 class AudioBus; | 24 class AudioBus; |
| 26 } // namespace media | 25 } // namespace media |
| 27 | 26 |
| 28 namespace content { | 27 namespace content { |
| 29 | 28 |
| 29 class MediaStreamAudioSink; |
| 30 class MediaStreamAudioSinkOwner; |
| 31 class PeerConnectionAudioSink; |
| 30 class WebAudioCapturerSource; | 32 class WebAudioCapturerSource; |
| 31 class WebRtcAudioCapturer; | 33 class WebRtcAudioCapturer; |
| 32 class WebRtcAudioCapturerSinkOwner; | |
| 33 | 34 |
| 34 // A WebRtcLocalAudioTrack instance contains the implementations of | 35 // A WebRtcLocalAudioTrack instance contains the implementations of |
| 35 // MediaStreamTrack and WebRtcAudioCapturerSink. | 36 // MediaStreamTrack and MediaStreamAudioSink. |
| 36 // When an instance is created, it will register itself as a track to the | 37 // When an instance is created, it will register itself as a track to the |
| 37 // WebRtcAudioCapturer to get the captured data, and forward the data to | 38 // WebRtcAudioCapturer to get the captured data, and forward the data to |
| 38 // its |sinks_|. The data flow can be stopped by disabling the audio track. | 39 // its |sinks_|. The data flow can be stopped by disabling the audio track. |
| 39 class CONTENT_EXPORT WebRtcLocalAudioTrack | 40 class CONTENT_EXPORT WebRtcLocalAudioTrack |
| 40 : NON_EXPORTED_BASE(public cricket::AudioRenderer), | 41 : NON_EXPORTED_BASE(public cricket::AudioRenderer), |
| 41 NON_EXPORTED_BASE( | 42 NON_EXPORTED_BASE( |
| 42 public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) { | 43 public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) { |
| 43 public: | 44 public: |
| 44 static scoped_refptr<WebRtcLocalAudioTrack> Create( | 45 static scoped_refptr<WebRtcLocalAudioTrack> Create( |
| 45 const std::string& id, | 46 const std::string& id, |
| 46 const scoped_refptr<WebRtcAudioCapturer>& capturer, | 47 const scoped_refptr<WebRtcAudioCapturer>& capturer, |
| 47 WebAudioCapturerSource* webaudio_source, | 48 WebAudioCapturerSource* webaudio_source, |
| 48 webrtc::AudioSourceInterface* track_source, | 49 webrtc::AudioSourceInterface* track_source, |
| 49 const webrtc::MediaConstraintsInterface* constraints); | 50 const webrtc::MediaConstraintsInterface* constraints); |
| 50 | 51 |
| 51 // Add a sink to the track. This function will trigger a SetCaptureFormat() | 52 // Add a sink to the track. This function will trigger a OnSetFormat() |
| 52 // call on the |sink|. | 53 // call on the |sink|. |
| 53 // Called on the main render thread. | 54 // Called on the main render thread. |
| 54 void AddSink(WebRtcAudioCapturerSink* sink); | 55 void AddSink(MediaStreamAudioSink* sink); |
| 55 | 56 |
| 56 // Remove a sink from the track. | 57 // Remove a sink from the track. |
| 57 // Called on the main render thread. | 58 // Called on the main render thread. |
| 58 void RemoveSink(WebRtcAudioCapturerSink* sink); | 59 void RemoveSink(MediaStreamAudioSink* sink); |
| 60 |
| 61 // Add/remove PeerConnection sink to/from the track. |
| 62 // TODO(xians): Remove these two methods after PeerConnection can use the |
| 63 // same sink interface as MediaStreamAudioSink. |
| 64 void AddSink(PeerConnectionAudioSink* sink); |
| 65 void RemoveSink(PeerConnectionAudioSink* sink); |
| 59 | 66 |
| 60 // Starts the local audio track. Called on the main render thread and | 67 // Starts the local audio track. Called on the main render thread and |
| 61 // should be called only once when audio track is created. | 68 // should be called only once when audio track is created. |
| 62 void Start(); | 69 void Start(); |
| 63 | 70 |
| 64 // Stops the local audio track. Called on the main render thread and | 71 // Stops the local audio track. Called on the main render thread and |
| 65 // should be called only once when audio track going away. | 72 // should be called only once when audio track going away. |
| 66 void Stop(); | 73 void Stop(); |
| 67 | 74 |
| 68 // Method called by the capturer to deliver the capture data. | 75 // Method called by the capturer to deliver the capture data. |
| 69 // Call on the capture audio thread. | 76 // Call on the capture audio thread. |
| 70 void Capture(media::AudioBus* audio_source, | 77 void Capture(media::AudioBus* audio_source, |
| 71 int audio_delay_milliseconds, | 78 int audio_delay_milliseconds, |
| 72 int volume, | 79 int volume, |
| 73 bool key_pressed); | 80 bool key_pressed); |
| 74 | 81 |
| 75 // Method called by the capturer to set the audio parameters used by source | 82 // Method called by the capturer to set the audio parameters used by source |
| 76 // of the capture data.. | 83 // of the capture data.. |
| 77 // Call on the capture audio thread. | 84 // Call on the capture audio thread. |
| 78 void SetCaptureFormat(const media::AudioParameters& params); | 85 void OnSetFormat(const media::AudioParameters& params); |
| 79 | 86 |
| 80 blink::WebAudioSourceProvider* audio_source_provider() const { | 87 blink::WebAudioSourceProvider* audio_source_provider() const { |
| 81 return source_provider_.get(); | 88 return source_provider_.get(); |
| 82 } | 89 } |
| 83 | 90 |
| 84 protected: | 91 protected: |
| 85 WebRtcLocalAudioTrack( | 92 WebRtcLocalAudioTrack( |
| 86 const std::string& label, | 93 const std::string& label, |
| 87 const scoped_refptr<WebRtcAudioCapturer>& capturer, | 94 const scoped_refptr<WebRtcAudioCapturer>& capturer, |
| 88 WebAudioCapturerSource* webaudio_source, | 95 WebAudioCapturerSource* webaudio_source, |
| 89 webrtc::AudioSourceInterface* track_source, | 96 webrtc::AudioSourceInterface* track_source, |
| 90 const webrtc::MediaConstraintsInterface* constraints); | 97 const webrtc::MediaConstraintsInterface* constraints); |
| 91 | 98 |
| 92 virtual ~WebRtcLocalAudioTrack(); | 99 virtual ~WebRtcLocalAudioTrack(); |
| 93 | 100 |
| 94 private: | 101 private: |
| 95 typedef std::list<scoped_refptr<WebRtcAudioCapturerSinkOwner> > SinkList; | 102 typedef std::list<scoped_refptr<MediaStreamAudioSinkOwner> > SinkList; |
| 96 | 103 |
| 97 // cricket::AudioCapturer implementation. | 104 // cricket::AudioCapturer implementation. |
| 98 virtual void AddChannel(int channel_id) OVERRIDE; | 105 virtual void AddChannel(int channel_id) OVERRIDE; |
| 99 virtual void RemoveChannel(int channel_id) OVERRIDE; | 106 virtual void RemoveChannel(int channel_id) OVERRIDE; |
| 100 | 107 |
| 101 // webrtc::AudioTrackInterface implementation. | 108 // webrtc::AudioTrackInterface implementation. |
| 102 virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE; | 109 virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE; |
| 103 virtual cricket::AudioRenderer* GetRenderer() OVERRIDE; | 110 virtual cricket::AudioRenderer* GetRenderer() OVERRIDE; |
| 104 | 111 |
| 105 // webrtc::MediaStreamTrack implementation. | 112 // webrtc::MediaStreamTrack implementation. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // The source provider to feed the track data to other clients like | 153 // The source provider to feed the track data to other clients like |
| 147 // WebAudio. | 154 // WebAudio. |
| 148 scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; | 155 scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; |
| 149 | 156 |
| 150 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); | 157 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); |
| 151 }; | 158 }; |
| 152 | 159 |
| 153 } // namespace content | 160 } // namespace content |
| 154 | 161 |
| 155 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | 162 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ |
| OLD | NEW |