patch-src_decoder_ffmpeg_decoder_plugin_c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. --- mpd-0.17.6.orig/src/decoder/ffmpeg_decoder_plugin.c 2013-08-04 14:20:16.000000000 +0200
  2. +++ mpd-0.17.6/src/decoder/ffmpeg_decoder_plugin.c 2013-10-15 16:26:29.000000000 +0200
  3. @@ -255,7 +255,8 @@ copy_interleave_frame2(uint8_t *dest, ui
  4. static int
  5. copy_interleave_frame(const AVCodecContext *codec_context,
  6. const AVFrame *frame,
  7. - uint8_t *buffer, size_t buffer_size)
  8. + uint8_t **output_buffer,
  9. + uint8_t **global_buffer, int *global_buffer_size)
  10. {
  11. int plane_size;
  12. const int data_size =
  13. @@ -263,18 +264,26 @@ copy_interleave_frame(const AVCodecConte
  14. codec_context->channels,
  15. frame->nb_samples,
  16. codec_context->sample_fmt, 1);
  17. - if (buffer_size < (size_t)data_size)
  18. - /* buffer is too small - shouldn't happen */
  19. - return AVERROR(EINVAL);
  20. if (av_sample_fmt_is_planar(codec_context->sample_fmt) &&
  21. codec_context->channels > 1) {
  22. - copy_interleave_frame2(buffer, frame->extended_data,
  23. + if(*global_buffer_size < data_size) {
  24. + av_freep(global_buffer);
  25. +
  26. + *global_buffer = (uint8_t*)av_malloc(data_size);
  27. +
  28. + if (!*global_buffer)
  29. + /* Not enough memory - shouldn't happen */
  30. + return AVERROR(ENOMEM);
  31. + *global_buffer_size = data_size;
  32. + }
  33. + *output_buffer = *global_buffer;
  34. + copy_interleave_frame2(*output_buffer, frame->extended_data,
  35. frame->nb_samples,
  36. codec_context->channels,
  37. av_get_bytes_per_sample(codec_context->sample_fmt));
  38. } else {
  39. - memcpy(buffer, frame->extended_data[0], data_size);
  40. + *output_buffer = frame->extended_data[0];
  41. }
  42. return data_size;
  43. @@ -285,7 +294,8 @@ static enum decoder_command
  44. ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
  45. const AVPacket *packet,
  46. AVCodecContext *codec_context,
  47. - const AVRational *time_base)
  48. + const AVRational *time_base,
  49. + uint8_t **buffer, int *buffer_size)
  50. {
  51. if (packet->pts >= 0 && packet->pts != (int64_t)AV_NOPTS_VALUE)
  52. decoder_timestamp(decoder,
  53. @@ -299,8 +309,7 @@ ffmpeg_send_packet(struct decoder *decod
  54. #endif
  55. #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0)
  56. - uint8_t aligned_buffer[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16];
  57. - const size_t buffer_size = sizeof(aligned_buffer);
  58. + uint8_t *output_buffer;
  59. #else
  60. /* libavcodec < 0.8 needs an aligned buffer */
  61. uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16];
  62. @@ -316,7 +325,7 @@ ffmpeg_send_packet(struct decoder *decod
  63. packet_size > 0 &&
  64. #endif
  65. cmd == DECODE_COMMAND_NONE) {
  66. - int audio_size = buffer_size;
  67. + int audio_size = 0;
  68. #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0)
  69. AVFrame *frame = avcodec_alloc_frame();
  70. @@ -332,12 +341,11 @@ ffmpeg_send_packet(struct decoder *decod
  71. if (len >= 0 && got_frame) {
  72. audio_size = copy_interleave_frame(codec_context,
  73. frame,
  74. - aligned_buffer,
  75. - buffer_size);
  76. + &output_buffer,
  77. + buffer, buffer_size);
  78. if (audio_size < 0)
  79. len = audio_size;
  80. - } else if (len >= 0)
  81. - len = -1;
  82. + }
  83. #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0)
  84. avcodec_free_frame(&frame);
  85. @@ -373,7 +381,7 @@ ffmpeg_send_packet(struct decoder *decod
  86. continue;
  87. cmd = decoder_data(decoder, is,
  88. - aligned_buffer, audio_size,
  89. + output_buffer, audio_size,
  90. codec_context->bit_rate / 1000);
  91. }
  92. return cmd;
  93. @@ -589,6 +597,9 @@ ffmpeg_decode(struct decoder *decoder, s
  94. decoder_initialized(decoder, &audio_format,
  95. input->seekable, total_time);
  96. + uint8_t *interleaved_buffer = NULL;
  97. + int interleaved_buffer_size = 0;
  98. +
  99. enum decoder_command cmd;
  100. do {
  101. AVPacket packet;
  102. @@ -599,7 +610,8 @@ ffmpeg_decode(struct decoder *decoder, s
  103. if (packet.stream_index == audio_stream)
  104. cmd = ffmpeg_send_packet(decoder, input,
  105. &packet, codec_context,
  106. - &av_stream->time_base);
  107. + &av_stream->time_base,
  108. + &interleaved_buffer, &interleaved_buffer_size);
  109. else
  110. cmd = decoder_get_command(decoder);
  111. @@ -620,6 +632,8 @@ ffmpeg_decode(struct decoder *decoder, s
  112. }
  113. } while (cmd != DECODE_COMMAND_STOP);
  114. + av_freep(&interleaved_buffer);
  115. +
  116. avcodec_close(codec_context);
  117. #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,17,0)
  118. avformat_close_input(&format_context);