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

Unified Diff: remoting/host/cast_extension_session.h

Issue 399253002: CastExtension Impl for Chromoting Host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes based on review Created 6 years, 4 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: remoting/host/cast_extension_session.h
diff --git a/remoting/host/cast_extension_session.h b/remoting/host/cast_extension_session.h
new file mode 100644
index 0000000000000000000000000000000000000000..c7ae1923551fa5b97554625ee4fb73b3a26d9bac
--- /dev/null
+++ b/remoting/host/cast_extension_session.h
@@ -0,0 +1,203 @@
+// Copyright 2014 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 REMOTING_HOST_CAST_EXTENSION_SESSION_H_
+#define REMOTING_HOST_CAST_EXTENSION_SESSION_H_
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread.h"
+#include "base/timer/timer.h"
+#include "base/values.h"
+#include "jingle/glue/thread_wrapper.h"
+#include "remoting/host/host_extension_session.h"
+#include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
+#include "third_party/webrtc/base/scoped_ref_ptr.h"
+#include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+class WaitableEvent;
+} // namespace base
+
+namespace net {
+class URLRequestContextGetter;
+} // namespace net
+
+namespace webrtc {
+class MediaStreamInterface;
+} // namespace webrtc
+
+namespace remoting {
+
+namespace protocol {
+class CursorShapeInfo;
+struct NetworkSettings;
+} // namespace protocol
+
+// A HostExtensionSession implementation that enables WebRTC support using
+// the PeerConnection native API.
+class CastExtensionSession : public HostExtensionSession,
+ public webrtc::PeerConnectionObserver,
+ public webrtc::ScreenCapturer::MouseShapeObserver {
+ public:
+ virtual ~CastExtensionSession();
+
+ // Creates and returns a CastExtensionSession object, after performing
+ // initialization steps on it. The caller must take ownership of the returned
+ // object.
+ static scoped_ptr<CastExtensionSession> Create(
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
+ const protocol::NetworkSettings& network_settings,
+ ClientSessionControl* client_session_control,
+ protocol::ClientStub* client_stub);
+
+ // Called by webrtc::CreateSessionDescriptionObserver implementation.
+ void OnCreateSessionDescription(webrtc::SessionDescriptionInterface* desc);
+ void OnCreateSessionDescriptionFailure(const std::string& error);
+
+ // HostExtensionSession interface.
+ virtual scoped_ptr<webrtc::ScreenCapturer> OnCreateVideoCapturer(
+ scoped_ptr<webrtc::ScreenCapturer> capturer) OVERRIDE;
+ virtual bool ModifiesVideoPipeline() const OVERRIDE;
+ virtual bool OnExtensionMessage(
+ ClientSessionControl* client_session_control,
+ protocol::ClientStub* client_stub,
+ const protocol::ExtensionMessage& message) OVERRIDE;
+
+ // webrtc::ScreenCapturer::MouseShapeObserver interface.
Wez 2014/08/12 22:15:01 Hmmm, you shouldn't be using MouseShapeObserver si
aiguha 2014/08/13 18:33:28 Removed for now as suggested in .cc.
+ virtual void OnCursorShapeChanged(
+ webrtc::MouseCursorShape* cursor_shape) OVERRIDE;
+
+ // webrtc::PeerConnectionObserver interface.
+ virtual void OnError() OVERRIDE;
+ virtual void OnSignalingChange(
+ webrtc::PeerConnectionInterface::SignalingState new_state) OVERRIDE;
+ virtual void OnStateChange(
+ webrtc::PeerConnectionObserver::StateType state_changed) OVERRIDE;
+ virtual void OnAddStream(webrtc::MediaStreamInterface* stream) OVERRIDE;
+ virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream) OVERRIDE;
+ virtual void OnDataChannel(
+ webrtc::DataChannelInterface* data_channel) OVERRIDE;
+ virtual void OnRenegotiationNeeded() OVERRIDE;
+ virtual void OnIceConnectionChange(
+ webrtc::PeerConnectionInterface::IceConnectionState new_state) OVERRIDE;
+ virtual void OnIceGatheringChange(
+ webrtc::PeerConnectionInterface::IceGatheringState new_state) OVERRIDE;
+ virtual void OnIceCandidate(
+ const webrtc::IceCandidateInterface* candidate) OVERRIDE;
+ virtual void OnIceComplete() OVERRIDE;
+
+ private:
+ CastExtensionSession(
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
+ const protocol::NetworkSettings& network_settings,
+ ClientSessionControl* client_session_control,
+ protocol::ClientStub* client_stub);
+
+ // Parses |message| for a Session Description and sets the remote
+ // description, returning true if successful.
+ bool ParseAndSetRemoteDescription(base::DictionaryValue* message);
+
+ // Parses |message| for a PeerConnection ICE candidate and adds it to the
+ // Peer Connection, returning true if successful.
+ bool ParseAndAddICECandidate(base::DictionaryValue* message);
+
+ // Sends a message to the client through |client_stub_|. This method must be
+ // called on the network thread.
+ bool SendMessageToClient(const std::string& subject, const std::string& data);
+
+ // Sends the new |cursor_shape| using the ClientStub through
+ // |client_session_|. This method must be called on the network thread.
+ void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape);
+
+ // Creates the jingle wrapper for the current thread, sets send to allowed,
+ // and saves a pointer to the relevant thread pointer in ptr. If |event|
+ // is not NULL, signals the event on completion.
+ void EnsureTaskAndSetSend(rtc::Thread** ptr,
+ base::WaitableEvent* event = NULL);
+
+ // Wraps each task runner in JingleThreadWrapper using EnsureTaskAndSetSend(),
+ // returning true if successful. Wrapping the task runners allows them to be
+ // shared with and used by the (about to be created) PeerConnectionFactory.
+ bool WrapTasksAndSave();
+
+ // Initializes PeerConnectionFactory and PeerConnection and sends a "ready"
+ // message to client. Returns true if these steps are performed successfully.
+ bool InitializePeerConnection();
+
+ // Constructs a CastVideoCapturerAdapter, a VideoSource, a VideoTrack and a
+ // MediaStream |stream_|, which it adds to the |peer_connection_|. Returns
+ // true if these steps are performed successfully. This method is called only
+ // when a PeerConnection offer is received from the client.
+ bool SetupVideoStream(scoped_ptr<webrtc::ScreenCapturer> screen_capturer);
+
+ // Polls a single stats report from the PeerConnection immediately. Called
+ // periodically using |stats_polling_timer_| after a PeerConnection has been
+ // established.
+ void PollPeerConnectionStats();
+
+ // Explicitly sets |peer_conn_factory_|, |peer_connection_| and |stream_| to
+ // NULL.
Wez 2014/08/12 22:15:01 Rather than "sets to nULL", suggest "releases |pee
aiguha 2014/08/13 18:33:28 Done.
+ void CleanupPeerConnection();
+
+ // Check if the connection is active.
+ bool connection_active() const;
+
+ // TaskRunners that will be used to setup the PeerConnectionFactory's
+ // signalling thread and worker thread respectively.
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
+ scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
+
+ // Objects related to the WebRTC PeerConnection.
+ rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
+ rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_conn_factory_;
+ rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_;
+
+ // Parameters passed to ChromiumPortAllocatorFactory on creation.
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
+ const protocol::NetworkSettings& network_settings_;
+
+ // Interface to interact with ClientSession.
+ ClientSessionControl* client_session_control_;
+
+ // Interface through which messages can be sent to the client.
+ protocol::ClientStub* client_stub_;
+
+ // Used to track webrtc connection statistics.
+ rtc::scoped_refptr<webrtc::StatsObserver> stats_observer_;
+
+ // Used to repeatedly poll stats from the |peer_connection_|.
+ base::RepeatingTimer<CastExtensionSession> stats_polling_timer_;
+
+ // True if a PeerConnection offer from the client has been received. This
+ // necessarily means that the host is not the caller in this attempted
+ // peer connection.
+ bool received_offer_;
+
+ // True if the webrtc::ScreenCapturer has been grabbed through the
+ // OnCreateVideoCapturer() callback.
+ bool has_grabbed_capturer_;
+
+ // PeerConnection signaling and worker threads created from
+ // JingleThreadWrappers. Each is created by calling
+ // jingle_glue::EnsureForCurrentMessageLoop() and thus deletes itself
+ // automatically when the associated MessageLoop is destroyed.
+ rtc::Thread* network_thread_wrapper_;
+ rtc::Thread* worker_thread_wrapper_;
+
+ // Worker thread that is wrapped to create |worker_thread_wrapper_|.
+ base::Thread worker_thread_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastExtensionSession);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_CAST_EXTENSION_SESSION_H_
+

Powered by Google App Engine
This is Rietveld 408576698