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

◆ open()

bool MayaFlux::IO::CameraReader::open ( const CameraConfig config)

Open a camera device using the supplied config.

Parameters
configDevice name, resolution hint, fps hint, format override.
Returns
True on success.

Definition at line 61 of file CameraReader.cpp.

62{
63 close();
64
65 const std::string fmt_name = config.format_override.empty()
66 ? std::string(CAMERA_FORMAT)
67 : config.format_override;
68
69 AVDictionary* opts = nullptr;
70
71 std::string fps_str = std::to_string(static_cast<int>(config.target_fps));
72 av_dict_set(&opts, "framerate", fps_str.c_str(), 0);
73
74 std::string size_str = std::to_string(config.target_width)
75 + "x"
76 + std::to_string(config.target_height);
77
78 av_dict_set(&opts, "video_size", size_str.c_str(), 0);
79
80 if (!m_demux->open_device(config.device_name, fmt_name, &opts)) {
81 m_last_error = "Device open failed: " + m_demux->last_error();
83 "CameraReader::open — {}", m_last_error);
84 return false;
85 }
86
87 if (!m_video->open_device(*m_demux,
88 config.target_width,
89 config.target_height)) {
90 m_last_error = "Video stream open failed: " + m_video->last_error();
92 "CameraReader::open — {}", m_last_error);
93 m_demux->close();
94 return false;
95 }
96
97 m_sws_buf.clear();
98 m_scaler_ready = false;
99
101 "CameraReader: opened '{}' via {} — {}x{} @{:.1f}fps (scaler deferred)",
102 config.device_name, fmt_name,
103 m_video->width, m_video->height, m_video->frame_rate);
104
105 return true;
106}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
std::vector< uint8_t > m_sws_buf
void close()
Release codec, demux, and scratch buffer resources.
std::shared_ptr< VideoStreamContext > m_video
std::shared_ptr< FFmpegDemuxContext > m_demux
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.

References close(), MayaFlux::IO::CameraConfig::device_name, MayaFlux::Journal::FileIO, MayaFlux::IO::CameraConfig::format_override, MayaFlux::Journal::IO, m_demux, m_last_error, m_scaler_ready, m_sws_buf, m_video, MF_ERROR, MF_INFO, MayaFlux::IO::CameraConfig::target_fps, MayaFlux::IO::CameraConfig::target_height, and MayaFlux::IO::CameraConfig::target_width.

+ Here is the call graph for this function: