Exemple #1
0
void SoftMP3::onPortFlushCompleted(OMX_U32 portIndex) {
    if (portIndex == 0) {
        // Make sure that the next buffer output does not still
        // depend on fragments from the last one decoded.
        pvmp3_InitDecoder(mConfig, mDecoderBuf);
    }
}
static long aacd_opencoremp3_start( AACDInfo *info, unsigned char *buffer, unsigned long buffer_size)
{
    AACD_TRACE( "start() buffer=%x size=%d", (*(unsigned long*)buffer), buffer_size );

    AACDOpenCoreMP3 *oc = (AACDOpenCoreMP3*) info->ext;
    tPVMP3DecoderExternal *pExt = oc->pExt;

    // prepare the first samples buffer:
    pExt->pOutputBuffer             = malloc(4096 * sizeof(int16_t));
    pExt->outputFrameSize           = 4096;

    pExt->pInputBuffer              = buffer;
    pExt->inputBufferMaxLength      = buffer_size;
    pExt->inputBufferCurrentLength  = buffer_size;
    pExt->inputBufferUsedLength     = 0;

    pExt->crcEnabled                = 0;
    pExt->equalizerType             = flat;
    pvmp3_InitDecoder( oc->pExt, oc->pMem );

    int32_t status;
    int frameDecoded = 0;
    pExt->outputFrameSize           = 0;

    /* pre-init search adts sync */
    while (pExt->outputFrameSize == 0) {
        pExt->pInputBuffer              = buffer;
        pExt->inputBufferMaxLength      = buffer_size;
        pExt->inputBufferCurrentLength  = buffer_size;
        pExt->inputBufferUsedLength     = 0;
        pExt->outputFrameSize           = 4096;

        status = pvmp3_framedecoder(pExt, oc->pMem);
        AACD_DEBUG( "start() Status[0]: %d - cosumed %d bytes", status, pExt->inputBufferUsedLength );

        if (status != NO_DECODING_ERROR) {
            buffer -= pExt->inputBufferUsedLength;
            buffer_size -= pExt->inputBufferUsedLength;
        }
        else frameDecoded = 1;

        if (buffer_size <= 64) break;
    }

    free(pExt->pOutputBuffer);
    pExt->pOutputBuffer = NULL;

    if (status != NO_DECODING_ERROR)
    {
        AACD_ERROR( "start() init failed status=%d", status );
        return -1;
    }

    AACD_DEBUG( "start() bytesconsumed=%d", pExt->inputBufferUsedLength );

    info->samplerate = pExt->samplingRate;
    info->channels = pExt->num_channels;

    return pExt->inputBufferUsedLength;
}
Exemple #3
0
void SoftMP3::initDecoder() {
    mConfig->equalizerType = flat;
    mConfig->crcEnabled = false;

    uint32_t memRequirements = pvmp3_decoderMemRequirements();
    mDecoderBuf = malloc(memRequirements);

    pvmp3_InitDecoder(mConfig, mDecoderBuf);
}
Exemple #4
0
// Initialize the MP3 reader.
int mp3_init(audio_decoder_p decoder, void *dec_ext)
{
	decoder->dec_ext = calloc(1, sizeof(tPVMP3DecoderExternal));
	RETURN_VAL_IF_FAIL((decoder->dec_ext != NULL), AUDIO_DECODER_ERROR);

	decoder->dec_mem = calloc(1, pvmp3_decoderMemRequirements());
	RETURN_VAL_IF_FAIL((decoder->dec_mem != NULL), AUDIO_DECODER_ERROR);

	*((tPVMP3DecoderExternal *) decoder->dec_ext) = *((tPVMP3DecoderExternal *) dec_ext);

	pvmp3_resetDecoder(decoder->dec_mem);
	pvmp3_InitDecoder((tPVMP3DecoderExternal *) decoder->dec_ext, decoder->dec_mem);

	return AUDIO_DECODER_OK;
}
static long aacd_opencoremp3_start( AACDInfo *info, unsigned char *buffer, unsigned long buffer_size)
{
    AACD_TRACE( "start() buffer=%x size=%d", (*(unsigned long*)buffer), buffer_size );

    AACDOpenCoreMP3 *oc = (AACDOpenCoreMP3*) info->ext;
    tPVMP3DecoderExternal *pExt = oc->pExt;

    // prepare the first samples buffer:
    //pExt->pOutputBuffer             = malloc(4096 * sizeof(int16_t));
    pExt->pOutputBuffer             = aacd_prepare_samples( info, 4096 );
    pExt->outputFrameSize           = 4096;

    pExt->pInputBuffer              = buffer;
    pExt->inputBufferMaxLength      = buffer_size;
    pExt->inputBufferCurrentLength  = buffer_size;
    pExt->inputBufferUsedLength     = 0;

    pExt->crcEnabled                = 0;
    pExt->equalizerType             = flat;
    pvmp3_InitDecoder( oc->pExt, oc->pMem );

    int32_t status;
    int frameDecoded = 0;
    int attempts = 16;
    int totalConsumed = 0;
    pExt->outputFrameSize           = 0;

    /* pre-init search adts sync */
    while (!frameDecoded && attempts--) {
        pExt->pInputBuffer              = buffer;
        pExt->inputBufferMaxLength      = buffer_size;
        pExt->inputBufferCurrentLength  = buffer_size;
        pExt->inputBufferUsedLength     = 0;
        pExt->outputFrameSize           = 4096;

        status = pvmp3_framedecoder(pExt, oc->pMem);
        AACD_DEBUG( "start() Status[0]: %d - consumed %d bytes", status, pExt->inputBufferUsedLength );

        totalConsumed += pExt->inputBufferUsedLength;

        if (status != NO_DECODING_ERROR) {
            AACD_ERROR( "start() frame decode error=%d", status );

            if (!pExt->inputBufferUsedLength) {
                AACD_ERROR( "start() first frame cannot be decoded - trying to sync again" );

                int move = buffer_size < 2048 ? (buffer_size >> 1) : 1024;
                buffer += move;
                buffer_size -= move;
                totalConsumed += move;

                pExt->pInputBuffer              = buffer;
                pExt->inputBufferMaxLength      = buffer_size;
                pExt->inputBufferCurrentLength  = buffer_size;

                ERROR_CODE err = pvmp3_frame_synch( oc->pExt, oc->pMem );

                if (err == SYNCH_LOST_ERROR) {
                    AACD_ERROR( "start() cannot re-sync the stream after next %d bytes, status=%d", move, err );
                }
                else if (err != NO_DECODING_ERROR) {
                    AACD_ERROR( "start() cannot sync the stream status=%d", err );
                    break;
                }
                else {
                    totalConsumed += pExt->inputBufferUsedLength;
                    AACD_INFO( "start() sync was successful - used bytes=%d", totalConsumed );
                }
            }
            buffer -= pExt->inputBufferUsedLength;
            buffer_size -= pExt->inputBufferUsedLength;
        }
Exemple #6
0
void SoftMP3::onReset() {
    pvmp3_InitDecoder(mConfig, mDecoderBuf);
    mIsFirst = true;
    mSignalledError = false;
    mOutputPortSettingsChange = NONE;
}