You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.4 KiB

  1. From 141c960e21d2860e354f9b90df136184dd00a9a8 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin@martin.st>
  3. Date: Fri, 31 Aug 2018 14:25:30 +0300
  4. Subject: [PATCH] libfdk-aacenc: Fix building with libfdk-aac v2
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. When flushing the encoder, we now need to provide non-null buffer
  9. parameters for everything, even if they are unused.
  10. The encoderDelay parameter has been replaced by two, nDelay and
  11. nDelayCore.
  12. Signed-off-by: Martin Storsjö <martin@martin.st>
  13. ---
  14. libavcodec/libfdk-aacenc.c | 34 +++++++++++++++++++++++++---------
  15. 1 file changed, 25 insertions(+), 9 deletions(-)
  16. diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
  17. index c340a1e3e0c..2ad768ed44e 100644
  18. --- a/libavcodec/libfdk-aacenc.c
  19. +++ b/libavcodec/libfdk-aacenc.c
  20. @@ -26,6 +26,11 @@
  21. #include "audio_frame_queue.h"
  22. #include "internal.h"
  23. +#define FDKENC_VER_AT_LEAST(vl0, vl1) \
  24. + (defined(AACENCODER_LIB_VL0) && \
  25. + ((AACENCODER_LIB_VL0 > vl0) || \
  26. + (AACENCODER_LIB_VL0 == vl0 && AACENCODER_LIB_VL1 >= vl1)))
  27. +
  28. typedef struct AACContext {
  29. const AVClass *class;
  30. HANDLE_AACENCODER handle;
  31. @@ -286,7 +291,11 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
  32. }
  33. avctx->frame_size = info.frameLength;
  34. +#if FDKENC_VER_AT_LEAST(4, 0)
  35. + avctx->initial_padding = info.nDelay;
  36. +#else
  37. avctx->initial_padding = info.encoderDelay;
  38. +#endif
  39. ff_af_queue_init(avctx, &s->afq);
  40. if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
  41. @@ -319,28 +328,35 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
  42. int out_buffer_size, out_buffer_element_size;
  43. void *in_ptr, *out_ptr;
  44. int ret;
  45. + uint8_t dummy_buf[1];
  46. AACENC_ERROR err;
  47. /* handle end-of-stream small frame and flushing */
  48. if (!frame) {
  49. + /* Must be a non-null pointer, even if it's a dummy. We could use
  50. + * the address of anything else on the stack as well. */
  51. + in_ptr = dummy_buf;
  52. + in_buffer_size = 0;
  53. +
  54. in_args.numInSamples = -1;
  55. } else {
  56. - in_ptr = frame->data[0];
  57. - in_buffer_size = 2 * avctx->channels * frame->nb_samples;
  58. - in_buffer_element_size = 2;
  59. + in_ptr = frame->data[0];
  60. + in_buffer_size = 2 * avctx->channels * frame->nb_samples;
  61. - in_args.numInSamples = avctx->channels * frame->nb_samples;
  62. - in_buf.numBufs = 1;
  63. - in_buf.bufs = &in_ptr;
  64. - in_buf.bufferIdentifiers = &in_buffer_identifier;
  65. - in_buf.bufSizes = &in_buffer_size;
  66. - in_buf.bufElSizes = &in_buffer_element_size;
  67. + in_args.numInSamples = avctx->channels * frame->nb_samples;
  68. /* add current frame to the queue */
  69. if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
  70. return ret;
  71. }
  72. + in_buffer_element_size = 2;
  73. + in_buf.numBufs = 1;
  74. + in_buf.bufs = &in_ptr;
  75. + in_buf.bufferIdentifiers = &in_buffer_identifier;
  76. + in_buf.bufSizes = &in_buffer_size;
  77. + in_buf.bufElSizes = &in_buffer_element_size;
  78. +
  79. /* The maximum packet size is 6144 bits aka 768 bytes per channel. */
  80. if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels), 0)) < 0)
  81. return ret;