*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <vlc/vlc.h>
-#include <vlc/aout.h>
-#include <vlc/vout.h>
-#include <vlc/decoder.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_aout.h>
+#include <vlc_codec.h>
#ifdef LOADER
/* Need the w32dll loader from mplayer */
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
-vlc_module_begin();
- set_description( _("RealAudio library decoder") );
- set_capability( "decoder", 10 );
- set_category( CAT_INPUT );
- set_subcategory( SUBCAT_INPUT_VCODEC );
- set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+ set_description( N_("RealAudio library decoder") )
+ set_capability( "decoder", 10 )
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_VCODEC )
+ set_callbacks( Open, Close )
+vlc_module_end ()
/*****************************************************************************
* Local prototypes
{
audio_date_t end_date;
- /* Frame buffer for data reordering */
- int i_subpacket;
- mtime_t i_packet_pts;
- int i_frame_size;
- char *p_frame;
- int i_frame;
-
/* Output buffer */
- char *p_out_buffer;
char *p_out;
unsigned int i_out;
/* Codec params */
void *context;
- int i_subpacket_size;
- int i_subpacket_h;
- int i_codec_flavor;
- int i_coded_frame_size;
- int i_extra;
- uint8_t *p_extra;
+ short int i_codec_flavor;
void *dll;
unsigned long (*raCloseCodec)(void*);
#endif
void *win32_dll;
- unsigned long WINAPI (*wraCloseCodec)(void*);
- unsigned long WINAPI (*wraDecode)(void*, char*, unsigned long, char*,
+ unsigned long (WINAPI *wraCloseCodec)(void*);
+ unsigned long (WINAPI *wraDecode)(void*, char*, unsigned long, char*,
unsigned int*, long);
- unsigned long WINAPI (*wraFlush)(unsigned long, unsigned long,
+ unsigned long (WINAPI *wraFlush)(unsigned long, unsigned long,
unsigned long);
- unsigned long WINAPI (*wraFreeDecoder)(void*);
- void* WINAPI (*wraGetFlavorProperty)(void*, unsigned long,
+ unsigned long (WINAPI *wraFreeDecoder)(void*);
+ void* (WINAPI *wraGetFlavorProperty)(void*, unsigned long,
unsigned long, int*);
- unsigned long WINAPI (*wraInitDecoder)(void*, void*);
- unsigned long WINAPI (*wraOpenCodec)(void*);
- unsigned long WINAPI (*wraOpenCodec2)(void*, void*);
- unsigned long WINAPI (*wraSetFlavor)(void*, unsigned long);
- void WINAPI (*wraSetDLLAccessPath)(char*);
- void WINAPI (*wraSetPwd)(char*, char*);
+ unsigned long (WINAPI *wraInitDecoder)(void*, void*);
+ unsigned long (WINAPI *wraOpenCodec)(void*);
+ unsigned long (WINAPI *wraOpenCodec2)(void*, void*);
+ unsigned long (WINAPI *wraSetFlavor)(void*, unsigned long);
+ void (WINAPI *wraSetDLLAccessPath)(char*);
+ void (WINAPI *wraSetPwd)(char*, char*);
};
/* linux dlls doesn't need packing */
void *__builtin_new(unsigned long size) {return malloc(size);}
void __builtin_delete(void *p) {free(p);}
-static int pi_channels_maps[7] =
+static const int pi_channels_maps[7] =
{
0,
AOUT_CHAN_CENTER,
switch( p_dec->fmt_in.i_codec )
{
- case VLC_FOURCC('c','o','o','k'):
+ case VLC_CODEC_COOK:
+ case VLC_CODEC_ATRAC3:
+ case VLC_FOURCC('s','i','p','r'):
break;
default:
return VLC_EGENERIC;
}
- p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) );
- memset( p_sys, 0, sizeof(decoder_sys_t) );
+ /* Channel detection */
+ if( p_dec->fmt_in.audio.i_channels <= 0 ||
+ p_dec->fmt_in.audio.i_channels > 6 )
+ {
+ msg_Err( p_dec, "invalid number of channels (not between 1 and 6): %i",
+ p_dec->fmt_in.audio.i_channels );
+ return VLC_EGENERIC;
+ }
+
+ p_dec->p_sys = p_sys = calloc( 1, sizeof( *p_sys ) );
+ if( !p_sys )
+ return VLC_ENOMEM;
- if( p_dec->fmt_in.i_extra >= 10 )
+ /* Flavor for SIPR codecs */
+ p_sys->i_codec_flavor = -1;
+ if( p_dec->fmt_in.i_codec == VLC_FOURCC('s','i','p','r') )
{
- p_sys->i_subpacket_size = ((short *)(p_dec->fmt_in.p_extra))[0];
- p_sys->i_subpacket_h = ((short *)(p_dec->fmt_in.p_extra))[1];
- p_sys->i_codec_flavor = ((short *)(p_dec->fmt_in.p_extra))[2];
- p_sys->i_coded_frame_size = ((short *)(p_dec->fmt_in.p_extra))[3];
- p_sys->i_extra = ((short*)(p_dec->fmt_in.p_extra))[4];
- p_sys->p_extra = p_dec->fmt_in.p_extra + 10;
+ p_sys->i_codec_flavor = p_dec->fmt_in.audio.i_flavor;
+ msg_Dbg( p_dec, "Got sipr flavor %d", p_sys->i_codec_flavor );
}
if( OpenDll( p_dec ) != VLC_SUCCESS )
p_dec->pf_decode_audio = Decode;
- p_sys->i_frame_size =
- p_dec->fmt_in.audio.i_blockalign * p_sys->i_subpacket_h;
- p_sys->p_frame = malloc( p_sys->i_frame_size );
- p_sys->i_packet_pts = 0;
- p_sys->i_subpacket = 0;
- p_sys->i_frame = 0;
-
- p_sys->p_out_buffer = malloc( 4096 * 10 );
- p_sys->p_out = 0;
+ p_sys->p_out = malloc( 4096 * 10 );
+ if( !p_sys->p_out )
+ {
+ free( p_sys );
+ return VLC_ENOMEM;
+ }
p_sys->i_out = 0;
return VLC_SUCCESS;
decoder_t *p_dec = (decoder_t*)p_this;
CloseDll( p_dec );
- if( p_dec->p_sys->p_frame ) free( p_dec->p_sys->p_frame );
- if( p_dec->p_sys->p_out_buffer ) free( p_dec->p_sys->p_out_buffer );
+ free( p_dec->p_sys->p_out );
free( p_dec->p_sys );
}
char *psz_dll;
int i, i_result;
+ /** Find the good path for the dlls.**/
char *ppsz_path[] =
{
".",
"/usr/lib/RealPlayer8/Codecs",
"/opt/RealPlayer8/Codecs",
"/usr/lib/RealPlayer9/users/Real/Codecs",
+ "/usr/lib/RealPlayer10/codecs",
+ "/usr/lib/RealPlayer10GOLD/codecs",
+ "/usr/lib/helix/player/codecs",
"/usr/lib64/RealPlayer8/Codecs",
"/usr/lib64/RealPlayer9/users/Real/Codecs",
+ "/usr/lib64/RealPlayer10/codecs",
+ "/usr/lib64/RealPlayer10GOLD/codecs",
"/usr/lib/win32",
+ "/usr/lib/codecs",
+ "/usr/local/lib/codecs",
#endif
NULL,
NULL,
#ifdef WIN32
char psz_win32_real_codecs[MAX_PATH + 1];
char psz_win32_helix_codecs[MAX_PATH + 1];
-#endif
- for( i = 0; ppsz_path[i]; i++ )
- {
- asprintf( &psz_dll, "%s/%4.4s.so.6.0", ppsz_path[i],
- (char *)&p_dec->fmt_in.i_codec );
- i_result = OpenNativeDll( p_dec, ppsz_path[i], psz_dll );
- free( psz_dll );
- if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
- }
-
-#ifdef WIN32
{
HKEY h_key;
DWORD i_type, i_data = MAX_PATH + 1, i_index = 1;
}
#endif
+
+ /** Try the native libraries first **/
+#ifndef WIN32
+ for( i = 0; ppsz_path[i]; i++ )
+ {
+ /* Old format */
+ if( asprintf( &psz_dll, "%s/%4.4s.so.6.0", ppsz_path[i],
+ (char *)&p_dec->fmt_in.i_codec ) != -1 )
+ {
+ i_result = OpenNativeDll( p_dec, ppsz_path[i], psz_dll );
+ free( psz_dll );
+ if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+ }
+
+ /* New format */
+ if( asprintf( &psz_dll, "%s/%4.4s.so", ppsz_path[i],
+ (char *)&p_dec->fmt_in.i_codec ) != -1 )
+ {
+ i_result = OpenNativeDll( p_dec, ppsz_path[i], psz_dll );
+ free( psz_dll );
+ if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+ }
+ }
+#endif
+
+ /** Or use the WIN32 dlls **/
+#if defined(LOADER) || defined(WIN32)
for( i = 0; ppsz_path[i]; i++ )
{
/* New format */
- asprintf( &psz_dll, "%s\\%4.4s.dll", ppsz_path[i],
- (char *)&p_dec->fmt_in.i_codec );
- i_result = OpenWin32Dll( p_dec, ppsz_path[i], psz_dll );
- free( psz_dll );
- if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+ if( asprintf( &psz_dll, "%s\\%4.4s.dll", ppsz_path[i],
+ (char *)&p_dec->fmt_in.i_codec ) != -1 )
+ {
+ i_result = OpenWin32Dll( p_dec, ppsz_path[i], psz_dll );
+ free( psz_dll );
+ if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+ }
/* Old format */
- asprintf( &psz_dll, "%s\\%4.4s3260.dll", ppsz_path[i],
- (char *)&p_dec->fmt_in.i_codec );
- i_result = OpenWin32Dll( p_dec, ppsz_path[i], psz_dll );
- free( psz_dll );
- if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+ if( asprintf( &psz_dll, "%s\\%4.4s3260.dll", ppsz_path[i],
+ (char *)&p_dec->fmt_in.i_codec ) != -1 )
+ {
+ i_result = OpenWin32Dll( p_dec, ppsz_path[i], psz_dll );
+ free( psz_dll );
+ if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+ }
}
+#endif
return VLC_EGENERIC;
}
p_dec->fmt_in.audio.i_bitspersample,
p_dec->fmt_in.audio.i_channels,
100, /* quality */
- p_sys->i_subpacket_size,
- p_sys->i_coded_frame_size,
- p_sys->i_extra, p_sys->p_extra
+ p_dec->fmt_in.audio.i_blockalign, /* subpacket size */
+ p_dec->fmt_in.audio.i_blockalign, /* coded frame size */
+ p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra
};
msg_Dbg( p_dec, "opening library '%s'", psz_dll );
goto error_native;
}
- i_result = p_sys->raSetFlavor( context, p_sys->i_codec_flavor );
- if( i_result )
+ if( p_sys->i_codec_flavor >= 0 )
{
- msg_Err( p_dec, "decoder flavor setup failed, error code: 0x%x",
- i_result );
- goto error_native;
- }
+ i_result = p_sys->raSetFlavor( context, p_sys->i_codec_flavor );
+ if( i_result )
+ {
+ msg_Err( p_dec, "decoder flavor setup failed, error code: 0x%x",
+ i_result );
+ goto error_native;
+ }
- p_prop = p_sys->raGetFlavorProperty( context, p_sys->i_codec_flavor,
- 0, &i_prop );
- msg_Dbg( p_dec, "audio codec: [%d] %s",
- p_sys->i_codec_flavor, (char *)p_prop );
+ p_prop = p_sys->raGetFlavorProperty( context, p_sys->i_codec_flavor,
+ 0, &i_prop );
+ msg_Dbg( p_dec, "audio codec: [%d] %s",
+ p_sys->i_codec_flavor, (char *)p_prop );
- p_prop = p_sys->raGetFlavorProperty( context, p_sys->i_codec_flavor,
- 1, &i_prop );
- if( p_prop )
- {
- int i_bps = ((*((int*)p_prop))+4)/8;
- msg_Dbg( p_dec, "audio bitrate: %5.3f kbit/s (%d bps)",
- (*((int*)p_prop))*0.001f, i_bps );
+ p_prop = p_sys->raGetFlavorProperty( context, p_sys->i_codec_flavor,
+ 1, &i_prop );
+ if( p_prop )
+ {
+ int i_bps = ((*((int*)p_prop))+4)/8;
+ msg_Dbg( p_dec, "audio bitrate: %5.3f kbit/s (%d bps)",
+ (*((int*)p_prop))*0.001f, i_bps );
+ }
}
p_sys->context = context;
p_dec->fmt_in.audio.i_bitspersample,
p_dec->fmt_in.audio.i_channels,
100, /* quality */
- p_sys->i_subpacket_size,
- p_sys->i_coded_frame_size,
- p_sys->i_extra, p_sys->p_extra
+ p_dec->fmt_in.audio.i_blockalign, /* subpacket size */
+ p_dec->fmt_in.audio.i_blockalign, /* coded frame size */
+ p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra
};
msg_Dbg( p_dec, "opening win32 dll '%s'", psz_dll );
goto error_win32;
}
- i_result = p_sys->wraSetFlavor( context, p_sys->i_codec_flavor );
- if( i_result )
+ if( p_sys->i_codec_flavor >= 0 )
{
- msg_Err( p_dec, "decoder flavor setup failed, error code: 0x%x",
- i_result );
- goto error_win32;
- }
+ i_result = p_sys->wraSetFlavor( context, p_sys->i_codec_flavor );
+ if( i_result )
+ {
+ msg_Err( p_dec, "decoder flavor setup failed, error code: 0x%x",
+ i_result );
+ goto error_win32;
+ }
- p_prop = p_sys->wraGetFlavorProperty( context, p_sys->i_codec_flavor,
- 0, &i_prop );
- msg_Dbg( p_dec, "audio codec: [%d] %s",
- p_sys->i_codec_flavor, (char *)p_prop );
+ p_prop = p_sys->wraGetFlavorProperty( context, p_sys->i_codec_flavor,
+ 0, &i_prop );
+ msg_Dbg( p_dec, "audio codec: [%d] %s",
+ p_sys->i_codec_flavor, (char *)p_prop );
- p_prop = p_sys->wraGetFlavorProperty( context, p_sys->i_codec_flavor,
- 1, &i_prop );
- if( p_prop )
- {
- int i_bps = ((*((int*)p_prop))+4)/8;
- msg_Dbg( p_dec, "audio bitrate: %5.3f kbit/s (%d bps)",
- (*((int*)p_prop))*0.001f, i_bps );
+ p_prop = p_sys->wraGetFlavorProperty( context, p_sys->i_codec_flavor,
+ 1, &i_prop );
+ if( p_prop )
+ {
+ int i_bps = ((*((int*)p_prop))+4)/8;
+ msg_Dbg( p_dec, "audio bitrate: %5.3f kbit/s (%d bps)",
+ (*((int*)p_prop))*0.001f, i_bps );
+ }
}
p_sys->context = context;
{
decoder_sys_t *p_sys = p_dec->p_sys;
aout_buffer_t *p_aout_buffer = 0;
+ unsigned int i_result;
+ int i_samples;
block_t *p_block;
#ifdef LOADER
if( OpenDll( p_dec ) != VLC_SUCCESS )
{
/* Fatal */
- p_dec->b_error = VLC_TRUE;
+ p_dec->b_error = true;
return NULL;
}
}
#endif
- /* Output 1024 samples at a time
- * (the audio output doesn't like big audio packets) */
- if( p_sys->i_out )
- {
- int i_out;
- int i_samples = p_sys->i_out * 8 /
- p_dec->fmt_out.audio.i_bitspersample /
- p_dec->fmt_out.audio.i_channels;
-
- i_samples = __MIN( i_samples, 1024 );
- i_out = i_samples * p_dec->fmt_out.audio.i_bitspersample *
- p_dec->fmt_out.audio.i_channels / 8;
-
- p_aout_buffer = p_dec->pf_aout_buffer_new( p_dec, i_samples );
- if( p_aout_buffer == NULL ) return NULL;
- memcpy( p_aout_buffer->p_buffer, p_sys->p_out, i_out );
-
- p_sys->i_out -= i_out;
- p_sys->p_out += i_out;
-
- /* Date management */
- p_aout_buffer->start_date = aout_DateGet( &p_sys->end_date );
- p_aout_buffer->end_date =
- aout_DateIncrement( &p_sys->end_date, i_samples );
-
- return p_aout_buffer;
- }
-
- /* If we have a full frame ready then we can start decoding */
- if( p_sys->i_frame )
- {
- unsigned int i_result;
-
- p_sys->p_out = p_sys->p_out_buffer;
-
- if( p_sys->dll )
- i_result = p_sys->raDecode( p_sys->context, p_sys->p_frame +
- p_sys->i_frame_size - p_sys->i_frame,
- p_dec->fmt_in.audio.i_blockalign,
- p_sys->p_out, &p_sys->i_out, -1 );
- else
- i_result = p_sys->wraDecode( p_sys->context, p_sys->p_frame +
- p_sys->i_frame_size - p_sys->i_frame,
- p_dec->fmt_in.audio.i_blockalign,
- p_sys->p_out, &p_sys->i_out, -1 );
-
-#if 0
- msg_Err( p_dec, "decoded: %i samples (%i)",
- p_sys->i_out * 8 / p_dec->fmt_out.audio.i_bitspersample /
- p_dec->fmt_out.audio.i_channels, i_result );
-#endif
-
- p_sys->i_frame -= p_dec->fmt_in.audio.i_blockalign;
-
- return Decode( p_dec, pp_block );
- }
-
-
if( pp_block == NULL || *pp_block == NULL ) return NULL;
p_block = *pp_block;
- //msg_Err( p_dec, "Decode: "I64Fd", %i", p_block->i_pts, p_block->i_buffer );
+ if( p_sys->dll )
+ i_result = p_sys->raDecode( p_sys->context, (char *)p_block->p_buffer,
+ (unsigned long)p_block->i_buffer,
+ p_sys->p_out, &p_sys->i_out, -1 );
+ else
+ i_result = p_sys->wraDecode( p_sys->context, (char *)p_block->p_buffer,
+ (unsigned long)p_block->i_buffer,
+ p_sys->p_out, &p_sys->i_out, -1 );
- /* Detect missing subpackets */
- if( p_sys->i_subpacket && p_block->i_pts > 0 &&
- p_block->i_pts != p_sys->i_packet_pts )
- {
- /* All subpackets in a packet should have the same pts so we must
- * have dropped some. Clear current frame buffer. */
- p_sys->i_subpacket = 0;
- msg_Dbg( p_dec, "detected dropped subpackets" );
- }
- if( p_block->i_pts > 0 ) p_sys->i_packet_pts = p_block->i_pts;
+#if 0
+ msg_Err( p_dec, "decoded: %i samples (%i)",
+ p_sys->i_out * 8 / p_dec->fmt_out.audio.i_bitspersample /
+ p_dec->fmt_out.audio.i_channels, i_result );
+#endif
/* Date management */
- if( /* !p_sys->i_subpacket && */ p_block && p_block->i_pts > 0 &&
+ if( p_block->i_pts > 0 &&
p_block->i_pts != aout_DateGet( &p_sys->end_date ) )
{
aout_DateSet( &p_sys->end_date, p_block->i_pts );
}
-#if 0
if( !aout_DateGet( &p_sys->end_date ) )
{
/* We've just started the stream, wait for the first PTS. */
if( p_block ) block_Release( p_block );
return NULL;
}
-#endif
- if( p_sys->i_subpacket_size )
- {
- /* 'cook' way */
- int sps = p_sys->i_subpacket_size;
- int w = p_dec->fmt_in.audio.i_blockalign;
- int h = p_sys->i_subpacket_h;
- /* int cfs = p_sys->i_coded_frame_size; */
- int x, y;
-
- w /= sps;
- y = p_sys->i_subpacket;
-
- for( x = 0; x < w; x++ )
- {
- memcpy( p_sys->p_frame + sps * (h*x+((h+1)/2)*(y&1)+(y>>1)),
- p_block->p_buffer, sps );
- p_block->p_buffer += sps;
- }
+ i_samples = p_sys->i_out * 8 /
+ p_dec->fmt_out.audio.i_bitspersample /p_dec->fmt_out.audio.i_channels;
- p_sys->i_subpacket = (p_sys->i_subpacket + 1) % p_sys->i_subpacket_h;
+ p_aout_buffer =
+ decoder_NewAudioBuffer( p_dec, i_samples );
+ if( p_aout_buffer )
+ {
+ memcpy( p_aout_buffer->p_buffer, p_sys->p_out, p_sys->i_out );
- if( !p_sys->i_subpacket )
- {
- /* We have a complete frame */
- p_sys->i_frame = p_sys->i_frame_size;
- p_aout_buffer = Decode( p_dec, pp_block );
- }
+ /* Date management */
+ p_aout_buffer->start_date = aout_DateGet( &p_sys->end_date );
+ p_aout_buffer->end_date =
+ aout_DateIncrement( &p_sys->end_date, i_samples );
}
block_Release( p_block );