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

◆ read_frames()

std::vector< Kakshya::DataVariant > MayaFlux::IO::SoundFileReader::read_frames ( uint64_t  num_frames,
uint64_t  offset = 0 
)

Read a specific number of frames from the file.

Parameters
num_framesNumber of frames to read.
offsetFrame offset from beginning.
Returns
DataVariant containing std::vector<double>.

Definition at line 369 of file SoundFileReader.cpp.

371{
372 std::shared_lock<std::shared_mutex> lock(m_context_mutex);
373 if (!m_demux || !m_audio) {
374 set_error("File not open");
375 return {};
376 }
377
378 if (offset != m_current_frame_position.load()) {
379 lock.unlock();
380 std::unique_lock<std::shared_mutex> wlock(m_context_mutex);
381 if (!m_demux || !m_audio) {
382 set_error("File closed during operation");
383 return {};
384 }
385 if (!seek_internal(m_demux, m_audio, offset))
386 return {};
387 wlock.unlock();
388 lock.lock();
389 if (!m_demux || !m_audio) {
390 set_error("File closed during operation");
391 return {};
392 }
393 }
394
395 return decode_frames(m_demux, m_audio, num_frames, offset);
396}
std::shared_ptr< AudioStreamContext > m_audio
Codec + resampler state.
std::shared_mutex m_context_mutex
Guards both context pointers.
bool seek_internal(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< AudioStreamContext > &audio, uint64_t frame_position)
Seek the demuxer and flush the codec to the given frame position.
std::vector< Kakshya::DataVariant > decode_frames(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< AudioStreamContext > &audio, uint64_t num_frames, uint64_t offset)
Decode num_frames PCM frames starting at offset.
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::shared_ptr< FFmpegDemuxContext > m_demux
Container / format state.

References decode_frames(), m_audio, m_context_mutex, m_current_frame_position, m_demux, seek_internal(), and set_error().

Referenced by load_bounded(), and read_region().

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