|  | @@ -1,11 +1,127 @@
 | 
	
		
			
				|  |  | ---- mpd-0.17.4.orig/src/decoder/ffmpeg_decoder_plugin.c	2013-04-08 20:01:53.000000000 +0200
 | 
	
		
			
				|  |  | -+++ mpd-0.17.4/src/decoder/ffmpeg_decoder_plugin.c	2013-07-10 11:02:20.000000000 +0200
 | 
	
		
			
				|  |  | -@@ -44,6 +44,8 @@
 | 
	
		
			
				|  |  | - #include <libavutil/dict.h>
 | 
	
		
			
				|  |  | +--- mpd-0.17.6.orig/src/decoder/ffmpeg_decoder_plugin.c	2013-08-04 14:20:16.000000000 +0200
 | 
	
		
			
				|  |  | ++++ mpd-0.17.6/src/decoder/ffmpeg_decoder_plugin.c	2013-10-15 16:26:29.000000000 +0200
 | 
	
		
			
				|  |  | +@@ -255,7 +255,8 @@ copy_interleave_frame2(uint8_t *dest, ui
 | 
	
		
			
				|  |  | + static int
 | 
	
		
			
				|  |  | + copy_interleave_frame(const AVCodecContext *codec_context,
 | 
	
		
			
				|  |  | + 		      const AVFrame *frame,
 | 
	
		
			
				|  |  | +-		      uint8_t *buffer, size_t buffer_size)
 | 
	
		
			
				|  |  | ++		      uint8_t **output_buffer,
 | 
	
		
			
				|  |  | ++		      uint8_t **global_buffer, int *global_buffer_size)	
 | 
	
		
			
				|  |  | + {
 | 
	
		
			
				|  |  | + 	int plane_size;
 | 
	
		
			
				|  |  | + 	const int data_size =
 | 
	
		
			
				|  |  | +@@ -263,18 +264,26 @@ copy_interleave_frame(const AVCodecConte
 | 
	
		
			
				|  |  | + 					   codec_context->channels,
 | 
	
		
			
				|  |  | + 					   frame->nb_samples,
 | 
	
		
			
				|  |  | + 					   codec_context->sample_fmt, 1);
 | 
	
		
			
				|  |  | +-	if (buffer_size < (size_t)data_size)
 | 
	
		
			
				|  |  | +-		/* buffer is too small - shouldn't happen */
 | 
	
		
			
				|  |  | +-		return AVERROR(EINVAL);
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | + 	if (av_sample_fmt_is_planar(codec_context->sample_fmt) &&
 | 
	
		
			
				|  |  | + 	    codec_context->channels > 1) {
 | 
	
		
			
				|  |  | +-		copy_interleave_frame2(buffer, frame->extended_data,
 | 
	
		
			
				|  |  | ++			if(*global_buffer_size < data_size) {
 | 
	
		
			
				|  |  | ++				av_freep(global_buffer);
 | 
	
		
			
				|  |  | ++
 | 
	
		
			
				|  |  | ++				*global_buffer = (uint8_t*)av_malloc(data_size);
 | 
	
		
			
				|  |  | ++
 | 
	
		
			
				|  |  | ++				if (!*global_buffer)
 | 
	
		
			
				|  |  | ++					/* Not enough memory - shouldn't happen */
 | 
	
		
			
				|  |  | ++					return AVERROR(ENOMEM);
 | 
	
		
			
				|  |  | ++				*global_buffer_size = data_size;
 | 
	
		
			
				|  |  | ++			}
 | 
	
		
			
				|  |  | ++			*output_buffer = *global_buffer;
 | 
	
		
			
				|  |  | ++			copy_interleave_frame2(*output_buffer, frame->extended_data,
 | 
	
		
			
				|  |  | + 				       frame->nb_samples,
 | 
	
		
			
				|  |  | + 				       codec_context->channels,
 | 
	
		
			
				|  |  | + 				       av_get_bytes_per_sample(codec_context->sample_fmt));
 | 
	
		
			
				|  |  | + 	} else {
 | 
	
		
			
				|  |  | +-		memcpy(buffer, frame->extended_data[0], data_size);
 | 
	
		
			
				|  |  | ++		*output_buffer = frame->extended_data[0];
 | 
	
		
			
				|  |  | + 	}
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | + 	return data_size;
 | 
	
		
			
				|  |  | +@@ -285,7 +294,8 @@ static enum decoder_command
 | 
	
		
			
				|  |  | + ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
 | 
	
		
			
				|  |  | + 		   const AVPacket *packet,
 | 
	
		
			
				|  |  | + 		   AVCodecContext *codec_context,
 | 
	
		
			
				|  |  | +-		   const AVRational *time_base)
 | 
	
		
			
				|  |  | ++		   const AVRational *time_base,
 | 
	
		
			
				|  |  | ++		   uint8_t **buffer, int *buffer_size)
 | 
	
		
			
				|  |  | + {
 | 
	
		
			
				|  |  | + 	if (packet->pts >= 0 && packet->pts != (int64_t)AV_NOPTS_VALUE)
 | 
	
		
			
				|  |  | + 		decoder_timestamp(decoder,
 | 
	
		
			
				|  |  | +@@ -299,8 +309,7 @@ ffmpeg_send_packet(struct decoder *decod
 | 
	
		
			
				|  |  | + #endif
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | + #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0)
 | 
	
		
			
				|  |  | +-	uint8_t aligned_buffer[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16];
 | 
	
		
			
				|  |  | +-	const size_t buffer_size = sizeof(aligned_buffer);
 | 
	
		
			
				|  |  | ++	uint8_t *output_buffer;
 | 
	
		
			
				|  |  | + #else
 | 
	
		
			
				|  |  | + 	/* libavcodec < 0.8 needs an aligned buffer */
 | 
	
		
			
				|  |  | + 	uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16];
 | 
	
		
			
				|  |  | +@@ -316,7 +325,7 @@ ffmpeg_send_packet(struct decoder *decod
 | 
	
		
			
				|  |  | + 	       packet_size > 0 &&
 | 
	
		
			
				|  |  |   #endif
 | 
	
		
			
				|  |  | + 	       cmd == DECODE_COMMAND_NONE) {
 | 
	
		
			
				|  |  | +-		int audio_size = buffer_size;
 | 
	
		
			
				|  |  | ++		int audio_size = 0;
 | 
	
		
			
				|  |  | + #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0)
 | 
	
		
			
				|  |  |   
 | 
	
		
			
				|  |  | -+#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
 | 
	
		
			
				|  |  | + 		AVFrame *frame = avcodec_alloc_frame();
 | 
	
		
			
				|  |  | +@@ -332,12 +341,11 @@ ffmpeg_send_packet(struct decoder *decod
 | 
	
		
			
				|  |  | + 		if (len >= 0 && got_frame) {
 | 
	
		
			
				|  |  | + 			audio_size = copy_interleave_frame(codec_context,
 | 
	
		
			
				|  |  | + 							   frame,
 | 
	
		
			
				|  |  | +-							   aligned_buffer,
 | 
	
		
			
				|  |  | +-							   buffer_size);
 | 
	
		
			
				|  |  | ++							   &output_buffer,
 | 
	
		
			
				|  |  | ++							   buffer, buffer_size);
 | 
	
		
			
				|  |  | + 			if (audio_size < 0)
 | 
	
		
			
				|  |  | + 				len = audio_size;
 | 
	
		
			
				|  |  | +-		} else if (len >= 0)
 | 
	
		
			
				|  |  | +-			len = -1;
 | 
	
		
			
				|  |  | ++		}
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | + #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0)
 | 
	
		
			
				|  |  | + 		avcodec_free_frame(&frame);
 | 
	
		
			
				|  |  | +@@ -373,7 +381,7 @@ ffmpeg_send_packet(struct decoder *decod
 | 
	
		
			
				|  |  | + 			continue;
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | + 		cmd = decoder_data(decoder, is,
 | 
	
		
			
				|  |  | +-				   aligned_buffer, audio_size,
 | 
	
		
			
				|  |  | ++				   output_buffer, audio_size,
 | 
	
		
			
				|  |  | + 				   codec_context->bit_rate / 1000);
 | 
	
		
			
				|  |  | + 	}
 | 
	
		
			
				|  |  | + 	return cmd;
 | 
	
		
			
				|  |  | +@@ -589,6 +597,9 @@ ffmpeg_decode(struct decoder *decoder, s
 | 
	
		
			
				|  |  | + 	decoder_initialized(decoder, &audio_format,
 | 
	
		
			
				|  |  | + 			    input->seekable, total_time);
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | ++	uint8_t *interleaved_buffer = NULL;
 | 
	
		
			
				|  |  | ++	int interleaved_buffer_size = 0;
 | 
	
		
			
				|  |  |  +
 | 
	
		
			
				|  |  | - #undef G_LOG_DOMAIN
 | 
	
		
			
				|  |  | - #define G_LOG_DOMAIN "ffmpeg"
 | 
	
		
			
				|  |  | + 	enum decoder_command cmd;
 | 
	
		
			
				|  |  | + 	do {
 | 
	
		
			
				|  |  | + 		AVPacket packet;
 | 
	
		
			
				|  |  | +@@ -599,7 +610,8 @@ ffmpeg_decode(struct decoder *decoder, s
 | 
	
		
			
				|  |  | + 		if (packet.stream_index == audio_stream)
 | 
	
		
			
				|  |  | + 			cmd = ffmpeg_send_packet(decoder, input,
 | 
	
		
			
				|  |  | + 						 &packet, codec_context,
 | 
	
		
			
				|  |  | +-						 &av_stream->time_base);
 | 
	
		
			
				|  |  | ++						 &av_stream->time_base,
 | 
	
		
			
				|  |  | ++						 &interleaved_buffer, &interleaved_buffer_size);
 | 
	
		
			
				|  |  | + 		else
 | 
	
		
			
				|  |  | + 			cmd = decoder_get_command(decoder);
 | 
	
		
			
				|  |  |   
 | 
	
		
			
				|  |  | +@@ -620,6 +632,8 @@ ffmpeg_decode(struct decoder *decoder, s
 | 
	
		
			
				|  |  | + 		}
 | 
	
		
			
				|  |  | + 	} while (cmd != DECODE_COMMAND_STOP);
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | ++	av_freep(&interleaved_buffer);
 | 
	
		
			
				|  |  | ++
 | 
	
		
			
				|  |  | + 	avcodec_close(codec_context);
 | 
	
		
			
				|  |  | + #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,17,0)
 | 
	
		
			
				|  |  | + 	avformat_close_input(&format_context);
 |