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

◆ seek_internal()

bool MayaFlux::IO::SoundFileReader::seek_internal ( const std::shared_ptr< FFmpegDemuxContext > &  demux,
const std::shared_ptr< AudioStreamContext > &  audio,
uint64_t  frame_position 
)
private

Seek the demuxer and flush the codec to the given frame position.

Parameters
ctxFFmpeg context.
frame_positionTarget frame position.
Returns
True if seek succeeded.

Caller must hold an exclusive lock on m_context_mutex.

Definition at line 339 of file SoundFileReader.cpp.

343{
344 if (frame_position > audio->total_frames)
345 frame_position = audio->total_frames;
346
347 if (audio->sample_rate == 0) {
348 set_error("Invalid sample rate");
349 return false;
350 }
351
352 AVStream* stream = demux->get_stream(audio->stream_index);
353 if (!stream) {
354 set_error("Invalid stream index");
355 return false;
356 }
357
358 int64_t ts = av_rescale_q(
359 static_cast<int64_t>(frame_position),
360 AVRational { 1, static_cast<int>(audio->sample_rate) },
361 stream->time_base);
362
363 if (!demux->seek(audio->stream_index, ts)) {
364 set_error(demux->last_error());
365 return false;
366 }
367
368 audio->flush_codec();
369 audio->drain_resampler_init();
370 m_current_frame_position = frame_position;
371 return true;
372}
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.

References m_current_frame_position, and set_error().

Referenced by read_frames(), and seek().

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