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

📄 skl_mpg4.h

📁 从FFMPEG转换而来的H264解码程序,VC下编译..
💻 H
📖 第 1 页 / 共 3 页
字号:
/********************************************************
 * 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 analyzer
class  SKL_MEM_I;           // memory pool interface
struct SKL_MP4_PIC;         // visible YUV picture

typedef struct SKL_IMG_DSP SKL_IMG_DSP; // image helper funcs
typedef struct SKL_MB_DSP  SKL_MB_DSP;  // macroblock helper funcs
typedef struct SKL_GMC_DSP SKL_GMC_DSP; // GMC helper funcs
typedef 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    7

typedef 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 */

⌨️ 快捷键说明

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