?? skl_mpg4.h
字號:
/******************************************************** * Some code. Copyright (C) 2003 by Pascal Massimino. * * All Rights Reserved. (http://skal.planet-d.net) * * For Educational/Academic use ONLY. See 'LICENSE.TXT'.* ********************************************************//* * skl_mpg4.h * * Main MPEG4 header ************************************************/#ifndef _SKL_MPG4_H_#define _SKL_MPG4_H_#include "skl.h"#include "skl_syst/skl_cpu_specs.h"//////////////////////////////////////////////////////////struct SKL_MP4_ENC;struct SKL_MP4_DEC;class SKL_MP4_ANALYZER;struct SKL_MP4_INFOS; // infos passed to analyzerclass SKL_MEM_I; // memory pool interfacestruct SKL_MP4_PIC; // visible YUV picturetypedef struct SKL_IMG_DSP SKL_IMG_DSP; // image helper funcstypedef struct SKL_MB_DSP SKL_MB_DSP; // macroblock helper funcstypedef struct SKL_GMC_DSP SKL_GMC_DSP; // GMC helper funcstypedef struct SKL_METRIC_DSP SKL_METRIC_DSP;//////////////////////////////////////////////////////////// Macroblock types & MV macros// shared by encoder and analyzer//#define SKL_MB_INTER 0#define SKL_MB_INTER_Q 1#define SKL_MB_INTER4V 2#define SKL_MB_INTRA 3#define SKL_MB_INTRA_Q 4#define SKL_MB_SKIPPED 6#define SKL_MB_LAST 7typedef SKL_INT16 SKL_MV[2]; // some compilers don't like copying typedef'd arrays...#define SKL_COPY_MV(a,b) ((a)[0]=(b)[0], (a)[1]=(b)[1])#define SKL_ZERO_MV(a) ((a)[0]=0, (a)[1]=0 ) // useful macros#define SKL_IS_ZERO_MV(MV) ((*(SKL_UINT32*)(MV)) == 0x00000000)#define SKL_IS_SAME_MV(MV1,MV2) (*(SKL_UINT32*)(MV1) == *(SKL_UINT32*)(MV2)) /** @file */ /** @var SKL_MP4_SLICER Hook function for pre/post processing of pictures. <p> This function is called after a macroblock row has been decoded, or just before encoding a row. The vertical row position is given by the parameter 'y', and its height is given by the parameter 'Height'.<p> In addition, this hook is called two more times at the start and end of picture scan. In this case, the 'Height' parameter is zero, and 'y' is either equal to 0 or to picture's Height. @see SKL_MP4_ENC @see SKL_MP4_DEC */typedef void (*SKL_MP4_SLICER)(const SKL_MP4_PIC *Pic, int y, int Height, SKL_ANY Data);//////////////////////////////////////////////////////////extern "C" { /** @internal Macroblock types for SKL_MP4_MAP::Type attribute, used by the analyzer. */#define SKL_MAP_SKIPPED 0#define SKL_MAP_INTRA 1 // for SKL_MB_INTRA#define SKL_MAP_GMC 2 // real GMC (not SKIPPED)#define SKL_MAP_16x16 3 // for SKL_MB_INTER#define SKL_MAP_16x8 4 // ..#define SKL_MAP_8x8 5 // ..#define SKL_MAP_LAST 6 /** Structure for storing analyzer's result */struct SKL_MP4_MAP { SKL_UINT8 Type; /**< 0: skipped <br> 1: INTRA (16x16) <br> INTER: 2:16x16, 3:16x8 (field pred), 4:8x8 (4v) 5: GMC (~16x16) <br>*/ SKL_UINT8 Fields; /**< field dirs (used for INTER 16x8 and B-DIRECT) */ SKL_INT8 dQ; /**< delta quant (used for INTER 16x8 and B-DIRECT) */ SKL_INT8 Flags; /**< Encoder Flags. bit 0: use field DCT */ SKL_UINT32 Sad; /**< Storage of the macroblock's final SAD */ SKL_UINT32 Sad16; /**< SAD after 16x16 full-pel search */ SKL_MV MV; /**< Motion vector after 16x16 full-pel search */ SKL_MV Acc; /**< Tentative value for acceleration vector */}; /** @class SKL_MP4_PIC This class is used for storing input/output frame informations such as dimensions, YUV data, time stamps...<p> <b>Warning</b> : The size of luma component is Width x Height, whereas the U and V components are of size Width/2 x Height/2 each.<br> However, <b>all</b> of the Y, U and V component planes share the same stride, given by BpS (Bytes Per Scanline).<br> Here is an example of the layout, with internal hidden edges shown in blue:<br> <img src="../mp4_yuv.jpg"> Note: This video format is often called "IMC2". <p> */struct SKL_MP4_PIC{ SKL_BYTE *Y; /**< Pointer to the Y-plane data, of size Width x Height, with stride BpS */ SKL_BYTE *U; /**< Pointer to the U-plane data, of size Width/2 x Height/2, with stride BpS */ SKL_BYTE *V; /**< Pointer to the V plane data, of size Width/2 x Height/2, with stride BpS */ int Coding; /**< Coding type. Set by the encoder/decoder. Values: 0:key frame (I-VOP), 1:P-VOP, 2:B-VOP, 3:S/D-VOP, 4: not coded */ int Width; /**< Width of picture, in pixel. */ int Height; /**< Height of picture, in pixel. */ int BpS; /**< Bytes Per Scanline */ SKL_MV *MV; /**< Motion Vectors */ double Time; /**< Presentation time, in seconds */ SKL_UINT64 Time_Ticks; /**< Presentation time, in ticks */ SKL_MP4_MAP *Map; /**< Auxiliary informations, for the analyzer. */ void *Data; /**< (Opaque) Any data pertaining to the analyzer */ /** @internal helper function */ void Set_Data(void *d) const { ((SKL_MP4_PIC*)this)->Data = d; }}; /** proxies */ /** @internal signatures for easy cast while importing from .dll */typedef SKL_MP4_ENC *(*SKL_MP4_NEW_ENC)();typedef void (*SKL_MP4_DELETE_ENC)(SKL_MP4_ENC *);typedef SKL_MP4_DEC *(*SKL_MP4_NEW_DEC)();typedef void (*SKL_MP4_DELETE_DEC)(SKL_MP4_DEC *); /** Factory for instantiating SKL_MP4_ENC class */extern SKL_EXPORT SKL_MP4_ENC *Skl_MP4_New_Encoder(); /** Factory for deleting SKL_MP4_ENC class instances */extern SKL_EXPORT void Skl_MP4_Delete_Encoder(SKL_MP4_ENC *); /** Factory for instantiating SKL_MP4_DEC class */extern SKL_EXPORT SKL_MP4_DEC *Skl_MP4_New_Decoder(); /** Factory for deleting SKL_MP4_DEC class instances */extern SKL_EXPORT void Skl_MP4_Delete_Decoder(SKL_MP4_DEC *);}//////////////////////////////////////////////////////////// SKL_MP4_DEC : decoder class////////////////////////////////////////////////////////// /** @class SKL_MP4_DEC SKL_MP4_DEC is the main decoding class. All methods are virtual, just like the COM-object paradigm. It eases the dynamic class loading (just map the proxy's symbol from dll, the vtbl will come along). */struct SKL_MP4_DEC{ protected: SKL_MP4_DEC(); /**< protected constructor. use Skl_MP4_New_Decoder() */ virtual ~SKL_MP4_DEC(); /**< protected destructor. use Skl_MP4_Delete_Decoder() */ friend SKL_MP4_DEC *Skl_MP4_New_Decoder(); friend void Skl_MP4_Delete_Decoder(SKL_MP4_DEC*); public: /** This function decodes 'Len' bytes of bitstream pointed to by 'Buf'. It returns the number of bytes consumed from the bitstream. For safety, it is required that the buffer contains at least a full chunk of VOP data (start code 0x000001b6) within it boundary. This is to ensure complete parsing of syntax elements.<p> If the 'Len' argument is 0, the last decoded frame will be removed from the decoder and made available for Consume_Frame(). Keep in mind that the decoder has a latency of one frame, so that inbetween incoming B-VOP can be decoded using future prediction. Hence, call with Len=0 should be performed at the end of the bitstream decoding, when you are sure that no frame are left to decode. <p> @param Buf the bitstream's bytes @param Len the number of bytes available. If equal to zero, the very last residual frame, will be made available. */ virtual int Decode(const SKL_BYTE *Buf, int Len) = 0; /** This function is the equivalent of Decode(), for partial MPEG1/2 decoding function. It only supports FRAME pic struct/4:2:0 format. You must call it when you are sure the bitstream is a MPEG1/2 one (no autodetection is available). @see Decode */ virtual int Decode_MPEG12(const SKL_BYTE *Buf, int Len) = 0; /** Returns the current frame's number (if available). @see Is_Frame_Ready @see Decode */ virtual int Get_Frame_Number() const = 0; /** Returns true if the current frame is finished decoding @see Decode */ virtual int Is_Frame_Ready() const = 0; /** Definitively retreive the last decoded frame. The data will remain valid until the next call to Decode() or Decode_MPEG12(). <b>Warning</b> : beware of the SKL_MP4_PIC data layout! @param Pic the structure to be filled with last frame's data. @see Decode @see SKL_MP4_PIC */ virtual void Consume_Frame(SKL_MP4_PIC *Pic) = 0; /** Set a new memory pool to use internally for subsequent memory allocation. Warning: it should preferably be called at start-up only, to ensure that cycles of New()/Delete() are performed on the same memory pool. @param Mem The memory pool to use. If equal to 0 (default), the C++ heap will be used. @return This function will return the previous memory manager. @see SKL_MEM_I */ virtual SKL_MEM_I *Set_Memory_Manager(SKL_MEM_I *Mem=0) = 0; /** Sets the CPU feature to use. @param Cpu : see the enum description for a list of available cpu features. */ virtual void Set_CPU(SKL_CPU_FEATURE Cpu = SKL_CPU_DETECT) = 0; /** Set post-decoding hook function. @ see SKL_MP4_SLICER @param Slicer callback function to use @param Slicer_Data can be anything, and will be passed as is to the Slicer hook function. */ virtual void Set_Slicer(SKL_MP4_SLICER Slicer, SKL_ANY Slicer_Data=0) = 0; /** @internal Sets the internal debug level. */ virtual void Set_Debug_Level(int Level=0) = 0; /** @internal For debug only. Returns all the Y/U/V planes in a single, edged, frame @param Pic the structure filled with frame's pixels */ virtual void Get_All_Frames(SKL_MP4_PIC *Pic) const = 0; /** @internal unused for now. */ virtual int Ioctl(SKL_CST_STRING Param) = 0;};//////////////////////////////////////////////////////////// SKL_MP4_ENC : encoder class////////////////////////////////////////////////////////// /** @class SKL_MP4_ENC SKL_MP4_ENC is the main encoding class. It is responsible for the bitstream coding only (that is: enforcing the syntax). The motion estimation is performed by an external module (SKL_MP4_ANALYZER), and parameter exchange is done using Get_Param(). All methods are virtual, just like the COM-object paradigm. It eases the dynamic class loading (just map the proxy's symbol from dll, the vtbl will come along). @see SKL_MP4_ANALYZER. */struct SKL_MP4_ENC{ protected: SKL_MP4_ENC(); /**< protected constructor. Use Skl_MP4_New_Encoder() */ virtual ~SKL_MP4_ENC(); /**< protected destructor. use Skl_MP4_Delete_Encoder() */ friend SKL_MP4_ENC *Skl_MP4_New_Encoder(); friend void Skl_MP4_Delete_Encoder(SKL_MP4_ENC*); public: /** Set the dimensions of the next input frame. A SKL_MP4_PIC structure is returned, ready for holding fresh data.<p> <b>Warning</b> : beware of the SKL_MP4_PIC data layout! @param Width the width, in pixel, of the input picture. @param Height the height, in pixel, of the input picture. @return This functions returns a uninitialized picture structure SKL_MP4_PIC, ready to be filled with incoming YUV data. @see SKL_MP4_PIC */ virtual const SKL_MP4_PIC *Prepare_Next_Frame(int Width, int Height) = 0; /** Return the last input frame set up by previous call to Prepare_Next_Frame(). This data is only valid until next call to Encode() <b>Warning</b> : beware of the SKL_MP4_PIC data layout! @return Last available input frame. @see SKL_MP4_PIC */ virtual const SKL_MP4_PIC *Get_Next_Frame() const = 0; /** Return the last coded frame, if any. This data is only valid until next call to Encode() <b>Warning</b> : beware of the SKL_MP4_PIC data layout! @return Last coded frame. @see SKL_MP4_PIC */ virtual const SKL_MP4_PIC *Get_Last_Coded_Frame() const = 0; /** Encode next input frame, as set up by call to Prepare_Next_Frame. @return the number of coded bytes available for writting in the buffer is returned. @see Get_Bits, Get_Bits_Length, Prepare_Next_Frame. */ virtual int Encode() = 0; /** Mark the end of sequence in the bitstream. Returns number of coded bytes. @see Get_Bits, Get_Bits_Length. */ virtual int Finish_Encoding() = 0; /** Returns the pointer to the coded bytes after last call to Encode(). This pointer and its content is only valid until next call to Encode(). The number of bytes is available using the Get_Bits_Length() member function. @see Encode, Get_Bits_Length */ virtual const SKL_BYTE *Get_Bits() const = 0; /** Returns the number of coded bytes after last call to Encode(). This value is only valid until next call to Encode(). The pointer to these bytes is available using the Get_Bits() member function. @see Encode, Get_Bits */ virtual int Get_Bits_Length() const = 0; /** Set a new memory pool to use internally for subsequent memory allocation. Warning: it should preferably be called at start-up only, to ensure that cycles of New()/Delete() are performed on the same memory pool. @param Mem The memory pool to use. If equal to 0 (default), the C++ heap will be used. @return This function will return the previous memory manager.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -