converter/tospdif: full rewrite
[vlc.git] / src / audio_output / common.c
blob60438c68f907ae054345e0f7c393da528d96ed94
1 /*****************************************************************************
2 * common.c : audio output management of common data structures
3 *****************************************************************************
4 * Copyright (C) 2002-2007 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <limits.h>
29 #include <assert.h>
31 #include <vlc_common.h>
32 #include <vlc_aout.h>
33 #include "aout_internal.h"
36 * Formats management (internal and external)
39 /*****************************************************************************
40 * aout_BitsPerSample : get the number of bits per sample
41 *****************************************************************************/
42 unsigned int aout_BitsPerSample( vlc_fourcc_t i_format )
44 switch( vlc_fourcc_GetCodec( AUDIO_ES, i_format ) )
46 case VLC_CODEC_U8:
47 case VLC_CODEC_S8:
48 case VLC_CODEC_ALAW:
49 case VLC_CODEC_MULAW:
50 return 8;
52 case VLC_CODEC_U16L:
53 case VLC_CODEC_S16L:
54 case VLC_CODEC_U16B:
55 case VLC_CODEC_S16B:
56 return 16;
58 case VLC_CODEC_U24L:
59 case VLC_CODEC_S24L:
60 case VLC_CODEC_U24B:
61 case VLC_CODEC_S24B:
62 return 24;
64 case VLC_CODEC_S24L32:
65 case VLC_CODEC_S24B32:
66 case VLC_CODEC_U32L:
67 case VLC_CODEC_U32B:
68 case VLC_CODEC_S32L:
69 case VLC_CODEC_S32B:
70 case VLC_CODEC_F32L:
71 case VLC_CODEC_F32B:
72 return 32;
74 case VLC_CODEC_F64L:
75 case VLC_CODEC_F64B:
76 return 64;
78 default:
79 /* For these formats the caller has to indicate the parameters
80 * by hand. */
81 return 0;
85 /*****************************************************************************
86 * aout_FormatPrepare : compute the number of bytes per frame & frame length
87 *****************************************************************************/
88 void aout_FormatPrepare( audio_sample_format_t * p_format )
90 p_format->i_channels = aout_FormatNbChannels( p_format );
91 p_format->i_bitspersample = aout_BitsPerSample( p_format->i_format );
92 if( p_format->i_bitspersample > 0 )
94 p_format->i_bytes_per_frame = ( p_format->i_bitspersample / 8 )
95 * p_format->i_channels;
96 p_format->i_frame_length = 1;
100 /*****************************************************************************
101 * aout_FormatPrintChannels : print a channel in a human-readable form
102 *****************************************************************************/
103 const char * aout_FormatPrintChannels( const audio_sample_format_t * p_format )
105 switch ( p_format->i_physical_channels )
107 case AOUT_CHAN_LEFT:
108 case AOUT_CHAN_RIGHT:
109 case AOUT_CHAN_CENTER:
110 if ( (p_format->i_original_channels & AOUT_CHAN_CENTER)
111 || (p_format->i_original_channels
112 & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
113 return "Mono";
114 else if ( p_format->i_original_channels & AOUT_CHAN_LEFT )
115 return "Left";
116 return "Right";
117 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT:
118 if ( p_format->i_original_channels & AOUT_CHAN_REVERSESTEREO )
120 if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
121 return "Dolby/Reverse";
122 return "Stereo/Reverse";
124 else
126 if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
127 return "Dolby";
128 else if ( p_format->i_original_channels & AOUT_CHAN_DUALMONO )
129 return "Dual-mono";
130 else if ( p_format->i_original_channels == AOUT_CHAN_CENTER )
131 return "Stereo/Mono";
132 else if ( !(p_format->i_original_channels & AOUT_CHAN_RIGHT) )
133 return "Stereo/Left";
134 else if ( !(p_format->i_original_channels & AOUT_CHAN_LEFT) )
135 return "Stereo/Right";
136 return "Stereo";
138 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER:
139 return "3F";
140 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER:
141 return "2F1R";
142 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
143 | AOUT_CHAN_REARCENTER:
144 return "3F1R";
145 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
146 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
147 return "2F2R";
148 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
149 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT:
150 return "2F2M";
151 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
152 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
153 return "3F2R";
154 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
155 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT:
156 return "3F2M";
158 case AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
159 if ( (p_format->i_original_channels & AOUT_CHAN_CENTER)
160 || (p_format->i_original_channels
161 & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
162 return "Mono/LFE";
163 else if ( p_format->i_original_channels & AOUT_CHAN_LEFT )
164 return "Left/LFE";
165 return "Right/LFE";
166 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_LFE:
167 if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
168 return "Dolby/LFE";
169 else if ( p_format->i_original_channels & AOUT_CHAN_DUALMONO )
170 return "Dual-mono/LFE";
171 else if ( p_format->i_original_channels == AOUT_CHAN_CENTER )
172 return "Mono/LFE";
173 else if ( !(p_format->i_original_channels & AOUT_CHAN_RIGHT) )
174 return "Stereo/Left/LFE";
175 else if ( !(p_format->i_original_channels & AOUT_CHAN_LEFT) )
176 return "Stereo/Right/LFE";
177 return "Stereo/LFE";
178 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
179 return "3F/LFE";
180 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER
181 | AOUT_CHAN_LFE:
182 return "2F1R/LFE";
183 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
184 | AOUT_CHAN_REARCENTER | AOUT_CHAN_LFE:
185 return "3F1R/LFE";
186 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
187 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
188 return "2F2R/LFE";
189 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
190 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
191 return "2F2M/LFE";
192 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
193 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
194 return "3F2R/LFE";
195 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
196 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
197 return "3F2M/LFE";
198 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
199 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
200 | AOUT_CHAN_MIDDLERIGHT:
201 return "3F2M2R";
202 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
203 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
204 | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
205 return "3F2M2R/LFE";
206 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
207 | AOUT_CHAN_REARCENTER | AOUT_CHAN_MIDDLELEFT
208 | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
209 return "3F2M1R/LFE";
210 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
211 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_REARCENTER
212 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
213 return "3F2M3R/LFE";
216 return "ERROR";
219 #undef aout_FormatPrint
221 * Prints an audio sample format in a human-readable form.
223 void aout_FormatPrint( vlc_object_t *obj, const char *psz_text,
224 const audio_sample_format_t *p_format )
226 msg_Dbg( obj, "%s '%4.4s' %d Hz %s frame=%d samples/%d bytes", psz_text,
227 (char *)&p_format->i_format, p_format->i_rate,
228 aout_FormatPrintChannels( p_format ),
229 p_format->i_frame_length, p_format->i_bytes_per_frame );
232 #undef aout_FormatsPrint
234 * Prints two formats in a human-readable form
236 void aout_FormatsPrint( vlc_object_t *obj, const char * psz_text,
237 const audio_sample_format_t * p_format1,
238 const audio_sample_format_t * p_format2 )
240 msg_Dbg( obj, "%s '%4.4s'->'%4.4s' %d Hz->%d Hz %s->%s",
241 psz_text,
242 (char *)&p_format1->i_format, (char *)&p_format2->i_format,
243 p_format1->i_rate, p_format2->i_rate,
244 aout_FormatPrintChannels( p_format1 ),
245 aout_FormatPrintChannels( p_format2 ) );
248 /*****************************************************************************
249 * aout_CheckChannelReorder : Check if we need to do some channel re-ordering
250 *****************************************************************************/
251 unsigned aout_CheckChannelReorder( const uint32_t *chans_in,
252 const uint32_t *chans_out,
253 uint32_t mask, uint8_t *restrict table )
255 static_assert(AOUT_CHAN_MAX <= (sizeof (mask) * CHAR_BIT), "Missing bits");
257 unsigned channels = 0;
259 if( chans_in == NULL )
260 chans_in = pi_vlc_chan_order_wg4;
261 if( chans_out == NULL )
262 chans_out = pi_vlc_chan_order_wg4;
264 for( unsigned i = 0; chans_in[i]; i++ )
266 const uint32_t chan = chans_in[i];
267 if( !(mask & chan) )
268 continue;
270 unsigned index = 0;
271 for( unsigned j = 0; chan != chans_out[j]; j++ )
272 if( mask & chans_out[j] )
273 index++;
275 table[channels++] = index;
278 for( unsigned i = 0; i < channels; i++ )
279 if( table[i] != i )
280 return channels;
281 return 0;
285 * Reorders audio samples within a block of linear audio interleaved samples.
286 * \param ptr start address of the block of samples
287 * \param bytes size of the block in bytes (must be a multiple of the product
288 * of the channels count and the sample size)
289 * \param channels channels count (also length of the chans_table table)
290 * \param chans_table permutation table to reorder the channels
291 * (usually computed by aout_CheckChannelReorder())
292 * \param fourcc sample format (must be a linear sample format)
293 * \note The samples must be naturally aligned in memory.
295 void aout_ChannelReorder( void *ptr, size_t bytes, uint8_t channels,
296 const uint8_t *restrict chans_table, vlc_fourcc_t fourcc )
298 if( unlikely(bytes == 0) )
299 return;
301 assert( channels != 0 );
303 /* The audio formats supported in audio output are inlined. For other
304 * formats (used in demuxers and muxers), memcpy() is used to avoid
305 * breaking type punning. */
306 #define REORDER_TYPE(type) \
307 do { \
308 const size_t frames = (bytes / sizeof (type)) / channels; \
309 type *buf = ptr; \
311 for( size_t i = 0; i < frames; i++ ) \
313 type tmp[AOUT_CHAN_MAX]; \
315 for( size_t j = 0; j < channels; j++ ) \
316 tmp[chans_table[j]] = buf[j]; \
317 memcpy( buf, tmp, sizeof (type) * channels ); \
318 buf += channels; \
320 } while(0)
322 if( likely(channels <= AOUT_CHAN_MAX) )
324 switch( fourcc )
326 case VLC_CODEC_U8: REORDER_TYPE(uint8_t); return;
327 case VLC_CODEC_S16N: REORDER_TYPE(int16_t); return;
328 case VLC_CODEC_FL32: REORDER_TYPE(float); return;
329 case VLC_CODEC_S32N: REORDER_TYPE(int32_t); return;
330 case VLC_CODEC_FL64: REORDER_TYPE(double); return;
334 unsigned size = aout_BitsPerSample( fourcc ) / 8;
335 assert( size != 0 && size <= 8 );
337 const size_t frames = bytes / (size * channels);
338 unsigned char *buf = ptr;
340 for( size_t i = 0; i < frames; i++ )
342 unsigned char tmp[256 * 8];
344 for( size_t j = 0; j < channels; j++ )
345 memcpy( tmp + size * chans_table[j], buf + size * j, size );
346 memcpy( buf, tmp, size * channels );
347 buf += size * channels;
352 * Interleaves audio samples within a block of samples.
353 * \param dst destination buffer for interleaved samples
354 * \param srcv source buffers (one per plane) of uninterleaved samples
355 * \param samples number of samples (per channel/per plane)
356 * \param chans channels/planes count
357 * \param fourcc sample format (must be a linear sample format)
358 * \note The samples must be naturally aligned in memory.
359 * \warning Destination and source buffers MUST NOT overlap.
361 void aout_Interleave( void *restrict dst, const void *const *srcv,
362 unsigned samples, unsigned chans, vlc_fourcc_t fourcc )
364 #define INTERLEAVE_TYPE(type) \
365 do { \
366 type *d = dst; \
367 for( size_t i = 0; i < chans; i++ ) { \
368 const type *s = srcv[i]; \
369 for( size_t j = 0, k = 0; j < samples; j++, k += chans ) \
370 d[k] = *(s++); \
371 d++; \
373 } while(0)
375 switch( fourcc )
377 case VLC_CODEC_U8: INTERLEAVE_TYPE(uint8_t); break;
378 case VLC_CODEC_S16N: INTERLEAVE_TYPE(uint16_t); break;
379 case VLC_CODEC_FL32: INTERLEAVE_TYPE(float); break;
380 case VLC_CODEC_S32N: INTERLEAVE_TYPE(int32_t); break;
381 case VLC_CODEC_FL64: INTERLEAVE_TYPE(double); break;
382 default: vlc_assert_unreachable();
384 #undef INTERLEAVE_TYPE
388 * Deinterleaves audio samples within a block of samples.
389 * \param dst destination buffer for planar samples
390 * \param src source buffer with interleaved samples
391 * \param samples number of samples (per channel/per plane)
392 * \param chans channels/planes count
393 * \param fourcc sample format (must be a linear sample format)
394 * \note The samples must be naturally aligned in memory.
395 * \warning Destination and source buffers MUST NOT overlap.
397 void aout_Deinterleave( void *restrict dst, const void *restrict src,
398 unsigned samples, unsigned chans, vlc_fourcc_t fourcc )
400 #define DEINTERLEAVE_TYPE(type) \
401 do { \
402 type *d = dst; \
403 const type *s = src; \
404 for( size_t i = 0; i < chans; i++ ) { \
405 for( size_t j = 0, k = 0; j < samples; j++, k += chans ) \
406 *(d++) = s[k]; \
407 s++; \
409 } while(0)
411 switch( fourcc )
413 case VLC_CODEC_U8: DEINTERLEAVE_TYPE(uint8_t); break;
414 case VLC_CODEC_S16N: DEINTERLEAVE_TYPE(uint16_t); break;
415 case VLC_CODEC_FL32: DEINTERLEAVE_TYPE(float); break;
416 case VLC_CODEC_S32N: DEINTERLEAVE_TYPE(int32_t); break;
417 case VLC_CODEC_FL64: DEINTERLEAVE_TYPE(double); break;
418 default: vlc_assert_unreachable();
420 #undef DEINTERLEAVE_TYPE
423 /*****************************************************************************
424 * aout_ChannelExtract:
425 *****************************************************************************/
426 static inline void ExtractChannel( uint8_t *pi_dst, int i_dst_channels,
427 const uint8_t *pi_src, int i_src_channels,
428 int i_sample_count,
429 const int *pi_selection, int i_bytes )
431 for( int i = 0; i < i_sample_count; i++ )
433 for( int j = 0; j < i_dst_channels; j++ )
434 memcpy( &pi_dst[j * i_bytes], &pi_src[pi_selection[j] * i_bytes], i_bytes );
435 pi_dst += i_dst_channels * i_bytes;
436 pi_src += i_src_channels * i_bytes;
440 void aout_ChannelExtract( void *p_dst, int i_dst_channels,
441 const void *p_src, int i_src_channels,
442 int i_sample_count, const int *pi_selection, int i_bits_per_sample )
444 /* It does not work in place */
445 assert( p_dst != p_src );
447 /* Force the compiler to inline for the specific cases so it can optimize */
448 if( i_bits_per_sample == 8 )
449 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 1 );
450 else if( i_bits_per_sample == 16 )
451 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 2 );
452 else if( i_bits_per_sample == 32 )
453 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 4 );
454 else if( i_bits_per_sample == 64 )
455 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 8 );
458 bool aout_CheckChannelExtraction( int *pi_selection,
459 uint32_t *pi_layout, int *pi_channels,
460 const uint32_t pi_order_dst[AOUT_CHAN_MAX],
461 const uint32_t *pi_order_src, int i_channels )
463 static_assert(AOUT_CHAN_MAX <= (sizeof (*pi_order_dst) * CHAR_BIT),
464 "Missing bits");
466 const uint32_t pi_order_dual_mono[] = { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT };
467 uint32_t i_layout = 0;
468 int i_out = 0;
469 int pi_index[AOUT_CHAN_MAX];
471 /* */
472 if( !pi_order_dst )
473 pi_order_dst = pi_vlc_chan_order_wg4;
475 /* Detect special dual mono case */
476 if( i_channels == 2 &&
477 pi_order_src[0] == AOUT_CHAN_CENTER && pi_order_src[1] == AOUT_CHAN_CENTER )
479 i_layout |= AOUT_CHAN_DUALMONO;
480 pi_order_src = pi_order_dual_mono;
483 /* */
484 for( int i = 0; i < i_channels; i++ )
486 /* Ignore unknown or duplicated channels or not present in output */
487 if( !pi_order_src[i] || (i_layout & pi_order_src[i]) )
488 continue;
490 for( int j = 0; j < AOUT_CHAN_MAX; j++ )
492 if( pi_order_dst[j] == pi_order_src[i] )
494 assert( i_out < AOUT_CHAN_MAX );
495 pi_index[i_out++] = i;
496 i_layout |= pi_order_src[i];
497 break;
502 /* */
503 for( int i = 0, j = 0; i < AOUT_CHAN_MAX; i++ )
505 for( int k = 0; k < i_out; k++ )
507 if( pi_order_dst[i] == pi_order_src[pi_index[k]] )
509 pi_selection[j++] = pi_index[k];
510 break;
515 *pi_layout = i_layout;
516 *pi_channels = i_out;
518 for( int i = 0; i < i_out; i++ )
520 if( pi_selection[i] != i )
521 return true;
523 return i_out != i_channels;
526 /* Return the order in which filters should be inserted */
527 static int FilterOrder( const char *psz_name )
529 static const struct {
530 const char psz_name[10];
531 int i_order;
532 } filter[] = {
533 { "equalizer", 0 },
535 for( unsigned i = 0; i < ARRAY_SIZE(filter); i++ )
537 if( !strcmp( filter[i].psz_name, psz_name ) )
538 return filter[i].i_order;
540 return INT_MAX;
543 /* This function will add or remove a module from a string list (colon
544 * separated). It will return true if there is a modification
545 * In case p_aout is NULL, we will use configuration instead of variable */
546 bool aout_ChangeFilterString( vlc_object_t *p_obj, vlc_object_t *p_aout,
547 const char *psz_variable,
548 const char *psz_name, bool b_add )
550 if( *psz_name == '\0' )
551 return false;
553 char *psz_list;
554 if( p_aout )
556 psz_list = var_GetString( p_aout, psz_variable );
558 else
560 psz_list = var_CreateGetString( p_obj->obj.libvlc, psz_variable );
561 var_Destroy( p_obj->obj.libvlc, psz_variable );
564 /* Split the string into an array of filters */
565 int i_count = 1;
566 for( char *p = psz_list; p && *p; p++ )
567 i_count += *p == ':';
568 i_count += b_add;
570 const char **ppsz_filter = calloc( i_count, sizeof(*ppsz_filter) );
571 if( !ppsz_filter )
573 free( psz_list );
574 return false;
576 bool b_present = false;
577 i_count = 0;
578 for( char *p = psz_list; p && *p; )
580 char *psz_end = strchr(p, ':');
581 if( psz_end )
582 *psz_end++ = '\0';
583 else
584 psz_end = p + strlen(p);
585 if( *p )
587 b_present |= !strcmp( p, psz_name );
588 ppsz_filter[i_count++] = p;
590 p = psz_end;
592 if( b_present == b_add )
594 free( ppsz_filter );
595 free( psz_list );
596 return false;
599 if( b_add )
601 int i_order = FilterOrder( psz_name );
602 int i;
603 for( i = 0; i < i_count; i++ )
605 if( FilterOrder( ppsz_filter[i] ) > i_order )
606 break;
608 if( i < i_count )
609 memmove( &ppsz_filter[i+1], &ppsz_filter[i], (i_count - i) * sizeof(*ppsz_filter) );
610 ppsz_filter[i] = psz_name;
611 i_count++;
613 else
615 for( int i = 0; i < i_count; i++ )
617 if( !strcmp( ppsz_filter[i], psz_name ) )
618 ppsz_filter[i] = "";
621 size_t i_length = 0;
622 for( int i = 0; i < i_count; i++ )
623 i_length += 1 + strlen( ppsz_filter[i] );
625 char *psz_new = malloc( i_length + 1 );
627 if( unlikely( !psz_new ) )
629 free( ppsz_filter );
630 free( psz_list );
631 return false;
634 *psz_new = '\0';
635 for( int i = 0; i < i_count; i++ )
637 if( *ppsz_filter[i] == '\0' )
638 continue;
639 if( *psz_new )
640 strcat( psz_new, ":" );
641 strcat( psz_new, ppsz_filter[i] );
643 free( ppsz_filter );
644 free( psz_list );
646 if( p_aout )
647 var_SetString( p_aout, psz_variable, psz_new );
648 else
649 config_PutPsz( p_obj, psz_variable, psz_new );
650 free( psz_new );
652 return true;