The player consists of the core framework module (common project), decoder, and separator plug-in. There are many tcpmp plug-ins. The main plug-ins are: interface plug-ins implement the tcpmp interface, FFmpeg is the main audio/video decoding module of the system, and splitter is the media file separator.
Because FFmpeg is not efficient in decoding, the system only uses some FFMPEG functions. The libavformat module is not used, but the splitter module is used. Other plug-ins are not currently under research. This week, we mainly analyzed the common project.
The common project is a core module and an open multimedia playing framework integrating data input, conversion, audio/video decoding, and signal output. This framework does not contain any decode and split functions. These functions are implemented by plug-ins. The core module manages all functional modules and plug-in modules in a tree structure to enable data render, controls the input, conversion, and Output Processes, accepts operations during playback and processes events, and implements some common functions that are frequently used during system operation, for example, inverse Discrete Cosine transformation, memory operations, and multilingual character processing that are frequently used during decoding.
The main directories of the common project are bits, dyncode, overlay, PCM, softidct, Win32, and zlib. Bits and overlay are stored in the video signal rendering module, PCM stores the PCM audio signal conversion module, softidct stores the inverse Discrete Cosine transform function, and Win32 stores memory operations among other common modules, the code in the dyncode directory is obscure. It stores the dynamically generated code module when the program is running. For different CPU instruction sets, the PCM Data sound path and sampling rate are different, different optimization codes are dynamically generated in different situations such as video rendering data format and color depth. zlib provides memory compression and decompression functions, including integrity check of uncompressed data.
The following are several important concepts in the core modules of the common project:
(1) Context object
This object creates an object instance (context. h) in the initialization function bool_t context_init ). This object instance records management function modules. The user interface can interact with the core module to manage and control the playback process.
(2) functional modules
The function module includes defining the object nodedef and the Data Object node, defining the logical structure between the object description function modules, and the attributes and methods of the Data Object Record module. The structure of all functional modules is organized in a tree structure. The structure relationship is as follows: node is the root node of the entire structure, which is a subnode. nodes can be divided into real nodes and global nodes by type, set nodes and abstract nodes.
Abstract nodes do not have corresponding object instances. Similar to the abstract base class of C ++, they exist to organize the system structure according to the logical relationship. For example, node is an abstract node. A global node has only one instance of an object, for example, player_id of the playback control module. The Set node representation is related to the system playback settings, such as the sound balancer module equalizer_id and the color control module color_id. Different from abstract nodes, a real node is a node that can generate an object instance. A real node does not have a special identifier. Generally, the memory size occupied by Data Objects indicates whether it is a real node, when creating a node, You need to allocate memory units based on the information. The real node can also have sub-nodes. For example, the parent node of mms_id is http_id. Global nodes: Set nodes and real nodes can be combined. For example, the playback control node is a global node, and set nodes and real nodes.
The main node tree distribution is shown below:
Node (root node)
Executor-flow (Flow Control Module)
│ ─ ── Codec (Decoding Module)
│ Audio-equalizer_id (sound balancer module)
│ ─ ── Vbuffer_id (video buffer module)
│ Mongo── DMO (DirectX Media object)
│ ── Wmv_id
│ ─ ── Wms_id
│ ─ ── Wmva_id
│ ── Wma_id
│ ── Wmav_id
│ Yun── FFMPEG video (FFMPEG decoding module)
│ ─ ── Libmad_id (libmad MP3 decoding module)
│ Signal-out (signal rendering module)
│ Audio-Aout (Audio Signal rendering)
│ ─ ── Nullaudio_id
│ └ ── Waveout_id
│ Audio-Vout (Video Signal rendering)
│ ─ ── Nullvideo_id
│ ─ ── Overlay
│ ├ ── IDCT (Discrete Cosine decoding module)
│ └ ── Softidct_id
│ Cosine-codecidct (Discrete Cosine decoding module, fewer functions than IDCT)
│ ─ ── Mpeg1_id
Media-media (Media File Format encoding parsing module)
│ ─ ── Format (format parsing module)
│ └ ── Formatbase
│ Audio-rawaudio
│ ─ ── Mp3_id
│ ─ ── Rawimage
│ ├ ── Asf_id
│ ─ ── Avi_id
│ ─ ── Mp4_id
│ Sampled-mpg_id
│ ─ ── Nsv_id
│ ─ ── Wav_id
│ Playlist (playlist module)
│ ─ ── Asx_id
│ ─ ── M3u_id
│ Sampled-pls_id
│ └-Streamprocess (data stream processing module)
├ ── Stream (data input module)
│ ─ ── Memstream_id (memory data stream module)
│ ├ ── File_id (file IO module)
│ ─ ── Http_id (Network Data Acquisition Module)
Timer-timer (timer module)
│ ─ ── Transferimer_id
Association_id (Automatic File Extension Association module)
├ ── Advanced_id (Advanced Settings module)
Color_id (color control module)
Platform-platform_id (platform information module)
├ ── Xscaledriver_id
Player_id (playback control module)
Playing-player_buffer_id (playing buffer module)
The following are several important data structures of the core modules of the common project:
(1) Context object
Typedef struct Context
{
Int version; // version information
Uint32_t programid; // application handle
Const tchar_t * programname; // Application name
Const tchar_t * programversion; // program version, string
Const tchar_t * cmdline; // program command line information
Void * WND; // handle of the video rendering window
Void * nodelock; // the function module accesses the mutex variable in the critical section.
Array node; // array of data objects in the function module
Array nodeclass; // The ordered by ID function module defines an array of objects, which are organized according to the system Logical Relationship.
Array nodeclasspri; // ordered by priority | ID function module defines an array of objects, which are arranged according to the system Logical Relationship and priority.
Array nodemodule; // an array of external plug-in Modules
Int loadmoduleno; // The number of the external plug-in currently being loaded
Void * loadmodule; // The external plug-in currently being loaded
Array strtable [2]; // string resource array. the string is divided into the standard string resource used at the underlying layer and the string resource displayed on the interface. The two resources are represented in two arrays.
Array strbuffer;
Array strmodule; // not used
Void * strlock; // string array access the mutex variable in the critical section
Uint32_t Lang; // current language flag
Int codePage; // The code page flag currently used
Struct pcm_soft * PCM; // PCM audio signal conversion module
Struct blitpack * BCT; // video signal rendering Module
Struct node * platform; // obtain platform information
Struct node * Advanced; // obtain the advanced information of the playback module.
Struct node * player; // playback control module
Y error; // information error callback function
INT (* hworientation) (void *);
Void * hworientationcontext;
Bool_t trydynamic; // unused
Int settingspage; // unused
Size_t startupmemory; // valid memory size available
Bool_t inhibernate; // whether the object is in sleep state
Bool_t waitdisable; // unused
Int ftrid; // not used
Bool_t lowmemory; // whether the valid memory size can be used is smaller than the minimum required by the system
// Generate intermediate status and data using dynamic code
Bool_t codefailed;
Bool_t codemoveback;
Bool_t codedelayslot;
Void * codelock;
Void * codeinstbegin;
Void * codeinstend;
Int nextcond;
Bool_t nextset;
Bool_t nextbyte;
Bool_t nexthalf;
Bool_t nextsign;
Uint32_t * flushcache; // unused
Void * charconvertutf8; // unused
Void * charconvertcustom; // unused
Int customcodepage; // not used
Void * charconvertascii; // unused
Void * application;
Void * logger; // not used
Bool_t keepdisplay; // whether to keep the backlight bright
Int disableoutofmemory; // not used
} Context;
(2) nodedef function module definition object
The tree structure of the function module is usually implemented by several static definition objects (nodedef) instances,
Typedef struct nodedef
{
Int flags; // type of the function module node: abstract, real node, global, and set.
Int class; // the identifier of a function module node, such as media_class or asf_id.
Int parentclass; // The identifier of the parent node of the function module. For example, the parent node of the assumimer_id object is timer_class.
Int priority; // indicates the node priority of the function module.
Nodecreate create; // create a function module to define the function pointer of an object
Nodedelete Delete; // The destroy function module defines the function pointer of an object.
} Nodedef; // function module definition object
For example, the static definition object of the decoder function module:
Static const nodedef codec =
{
Sizeof (codec) | cf_abstract,
Codec_class,
Flow_class,
Pri_default,
(Nodecreate) Create,
(Nodedelete) delete,
};
(3) The nodeclass function module defines the object linked list structure.
The function module tree structure is implemented using a linked list. Each linked list represents a branch of the tree structure.
Typedef struct nodeclass
{
Nodedef def; // define the object of the function module
Bool_t registered; // whether to register
Int moduleno; // module ID
Struct nodeclass * parent; // the function module defines the parent object of the object.
} Nodeclass; // the function module defines the Node object linked list structure.
(4) node function module data object
Typedef struct Node
{
Int class; // type of function module nodes, such as media_class, which is the same as nodedef.
Nodeenum Enum; // node attribute function pointer
Nodeget; // get the function pointer of the node attribute.
Nodeset set; // set the function pointer of the node attribute.
} Node; // function module data object
The relationship between the above data objects:
In the context object of the system, there are two elements to record function module information: array node and array nodeclass. array is an array data type (in buffer. h/C definition and implementation). node is an array of data objects in the function module. The nodeclass function module defines an array of objects and is organized according to the system Logical Relationship.
When creating a function module, input the nodedef object to the function module to create a function. The function generates the corresponding nodeclass object based on the nodedef information and adds it to the nodeclass array. Meanwhile, it allocates the memory space of the data object according to the nodedef information. Initialize the Data Object node of the function module in the create function of the node.
(5) attributes of the datadef function module
Typedef struct datadef
{
Int no; // The identifier of the attribute. For example, the # define player_play 0x32 in the playback control module controls the player to play or pause.
Int type; // the Data Type of the attribute, defined in node. H, such as type_bool
Int flags; // attribute data flag. It indicates whether the data is read-only and has the maximum or minimum values. It is defined in node. H, such as df_rdonly.
Int format1;
Int format2;
Const tchar_t * Name;
Int class;
Int size;
} Datadef; // attribute object definition
Format1 and format2 are optional and used together with flags. For example, if flags indicates that the attribute has the maximum and minimum values, format1 indicates the maximum value, and format2 indicates the minimum value;
In addition, if (! (Flags & df_nosave )&&! (Flags & df_rdonly) indicates that the attribute is saved and can be read and written, and is recorded in the registry. The Attribute Table is initialized with the registry data at the next startup.
(6) datatable function module attribute list
Typedef struct datatable
{
Int no;
Int type;
Int flags;
Int format1;
Int format2;
} Datatable; // list of function module attributes
The attributes of each function module are usually defined and stored in arrays, such as the list of attributes of the format parsing module.
Static const datatable Params [] =
{
{Format_input, type_node, df_input | df_hidden, stream_class },
{Format_output, type_node, df_hidden, stream_class },
{Format_duration, type_tick },
{Format_filepos, type_int, df_hidden },
{Format_filesize, type_int, df_kbyte },
{Format_auto_readsize, type_bool, df_hidden },
{Format_global_comment, type_comment, df_output },
{Format_find_subtitles, type_bool, df_hidden },
{Format_stream_count, type_int, df_hidden },
Datatable_end (format_class)
};
(7) nodemodule external plug-in function module
Typedef struct nodemodule
{
Int ID; // plug-in ID
Int objectcount; // number of instances for this plug-in (reference count)
Bool_t TMP; // whether it is a temporary Node
Int64_t date; // set the time
Int keepalive; // The retention time.
Void * module; // external plug-in Module
Void * dB;
Void * func;
Uint8_t * min;
Uint8_t * max;
} Nodemodule; // external plug-in module Node
Core module initialization process and corresponding code correspondence (refer to context_init function in context. c)
Mem_init ();
// Initialize resources such as memory (Win32/mem_win32.c)
Dyncode_init ();
// The program runs the program to dynamically generate code modules, optimize PCM and video rendering modules (dyncode/dyncode. c)
String_init ();
// The system uses string initialization (Str. C, Win32/str_win32.c)
Pcm_init ();
// Audio signal conversion module initialization (PCM/pcm_soft.c)
Blit_init ();
// Initialize the video signal rendering module (blit/blit_soft.c)
Node_init ();
// Initialize the root node module (node. C, Win32/node_win32.c)
Platform_init ();
// Platform information module initialization (platform. C, Win32/platform_win32.c)
Stream_init ();
// Input data stream module initialization (streams. c)
Advanced_init ();
// Advanced settings module initialization (advance. c)
Flow_init ();
// Flow control module initialization (flow. c)
Codec_init ();
// Initialize the decoding module (codec. c)
Audio_init ();
// Audio signal processing module initialization (audio. c)
Video_init ();
// Initialize the video signal processing module (video. c)
Format_init ();
// Format parsing module initialization (format. c)
Playlist_init ();
// Playlist module initialization (playlist. c)
Formatbase_init ();
// Initialize the basic format parsing module (format_base.c, format_subtitle.c)
Nulloutput_init ();
// No output device module initialization (nulloutput. c)
Rawaudio_init ();
// Rawaudio module initialization (rawaudio. c)
Rawimage_init ();
// Rawimage module initialization (rawimage. c)
Timer_init ();
// Timer module initialization (timer. c)
Idct_init ();
// Initialize the Discrete Cosine decoding module (IDCT. c)
Overlay_init ();
// Overlay. c)
M3u_init ();
// Initialize the M3U format playlist module (playlist/M3U. c)
Pls_init ();
// Initialize the playlist module in the PLS format (playlist/pls. c)
Asx_init ();
// ASX format playlist module initialization (playlist/ASX. c)
Waveout_init ();
// Waveform output module initialization (waveout. C, Win32/waveout_win32.c)
Softidct_init ();
// Soft Discrete Cosine decoding module initialization (softidct/softidct. c)
Plugins_init ();
// External plug-in module initialization (Win32/node_win32.c)
In addition, the association_init module of the Automatic File Extension (refer to Win32/association_win32.c) and color_init module of the Color Control Module (refer to color. c); equalizer_init (see equalizer. c); initialize the playback control module (refer to player. c ).
Load External plug-in modules to the system (refer to node. C and node_win32.c)
The loadmodule function in node. C can load external plug-in modules in the system,
Static noinline nodemodule * loadmodule (Context * P, int no ),
The first parameter is the context object,
The second parameter is the external plug-in module identifier.
Node_win32.c defines the DLL Load And Unload functions and corresponding registry operations, as shown in
Load the external plug-in module on the function module Node
Void * nodeloadmodule (const tchar_t * path, int * ID, void ** anyfunc, void ** dB)
Player. c)
The main interaction between all functional modules and the interface is the playback control module struct node * player. The usage is as follows:
Context * P = context ();
Player * myplayer = NULL;
If (p) myplayer = (player *) (p-> player );
Control playback
Set (void * This, int No, const void * data, int size)
The first parameter is the playback module pointer,
The second parameter is to control the code, that is, what operations to perform,
The third parameter is the value that needs to be assigned to the control code,
The last parameter is the memory occupied by the assigned value.
Myplayer-> set (myplayer, player_play, 1, sizeof (INT ));
Player_play is the control code, indicating that the current control is the playback pause function. The value 1 indicates that the playback is 0, indicating that the playback is paused.
Get a control property using get (void * This, int No, void * data, int size); function, parameter meaning is the same as set function.
The control code is a set of macros defined in the player. h file. For more important control parameters, see static const datatable playerparams [] structure.
Add a media file to the playback module.
Int playeradd (player * player, int index, const tchar_t * path, const tchar_t * Title );
The first parameter is the playback module pointer,
The second parameter is the serial number added to the file queue of the playback module. If the file is the first file, this parameter is set to 0,
The third parameter is the Directory and name of the media file,
The fourth parameter is the media file title, which can be ignored.