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

Method DrainResamplerToFifoQueue

src/plugins/ffmpegdecoder/FfmpegDecoder.cpp:528–572  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526}
527
528bool FfmpegDecoder::DrainResamplerToFifoQueue() {
529 if (!this->resampler) {
530 return false;
531 }
532
533 const int64_t targetRate =
534 RESOLVE_SAMPLE_RATE() > this->codecContext->sample_rate
535 ? RESOLVE_SAMPLE_RATE()
536 : this->codecContext->sample_rate;
537
538 int64_t bufferedFrames = swr_get_delay(this->resampler, targetRate);
539
540 while (bufferedFrames > 0) {
541 this->resampledFrame = this->AllocFrame(
542 this->resampledFrame,
543 this->codecContext->sample_fmt,
544 this->codecContext->sample_rate);
545
546 int converted = swr_convert(
547 this->resampler,
548 this->resampledFrame->extended_data,
549 this->resampledFrame->nb_samples,
550 nullptr,
551 0);
552
553 if (converted > 0) {
554 int error = av_audio_fifo_write(
555 this->outputFifo,
556 (void**) this->resampledFrame->extended_data,
557 converted);
558
559 if (error < 0) {
560 logAvError("av_audio_fifo_write", error);
561 return false;
562 }
563
564 bufferedFrames -= converted;
565 }
566 else {
567 break;
568 }
569 }
570
571 return true;
572}
573
574bool FfmpegDecoder::RefillFifoQueue() {
575 bool sentAtLeastOnePacket = false;

Callers 2

GetBufferMethod · 0.95

Calls 2

AllocFrameMethod · 0.95
logAvErrorFunction · 0.70

Tested by

no test coverage detected