qt: playlist: use item title if available
[vlc.git] / src / audio_output / common.c
blob9ed3a8254677c4567c4fdc9f5795cf0518f99a3d
1 /*****************************************************************************
2 * common.c : audio output management of common data structures
3 *****************************************************************************
4 * Copyright (C) 2002-2007 VLC authors and VideoLAN
6 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <limits.h>
28 #include <assert.h>
30 #include <vlc_common.h>
31 #include <vlc_aout.h>
32 #include "aout_internal.h"
35 * Formats management (internal and external)
38 /*****************************************************************************
39 * aout_BitsPerSample : get the number of bits per sample
40 *****************************************************************************/
41 unsigned int aout_BitsPerSample( vlc_fourcc_t i_format )
43 switch( vlc_fourcc_GetCodec( AUDIO_ES, i_format ) )
45 case VLC_CODEC_U8:
46 case VLC_CODEC_S8:
47 case VLC_CODEC_ALAW:
48 case VLC_CODEC_MULAW:
49 return 8;
51 case VLC_CODEC_U16L:
52 case VLC_CODEC_S16L:
53 case VLC_CODEC_U16B:
54 case VLC_CODEC_S16B:
55 return 16;
57 case VLC_CODEC_U24L:
58 case VLC_CODEC_S24L:
59 case VLC_CODEC_U24B:
60 case VLC_CODEC_S24B:
61 return 24;
63 case VLC_CODEC_S24L32:
64 case VLC_CODEC_S24B32:
65 case VLC_CODEC_U32L:
66 case VLC_CODEC_U32B:
67 case VLC_CODEC_S32L:
68 case VLC_CODEC_S32B:
69 case VLC_CODEC_F32L:
70 case VLC_CODEC_F32B:
71 return 32;
73 case VLC_CODEC_F64L:
74 case VLC_CODEC_F64B:
75 return 64;
77 default:
78 /* For these formats the caller has to indicate the parameters
79 * by hand. */
80 return 0;
84 /*****************************************************************************
85 * aout_FormatPrepare : compute the number of bytes per frame & frame length
86 *****************************************************************************/
87 void aout_FormatPrepare( audio_sample_format_t * p_format )
90 unsigned i_channels = aout_FormatNbChannels( p_format );
91 if( i_channels > 0 )
92 p_format->i_channels = i_channels;
93 p_format->i_bitspersample = aout_BitsPerSample( p_format->i_format );
94 if( p_format->i_bitspersample > 0 )
96 p_format->i_bytes_per_frame = ( p_format->i_bitspersample / 8 )
97 * p_format->i_channels;
98 p_format->i_frame_length = 1;
102 /*****************************************************************************
103 * aout_FormatPrintChannels : print a channel in a human-readable form
104 *****************************************************************************/
105 const char * aout_FormatPrintChannels( const audio_sample_format_t * p_format )
107 if (p_format->channel_type == AUDIO_CHANNEL_TYPE_AMBISONICS)
108 return "Ambisonics";
110 /* AUDIO_CHANNEL_TYPE_BITMAP */
111 switch ( p_format->i_physical_channels )
113 case AOUT_CHAN_LEFT:
114 case AOUT_CHAN_RIGHT:
115 case AOUT_CHAN_CENTER:
116 if ( (p_format->i_physical_channels & AOUT_CHAN_CENTER)
117 || (p_format->i_physical_channels
118 & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
119 return "Mono";
120 else if ( p_format->i_physical_channels & AOUT_CHAN_LEFT )
121 return "Left";
122 return "Right";
123 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT:
124 if ( p_format->i_chan_mode & AOUT_CHANMODE_DOLBYSTEREO )
125 return "Dolby";
126 else if ( p_format->i_chan_mode & AOUT_CHANMODE_DUALMONO )
127 return "Dual-mono";
128 else if ( p_format->i_physical_channels == AOUT_CHAN_CENTER )
129 return "Stereo/Mono";
130 else if ( !(p_format->i_physical_channels & AOUT_CHAN_RIGHT) )
131 return "Stereo/Left";
132 else if ( !(p_format->i_physical_channels & AOUT_CHAN_LEFT) )
133 return "Stereo/Right";
134 return "Stereo";
135 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER:
136 return "3F";
137 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER:
138 return "2F1R";
139 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
140 | AOUT_CHAN_REARCENTER:
141 return "3F1R";
142 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
143 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
144 return "2F2R";
145 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
146 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT:
147 return "2F2M";
148 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
149 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
150 return "3F2R";
151 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
152 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT:
153 return "3F2M";
155 case AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
156 if ( (p_format->i_physical_channels & AOUT_CHAN_CENTER)
157 || (p_format->i_physical_channels
158 & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
159 return "Mono/LFE";
160 else if ( p_format->i_physical_channels & AOUT_CHAN_LEFT )
161 return "Left/LFE";
162 return "Right/LFE";
163 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_LFE:
164 if ( p_format->i_chan_mode & AOUT_CHANMODE_DOLBYSTEREO )
165 return "Dolby/LFE";
166 else if ( p_format->i_chan_mode & AOUT_CHANMODE_DUALMONO )
167 return "Dual-mono/LFE";
168 else if ( p_format->i_physical_channels == AOUT_CHAN_CENTER )
169 return "Mono/LFE";
170 else if ( !(p_format->i_physical_channels & AOUT_CHAN_RIGHT) )
171 return "Stereo/Left/LFE";
172 else if ( !(p_format->i_physical_channels & AOUT_CHAN_LEFT) )
173 return "Stereo/Right/LFE";
174 return "Stereo/LFE";
175 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
176 return "3F/LFE";
177 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER
178 | AOUT_CHAN_LFE:
179 return "2F1R/LFE";
180 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
181 | AOUT_CHAN_REARCENTER | AOUT_CHAN_LFE:
182 return "3F1R/LFE";
183 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
184 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
185 return "2F2R/LFE";
186 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
187 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
188 return "2F2M/LFE";
189 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
190 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
191 return "3F2R/LFE";
192 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
193 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_REARCENTER
194 | AOUT_CHAN_LFE:
195 return "3F3R/LFE";
196 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
197 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
198 return "3F2M/LFE";
199 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
200 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
201 | AOUT_CHAN_MIDDLERIGHT:
202 return "2F2M2R";
203 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
204 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
205 | AOUT_CHAN_MIDDLERIGHT:
206 return "3F2M2R";
207 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
208 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
209 | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
210 return "3F2M2R/LFE";
211 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
212 | AOUT_CHAN_REARCENTER | AOUT_CHAN_MIDDLELEFT
213 | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
214 return "3F2M1R/LFE";
215 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
216 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_REARCENTER
217 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
218 return "3F2M3R/LFE";
221 return "Unknown-chan-mask";
224 #undef aout_FormatPrint
226 * Prints an audio sample format in a human-readable form.
228 void aout_FormatPrint( vlc_object_t *obj, const char *psz_text,
229 const audio_sample_format_t *p_format )
231 msg_Dbg( obj, "%s '%4.4s' %d Hz %s frame=%u samples/%u bytes", psz_text,
232 (char *)&p_format->i_format, p_format->i_rate,
233 aout_FormatPrintChannels( p_format ),
234 p_format->i_frame_length, p_format->i_bytes_per_frame );
237 #undef aout_FormatsPrint
239 * Prints two formats in a human-readable form
241 void aout_FormatsPrint( vlc_object_t *obj, const char * psz_text,
242 const audio_sample_format_t * p_format1,
243 const audio_sample_format_t * p_format2 )
245 msg_Dbg( obj, "%s '%4.4s'->'%4.4s' %u Hz->%u Hz %s->%s",
246 psz_text,
247 (char *)&p_format1->i_format, (char *)&p_format2->i_format,
248 p_format1->i_rate, p_format2->i_rate,
249 aout_FormatPrintChannels( p_format1 ),
250 aout_FormatPrintChannels( p_format2 ) );
253 /*****************************************************************************
254 * aout_CheckChannelReorder : Check if we need to do some channel re-ordering
255 *****************************************************************************/
256 unsigned aout_CheckChannelReorder( const uint32_t *chans_in,
257 const uint32_t *chans_out,
258 uint32_t mask, uint8_t *restrict table )
260 static_assert(AOUT_CHAN_MAX <= (sizeof (mask) * CHAR_BIT), "Missing bits");
262 unsigned channels = 0;
264 if( chans_in == NULL )
265 chans_in = pi_vlc_chan_order_wg4;
266 if( chans_out == NULL )
267 chans_out = pi_vlc_chan_order_wg4;
269 for( unsigned i = 0; chans_in[i]; i++ )
271 const uint32_t chan = chans_in[i];
272 if( !(mask & chan) )
273 continue;
275 unsigned index = 0;
276 for( unsigned j = 0; chan != chans_out[j]; j++ )
277 if( mask & chans_out[j] )
278 index++;
280 table[channels++] = index;
283 for( unsigned i = 0; i < channels; i++ )
284 if( table[i] != i )
285 return channels;
286 return 0;
290 * Reorders audio samples within a block of linear audio interleaved samples.
291 * \param ptr start address of the block of samples
292 * \param bytes size of the block in bytes (must be a multiple of the product
293 * of the channels count and the sample size)
294 * \param channels channels count (also length of the chans_table table)
295 * \param chans_table permutation table to reorder the channels
296 * (usually computed by aout_CheckChannelReorder())
297 * \param fourcc sample format (must be a linear sample format)
298 * \note The samples must be naturally aligned in memory.
300 void aout_ChannelReorder( void *ptr, size_t bytes, uint8_t channels,
301 const uint8_t *restrict chans_table, vlc_fourcc_t fourcc )
303 if( unlikely(bytes == 0) )
304 return;
306 assert( channels != 0 );
308 /* The audio formats supported in audio output are inlined. For other
309 * formats (used in demuxers and muxers), memcpy() is used to avoid
310 * breaking type punning. */
311 #define REORDER_TYPE(type) \
312 do { \
313 const size_t frames = (bytes / sizeof (type)) / channels; \
314 type *buf = ptr; \
316 for( size_t i = 0; i < frames; i++ ) \
318 type tmp[AOUT_CHAN_MAX]; \
320 for( size_t j = 0; j < channels; j++ ) \
321 tmp[chans_table[j]] = buf[j]; \
322 memcpy( buf, tmp, sizeof (type) * channels ); \
323 buf += channels; \
325 } while(0)
327 if( likely(channels <= AOUT_CHAN_MAX) )
329 switch( fourcc )
331 case VLC_CODEC_U8: REORDER_TYPE(uint8_t); return;
332 case VLC_CODEC_S16N: REORDER_TYPE(int16_t); return;
333 case VLC_CODEC_FL32: REORDER_TYPE(float); return;
334 case VLC_CODEC_S32N: REORDER_TYPE(int32_t); return;
335 case VLC_CODEC_FL64: REORDER_TYPE(double); return;
339 unsigned size = aout_BitsPerSample( fourcc ) / 8;
340 assert( size != 0 && size <= 8 );
342 const size_t frames = bytes / (size * channels);
343 unsigned char *buf = ptr;
345 for( size_t i = 0; i < frames; i++ )
347 unsigned char tmp[256 * 8];
349 for( size_t j = 0; j < channels; j++ )
350 memcpy( tmp + size * chans_table[j], buf + size * j, size );
351 memcpy( buf, tmp, size * channels );
352 buf += size * channels;
357 * Interleaves audio samples within a block of samples.
358 * \param dst destination buffer for interleaved samples
359 * \param srcv source buffers (one per plane) of uninterleaved samples
360 * \param samples number of samples (per channel/per plane)
361 * \param chans channels/planes count
362 * \param fourcc sample format (must be a linear sample format)
363 * \note The samples must be naturally aligned in memory.
364 * \warning Destination and source buffers MUST NOT overlap.
366 void aout_Interleave( void *restrict dst, const void *const *srcv,
367 unsigned samples, unsigned chans, vlc_fourcc_t fourcc )
369 #define INTERLEAVE_TYPE(type) \
370 do { \
371 type *d = dst; \
372 for( size_t i = 0; i < chans; i++ ) { \
373 const type *s = srcv[i]; \
374 for( size_t j = 0, k = 0; j < samples; j++, k += chans ) \
375 d[k] = *(s++); \
376 d++; \
378 } while(0)
380 switch( fourcc )
382 case VLC_CODEC_U8: INTERLEAVE_TYPE(uint8_t); break;
383 case VLC_CODEC_S16N: INTERLEAVE_TYPE(int16_t); break;
384 case VLC_CODEC_FL32: INTERLEAVE_TYPE(float); break;
385 case VLC_CODEC_S32N: INTERLEAVE_TYPE(int32_t); break;
386 case VLC_CODEC_FL64: INTERLEAVE_TYPE(double); break;
387 default: vlc_assert_unreachable();
389 #undef INTERLEAVE_TYPE
393 * Deinterleaves audio samples within a block of samples.
394 * \param dst destination buffer for planar samples
395 * \param src source buffer with interleaved samples
396 * \param samples number of samples (per channel/per plane)
397 * \param chans channels/planes count
398 * \param fourcc sample format (must be a linear sample format)
399 * \note The samples must be naturally aligned in memory.
400 * \warning Destination and source buffers MUST NOT overlap.
402 void aout_Deinterleave( void *restrict dst, const void *restrict src,
403 unsigned samples, unsigned chans, vlc_fourcc_t fourcc )
405 #define DEINTERLEAVE_TYPE(type) \
406 do { \
407 type *d = dst; \
408 const type *s = src; \
409 for( size_t i = 0; i < chans; i++ ) { \
410 for( size_t j = 0, k = 0; j < samples; j++, k += chans ) \
411 *(d++) = s[k]; \
412 s++; \
414 } while(0)
416 switch( fourcc )
418 case VLC_CODEC_U8: DEINTERLEAVE_TYPE(uint8_t); break;
419 case VLC_CODEC_S16N: DEINTERLEAVE_TYPE(int16_t); break;
420 case VLC_CODEC_FL32: DEINTERLEAVE_TYPE(float); break;
421 case VLC_CODEC_S32N: DEINTERLEAVE_TYPE(int32_t); break;
422 case VLC_CODEC_FL64: DEINTERLEAVE_TYPE(double); break;
423 default: vlc_assert_unreachable();
425 #undef DEINTERLEAVE_TYPE
428 /*****************************************************************************
429 * aout_ChannelExtract:
430 *****************************************************************************/
431 static inline void ExtractChannel( uint8_t *pi_dst, int i_dst_channels,
432 const uint8_t *pi_src, int i_src_channels,
433 int i_sample_count,
434 const int *pi_selection, int i_bytes )
436 for( int i = 0; i < i_sample_count; i++ )
438 for( int j = 0; j < i_dst_channels; j++ )
439 memcpy( &pi_dst[j * i_bytes], &pi_src[pi_selection[j] * i_bytes], i_bytes );
440 pi_dst += i_dst_channels * i_bytes;
441 pi_src += i_src_channels * i_bytes;
445 void aout_ChannelExtract( void *p_dst, int i_dst_channels,
446 const void *p_src, int i_src_channels,
447 int i_sample_count, const int *pi_selection, int i_bits_per_sample )
449 /* It does not work in place */
450 assert( p_dst != p_src );
452 /* Force the compiler to inline for the specific cases so it can optimize */
453 if( i_bits_per_sample == 8 )
454 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 1 );
455 else if( i_bits_per_sample == 16 )
456 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 2 );
457 else if( i_bits_per_sample == 32 )
458 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 4 );
459 else if( i_bits_per_sample == 64 )
460 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 8 );
463 bool aout_CheckChannelExtraction( int *pi_selection,
464 uint32_t *pi_layout, int *pi_channels,
465 const uint32_t pi_order_dst[AOUT_CHAN_MAX],
466 const uint32_t *pi_order_src, int i_channels )
468 static_assert(AOUT_CHAN_MAX <= (sizeof (*pi_order_dst) * CHAR_BIT),
469 "Missing bits");
471 uint32_t i_layout = 0;
472 int i_out = 0;
473 int pi_index[AOUT_CHAN_MAX];
475 /* */
476 if( !pi_order_dst )
477 pi_order_dst = pi_vlc_chan_order_wg4;
479 /* */
480 for( int i = 0; i < i_channels; i++ )
482 /* Ignore unknown or duplicated channels or not present in output */
483 if( !pi_order_src[i] || (i_layout & pi_order_src[i]) )
484 continue;
486 for( int j = 0; j < AOUT_CHAN_MAX; j++ )
488 if( pi_order_dst[j] == pi_order_src[i] )
490 assert( i_out < AOUT_CHAN_MAX );
491 pi_index[i_out++] = i;
492 i_layout |= pi_order_src[i];
493 break;
498 /* */
499 for( int i = 0, j = 0; i < AOUT_CHAN_MAX; i++ )
501 for( int k = 0; k < i_out; k++ )
503 if( pi_order_dst[i] == pi_order_src[pi_index[k]] )
505 pi_selection[j++] = pi_index[k];
506 break;
511 *pi_layout = i_layout;
512 *pi_channels = i_out;
514 for( int i = 0; i < i_out; i++ )
516 if( pi_selection[i] != i )
517 return true;
519 return i_out != i_channels;
522 /* Return the order in which filters should be inserted */
523 static int FilterOrder( const char *psz_name )
525 static const struct {
526 const char psz_name[10];
527 int i_order;
528 } filter[] = {
529 { "equalizer", 0 },
531 for( unsigned i = 0; i < ARRAY_SIZE(filter); i++ )
533 if( !strcmp( filter[i].psz_name, psz_name ) )
534 return filter[i].i_order;
536 return INT_MAX;
539 int aout_EnableFilter( audio_output_t *p_aout, const char *psz_name, bool b_add )
541 if( *psz_name == '\0' )
542 return VLC_EGENERIC;
544 const char *psz_variable = "audio-filter";
545 char *psz_list;
546 psz_list = var_GetString( p_aout, psz_variable );
548 /* Split the string into an array of filters */
549 int i_count = 1;
550 for( char *p = psz_list; p && *p; p++ )
551 i_count += *p == ':';
552 i_count += b_add;
554 const char **ppsz_filter = calloc( i_count, sizeof(*ppsz_filter) );
555 if( !ppsz_filter )
557 free( psz_list );
558 return VLC_ENOMEM;
560 bool b_present = false;
561 i_count = 0;
562 for( char *p = psz_list; p && *p; )
564 char *psz_end = strchr(p, ':');
565 if( psz_end )
566 *psz_end++ = '\0';
567 else
568 psz_end = p + strlen(p);
569 if( *p )
571 b_present |= !strcmp( p, psz_name );
572 ppsz_filter[i_count++] = p;
574 p = psz_end;
576 if( b_present == b_add )
578 free( ppsz_filter );
579 free( psz_list );
580 return VLC_EGENERIC;
583 if( b_add )
585 int i_order = FilterOrder( psz_name );
586 int i;
587 for( i = 0; i < i_count; i++ )
589 if( FilterOrder( ppsz_filter[i] ) > i_order )
590 break;
592 if( i < i_count )
593 memmove( &ppsz_filter[i+1], &ppsz_filter[i], (i_count - i) * sizeof(*ppsz_filter) );
594 ppsz_filter[i] = psz_name;
595 i_count++;
597 else
599 for( int i = 0; i < i_count; i++ )
601 if( !strcmp( ppsz_filter[i], psz_name ) )
602 ppsz_filter[i] = "";
605 size_t i_length = 0;
606 for( int i = 0; i < i_count; i++ )
607 i_length += 1 + strlen( ppsz_filter[i] );
609 char *psz_new = malloc( i_length + 1 );
611 if( unlikely( !psz_new ) )
613 free( ppsz_filter );
614 free( psz_list );
615 return VLC_ENOMEM;
618 *psz_new = '\0';
619 for( int i = 0; i < i_count; i++ )
621 if( *ppsz_filter[i] == '\0' )
622 continue;
623 if( *psz_new )
624 strcat( psz_new, ":" );
625 strcat( psz_new, ppsz_filter[i] );
627 free( ppsz_filter );
628 free( psz_list );
630 var_SetString( p_aout, psz_variable, psz_new );
631 free( psz_new );
633 return VLC_SUCCESS;