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

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: Minor fix Created 6 years, 5 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..7a7e64bb5c41bf3860cd3c43bcfcd6cc93e802c8
--- /dev/null
+++ b/remoting/host/cast_extension_session.h
@@ -0,0 +1,179 @@
+// 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/bind.h"
+#include "base/memory/ref_counted.h"
+#include "base/timer/timer.h"
+#include "base/values.h"
+#include "jingle/glue/thread_wrapper.h"
+#include "remoting/host/host_extension_session.h"
+#include "remoting/protocol/client_stub.h"
+#include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
+#include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
+#include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h"
+#include "third_party/libjingle/source/talk/media/base/videocapturer.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 remoting {
+
+namespace protocol {
+struct NetworkSettings;
+} // namespace protocol
+
+// A class that extends HostExtensionSession to enable WebRTC support using
+// the PeerConnection native APIs.
+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 CastExtensionSession* Create(
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner,
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
+ const protocol::NetworkSettings& network_settings,
+ ClientSession* client_session);
+
+ // HostExtensionSession implementation.
+ virtual bool OnExtensionMessage(
+ ClientSession* client_session,
+ const protocol::ExtensionMessage& message) OVERRIDE;
+
+ // PeerConnectionObserver implementation.
+ 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;
+
+ // MouseShapeObserver implementation.
+ virtual void OnCursorShapeChanged(
+ webrtc::MouseCursorShape* cursor_shape) OVERRIDE;
+
+ // Called by webrtc::CreateSessionDescriptionObserver implementation.
+ void OnSuccess(webrtc::SessionDescriptionInterface* desc);
+ void OnFailure(const std::string& error);
+
+ private:
+ CastExtensionSession(
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner,
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
+ const protocol::NetworkSettings& network_settings,
+ ClientSession* client_session);
+
+ // Sends messages to client using the ClientStub through |client_session_|.
+ // |data| should be json formatted. This method must be called on the
+ // network thread.
+ bool SendMessageToClient(const char* subject, const std::string& data);
+
+ // Sends the new |cursor_shape| using the ClientStub through
+ // |client_session_|.
+ 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(talk_base::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();
+
+ // Requests a ScreenCapturer from |client_session_|, sets |this| as the
+ // MouseShapeObserver, constructs a VideoSource, a VideoTrack and a
+ // MediaStream |stream_|, which it adds to the |peer_connection_|. It returns
+ // true if these steps are performed successfully. This method is called when
+ // only when a PeerConnection offer is received from the client.
+ bool InitializeAndAddMediaStream();
+
+ // 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.
+ void DeletePeerConnection();
+
+ // Check if the connection is active.
+ bool connection_active() const;
+
+ // TaskRunners that will be used to setup the PeerConnectionFactory's
+ // signalling and worker threads.
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
+ scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
+
+ // Objects related to the WebRTC PeerConnection.
+ talk_base::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
+ peer_conn_factory_;
+ talk_base::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
+ talk_base::scoped_refptr<webrtc::MediaStreamInterface> stream_;
+
+ // Jingle Thread wrappers for talk_base::Thread, to be used with
+ // PeerConnection API as well as the VideoScheduler for networking.
+ // Created by calling jingle_glue::EnsureForCurrentMessageLoop() and thus
+ // deletes itself automatically when the associated MessageLoop is destroyed.
+ talk_base::Thread* network_thread_wrapper_;
+
+ // Jingle Thread wrappers for talk_base::Thread, to be used with
+ // PeerConnection API as well as the VideoScheduler for capturing/as worker.
+ // Deletion of this object is handled same as above.
+ talk_base::Thread* capture_thread_wrapper_;
+
+ // Parameters passed to ChromiumPortAllocatorFactory on creation.
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
+ const protocol::NetworkSettings& network_settings_;
+
+ // Client Session that owns this CastExtensionSession.
+ ClientSession* client_session_;
+
+ // Used to track webrtc connection statistics.
+ talk_base::scoped_refptr<webrtc::StatsObserver> stats_observer_;
+
+ // Used to repeatedly poll stats from the |peer_connection_|.
+ base::RepeatingTimer<CastExtensionSession> stats_polling_timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastExtensionSession);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_CAST_EXTENSION_SESSION_H_
+

Powered by Google App Engine
This is Rietveld 408576698