Beispiel #1
0
/*****************************************************************************
 * OpenDecoder :
 *****************************************************************************/
static int OpenDecoder( vlc_object_t *p_this )
{
    decoder_t *p_dec = (decoder_t *)p_this;
    decoder_sys_t *p_sys;

    if( p_dec->fmt_in.i_codec != VLC_CODEC_MPGA &&
        p_dec->fmt_in.i_codec != VLC_CODEC_MP3 )
        return VLC_EGENERIC;

    /* Initialize libmpg123 */
    if( InitMPG123() != MPG123_OK )
        return VLC_EGENERIC;

    /* Allocate the memory needed to store the module's structure */
    p_sys = p_dec->p_sys = malloc( sizeof(decoder_sys_t) );
    if( p_sys == NULL )
        return VLC_ENOMEM;

    p_sys->p_out = NULL;
    date_Set( &p_sys->end_date, VLC_TS_INVALID );

    if( MPG123Open( p_dec ) )
        goto error;

    p_dec->fmt_out.i_codec = VLC_CODEC_FL32;
    p_dec->fmt_out.audio.i_rate = 0; /* So end_date gets initialized */
    p_dec->fmt_out.audio.i_format = p_dec->fmt_out.i_codec;
    p_dec->pf_decode = DecodeBlock;
    p_dec->pf_flush  = Flush;

    msg_Dbg( p_this, "%4.4s->%4.4s, bits per sample: %i",
             (char *)&p_dec->fmt_in.i_codec,
             (char *)&p_dec->fmt_out.i_codec,
             aout_BitsPerSample( p_dec->fmt_out.i_codec ) );

    return VLC_SUCCESS;
error:
    ExitMPG123();
    free( p_sys );
    return VLC_EGENERIC;
}
Beispiel #2
0
/*****************************************************************************
 * OpenDecoder :
 *****************************************************************************/
static int OpenDecoder( vlc_object_t *p_this )
{
    decoder_t *p_dec = (decoder_t *)p_this;
    decoder_sys_t *p_sys;

    if( p_dec->fmt_in.i_codec != VLC_CODEC_MPGA &&
        p_dec->fmt_in.i_codec != VLC_CODEC_MP3 )
        return VLC_EGENERIC;

    p_dec->fmt_out.i_cat = AUDIO_ES;
    p_dec->fmt_out.i_codec = VLC_CODEC_FL32;

    /* Initialize libmpg123 */
    if( InitMPG123() != MPG123_OK )
        return VLC_EGENERIC;

    /* Allocate the memory needed to store the module's structure */
    p_sys = p_dec->p_sys = malloc( sizeof(decoder_sys_t) );
    if( p_sys == NULL )
        return VLC_ENOMEM;

    /* Create our mpg123 handle */
    if( ( p_sys->p_handle = mpg123_new( NULL, NULL ) ) == NULL )
        goto error;

    /* Open a new bitstream */
    if( mpg123_open_feed( p_sys->p_handle ) != MPG123_OK )
    {
        msg_Err( p_this, "mpg123 error: can't open feed" );
        goto error;
    }

    /* Disable resync stream after error */
    mpg123_param( p_sys->p_handle, MPG123_ADD_FLAGS, MPG123_NO_RESYNC, 0 );

    /* Setup output format */
    mpg123_format_none( p_sys->p_handle );

    if( MPG123_OK != mpg123_format( p_sys->p_handle,
                                    p_dec->fmt_in.audio.i_rate,
                                    MPG123_MONO | MPG123_STEREO,
                                    MPG123_ENC_FLOAT_32 ) )
    {
        msg_Err( p_this, "mpg123 error: %s",
                mpg123_strerror( p_sys->p_handle ) );
        mpg123_close( p_sys->p_handle );
        goto error;
    }

    p_dec->fmt_out.audio.i_rate = 0; /* So end_date gets initialized */
    p_dec->fmt_out.audio.i_format = p_dec->fmt_out.i_codec;
    p_dec->pf_decode_audio = DecodeBlock;

    msg_Dbg( p_this, "%4.4s->%4.4s, bits per sample: %i",
             (char *)&p_dec->fmt_in.i_codec,
             (char *)&p_dec->fmt_out.i_codec,
             aout_BitsPerSample( p_dec->fmt_out.i_codec ) );

    return VLC_SUCCESS;
error:
    mpg123_delete( p_sys->p_handle );
    ExitMPG123();
    free( p_sys );
    return VLC_EGENERIC;
}