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

425{
426 if (frame_position > audio->total_frames)
427 frame_position = audio->total_frames;
428
429 if (audio->sample_rate == 0) {
430 set_error("Invalid sample rate");
431 return false;
432 }
433
434 AVStream* stream = demux->get_stream(audio->stream_index);
435 if (!stream) {
436 set_error("Invalid stream index");
437 return false;
438 }
439
440 int64_t ts = av_rescale_q(
441 static_cast<int64_t>(frame_position),
442 AVRational { .num = 1, .den = static_cast<int>(audio->sample_rate) },
443 stream->time_base);
444
445 if (!demux->seek(audio->stream_index, ts)) {
446 set_error(demux->last_error());
447 return false;
448 }
449
450 audio->flush_codec();
451 audio->drain_resampler_init();
452 m_current_frame_position = frame_position;
453 return true;
454}
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: