MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ record()

bool MayaFlux::IO::VideoFileWriter::record ( const std::shared_ptr< Core::Window > &  window,
const std::string &  filepath,
double  frame_rate,
AVCodecID  codec_id = AV_CODEC_ID_NONE 
)

Definition at line 100 of file VideoFileWriter.cpp.

104{
105 if (!window) {
106 set_error("record: null window");
107 return false;
108 }
109
111 .get_service<Registry::Service::DisplayService>();
112 if (!svc || !svc->register_frame_observer) {
113 set_error("record: DisplayService unavailable");
114 return false;
115 }
116
117 if (m_observer_id.load(std::memory_order_acquire) != 0)
118 stop_recording().get();
119
120 m_capture_filepath = filepath;
121 m_capture_frame_rate = frame_rate;
122 m_capture_codec_id = codec_id;
123 m_capture_window = window;
124 m_capture_opened.store(false, std::memory_order_release);
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
139 if (!m_capture_opened.exchange(true, std::memory_order_acq_rel)) {
140 const AVPixelFormat av_fmt = vk_format_to_avpixfmt(vk_fmt);
141 if (!open(m_capture_filepath, w, h,
144 "[VideoFileWriter] record: failed to open encoder for "
145 "'{}': {}",
147 m_capture_opened.store(false, std::memory_order_release);
148 return;
149 }
150 }
151
152 if (!m_open.load(std::memory_order_acquire))
153 return;
154
155 post(RawFrame {
156 .pixels = std::vector<uint8_t>(buf->begin(), buf->end()),
157 .width = w,
158 .height = h });
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);
166 m_capture_did_enable = false;
167 }
168 m_capture_window.reset();
169 return false;
170 }
171
172 m_observer_id.store(obs_id, std::memory_order_release);
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,...)
uint32_t h
Definition InkPress.cpp:28
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)
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.

References MayaFlux::Journal::FileIO, MayaFlux::Registry::BackendRegistry::get_service(), h, MayaFlux::Registry::BackendRegistry::instance(), MayaFlux::Journal::IO, last_error(), m_capture_codec_id, m_capture_did_enable, m_capture_filepath, m_capture_frame_rate, m_capture_opened, m_capture_window, m_observer_id, m_open, MF_ERROR, MF_INFO, open(), MayaFlux::IO::VideoFileWriter::RawFrame::pixels, post(), set_error(), and stop_recording().

+ Here is the call graph for this function: