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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_REMOTE_MEDIA_STREAM_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_REMOTE_MEDIA_STREAM_IMPL_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_checker.h"
15 #include "content/common/content_export.h"
16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
17 #include "third_party/WebKit/public/platform/WebMediaStream.h"
18 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
19 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
23 class RemoteAudioTrackAdapter
;
24 class RemoteVideoTrackAdapter
;
26 // RemoteMediaStreamImpl serves as a container and glue between remote webrtc
27 // MediaStreams and WebKit MediaStreams. For each remote MediaStream received
28 // on a PeerConnection a RemoteMediaStreamImpl instance is created and
29 // owned by RtcPeerConnection.
30 class CONTENT_EXPORT RemoteMediaStreamImpl
{
32 RemoteMediaStreamImpl(
33 const scoped_refptr
<base::SingleThreadTaskRunner
>& main_thread
,
34 webrtc::MediaStreamInterface
* webrtc_stream
);
35 ~RemoteMediaStreamImpl();
37 const blink::WebMediaStream
& webkit_stream() { return webkit_stream_
; }
38 const scoped_refptr
<webrtc::MediaStreamInterface
>& webrtc_stream() {
39 return observer_
->stream();
43 typedef std::vector
<scoped_refptr
<RemoteAudioTrackAdapter
>>
44 RemoteAudioTrackAdapters
;
45 typedef std::vector
<scoped_refptr
<RemoteVideoTrackAdapter
>>
46 RemoteVideoTrackAdapters
;
48 void InitializeOnMainThread(const std::string
& label
);
51 : NON_EXPORTED_BASE(public webrtc::ObserverInterface
),
52 public base::RefCountedThreadSafe
<Observer
> {
54 Observer(const base::WeakPtr
<RemoteMediaStreamImpl
>& media_stream
,
55 const scoped_refptr
<base::SingleThreadTaskRunner
>& main_thread
,
56 webrtc::MediaStreamInterface
* webrtc_stream
);
58 const scoped_refptr
<webrtc::MediaStreamInterface
>& stream() const {
59 return webrtc_stream_
;
62 const scoped_refptr
<base::SingleThreadTaskRunner
>& main_thread() const {
66 void InitializeOnMainThread(const std::string
& label
);
68 // Uninitializes the observer, unregisteres from receiving notifications
69 // and releases the webrtc stream.
70 // Note: Must be called from the main thread before releasing the main
75 friend class base::RefCountedThreadSafe
<Observer
>;
78 // webrtc::ObserverInterface implementation.
79 void OnChanged() override
;
81 void OnChangedOnMainThread(
82 scoped_ptr
<RemoteAudioTrackAdapters
> audio_tracks
,
83 scoped_ptr
<RemoteVideoTrackAdapters
> video_tracks
);
85 base::WeakPtr
<RemoteMediaStreamImpl
> media_stream_
;
86 const scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_
;
87 scoped_refptr
<webrtc::MediaStreamInterface
> webrtc_stream_
;
90 void OnChanged(scoped_ptr
<RemoteAudioTrackAdapters
> audio_tracks
,
91 scoped_ptr
<RemoteVideoTrackAdapters
> video_tracks
);
93 const scoped_refptr
<base::SingleThreadTaskRunner
> signaling_thread_
;
94 scoped_refptr
<Observer
> observer_
;
96 RemoteVideoTrackAdapters video_track_observers_
;
97 RemoteAudioTrackAdapters audio_track_observers_
;
98 blink::WebMediaStream webkit_stream_
;
100 base::WeakPtrFactory
<RemoteMediaStreamImpl
> weak_factory_
;
102 DISALLOW_COPY_AND_ASSIGN(RemoteMediaStreamImpl
);
105 } // namespace content
107 #endif // CONTENT_RENDERER_MEDIA_REMOTE_MEDIA_STREAM_IMPL_H_