Android-cuttlefish cvd tool
screen_connector_multiplexer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 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 <cstdint>
20
23
26
27namespace cuttlefish {
28template <typename ProcessedFrameType>
32
33 public:
35 : host_mode_ctrl_(host_mode_ctrl) {
40 }
41
43
44 void PushToAndroidQueue(ProcessedFrameType&& t) {
46 }
47
48 void PushToConfUiQueue(ProcessedFrameType&& t) {
50 }
51
52 // customize Pop()
53 ProcessedFrameType Pop() {
55
56 // is_discard_frame is thread-specific
57 bool is_discard_frame = false;
58
59 // callback to select the queue index, and update is_discard_frame
60 auto selector = [this, &is_discard_frame]() -> int {
63 << "Streamer gets Conf UI frame with host ctrl mode = "
64 << static_cast<std::uint32_t>(host_mode_ctrl_.GetMode())
65 << " and cnd = #" << on_next_frame_cnt_;
67 }
68 auto mode = host_mode_ctrl_.GetMode();
70 // AndroidFrameFetchingLoop could have added 1 or 2 frames
71 // before it becomes Conf UI mode.
73 << "Streamer ignores Android frame with host ctrl mode ="
74 << static_cast<std::uint32_t>(mode) << "and cnd = #"
76 is_discard_frame = true;
77 }
78 ConfUiLog(VERBOSE) << "Streamer gets Android frame with host ctrl mode ="
79 << static_cast<std::uint32_t>(mode) << "and cnd = #"
82 };
83
84 while (true) {
85 ConfUiLog(VERBOSE) << "Streamer waiting Semaphore with host ctrl mode ="
86 << static_cast<std::uint32_t>(
88 << " and cnd = #" << on_next_frame_cnt_;
89 auto processed_frame = multiplexer_.Pop(selector);
90 if (!is_discard_frame) {
91 return processed_frame;
92 }
93 is_discard_frame = false;
94 }
95 }
96
97 private:
100 unsigned long long int on_next_frame_cnt_;
103};
104} // end of namespace cuttlefish
Definition: host_mode_ctrl.h:38
auto GetMode()
Definition: host_mode_ctrl.h:97
static QueuePtr CreateQueue(Args &&... args)
Definition: multiplexer.h:33
T Pop(QueueSelector selector)
Definition: multiplexer.h:52
int RegisterQueue(QueuePtr &&queue)
Definition: multiplexer.h:40
void Push(const int idx, T &&t)
Definition: multiplexer.h:46
bool IsEmpty(const int idx)
Definition: multiplexer.h:73
Definition: screen_connector_multiplexer.h:29
int sc_confui_queue_id_
Definition: screen_connector_multiplexer.h:102
int sc_android_queue_id_
Definition: screen_connector_multiplexer.h:101
Multiplexer< ProcessedFrameType, Queue > Multiplexer
Definition: screen_connector_multiplexer.h:31
unsigned long long int on_next_frame_cnt_
Definition: screen_connector_multiplexer.h:100
ScreenConnectorInputMultiplexer(HostModeCtrl &host_mode_ctrl)
Definition: screen_connector_multiplexer.h:34
ProcessedFrameType Pop()
Definition: screen_connector_multiplexer.h:53
Multiplexer multiplexer_
Definition: screen_connector_multiplexer.h:99
void PushToAndroidQueue(ProcessedFrameType &&t)
Definition: screen_connector_multiplexer.h:44
HostModeCtrl & host_mode_ctrl_
Definition: screen_connector_multiplexer.h:98
void PushToConfUiQueue(ProcessedFrameType &&t)
Definition: screen_connector_multiplexer.h:48
Definition: screen_connector_queue.h:31
#define ConfUiLog(LOG_LEVEL)
Definition: utils.h:61
@ VERBOSE
Definition: logging.h:88
Definition: alloc_utils.cpp:23