d0c5b1ae.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. From d0c5b1ae4289c7f3cde3fbc031cb4a3160df05ff Mon Sep 17 00:00:00 2001
  2. From: Armin Novak <armin.novak@thincast.com>
  3. Date: Wed, 7 Jun 2023 11:46:07 +0200
  4. Subject: [PATCH] [codec,dsp] fix ffmpeg deprecations
  5. ---
  6. libfreerdp/codec/dsp_ffmpeg.c | 54 +++++++++++++++++++++++++++--------
  7. 1 file changed, 42 insertions(+), 12 deletions(-)
  8. diff --git a/libfreerdp/codec/dsp_ffmpeg.c b/libfreerdp/codec/dsp_ffmpeg.c
  9. index 2c93a667750e..ebba52b147d2 100644
  10. --- a/libfreerdp/codec/dsp_ffmpeg.c
  11. +++ b/libfreerdp/codec/dsp_ffmpeg.c
  12. @@ -224,18 +224,17 @@ static void ffmpeg_close_context(FREERDP_DSP_CONTEXT* context)
  13. static BOOL ffmpeg_open_context(FREERDP_DSP_CONTEXT* context)
  14. {
  15. int ret;
  16. - int layout;
  17. - const AUDIO_FORMAT* format;
  18. if (!context || context->isOpen)
  19. return FALSE;
  20. - format = &context->format;
  21. + const AUDIO_FORMAT* format = &context->format;
  22. if (!format)
  23. return FALSE;
  24. -
  25. - layout = av_get_default_channel_layout(format->nChannels);
  26. +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 28, 100)
  27. + const int layout = av_get_default_channel_layout(format->nChannels);
  28. +#endif
  29. context->id = ffmpeg_get_avcodec(format);
  30. if (ffmpeg_codec_is_filtered(context->id, context->encoder))
  31. @@ -271,8 +270,12 @@ static BOOL ffmpeg_open_context(FREERDP_DSP_CONTEXT* context)
  32. break;
  33. }
  34. +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 28, 100)
  35. context->context->channels = format->nChannels;
  36. context->context->channel_layout = layout;
  37. +#else
  38. + av_channel_layout_default(&context->context->ch_layout, format->nChannels);
  39. +#endif
  40. context->context->sample_rate = format->nSamplesPerSec;
  41. context->context->block_align = format->nBlockAlign;
  42. context->context->bit_rate = format->nAvgBytesPerSec * 8;
  43. @@ -315,8 +318,12 @@ static BOOL ffmpeg_open_context(FREERDP_DSP_CONTEXT* context)
  44. if (!context->rcontext)
  45. goto fail;
  46. +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 28, 100)
  47. context->frame->channel_layout = layout;
  48. context->frame->channels = format->nChannels;
  49. +#else
  50. + av_channel_layout_default(&context->frame->ch_layout, format->nChannels);
  51. +#endif
  52. context->frame->sample_rate = format->nSamplesPerSec;
  53. context->frame->format = AV_SAMPLE_FMT_S16;
  54. @@ -331,13 +338,21 @@ static BOOL ffmpeg_open_context(FREERDP_DSP_CONTEXT* context)
  55. context->resampled->sample_rate = format->nSamplesPerSec;
  56. }
  57. +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 28, 100)
  58. context->resampled->channel_layout = layout;
  59. context->resampled->channels = format->nChannels;
  60. +#else
  61. + av_channel_layout_default(&context->resampled->ch_layout, format->nChannels);
  62. +#endif
  63. if (context->context->frame_size > 0)
  64. {
  65. +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 28, 100)
  66. context->buffered->channel_layout = context->resampled->channel_layout;
  67. context->buffered->channels = context->resampled->channels;
  68. +#else
  69. + av_channel_layout_copy(&context->buffered->ch_layout, &context->resampled->ch_layout);
  70. +#endif
  71. context->buffered->format = context->resampled->format;
  72. context->buffered->nb_samples = context->context->frame_size;
  73. @@ -458,14 +473,20 @@ static BOOL ffmpeg_fill_frame(AVFrame* frame, const AUDIO_FORMAT* inputFormat, c
  74. size_t size)
  75. {
  76. int ret, bpp;
  77. +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 28, 100)
  78. frame->channels = inputFormat->nChannels;
  79. + frame->channel_layout = av_get_default_channel_layout(frame->channels);
  80. +#else
  81. + av_channel_layout_default(&frame->ch_layout, inputFormat->nChannels);
  82. +#endif
  83. frame->sample_rate = inputFormat->nSamplesPerSec;
  84. frame->format = ffmpeg_sample_format(inputFormat);
  85. - frame->channel_layout = av_get_default_channel_layout(frame->channels);
  86. +
  87. bpp = av_get_bytes_per_sample(frame->format);
  88. frame->nb_samples = size / inputFormat->nChannels / bpp;
  89. - if ((ret = avcodec_fill_audio_frame(frame, frame->channels, frame->format, data, size, 1)) < 0)
  90. + if ((ret = avcodec_fill_audio_frame(frame, inputFormat->nChannels, frame->format, data, size,
  91. + 1)) < 0)
  92. {
  93. const char* err = av_err2str(ret);
  94. WLog_ERR(TAG, "Error during audio frame fill %s [%d]", err, ret);
  95. @@ -547,7 +568,12 @@ static BOOL ffmpeg_decode(AVCodecContext* dec_ctx, AVPacket* pkt, AVFrame* frame
  96. }
  97. {
  98. - const size_t data_size = resampled->channels * resampled->nb_samples * 2;
  99. +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 28, 100)
  100. + const size_t channels = resampled->channels;
  101. +#else
  102. + const size_t channels = resampled->ch_layout.nb_channels;
  103. +#endif
  104. + const size_t data_size = channels * resampled->nb_samples * 2;
  105. Stream_EnsureRemainingCapacity(out, data_size);
  106. Stream_Write(out, resampled->data[0], data_size);
  107. }
  108. @@ -745,10 +771,14 @@ BOOL freerdp_dsp_ffmpeg_encode(FREERDP_DSP_CONTEXT* context, const AUDIO_FORMAT*
  109. if (inSamples + (int)context->bufferedSamples > context->context->frame_size)
  110. inSamples = context->context->frame_size - (int)context->bufferedSamples;
  111. - rc =
  112. - av_samples_copy(context->buffered->extended_data, context->resampled->extended_data,
  113. - (int)context->bufferedSamples, copied, inSamples,
  114. - context->context->channels, context->context->sample_fmt);
  115. +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 28, 100)
  116. + const int channels = context->context->channels;
  117. +#else
  118. + const int channels = context->context->ch_layout.nb_channels;
  119. +#endif
  120. + rc = av_samples_copy(context->buffered->extended_data,
  121. + context->resampled->extended_data, (int)context->bufferedSamples,
  122. + copied, inSamples, channels, context->context->sample_fmt);
  123. rest -= inSamples;
  124. copied += inSamples;
  125. context->bufferedSamples += (UINT32)inSamples;