Skip to content
Snippets Groups Projects
Commit a687eb2d authored by Adrien Béraud's avatar Adrien Béraud
Browse files

audioframeresizer: preserve pts


Change-Id: I89e3096ccdc27a2ca32f58c40e33f3e65fe45405
Reviewed-by: default avatarPhilippe Gorley <philippe.gorley@savoirfairelinux.com>
parent a436351a
No related branches found
No related tags found
No related merge requests found
...@@ -95,7 +95,9 @@ AudioFrameResizer::enqueue(std::shared_ptr<AudioFrame>&& frame) ...@@ -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"); 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)); cb_(std::move(frame));
return; // return if frame was just passed through return; // return if frame was just passed through
} }
...@@ -106,6 +108,9 @@ AudioFrameResizer::enqueue(std::shared_ptr<AudioFrame>&& frame) ...@@ -106,6 +108,9 @@ AudioFrameResizer::enqueue(std::shared_ptr<AudioFrame>&& frame)
throw std::runtime_error("Failed to add audio to frame resizer"); throw std::runtime_error("Failed to add audio to frame resizer");
} }
if (nextOutputPts_ == 0)
nextOutputPts_ = frame->pointer()->pts - nb_samples;
if (cb_) if (cb_)
while (auto frame = dequeue()) while (auto frame = dequeue())
cb_(std::move(frame)); cb_(std::move(frame));
...@@ -123,6 +128,8 @@ AudioFrameResizer::dequeue() ...@@ -123,6 +128,8 @@ AudioFrameResizer::dequeue()
RING_ERR() << "Could not read samples from queue: " << libav_utils::getError(ret); RING_ERR() << "Could not read samples from queue: " << libav_utils::getError(ret);
return {}; return {};
} }
frame->pointer()->pts = nextOutputPts_;
nextOutputPts_ += frameSize_;
return frame; return frame;
} }
......
...@@ -98,6 +98,7 @@ private: ...@@ -98,6 +98,7 @@ private:
* Audio queue operating on the sample level instead of byte level. * Audio queue operating on the sample level instead of byte level.
*/ */
AVAudioFifo* queue_; AVAudioFifo* queue_;
int64_t nextOutputPts_ {0};
}; };
} // namespace ring } // namespace ring
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment