Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

a52tospdif.c

00001 /*****************************************************************************
00002  * a52tospdif.c : encapsulates A/52 frames into S/PDIF packets
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  * $Id: a52tospdif.c 13671 2005-12-10 19:26:03Z hartman $
00006  *
00007  * Authors: Christophe Massiot <[email protected]>
00008  *          Stéphane Borel <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  * 
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 #include <string.h>
00030 
00031 #include <vlc/vlc.h>
00032 
00033 #ifdef HAVE_UNISTD_H
00034 #   include <unistd.h>
00035 #endif
00036 
00037 #include "audio_output.h"
00038 #include "aout_internal.h"
00039 
00040 /*****************************************************************************
00041  * Local prototypes
00042  *****************************************************************************/
00043 static int  Create    ( vlc_object_t * );
00044 static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
00045                         aout_buffer_t * );
00046 
00047 /*****************************************************************************
00048  * Module descriptor
00049  *****************************************************************************/
00050 vlc_module_begin();
00051     set_category( CAT_AUDIO );
00052     set_subcategory( SUBCAT_AUDIO_MISC );
00053     set_description( _("audio filter for A/52->S/PDIF encapsulation") );
00054     set_capability( "audio filter", 10 );
00055     set_callbacks( Create, NULL );
00056 vlc_module_end();
00057 
00058 /*****************************************************************************
00059  * Create:
00060  *****************************************************************************/
00061 static int Create( vlc_object_t *p_this )
00062 {
00063     aout_filter_t * p_filter = (aout_filter_t *)p_this;
00064 
00065     if ( p_filter->input.i_format != VLC_FOURCC('a','5','2',' ') ||
00066          ( p_filter->output.i_format != VLC_FOURCC('s','p','d','b') &&
00067            p_filter->output.i_format != VLC_FOURCC('s','p','d','i') ) )
00068     {
00069         return -1;
00070     }
00071 
00072     p_filter->pf_do_work = DoWork;
00073     p_filter->b_in_place = 0;
00074 
00075     return 0;
00076 }
00077 
00078 /*****************************************************************************
00079  * DoWork: convert a buffer
00080  *****************************************************************************/
00081 static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
00082                     aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00083 {
00084     /* AC3 is natively big endian. Most SPDIF devices have the native
00085      * endianness of the computersystem.
00086      * On MAc OS X however, little endian devices are also common.
00087      */
00088     static const uint8_t p_sync_le[6] = { 0x72, 0xF8, 0x1F, 0x4E, 0x01, 0x00 };
00089     static const uint8_t p_sync_be[6] = { 0xF8, 0x72, 0x4E, 0x1F, 0x00, 0x01 };
00090 #ifndef HAVE_SWAB
00091     byte_t * p_tmp;
00092     uint16_t i;
00093 #endif
00094     uint16_t i_frame_size = p_in_buf->i_nb_bytes / 2;
00095     byte_t * p_in = p_in_buf->p_buffer;
00096     byte_t * p_out = p_out_buf->p_buffer;
00097 
00098     /* Copy the S/PDIF headers. */
00099     if( p_filter->output.i_format == VLC_FOURCC('s','p','d','b') )
00100     {
00101         p_filter->p_vlc->pf_memcpy( p_out, p_sync_be, 6 );
00102         p_out[4] = p_in[5] & 0x7; /* bsmod */
00103         p_out[6] = (i_frame_size >> 4) & 0xff;
00104         p_out[7] = (i_frame_size << 4) & 0xff;
00105         p_filter->p_vlc->pf_memcpy( &p_out[8], p_in, i_frame_size * 2 );
00106     }
00107     else
00108     {
00109         p_filter->p_vlc->pf_memcpy( p_out, p_sync_le, 6 );
00110         p_out[5] = p_in[5] & 0x7; /* bsmod */
00111         p_out[6] = (i_frame_size << 4) & 0xff;
00112         p_out[7] = (i_frame_size >> 4) & 0xff;
00113 #ifdef HAVE_SWAB
00114         swab( p_in, &p_out[8], i_frame_size * 2 );
00115 #else
00116         p_tmp = &p_out[8];
00117         for( i = i_frame_size; i-- ; )
00118         {
00119             p_tmp[0] = p_in[1];
00120             p_tmp[1] = p_in[0];
00121             p_tmp += 2; p_in += 2;
00122         }
00123 #endif
00124     }
00125     p_filter->p_vlc->pf_memset( p_out + 8 + i_frame_size * 2, 0,
00126                                 AOUT_SPDIF_SIZE - i_frame_size * 2 - 8 );
00127 
00128     p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00129     p_out_buf->i_nb_bytes = AOUT_SPDIF_SIZE;
00130 }
00131 

Generated on Tue Dec 20 10:14:27 2005 for vlc-0.8.4a by  doxygen 1.4.2