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