Commit 29331c25 authored by Yavor Doganov's avatar Yavor Doganov Committed by Christophe Mutricy

Port to new libmpcdec API

Please find attached my attempt to port VLC to libmpcdec6.  Playing
and seeking works according to my tests with a bunch of files (both
SV7 and SV8).  I tried to follow upstream's coding style.
Signed-off-by: default avatarChristophe Mutricy <xtophe@videolan.org>
(cherry picked from commit 87cb4e59)
parent 0fc00a79
...@@ -2950,9 +2950,12 @@ AC_ARG_ENABLE(mpc, ...@@ -2950,9 +2950,12 @@ AC_ARG_ENABLE(mpc,
[ --enable-mpc Mpc demux support (default enabled)]) [ --enable-mpc Mpc demux support (default enabled)])
if test "${enable_mpc}" != "no" if test "${enable_mpc}" != "no"
then then
AC_CHECK_HEADERS(mpcdec/mpcdec.h, [ AC_CHECK_HEADERS([mpc/mpcdec.h], [
VLC_ADD_PLUGIN([mpc]) VLC_ADD_PLUGIN([mpc])
VLC_ADD_LIBS([mpc],[-lmpcdec])]) VLC_ADD_LIBS([mpc],[-lmpcdec])],
[AC_CHECK_HEADERS([mpcdec/mpcdec.h], [
VLC_ADD_PLUGIN([mpc])
VLC_ADD_LIBS([mpc],[-lmpcdec])])])
fi fi
dnl dnl
......
...@@ -35,7 +35,11 @@ ...@@ -35,7 +35,11 @@
#include <vlc_codec.h> #include <vlc_codec.h>
#include <math.h> #include <math.h>
#ifdef HAVE_MPC_MPCDEC_H
#include <mpc/mpcdec.h>
#else
#include <mpcdec/mpcdec.h> #include <mpcdec/mpcdec.h>
#endif
/* TODO: /* TODO:
* - test stream version 4..6 * - test stream version 4..6
...@@ -74,7 +78,11 @@ struct demux_sys_t ...@@ -74,7 +78,11 @@ struct demux_sys_t
es_out_id_t *p_es; es_out_id_t *p_es;
/* */ /* */
#ifndef HAVE_MPC_MPCDEC_H
mpc_decoder decoder; mpc_decoder decoder;
#else
mpc_demux *decoder;
#endif
mpc_reader reader; mpc_reader reader;
mpc_streaminfo info; mpc_streaminfo info;
...@@ -82,11 +90,19 @@ struct demux_sys_t ...@@ -82,11 +90,19 @@ struct demux_sys_t
int64_t i_position; int64_t i_position;
}; };
#ifndef HAVE_MPC_MPCDEC_H
static mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size ); static mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size );
static mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset ); static mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset );
static mpc_int32_t ReaderTell( void *p_private); static mpc_int32_t ReaderTell( void *p_private);
static mpc_int32_t ReaderGetSize( void *p_private ); static mpc_int32_t ReaderGetSize( void *p_private );
static mpc_bool_t ReaderCanSeek( void *p_private ); static mpc_bool_t ReaderCanSeek( void *p_private );
#else
static mpc_int32_t ReaderRead( mpc_reader *p_private, void *dst, mpc_int32_t i_size );
static mpc_bool_t ReaderSeek( mpc_reader *p_private, mpc_int32_t i_offset );
static mpc_int32_t ReaderTell( mpc_reader *p_private);
static mpc_int32_t ReaderGetSize( mpc_reader *p_private );
static mpc_bool_t ReaderCanSeek( mpc_reader *p_private );
#endif
/***************************************************************************** /*****************************************************************************
* Open: initializes ES structures * Open: initializes ES structures
...@@ -101,11 +117,15 @@ static int Open( vlc_object_t * p_this ) ...@@ -101,11 +117,15 @@ static int Open( vlc_object_t * p_this )
if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
return VLC_EGENERIC; return VLC_EGENERIC;
if( memcmp( p_peek, "MP+", 3 ) ) if( memcmp( p_peek, "MP+", 3 )
#ifdef HAVE_MPC_MPCDEC_H
/* SV8 format */
&& memcmp( p_peek, "MPCK", 4 )
#endif
)
{ {
/* for v4..6 we check extension file */ /* for v4..6 we check extension file */
const int i_version = (GetDWLE( p_peek ) >> 11)&0x3ff; const int i_version = (GetDWLE( p_peek ) >> 11)&0x3ff;
if( i_version < 4 || i_version > 6 ) if( i_version < 4 || i_version > 6 )
return VLC_EGENERIC; return VLC_EGENERIC;
...@@ -133,6 +153,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -133,6 +153,7 @@ static int Open( vlc_object_t * p_this )
p_sys->reader.canseek = ReaderCanSeek; p_sys->reader.canseek = ReaderCanSeek;
p_sys->reader.data = p_demux; p_sys->reader.data = p_demux;
#ifndef HAVE_MPC_MPCDEC_H
/* Load info */ /* Load info */
mpc_streaminfo_init( &p_sys->info ); mpc_streaminfo_init( &p_sys->info );
if( mpc_streaminfo_read( &p_sys->info, &p_sys->reader ) != ERROR_CODE_OK ) if( mpc_streaminfo_read( &p_sys->info, &p_sys->reader ) != ERROR_CODE_OK )
...@@ -142,6 +163,13 @@ static int Open( vlc_object_t * p_this ) ...@@ -142,6 +163,13 @@ static int Open( vlc_object_t * p_this )
mpc_decoder_setup( &p_sys->decoder, &p_sys->reader ); mpc_decoder_setup( &p_sys->decoder, &p_sys->reader );
if( !mpc_decoder_initialize( &p_sys->decoder, &p_sys->info ) ) if( !mpc_decoder_initialize( &p_sys->decoder, &p_sys->info ) )
goto error; goto error;
#else
p_sys->decoder = mpc_demux_init( &p_sys->reader );
if( !p_sys->decoder )
goto error;
mpc_demux_get_info( p_sys->decoder, &p_sys->info );
#endif
/* Fill p_demux fields */ /* Fill p_demux fields */
p_demux->pf_demux = Demux; p_demux->pf_demux = Demux;
...@@ -198,6 +226,10 @@ static void Close( vlc_object_t * p_this ) ...@@ -198,6 +226,10 @@ static void Close( vlc_object_t * p_this )
demux_t *p_demux = (demux_t*)p_this; demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
#ifdef HAVE_MPC_MPCDEC_H
if( p_sys->decoder )
mpc_demux_exit( p_sys->decoder );
#endif
free( p_sys ); free( p_sys );
} }
...@@ -211,12 +243,16 @@ static int Demux( demux_t *p_demux ) ...@@ -211,12 +243,16 @@ static int Demux( demux_t *p_demux )
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
block_t *p_data; block_t *p_data;
int i_ret; int i_ret;
#ifdef HAVE_MPC_MPCDEC_H
mpc_frame_info frame;
mpc_status err;
#endif
p_data = block_New( p_demux, p_data = block_New( p_demux,
MPC_DECODER_BUFFER_LENGTH*sizeof(MPC_SAMPLE_FORMAT) ); MPC_DECODER_BUFFER_LENGTH*sizeof(MPC_SAMPLE_FORMAT) );
if( !p_data ) if( !p_data )
return -1; return -1;
#ifndef HAVE_MPC_MPCDEC_H
i_ret = mpc_decoder_decode( &p_sys->decoder, i_ret = mpc_decoder_decode( &p_sys->decoder,
(MPC_SAMPLE_FORMAT*)p_data->p_buffer, (MPC_SAMPLE_FORMAT*)p_data->p_buffer,
NULL, NULL ); NULL, NULL );
...@@ -225,6 +261,22 @@ static int Demux( demux_t *p_demux ) ...@@ -225,6 +261,22 @@ static int Demux( demux_t *p_demux )
block_Release( p_data ); block_Release( p_data );
return i_ret < 0 ? -1 : 0; return i_ret < 0 ? -1 : 0;
} }
#else
frame.buffer = (MPC_SAMPLE_FORMAT*)p_data->p_buffer;
err = mpc_demux_decode( p_sys->decoder, &frame );
if( err != MPC_STATUS_OK )
{
block_Release( p_data );
return -1;
}
else if( frame.bits == -1 )
{
block_Release( p_data );
return 0;
}
i_ret = frame.samples;
#endif
/* */ /* */
p_data->i_buffer = i_ret * sizeof(MPC_SAMPLE_FORMAT) * p_sys->info.channels; p_data->i_buffer = i_ret * sizeof(MPC_SAMPLE_FORMAT) * p_sys->info.channels;
...@@ -260,15 +312,27 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) ...@@ -260,15 +312,27 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
case DEMUX_GET_LENGTH: case DEMUX_GET_LENGTH:
pi64 = (int64_t*)va_arg( args, int64_t * ); pi64 = (int64_t*)va_arg( args, int64_t * );
#ifndef HAVE_MPC_MPCDEC_H
*pi64 = INT64_C(1000000) * p_sys->info.pcm_samples / *pi64 = INT64_C(1000000) * p_sys->info.pcm_samples /
p_sys->info.sample_freq; p_sys->info.sample_freq;
#else
*pi64 = INT64_C(1000000) * (p_sys->info.samples -
p_sys->info.beg_silence) /
p_sys->info.sample_freq;
#endif
return VLC_SUCCESS; return VLC_SUCCESS;
case DEMUX_GET_POSITION: case DEMUX_GET_POSITION:
pf = (double*)va_arg( args, double * ); pf = (double*)va_arg( args, double * );
#ifndef HAVE_MPC_MPCDEC_H
if( p_sys->info.pcm_samples > 0 ) if( p_sys->info.pcm_samples > 0 )
*pf = (double) p_sys->i_position / *pf = (double) p_sys->i_position /
(double)p_sys->info.pcm_samples; (double)p_sys->info.pcm_samples;
#else
if( p_sys->info.samples - p_sys->info.beg_silence > 0)
*pf = (double) p_sys->i_position /
(double)(p_sys->info.samples - p_sys->info.beg_silence);
#endif
else else
*pf = 0.0; *pf = 0.0;
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -281,8 +345,14 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) ...@@ -281,8 +345,14 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
case DEMUX_SET_POSITION: case DEMUX_SET_POSITION:
f = (double)va_arg( args, double ); f = (double)va_arg( args, double );
#ifndef HAVE_MPC_MPCDEC_H
i64 = (int64_t)(f * p_sys->info.pcm_samples); i64 = (int64_t)(f * p_sys->info.pcm_samples);
if( mpc_decoder_seek_sample( &p_sys->decoder, i64 ) ) if( mpc_decoder_seek_sample( &p_sys->decoder, i64 ) )
#else
i64 = (int64_t)(f * (p_sys->info.samples -
p_sys->info.beg_silence));
if( mpc_demux_seek_sample( p_sys->decoder, i64 ) == MPC_STATUS_OK )
#endif
{ {
p_sys->i_position = i64; p_sys->i_position = i64;
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -291,7 +361,11 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) ...@@ -291,7 +361,11 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
case DEMUX_SET_TIME: case DEMUX_SET_TIME:
i64 = (int64_t)va_arg( args, int64_t ); i64 = (int64_t)va_arg( args, int64_t );
#ifndef HAVE_MPC_MPCDEC_H
if( mpc_decoder_seek_sample( &p_sys->decoder, i64 ) ) if( mpc_decoder_seek_sample( &p_sys->decoder, i64 ) )
#else
if( mpc_demux_seek_sample( p_sys->decoder, i64 ) == MPC_STATUS_OK )
#endif
{ {
p_sys->i_position = i64; p_sys->i_position = i64;
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -303,33 +377,63 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) ...@@ -303,33 +377,63 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
} }
} }
#ifndef HAVE_MPC_MPCDEC_H
static mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size ) static mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size )
{ {
demux_t *p_demux = (demux_t*)p_private; demux_t *p_demux = (demux_t*)p_private;
#else
static mpc_int32_t ReaderRead( mpc_reader *p_private, void *dst, mpc_int32_t i_size )
{
demux_t *p_demux = (demux_t*)p_private->data;
#endif
return stream_Read( p_demux->s, dst, i_size ); return stream_Read( p_demux->s, dst, i_size );
} }
#ifndef HAVE_MPC_MPCDEC_H
static mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset ) static mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset )
{ {
demux_t *p_demux = (demux_t*)p_private; demux_t *p_demux = (demux_t*)p_private;
#else
static mpc_bool_t ReaderSeek( mpc_reader *p_private, mpc_int32_t i_offset )
{
demux_t *p_demux = (demux_t*)p_private->data;
#endif
return !stream_Seek( p_demux->s, i_offset ); return !stream_Seek( p_demux->s, i_offset );
} }
#ifndef HAVE_MPC_MPCDEC_H
static mpc_int32_t ReaderTell( void *p_private) static mpc_int32_t ReaderTell( void *p_private)
{ {
demux_t *p_demux = (demux_t*)p_private; demux_t *p_demux = (demux_t*)p_private;
#else
static mpc_int32_t ReaderTell( mpc_reader *p_private)
{
demux_t *p_demux = (demux_t*)p_private->data;
#endif
return stream_Tell( p_demux->s ); return stream_Tell( p_demux->s );
} }
#ifndef HAVE_MPC_MPCDEC_H
static mpc_int32_t ReaderGetSize( void *p_private ) static mpc_int32_t ReaderGetSize( void *p_private )
{ {
demux_t *p_demux = (demux_t*)p_private; demux_t *p_demux = (demux_t*)p_private;
#else
static mpc_int32_t ReaderGetSize( mpc_reader *p_private )
{
demux_t *p_demux = (demux_t*)p_private->data;
#endif
return stream_Size( p_demux->s ); return stream_Size( p_demux->s );
} }
#ifndef HAVE_MPC_MPCDEC_H
static mpc_bool_t ReaderCanSeek( void *p_private ) static mpc_bool_t ReaderCanSeek( void *p_private )
{ {
demux_t *p_demux = (demux_t*)p_private; demux_t *p_demux = (demux_t*)p_private;
#else
static mpc_bool_t ReaderCanSeek( mpc_reader *p_private )
{
demux_t *p_demux = (demux_t*)p_private->data;
#endif
bool b_canseek; bool b_canseek;
stream_Control( p_demux->s, STREAM_CAN_SEEK, &b_canseek ); stream_Control( p_demux->s, STREAM_CAN_SEEK, &b_canseek );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment