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"
21 class RemoteAudioTrackAdapter
;
22 class RemoteVideoTrackAdapter
;
24 // RemoteMediaStreamImpl serves as a container and glue between remote webrtc
25 // MediaStreams and WebKit MediaStreams. For each remote MediaStream received
26 // on a PeerConnection a RemoteMediaStreamImpl instance is created and
27 // owned by RtcPeerConnection.
28 class CONTENT_EXPORT RemoteMediaStreamImpl
{
30 RemoteMediaStreamImpl(
31 const scoped_refptr
<base::SingleThreadTaskRunner
>& main_thread
,
32 webrtc::MediaStreamInterface
* webrtc_stream
);
33 ~RemoteMediaStreamImpl();
35 const blink::WebMediaStream
& webkit_stream() { return webkit_stream_
; }
36 const scoped_refptr
<webrtc::MediaStreamInterface
>& webrtc_stream() {
37 return observer_
->stream();
41 typedef std::vector
<scoped_refptr
<RemoteAudioTrackAdapter
>>
42 RemoteAudioTrackAdapters
;
43 typedef std::vector
<scoped_refptr
<RemoteVideoTrackAdapter
>>
44 RemoteVideoTrackAdapters
;
46 void InitializeOnMainThread(const std::string
& label
);
49 : NON_EXPORTED_BASE(public webrtc::ObserverInterface
),
50 public base::RefCountedThreadSafe
<Observer
> {
52 Observer(const base::WeakPtr
<RemoteMediaStreamImpl
>& media_stream
,
53 const scoped_refptr
<base::SingleThreadTaskRunner
>& main_thread
,
54 webrtc::MediaStreamInterface
* webrtc_stream
);
56 const scoped_refptr
<webrtc::MediaStreamInterface
>& stream() const {
57 return webrtc_stream_
;
60 const scoped_refptr
<base::SingleThreadTaskRunner
>& main_thread() const {
64 void InitializeOnMainThread(const std::string
& label
);
66 // Uninitializes the observer, unregisteres from receiving notifications
67 // and releases the webrtc stream.
68 // Note: Must be called from the main thread before releasing the main
73 friend class base::RefCountedThreadSafe
<Observer
>;
76 // webrtc::ObserverInterface implementation.
77 void OnChanged() override
;
79 void OnChangedOnMainThread(
80 scoped_ptr
<RemoteAudioTrackAdapters
> audio_tracks
,
81 scoped_ptr
<RemoteVideoTrackAdapters
> video_tracks
);
83 base::WeakPtr
<RemoteMediaStreamImpl
> media_stream_
;
84 const scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_
;
85 scoped_refptr
<webrtc::MediaStreamInterface
> webrtc_stream_
;
88 void OnChanged(scoped_ptr
<RemoteAudioTrackAdapters
> audio_tracks
,
89 scoped_ptr
<RemoteVideoTrackAdapters
> video_tracks
);
91 const scoped_refptr
<base::SingleThreadTaskRunner
> signaling_thread_
;
92 scoped_refptr
<Observer
> observer_
;
94 RemoteVideoTrackAdapters video_track_observers_
;
95 RemoteAudioTrackAdapters audio_track_observers_
;
96 blink::WebMediaStream webkit_stream_
;
98 base::WeakPtrFactory
<RemoteMediaStreamImpl
> weak_factory_
;
100 DISALLOW_COPY_AND_ASSIGN(RemoteMediaStreamImpl
);
103 } // namespace content
105 #endif // CONTENT_RENDERER_MEDIA_REMOTE_MEDIA_STREAM_IMPL_H_