104{
105 if (!window) {
107 return false;
108 }
109
112 if (!svc || !svc->register_frame_observer) {
113 set_error(
"record: DisplayService unavailable");
114 return false;
115 }
116
119
125
126 if (!window->is_capture_enabled()) {
127 window->set_capture_enabled(true);
129 }
130
131 auto handle = std::static_pointer_cast<void>(window);
132
133 uint32_t obs_id = svc->register_frame_observer(handle,
134 [this](const std::shared_ptr<std::vector<uint8_t>>& buf,
135 uint32_t w, uint32_t
h, uint32_t vk_fmt) {
136 if (!buf || buf->empty())
137 return;
138
140 const AVPixelFormat av_fmt = vk_format_to_avpixfmt(vk_fmt);
144 "[VideoFileWriter] record: failed to open encoder for "
145 "'{}': {}",
148 return;
149 }
150 }
151
152 if (!
m_open.load(std::memory_order_acquire))
153 return;
154
156 .pixels = std::vector<uint8_t>(buf->begin(), buf->end()),
157 .width = w,
159 });
160
161 if (obs_id == 0) {
162 set_error(
"record: register_frame_observer returned 0 — "
163 "capture not yet active for this window");
165 window->set_capture_enabled(false);
167 }
169 return false;
170 }
171
173
175 "[VideoFileWriter] record: observer {} registered for '{}' -> '{}'",
176 obs_id, window->get_create_info().title, filepath);
177
178 return true;
179}
#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.