From 70495aada1a1e655b24173ca77d20c71af0dbc8c Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@duempel.org>
Date: Wed, 13 Apr 2016 09:04:51 +0200
Subject: [PATCH] decoder/ffmpeg: don't copy the AVPacket in
 ffmpeg_send_packet()

Reduce some overhead.  It is not necessary to copy the object.
---
 src/decoder/plugins/FfmpegDecoderPlugin.cxx | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
index 704cb6c84..640445007 100644
--- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
@@ -349,7 +349,7 @@ PtsToPcmFrame(uint64_t pts, const AVStream &stream,
  */
 static DecoderCommand
 ffmpeg_send_packet(Decoder &decoder, InputStream &is,
-		   const AVPacket &packet,
+		   AVPacket &&packet,
 		   AVCodecContext &codec_context,
 		   const AVStream &stream,
 		   AVFrame *frame,
@@ -370,17 +370,15 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is,
 					  time_from_ffmpeg(pts, stream.time_base));
 	}
 
-	AVPacket packet2 = packet;
-
 	uint8_t *output_buffer;
 
 	DecoderCommand cmd = DecoderCommand::NONE;
-	while (packet2.size > 0 && cmd == DecoderCommand::NONE) {
+	while (packet.size > 0 && cmd == DecoderCommand::NONE) {
 		int audio_size = 0;
 		int got_frame = 0;
 		int len = avcodec_decode_audio4(&codec_context,
 						frame, &got_frame,
-						&packet2);
+						&packet);
 		if (len >= 0 && got_frame) {
 			audio_size = copy_interleave_frame(codec_context,
 							   *frame,
@@ -397,8 +395,8 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is,
 			break;
 		}
 
-		packet2.data += len;
-		packet2.size -= len;
+		packet.data += len;
+		packet.size -= len;
 
 		if (audio_size <= 0)
 			continue;
@@ -631,7 +629,8 @@ ffmpeg_decode(Decoder &decoder, InputStream &input)
 
 		if (packet.stream_index == audio_stream) {
 			cmd = ffmpeg_send_packet(decoder, input,
-						 packet, *codec_context,
+						 std::move(packet),
+						 *codec_context,
 						 *av_stream,
 						 frame,
 						 min_frame, audio_format.GetFrameSize(),