/* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include "common/libs/utils/result.h" #include "host/frontend/webrtc/libcommon/connection_controller.h" #include "host/frontend/webrtc/libdevice/data_channels.h" #include "host/frontend/webrtc/libdevice/connection_observer.h" namespace cuttlefish { namespace webrtc_streaming { class InputChannelHandler; class AdbChannelHandler; class ControlChannelHandler; class BluetoothChannelHandler; class CameraChannelHandler; class SensorsChannelHandler; class LocationChannelHandler; class KmlLocationsChannelHandler; class GpxLocationsChannelHandler; class ClientVideoTrackInterface; class ClientVideoTrackImpl; class PeerConnectionBuilder; class ClientHandler : public ConnectionController::Observer, public PeerConnectionBuilder, public PeerSignalingHandler { public: static std::shared_ptr Create( int client_id, std::shared_ptr observer, PeerConnectionBuilder& connection_builder, std::function send_client_cb, std::function on_connection_changed_cb); ~ClientHandler() override = default; bool AddDisplay(rtc::scoped_refptr track, const std::string& label); bool RemoveDisplay(const std::string& label); bool AddAudio(rtc::scoped_refptr track, const std::string& label); ClientVideoTrackInterface* GetCameraStream(); void HandleMessage(const Json::Value& client_message); // ConnectionController::Observer implementation void OnConnectionStateChange( Result status) override; void OnDataChannel( rtc::scoped_refptr data_channel) override; void OnTrack( rtc::scoped_refptr transceiver) override; void OnRemoveTrack( rtc::scoped_refptr receiver) override; // PeerSignalingHandling implementation Result SendMessage(const Json::Value& msg) override; // PeerConnectionBuilder implementation // Delegates on its own pc builder to create the pc and then adds the displays // and other streams as required. Result> Build( webrtc::PeerConnectionObserver& observer, const std::vector& per_connection_servers) override; private: ClientHandler(int client_id, std::shared_ptr observer, PeerConnectionBuilder& connection_builder, std::function send_client_cb, std::function on_connection_changed_cb); // Intentionally private, disconnect the client by destroying the object. void Close(); void LogAndReplyError(const std::string& error_msg) const; rtc::scoped_refptr AddTrackToConnection( rtc::scoped_refptr track, rtc::scoped_refptr peer_connection, const std::string& label); int client_id_; std::shared_ptr observer_; std::function send_to_client_; std::function on_connection_changed_cb_; PeerConnectionBuilder& connection_builder_; ConnectionController controller_; DataChannelHandlers data_channels_handler_; std::unique_ptr camera_track_; struct DisplayTrackAndSender { rtc::scoped_refptr track; rtc::scoped_refptr sender; }; std::map displays_; std::vector< std::pair, std::string>> audio_streams_; }; class ClientVideoTrackInterface { public: virtual ~ClientVideoTrackInterface() = default; virtual void AddOrUpdateSink( rtc::VideoSinkInterface* sink, const rtc::VideoSinkWants& wants) = 0; }; } // namespace webrtc_streaming } // namespace cuttlefish