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 <stdint.h>
20
24
25namespace cuttlefish {
26template <typename ProcessedFrameType>
30
31 public:
33 : host_mode_ctrl_(host_mode_ctrl) {
38 }
39
41
42 void PushToAndroidQueue(ProcessedFrameType&& t) {
44 }
45
46 void PushToConfUiQueue(ProcessedFrameType&& t) {
48 }
49
50 // customize Pop()
51 ProcessedFrameType Pop() {
53
54 // is_discard_frame is thread-specific
55 bool is_discard_frame = false;
56
57 // callback to select the queue index, and update is_discard_frame
58 auto selector = [this, &is_discard_frame]() -> int {
60 ConfUiLogVerbose << "Streamer gets Conf UI frame with host ctrl mode = "
61 << static_cast<uint32_t>(host_mode_ctrl_.GetMode())
62 << " and cnd = #" << on_next_frame_cnt_;
64 }
65 auto mode = host_mode_ctrl_.GetMode();
67 // AndroidFrameFetchingLoop could have added 1 or 2 frames
68 // before it becomes Conf UI mode.
70 << "Streamer ignores Android frame with host ctrl mode ="
71 << static_cast<uint32_t>(mode) << "and cnd = #"
73 is_discard_frame = true;
74 }
75 ConfUiLogVerbose << "Streamer gets Android frame with host ctrl mode ="
76 << static_cast<uint32_t>(mode) << "and cnd = #"
79 };
80
81 while (true) {
82 ConfUiLogVerbose << "Streamer waiting Semaphore with host ctrl mode ="
83 << static_cast<uint32_t>(host_mode_ctrl_.GetMode())
84 << " and cnd = #" << on_next_frame_cnt_;
85 auto processed_frame = multiplexer_.Pop(selector);
86 if (!is_discard_frame) {
87 return processed_frame;
88 }
89 is_discard_frame = false;
90 }
91 }
92
93 private:
96 unsigned long long int on_next_frame_cnt_;
99};
100} // end of namespace cuttlefish
Definition: host_mode_ctrl.h:39
auto GetMode()
Definition: host_mode_ctrl.h:98
static QueuePtr CreateQueue(Args &&... args)
Definition: multiplexer.h:35
T Pop(QueueSelector selector)
Definition: multiplexer.h:54
int RegisterQueue(QueuePtr &&queue)
Definition: multiplexer.h:42
void Push(const int idx, T &&t)
Definition: multiplexer.h:48
bool IsEmpty(const int idx)
Definition: multiplexer.h:75
Definition: screen_connector_multiplexer.h:27
int sc_confui_queue_id_
Definition: screen_connector_multiplexer.h:98
int sc_android_queue_id_
Definition: screen_connector_multiplexer.h:97
Multiplexer< ProcessedFrameType, Queue > Multiplexer
Definition: screen_connector_multiplexer.h:29
unsigned long long int on_next_frame_cnt_
Definition: screen_connector_multiplexer.h:96
ScreenConnectorInputMultiplexer(HostModeCtrl &host_mode_ctrl)
Definition: screen_connector_multiplexer.h:32
ProcessedFrameType Pop()
Definition: screen_connector_multiplexer.h:51
Multiplexer multiplexer_
Definition: screen_connector_multiplexer.h:95
void PushToAndroidQueue(ProcessedFrameType &&t)
Definition: screen_connector_multiplexer.h:42
HostModeCtrl & host_mode_ctrl_
Definition: screen_connector_multiplexer.h:94
void PushToConfUiQueue(ProcessedFrameType &&t)
Definition: screen_connector_multiplexer.h:46
Definition: screen_connector_queue.h:31
#define ConfUiLogVerbose
Definition: utils.h:62
Definition: alloc_driver.h:20