Exemple #1
0
int mpae_init_toolame(audio_encoder_t *encoder)
{
	int mode;
	mpae_toolame_ctx *ctx = NULL;

	if(encoder->params.channels == 1)
	{
		mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_toolame, 1 audio channel, forcing mono mode\n");
		mode = MPG_MD_MONO;
	}
	else if(encoder->params.channels == 2)
	{
		if(! strcasecmp(param_mode, "dual"))
			mode = MPG_MD_DUAL_CHANNEL;
		else if(! strcasecmp(param_mode, "jstereo"))
			mode = MPG_MD_JOINT_STEREO;
		else if(! strcasecmp(param_mode, "stereo"))
			mode = MPG_MD_STEREO;
		else
		{
			mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, unknown mode %s, exiting\n", param_mode);
		}
	}
	else
		mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, Toolame can't encode > 2 channels, exiting\n");

	ctx = calloc(1, sizeof(mpae_toolame_ctx));
	if(ctx == NULL)
	{
		mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_toolame_ctx));
		return 0;
	}

	ctx->toolame_ctx = toolame_init();
	if(ctx->toolame_ctx == NULL)
	{
		mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't initial parameters from libtoolame, exiting\n");
		free(ctx);
		return 0;
	}
	ctx->vbr = 0;
	ctx->channels = encoder->params.channels;
	ctx->srate = encoder->params.sample_rate;

	if(toolame_setMode(ctx->toolame_ctx, mode) != 0)
		return 0;

	if(toolame_setPsymodel(ctx->toolame_ctx, param_psy) != 0)
		return 0;

	if(toolame_setSampleFreq(ctx->toolame_ctx, encoder->params.sample_rate) != 0)
		return 0;

	if(toolame_setBitrate(ctx->toolame_ctx, param_bitrate) != 0)
		return 0;

	if(param_errprot)
		if(toolame_setErrorProtection(ctx->toolame_ctx, TRUE) != 0)
			return 0;

	if(param_vbr != 0)
	{
		if(toolame_setVBR(ctx->toolame_ctx, TRUE) != 0)
			return 0;
		if(toolame_setVBRLevel(ctx->toolame_ctx, param_vbr) != 0)
			return 0;
		if(toolame_setPadding(ctx->toolame_ctx, FALSE) != 0)
			return 0;
		if(param_maxvbr)
		{
			if(toolame_setVBRUpperBitrate(ctx->toolame_ctx, param_maxvbr) != 0)
				return 0;
		}
		ctx->vbr = 1;
	}

	if(toolame_setVerbosity(ctx->toolame_ctx, param_debug) != 0)
		return 0;

	if(toolame_init_params(ctx->toolame_ctx) != 0)
		return 0;

	ctx->bitrate = param_bitrate;
	encoder->params.bitrate = ctx->bitrate;
	encoder->params.samples_per_frame = 1152;
	encoder->priv = ctx;
	encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels;

	encoder->bind = bind_toolame;
	encoder->get_frame_size = get_frame_size;
	encoder->encode = encode_toolame;
	encoder->close = close_toolame;

	return 1;
}
Exemple #2
0
/*****************************************************************************
 * OpenEncoder: probe the encoder and return score
 *****************************************************************************/
static int OpenEncoder( vlc_object_t *p_this )
{
    encoder_t *p_enc = (encoder_t *)p_this;
    encoder_sys_t *p_sys;
    vlc_value_t val;

    if( p_enc->fmt_out.i_codec != VLC_FOURCC('m','p','g','a') &&
            p_enc->fmt_out.i_codec != VLC_FOURCC('m','p','2','a') &&
            p_enc->fmt_out.i_codec != VLC_FOURCC('m','p','2',' ') &&
            !p_enc->b_force )
    {
        return VLC_EGENERIC;
    }

    if( p_enc->fmt_in.audio.i_channels > 2 )
    {
        msg_Err( p_enc, "doesn't support > 2 channels" );
        return VLC_EGENERIC;
    }

    /* Allocate the memory needed to store the decoder's structure */
    if( ( p_sys = (encoder_sys_t *)malloc(sizeof(encoder_sys_t)) ) == NULL )
    {
        msg_Err( p_enc, "out of memory" );
        return VLC_EGENERIC;
    }
    p_enc->p_sys = p_sys;

    p_enc->pf_encode_audio = Encode;
    p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE;
    p_enc->fmt_out.i_codec = VLC_FOURCC('m','p','g','a');

    sout_CfgParse( p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg );

    p_sys->p_toolame = toolame_init();

    /* Set options */
    toolame_setSampleFreq( p_sys->p_toolame, p_enc->fmt_out.audio.i_rate );

    var_Get( p_enc, ENC_CFG_PREFIX "vbr", &val );
    if ( val.b_bool )
    {
        FLOAT i_quality;
        var_Get( p_enc, ENC_CFG_PREFIX "quality", &val );
        i_quality = val.i_int;
        if ( i_quality > 50.0 ) i_quality = 50.0;
        if ( i_quality < 0.0 ) i_quality = 0.0;
        toolame_setVBR( p_sys->p_toolame, 1 );
        toolame_setVBRLevel( p_sys->p_toolame, i_quality );
    }
    else
    {
        toolame_setBitrate( p_sys->p_toolame, p_enc->fmt_out.i_bitrate / 1000 );
    }

    if ( p_enc->fmt_in.audio.i_channels == 1 )
    {
        toolame_setMode( p_sys->p_toolame, MPG_MD_MONO );
    }
    else
    {
        var_Get( p_enc, ENC_CFG_PREFIX "mode", &val );
        switch ( val.i_int )
        {
        case 1:
            toolame_setMode( p_sys->p_toolame, MPG_MD_DUAL_CHANNEL );
            break;
        case 2:
            toolame_setMode( p_sys->p_toolame, MPG_MD_JOINT_STEREO );
            break;
        case 0:
        default:
            toolame_setMode( p_sys->p_toolame, MPG_MD_STEREO );
            break;
        }
    }

    if ( toolame_init_params( p_sys->p_toolame ) )
    {
        msg_Err( p_enc, "toolame initialization failed" );
        return -VLC_EGENERIC;
    }

    p_sys->i_nb_samples = 0;
    aout_DateInit( &p_sys->pts, p_enc->fmt_out.audio.i_rate );

    return VLC_SUCCESS;
}