⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aud_utility.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    }
}


/*****************************************************************************
 * FUNCTION
 *  aud_create_full_path_folder
 * DESCRIPTION
 *  check or make dir along the assigned path
 * PARAMETERS
 *  filepath        [?]     
 * RETURNS
 *  int
 *****************************************************************************/
int aud_create_full_path_folder(kal_uint16 *filepath)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 *filepath_p = filepath;
    kal_int32 fs_ret = FS_FILE_EXISTS;
    FS_HANDLE file_handle;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    file_handle = FS_Open(filepath, FS_OPEN_DIR | FS_READ_ONLY);

    /* path already exist */
    if (file_handle >= 0)
    {
        FS_Close(file_handle);
        return FS_FILE_EXISTS;
    }

    /* skip drive, i.e. "C:\" */
    while (*filepath_p != L'\\')
    {
        if (*filepath_p != 0)
        {
            filepath_p++;
        }
        else
        {
            return FS_INVALID_FILENAME;
        }
    }

    while (*(filepath_p++))
    {
        if (*filepath_p == L'\\')
        {
            *filepath_p = 0;
            file_handle = FS_Open(filepath, FS_OPEN_DIR | FS_READ_ONLY);
            /* check if path exists */
            if (file_handle < 0)
            {
                /* create dir */
                fs_ret = FS_CreateDir(filepath);
                *filepath_p = L'\\';
                if (fs_ret != FS_NO_ERROR)
                {
                    break;
                }
            }
            else
            {
                FS_Close(file_handle);
                *filepath_p = L'\\';
            }
        }
    }

    return fs_ret;
}

#ifdef TST_HANDLER


/*****************************************************************************
 * FUNCTION
 *  aud_tst_handler
 * DESCRIPTION
 *  
 * PARAMETERS
 *  ilm_ptr     [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void aud_tst_handler(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    tst_module_string_inject_struct *tst_inject = (tst_module_string_inject_struct*) ilm_ptr->local_para_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ASSERT(tst_inject != NULL);

    switch (tst_inject->index)
    {
        case 13:    /* audio play by name */
        {
            l4aud_audio_play_by_name_req_struct msg;

            kal_wsprintf(msg.file_name, "%s", tst_inject->string);
            msg.play_style = DEVICE_AUDIO_PLAY_INFINITE;
            msg.src_id = 0;
            ilm_ptr->local_para_ptr = (local_para_struct*) & msg;
            aud_play_by_name_req_hdlr(ilm_ptr);
            break;
        }
        case 14:    /* audio stop by name */
        {
            l4aud_audio_stop_by_name_req_struct msg;

            kal_wsprintf(msg.file_name, "%s", tst_inject->string);
            ilm_ptr->local_para_ptr = (local_para_struct*) & msg;
            aud_stop_by_name_req_hdlr(ilm_ptr);
            break;
        }
        case 15:    /* audio play by string */
        {
            l4aud_audio_play_by_string_req_struct msg;

            msg.melody = resource_midis[tst_inject->string[0] - '0'].data;
            msg.format = AUD_MEDIA_SMF;
            msg.play_style = DEVICE_AUDIO_PLAY_INFINITE;
            msg.len = resource_midis[tst_inject->string[0] - '0'].len;
            msg.src_id = 0;
            ilm_ptr->local_para_ptr = (local_para_struct*) & msg;
            aud_play_by_string_req_hdlr(ilm_ptr);
            break;
        }
        case 16:    /* audio stop by string */
        {
            l4aud_audio_stop_by_string_req_struct msg;

            msg.src_id = 0;
            ilm_ptr->local_para_ptr = (local_para_struct*) & msg;
            aud_stop_by_string_req_hdlr(ilm_ptr);
            break;
        }
    }

}

#endif /* TST_HANDLER */

#ifndef SLIM_AUDIO_PROFILE
/*****************************************************************************
 * DATA STRUCTURE
 *  it contains a file STFSAL to be used by AMR_Open or DAF_Open
 *  and a handle_p to be returned by AMR_Open or DAF_Open 
 *  and most importantly it has BuildCache func that we use to build cache
 *****************************************************************************/
struct _media_struct
{
    STFSAL file;
    MHdl *handle_p;
    void* file_buf;
    void* proc_buf;
} media_cache;

/*****************************************************************************
 * FUNCTION
 *  aud_util_build_cache_start
 * DESCRIPTION
 *  start the process of build cache
 * PARAMETERS
 *  filename     [IN]
 *  cache_p      [IN]
 *  cache_size   [IN]
 *  file_buf     [IN]
 *  file_buf_size[IN]
 *  proc_buf     [IN]
 *  proc_buf_size[IN]
 * RETURNS
 *  kal_bool
 *****************************************************************************/
kal_bool aud_util_build_cache_start( kal_wchar *filename, 
    void* cache_p, kal_int32 cache_size, 
    void *file_buf, kal_int32 file_buf_size, 
    void *proc_buf, kal_int32 proc_buf_size )
{
    kal_int16 type;
    Media_VM_PCM_Param vpFormat;

    ASSERT( media_cache.handle_p == NULL );

    /* get media type from filename extension */
    type = med_get_media_type( filename );

    if( type == MED_TYPE_NONE )
        return KAL_FALSE;

    /* open file */
    if( FSAL_Open( &media_cache.file, filename, FSAL_READ ) != FSAL_OK )
        return KAL_FALSE;

    FSAL_SetBuffer( &media_cache.file, file_buf_size, (kal_uint8*)file_buf );

    memset( cache_p, 0, cache_size );

    /* determine which open func */
    switch( type )
    {
#ifdef AMR_DECODE
    case MED_TYPE_AMR:
        vpFormat.mediaType = MED_TYPE_AMR;
        vpFormat.vmParam = (kal_uint32) MEDIA_VMP_AS_RINGTONE;
        media_cache.handle_p = AMR_Open( NULL, &media_cache.file, &vpFormat );
        break;
#endif /* AMR_DECODE */
#ifdef DAF_DECODE
    case MED_TYPE_DAF:
        media_cache.handle_p = DAF_Open( NULL, &media_cache.file, NULL );
        break;
#endif /* DAF_DECODE */
    default:
        ASSERT(0);
    }

    /* handle open func fail case */
    if( media_cache.handle_p == NULL )
    {
        FSAL_Close( &media_cache.file );
        return KAL_FALSE;
    }

    media_cache.handle_p->SetCacheTbl( media_cache.handle_p, cache_p, NULL );
    media_cache.handle_p->SetBuffer( media_cache.handle_p, 
        (kal_uint8*)proc_buf, proc_buf_size );

    return KAL_TRUE;
}

/*****************************************************************************
 * FUNCTION
 *  aud_util_build_cache_stop
 * DESCRIPTION
 *  stop the process of build cache
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void aud_util_build_cache_stop( void )
{
    /* if it's not started, skip it */
    if( media_cache.handle_p != NULL )
    {
        /* close func */
        media_cache.handle_p->Close( media_cache.handle_p );

        /* close file */
        FSAL_Close( &media_cache.file );

        /* reset handle & start flag */
        media_cache.handle_p = NULL;
    }
}

/*****************************************************************************
 * FUNCTION
 *  aud_util_build_cache_process
 * DESCRIPTION
 *  do the process of build cache incrementally
 * PARAMETERS
 *  progress_p     [IN]
 * RETURNS
 *  kal_bool
 *****************************************************************************/
kal_bool aud_util_build_cache_process( kal_uint32 *progress_p )
{
    Media_Status result;

    ASSERT( media_cache.handle_p != NULL );

    /* do build cache incrementally */
    media_cache.handle_p->BuildCache( media_cache.handle_p, &result, progress_p );

    if( result == MEDIA_SUCCESS )
    {
        return KAL_TRUE;
    }
    else
    {
        /* handle build cache failed case */
        aud_util_build_cache_stop();

        return KAL_FALSE;
    }
}

/*****************************************************************************
 * FUNCTION
 *  aud_util_build_cache_get_duration
 * DESCRIPTION
 *  get the total duration from the process of build cache
 * PARAMETERS
 *  void
 * RETURNS
 *  kal_uint32
 *****************************************************************************/
kal_uint32 aud_util_build_cache_get_duration( void )
{
    kal_uint32 duration;

    ASSERT( media_cache.handle_p != NULL );

    duration = media_cache.handle_p->GetTotalDuration( media_cache.handle_p );

    return duration;
}
#endif /* SLIM_AUDIO_PROFILE */

#endif /* MED_NOT_PRESENT */ 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -