1 /*****************************************************************************
2 * common.c : audio output management of common data structures
3 *****************************************************************************
4 * Copyright (C) 2002-2007 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
33 #include <vlc_common.h>
35 #include "aout_internal.h"
39 * Instances management (internal and external)
42 #define AOUT_ASSERT_FIFO_LOCKED aout_assert_fifo_locked(p_aout, p_fifo)
43 static inline void aout_assert_fifo_locked( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
49 if( p_fifo == &p_aout->output.fifo )
50 vlc_assert_locked( &p_aout->output_fifo_lock );
54 for( i = 0; i < p_aout->i_nb_inputs; i++ )
56 if( p_fifo == &p_aout->pp_inputs[i]->mixer.fifo)
58 vlc_assert_locked( &p_aout->input_fifos_lock );
62 if( i == p_aout->i_nb_inputs )
63 vlc_assert_locked( &p_aout->mixer_lock );
72 static void aout_Destructor( vlc_object_t * p_this );
74 /*****************************************************************************
75 * aout_New: initialize aout structure
76 *****************************************************************************/
77 aout_instance_t * __aout_New( vlc_object_t * p_parent )
79 aout_instance_t * p_aout;
81 /* Allocate descriptor. */
82 p_aout = vlc_object_create( p_parent, VLC_OBJECT_AOUT );
88 /* Initialize members. */
89 vlc_mutex_init( &p_aout->input_fifos_lock );
90 vlc_mutex_init( &p_aout->mixer_lock );
91 vlc_mutex_init( &p_aout->output_fifo_lock );
92 p_aout->i_nb_inputs = 0;
93 p_aout->mixer_multiplier = 1.0;
94 p_aout->p_mixer = NULL;
95 p_aout->output.b_error = 1;
96 p_aout->output.b_starving = 1;
98 var_Create( p_aout, "intf-change", VLC_VAR_BOOL );
99 var_SetBool( p_aout, "intf-change", true );
101 vlc_object_set_destructor( p_aout, aout_Destructor );
106 /*****************************************************************************
107 * aout_Destructor: destroy aout structure
108 *****************************************************************************/
109 static void aout_Destructor( vlc_object_t * p_this )
111 aout_instance_t * p_aout = (aout_instance_t *)p_this;
112 vlc_mutex_destroy( &p_aout->input_fifos_lock );
113 vlc_mutex_destroy( &p_aout->mixer_lock );
114 vlc_mutex_destroy( &p_aout->output_fifo_lock );
117 /* Lock ordering rules:
119 * Vars Mixer Input IFIFO OFIFO (< Inner lock)
120 * Vars No! Yes Yes Yes Yes
121 * Mixer No! No! Yes Yes Yes
122 * Input No! No! No! Yes Yes
123 * In FIFOs No! No! No! No! Yes
124 * Out FIFOs No! No! No! No! No!
129 static __thread unsigned aout_locks = 0;
131 void aout_lock (unsigned i)
136 case VOLUME_VARS_LOCK:
140 allowed = VOLUME_VARS_LOCK;
143 allowed = VOLUME_VARS_LOCK|MIXER_LOCK;
145 case INPUT_FIFO_LOCK:
146 allowed = VOLUME_VARS_LOCK|MIXER_LOCK|INPUT_LOCK;
148 case OUTPUT_FIFO_LOCK:
149 allowed = VOLUME_VARS_LOCK|MIXER_LOCK|INPUT_LOCK|INPUT_FIFO_LOCK;
155 if (aout_locks & ~allowed)
157 fprintf (stderr, "Illegal audio lock transition (%x -> %x)\n",
158 aout_locks, aout_locks|i);
165 void aout_unlock (unsigned i)
167 assert (aout_locks & i);
173 * Formats management (internal and external)
176 /*****************************************************************************
177 * aout_FormatNbChannels : return the number of channels
178 *****************************************************************************/
179 unsigned int aout_FormatNbChannels( const audio_sample_format_t * p_format )
181 static const uint32_t pi_channels[] =
182 { AOUT_CHAN_CENTER, AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
183 AOUT_CHAN_REARCENTER, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
184 AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, AOUT_CHAN_LFE };
185 unsigned int i_nb = 0, i;
187 for ( i = 0; i < sizeof(pi_channels)/sizeof(uint32_t); i++ )
189 if ( p_format->i_physical_channels & pi_channels[i] ) i_nb++;
195 /*****************************************************************************
196 * aout_BitsPerSample : get the number of bits per sample
197 *****************************************************************************/
198 unsigned int aout_BitsPerSample( vlc_fourcc_t i_format )
228 /* For these formats the caller has to indicate the parameters
234 /*****************************************************************************
235 * aout_FormatPrepare : compute the number of bytes per frame & frame length
236 *****************************************************************************/
237 void aout_FormatPrepare( audio_sample_format_t * p_format )
239 p_format->i_bitspersample = aout_BitsPerSample( p_format->i_format );
240 if( p_format->i_bitspersample > 0 )
242 p_format->i_bytes_per_frame = ( p_format->i_bitspersample / 8 )
243 * aout_FormatNbChannels( p_format );
244 p_format->i_frame_length = 1;
248 /*****************************************************************************
249 * aout_FormatPrintChannels : print a channel in a human-readable form
250 *****************************************************************************/
251 const char * aout_FormatPrintChannels( const audio_sample_format_t * p_format )
253 switch ( p_format->i_physical_channels & AOUT_CHAN_PHYSMASK )
256 case AOUT_CHAN_RIGHT:
257 case AOUT_CHAN_CENTER:
258 if ( (p_format->i_original_channels & AOUT_CHAN_CENTER)
259 || (p_format->i_original_channels
260 & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
262 else if ( p_format->i_original_channels & AOUT_CHAN_LEFT )
265 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT:
266 if ( p_format->i_original_channels & AOUT_CHAN_REVERSESTEREO )
268 if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
269 return "Dolby/Reverse";
270 return "Stereo/Reverse";
274 if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
276 else if ( p_format->i_original_channels & AOUT_CHAN_DUALMONO )
278 else if ( p_format->i_original_channels == AOUT_CHAN_CENTER )
279 return "Stereo/Mono";
280 else if ( !(p_format->i_original_channels & AOUT_CHAN_RIGHT) )
281 return "Stereo/Left";
282 else if ( !(p_format->i_original_channels & AOUT_CHAN_LEFT) )
283 return "Stereo/Right";
286 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER:
288 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER:
290 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
291 | AOUT_CHAN_REARCENTER:
293 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
294 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
296 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
297 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT:
299 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
300 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
302 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
303 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT:
306 case AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
307 if ( (p_format->i_original_channels & AOUT_CHAN_CENTER)
308 || (p_format->i_original_channels
309 & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
311 else if ( p_format->i_original_channels & AOUT_CHAN_LEFT )
314 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_LFE:
315 if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
317 else if ( p_format->i_original_channels & AOUT_CHAN_DUALMONO )
318 return "Dual-mono/LFE";
319 else if ( p_format->i_original_channels == AOUT_CHAN_CENTER )
321 else if ( !(p_format->i_original_channels & AOUT_CHAN_RIGHT) )
322 return "Stereo/Left/LFE";
323 else if ( !(p_format->i_original_channels & AOUT_CHAN_LEFT) )
324 return "Stereo/Right/LFE";
326 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
328 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER
331 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
332 | AOUT_CHAN_REARCENTER | AOUT_CHAN_LFE:
334 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
335 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
337 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
338 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
340 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
341 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
343 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
344 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
346 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
347 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
348 | AOUT_CHAN_MIDDLERIGHT:
350 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
351 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
352 | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
359 /*****************************************************************************
360 * aout_FormatPrint : print a format in a human-readable form
361 *****************************************************************************/
362 void aout_FormatPrint( aout_instance_t * p_aout, const char * psz_text,
363 const audio_sample_format_t * p_format )
365 msg_Dbg( p_aout, "%s '%4.4s' %d Hz %s frame=%d samples/%d bytes", psz_text,
366 (char *)&p_format->i_format, p_format->i_rate,
367 aout_FormatPrintChannels( p_format ),
368 p_format->i_frame_length, p_format->i_bytes_per_frame );
371 /*****************************************************************************
372 * aout_FormatsPrint : print two formats in a human-readable form
373 *****************************************************************************/
374 void aout_FormatsPrint( aout_instance_t * p_aout, const char * psz_text,
375 const audio_sample_format_t * p_format1,
376 const audio_sample_format_t * p_format2 )
378 msg_Dbg( p_aout, "%s '%4.4s'->'%4.4s' %d Hz->%d Hz %s->%s",
380 (char *)&p_format1->i_format, (char *)&p_format2->i_format,
381 p_format1->i_rate, p_format2->i_rate,
382 aout_FormatPrintChannels( p_format1 ),
383 aout_FormatPrintChannels( p_format2 ) );
388 * FIFO management (internal) - please understand that solving race conditions
389 * is _your_ job, ie. in the audio output you should own the mixer lock
390 * before calling any of these functions.
393 /*****************************************************************************
394 * aout_FifoInit : initialize the members of a FIFO
395 *****************************************************************************/
396 void aout_FifoInit( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
399 AOUT_ASSERT_FIFO_LOCKED;
403 msg_Err( p_aout, "initialising fifo with zero divider" );
406 p_fifo->p_first = NULL;
407 p_fifo->pp_last = &p_fifo->p_first;
408 date_Init( &p_fifo->end_date, i_rate, 1 );
411 /*****************************************************************************
412 * aout_FifoPush : push a packet into the FIFO
413 *****************************************************************************/
414 void aout_FifoPush( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
415 aout_buffer_t * p_buffer )
418 AOUT_ASSERT_FIFO_LOCKED;
420 *p_fifo->pp_last = p_buffer;
421 p_fifo->pp_last = &p_buffer->p_next;
422 *p_fifo->pp_last = NULL;
423 /* Enforce the continuity of the stream. */
424 if ( date_Get( &p_fifo->end_date ) )
426 p_buffer->i_pts = date_Get( &p_fifo->end_date );
427 p_buffer->i_length = date_Increment( &p_fifo->end_date,
428 p_buffer->i_nb_samples );
429 p_buffer->i_length -= p_buffer->i_pts;
433 date_Set( &p_fifo->end_date, p_buffer->i_pts + p_buffer->i_length );
437 /*****************************************************************************
438 * aout_FifoSet : set end_date and trash all buffers (because they aren't
440 *****************************************************************************/
441 void aout_FifoSet( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
444 aout_buffer_t * p_buffer;
446 AOUT_ASSERT_FIFO_LOCKED;
448 date_Set( &p_fifo->end_date, date );
449 p_buffer = p_fifo->p_first;
450 while ( p_buffer != NULL )
452 aout_buffer_t * p_next = p_buffer->p_next;
453 aout_BufferFree( p_buffer );
456 p_fifo->p_first = NULL;
457 p_fifo->pp_last = &p_fifo->p_first;
460 /*****************************************************************************
461 * aout_FifoMoveDates : Move forwards or backwards all dates in the FIFO
462 *****************************************************************************/
463 void aout_FifoMoveDates( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
466 aout_buffer_t * p_buffer;
468 AOUT_ASSERT_FIFO_LOCKED;
470 date_Move( &p_fifo->end_date, difference );
471 p_buffer = p_fifo->p_first;
472 while ( p_buffer != NULL )
474 p_buffer->i_pts += difference;
475 p_buffer = p_buffer->p_next;
479 /*****************************************************************************
480 * aout_FifoNextStart : return the current end_date
481 *****************************************************************************/
482 mtime_t aout_FifoNextStart( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
485 AOUT_ASSERT_FIFO_LOCKED;
486 return date_Get( &p_fifo->end_date );
489 /*****************************************************************************
490 * aout_FifoFirstDate : return the playing date of the first buffer in the
492 *****************************************************************************/
493 mtime_t aout_FifoFirstDate( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
496 AOUT_ASSERT_FIFO_LOCKED;
497 return p_fifo->p_first ? p_fifo->p_first->i_pts : 0;
500 /*****************************************************************************
501 * aout_FifoPop : get the next buffer out of the FIFO
502 *****************************************************************************/
503 aout_buffer_t * aout_FifoPop( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
505 aout_buffer_t * p_buffer;
507 AOUT_ASSERT_FIFO_LOCKED;
509 p_buffer = p_fifo->p_first;
510 if ( p_buffer == NULL ) return NULL;
511 p_fifo->p_first = p_buffer->p_next;
512 if ( p_fifo->p_first == NULL )
514 p_fifo->pp_last = &p_fifo->p_first;
520 /*****************************************************************************
521 * aout_FifoDestroy : destroy a FIFO and its buffers
522 *****************************************************************************/
523 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
525 aout_buffer_t * p_buffer;
527 AOUT_ASSERT_FIFO_LOCKED;
529 p_buffer = p_fifo->p_first;
530 while ( p_buffer != NULL )
532 aout_buffer_t * p_next = p_buffer->p_next;
533 aout_BufferFree( p_buffer );
537 p_fifo->p_first = NULL;
538 p_fifo->pp_last = &p_fifo->p_first;
541 /*****************************************************************************
542 * aout_CheckChannelReorder : Check if we need to do some channel re-ordering
543 *****************************************************************************/
544 int aout_CheckChannelReorder( const uint32_t *pi_chan_order_in,
545 const uint32_t *pi_chan_order_out,
546 uint32_t i_channel_mask,
547 int i_channels, int *pi_chan_table )
549 bool b_chan_reorder = false;
552 if( i_channels > AOUT_CHAN_MAX )
555 if( pi_chan_order_in == NULL )
556 pi_chan_order_in = pi_vlc_chan_order_wg4;
557 if( pi_chan_order_out == NULL )
558 pi_chan_order_out = pi_vlc_chan_order_wg4;
560 for( i = 0, j = 0; pi_chan_order_in[i]; i++ )
562 if( !(i_channel_mask & pi_chan_order_in[i]) ) continue;
564 for( k = 0, l = 0; pi_chan_order_in[i] != pi_chan_order_out[k]; k++ )
566 if( i_channel_mask & pi_chan_order_out[k] ) l++;
569 pi_chan_table[j++] = l;
572 for( i = 0; i < i_channels; i++ )
574 if( pi_chan_table[i] != i ) b_chan_reorder = true;
577 return b_chan_reorder;
580 /*****************************************************************************
581 * aout_ChannelReorder :
582 *****************************************************************************/
583 void aout_ChannelReorder( uint8_t *p_buf, int i_buffer,
584 int i_channels, const int *pi_chan_table,
585 int i_bits_per_sample )
587 uint8_t p_tmp[AOUT_CHAN_MAX * 4];
590 if( i_bits_per_sample == 8 )
592 for( i = 0; i < i_buffer / i_channels; i++ )
594 for( j = 0; j < i_channels; j++ )
596 p_tmp[pi_chan_table[j]] = p_buf[j];
599 memcpy( p_buf, p_tmp, i_channels );
603 else if( i_bits_per_sample == 16 )
605 for( i = 0; i < i_buffer / i_channels / 2; i++ )
607 for( j = 0; j < i_channels; j++ )
609 p_tmp[2 * pi_chan_table[j]] = p_buf[2 * j];
610 p_tmp[2 * pi_chan_table[j] + 1] = p_buf[2 * j + 1];
613 memcpy( p_buf, p_tmp, 2 * i_channels );
614 p_buf += 2 * i_channels;
617 else if( i_bits_per_sample == 24 )
619 for( i = 0; i < i_buffer / i_channels / 3; i++ )
621 for( j = 0; j < i_channels; j++ )
623 p_tmp[3 * pi_chan_table[j]] = p_buf[3 * j];
624 p_tmp[3 * pi_chan_table[j] + 1] = p_buf[3 * j + 1];
625 p_tmp[3 * pi_chan_table[j] + 2] = p_buf[3 * j + 2];
628 memcpy( p_buf, p_tmp, 3 * i_channels );
629 p_buf += 3 * i_channels;
632 else if( i_bits_per_sample == 32 )
634 for( i = 0; i < i_buffer / i_channels / 4; i++ )
636 for( j = 0; j < i_channels; j++ )
638 p_tmp[4 * pi_chan_table[j]] = p_buf[4 * j];
639 p_tmp[4 * pi_chan_table[j] + 1] = p_buf[4 * j + 1];
640 p_tmp[4 * pi_chan_table[j] + 2] = p_buf[4 * j + 2];
641 p_tmp[4 * pi_chan_table[j] + 3] = p_buf[4 * j + 3];
644 memcpy( p_buf, p_tmp, 4 * i_channels );
645 p_buf += 4 * i_channels;
650 /*****************************************************************************
651 * aout_ChannelExtract:
652 *****************************************************************************/
653 static inline void ExtractChannel( uint8_t *pi_dst, int i_dst_channels,
654 const uint8_t *pi_src, int i_src_channels,
656 const int *pi_selection, int i_bytes )
658 for( int i = 0; i < i_sample_count; i++ )
660 for( int j = 0; j < i_dst_channels; j++ )
661 memcpy( &pi_dst[j * i_bytes], &pi_src[pi_selection[j] * i_bytes], i_bytes );
662 pi_dst += i_dst_channels * i_bytes;
663 pi_src += i_src_channels * i_bytes;
667 void aout_ChannelExtract( void *p_dst, int i_dst_channels,
668 const void *p_src, int i_src_channels,
669 int i_sample_count, const int *pi_selection, int i_bits_per_sample )
671 /* It does not work in place */
672 assert( p_dst != p_src );
674 /* Force the compiler to inline for the specific cases so it can optimize */
675 if( i_bits_per_sample == 8 )
676 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 1 );
677 else if( i_bits_per_sample == 16 )
678 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 2 );
679 else if( i_bits_per_sample == 24 )
680 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 3 );
681 else if( i_bits_per_sample == 32 )
682 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 4 );
683 else if( i_bits_per_sample == 64 )
684 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 8 );
687 bool aout_CheckChannelExtraction( int *pi_selection,
688 uint32_t *pi_layout, int *pi_channels,
689 const uint32_t pi_order_dst[AOUT_CHAN_MAX],
690 const uint32_t *pi_order_src, int i_channels )
692 const uint32_t pi_order_dual_mono[] = { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT };
693 uint32_t i_layout = 0;
695 int pi_index[AOUT_CHAN_MAX];
699 pi_order_dst = pi_vlc_chan_order_wg4;
701 /* Detect special dual mono case */
702 if( i_channels == 2 &&
703 pi_order_src[0] == AOUT_CHAN_CENTER && pi_order_src[1] == AOUT_CHAN_CENTER )
705 i_layout |= AOUT_CHAN_DUALMONO;
706 pi_order_src = pi_order_dual_mono;
710 for( int i = 0; i < i_channels; i++ )
712 /* Ignore unknown or duplicated channels or not present in output */
713 if( !pi_order_src[i] || (i_layout & pi_order_src[i]) )
716 for( int j = 0; j < AOUT_CHAN_MAX; j++ )
718 if( pi_order_dst[j] == pi_order_src[i] )
720 assert( i_out < AOUT_CHAN_MAX );
721 pi_index[i_out++] = i;
722 i_layout |= pi_order_src[i];
729 for( int i = 0, j = 0; i < AOUT_CHAN_MAX; i++ )
731 for( int k = 0; k < i_out; k++ )
733 if( pi_order_dst[i] == pi_order_src[pi_index[k]] )
735 pi_selection[j++] = pi_index[k];
741 *pi_layout = i_layout;
742 *pi_channels = i_out;
744 for( int i = 0; i < i_out; i++ )
746 if( pi_selection[i] != i )
749 return i_out == i_channels;
752 /*****************************************************************************
754 *****************************************************************************/
756 aout_buffer_t *aout_BufferAlloc(aout_alloc_t *allocation, mtime_t microseconds,
757 aout_buffer_t *old_buffer)
759 if ( !allocation->b_alloc )
764 size_t i_alloc_size = (int)( (uint64_t)allocation->i_bytes_per_sec
765 * (microseconds) / 1000000 + 1 );
767 return block_Alloc( i_alloc_size );