MayaFlux 0.4.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 128 of file SoundFileReader.cpp.

133{
134 std::unique_lock<std::shared_mutex> lock(m_context_mutex);
135
136 m_demux.reset();
137 m_audio.reset();
139 {
140 std::lock_guard<std::mutex> ml(m_metadata_mutex);
141 m_cached_metadata.reset();
142 m_cached_regions.clear();
143 }
144 clear_error();
145
146 if (!demux || !demux->is_open()) {
147 set_error("open_from_demux: demux context is null or not open");
148 return false;
149 }
150
151 if (!audio || !audio->is_valid()) {
152 set_error("open_from_demux: audio stream context is null or not valid");
153 return false;
154 }
155
156 m_filepath = filepath;
157 m_demux = std::move(demux);
158 m_audio = std::move(audio);
159
162
165
166 return true;
167}
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: