aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-06-19 18:56:29 +0200
committerMax Kellermann <max@duempel.org>2015-06-19 18:56:29 +0200
commitf768ca3a2d20cc839e25ca3c95438909d54afd77 (patch)
treea904c7c9f8458b9d7483b8ab25604eabee75a645 /src
parent947e902288d5436c62214c509fda81708815b3d6 (diff)
downloadmpd-f768ca3a2d20cc839e25ca3c95438909d54afd77.tar.gz
mpd-f768ca3a2d20cc839e25ca3c95438909d54afd77.tar.xz
mpd-f768ca3a2d20cc839e25ca3c95438909d54afd77.zip
decoder/ffmpeg: move code to StreamRelativePts()
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;