MayaFlux 0.3.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 287 of file SoundFileReader.cpp.

289{
290 std::shared_lock<std::shared_mutex> lock(m_context_mutex);
291 if (!m_demux || !m_audio) {
292 set_error("File not open");
293 return {};
294 }
295
296 if (offset != m_current_frame_position.load()) {
297 lock.unlock();
298 std::unique_lock<std::shared_mutex> wlock(m_context_mutex);
299 if (!m_demux || !m_audio) {
300 set_error("File closed during operation");
301 return {};
302 }
303 if (!seek_internal(m_demux, m_audio, offset))
304 return {};
305 wlock.unlock();
306 lock.lock();
307 if (!m_demux || !m_audio) {
308 set_error("File closed during operation");
309 return {};
310 }
311 }
312
313 return decode_frames(m_demux, m_audio, num_frames, offset);
314}
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 read_region().

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