From f768ca3a2d20cc839e25ca3c95438909d54afd77 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 19 Jun 2015 18:56:29 +0200 Subject: decoder/ffmpeg: move code to StreamRelativePts() --- src/decoder/plugins/FfmpegDecoderPlugin.cxx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/decoder/plugins') 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; -- cgit v1.2.3