Android-cuttlefish cvd tool
display_handler.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 <chrono>
20#include <memory>
21#include <mutex>
22#include <optional>
23#include <thread>
24
31
32namespace cuttlefish {
33class CompositionManager;
44 // must support move semantic
45 std::unique_ptr<VideoFrameBuffer> buf_;
46 std::unique_ptr<WebRtcScProcessedFrame> Clone() {
47 // copy internal buffer, not move
48 auto cloned_frame = std::make_unique<WebRtcScProcessedFrame>();
49 if (buf_) {
50 cloned_frame->buf_ = buf_->Clone();
51 }
52 return cloned_frame;
53 }
54};
55
56namespace webrtc_streaming {
57class Streamer;
58} // namespace webrtc_streaming
59
61 public:
66
69 ScreenshotHandler& screenshot_handler, ScreenConnector& screen_connector,
70 std::optional<std::unique_ptr<CompositionManager>> composition_manager);
72
73 [[noreturn]] void Loop();
74 // If std::nullopt, send last frame for all displays.
75 void SendLastFrame(std::optional<uint32_t> display_number);
76
77 void AddDisplayClient();
79
80 private:
81 struct BufferInfo {
82 std::chrono::system_clock::time_point last_sent_time_stamp;
83 std::shared_ptr<VideoFrameBuffer> buffer;
84 };
85 enum class RepeaterState {
86 RUNNING,
87 STOPPED,
88 };
90 void SendBuffers(std::map<uint32_t, std::shared_ptr<BufferInfo>> buffers);
92
93 std::optional<std::unique_ptr<CompositionManager>> composition_manager_;
94 std::map<uint32_t, std::shared_ptr<webrtc_streaming::VideoSink>>
99 std::map<uint32_t, std::shared_ptr<BufferInfo>> display_last_buffers_;
101 std::mutex send_mutex_;
102 std::thread frame_repeater_;
103 // Protected by repeater_state_mutex
105 // Protected by repeater_state_mutex
108 std::condition_variable repeater_state_condvar_;
109};
110} // namespace cuttlefish
Definition: display_handler.h:60
void SendLastFrame(std::optional< uint32_t > display_number)
Definition: display_handler.cpp:149
std::mutex last_buffers_mutex_
Definition: display_handler.h:100
std::optional< std::unique_ptr< CompositionManager > > composition_manager_
Definition: display_handler.h:93
void SendBuffers(std::map< uint32_t, std::shared_ptr< BufferInfo > > buffers)
Definition: display_handler.cpp:181
std::condition_variable repeater_state_condvar_
Definition: display_handler.h:108
int num_active_clients_
Definition: display_handler.h:106
RepeaterState repeater_state_
Definition: display_handler.h:104
void RemoveDisplayClient()
Definition: display_handler.cpp:277
void AddDisplayClient()
Definition: display_handler.cpp:270
void RepeatFramesPeriodically()
Definition: display_handler.cpp:204
webrtc_streaming::Streamer & streamer_
Definition: display_handler.h:96
void Loop()
Definition: display_handler.cpp:128
RepeaterState
Definition: display_handler.h:85
DisplayHandler(webrtc_streaming::Streamer &streamer, ScreenshotHandler &screenshot_handler, ScreenConnector &screen_connector, std::optional< std::unique_ptr< CompositionManager > > composition_manager)
Definition: display_handler.cpp:37
GenerateProcessedFrameCallback GetScreenConnectorCallback()
Definition: display_handler.cpp:98
std::map< uint32_t, std::shared_ptr< webrtc_streaming::VideoSink > > display_sinks_
Definition: display_handler.h:95
~DisplayHandler()
Definition: display_handler.cpp:88
std::mutex repeater_state_mutex_
Definition: display_handler.h:107
std::map< uint32_t, std::shared_ptr< BufferInfo > > display_last_buffers_
Definition: display_handler.h:99
std::thread frame_repeater_
Definition: display_handler.h:102
ScreenConnector::GenerateProcessedFrameCallback GenerateProcessedFrameCallback
Definition: display_handler.h:64
ScreenConnector & screen_connector_
Definition: display_handler.h:98
ScreenshotHandler & screenshot_handler_
Definition: display_handler.h:97
std::mutex send_mutex_
Definition: display_handler.h:101
Definition: screen_connector.h:45
std::function< void(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint8_t *, ProcessedFrameType &msg)> GenerateProcessedFrameCallback
Definition: screen_connector.h:95
Definition: screenshot_handler.h:32
Definition: alloc_driver.h:20
Definition: display_handler.h:81
std::shared_ptr< VideoFrameBuffer > buffer
Definition: display_handler.h:83
std::chrono::system_clock::time_point last_sent_time_stamp
Definition: display_handler.h:82
Definition: screen_connector_common.h:63
Definition: display_handler.h:43
std::unique_ptr< WebRtcScProcessedFrame > Clone()
Definition: display_handler.h:46
std::unique_ptr< VideoFrameBuffer > buf_
Definition: display_handler.h:45