MCPcopy Create free account
hub / github.com/clangen/musikcube / ReadFromFifoAndWriteToBuffer

Method ReadFromFifoAndWriteToBuffer

src/plugins/ffmpegdecoder/FfmpegDecoder.cpp:616–643  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

614}
615
616bool FfmpegDecoder::ReadFromFifoAndWriteToBuffer(IBuffer* buffer) {
617 int error = 0;
618 int fifoSize = av_audio_fifo_size(this->outputFifo);
619
620 if (this->eof && fifoSize == 0) {
621 return false;
622 }
623
624 if (
625 fifoSize >= this->preferredFrameSize ||
626 (this->eof && fifoSize > 0)
627 ) {
628 const int expectedFrameSize = FFMIN(fifoSize, this->preferredFrameSize);
629 buffer->SetSamples(expectedFrameSize * this->channels);
630 void* outData = (void*)buffer->BufferPointer();
631 int actualFrameSize = av_audio_fifo_read(this->outputFifo, &outData, expectedFrameSize);
632
633 if (actualFrameSize > expectedFrameSize) {
634 logError("av_audio_fifo_read read the incorrect number of samples");
635 return false;
636 }
637 else if (actualFrameSize != expectedFrameSize) {
638 buffer->SetSamples(actualFrameSize * this->channels);
639 }
640 }
641
642 return true;
643}
644
645void FfmpegDecoder::FlushAndFinalizeDecoder() {
646 /* reading from a packet with a null `data` pointer is a "flush" operation,

Callers 1

GetBufferMethod · 0.95

Calls 3

logErrorFunction · 0.70
SetSamplesMethod · 0.45
BufferPointerMethod · 0.45

Tested by

no test coverage detected