Пример #1
0
tdmb_demux_t* construct_cyberlink_tdmb_demux()
{
    cyberlink_tdmb_demux_t* pthis = (cyberlink_tdmb_demux_t*) med_alloc_ext_mem(sizeof(cyberlink_tdmb_demux_t));
    ASSERT(pthis);
    kal_mem_set(pthis, 0, sizeof(*pthis));

	pthis->itf.open = cyberlink_tdmb_demux_open;
	pthis->itf.send = cyberlink_tdmb_demux_send;
	pthis->itf.close = cyberlink_tdmb_demux_close;
    pthis->itf.destroy = cyberlink_tdmb_demux_destroy;

	return &pthis->itf;
}
Пример #2
0
kal_int32 cached_io_set_async(cached_io_t* io)
{
    kal_int32 ret;

    io->aio = (async_io_t*) med_alloc_ext_mem(sizeof(async_io_t));
    ASSERT(io->aio != NULL);

    ret = async_io_attach(io->aio, io->file_h, io->block_size);
    if (ret < 0) {
        med_free_ext_mem((void**) &io->aio);
    }

    return ret;
}
Пример #3
0
kal_int32 cached_io_attach(cached_io_t* io, FS_HANDLE file_h, kal_uint32 block_size)
{
    kal_int32 i;

    io->file_h = file_h;
    if (io->file_h >= 0)
    {
	    FS_GetFilePosition(file_h, &io->pos);
    }
    else {
        io->pos = 0;
    }

    ASSERT(block_size != 0);
    io->block_size = block_size;

    for (i = 0; i < ARRAY_SIZE(io->blocks); i++)
    {
        cached_block_t* block = &io->blocks[i];

        block->block_no = (kal_uint32) -1;
        block->state = BLOCK_STATE_INVALID;
        block->bytes = 0;
#ifdef _DEBUG
        block->read_hits = block->write_hits = 0;
#endif
        if (io->file_h >= 0)
        {
            block->buffer = (kal_uint8*) med_alloc_ext_mem(block_size);
            ASSERT(block->buffer);
        }
        else
        {
            block->buffer = NULL;
        }
    }

    io->aio = NULL;

    return io->file_h;
}
Пример #4
0
/**
 * \brief Initialization of parser object
 * @return true (1) - success or false (0) - fail
 */
int nmea_parser_init(nmeaPARSER *parser)
{
    int resv = 0;
    int buff_size = nmea_property()->parse_buff_size;

    NMEA_ASSERT(parser);

    if(buff_size < NMEA_MIN_PARSEBUFF)
        buff_size = NMEA_MIN_PARSEBUFF;

    memset(parser, 0, sizeof(nmeaPARSER));

    if(0 == (parser->buffer = (unsigned char *)med_alloc_ext_mem(buff_size)))
        nmea_error("Insufficient memory!");
    else
    {
        parser->buff_size = buff_size;
        resv = 1;
    }    

    return resv;
}
Пример #5
0
/*****************************************************************************
 * FUNCTION
 *  aud_media_get_audio_format_in_video
 * DESCRIPTION
 *  This function is to get the audio format in video
 * PARAMETERS
 *
 * RETURNS
 * kal_uint8   result
 *****************************************************************************/
kal_uint8 aud_stretch_is_aduio_in_video_PP_support(kal_wchar *file_name, kal_uint8 *data, kal_uint32 data_len, kal_int16 data_format)
{
#if defined(MED_PURE_AUDIO)
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MP4_Parser_Status eMp4ParserRet;
    FSAL_Status eFSALRet;
    kal_uint8 result;
    kal_bool is_file_opened = KAL_FALSE;
    kal_bool has_aud_track;
    kal_bool is_PP_support = KAL_FALSE;
    Media_Format audio_format;
    kal_uint32 filesize;
    kal_uint32 index;
    kal_uint64 temp;
    STFSAL stFSAL_ROM;
    kal_uint8 *fsal_rom_buf;

    STMp4Parser *stMp4Parser_aud;
    STFSAL *stFSAL_aud;
    STFSAL *stFSAL_aud_stsz;
    STFSAL *stFSAL_aud_stco;
    STFSAL *stFSAL_aud_aud_data;
    kal_uint32 *mp4_aud_buf;
    kal_uint32 *mp4_aud_data_buf;
    kal_uint32 *mp4_aud_stco_buf;
    kal_uint32 *mp4_aud_stsz_buf;
    kal_uint32 *mp4_aud_stbl_buf;
    FS_FileLocationHint *aud_seek_hint;
  
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    /* Open file for playing */
    stFSAL_aud = (STFSAL*)get_ctrl_buffer(sizeof(STFSAL));    
    eFSALRet = FSAL_Open(stFSAL_aud, (void*)file_name, FSAL_READ); 

    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }
    is_file_opened = KAL_TRUE;

    /* Allocate working buffer for operation */    
    stMp4Parser_aud = (STMp4Parser*)get_ctrl_buffer(sizeof(STMp4Parser));
    stFSAL_aud_stsz = (STFSAL*)get_ctrl_buffer(sizeof(STFSAL));
    stFSAL_aud_stco = (STFSAL*)get_ctrl_buffer(sizeof(STFSAL));
    stFSAL_aud_aud_data = (STFSAL*)get_ctrl_buffer(sizeof(STFSAL));
    mp4_aud_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_FSAL_BUF_SIZE*sizeof(kal_uint32) );
    mp4_aud_data_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_FSAL_BUF_SIZE*sizeof(kal_uint32) );
    mp4_aud_stco_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_STCO_BUF_SIZE*sizeof(kal_uint32) );
    mp4_aud_stsz_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_STSZ_BUF_SIZE*sizeof(kal_uint32) );
    mp4_aud_stbl_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_STBL_BUF_SIZE*sizeof(kal_uint32) );
    aud_seek_hint = (FS_FileLocationHint*)med_alloc_ext_mem( AUD_DEC_SEEK_HINT_SIZE*sizeof(FS_FileLocationHint) );

    /* Set buffer for FSAL */
    FSAL_SetBuffer(stFSAL_aud, AUD_MP4_FSAL_BUF_SIZE, (kal_uint8*)mp4_aud_buf);

    /* Set seek hint */
    eFSALRet = FSAL_GetFileSize(stFSAL_aud, &filesize);
    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }

    for (index = 0; index < AUD_DEC_SEEK_HINT_SIZE; index++)
    {
        temp = ((kal_uint64) filesize * (kal_uint64) (index + 1)) / (kal_uint64) (AUD_DEC_SEEK_HINT_SIZE + 1);
        aud_seek_hint[index].Index = (kal_uint32) temp;
    }
    DRM_set_seek_hint(stFSAL_aud->hFile, AUD_DEC_SEEK_HINT_SIZE, aud_seek_hint);

    /* Creat MP4 parser */
    eMp4ParserRet = MP4_Parse(stMp4Parser_aud, stFSAL_aud);

    if (eMp4ParserRet != MP4_PARSER_OK && eMp4ParserRet != MP4_PARSER_WARNING_TRAILING_GARBAGE)
    {
        result = MED_RES_BAD_FORMAT;
        goto pure_audio_error_out;
    }

    /* Check if there's audio track */
    MP4_MetaHasAudioTrack(stMp4Parser_aud, &has_aud_track);
    if (!has_aud_track)
    {
        result = MED_RES_MP4_NO_AUDIO_TRACK;
        goto pure_audio_error_out;
    }

    /* Prepare cache table */
    eMp4ParserRet = MP4_STBL_CacheTablePreprocess(
                        stMp4Parser_aud, 
                        mp4_aud_stbl_buf, 
                        AUD_MP4_STBL_BUF_SIZE);
                        
    if (eMp4ParserRet != MP4_PARSER_OK)
    {
        result = MED_RES_BAD_FORMAT;
        goto pure_audio_error_out;
    }    

    /* FSAL aud data */
    eFSALRet = FSAL_Open_Attach(stFSAL_aud_aud_data, stFSAL_aud);
    
    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }
    FSAL_SetBuffer(stFSAL_aud_aud_data, AUD_MP4_FSAL_BUF_SIZE, (kal_uint8*)mp4_aud_data_buf);

    /* FASL stco */
    eFSALRet = FSAL_Open_Attach(stFSAL_aud_stco, stFSAL_aud);
    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }
    FSAL_SetBuffer(stFSAL_aud_stco, AUD_MP4_STCO_BUF_SIZE, (kal_uint8*)mp4_aud_stco_buf);

    /* FSAL stsz */
    eFSALRet = FSAL_Open_Attach(stFSAL_aud_stsz, stFSAL_aud);
    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }
    FSAL_SetBuffer(stFSAL_aud_stsz, AUD_MP4_STSZ_BUF_SIZE, (kal_uint8*)mp4_aud_stsz_buf);

    /* Set FSAL to MP4 Parser */
    MP4_Audio_SetFSAL(stMp4Parser_aud, stFSAL_aud_aud_data);    
    MP4_SetFSAL_STCO(stMp4Parser_aud, MP4_TRACK_AUDIO, stFSAL_aud_stco);
    MP4_SetFSAL_STSZ(stMp4Parser_aud, MP4_TRACK_AUDIO, stFSAL_aud_stsz);
    MP4_UpdateSampleCount(stMp4Parser_aud, MP4_TRACK_AUDIO);

    /* Get Audio Type */
    audio_format = MP4_Audio_Type_To_Media_Format(MP4_GetAudioType(stMp4Parser_aud));
    AUD_VALUE_TRACE(audio_format, -1, __LINE__);

    /* The audio format in 3GP/MP4 file */
    switch (audio_format)
    {
        /* Check AMR / AMR-WB by format enum directly */
    #ifdef AMR_DECODE    
        case MEDIA_FORMAT_AMR:
    #ifdef AMRWB_DECODE        
        case MEDIA_FORMAT_AMR_WB:
    #endif         
            is_PP_support = AudioPP_TS_IsSupport((Media_Format) audio_format, NULL);
            break;
    #endif /*AMR_DECODE*/

        /* Need to wrap audio data in FSAL ROM file for check function */
    #if defined(AAC_DECODE)            
        case MEDIA_FORMAT_AAC:
        {
            kal_uint32 uSampleNo;
            kal_uint32 num_bytes;

            /* Seek to front and read a small range of data */
            eMp4ParserRet =  MP4_Audio_TimeToSampleNo(stMp4Parser_aud, 0, &uSampleNo );
            if(eMp4ParserRet != MP4_PARSER_OK)
            {
                result = MED_RES_FAIL;
                goto pure_audio_error_out; 
            }
            eMp4ParserRet =  MP4_Audio_Seek(stMp4Parser_aud, uSampleNo);
            if(eMp4ParserRet != MP4_PARSER_OK)
            {
                result = MED_RES_FAIL;
                goto pure_audio_error_out; 
            }

            /* Read audio data into buffer and set it to FSAL ROM file */
            fsal_rom_buf = (kal_uint8*)med_alloc_ext_mem( AUD_STRETCH_FSAL_ROM_SIZE*sizeof(kal_uint8) );
            eMp4ParserRet = MP4_Audio_Read(stMp4Parser_aud, fsal_rom_buf, AUD_STRETCH_FSAL_ROM_SIZE, &num_bytes);

            if((eMp4ParserRet != MP4_PARSER_OK) && (eMp4ParserRet != MP4_PARSER_READ_EOF))
            {
                med_free_ext_mem((void**)&fsal_rom_buf);
                result = MED_RES_FAIL;
                goto pure_audio_error_out;             
            }

            FSAL_Direct_SetRamFileSize(&stFSAL_ROM, num_bytes);
            eFSALRet = FSAL_Open(&stFSAL_ROM, (void*)fsal_rom_buf, FSAL_ROMFILE);

            if (eFSALRet != FSAL_OK)
            {
                med_free_ext_mem((void**)&fsal_rom_buf);            
                result = MED_RES_OPEN_FILE_FAIL;
                goto pure_audio_error_out;
            }

            /* check time stretch support by using extract audio data in FSAL ROM file */
            is_PP_support = AudioPP_TS_IsSupport((Media_Format) audio_format, &stFSAL_ROM);

            med_free_ext_mem((void**)&fsal_rom_buf);
            break;
        }            
    #endif /*AAC_DECODE*/            

        default:
            result = MED_RES_INVALID_FORMAT;
            goto pure_audio_error_out;
            break;
    }

    if (is_PP_support)
    {
        result = MED_RES_OK;
    }
    else
    {
        result = MED_RES_UNSUPPORTED_SPEED;
    }
     
pure_audio_error_out:
    if (is_file_opened)
    {
        FSAL_Close(stFSAL_aud);

        free_ctrl_buffer(stMp4Parser_aud);        
        free_ctrl_buffer(stFSAL_aud_stsz);
        free_ctrl_buffer(stFSAL_aud_stco);
        free_ctrl_buffer(stFSAL_aud_aud_data);
        med_free_ext_mem((void**)&mp4_aud_buf);
        med_free_ext_mem((void**)&mp4_aud_data_buf);
        med_free_ext_mem((void**)&mp4_aud_stco_buf);
        med_free_ext_mem((void**)&mp4_aud_stsz_buf);
        med_free_ext_mem((void**)&mp4_aud_stbl_buf);     
        med_free_ext_mem((void**)&aud_seek_hint);
    }

    free_ctrl_buffer(stFSAL_aud);

    return result;

#else
    return MED_RES_INVALID_FORMAT;
#endif /* #if defined(MED_PURE_AUDIO) */

}
Пример #6
0
void* sf_system_malloc(kal_uint32 size)
{
	//todo
	return med_alloc_ext_mem(size);
}
Пример #7
0
int nmea_parser_real_push(nmeaPARSER *parser, const char *buff, int buff_sz)
{
    int nparsed = 0, crc, sen_sz, ptype;
    nmeaParserNODE *node = 0;

    NMEA_ASSERT(parser && parser->buffer);

    /* clear unuse buffer (for debug) */
    /*
    memset(
        parser->buffer + parser->buff_use, 0,
        parser->buff_size - parser->buff_use
        );
        */

    /* add */
    if(parser->buff_use + buff_sz >= parser->buff_size)
        nmea_parser_buff_clear(parser);

    memcpy(parser->buffer + parser->buff_use, buff, buff_sz);
    parser->buff_use += buff_sz;

    /* parse */
    for(;;node = 0)
    {
        sen_sz = nmea_find_tail(
            (const char *)parser->buffer + nparsed,
            (int)parser->buff_use - nparsed, &crc);

        if(!sen_sz)
        {
            if(nparsed)
                memcpy(
                parser->buffer,
                parser->buffer + nparsed,
                parser->buff_use -= nparsed);
            break;
        }
        else if(crc >= 0)
        {
            ptype = nmea_pack_type(
                (const char *)parser->buffer + nparsed + 1,
                parser->buff_use - nparsed - 1);

            if(0 == (node = (nmeaParserNODE *)med_alloc_ext_mem(sizeof(nmeaParserNODE))))
                goto mem_fail;

            node->pack = 0;

            switch(ptype)
            {
            case GPGGA:
                if(0 == (node->pack = (void *)med_alloc_ext_mem(sizeof(nmeaGPGGA))))
                    goto mem_fail;
                node->packType = GPGGA;
                if(!nmea_parse_GPGGA(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPGGA *)node->pack))
                {
                    med_free_ext_mem((void **)node);
                    node = 0;
                }
                break;
            case GPGSA:
                if(0 == (node->pack = (void *)med_alloc_ext_mem(sizeof(nmeaGPGSA))))
                    goto mem_fail;
                node->packType = GPGSA;
                if(!nmea_parse_GPGSA(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPGSA *)node->pack))
                {
                    med_free_ext_mem((void **)node);
                    node = 0;
                }
                break;
            case GPGSV:
                if(0 == (node->pack = (void *)med_alloc_ext_mem(sizeof(nmeaGPGSV))))
                    goto mem_fail;
                node->packType = GPGSV;
                if(!nmea_parse_GPGSV(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPGSV *)node->pack))
                {
                    med_free_ext_mem((void **)node);
                    node = 0;
                }
                break;
            case GPRMC:
                if(0 == (node->pack = (void *)med_alloc_ext_mem(sizeof(nmeaGPRMC))))
                    goto mem_fail;
                node->packType = GPRMC;
                if(!nmea_parse_GPRMC(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPRMC *)node->pack))
                {
                    med_free_ext_mem((void **)node);
                    node = 0;
                }
                break;
            case GPVTG:
                if(0 == (node->pack = (void *)med_alloc_ext_mem(sizeof(nmeaGPVTG))))
                    goto mem_fail;
                node->packType = GPVTG;
                if(!nmea_parse_GPVTG(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPVTG *)node->pack))
                {
                    med_free_ext_mem((void **)node);
                    node = 0;
                }
                break;
            default:
                med_free_ext_mem((void **)node);
                node = 0;
                break;
            };

            if(node)
            {
                if(parser->end_node)
                    ((nmeaParserNODE *)parser->end_node)->next_node = node;
                parser->end_node = node;
                if(!parser->top_node)
                    parser->top_node = node;
                node->next_node = 0;
            }
        }

        nparsed += sen_sz;
    }

    return nparsed;

mem_fail:
    if(node)
        med_free_ext_mem((void **)node);

    nmea_error("Insufficient memory!");

    return -1;
}