00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdlib.h>
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
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
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
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
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
00085
00086
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
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;
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;
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