diff --git a/src/media/audio/audio_frame_resizer.cpp b/src/media/audio/audio_frame_resizer.cpp index 4bcf86d28f3f8e1748bf012d3217514e4e00d75f..77c26dc9a06eda9e908cc6753cccc7b284e44fbd 100644 --- a/src/media/audio/audio_frame_resizer.cpp +++ b/src/media/audio/audio_frame_resizer.cpp @@ -95,7 +95,9 @@ AudioFrameResizer::enqueue(std::shared_ptr<AudioFrame>&& frame) throw std::runtime_error("Could not write samples to audio queue: input frame is not the right format"); } - if (samples() == 0 && f->nb_samples == frameSize_) { + auto nb_samples = samples(); + if (nb_samples == 0 && f->nb_samples == frameSize_) { + nextOutputPts_ = frame->pointer()->pts + frameSize_; cb_(std::move(frame)); return; // return if frame was just passed through } @@ -106,6 +108,9 @@ AudioFrameResizer::enqueue(std::shared_ptr<AudioFrame>&& frame) throw std::runtime_error("Failed to add audio to frame resizer"); } + if (nextOutputPts_ == 0) + nextOutputPts_ = frame->pointer()->pts - nb_samples; + if (cb_) while (auto frame = dequeue()) cb_(std::move(frame)); @@ -123,6 +128,8 @@ AudioFrameResizer::dequeue() RING_ERR() << "Could not read samples from queue: " << libav_utils::getError(ret); return {}; } + frame->pointer()->pts = nextOutputPts_; + nextOutputPts_ += frameSize_; return frame; } diff --git a/src/media/audio/audio_frame_resizer.h b/src/media/audio/audio_frame_resizer.h index 0023ae99c082aec9e49680aaf4c67498837ce908..ddb037a87c7b3c6d60f1b875d54263f2dc382c5e 100644 --- a/src/media/audio/audio_frame_resizer.h +++ b/src/media/audio/audio_frame_resizer.h @@ -98,6 +98,7 @@ private: * Audio queue operating on the sample level instead of byte level. */ AVAudioFifo* queue_; + int64_t nextOutputPts_ {0}; }; } // namespace ring