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

📄 aud_vm.c

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

    l4aud_vm_record_req_struct *msg_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    AUD_FUNC_ENTRY(AUD_VM_RECORD_REQ_HDLR) aud_context_p->src_mod = ilm_ptr->src_mod_id;

    msg_p = (l4aud_vm_record_req_struct*) ilm_ptr->local_para_ptr;

    aud_context_p->src_id = msg_p->src_id;

    /* If the media is playing, return busy */
    if (aud_context_p->media_playing)
    {
        /* send confirm message to L4 */
        aud_send_vm_record_cnf(MED_RES_BUSY);
        return;
    }

    if (aud_context_p->state == AUD_VM_IDLE)
    {

        if (!aud_context_p->disc_full &&
            aud_context_p->vm_info.num_of_vm < MAX_NUM_OF_VM_FILE && aud_check_free_space(L"c:"))
        {
            kal_wchar full_name[FULL_NAME_LEN];

            aud_vm_get_current_file_name(aud_context_p->current_file_name);
            kal_wsprintf(full_name, "%w\\%w", VM_DIR, aud_context_p->current_file_name);
            aud_context_p->current_file_handle = FS_Open(full_name, FS_CREATE | FS_READ_WRITE);

            if (aud_context_p->current_file_handle >= 0 && aud_vm_add_file_to_list(aud_context_p->current_file_name))
            {

                /* call L1AUD to set buffer */
                Media_SetBuffer(aud_context_p->ring_buf, AUD_RING_BUFFER_LEN);

                /* start to record */
                Media_Record((Media_Format) aud_context_p->vm_sp_type, aud_vm_record_callback, NULL);

                /* reset offset */
                aud_context_p->offset = 0;

                cnf_result = MED_RES_OK;

                /* enter AUD_VM_RECORD state */
                AUD_ENTER_STATE(AUD_VM_RECORD);
            }
            else if (aud_context_p->current_file_handle >= 0)
            {
                FS_Close(aud_context_p->current_file_handle);
                /* send confirm message to l4 */
                cnf_result = MED_RES_OPEN_FILE_FAIL;
            }
            else
            {
                /* send confirm message to l4 */
                cnf_result = MED_RES_OPEN_FILE_FAIL;
            }

        }
        else
        {
            aud_context_p->disc_full = KAL_TRUE;
            /* send confirm message to l4 */
            cnf_result = MED_RES_DISC_FULL;
        }
    }
    else
    {
        cnf_result = MED_RES_BUSY;
    }
    /* send confirm message to l4 */
    aud_send_vm_record_cnf(cnf_result);

}


/*****************************************************************************
 * FUNCTION
 *  aud_vm_play_callback
 * DESCRIPTION
 *  
 * PARAMETERS
 *  event       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vm_play_callback(Media_Event event)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    aud_vm_write_data_ind_struct *ind_p = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    Media_GetWriteBuffer(&(aud_context_p->buf_p), (kal_uint32*) & (aud_context_p->buf_len));
    if (aud_context_p->buf_p == NULL || aud_context_p->buf_len == 0)
    {
        return;
    }

    ind_p = (aud_vm_write_data_ind_struct*) construct_local_para(sizeof(aud_vm_write_data_ind_struct), TD_CTRL);

    ind_p->event = (kal_uint8) event;

    aud_send_ilm(MOD_MED, MSG_ID_AUD_VM_WRITE_DATA_IND, ind_p, NULL);
}


/*****************************************************************************
 * FUNCTION
 *  aud_vm_play_req_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  ilm_ptr     [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vm_play_req_hdlr(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    l4aud_vm_play_req_struct *msg_p = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    AUD_FUNC_ENTRY(AUD_VM_PLAY_REQ_HDLR) aud_context_p->src_mod = ilm_ptr->src_mod_id;

    msg_p = (l4aud_vm_play_req_struct*) ilm_ptr->local_para_ptr;

    aud_context_p->src_id = msg_p->src_id;

    if (aud_context_p->media_playing)
    {
        /* send confirm message to L4 */
        aud_send_vm_play_cnf(MED_RES_BUSY);
        return;
    }

    switch (aud_context_p->state)
    {
        case AUD_VM_IDLE:
        {

            if (aud_vm_check_existing_file_name((kal_wchar*) msg_p->file_name))
            {
                /* open the file */
                kal_wchar full_name[FULL_NAME_LEN];

                kal_wsprintf(full_name, "%w\\%w", VM_DIR, (kal_wchar*) msg_p->file_name);
                aud_context_p->current_file_handle = FS_Open(full_name, FS_READ_ONLY | FS_OPEN_NO_DIR);

                if (aud_context_p->current_file_handle >= 0)
                {
                    kal_uint32 len;

                    /* set current file name */
                    kal_mem_cpy(aud_context_p->current_file_name, msg_p->file_name, MAX_VM_FILE_NAME * ENCODE_BYTE);
                    /* call L1AUD to set buffer */
                    Media_SetBuffer(aud_context_p->ring_buf, AUD_RING_BUFFER_LEN);
                    Media_GetWriteBuffer(&(aud_context_p->buf_p), (kal_uint32*) & (aud_context_p->buf_len));
                    ASSERT(aud_context_p->buf_p != NULL);

                    /* read data from file to buffer */
                    FS_Read(aud_context_p->current_file_handle, aud_context_p->buf_p, aud_context_p->buf_len * 2, &len);

                    /* update offset */
                    aud_context_p->offset = len;

                    AUD_VALUE_TRACE(aud_context_p->offset, aud_context_p->buf_len, len >> 1) len = len >> 1;
                    if (len == 0)
                    {
                        /* close the file */
                        FS_Close(aud_context_p->current_file_handle);

                        /* send confirm message to L4 */
                        aud_send_vm_play_cnf(MED_RES_OPEN_FILE_FAIL);
                    }
                    else if (len < aud_context_p->buf_len)
                    {
                        aud_context_p->buf_len = len;

                        /* inform L1AUD the amount of data read from file to ring buffer */
                        Media_WriteDataDone(len);

                        /* follow ring tone volume */
                    #ifdef SET_VOLUME_WHEN_PLAY
                        aud_set_active_ring_tone_volume();
                    #endif 
                        /* start to play */
                        Media_Play(
                            (Media_Format) aud_context_p->vm_sp_type,
                            aud_vm_play_callback,
                            MEDIA_VMP_AS_RINGTONE);
                        Media_DataFinished();

                        /* close the file */
                        FS_Close(aud_context_p->current_file_handle);

                        /* send confirm message to L4 */
                        aud_send_vm_play_cnf(MED_RES_OK);

                        /* play as memo */
                        aud_context_p->play_mode = AUD_VM_PLAY_AS_MEMO;

                        /* enter AUD_VM_PLAY_FINISH state */
                        AUD_ENTER_STATE(AUD_VM_PLAY_FINISH);
                    }
                    else
                    {
                        /* inform L1AUD the amount of data read from file to ring buffer */
                        Media_WriteDataDone(len);

                        /* follow ring tone volume */
                    #ifdef SET_VOLUME_WHEN_PLAY
                        aud_set_active_ring_tone_volume();
                    #endif 
                        /* start to play */
                        Media_Play(
                            (Media_Format) aud_context_p->vm_sp_type,
                            aud_vm_play_callback,
                            MEDIA_VMP_AS_RINGTONE);

                        /* send confirm message to L4 */
                        aud_send_vm_play_cnf(MED_RES_OK);

                        /* play as memo */
                        aud_context_p->play_mode = AUD_VM_PLAY_AS_MEMO;

                        /* enter AUD_VM_PLAY state */
                        AUD_ENTER_STATE(AUD_VM_PLAY);
                    }

                }
                else
                {
                    /* send confirm message to L4 */
                    aud_send_vm_play_cnf(MED_RES_OPEN_FILE_FAIL);
                }

            }
            else
            {
                /* send confirm message to L4 */
                aud_send_vm_play_cnf(MED_RES_OPEN_FILE_FAIL);

            }

            break;
        }
        default:
        {

            /* send confirm message to L4 */
            aud_send_vm_play_cnf(MED_RES_BUSY);
            break;
        }
    }

}


/*****************************************************************************
 * FUNCTION
 *  aud_vm_play
 * DESCRIPTION
 *  
 * PARAMETERS
 *  file_id         [IN]        
 *  play_style      [IN]        
 *  out_device      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vm_play(kal_uint8 file_id, kal_uint8 play_style, kal_uint8 out_device)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_wchar *vm_file;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (aud_context_p->state)
    {
        case AUD_VM_IDLE:
        {
            vm_file = aud_context_p->vm_info.file_name_list[file_id];

            if (aud_vm_check_existing_file_name(vm_file))
            {
                /* open the file */
                kal_wchar full_name[FULL_NAME_LEN];

                kal_wsprintf(full_name, "%w\\%w", VM_DIR, (kal_wchar*) vm_file);
                aud_context_p->current_file_handle = FS_Open(full_name, FS_READ_ONLY | FS_OPEN_NO_DIR);

                if (aud_context_p->current_file_handle >= 0)
                {
                    kal_uint32 len;

                    /* set current file name */
                    kal_mem_cpy(aud_context_p->current_file_name, vm_file, MAX_VM_FILE_NAME * ENCODE_BYTE);
                    /* call L1AUD to set buffer */
                    Media_SetBuffer(aud_context_p->ring_buf, AUD_RING_BUFFER_LEN);
                    Media_GetWriteBuffer(&(aud_context_p->buf_p), (kal_uint32*) & (aud_context_p->buf_len));
                    ASSERT(aud_context_p->buf_p != NULL);

                    /* read data from file to buffer */
                    FS_Read(aud_context_p->current_file_handle, aud_context_p->buf_p, aud_context_p->buf_len * 2, &len);

                    /* update offset */
                    aud_context_p->offset += len;

                    len = len >> 1;
                    if (len == 0)
                    {
                        /* close the file */
                        FS_Close(aud_context_p->current_file_handle);
                    }
                    else if (len < aud_context_p->buf_len)
                    {
                        aud_context_p->buf_len = len;

                        /* inform L1AUD the amount of data read from file to ring buffer */
                        Media_WriteDataDone(len);

                        /* follow ring tone volume */
                    #ifdef SET_VOLUME_WHEN_PLAY
                        aud_set_active_ring_tone_volume();
                    #endif 
                        /* start to play */
                        Media_Play(
                            (Media_Format) aud_context_p->vm_sp_type,
                            aud_vm_play_callback,
                            MEDIA_VMP_AS_RINGTONE);
                        Media_DataFinished();

                        /* close the file */
                        FS_Close(aud_context_p->current_file_handle);

                        /* play as memo */
                        aud_context_p->play_mode = AUD_VM_PLAY_AS_RING;

                        /* enter AUD_VM_PLAY_FINISH state */
                        AUD_ENTER_STATE(AUD_VM_PLAY_FINISH);
                    }
                    else
                    {
                        /* inform L1AUD the amount of data read from file to ring buffer */
                        Media_WriteDataDone(len);

                        /* follow ring tone volume */
                    #ifdef SET_VOLUME_WHEN_PLAY
                        aud_set_active_ring_tone_volume();
                    #endif 
                        /* start to play */
                        Media_Play(
                            (Media_Format) aud_context_p->vm_sp_type,
                            aud_vm_play_callback,
                            MEDIA_VMP_AS_RINGTONE);

                        /* send confirm message to L4 */
                        aud_send_vm_play_cnf(MED_RES_OK);

                        /* play as memo */
                        aud_context_p->play_mode = AUD_VM_PLAY_AS_RING;

                        /* enter AUD_VM_PLAY state */
                        AUD_ENTER_STATE(AUD_VM_PLAY);
                    }

⌨️ 快捷键说明

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