File: ffmpeg5.1.patch

package info (click to toggle)
aubio 0.4.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,720 kB
  • sloc: python: 20,447; ansic: 20,127; makefile: 348; sh: 232
file content (97 lines) | stat: -rw-r--r-- 4,225 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
From: Paul Brossier <piem@piem.org>
Date: Tue, 7 Oct 2025 09:01:31 +0200
Subject: [source_avcodec] add support for AVChannelLayout (ffmpeg 5.1)

Origin: upstream, https://github.com/aubio/aubio/commit/0b947f9634937d27589d995ec90e90d763aca86f
Last-Update: 2024-09-17

Last-Update: 2024-09-17
---
 src/io/source_avcodec.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/io/source_avcodec.c b/src/io/source_avcodec.c
index 99615d0..517aca2 100644
--- a/src/io/source_avcodec.c
+++ b/src/io/source_avcodec.c
@@ -263,7 +263,11 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path,
 
   /* get input specs */
   s->input_samplerate = avCodecCtx->sample_rate;
+#ifdef AVUTIL_CHANNEL_LAYOUT_H
+  s->input_channels   = avCodecCtx->ch_layout.nb_channels;
+#else
   s->input_channels   = avCodecCtx->channels;
+#endif
   //AUBIO_DBG("input_samplerate: %d\n", s->input_samplerate);
   //AUBIO_DBG("input_channels: %d\n", s->input_channels);
 
@@ -316,16 +320,26 @@ void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s)
   // create or reset resampler to/from mono/multi-channel
   if ( s->avr == NULL ) {
     int err;
-    int64_t input_layout = av_get_default_channel_layout(s->input_channels);
-    int64_t output_layout = av_get_default_channel_layout(s->input_channels);
 #ifdef HAVE_AVRESAMPLE
     AVAudioResampleContext *avr = avresample_alloc_context();
 #elif defined(HAVE_SWRESAMPLE)
     SwrContext *avr = swr_alloc();
 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
+#ifdef AVUTIL_CHANNEL_LAYOUT_H
+    AVChannelLayout input_layout;
+    AVChannelLayout output_layout;
+    av_channel_layout_default(&input_layout, s->input_channels);
+    av_channel_layout_default(&output_layout, s->input_channels);
+
+    av_opt_set_chlayout(avr, "in_chlayout",  &input_layout,        0);
+    av_opt_set_chlayout(avr, "out_chlayout", &output_layout,       0);
+#else
+    int64_t input_layout = av_get_default_channel_layout(s->input_channels);
+    int64_t output_layout = av_get_default_channel_layout(s->input_channels);
 
     av_opt_set_int(avr, "in_channel_layout",  input_layout,              0);
     av_opt_set_int(avr, "out_channel_layout", output_layout,             0);
+#endif /* AVUTIL_CHANNEL_LAYOUT_H */
     av_opt_set_int(avr, "in_sample_rate",     s->input_samplerate,       0);
     av_opt_set_int(avr, "out_sample_rate",    s->samplerate,             0);
     av_opt_set_int(avr, "in_sample_fmt",      s->avCodecCtx->sample_fmt, 0);
@@ -373,7 +387,11 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s,
   int out_samples = 0;
 #elif defined(HAVE_SWRESAMPLE)
   int in_samples = avFrame->nb_samples;
+#ifdef AVUTIL_CHANNEL_LAYOUT_H
+  int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->ch_layout.nb_channels;
+#else
   int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
+#endif
   int out_samples = 0;
 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
   smpl_t *output = s->output;
@@ -440,10 +458,15 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s,
   }
 
 #if LIBAVUTIL_VERSION_MAJOR > 52
-  if (avFrame->channels != (sint_t)s->input_channels) {
+#ifdef AVUTIL_CHANNEL_LAYOUT_H
+  int frame_channels = avFrame->ch_layout.nb_channels;
+#else
+  int frame_channels = avFrame->channels;
+#endif
+  if (frame_channels != (sint_t)s->input_channels) {
     AUBIO_WRN ("source_avcodec: trying to read from %d channel(s),"
         "but configured for %d; is '%s' corrupt?\n",
-        avFrame->channels, s->input_channels, s->path);
+        frame_channels, s->input_channels, s->path);
     goto beach;
   }
 #else
@@ -462,7 +485,8 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s,
         (uint8_t **)avFrame->data, in_linesize, in_samples);
 #elif defined(HAVE_SWRESAMPLE)
   in_samples = avFrame->nb_samples;
-  max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
+  max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
+  if (frame_channels > 0) max_out_samples /= frame_channels;
   out_samples = swr_convert( avr,
       (uint8_t **)&output, max_out_samples,
       (const uint8_t **)avFrame->data, in_samples);