MayaFlux 0.4.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 99 of file VideoFileWriter.cpp.

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