Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(672)

Side by Side Diff: content/renderer/media/webrtc/webrtc_media_stream_track_adapter.h

Issue 2883023002: WebRtcMediaStreamTrackAdapter, maps 1 webrtc and 1 blink track (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017 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.
4
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_TRACK_ADAPTER_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_TRACK_ADAPTER_H_
7
8 #include <memory>
9
10 #include "base/memory/ref_counted.h"
11 #include "content/common/content_export.h"
12 #include "content/renderer/media/remote_media_stream_track_adapter.h"
13 #include "content/renderer/media/webrtc/media_stream_video_webrtc_sink.h"
14 #include "content/renderer/media/webrtc/webrtc_audio_sink.h"
15 #include "content/renderer/media/webrtc/webrtc_media_stream_track_adapter.h"
16 #include "third_party/WebKit/public/platform/WebMediaStream.h"
17 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
18 #include "third_party/webrtc/api/mediastreaminterface.h"
19
20 namespace content {
21
22 class PeerConnectionDependencyFactory;
23
24 // This is a mapping between a webrtc and blink media stream track. It takes
25 // care of creation, initialization and uninitialization independently of media
26 // streams.
27 // There are different sinks/adapters used whether the track is local or remote
28 // and whether it is an audio or video track; this adapter hides that fact and
29 // lets you use a single class for any type of track.
30 class CONTENT_EXPORT WebRtcMediaStreamTrackAdapter
31 : public base::RefCountedThreadSafe<WebRtcMediaStreamTrackAdapter> {
32 public:
33 // Invoke on the main thread. Construction and initialization happens here,
34 // ensuring |is_initialized| is true for the returned adapter.
35 static scoped_refptr<WebRtcMediaStreamTrackAdapter> CreateLocalTrackAdapter(
36 PeerConnectionDependencyFactory* factory,
37 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
38 const blink::WebMediaStreamTrack& web_track);
39 // Invoke on the webrtc signaling thread. Initialization completes on the main
40 // thread in a post. |is_initialized| is ensured in posts to the main thread
Guido Urdaneta 2017/05/22 14:26:38 Please update this comment. What is |is_initialize
hbos_chromium 2017/05/29 11:24:17 Done.
41 // subsequent to |CreateRemoteTrackAdapter|.
42 static scoped_refptr<WebRtcMediaStreamTrackAdapter> CreateRemoteTrackAdapter(
43 PeerConnectionDependencyFactory* factory,
44 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
45 webrtc::MediaStreamTrackInterface* webrtc_track);
46 // Invoke on the main thread. Uninitialization may finish asynchronously using
47 // the webrtc signaling thread and the main thread. After calling this method
48 // it is safe to release all external references to the adapter.
49 // Must be invoked after initialization is finished and before destruction.
50 void Uninitialize();
Guido Urdaneta 2017/05/22 14:26:38 Does the term Uninitialize come from existing code
hbos_chromium 2017/05/29 11:24:17 Done.
51
52 bool is_initialized() const;
53 const blink::WebMediaStreamTrack& web_track() const;
54 webrtc::MediaStreamTrackInterface* webrtc_track() const;
55 bool IsEqual(const blink::WebMediaStreamTrack& web_track) const;
56
57 // For testing.
58 WebRtcAudioSink* GetLocalAudioSinkForTesting() {
59 return local_audio_sink_.get();
60 }
61 MediaStreamVideoWebRtcSink* GetLocalVideoSinkForTesting() {
62 return local_video_sink_.get();
63 }
64 RemoteAudioTrackAdapter* GetRemoteAudioTrackAdapterForTesting() {
65 return remote_audio_track_adapter_.get();
66 }
67 RemoteVideoTrackAdapter* GetRemoteVideoTrackAdapterForTesting() {
68 return remote_video_track_adapter_.get();
69 }
70
71 protected:
72 friend class base::RefCountedThreadSafe<WebRtcMediaStreamTrackAdapter>;
73
74 WebRtcMediaStreamTrackAdapter(
75 PeerConnectionDependencyFactory* factory,
76 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread);
77 virtual ~WebRtcMediaStreamTrackAdapter();
78
79 private:
80 // Initialization of local tracks occurs on the main thread.
81 void InitializeLocalAudioTrack(const blink::WebMediaStreamTrack& web_track);
82 void InitializeLocalVideoTrack(const blink::WebMediaStreamTrack& web_track);
83 // Initialization of remote tracks starts on the webrtc signaling thread and
84 // finishes on the main thread.
85 void InitializeRemoteAudioTrack(
86 webrtc::AudioTrackInterface* webrtc_audio_track);
87 void InitializeRemoteVideoTrack(
88 webrtc::VideoTrackInterface* webrtc_video_track);
89 void FinalizeRemoteTrackInitializationOnMainThread();
90
91 // Uninitialization of local tracks occurs on the main thread.
92 void UninitializeLocalAudioTrack();
93 void UninitializeLocalVideoTrack();
94 // Uninitialization of remote tracks starts on the main thread and finishes on
95 // the webrtc signaling thread.
hbos_chromium 2017/05/18 11:46:04 Oops, need to update this comment, it starts and f
Guido Urdaneta 2017/05/22 14:26:38 Perhaps you should just remove the comment. The co
hbos_chromium 2017/05/29 11:24:17 Comment updated. I'd like to document this even th
Guido Urdaneta 2017/05/30 08:45:35 Acknowledged.
96 void UninitializeRemoteAudioTrack();
97 void UninitializeRemoteVideoTrack();
98 void UnregisterRemoteAudioTrackAdapterOnSignalingThread();
99 void FinalizeRemoteTrackUninitalizationOnMainThread();
100
101 // Pointer to a |PeerConnectionDependencyFactory| owned by the |RenderThread|.
102 // It's valid for the lifetime of |RenderThread|.
103 PeerConnectionDependencyFactory* const factory_;
104 scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
105
106 // This class is "const" between being initialized (triggered by |Create...|)
107 // and being uninitialized (by calling |Uninitialize|). As such, no locks are
108 // required in the implementation for only inherently racey actions could
109 // cause problems (such as uninitializing while still in use).
110 bool is_initialized_;
111 blink::WebMediaStreamTrack web_track_;
112 scoped_refptr<webrtc::MediaStreamTrackInterface> webrtc_track_;
113 // If |track_| is local, a sink is added to the local webrtc track that is
114 // owned by us.
115 std::unique_ptr<WebRtcAudioSink> local_audio_sink_;
Guido Urdaneta 2017/05/22 14:26:38 It seems to me that what is local about this sink
hbos_chromium 2017/05/29 11:24:17 Done.
116 std::unique_ptr<MediaStreamVideoWebRtcSink> local_video_sink_;
117 // If |track_| is remote, an adapter is used that listens to notifications on
118 // the remote webrtc track and notifies WebKit.
119 scoped_refptr<RemoteAudioTrackAdapter> remote_audio_track_adapter_;
120 scoped_refptr<RemoteVideoTrackAdapter> remote_video_track_adapter_;
121
122 DISALLOW_COPY_AND_ASSIGN(WebRtcMediaStreamTrackAdapter);
123 };
124
125 } // namespace content
126
127 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_TRACK_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698