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->volume_vars_lock );
92 vlc_mutex_init( &p_aout->output_fifo_lock );
93 p_aout->i_nb_inputs = 0;
94 p_aout->mixer_multiplier = 1.0;
95 p_aout->p_mixer = NULL;
96 p_aout->output.b_error = 1;
97 p_aout->output.b_starving = 1;
99 var_Create( p_aout, "intf-change", VLC_VAR_BOOL );
100 var_SetBool( p_aout, "intf-change", true );
102 vlc_object_set_destructor( p_aout, aout_Destructor );
107 /*****************************************************************************
108 * aout_Destructor: destroy aout structure
109 *****************************************************************************/
110 static void aout_Destructor( vlc_object_t * p_this )
112 aout_instance_t * p_aout = (aout_instance_t *)p_this;
113 vlc_mutex_destroy( &p_aout->input_fifos_lock );
114 vlc_mutex_destroy( &p_aout->mixer_lock );
115 vlc_mutex_destroy( &p_aout->volume_vars_lock );
116 vlc_mutex_destroy( &p_aout->output_fifo_lock );
119 /* Lock ordering rules:
121 * Vars Mixer Input IFIFO OFIFO (< Inner lock)
122 * Vars No! Yes Yes Yes Yes
123 * Mixer No! No! Yes Yes Yes
124 * Input No! No! No! Yes Yes
125 * In FIFOs No! No! No! No! Yes
126 * Out FIFOs No! No! No! No! No!
131 static __thread unsigned aout_locks = 0;
133 void aout_lock (unsigned i)
138 case VOLUME_VARS_LOCK:
142 allowed = VOLUME_VARS_LOCK;
145 allowed = VOLUME_VARS_LOCK|MIXER_LOCK;
147 case INPUT_FIFO_LOCK:
148 allowed = VOLUME_VARS_LOCK|MIXER_LOCK|INPUT_LOCK;
150 case OUTPUT_FIFO_LOCK:
151 allowed = VOLUME_VARS_LOCK|MIXER_LOCK|INPUT_LOCK|INPUT_FIFO_LOCK;
157 if (aout_locks & ~allowed)
159 fprintf (stderr, "Illegal audio lock transition (%x -> %x)\n",
160 aout_locks, aout_locks|i);
167 void aout_unlock (unsigned i)
169 assert (aout_locks & i);
175 * Formats management (internal and external)
178 /*****************************************************************************
179 * aout_FormatNbChannels : return the number of channels
180 *****************************************************************************/
181 unsigned int aout_FormatNbChannels( const audio_sample_format_t * p_format )
183 static const uint32_t pi_channels[] =
184 { AOUT_CHAN_CENTER, AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
185 AOUT_CHAN_REARCENTER, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
186 AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, AOUT_CHAN_LFE };
187 unsigned int i_nb = 0, i;
189 for ( i = 0; i < sizeof(pi_channels)/sizeof(uint32_t); i++ )
191 if ( p_format->i_physical_channels & pi_channels[i] ) i_nb++;
197 /*****************************************************************************
198 * aout_BitsPerSample : get the number of bits per sample
199 *****************************************************************************/
200 unsigned int aout_BitsPerSample( vlc_fourcc_t i_format )
230 /* For these formats the caller has to indicate the parameters
236 /*****************************************************************************
237 * aout_FormatPrepare : compute the number of bytes per frame & frame length
238 *****************************************************************************/
239 void aout_FormatPrepare( audio_sample_format_t * p_format )
241 p_format->i_bitspersample = aout_BitsPerSample( p_format->i_format );
242 if( p_format->i_bitspersample > 0 )
244 p_format->i_bytes_per_frame = ( p_format->i_bitspersample / 8 )
245 * aout_FormatNbChannels( p_format );
246 p_format->i_frame_length = 1;
250 /*****************************************************************************
251 * aout_FormatPrintChannels : print a channel in a human-readable form
252 *****************************************************************************/
253 const char * aout_FormatPrintChannels( const audio_sample_format_t * p_format )
255 switch ( p_format->i_physical_channels & AOUT_CHAN_PHYSMASK )
258 case AOUT_CHAN_RIGHT:
259 case AOUT_CHAN_CENTER:
260 if ( (p_format->i_original_channels & AOUT_CHAN_CENTER)
261 || (p_format->i_original_channels
262 & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
264 else if ( p_format->i_original_channels & AOUT_CHAN_LEFT )
267 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT:
268 if ( p_format->i_original_channels & AOUT_CHAN_REVERSESTEREO )
270 if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
271 return "Dolby/Reverse";
272 return "Stereo/Reverse";
276 if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
278 else if ( p_format->i_original_channels & AOUT_CHAN_DUALMONO )
280 else if ( p_format->i_original_channels == AOUT_CHAN_CENTER )
281 return "Stereo/Mono";
282 else if ( !(p_format->i_original_channels & AOUT_CHAN_RIGHT) )
283 return "Stereo/Left";
284 else if ( !(p_format->i_original_channels & AOUT_CHAN_LEFT) )
285 return "Stereo/Right";
288 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER:
290 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER:
292 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
293 | AOUT_CHAN_REARCENTER:
295 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
296 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
298 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
299 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT:
301 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
302 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
304 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
305 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT:
308 case AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
309 if ( (p_format->i_original_channels & AOUT_CHAN_CENTER)
310 || (p_format->i_original_channels
311 & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
313 else if ( p_format->i_original_channels & AOUT_CHAN_LEFT )
316 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_LFE:
317 if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
319 else if ( p_format->i_original_channels & AOUT_CHAN_DUALMONO )
320 return "Dual-mono/LFE";
321 else if ( p_format->i_original_channels == AOUT_CHAN_CENTER )
323 else if ( !(p_format->i_original_channels & AOUT_CHAN_RIGHT) )
324 return "Stereo/Left/LFE";
325 else if ( !(p_format->i_original_channels & AOUT_CHAN_LEFT) )
326 return "Stereo/Right/LFE";
328 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
330 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER
333 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
334 | AOUT_CHAN_REARCENTER | AOUT_CHAN_LFE:
336 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
337 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
339 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
340 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
342 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
343 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
345 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
346 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
348 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
349 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
350 | AOUT_CHAN_MIDDLERIGHT:
352 case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
353 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
354 | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
361 /*****************************************************************************
362 * aout_FormatPrint : print a format in a human-readable form
363 *****************************************************************************/
364 void aout_FormatPrint( aout_instance_t * p_aout, const char * psz_text,
365 const audio_sample_format_t * p_format )
367 msg_Dbg( p_aout, "%s '%4.4s' %d Hz %s frame=%d samples/%d bytes", psz_text,
368 (char *)&p_format->i_format, p_format->i_rate,
369 aout_FormatPrintChannels( p_format ),
370 p_format->i_frame_length, p_format->i_bytes_per_frame );
373 /*****************************************************************************
374 * aout_FormatsPrint : print two formats in a human-readable form
375 *****************************************************************************/
376 void aout_FormatsPrint( aout_instance_t * p_aout, const char * psz_text,
377 const audio_sample_format_t * p_format1,
378 const audio_sample_format_t * p_format2 )
380 msg_Dbg( p_aout, "%s '%4.4s'->'%4.4s' %d Hz->%d Hz %s->%s",
382 (char *)&p_format1->i_format, (char *)&p_format2->i_format,
383 p_format1->i_rate, p_format2->i_rate,
384 aout_FormatPrintChannels( p_format1 ),
385 aout_FormatPrintChannels( p_format2 ) );
390 * FIFO management (internal) - please understand that solving race conditions
391 * is _your_ job, ie. in the audio output you should own the mixer lock
392 * before calling any of these functions.
395 /*****************************************************************************
396 * aout_FifoInit : initialize the members of a FIFO
397 *****************************************************************************/
398 void aout_FifoInit( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
401 AOUT_ASSERT_FIFO_LOCKED;
405 msg_Err( p_aout, "initialising fifo with zero divider" );
408 p_fifo->p_first = NULL;
409 p_fifo->pp_last = &p_fifo->p_first;
410 date_Init( &p_fifo->end_date, i_rate, 1 );
413 /*****************************************************************************
414 * aout_FifoPush : push a packet into the FIFO
415 *****************************************************************************/
416 void aout_FifoPush( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
417 aout_buffer_t * p_buffer )
420 AOUT_ASSERT_FIFO_LOCKED;
422 *p_fifo->pp_last = p_buffer;
423 p_fifo->pp_last = &p_buffer->p_next;
424 *p_fifo->pp_last = NULL;
425 /* Enforce the continuity of the stream. */
426 if ( date_Get( &p_fifo->end_date ) )
428 p_buffer->i_pts = date_Get( &p_fifo->end_date );
429 p_buffer->i_length = date_Increment( &p_fifo->end_date,
430 p_buffer->i_nb_samples );
431 p_buffer->i_length -= p_buffer->i_pts;
435 date_Set( &p_fifo->end_date, p_buffer->i_pts + p_buffer->i_length );
439 /*****************************************************************************
440 * aout_FifoSet : set end_date and trash all buffers (because they aren't
442 *****************************************************************************/
443 void aout_FifoSet( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
446 aout_buffer_t * p_buffer;
448 AOUT_ASSERT_FIFO_LOCKED;
450 date_Set( &p_fifo->end_date, date );
451 p_buffer = p_fifo->p_first;
452 while ( p_buffer != NULL )
454 aout_buffer_t * p_next = p_buffer->p_next;
455 aout_BufferFree( p_buffer );
458 p_fifo->p_first = NULL;
459 p_fifo->pp_last = &p_fifo->p_first;
462 /*****************************************************************************
463 * aout_FifoMoveDates : Move forwards or backwards all dates in the FIFO
464 *****************************************************************************/
465 void aout_FifoMoveDates( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
468 aout_buffer_t * p_buffer;
470 AOUT_ASSERT_FIFO_LOCKED;
472 date_Move( &p_fifo->end_date, difference );
473 p_buffer = p_fifo->p_first;
474 while ( p_buffer != NULL )
476 p_buffer->i_pts += difference;
477 p_buffer = p_buffer->p_next;
481 /*****************************************************************************
482 * aout_FifoNextStart : return the current end_date
483 *****************************************************************************/
484 mtime_t aout_FifoNextStart( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
487 AOUT_ASSERT_FIFO_LOCKED;
488 return date_Get( &p_fifo->end_date );
491 /*****************************************************************************
492 * aout_FifoFirstDate : return the playing date of the first buffer in the
494 *****************************************************************************/
495 mtime_t aout_FifoFirstDate( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
498 AOUT_ASSERT_FIFO_LOCKED;
499 return p_fifo->p_first ? p_fifo->p_first->i_pts : 0;
502 /*****************************************************************************
503 * aout_FifoPop : get the next buffer out of the FIFO
504 *****************************************************************************/
505 aout_buffer_t * aout_FifoPop( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
507 aout_buffer_t * p_buffer;
509 AOUT_ASSERT_FIFO_LOCKED;
511 p_buffer = p_fifo->p_first;
512 if ( p_buffer == NULL ) return NULL;
513 p_fifo->p_first = p_buffer->p_next;
514 if ( p_fifo->p_first == NULL )
516 p_fifo->pp_last = &p_fifo->p_first;
522 /*****************************************************************************
523 * aout_FifoDestroy : destroy a FIFO and its buffers
524 *****************************************************************************/
525 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
527 aout_buffer_t * p_buffer;
529 AOUT_ASSERT_FIFO_LOCKED;
531 p_buffer = p_fifo->p_first;
532 while ( p_buffer != NULL )
534 aout_buffer_t * p_next = p_buffer->p_next;
535 aout_BufferFree( p_buffer );
539 p_fifo->p_first = NULL;
540 p_fifo->pp_last = &p_fifo->p_first;
543 /*****************************************************************************
544 * aout_CheckChannelReorder : Check if we need to do some channel re-ordering
545 *****************************************************************************/
546 int aout_CheckChannelReorder( const uint32_t *pi_chan_order_in,
547 const uint32_t *pi_chan_order_out,
548 uint32_t i_channel_mask,
549 int i_channels, int *pi_chan_table )
551 bool b_chan_reorder = false;
554 if( i_channels > AOUT_CHAN_MAX )
557 if( pi_chan_order_in == NULL )
558 pi_chan_order_in = pi_vlc_chan_order_wg4;
559 if( pi_chan_order_out == NULL )
560 pi_chan_order_out = pi_vlc_chan_order_wg4;
562 for( i = 0, j = 0; pi_chan_order_in[i]; i++ )
564 if( !(i_channel_mask & pi_chan_order_in[i]) ) continue;
566 for( k = 0, l = 0; pi_chan_order_in[i] != pi_chan_order_out[k]; k++ )
568 if( i_channel_mask & pi_chan_order_out[k] ) l++;
571 pi_chan_table[j++] = l;
574 for( i = 0; i < i_channels; i++ )
576 if( pi_chan_table[i] != i ) b_chan_reorder = true;
579 return b_chan_reorder;
582 /*****************************************************************************
583 * aout_ChannelReorder :
584 *****************************************************************************/
585 void aout_ChannelReorder( uint8_t *p_buf, int i_buffer,
586 int i_channels, const int *pi_chan_table,
587 int i_bits_per_sample )
589 uint8_t p_tmp[AOUT_CHAN_MAX * 4];
592 if( i_bits_per_sample == 8 )
594 for( i = 0; i < i_buffer / i_channels; i++ )
596 for( j = 0; j < i_channels; j++ )
598 p_tmp[pi_chan_table[j]] = p_buf[j];
601 memcpy( p_buf, p_tmp, i_channels );
605 else if( i_bits_per_sample == 16 )
607 for( i = 0; i < i_buffer / i_channels / 2; i++ )
609 for( j = 0; j < i_channels; j++ )
611 p_tmp[2 * pi_chan_table[j]] = p_buf[2 * j];
612 p_tmp[2 * pi_chan_table[j] + 1] = p_buf[2 * j + 1];
615 memcpy( p_buf, p_tmp, 2 * i_channels );
616 p_buf += 2 * i_channels;
619 else if( i_bits_per_sample == 24 )
621 for( i = 0; i < i_buffer / i_channels / 3; i++ )
623 for( j = 0; j < i_channels; j++ )
625 p_tmp[3 * pi_chan_table[j]] = p_buf[3 * j];
626 p_tmp[3 * pi_chan_table[j] + 1] = p_buf[3 * j + 1];
627 p_tmp[3 * pi_chan_table[j] + 2] = p_buf[3 * j + 2];
630 memcpy( p_buf, p_tmp, 3 * i_channels );
631 p_buf += 3 * i_channels;
634 else if( i_bits_per_sample == 32 )
636 for( i = 0; i < i_buffer / i_channels / 4; i++ )
638 for( j = 0; j < i_channels; j++ )
640 p_tmp[4 * pi_chan_table[j]] = p_buf[4 * j];
641 p_tmp[4 * pi_chan_table[j] + 1] = p_buf[4 * j + 1];
642 p_tmp[4 * pi_chan_table[j] + 2] = p_buf[4 * j + 2];
643 p_tmp[4 * pi_chan_table[j] + 3] = p_buf[4 * j + 3];
646 memcpy( p_buf, p_tmp, 4 * i_channels );
647 p_buf += 4 * i_channels;
652 /*****************************************************************************
653 * aout_ChannelExtract:
654 *****************************************************************************/
655 static inline void ExtractChannel( uint8_t *pi_dst, int i_dst_channels,
656 const uint8_t *pi_src, int i_src_channels,
658 const int *pi_selection, int i_bytes )
660 for( int i = 0; i < i_sample_count; i++ )
662 for( int j = 0; j < i_dst_channels; j++ )
663 memcpy( &pi_dst[j * i_bytes], &pi_src[pi_selection[j] * i_bytes], i_bytes );
664 pi_dst += i_dst_channels * i_bytes;
665 pi_src += i_src_channels * i_bytes;
669 void aout_ChannelExtract( void *p_dst, int i_dst_channels,
670 const void *p_src, int i_src_channels,
671 int i_sample_count, const int *pi_selection, int i_bits_per_sample )
673 /* It does not work in place */
674 assert( p_dst != p_src );
676 /* Force the compiler to inline for the specific cases so it can optimize */
677 if( i_bits_per_sample == 8 )
678 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 1 );
679 else if( i_bits_per_sample == 16 )
680 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 2 );
681 else if( i_bits_per_sample == 24 )
682 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 3 );
683 else if( i_bits_per_sample == 32 )
684 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 4 );
685 else if( i_bits_per_sample == 64 )
686 ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 8 );
689 bool aout_CheckChannelExtraction( int *pi_selection,
690 uint32_t *pi_layout, int *pi_channels,
691 const uint32_t pi_order_dst[AOUT_CHAN_MAX],
692 const uint32_t *pi_order_src, int i_channels )
694 const uint32_t pi_order_dual_mono[] = { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT };
695 uint32_t i_layout = 0;
697 int pi_index[AOUT_CHAN_MAX];
701 pi_order_dst = pi_vlc_chan_order_wg4;
703 /* Detect special dual mono case */
704 if( i_channels == 2 &&
705 pi_order_src[0] == AOUT_CHAN_CENTER && pi_order_src[1] == AOUT_CHAN_CENTER )
707 i_layout |= AOUT_CHAN_DUALMONO;
708 pi_order_src = pi_order_dual_mono;
712 for( int i = 0; i < i_channels; i++ )
714 /* Ignore unknown or duplicated channels or not present in output */
715 if( !pi_order_src[i] || (i_layout & pi_order_src[i]) )
718 for( int j = 0; j < AOUT_CHAN_MAX; j++ )
720 if( pi_order_dst[j] == pi_order_src[i] )
722 assert( i_out < AOUT_CHAN_MAX );
723 pi_index[i_out++] = i;
724 i_layout |= pi_order_src[i];
731 for( int i = 0, j = 0; i < AOUT_CHAN_MAX; i++ )
733 for( int k = 0; k < i_out; k++ )
735 if( pi_order_dst[i] == pi_order_src[pi_index[k]] )
737 pi_selection[j++] = pi_index[k];
743 *pi_layout = i_layout;
744 *pi_channels = i_out;
746 for( int i = 0; i < i_out; i++ )
748 if( pi_selection[i] != i )
751 return i_out == i_channels;
754 /*****************************************************************************
756 *****************************************************************************/
758 aout_buffer_t *aout_BufferAlloc(aout_alloc_t *allocation, mtime_t microseconds,
759 aout_buffer_t *old_buffer)
761 if ( !allocation->b_alloc )
766 size_t i_alloc_size = (int)( (uint64_t)allocation->i_bytes_per_sec
767 * (microseconds) / 1000000 + 1 );
769 return block_Alloc( i_alloc_size );