103{
104 if (!window) {
106 return false;
107 }
108
111 if (!svc || !svc->register_frame_observer) {
112 set_error(
"record: DisplayService unavailable");
113 return false;
114 }
115
118
124
125 if (!window->is_capture_enabled()) {
126 window->set_capture_enabled(true);
128 }
129
130 auto handle = std::static_pointer_cast<void>(window);
131
132 uint32_t obs_id = svc->register_frame_observer(handle,
133 [this](const std::shared_ptr<std::vector<uint8_t>>& buf,
134 uint32_t w, uint32_t
h, uint32_t vk_fmt) {
135 if (!buf || buf->empty())
136 return;
137
139 const AVPixelFormat av_fmt = vk_format_to_avpixfmt(vk_fmt);
143 "[VideoFileWriter] record: failed to open encoder for "
144 "'{}': {}",
147 return;
148 }
149 }
150
151 if (!
m_open.load(std::memory_order_acquire))
152 return;
153
155 .pixels = std::vector<uint8_t>(buf->begin(), buf->end()),
156 .width = w,
158 });
159
160 if (obs_id == 0) {
161 set_error(
"record: register_frame_observer returned 0 — "
162 "capture not yet active for this window");
164 window->set_capture_enabled(false);
166 }
168 return false;
169 }
170
172
174 "[VideoFileWriter] record: observer {} registered for '{}' -> '{}'",
175 obs_id, window->get_create_info().title, filepath);
176
177 return true;
178}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
double m_capture_frame_rate
bool open(const std::string &filepath, uint32_t width, uint32_t height, double frame_rate, AVPixelFormat src_pixel_format, AVCodecID explicit_codec=AV_CODEC_ID_NONE)
bool post(const WorkItem &item)
std::future< bool > stop_recording()
std::atomic< uint32_t > m_observer_id
std::atomic< bool > m_capture_opened
std::shared_ptr< Core::Window > m_capture_window
void set_error(std::string msg)
std::atomic< bool > m_open
std::string m_capture_filepath
AVCodecID m_capture_codec_id
bool m_capture_did_enable
std::string last_error() const
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.