Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MEDIA_STREAM_AUDIO_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 10 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 11 #include "content/renderer/media/media_stream_source.h" | 13 #include "content/renderer/media/media_stream_source.h" |
| 14 #include "content/renderer/media/webaudio_capturer_source.h" | |
| 12 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 15 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
| 13 #include "content/renderer/media/webrtc_audio_capturer.h" | 16 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 14 #include "third_party/webrtc/api/mediastreaminterface.h" | 17 #include "third_party/webrtc/api/mediastreaminterface.h" |
| 15 | 18 |
| 16 namespace content { | 19 namespace content { |
| 17 | 20 |
| 21 class MediaStreamAudioTrack; | |
| 22 | |
| 23 // TODO(miu): In a soon-upcoming set of refactoring changes, this class will | |
| 24 // become a base class for managing tracks (part of what WebRtcAudioCapturer | |
| 25 // does today). Then, the rest of WebRtcAudioCapturer will be rolled into a | |
| 26 // subclass. http://crbug.com/577874 | |
| 18 class CONTENT_EXPORT MediaStreamAudioSource | 27 class CONTENT_EXPORT MediaStreamAudioSource |
| 19 : NON_EXPORTED_BASE(public MediaStreamSource) { | 28 : NON_EXPORTED_BASE(public MediaStreamSource) { |
| 20 public: | 29 public: |
| 21 MediaStreamAudioSource(int render_frame_id, | 30 MediaStreamAudioSource(int render_frame_id, |
| 22 const StreamDeviceInfo& device_info, | 31 const StreamDeviceInfo& device_info, |
| 23 const SourceStoppedCallback& stop_callback, | 32 const SourceStoppedCallback& stop_callback, |
| 24 PeerConnectionDependencyFactory* factory); | 33 PeerConnectionDependencyFactory* factory); |
| 25 MediaStreamAudioSource(); | 34 MediaStreamAudioSource(); |
| 26 ~MediaStreamAudioSource() override; | 35 ~MediaStreamAudioSource() override; |
| 27 | 36 |
| 37 // Returns the MediaStreamAudioSource instance owned by the given blink | |
| 38 // |source| or null. | |
| 39 static MediaStreamAudioSource* From(const blink::WebMediaStreamSource& track); | |
| 40 | |
| 28 void AddTrack(const blink::WebMediaStreamTrack& track, | 41 void AddTrack(const blink::WebMediaStreamTrack& track, |
| 29 const blink::WebMediaConstraints& constraints, | 42 const blink::WebMediaConstraints& constraints, |
| 30 const ConstraintsCallback& callback); | 43 const ConstraintsCallback& callback); |
| 31 | 44 |
| 32 void SetLocalAudioSource(webrtc::AudioSourceInterface* source) { | 45 base::WeakPtr<MediaStreamAudioSource> GetWeakPtr() { |
| 33 local_audio_source_ = source; | 46 return weak_factory_.GetWeakPtr(); |
| 34 } | 47 } |
| 35 | 48 |
| 36 void SetAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer) { | 49 // Removes |track| from the list of instances that get a copy of the source |
| 50 // audio data. | |
| 51 void StopAudioDeliveryTo(MediaStreamAudioTrack* track); | |
| 52 | |
| 53 WebRtcAudioCapturer* audio_capturer() const { return audio_capturer_.get(); } | |
| 54 | |
| 55 void SetAudioCapturer(scoped_ptr<WebRtcAudioCapturer> capturer) { | |
| 37 DCHECK(!audio_capturer_.get()); | 56 DCHECK(!audio_capturer_.get()); |
| 38 audio_capturer_ = capturer; | 57 audio_capturer_ = std::move(capturer); |
| 39 } | |
| 40 | |
| 41 const scoped_refptr<WebRtcAudioCapturer>& GetAudioCapturer() { | |
| 42 return audio_capturer_; | |
| 43 } | 58 } |
| 44 | 59 |
| 45 webrtc::AudioSourceInterface* local_audio_source() { | 60 webrtc::AudioSourceInterface* local_audio_source() { |
| 46 return local_audio_source_.get(); | 61 return local_audio_source_.get(); |
| 47 } | 62 } |
| 48 | 63 |
| 64 void SetLocalAudioSource(scoped_refptr<webrtc::AudioSourceInterface> source) { | |
|
tommi (sloooow) - chröme
2016/03/03 11:07:30
just checking - the intent here is to take ownersh
miu
2016/03/05 02:55:31
Done (using std::move() here and in other places t
| |
| 65 local_audio_source_ = source; | |
|
tommi (sloooow) - chröme
2016/03/03 11:07:30
and if not passing by value is intentional, I thin
miu
2016/03/05 02:55:30
Done.
| |
| 66 } | |
| 67 | |
| 68 WebAudioCapturerSource* webaudio_capturer() const { | |
| 69 return webaudio_capturer_.get(); | |
| 70 } | |
| 71 | |
| 72 void SetWebAudioCapturer(scoped_ptr<WebAudioCapturerSource> capturer) { | |
| 73 DCHECK(!webaudio_capturer_.get()); | |
| 74 webaudio_capturer_ = std::move(capturer); | |
| 75 } | |
| 76 | |
| 49 protected: | 77 protected: |
| 50 void DoStopSource() override; | 78 void DoStopSource() override; |
| 51 | 79 |
| 52 private: | 80 private: |
| 53 const int render_frame_id_; | 81 const int render_frame_id_; |
| 54 PeerConnectionDependencyFactory* const factory_; | 82 PeerConnectionDependencyFactory* const factory_; |
| 55 | 83 |
| 84 // MediaStreamAudioSource is the owner of either a WebRtcAudioCapturer or a | |
| 85 // WebAudioCapturerSource. | |
| 86 // | |
| 87 // TODO(miu): In a series of soon-upcoming changes, WebRtcAudioCapturer and | |
| 88 // WebAudioCapturerSource will become subclasses of MediaStreamAudioSource | |
| 89 // instead. | |
| 90 scoped_ptr<WebRtcAudioCapturer> audio_capturer_; | |
| 91 scoped_ptr<WebAudioCapturerSource> webaudio_capturer_; | |
| 92 | |
| 56 // This member holds an instance of webrtc::LocalAudioSource. This is used | 93 // This member holds an instance of webrtc::LocalAudioSource. This is used |
| 57 // as a container for audio options. | 94 // as a container for audio options. |
| 58 scoped_refptr<webrtc::AudioSourceInterface> local_audio_source_; | 95 scoped_refptr<webrtc::AudioSourceInterface> local_audio_source_; |
| 59 | 96 |
| 60 scoped_refptr<WebRtcAudioCapturer> audio_capturer_; | 97 // Provides weak pointers so that MediaStreamAudioTracks won't call |
| 98 // StopAudioDeliveryTo() if this instance dies first. | |
| 99 base::WeakPtrFactory<MediaStreamAudioSource> weak_factory_; | |
| 61 | 100 |
| 62 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioSource); | 101 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioSource); |
| 63 }; | 102 }; |
| 64 | 103 |
| 65 } // namespace content | 104 } // namespace content |
| 66 | 105 |
| 67 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ | 106 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ |
| OLD | NEW |