Water boiled TCPMP

Source: Internet
Author: User
Tags abstract character set file separator int size mutex valid win32

At the end of last year to help others to do a project, understand the TCPMP, think the structure of the software is well written to do some records, today accidentally turned out to see that may be the people who are studying the software a little help to post it. If reproduced please indicate the source, thank you.

TCPMP is a powerful open source multimedia player,
The player is composed mainly of core frame module (common engineering) and decoder separator plug-in.
TCPMP plug-ins are very many, Libmad we combine a few of the most common plug-ins (FFmpeg, splitter) to illustrate, where interface plug-in implementation of TCPMP interface, because he and the media play no relationship, this part can be completely replaced, Replace it with your own interface.
FFMPEG Engineering is the main system of audio and video decoding module, FFmpeg is a set of recording, conversion, audio/video encoding and decoding functions as one of the complete open source solution. The development of FFmpeg is based on the Linux operating system, but it can be compiled and used in most operating systems. FFmpeg support MPEG, DivX, MPEG4, AC3, DV, FLV and more than 40 kinds of encoding, AVI, MPEG, OGG, Matroska, ASF and more than 90 kinds of decoding. Many open source players use the ffmpeg. But the FFMPEG program decoding efficiency is not very high, the system only uses the FFmpeg partial decoding function.
FFmpeg main directory has libavcodec, Libavformat and Libavutil subdirectories. Wherein the LIBAVCODEC is used for storing each Encode/decode module, Libavformat for storing muxer/demuxer module, libavutil for storing memory operation and other common modules. The system's media file splitter has a separate splitter module complete so no Libavformat subdirectories are required. FFmpeg directory libavcodec, libavutil reserved subdirectories.

Libmad works for MP3 file decoding, the project contains two function modules, one is responsible for parsing the MP3 file format, including MPEG1 audio files (Mp1,mp2,mp3,mpa), reading each frame of audio data, the other is responsible for decoding the MPEG1 audio data, The decoding code is in the Libmad subdirectory.
Libmad is an open source, high-precision MPEG1 audio decoding library that supports MPEG-1 (layer I, layer II, and LAYERIII, which is MP3). The Libmad provides a 24-bit PCM output that is fully fixed-point and is ideal for use on platforms without floating-point support. Using a series of APIs provided by Libmad, it is very simple to implement MP3 data decoding work. In the Mad.h file under the source code file directory of Libmad, you can see most of the data structure and API of the library. Libmad is used Fixed-integer, by integer analog decimal calculation, precision can only be guaranteed to the 9th digit after the decimal point (greater than 0 of the minimum 0.00000000372529), although the decoding accuracy will have a loss, but greatly improved the decoding efficiency, Especially in the embedded device can also achieve high bitrate MP3 file decoding.

Splitter engineering is used to parse multiple audio and video file formats. The file formats that can be parsed include: ASF media files, video files (AVI,DIVX), Windows waveform files (WAV,RMP), MPEG movie Files (MPEG,MPG,MPV), MPEG4 files (mp4,3gp,m4a,m4b,k3g). The above format can be parsed but the data encoding does not necessarily decode correctly, it needs to rely on the decoder of the system.

Common engineering is the core module, is an open set of data input, conversion, audio/video decoding, signal output and other functions as one of the complete multimedia playback framework. The framework itself does not contain any decode and split functions, these functions are implemented by plug-ins, the core module in a tree structure to manage all functional modules and plug-in modules, to achieve data render function, the input, conversion, output process Control, accept the playback process and processing of events, At the same time, it also realizes some common functions commonly used in the system operation, such as inverse discrete cosine transform, memory operation, multi-language character processing which is used in the interface. The main contents of the common project are as follows: Blit, Dyncode, overlay, PCM, SOFTIDCT, Win32, Zlib and other sub-directories. wherein Blit and overlay storage is a video signal rendering module, PCM storage PCM audio signal conversion module, SOFTIDCT storage inverse discrete cosine transform function, Win32 storage memory operation and other common modules, Dyncode This directory code is more obscure, Store is the program run is dynamically generated code module, for different CPU instruction set, PCM data channel and sampling rate different, video rendering data format and color depth, and other different situations dynamically generated different optimization code (this code is very exciting, not to let people admire TCPMP author's superb level). The core module has a context object, the object in the initialization function bool_t context_init (...) An instance of the object is created in the middle. This object instance record manages each function module, which can be used by the user interface to interact with the core module and manage the playback process.
Context Object Description:
typedef struct CONTEXT
{
int Version; Version information
uint32_t ProgramID;
Const tchar_t* ProgramName; Application Name
Const tchar_t* Programversion; Program version number, string
Const tchar_t* CmdLine; Program Command line information
void* Wnd; Video Render Window Handle
void* Nodelock; The function module accesses the critical section mutex variable
Array Node; Array of function module data Objects
Array Nodeclass; Function module defines an array of objects, organized according to the system logical relationship
Array Nodeclasspri; Function module defines an array of objects, arranged by system logic and module precedence
Array Nodemodule; External plug-in module array
int Loadmoduleno; The external plug-in number that is currently being loaded
void* LoadModule;
Array strtable[2]; A string resource array, which is divided into
Standard string resources for the underlying use and
The display string resource used for the interface, two resources represented by two arrays
Array Strbuffer;
Array Strmodule; Not used
void* Strlock; String array access critical section mutex variable
uint32_t Lang; Currently using language flags
int CodePage; Currently using code page flags
struct pcm_soft* PCM; PCM Audio Signal Conversion module
struct blitpack* Blit; Video Signal Rendering Module
struct node* Platform; Get platform-related information
struct node* advanced; Get advanced information on the playback module
struct node* Player; Playback control Module
Notify Error; Information Error callback function
Screen rotation information, in some systems the screen can be rotated 90 degrees or 180 degrees
Int (*hworientation) (void*);
void *hworientationcontext;
bool_t trydynamic; Not used
int settingspage; Not used
size_t Startupmemory; The number of valid memory that can be used
bool_t inhibernate; Whether to enter the hibernation state
bool_t waitdisable; Not used
int Ftrid; Not used
bool_t lowmemory; Whether the number of valid memory can be used is less than the minimum required by the system
Dynamic code Generation intermediate State and data
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; Not used
void* CharConvertUTF8; Not used
void* Charconvertcustom; Not used
int customcodepage; Not used
void* Charconvertascii; Not used
void* Application;
void* Logger; Not used
bool_t Keepdisplay; Do you want to keep the backlight long lit
int disableoutofmemory; Not used

} context;
The core module context pointer can be obtained by global function context* context ();
The global function that initializes the context object is bool_t context_init (const tchar_t* name,const tchar_t* version,int id,const tchar_t* cmdline,void* Application, where the name parameter is the application name and version is the release information string.
The global function that releases the context object is void Context_done ();
void Context_wnd (void*); the function initializes the video playback window handle to the device context.

The function module contains the definition object and the data object, defines the logical structure of the function module, and the data Object records the module properties and methods.
All the function module structure is organized by a tree structure, the structure relationship is as follows, node is the root node of the whole structure, under the Sub-node, the node can be divided into real node, global node, set node and abstract node by type.
#define Cf_size 0X00FFFFFF
#define Cf_global 0x01000000
#define Cf_settings 0x02000000
#define CF_ABSTRACT 0x08000000
Abstract nodes do not have corresponding object instances, like the abstract base class of C + +, in order to organize system structure according to the logical relationship, for example, node is abstract nodes. Global nodes have only one instance of an object globally, such as the playback control module PLAYER_ID. Set the node representation and system playback settings related, such as the Sound Equalizer module equalizer_id, Color control module COLOR_ID. The real node is different from the abstract node, that is, the node that can generate the object instance, the real node does not have a special identity, usually the data object occupies memory size to indicate whether it is a real node, when the node is created to allocate memory unit according to this information, the real node can have child nodes, for example: mms_id parent node is http_id. Global node, the set node and the real node can be combined, such as the playback control node is also a global node, set node and real node. The node name is the real node after the _id, otherwise it is the abstract node.

Node (root)
├─flow (flow control module)
│├─codec (decoding module)
││├─equalizer_id (sound equalizer module)
││├─VBUFFER_ID (video buffer module)
││├─DMO (DirectX Media Object)
│││├─wmv_id
│││├─wms_id
│││├─wmva_id
│││├─wma_id
│││└─wmav_id
││├─ffmpeg VIDEO (FFMPEG decoding module)
││└─LIBMAD_ID (Libmad Mp3 decoding module)
│├─out (signal rendering module)
││├─aout (audio signal rendering)
│││├─nullaudio_id
│││└─waveout_id
││└─vout (video signal rendering)
││├─nullvideo_id
││└─overlay
│├─IDCT (Discrete cosine decoding module)
││└─softidct_id
│└─CODECIDCT (Discrete cosine decoding module, less function than IDCT)
│└─mpeg1_id
├─media (media file format Encoding parsing module)
│├─format (Format parsing module)
││└─formatbase
││├─rawaudio
│││└─mp3_id
││├─rawimage
││├─asf_id
││├─avi_id
││├─mp4_id
││├─mpg_id
││├─nsv_id
││└─wav_id
│├─playlist (Playlist module)
││├─asx_id
││├─m3u_id
││└─pls_id
│└─streamprocess (Data stream processing module)
├─stream (data input module)
│├─MEMSTREAM_ID (Memory Data Flow module)
│├─file_id (File IO module)
│└─HTTP_ID (Network data acquisition module)
├─timer (Timer module)
│└─systimer_id
├─association_id (File extension auto-correlation module)
├─ADVANCED_ID (Advanced Setup module)
├─COLOR_ID (Color control module)
├─PLATFORM_ID (Platform information module)
├─xscaledriver_id (Intel xscale CPU information Module)
├─PLAYER_ID (playback control module)
└─PLAYER_BUFFER_ID (play buffer module)

The node tree structure is implemented by a number of static definition objects (NODEDEF) instances,
typedef struct NODEDEF
{
int Flags;
int Class;
int ParentClass;
int priority;
Nodecreate Create;
Nodedelete Delete;
} nodedef;
Flags represents the type of the current node: abstract, real node, global, setting.
class represents the identity of the current node, such as Media_class or asf_id, and so on.
ParentClass represents the parent node identity of the current node, such as the parent node of the Systimer_id object is Timer_class.
Priority indicates the current node precedence.
Create and delete are two function pointers that represent the creation and destruction functions of the node.
If the structure definition of the playback control module is
static const NODEDEF Player =
{
sizeof (Player_base) | cf_global| Cf_settings,
PLAYER_ID,
Node_class,
pri_maximum+600,
(nodecreate) Create,
(Nodedelete) Delete,
};

Most nodes have a corresponding data object, record the data and methods of the node, each child node object is a parent node object as an element of that node, similar to C + + encapsulation inheritance mechanism. If the parent node of a child node does not have a data object, the node can inherit directly from node nodes. Each node can be viewed as a direct or indirect child node of a node, so all nodes nod to the same node structure, and the child nodes may have their own attributes, which are the child nodes ' own elements after inheriting the parent object.
typedef struct NODE
{
int Class;
Nodeenum Enum;
Nodeget Get;
NodeSet Set;
} node;
class represents the identity of the object, such as player_id.
An enum is a function pointer to a function that enumerates the properties of the current node.
Get is a function pointer that gets the value of a property of the current node.
Set is a function pointer that sets the value of a property of the current node.

The attribute value data attribute of a node is in a static const datatable xxxparams[] = {...}; is defined in the static array.
typedef struct DataTable
{
int No;
int Type;
int Flags;
int FORMAT1;
int Format2;
} DataTable;

No indicates that the identity of the property, such as the # define Player_play 0x32 of the playback control module, indicates that the player is playing or pausing.
Type represents the data type of the property, and the available values are defined in node.h.
Flags are flags of attribute data, indicating whether the data is read-only, has a maximum minimum, and so on, and the available values are defined in node.h, and if the flag contains Df_setup and does not contain df_nosave and df_rdonly attributes, the property is recorded in the registry. Initialize the property with data from the registry the next time it is started.
FORMAT1 and FORMAT2 are optional flags for use with flags, such as if flags indicates that the attribute has a maximum minimum value, FORMAT1 and FORMAT2 can represent the minimum and maximum values, respectively.

In the System context object, there are two elements that record the node information, and array nodeclass;,array is the array data type, node is an array of nodes data objects, an array of Nodeclass node objects, organized according to the system logic relationship.
When you create a node, you pass in the Nodedef object-to-node creation function, which generates a corresponding Nodeclass object based on the Nodedef information and adds it to the Nodeclass array, allocating the memory space of the data object based on the Nodedef information. The node's data object is initialized inside the CREATE function of the node.

In all function modules and interface interaction is mainly the playback control module struct node* player;
context* p = Context ();
player* Myplayer = NULL;
if (p) Myplayer = (player*) (P->player);
The control playback parameters use Set (void* this,int no,const void* data,int Size), function, the first argument is the play module pointer, the second parameter is the control code, that is, what to do, and the third parameter is a value that needs to be assigned to the control code. The last parameter is the amount of memory occupied by the assigned value.
For example, the code that starts playing is:
Myplayer->set (myplayer,player_play,1,sizeof (int));
Player_play is the control code, which indicates that the playback pause function is currently controlled, and a value of 1 means that playback is 0 for pause.
Get a control property using Get (void* this,int no,void* data,int Size); function, the parameter means the same as the set function.
The control code is a set of macros defined in the Player.h file. The more important control parameters are
Play or Pause (bool_t)
#define Player_play 0x32
Position in fraction (fraction)
#define Player_percent 0x25
Position in time (tick_t)
#define Player_position 0x28
Current format (format*)
#define Player_format 0x2B
Current file in playlist (int)
#define Player_list_current 0x2F
Current file index (suffled) in playlist (int)
#define PLAYER_LIST_CURRIDX 0xa2
Fullscreen mode (bool_t)
#define Player_fullscreen 0x3e
Stop
#define PLAYER_STOP 0xb2
Skin viewport Rectangle (rect)
#define Player_skin_viewport 0x3C
All available parameters of the playback control module are shown in the static const DataTable playerparams[] structure.

Add a media file to the playback module using int playeradd (player* player,int Index, const tchar_t* Path, const tchar_t* Title);
The first parameter is the play module pointer, the second parameter is the ordinal that is added to the module file queue, if the file is the first file the parameter is set to 0, the third parameter is the media file's directory and name, the fourth parameter is the media file title, the parameter can be ignored.

The core module also manages multi-language strings, using the function const tchar_t* LANGSTR (int class, int id), and the const tchar_t* langstrdef (int class, int id) to get the corresponding string, There are two types of system string resources, standard strings and special character set strings. The standard string resource file is the Lang_std.txt file under the project directory, which is an ASCII character that can be compatible with other code page characters. This file records the strings that are required for the core module to run, and the encoding format and file format that the decode and Splite modules can handle are also recorded in this file, such as in the Lang_std.txt file.
Mp3_0001=audio/mpeg
Mp3_0002=mp1:a;mp2:a;mp3:a;mpa:a
mp3_0200=acodec/0x0055
Records the file types, extensions, and file signatures of the MP3 file separator.
To get a standard string using the function Langstrdef, the first parameter represents the character category, and the second parameter represents the character ID. The interface is related to a special character set string, using the function Langstr, the first parameter represents the character category, and the second parameter represents the character ID. The meaning of the structure of the string resource file is described in a later document.




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.