MTK audio player case implementation

Source: Internet
Author: User

MTK audio playerCase implementation is the content of this article, mainly aboutMTK audio player.MTKThe structure of audio player on 6225 can be divided into three layers: The top application interface layer, the middle audio playing api layer, and the underlying codec library andAudioDriver. Its structure is roughly as follows:

It can be seen that the entire invocation layer is deep. We will learn layers separately.
 
1. MMI Task Layer

In this layer, the audio player module implementsPlayerProgram, including the implementation of the interface view, the processing of the interface logic, and the call of the interface of the MID module to implementAudioOperation. to learn the specific implementation details, you can refer to the simplified MVC mode of view and model + control, including the display-related screen operation Display Section, the msghandler part of the message and the main program logic and key processing part.

MTKThe Platform processes events in the callback function mode, so the program processes are not in order. The occurrence of events will cause the corresponding callback to be called and trigger a response of the entire audio player. it should be noted that the callback function for handling the same event may be different on different interfaces, which is set when the interface is created.

The interfaces of this module are complex. To provide a uniform BT interface, there are two layers of playback interfaces, such as mmi_audply_play and mmi_audply_do_play_action (). the interface of the entire module is not clear enough, and it is complicated and confusing. the display part of the module is implemented by controls, which is relatively simple. You can refer to the control implementation details to understand the display subsystem of the platform. The management of the playback file list is implemented through file operations, for more information, see audioplayerplaylist.

The MDI layer and Media interface layer can be considered as a whole, and are the encapsulation of Media operations by the MMI layer. it includes multiple parts of the interface, Here we only look at the audio interface part, other modules such as video, fm interface is similar. the Audio interface includes playing, pausing, stopping, obtaining the playing time, and obtaining the playing spectrum. these interfaces are basically implemented in synchronous processing. for example, the playback interface:

The interface at the MDI layer is

 
 
  1. mdi_result mdi_audio_play_file(void *file_name, U8 play_style, void *cache_p, mdi_callback handler); 

The called Media interface is:

 
 
  1. kal_int32 media_aud_play_file(module_type src_mod_id, void *file_param)  
  2. {  
  3.       aud_result = MED_RES_OK;  
  4.     aud_send_play_file_req(src_mod_id, file_param);  
  5.     AUD_WAIT_EVENT(AUD_EVT_PLAY);  
  6.     return aud_result;  

Aud_send_play_file_req (src_mod_id, file_param calls msg_send_ext_queue (ilm_ptr );

Send a playback request Message to the external Message queue of the media task. The AUD_WAIT_EVENT (AUD_EVT_PLAY) is defined as follows:

 
 
  1. #define AUD_WAIT_EVENT(evt_) do{                                   
  2.          kal_uint32 retrieved_events;                                    
  3.          kal_retrieve_eg_events(aud_context_p->aud_event, (evt_),            
  4.          KAL_OR_CONSUME, &retrieved_events, KAL_SUSPEND); }while(0) 

Wait until the AUD_EVT_PLAY event arrives. synchronization is achieved through the event.
 
2. on the Media Task layer, after media task is started, med_task_main calls med_main (void *) & current_ilm) to process the message after obtaining the external message, med_main will be performed again based on the Message Type
Distribution: audio messages are distributed to void aud_main (ilm_struct * ilm_ptr) for processing. according to the corresponding request message, aud_main calls the corresponding handler function for processing. for example, the stream playback request message MSG_ID_L4AUD_MEDIA_PLAY_REQ can be processed as follows:

 
 
  1. Void aud_media_play_req_hdlr (ilm_struct * ilm_ptr)
  2. {
  3. .... // Omit other branch processing and error handling
  4. // Step 1: Release conflicting resources and set playing parameters.
  5. // Step 2: select the playing function based on the format
  6. Switch (aud_context_p-> current_format)
  7. {
  8. ...
  9. Case MED_TYPE_MMF:
  10. Result = aud_melody_play_by_name (msg_p-> file_name, msg_p-> play_style, 0 );
  11. Break;
  12. ...
  13. Case MED_TYPE_M4A:
  14. Aud_context_p-> source_type = AUD_FILE;
  15. Aud_context_p-> play_style = msg_p-> play_style;
  16. Result = aud_media_play_file_stream (
  17. Msg_p-> file_name,
  18. Msg_p-> play_style,
  19. 1,
  20. KAL_FALSE,
  21. Msg_p-> cache_p );
  22. Break;
  23. Case MED_TYPE_3GP:
  24. Case MED_TYPE_MP4:
  25. Aud_context_p-> source_type = AUD_FILE;
  26. Aud_context_p-> play_style = msg_p-> play_style;
  27. Result = aud_media_play_audio_track_in_video (
  28. Msg_p-> file_name,
  29. Msg_p-> play_style,
  30. KAL_TRUE,
  31. KAL_FALSE );
  32. Break;
  33. Default:
  34. Result = MED_RES_INVALID_FORMAT;
  35. Break;
  36. }
  37. // Step 3: start playback after processing
  38. Aud_set_result (kal_int32) result); // sets the result returned by the playback operation.
  39. AUD_SET_EVENT (AUD_EVT_PLAY); // sets the AUD_EVT_PLAY event
  40. If (aud_context_p-> src_mod! = MOD_MMI) // whether the playback request comes from the MMI task
  41. {
  42. Aud_send_media_play_cnf (result); // sends a playback feedback message to the request module.
  43. }
  44. }

3. L1Audio module layer. This layer includes the underlying decoding library, drivers for the lower layer, and audio hardware calls and processing. it includes the processing interface for the specific audio format, such as the interface for AAC files:

 
 
  1. MHdl *AAC_Open(void(*handler)( MHdl *handle, Media_Event event ),  
  2. STFSAL *pstFSAL, void *param)  
  3. Media_Status aacMFPlayFile( MHdl *hdl );  
  4. Media_Status aacMFResumeFile( MHdl *hdl );  
  5. Media_Status aacMFPause( MHdl *hdl );  
  6. Media_Status aacMFStop( MHdl *hdl ); 

....

A complete set of interfaces. in the play request processing function described in the second layer above, if the file format to be processed is AAC, it calls the AAC_Open interface to obtain all function interfaces related to the playback operation. other subsequent operations provide processing functions.

MTKHow are tasks and mod defined?

I cannot figure out task and mod in MTK. Does a task load only one mod?

In task _ init.c, void InitApplication,

 
 
  1. for(i=0;i<TOTAL_TASKS-9;i++)  
  2.  {  
  3.   task_info_g1[i+9].task_ext_qid=OslCreateMsgQ(task_create_tbl[i].task_qname,  
  4.         sizeof(MYQUEUE),  
  5.         task_create_tbl[i].task_ext_qsize);  
  6.   task_info_g1[i+9].task_id = osl_create_task (task_create_tbl[i].task_name,  
  7.         task_create_tbl[i].task_priority,  
  8.         task_create_tbl[i].task_stack_size,  
  9.         task_create_tbl[i].task_entry_func,  
  10.         (void *)(i+9),0);  
  11.    
  12.   task_info_g1[i+9].task_name=task_create_tbl[i].task_name;  
  13.   task_info_g1[i+9].task_priority=task_create_tbl[i].task_priority;  
  14.   task_info_g1[i+9].task_stack_size=task_create_tbl[i].task_stack_size;  
  15.   task_info_g1[i+9].task_entry_func=task_create_tbl[i].task_entry_func;  
  16.  
  17.   task_info_g1[i+9].task_qname=task_create_tbl[i].task_qname;  
  18.   task_info_g1[i+9].task_ext_qsize=task_create_tbl[i].task_ext_qsize;  
  19.  
  20.  } 

Here, why is task _ info_g1 [I + 9] running at the positions 0 to 9?

The task generated here is defined by TOTAL_TASKS. I have selected one of MMItask. c as follows:

 
 
  1. #ifdef MMI_ON_WIN32  
  2. #define MOD_MMI MOD_PRT  
  3. typedef enum {  
  4.   MOD_DUM1=0x09,  
  5.   MOD_L4C1,  
  6.   MOD_PRT,  
  7.   MOD_DUM2,  
  8.   TOTAL_TASKS  
  9. }task_indx_type;  
  10. extern osl_task_info   task_info_g1[TOTAL_TASKS];  
  11. #endif 

At the time of task generation, the task and mod are connected. However, when the task is communicating, there are many msg_send_ext_queue and receive_ext_queue, src_mod_id and dest_mod_id, which are different mod.

In addition to MMI task and MOD_MMI, where are the other tasks in which the mod runs?

No. A task is running like a process. It is awakened when a message is received from the queue.

One task can load N mod.

Summary:MTK audio playerThe implementation of the case is complete. I hope this article will help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.