]> git.pld-linux.org Git - packages/pipewire.git/blame - pipewire-lc3plus.patch
up to 1.0.5
[packages/pipewire.git] / pipewire-lc3plus.patch
CommitLineData
0a4d9274
JB
1Adjust for LC3plus 1.4.1
2--- pipewire-1.0.4/spa/plugins/bluez5/a2dp-codec-lc3plus.c.orig 2024-03-13 09:22:08.000000000 +0100
3+++ pipewire-1.0.4/spa/plugins/bluez5/a2dp-codec-lc3plus.c 2024-03-23 16:29:16.174945983 +0100
4@@ -331,7 +331,9 @@ static void *codec_init(const struct med
5 struct spa_audio_info config_info;
6 int size;
7 int res;
8+ int32_t lfe[LC3PLUS_MAX_CHANNELS];
9
10+ memset(lfe, 0, sizeof(lfe));
11 if (info->media_type != SPA_MEDIA_TYPE_audio ||
12 info->media_subtype != SPA_MEDIA_SUBTYPE_raw ||
13 info->info.raw.format != SPA_AUDIO_FORMAT_S24_32) {
14@@ -371,15 +373,11 @@ static void *codec_init(const struct med
15 }
16 if ((this->enc = calloc(1, size)) == NULL)
17 goto error_errno;
18- if (lc3plus_enc_init(this->enc, this->samplerate, this->channels) != LC3PLUS_OK) {
19+ if (lc3plus_enc_init(this->enc, this->samplerate, this->channels, 1, lfe) != LC3PLUS_OK) {
20 res = -EINVAL;
21 goto error;
22 }
23- if (lc3plus_enc_set_frame_ms(this->enc, this->frame_dms/10.0f) != LC3PLUS_OK) {
24- res = -EINVAL;
25- goto error;
26- }
27- if (lc3plus_enc_set_hrmode(this->enc, 1) != LC3PLUS_OK) {
28+ if (lc3plus_enc_set_frame_dms(this->enc, this->frame_dms) != LC3PLUS_OK) {
29 res = -EINVAL;
30 goto error;
31 }
32@@ -400,15 +398,11 @@ static void *codec_init(const struct med
33 }
34 if ((this->dec = calloc(1, size)) == NULL)
35 goto error_errno;
36- if (lc3plus_dec_init(this->dec, this->samplerate, this->channels, LC3PLUS_PLC_ADVANCED) != LC3PLUS_OK) {
37+ if (lc3plus_dec_init(this->dec, this->samplerate, this->channels, LC3PLUS_PLC_ADVANCED, 1) != LC3PLUS_OK) {
38 res = -EINVAL;
39 goto error;
40 }
41- if (lc3plus_dec_set_frame_ms(this->dec, this->frame_dms/10.0f) != LC3PLUS_OK) {
42- res = -EINVAL;
43- goto error;
44- }
45- if (lc3plus_dec_set_hrmode(this->dec, 1) != LC3PLUS_OK) {
46+ if (lc3plus_dec_set_frame_dms(this->dec, this->frame_dms) != LC3PLUS_OK) {
47 res = -EINVAL;
48 goto error;
49 }
50@@ -533,6 +527,13 @@ static int codec_encode(void *data,
51 int size, processed;
52 int header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
53 int32_t *inputs[2];
54+ void *scratch = NULL;
55+
56+#ifdef LC3PLUS_ENC_MAX_SCRATCH_SIZE
57+ scratch = malloc(LC3PLUS_ENC_MAX_SCRATCH_SIZE);
58+ if (scratch == NULL)
59+ return -ENOMEM;
60+#endif
61
62 if (src == NULL) {
63 /* Produce fragment packets.
64@@ -545,6 +546,9 @@ static int codec_encode(void *data,
65 this->e.fragment < dst ||
66 SPA_PTROFF(this->e.fragment, this->e.fragment_size, void) > SPA_PTROFF(dst, dst_size, void)) {
67 this->e.fragment = NULL;
68+#ifdef LC3PLUS_ENC_MAX_SCRATCH_SIZE
69+ free(scratch);
70+#endif
71 return -EINVAL;
72 }
73
74@@ -564,6 +568,9 @@ static int codec_encode(void *data,
75 this->e.fragment = NULL;
76 *need_flush = NEED_FLUSH_ALL;
77 }
78+#ifdef LC3PLUS_ENC_MAX_SCRATCH_SIZE
79+ free(scratch);
80+#endif
81 return 0;
82 }
83
84@@ -580,15 +587,19 @@ static int codec_encode(void *data,
85
86 if (this->channels == 1) {
87 inputs[0] = (int32_t *)src;
88- res = lc3plus_enc24(this->enc, inputs, dst, &size);
89+ res = lc3plus_enc24(this->enc, inputs, dst, &size, scratch);
90 } else {
91 inputs[0] = this->buf[0];
92 inputs[1] = this->buf[1];
93 deinterleave_32_c2(inputs, src, this->e.samples);
94- res = lc3plus_enc24(this->enc, inputs, dst, &size);
95+ res = lc3plus_enc24(this->enc, inputs, dst, &size, scratch);
96 }
97- if (SPA_UNLIKELY(res != LC3PLUS_OK))
98+ if (SPA_UNLIKELY(res != LC3PLUS_OK)) {
99+#ifdef LC3PLUS_ENC_MAX_SCRATCH_SIZE
100+ free(scratch);
101+#endif
102 return -EINVAL;
103+ }
104 *dst_out = size;
105
106 processed += this->e.codesize;
107@@ -596,6 +607,9 @@ static int codec_encode(void *data,
108 this->e.payload->frame_count++;
109
110 done:
111+#ifdef LC3PLUS_ENC_MAX_SCRATCH_SIZE
112+ free(scratch);
113+#endif
114 if (this->e.payload->frame_count == 0)
115 return processed;
116 if (this->e.payload->frame_count < 0xf &&
117@@ -678,7 +692,13 @@ static SPA_UNUSED int codec_decode(void
118 int32_t *outputs[2];
119 int consumed;
120 int samples;
121+ void *scratch = NULL;
122
123+#ifdef LC3PLUS_DEC_MAX_SCRATCH_SIZE
124+ scratch = malloc(LC3PLUS_DEC_MAX_SCRATCH_SIZE);
125+ if (scratch == NULL)
126+ return -ENOMEM;
127+#endif
128 if (this->d.fragment_count > 0) {
129 /* Fragmented frame */
130 size_t avail;
131@@ -691,6 +711,9 @@ static SPA_UNUSED int codec_decode(void
132 if (this->d.fragment_count > 1) {
133 /* More fragments to come */
134 *dst_out = 0;
135+#ifdef LC3PLUS_DEC_MAX_SCRATCH_SIZE
136+ free(scratch);
137+#endif
138 return consumed;
139 }
140
141@@ -706,18 +729,25 @@ static SPA_UNUSED int codec_decode(void
142
143 samples = lc3plus_dec_get_output_samples(this->dec);
144 *dst_out = samples * this->channels * sizeof(int32_t);
145- if (dst_size < *dst_out)
146+ if (dst_size < *dst_out) {
147+#ifdef LC3PLUS_DEC_MAX_SCRATCH_SIZE
148+ free(scratch);
149+#endif
150 return -EINVAL;
151+ }
152
153 if (this->channels == 1) {
154 outputs[0] = (int32_t *)dst;
155- res = lc3plus_dec24(this->dec, (void *)src, src_size, outputs, 0);
156+ res = lc3plus_dec24(this->dec, (void *)src, src_size, outputs, scratch, 0);
157 } else {
158 outputs[0] = this->buf[0];
159 outputs[1] = this->buf[1];
160- res = lc3plus_dec24(this->dec, (void *)src, src_size, outputs, 0);
161+ res = lc3plus_dec24(this->dec, (void *)src, src_size, outputs, scratch, 0);
162 interleave_32_c2(dst, (const int32_t**)outputs, samples);
163 }
164+#ifdef LC3PLUS_DEC_MAX_SCRATCH_SIZE
165+ free(scratch);
166+#endif
167 if (SPA_UNLIKELY(res != LC3PLUS_OK && res != LC3PLUS_DECODE_ERROR))
168 return -EINVAL;
169
This page took 0.065168 seconds and 4 git commands to generate.