aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/decoder/plugins/FfmpegDecoderPlugin.cxx26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
index 722f954e2..586a1ef41 100644
--- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
@@ -305,6 +305,22 @@ copy_interleave_frame(const AVCodecContext *codec_context,
return data_size;
}
+/**
+ * Convert AVPacket::pts to a stream-relative time stamp (still in
+ * AVStream::time_base units). Returns a negative value on error.
+ */
+gcc_pure
+static int64_t
+StreamRelativePts(const AVPacket &packet, const AVStream &stream)
+{
+ auto pts = packet.pts;
+ if (pts < 0 || pts == int64_t(AV_NOPTS_VALUE))
+ return -1;
+
+ auto start = start_time_fallback(stream);
+ return pts - start;
+}
+
static DecoderCommand
ffmpeg_send_packet(Decoder &decoder, InputStream &is,
const AVPacket *packet,
@@ -313,12 +329,10 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is,
AVFrame *frame,
uint8_t **buffer, int *buffer_size)
{
- if (packet->pts >= 0 && packet->pts != (int64_t)AV_NOPTS_VALUE) {
- auto start = start_time_fallback(*stream);
- if (packet->pts >= start)
- decoder_timestamp(decoder,
- time_from_ffmpeg(packet->pts - start,
- stream->time_base));
+ const auto pts = StreamRelativePts(*packet, *stream);
+ if (pts >= 0) {
+ decoder_timestamp(decoder,
+ time_from_ffmpeg(pts, stream->time_base));
}
AVPacket packet2 = *packet;