Android-cuttlefish cvd tool
streamer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <memory>
20#include <string>
21#include <utility>
22#include <vector>
23
25
32
33namespace cuttlefish {
34namespace webrtc_streaming {
35
36class ClientHandler;
37
39 // The id with which to register with the operator server.
40 std::string device_id;
41
42 // The port on which the client files are being served
44 std::string operator_path;
45 // The port ranges webrtc is allowed to use.
46 // [0,0] means all ports
47 std::pair<uint16_t, uint16_t> udp_port_range = {15550, 15599};
48 std::pair<uint16_t, uint16_t> tcp_port_range = {15550, 15599};
49 // WebRTC device id obtaining openwrt instance.
50 std::string openwrt_device_id;
51 // Openwrt IP address for accessing Luci interface.
52 std::string openwrt_addr;
53 // Adb port number of the device.
55 // Path of ControlEnvProxyServer for serving Rest API in WebUI.
57 // Whether mouse is enabled.
59 // Whether gamepad is enabled.
61};
62
64 public:
65 virtual ~OperatorObserver() = default;
66 // Called when the websocket connection with the operator is established.
67 virtual void OnRegistered() = 0;
68 // Called when the websocket connection with the operator is closed.
69 virtual void OnClose() = 0;
70 // Called when an error is encountered in the connection to the operator.
71 virtual void OnError() = 0;
72};
73
74class Streamer {
75 public:
76 // The observer_factory will be used to create an observer for every new
77 // client connection. Unregister() needs to be called to stop accepting
78 // connections.
79 static std::unique_ptr<Streamer> Create(
80 const StreamerConfig& cfg, RecordingManager& recording_manager,
81 std::shared_ptr<ConnectionObserverFactory> factory);
82 ~Streamer() = default;
83
84 std::shared_ptr<VideoSink> AddDisplay(const std::string& label, int width,
85 int height, int dpi,
86 bool touch_enabled);
87 bool RemoveDisplay(const std::string& label);
88
89 bool AddTouchpad(const std::string& label, int width, int height);
90
91 void SetHardwareSpec(std::string key, std::string value);
92
93 template <typename V>
94 void SetHardwareSpec(std::string key, V value) {
96 }
97
98 std::shared_ptr<AudioSink> AddAudioStream(const std::string& label);
99 // Grants access to streams originating on the client side. If there are
100 // multiple streams (either because one client sends more than one or there
101 // are several clients) the audio will be mixed and provided as a single
102 // stream here.
103 std::shared_ptr<AudioSource> GetAudioSource();
104
105 CameraController* AddCamera(unsigned int port, unsigned int cid,
106 bool vhost_user);
107
108 // Add a custom button to the control panel.
109 void AddCustomControlPanelButton(const std::string& command,
110 const std::string& title,
111 const std::string& icon_name);
113 const std::string& command, const std::string& title,
114 const std::string& icon_name, const std::string& shell_command);
116 const std::string& command, const std::string& title,
117 const std::string& icon_name,
118 const std::vector<DeviceState>& device_states);
119
120 // Register with the operator.
121 void Register(std::weak_ptr<OperatorObserver> operator_observer);
122 void Unregister();
123
124 private:
125 /*
126 * Private Implementation idiom.
127 * https://en.cppreference.com/w/cpp/language/pimpl
128 */
129 class Impl;
130
131 Streamer(std::unique_ptr<Impl> impl);
132 std::shared_ptr<Impl> impl_;
133};
134
135} // namespace webrtc_streaming
136} // namespace cuttlefish
137
std::string to_string(ConnectionState state)
Definition: adb.cpp:144
Definition: camera_controller.h:24
Definition: recording_manager.h:41
Streamer(std::unique_ptr< Impl > impl)
Definition: streamer.cpp:192
bool RemoveDisplay(const std::string &label)
Definition: streamer.cpp:282
void Unregister()
Definition: streamer.cpp:381
void SetHardwareSpec(std::string key, std::string value)
Definition: streamer.cpp:341
CameraController * AddCamera(unsigned int port, unsigned int cid, bool vhost_user)
Definition: streamer.cpp:334
void SetHardwareSpec(std::string key, V value)
Definition: streamer.h:94
bool AddTouchpad(const std::string &label, int width, int height)
Definition: streamer.cpp:299
std::shared_ptr< VideoSink > AddDisplay(const std::string &label, int width, int height, int dpi, bool touch_enabled)
Definition: streamer.cpp:244
void AddCustomControlPanelButtonWithShellCommand(const std::string &command, const std::string &title, const std::string &icon_name, const std::string &shell_command)
Definition: streamer.cpp:353
static std::unique_ptr< Streamer > Create(const StreamerConfig &cfg, RecordingManager &recording_manager, std::shared_ptr< ConnectionObserverFactory > factory)
Definition: streamer.cpp:196
std::shared_ptr< Impl > impl_
Definition: streamer.h:132
std::shared_ptr< AudioSource > GetAudioSource()
Definition: streamer.cpp:330
std::shared_ptr< AudioSink > AddAudioStream(const std::string &label)
Definition: streamer.cpp:313
void AddCustomControlPanelButton(const std::string &command, const std::string &title, const std::string &icon_name)
Definition: streamer.cpp:345
void AddCustomControlPanelButtonWithDeviceStates(const std::string &command, const std::string &title, const std::string &icon_name, const std::vector< DeviceState > &device_states)
Definition: streamer.cpp:362
void Register(std::weak_ptr< OperatorObserver > operator_observer)
Definition: streamer.cpp:372
Definition: alloc_utils.cpp:23
std::string device_id
Definition: streamer.h:40
std::pair< uint16_t, uint16_t > udp_port_range
Definition: streamer.h:47
std::string operator_path
Definition: streamer.h:44
int client_files_port
Definition: streamer.h:43
bool enable_mouse
Definition: streamer.h:58
std::string openwrt_addr
Definition: streamer.h:52
std::string control_env_proxy_server_path
Definition: streamer.h:56
bool enable_gamepad
Definition: streamer.h:60
int adb_port
Definition: streamer.h:54
std::string openwrt_device_id
Definition: streamer.h:50
std::pair< uint16_t, uint16_t > tcp_port_range
Definition: streamer.h:48