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

◆ open_from_demux()

bool MayaFlux::IO::SoundFileReader::open_from_demux ( std::shared_ptr< FFmpegDemuxContext demux,
std::shared_ptr< AudioStreamContext audio,
const std::string &  filepath,
FileReadOptions  options = FileReadOptions::ALL 
)

Open an audio stream from an already-constructed demux and stream context.

Secondary open path for callers that have already probed the demuxer and opened an AudioStreamContext (e.g. VideoFileReader sharing its m_demux and m_audio). No avformat_open_input or AudioStreamContext::open is performed — both contexts are adopted as-is.

The filepath is required only for filesystem-level metadata (file_size, modification_time) populated during build_metadata. It must point to the same file already open in the demux context. Pass an empty string only if FileReadOptions::EXTRACT_METADATA is not set.

All subsequent SoundFileReader operations — metadata, regions, read_all, load_into_container — behave identically to the filepath-based open().

Both contexts must remain valid for the lifetime of this reader.

Parameters
demuxShared, already-open demux context.
audioShared, already-open and valid audio stream context.
filepathPath to the source file (used for filesystem metadata only).
optionsFile read options (metadata, regions, etc.).
Returns
True if both contexts are valid and setup succeeded.

Definition at line 126 of file SoundFileReader.cpp.

131{
132 std::unique_lock<std::shared_mutex> lock(m_context_mutex);
133
134 m_demux.reset();
135 m_audio.reset();
137 {
138 std::lock_guard<std::mutex> ml(m_metadata_mutex);
139 m_cached_metadata.reset();
140 m_cached_regions.clear();
141 }
142 clear_error();
143
144 if (!demux || !demux->is_open()) {
145 set_error("open_from_demux: demux context is null or not open");
146 return false;
147 }
148
149 if (!audio || !audio->is_valid()) {
150 set_error("open_from_demux: audio stream context is null or not valid");
151 return false;
152 }
153
154 m_filepath = filepath;
155 m_demux = std::move(demux);
156 m_audio = std::move(audio);
157
160
163
164 return true;
165}
void build_regions(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< AudioStreamContext > &audio) const
Build and cache FileRegion list from both contexts.
void build_metadata(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< AudioStreamContext > &audio) const
Build and cache FileMetadata from both contexts.
std::shared_ptr< AudioStreamContext > m_audio
Codec + resampler state.
std::shared_mutex m_context_mutex
Guards both context pointers.
std::mutex m_metadata_mutex
Mutex for thread-safe metadata access.
void set_error(const std::string &error) const
Set the last error message.
std::atomic< uint64_t > m_current_frame_position
Current frame position for reading.
std::optional< FileMetadata > m_cached_metadata
Cached file metadata.
std::vector< FileRegion > m_cached_regions
Cached file regions (markers, loops, etc.).
void clear_error() const
Clear the last error message.
std::string m_filepath
Path to the currently open file.
std::shared_ptr< FFmpegDemuxContext > m_demux
Container / format state.
@ EXTRACT_METADATA
Extract file metadata.
@ EXTRACT_REGIONS
Extract semantic regions (format-specific)
@ NONE
No special options.

References build_metadata(), build_regions(), clear_error(), MayaFlux::IO::EXTRACT_METADATA, MayaFlux::IO::EXTRACT_REGIONS, m_audio, m_cached_metadata, m_cached_regions, m_context_mutex, m_current_frame_position, m_demux, m_filepath, m_metadata_mutex, MayaFlux::IO::NONE, and set_error().

Referenced by MayaFlux::IO::VideoFileReader::load_into_container().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: