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

Unified Diff: content/renderer/media/webrtc/webrtc_media_stream_track_adapter_map.h

Issue 2887403003: WebRtcMediaStreamTrackMap added (Closed)
Patch Set: EXPECT_FALSE( instead of EXPECT_EQ(false fixing android compile error 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/webrtc/webrtc_media_stream_track_adapter_map.h
diff --git a/content/renderer/media/webrtc/webrtc_media_stream_track_adapter_map.h b/content/renderer/media/webrtc/webrtc_media_stream_track_adapter_map.h
new file mode 100644
index 0000000000000000000000000000000000000000..4b156ac8bc199c5111ec492a086ddb7e86512f7a
--- /dev/null
+++ b/content/renderer/media/webrtc/webrtc_media_stream_track_adapter_map.h
@@ -0,0 +1,90 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_TRACK_COLLECTION_H_
+#define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_TRACK_COLLECTION_H_
+
+#include <map>
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/single_thread_task_runner.h"
+#include "content/common/content_export.h"
+#include "content/renderer/media/webrtc/webrtc_media_stream_track_adapter.h"
+#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
+#include "third_party/webrtc/api/mediastreaminterface.h"
+
+namespace content {
+
+class PeerConnectionDependencyFactory;
+
+// A map and owner of |WebRtcMediaStreamTrackAdapter|s. It takes care of
+// creating, initializing and disposing track adapters independently of media
+// streams. The map should be used such that it contains track adapters for the
+// duration of the tracks' lifetime, ensuring a consistent mapping between the
+// blink and webrtc layer representations of tracks.
+//
+// This class is thread safe. Some methods are restricted to the main thread or
+// the webrtc signaling thread, the other methods can be invoked on any thread.
+class CONTENT_EXPORT WebRtcMediaStreamTrackAdapterMap
+ : public base::RefCountedThreadSafe<WebRtcMediaStreamTrackAdapterMap> {
+ public:
+ WebRtcMediaStreamTrackAdapterMap(
+ PeerConnectionDependencyFactory* const factory,
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_thread);
+
+ // Gets local track adapter by ID, or null if not found.
+ scoped_refptr<WebRtcMediaStreamTrackAdapter> GetLocalTrackAdapter(
+ const std::string& id) const;
+ // Invoke on the main thread. Returned adapters are guaranteed to be
+ // initialized, see |WebRtcMediaStreamTrackAdapter::is_initialized|.
+ scoped_refptr<WebRtcMediaStreamTrackAdapter> GetOrCreateLocalTrackAdapter(
+ const blink::WebMediaStreamTrack& web_track);
+ // Invoke on the main thread. Removes and disposes the local track adapter.
+ // Returns false if not found. There must not be any external references to
+ // 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
+ bool DisposeLocalTrackAdapter(const std::string& id);
+ size_t GetLocalTrackCount() const;
+
+ // Gets remote track adapter by ID, or null if not found.
+ scoped_refptr<WebRtcMediaStreamTrackAdapter> GetRemoteTrackAdapter(
+ const std::string& id) const;
+ // Invoke on the webrtc signaling thread. If this results in a new adapter it
+ // will become initialized in a post to the main thread, see
+ // |WebRtcMediaStreamTrackAdapter::is_initialized|.
+ scoped_refptr<WebRtcMediaStreamTrackAdapter> GetOrCreateRemoteTrackAdapter(
+ webrtc::MediaStreamTrackInterface* webrtc_track);
+ // Invoke on the main thread. Removes and disposes the remote track adapter.
+ // Returns false if not found. There must not be any external references to
+ // the track adapter when this is called.
+ bool DisposeRemoteTrackAdapter(const std::string& id);
+ size_t GetRemoteTrackCount() const;
+
+ // Invoke on the main thread. Clears the map and disposes all track adapters.
+ // There must not be any external references to any of the track adapters when
+ // this is called.
+ void DisposeAllTrackAdapters();
+
+ protected:
+ friend class base::RefCountedThreadSafe<WebRtcMediaStreamTrackAdapterMap>;
+
+ // Invoke on the main thread.
+ virtual ~WebRtcMediaStreamTrackAdapterMap();
+
+ private:
+ // Pointer to a |PeerConnectionDependencyFactory| owned by the |RenderThread|.
+ // It's valid for the lifetime of |RenderThread|.
+ PeerConnectionDependencyFactory* const factory_;
+ scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
+
+ mutable base::Lock lock_;
+ std::map<std::string, scoped_refptr<WebRtcMediaStreamTrackAdapter>>
+ local_tracks_;
+ std::map<std::string, scoped_refptr<WebRtcMediaStreamTrackAdapter>>
+ remote_tracks_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_TRACK_COLLECTION_H_

Powered by Google App Engine
This is Rietveld 408576698