OLD | NEW |
---|---|
(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_COLLECTION_H_ | |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_TRACK_COLLECTION_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/single_thread_task_runner.h" | |
13 #include "content/common/content_export.h" | |
14 #include "content/renderer/media/webrtc/webrtc_media_stream_track_adapter.h" | |
15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
16 #include "third_party/webrtc/api/mediastreaminterface.h" | |
17 | |
18 namespace content { | |
19 | |
20 class PeerConnectionDependencyFactory; | |
21 | |
22 // A map and owner of |WebRtcMediaStreamTrackAdapter|s. It takes care of | |
23 // creating, initializing and disposing track adapters independently of media | |
24 // streams. The map should be used such that it contains track adapters for the | |
25 // duration of the tracks' lifetime, ensuring a consistent mapping between the | |
26 // blink and webrtc layer representations of tracks. | |
27 // | |
28 // This class is thread safe. Some methods are restricted to the main thread or | |
29 // the webrtc signaling thread, the other methods can be invoked on any thread. | |
30 class CONTENT_EXPORT WebRtcMediaStreamTrackAdapterMap | |
31 : public base::RefCountedThreadSafe<WebRtcMediaStreamTrackAdapterMap> { | |
32 public: | |
33 WebRtcMediaStreamTrackAdapterMap( | |
34 PeerConnectionDependencyFactory* const factory, | |
35 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread); | |
36 | |
37 // Gets local track adapter by ID, or null if not found. | |
38 scoped_refptr<WebRtcMediaStreamTrackAdapter> GetLocalTrackAdapter( | |
39 const std::string& id) const; | |
40 // Invoke on the main thread. Returned adapters are guaranteed to be | |
41 // initialized, see |WebRtcMediaStreamTrackAdapter::is_initialized|. | |
42 scoped_refptr<WebRtcMediaStreamTrackAdapter> GetOrCreateLocalTrackAdapter( | |
43 const blink::WebMediaStreamTrack& web_track); | |
44 // Invoke on the main thread. Removes and disposes the local track adapter. | |
45 // Returns false if not found. There must not be any external references to | |
46 // the track adapter when this is called. | |
Guido Urdaneta
2017/05/30 09:02:41
Is the latter precondition something easy to achie
hbos_chromium
2017/06/02 08:52:19
Based on offline discussions, I made an AdapterRef
| |
47 bool DisposeLocalTrackAdapter(const std::string& id); | |
48 size_t GetLocalTrackCount() const; | |
49 | |
50 // Gets remote track adapter by ID, or null if not found. | |
51 scoped_refptr<WebRtcMediaStreamTrackAdapter> GetRemoteTrackAdapter( | |
52 const std::string& id) const; | |
53 // Invoke on the webrtc signaling thread. If this results in a new adapter it | |
54 // will become initialized in a post to the main thread, see | |
55 // |WebRtcMediaStreamTrackAdapter::is_initialized|. | |
56 scoped_refptr<WebRtcMediaStreamTrackAdapter> GetOrCreateRemoteTrackAdapter( | |
57 webrtc::MediaStreamTrackInterface* webrtc_track); | |
58 // Invoke on the main thread. Removes and disposes the remote track adapter. | |
59 // Returns false if not found. There must not be any external references to | |
60 // the track adapter when this is called. | |
61 bool DisposeRemoteTrackAdapter(const std::string& id); | |
62 size_t GetRemoteTrackCount() const; | |
63 | |
64 // Invoke on the main thread. Clears the map and disposes all track adapters. | |
65 // There must not be any external references to any of the track adapters when | |
66 // this is called. | |
67 void DisposeAllTrackAdapters(); | |
68 | |
69 protected: | |
70 friend class base::RefCountedThreadSafe<WebRtcMediaStreamTrackAdapterMap>; | |
71 | |
72 // Invoke on the main thread. | |
73 virtual ~WebRtcMediaStreamTrackAdapterMap(); | |
74 | |
75 private: | |
76 // Pointer to a |PeerConnectionDependencyFactory| owned by the |RenderThread|. | |
77 // It's valid for the lifetime of |RenderThread|. | |
78 PeerConnectionDependencyFactory* const factory_; | |
79 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | |
80 | |
81 mutable base::Lock lock_; | |
82 std::map<std::string, scoped_refptr<WebRtcMediaStreamTrackAdapter>> | |
83 local_tracks_; | |
84 std::map<std::string, scoped_refptr<WebRtcMediaStreamTrackAdapter>> | |
85 remote_tracks_; | |
86 }; | |
87 | |
88 } // namespace content | |
89 | |
90 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_TRACK_COLLECTION_H_ | |
OLD | NEW |