Android-cuttlefish cvd tool
display_server_frame_source.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 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
21#include <map>
22#include <memory>
23#include <mutex>
24#include <optional>
25#include <string>
26#include <thread>
27
34
36
37// A FrameSource that receives frames from a running cvd_display_server.
39 public:
41 const std::string& socket_path);
43
44 void SetFrameCallback(FrameCallback callback) override;
45 void SetDisplayEventCallback(DisplayEventCallback callback) override;
46
47 private:
49 uint32_t width = 0;
50 uint32_t height = 0;
51 size_t slot_size = 0;
54 std::optional<uint32_t> last_slot;
55 };
56
57 struct Frame {
59 uint8_t* pixels;
60 };
61
62 DisplayServerFrameSource(SharedFD socket, SharedFD stop_event);
63 void ReceiveLoop();
64 Result<void> HandleMessage(const void* data, size_t size);
65 void OnDisplayCreated(const DisplayCreatedMsg& msg);
68 Result<void> OnFrame(const FrameMsg& msg);
70 static Result<Frame> GetFrameFromShm(MappedDisplay& display, uint32_t slot);
71
75 std::mutex callback_mutex_;
78 std::map<uint32_t, MappedDisplay> displays_;
79 std::thread receive_thread_;
80};
81
82} // namespace cuttlefish::display_server
Definition: frame_source.h:24
Definition: scoped_mmap.h:28
Definition: shared_fd.h:125
Definition: display_server_frame_source.h:38
SharedFD socket_
Definition: display_server_frame_source.h:72
void SetFrameCallback(FrameCallback callback) override
Definition: display_server_frame_source.cpp:80
Result< void > OnFrame(const FrameMsg &msg)
Definition: display_server_frame_source.cpp:295
DisplayEventCallback display_event_callback_
Definition: display_server_frame_source.h:77
std::map< uint32_t, MappedDisplay > displays_
Definition: display_server_frame_source.h:78
SharedFD stop_event_
Definition: display_server_frame_source.h:73
DisplayServerFrameSource(SharedFD socket, SharedFD stop_event)
Definition: display_server_frame_source.cpp:64
void OnDisplayCreated(const DisplayCreatedMsg &msg)
Definition: display_server_frame_source.cpp:251
void ReceiveLoop()
Definition: display_server_frame_source.cpp:179
std::thread receive_thread_
Definition: display_server_frame_source.h:79
Result< void > AttachShm(const DisplayShmMsg &msg)
Definition: display_server_frame_source.cpp:128
FrameCallback frame_callback_
Definition: display_server_frame_source.h:76
void OnDisplayDestroyed(const DisplayDestroyedMsg &msg)
Definition: display_server_frame_source.cpp:269
Result< void > OnDisplayShm(const DisplayShmMsg &msg)
Definition: display_server_frame_source.cpp:283
Result< void > HandleMessage(const void *data, size_t size)
Definition: display_server_frame_source.cpp:223
std::mutex frame_delivery_mutex_
Definition: display_server_frame_source.h:74
static Result< std::unique_ptr< DisplayServerFrameSource > > Create(const std::string &socket_path)
Definition: display_server_frame_source.cpp:51
std::mutex callback_mutex_
Definition: display_server_frame_source.h:75
~DisplayServerFrameSource() override
Definition: display_server_frame_source.cpp:70
static Result< Frame > GetFrameFromShm(MappedDisplay &display, uint32_t slot)
Definition: display_server_frame_source.cpp:168
void SetDisplayEventCallback(DisplayEventCallback callback) override
Definition: display_server_frame_source.cpp:105
uint32_t size
Definition: io.h:2
char data[Size]
Definition: incremental_server.cpp:1
Definition: display_server_frame_source.cpp:48
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30
Definition: display_server_frame_source.h:57
FrameInfo info
Definition: display_server_frame_source.h:58
uint8_t * pixels
Definition: display_server_frame_source.h:59
uint32_t width
Definition: display_server_frame_source.h:49
size_t slot_size
Definition: display_server_frame_source.h:51
uint32_t height
Definition: display_server_frame_source.h:50
FrameInfo frame_info
Definition: display_server_frame_source.h:52
std::optional< uint32_t > last_slot
Definition: display_server_frame_source.h:54
ScopedMMap shm
Definition: display_server_frame_source.h:53
Definition: protocol.h:32
Definition: protocol.h:81
std::function< void(const DisplayEvent &)> DisplayEventCallback
Definition: wayland_server_callbacks.h:35
std::function< void(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint8_t *)> FrameCallback
Definition: wayland_server_callbacks.h:43