1 /*****************************************************************************
2 * lpcm.c: lpcm decoder/packetizer module
3 *****************************************************************************
4 * Copyright (C) 1999-2008 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Henri Fallon <henri@videolan.org>
9 * Christophe Massiot <massiot@via.ecp.fr>
10 * Gildas Bazin <gbazin@videolan.org>
11 * Lauren Aimar <fenrir _AT_ videolan _DOT_ org >
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_codec.h>
41 /*****************************************************************************
43 *****************************************************************************/
44 static int OpenDecoder ( vlc_object_t * );
45 static int OpenPacketizer( vlc_object_t * );
46 static void CloseCommon ( vlc_object_t * );
50 set_category( CAT_INPUT )
51 set_subcategory( SUBCAT_INPUT_ACODEC )
52 set_description( N_("Linear PCM audio decoder") )
53 set_capability( "decoder", 100 )
54 set_callbacks( OpenDecoder, CloseCommon )
57 set_description( N_("Linear PCM audio packetizer") )
58 set_capability( "packetizer", 100 )
59 set_callbacks( OpenPacketizer, CloseCommon )
64 /*****************************************************************************
65 * decoder_sys_t : lpcm decoder descriptor
66 *****************************************************************************/
78 unsigned i_header_size;
84 * - frame number (8 bits)
85 * - unknown (16 bits) == 0x0003 ?
87 * - current frame (4 bits)
89 * - frequency (2 bits) 0 == 48 kHz, 1 == 32 kHz, 2 == ?, 3 == ?
91 * - number of channels - 1 (3 bits) 1 == 2 channels
92 * - start code (8 bits) == 0x80
94 * LPCM DVD-A header (http://dvd-audio.sourceforge.net/spec/aob.shtml)
95 * - continuity counter (8 bits, clipped to 0x00-0x1f)
96 * - header size (16 bits)
97 * - byte pointer to start of first audio frame.
98 * - unknown (8bits, 0x10 for stereo, 0x00 for surround)
99 * - sample size (4+4 bits)
100 * - samplerate (4+4 bits)
102 * - group assignment (8 bits)
104 * - padding(variable)
108 * - number of channels (4 bits)
109 * - frequency (4 bits)
110 * - bits per sample (2 bits)
114 #define LPCM_VOB_HEADER_LEN (6)
115 #define LPCM_AOB_HEADER_LEN (11)
116 #define LPCM_BD_HEADER_LEN (4)
129 unsigned pi_position[6];
132 /*****************************************************************************
134 *****************************************************************************/
135 static void *DecodeFrame ( decoder_t *, block_t ** );
138 static int VobHeader( unsigned *pi_rate,
139 unsigned *pi_channels, unsigned *pi_original_channels,
141 const uint8_t *p_header );
142 static void VobExtract( aout_buffer_t *, block_t *, unsigned i_bits );
144 static int AobHeader( unsigned *pi_rate,
145 unsigned *pi_channels, unsigned *pi_layout,
147 unsigned *pi_padding,
149 const uint8_t *p_header );
150 static void AobExtract( aout_buffer_t *, block_t *, unsigned i_bits, aob_group_t p_group[2] );
152 static int BdHeader( unsigned *pi_rate,
153 unsigned *pi_channels, unsigned *pi_original_channels,
155 const uint8_t *p_header );
156 static void BdExtract( aout_buffer_t *, block_t * );
159 /*****************************************************************************
161 *****************************************************************************/
162 static int OpenCommon( vlc_object_t *p_this, bool b_packetizer )
164 decoder_t *p_dec = (decoder_t*)p_this;
165 decoder_sys_t *p_sys;
169 switch( p_dec->fmt_in.i_codec )
172 case VLC_CODEC_DVD_LPCM:
174 i_header_size = LPCM_VOB_HEADER_LEN;
177 case VLC_CODEC_DVDA_LPCM:
179 i_header_size = LPCM_AOB_HEADER_LEN;
182 case VLC_CODEC_BD_LPCM:
184 i_header_size = LPCM_BD_HEADER_LEN;
190 /* Allocate the memory needed to store the decoder's structure */
191 if( ( p_dec->p_sys = p_sys = malloc(sizeof(decoder_sys_t)) ) == NULL )
195 p_sys->b_packetizer = b_packetizer;
196 date_Set( &p_sys->end_date, 0 );
197 p_sys->i_type = i_type;
198 p_sys->i_header_size = i_header_size;
200 /* Set output properties */
201 p_dec->fmt_out.i_cat = AUDIO_ES;
208 p_dec->fmt_out.i_codec = VLC_CODEC_DVD_LPCM;
211 p_dec->fmt_out.i_codec = VLC_CODEC_DVDA_LPCM;
216 p_dec->fmt_out.i_codec = VLC_CODEC_BD_LPCM;
222 switch( p_dec->fmt_out.audio.i_bitspersample )
226 p_dec->fmt_out.i_codec = VLC_CODEC_S24B;
227 p_dec->fmt_out.audio.i_bitspersample = 24;
230 p_dec->fmt_out.i_codec = VLC_CODEC_S16B;
231 p_dec->fmt_out.audio.i_bitspersample = 16;
237 p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
239 p_dec->pf_packetize = (block_t *(*)(decoder_t *, block_t **))
244 static int OpenDecoder( vlc_object_t *p_this )
246 return OpenCommon( p_this, false );
248 static int OpenPacketizer( vlc_object_t *p_this )
250 return OpenCommon( p_this, true );
253 /*****************************************************************************
254 * DecodeFrame: decodes an lpcm frame.
255 ****************************************************************************
256 * Beware, this function must be fed with complete frames (PES packet).
257 *****************************************************************************/
258 static void *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
260 decoder_sys_t *p_sys = p_dec->p_sys;
262 unsigned int i_rate = 0, i_original_channels = 0, i_channels = 0, i_bits = 0;
265 if( !pp_block || !*pp_block ) return NULL;
268 *pp_block = NULL; /* So the packet doesn't get re-sent */
270 /* Date management */
271 if( p_block->i_pts > VLC_TS_INVALID &&
272 p_block->i_pts != date_Get( &p_sys->end_date ) )
274 date_Set( &p_sys->end_date, p_block->i_pts );
277 if( !date_Get( &p_sys->end_date ) )
279 /* We've just started the stream, wait for the first PTS. */
280 block_Release( p_block );
284 if( p_block->i_buffer <= p_sys->i_header_size )
286 msg_Err(p_dec, "frame is too short");
287 block_Release( p_block );
292 unsigned i_padding = 0;
293 aob_group_t p_aob_group[2];
294 switch( p_sys->i_type )
297 i_ret = VobHeader( &i_rate, &i_channels, &i_original_channels, &i_bits,
301 i_ret = AobHeader( &i_rate, &i_channels, &i_original_channels, &i_bits, &i_padding,
306 i_ret = BdHeader( &i_rate, &i_channels, &i_original_channels, &i_bits,
313 if( i_ret || p_block->i_buffer <= p_sys->i_header_size + i_padding )
315 msg_Warn( p_dec, "no frame sync or too small frame" );
316 block_Release( p_block );
320 /* Set output properties */
321 if( p_dec->fmt_out.audio.i_rate != i_rate )
323 date_Init( &p_sys->end_date, i_rate, 1 );
324 date_Set( &p_sys->end_date, p_block->i_pts );
326 p_dec->fmt_out.audio.i_rate = i_rate;
327 p_dec->fmt_out.audio.i_channels = i_channels;
328 p_dec->fmt_out.audio.i_original_channels = i_original_channels;
329 p_dec->fmt_out.audio.i_physical_channels = i_original_channels & AOUT_CHAN_PHYSMASK;
331 i_frame_length = (p_block->i_buffer - p_sys->i_header_size - i_padding) / i_channels * 8 / i_bits;
333 if( p_sys->b_packetizer )
335 p_block->i_pts = p_block->i_dts = date_Get( &p_sys->end_date );
337 date_Increment( &p_sys->end_date, i_frame_length ) -
340 /* Just pass on the incoming frame */
348 p_dec->fmt_out.i_codec = VLC_CODEC_S16B;
349 p_dec->fmt_out.audio.i_bitspersample = 16;
353 p_dec->fmt_out.i_codec = VLC_CODEC_S24B;
354 p_dec->fmt_out.audio.i_bitspersample = 24;
358 aout_buffer_t *p_aout_buffer;
359 p_aout_buffer = decoder_NewAudioBuffer( p_dec, i_frame_length );
363 p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
364 p_aout_buffer->i_length =
365 date_Increment( &p_sys->end_date, i_frame_length )
366 - p_aout_buffer->i_pts;
368 p_block->p_buffer += p_sys->i_header_size + i_padding;
369 p_block->i_buffer -= p_sys->i_header_size + i_padding;
371 switch( p_sys->i_type )
374 VobExtract( p_aout_buffer, p_block, i_bits );
377 AobExtract( p_aout_buffer, p_block, i_bits, p_aob_group );
382 BdExtract( p_aout_buffer, p_block );
386 block_Release( p_block );
387 return p_aout_buffer;
391 /*****************************************************************************
392 * CloseCommon : lpcm decoder destruction
393 *****************************************************************************/
394 static void CloseCommon( vlc_object_t *p_this )
396 decoder_t *p_dec = (decoder_t*)p_this;
397 free( p_dec->p_sys );
400 /*****************************************************************************
402 *****************************************************************************/
403 static int VobHeader( unsigned *pi_rate,
404 unsigned *pi_channels, unsigned *pi_original_channels,
406 const uint8_t *p_header )
408 const uint8_t i_header = p_header[4];
410 switch( (i_header >> 4) & 0x3 )
426 *pi_channels = (i_header & 0x7) + 1;
427 switch( *pi_channels - 1 )
430 *pi_original_channels = AOUT_CHAN_CENTER;
433 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
436 /* This is unsure. */
437 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_LFE;
440 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
441 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
444 /* This is unsure. */
445 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
446 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
450 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
451 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
452 | AOUT_CHAN_CENTER | AOUT_CHAN_LFE;
455 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
456 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
457 | AOUT_CHAN_CENTER | AOUT_CHAN_MIDDLELEFT
458 | AOUT_CHAN_MIDDLERIGHT;
461 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
462 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
463 | AOUT_CHAN_CENTER | AOUT_CHAN_MIDDLELEFT
464 | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE;
468 switch( (i_header >> 6) & 0x3 )
482 /* Check frame sync and drop it. */
483 if( p_header[5] != 0x80 )
488 static const unsigned p_aob_group1[21][6] = {
489 { AOUT_CHAN_CENTER, 0 },
490 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
491 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
492 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
493 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
494 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
495 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
496 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
497 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
498 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
499 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
500 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
501 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
502 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
503 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
504 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
505 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
506 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
507 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
508 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
509 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
511 static const unsigned p_aob_group2[21][6] = {
514 { AOUT_CHAN_REARCENTER, 0 },
515 { AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
516 { AOUT_CHAN_LFE, 0 },
517 { AOUT_CHAN_LFE, AOUT_CHAN_REARCENTER, 0 },
518 { AOUT_CHAN_LFE, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
519 { AOUT_CHAN_CENTER, 0 },
520 { AOUT_CHAN_CENTER, AOUT_CHAN_REARCENTER, 0 },
521 { AOUT_CHAN_CENTER, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
522 { AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 },
523 { AOUT_CHAN_CENTER, AOUT_CHAN_LFE, AOUT_CHAN_REARCENTER, 0 },
524 { AOUT_CHAN_CENTER, AOUT_CHAN_LFE, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
525 { AOUT_CHAN_REARCENTER, 0 },
526 { AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
527 { AOUT_CHAN_LFE, 0 },
528 { AOUT_CHAN_LFE, AOUT_CHAN_REARCENTER, 0 },
529 { AOUT_CHAN_LFE, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
530 { AOUT_CHAN_LFE, 0 },
531 { AOUT_CHAN_CENTER, 0 },
532 { AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 },
535 static int AobHeader( unsigned *pi_rate,
536 unsigned *pi_channels, unsigned *pi_layout,
538 unsigned *pi_padding,
540 const uint8_t *p_header )
542 const unsigned i_header_size = GetWBE( &p_header[1] );
543 if( i_header_size + 3 < LPCM_AOB_HEADER_LEN )
546 *pi_padding = 3+i_header_size - LPCM_AOB_HEADER_LEN;
548 const int i_index_size_g1 = (p_header[6] >> 4) & 0x0f;
549 const int i_index_size_g2 = (p_header[6] ) & 0x0f;
550 const int i_index_rate_g1 = (p_header[7] >> 4) & 0x0f;
551 const int i_index_rate_g2 = (p_header[7] ) & 0x0f;
552 const int i_assignment = p_header[9];
555 if( i_index_size_g1 > 0x02 ||
556 ( i_index_size_g2 != 0x0f && i_index_size_g2 > 0x02 ) )
558 if( (i_index_rate_g1 & 0x07) > 0x02 ||
559 ( i_index_rate_g2 != 0x0f && (i_index_rate_g1 & 0x07) > 0x02 ) )
561 if( i_assignment > 20 )
565 *pi_bits = 16 + 4 * i_index_size_g1;
566 if( i_index_rate_g1 & 0x08 )
567 *pi_rate = 44100 << (i_index_rate_g1 & 0x07);
569 *pi_rate = 48000 << (i_index_rate_g1 & 0x07);
573 unsigned i_channels1 = 0;
574 unsigned i_layout1 = 0;
575 for( int i = 0; p_aob_group1[i_assignment][i] != 0; i++ )
578 i_layout1 |= p_aob_group1[i_assignment][i];
581 unsigned i_channels2 = 0;
582 unsigned i_layout2 = 0;
583 if( i_index_size_g2 != 0x0f && i_index_rate_g2 != 0x0f )
585 for( int i = 0; p_aob_group2[i_assignment][i] != 0; i++ )
588 i_layout2 |= p_aob_group2[i_assignment][i];
590 assert( (i_layout1 & i_layout2) == 0 );
592 /* It is enabled only when presents and compatible wih group1 */
593 const bool b_group2_used = i_index_size_g1 == i_index_size_g2 &&
594 i_index_rate_g1 == i_index_rate_g2;
597 *pi_channels = i_channels1 + ( b_group2_used ? i_channels2 : 0 );
598 *pi_layout = i_layout1 | ( b_group2_used ? i_layout2 : 0 );
601 for( unsigned i = 0; i < 2; i++ )
603 const unsigned *p_aob = i == 0 ? p_aob_group1[i_assignment] :
604 p_aob_group2[i_assignment];
605 g[i].i_channels = i == 0 ? i_channels1 :
608 g[i].b_used = i == 0 || b_group2_used;
611 for( unsigned j = 0; j < g[i].i_channels; j++ )
613 g[i].pi_position[j] = 0;
614 for( int k = 0; pi_vlc_chan_order_wg4[k] != 0; k++ )
616 const unsigned i_channel = pi_vlc_chan_order_wg4[k];
617 if( i_channel == p_aob[j] )
619 if( (*pi_layout) & i_channel )
620 g[i].pi_position[j]++;
627 static int BdHeader( unsigned *pi_rate,
628 unsigned *pi_channels, unsigned *pi_original_channels,
630 const uint8_t *p_header )
632 const uint32_t h = GetDWBE( p_header );
633 switch( ( h & 0xf000) >> 12 )
637 *pi_original_channels = AOUT_CHAN_CENTER;
641 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
645 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER;
649 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER;
653 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
654 AOUT_CHAN_REARCENTER;
658 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
659 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
663 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
664 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
668 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
669 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
674 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
675 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
676 AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT;
680 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
681 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
682 AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT |
689 switch( (h >> 6) & 0x03 )
694 case 2: /* 20 bits but samples are stored on 24 bits */
695 case 3: /* 24 bits */
701 switch( (h >> 8) & 0x0f )
718 static void VobExtract( aout_buffer_t *p_aout_buffer, block_t *p_block,
721 uint8_t *p_out = p_aout_buffer->p_buffer;
723 /* 20/24 bits LPCM use special packing */
726 while( p_block->i_buffer / 12 )
729 p_out[0] = p_block->p_buffer[0];
730 p_out[1] = p_block->p_buffer[1];
731 p_out[2] = p_block->p_buffer[8];
733 p_out[3] = p_block->p_buffer[2];
734 p_out[4] = p_block->p_buffer[3];
735 p_out[5] = p_block->p_buffer[9];
737 p_out[6] = p_block->p_buffer[4];
738 p_out[7] = p_block->p_buffer[5];
739 p_out[8] = p_block->p_buffer[10];
741 p_out[9] = p_block->p_buffer[6];
742 p_out[10] = p_block->p_buffer[7];
743 p_out[11] = p_block->p_buffer[11];
745 p_block->i_buffer -= 12;
746 p_block->p_buffer += 12;
750 else if( i_bits == 20 )
752 while( p_block->i_buffer / 10 )
755 p_out[0] = p_block->p_buffer[0];
756 p_out[1] = p_block->p_buffer[1];
757 p_out[2] = p_block->p_buffer[8] & 0xF0;
759 p_out[3] = p_block->p_buffer[2];
760 p_out[4] = p_block->p_buffer[3];
761 p_out[5] = p_block->p_buffer[8] << 4;
763 p_out[6] = p_block->p_buffer[4];
764 p_out[7] = p_block->p_buffer[5];
765 p_out[8] = p_block->p_buffer[9] & 0xF0;
767 p_out[9] = p_block->p_buffer[6];
768 p_out[10] = p_block->p_buffer[7];
769 p_out[11] = p_block->p_buffer[9] << 4;
771 p_block->i_buffer -= 10;
772 p_block->p_buffer += 10;
778 assert( i_bits == 16 );
779 memcpy( p_out, p_block->p_buffer, p_block->i_buffer );
782 static void AobExtract( aout_buffer_t *p_aout_buffer,
783 block_t *p_block, unsigned i_bits, aob_group_t p_group[2] )
785 const unsigned i_channels = p_group[0].i_channels +
786 ( p_group[1].b_used ? p_group[1].i_channels : 0 );
787 uint8_t *p_out = p_aout_buffer->p_buffer;
789 while( p_block->i_buffer > 0 )
791 for( int i = 0; i < 2; i++ )
793 const aob_group_t *g = &p_group[1-i];
794 const unsigned int i_group_size = 2 * g->i_channels * i_bits / 8;
796 if( p_block->i_buffer < i_group_size )
798 p_block->i_buffer = 0;
801 for( unsigned n = 0; n < 2; n++ )
803 for( unsigned j = 0; j < g->i_channels && g->b_used; j++ )
805 const int i_src = n * g->i_channels + j;
806 const int i_dst = n * i_channels + g->pi_position[j];
810 p_out[3*i_dst+0] = p_block->p_buffer[2*i_src+0];
811 p_out[3*i_dst+1] = p_block->p_buffer[2*i_src+1];
812 p_out[3*i_dst+2] = p_block->p_buffer[4*g->i_channels+i_src];
814 else if( i_bits == 20 )
816 p_out[3*i_dst+0] = p_block->p_buffer[2*i_src+0];
817 p_out[3*i_dst+1] = p_block->p_buffer[2*i_src+1];
819 p_out[3*i_dst+2] = (p_block->p_buffer[4*g->i_channels+i_src] ) & 0xf0;
821 p_out[3*i_dst+2] = (p_block->p_buffer[4*g->i_channels+i_src] << 4) & 0xf0;
825 assert( i_bits == 16 );
826 p_out[2*i_dst+0] = p_block->p_buffer[2*i_src+0];
827 p_out[2*i_dst+1] = p_block->p_buffer[2*i_src+1];
832 p_block->i_buffer -= i_group_size;
833 p_block->p_buffer += i_group_size;
836 p_out += (i_bits == 16 ? 2 : 3) * i_channels * 2;
840 static void BdExtract( aout_buffer_t *p_aout_buffer, block_t *p_block )
842 memcpy( p_aout_buffer->p_buffer, p_block->p_buffer, p_block->i_buffer );