📄 umc_frame_constructor.h
字号:
/*//////////////////////////////////////////////////////////////////////////////
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright(c) 2005-2007 Intel Corporation. All Rights Reserved.
//
*/
#ifndef __UMC_FRAME_CONSTRUCTOR_H__
#define __UMC_FRAME_CONSTRUCTOR_H__
#include "umc_media_buffer.h"
#include "umc_linked_list.h"
#include "umc_splitter.h"
namespace UMC
{
// this macro checks 3 bytes for being '0x000001'
#define IS_001(PTR) ((PTR)[0] == 0 && (PTR)[1] == 0 && (PTR)[2] == 1)
// this macro checks 4 bytes for being video start code
#define IS_CODE(PTR, CODE) (IS_001(PTR) && (PTR)[3] == (CODE))
// this macro checks 4 bytes for being one of 2 video start codes
#define IS_CODE_2(PTR, CODE1, CODE2) (IS_001(PTR) && ((PTR)[3] == (CODE1) || (PTR)[3] == (CODE2)))
// this macro checks 4 bytes for being one of 3 video start codes
#define IS_CODE_3(PTR, CODE1, CODE2, CODE3) (IS_001(PTR) && ((PTR)[3] == (CODE1) || (PTR)[3] == (CODE2) || (PTR)[3] == (CODE3)))
// this macro checks 4 bytes for being one of 4 video start codes
#define IS_CODE_4(PTR, CODE1, CODE2, CODE3, CODE4) (IS_001(PTR) && ((PTR)[3] == (CODE1) || (PTR)[3] == (CODE2) || (PTR)[3] == (CODE3) || (PTR)[3] == (CODE4)))
// this macro checks 4 bytes for being one of video start codes from interval
#define IS_CODE_INT(PTR, CODE_MIN, CODE_MAX) ((PTR)[0] == 0 && (PTR)[1] == 0 && (PTR)[2] == 1 && (PTR)[3] >= (CODE_MIN) && (PTR)[3] <= (CODE_MAX))
// this macro checks 4 bytes for being valid h264 video start code
#define IS_H264_CODE(PTR, CODE) ((PTR)[0] == 0 && (PTR)[1] == 0 && (PTR)[2] == 1 && ((PTR)[3] & 0x1f) == (CODE))
// macro for mp3 header parsing
#define MPEGA_HDR_VERSION(x) ((x & 0x80000) >> 19)
#define MPEGA_HDR_LAYER(x) (4 - ((x & 0x60000) >> 17))
#define MPEGA_HDR_ERRPROTECTION(x) ((x & 0x10000) >> 16)
#define MPEGA_HDR_BITRADEINDEX(x) ((x & 0x0f000) >> 12)
#define MPEGA_HDR_SAMPLINGFREQ(x) ((x & 0x00c00) >> 10)
#define MPEGA_HDR_PADDING(x) ((x & 0x00200) >> 9)
#define MPEGA_HDR_EXTENSION(x) ((x & 0x00100) >> 8)
#define MPEGA_HDR_MODE(x) ((x & 0x000c0) >> 6)
#define MPEGA_HDR_MODEEXT(x) ((x & 0x00030) >> 4)
#define MPEGA_HDR_COPYRIGHT(x) ((x & 0x00008) >> 3)
#define MPEGA_HDR_ORIGINAL(x) ((x & 0x00004) >> 2)
#define MPEGA_HDR_EMPH(x) ((x & 0x00003))
inline
Ipp32s CalcCurrentLevel(Ipp32s iStart, Ipp32s iEnd, Ipp32s iBufSize)
{
Ipp32s iCurrentLevel = iEnd - iStart;
return iCurrentLevel + ((iCurrentLevel >= 0) ? 0 : iBufSize);
}
inline
bool ArePTSEqual(Ipp64f dTime1, Ipp64f dTime2)
{
return 0 == (Ipp32s)(90000 * (dTime1 - dTime2));
}
// maps TrackType to AudioStreamType and VideoStreamType
Ipp32u ConvertTrackType(TrackType type);
// maps AudioStreamType to TrackType
TrackType ConvertAudioType(Ipp32u type);
// maps VideoStreamType to TrackType
TrackType ConvertVideoType(Ipp32u type);
struct TeletextStreamInfo : public StreamInfo
{
Ipp8u szLanguage[4];
Ipp8u uiType;
Ipp8u uiMagazineNumber;
Ipp8u uiPageNumber;
};
// extends TrackInfo for needs of mpeg2
// adds some utilities
struct Mpeg2TrackInfo : public TrackInfo
{
DYNAMIC_CAST_DECL(Mpeg2TrackInfo, TrackInfo)
// constructor
Mpeg2TrackInfo();
// copy track's info structure from another one including all pointers
Status CopyFrom(Mpeg2TrackInfo *pSrc);
// releases StreamInfo
void ReleaseStreamInfo(void);
// releases decoder specific info
void ReleaseDecSpecInfo(void);
// releases all pointers and resets fields
void ReleaseAll(void);
// allocates StreamInfo pointer, copies PID and stream type from parent object
Status Alloc(void);
// sets duration field (m_Type is requiered)
void SetDuration(Ipp64f dDuration);
// number of program that track belongs to
// 0 if not applied
Ipp32u m_uiProgNum;
// number of frames is currently stored in track buffer
// it decreaments after lock
Ipp32u m_uiFramesReady;
// number of track in order of its first frame ready
// -1 means that first frame isn't ready yet
Ipp32s m_iFirstFrameOrder;
};
class SplMediaData : public MediaData
{
DYNAMIC_CAST_DECL(SplMediaData, MediaData)
public:
// constructor
SplMediaData();
// sets absolute position
void SetAbsPos(Ipp64u uiAbsPos);
// returns absolute position
Ipp64u GetAbsPos(void);
protected:
// absolute position of sample (specified by data reader)
Ipp64u m_uiAbsPos;
};
struct FCSample
{
enum
{
STAMPS_APPLIED = 0x10,
PES_START = 0x20,
ACCESS_POINT = 0x30
};
// constructor
FCSample();
// resets sample
void Reset(void);
// copy from MediaData
void CopyFrom(MediaData &data, Ipp32s iOffset);
// copy to MediaData
void CopyTo(MediaData &data, Ipp8u *pBufBase);
// checks if position is enclosed
bool IsHit(Ipp32s iPos);
// sets frame type, returns previous
Ipp32u SetFrameType(Ipp32u uiType);
// returns frame type
Ipp32u GetFrameType(void);
// sets certain flag, returns its previous value
bool SetFlag(Ipp32u uiFlagMask, bool bNewFlag);
// returns certain flag
bool GetFlag(Ipp32u uiFlagMask);
// PTS of media sample
Ipp64f dPTS;
// DTS or media sample
Ipp64f dDTS;
// media sample size
Ipp32u uiSize;
// bits 0...2 - picture type (only for video)
// bit 3 - reserved
// bit 4 - is set if sample's timestamps are used (for input samples)
// bit 5 - indicates if access unit commence here
// bit 6 - indicates if access point commence here
Ipp32u uiFlags;
// absolute position of sample in stream
Ipp64u uiAbsPos;
// offset in buffer of first byte of sample
Ipp32s iBufOffset;
};
inline
void UpdateInputSample(FCSample &sample, Ipp32s iFrom, Ipp32s iTo)
{
Ipp32s iEndOffset = sample.iBufOffset + sample.uiSize;
if (sample.iBufOffset > iFrom)
sample.iBufOffset -= IPP_MIN(sample.iBufOffset, iTo) - iFrom;
if (iEndOffset > iFrom)
iEndOffset -= IPP_MIN(iEndOffset, iTo) - iFrom;
sample.uiSize = iEndOffset - sample.iBufOffset;
}
inline
void CutInterval(FCSample &sample1, FCSample &sample2, Ipp8u *pBuf, Ipp32s iFrom, Ipp32s iTo, Ipp32s iLastByte)
{
Ipp8u *pFrom = pBuf + iTo;
Ipp8u *pTo = pBuf + iFrom;
ippsCopy_8u(pFrom, pTo, iLastByte - iTo);
UpdateInputSample(sample1, iFrom, iTo);
UpdateInputSample(sample2, iFrom, iTo);
}
struct InnerListElement
{
InnerListElement(void);
InnerListElement(FCSample &rData);
FCSample m_data;
InnerListElement *pNext;
InnerListElement *pPrev;
};
// used for reordering at backward
class ReorderQueue : public LinkedList<InnerListElement>
{
public:
ReorderQueue(void);
Status Add(FCSample &rSample);
Status Add(FCSample &rSample, Ipp32s idx);
Status Remove(void);
Status Remove(Ipp32s idx);
Status First(FCSample &rSample);
Status Last(FCSample &rSample);
Status Next(FCSample &rSample);
Status Prev(FCSample &rSample);
Status Get(FCSample &rSample, Ipp32s idx);
FCSample *FirstBO(void);
FCSample *LastBO(void);
protected:
void AddToSuperList(InnerListElement *pAddedElem);
void RemoveFromSuperList(void);
InnerListElement *m_pSuperFirst;
InnerListElement *m_pSuperLast;
};
#define MAX_NUM_SPS_PARSETS 32
// represents all interesting fields of SPS NAL unit
struct FCH264SeqParSet
{
FCH264SeqParSet(void);
Ipp8u seq_parameter_set_id;
Ipp8u log2_max_pic_order_cnt_lsb;
Ipp8u log2_max_frame_num;
Ipp8u frame_mbs_only_flag;
Ipp8u pic_order_cnt_type;
Ipp8u delta_pic_order_always_zero_flag;
};
#define MAX_NUM_PPS_PARSETS 256
// represents all interesting fields of PPS NAL unit
struct FCH264PicParSet
{
FCH264PicParSet(void);
Ipp16u pic_parameter_set_id;
Ipp8u seq_parameter_set_id;
Ipp8u pic_order_present_flag;
};
// represents all interesting fields of slice header
struct FCH264SliceHeader
{
FCH264SliceHeader(void);
Ipp16u pic_parameter_set_id;
Ipp8u field_pic_flag;
Ipp8u bottom_field_flag;
Ipp32u frame_num;
Ipp32s slice_type;
Ipp32u pic_order_cnt_lsb;
Ipp32s delta_pic_order_cnt_bottom;
Ipp32s delta_pic_order_cnt[2];
Ipp8u nal_ref_idc;
Ipp8u idr_flag;
Ipp32u idr_pic_id;
};
// saves all encountered SPS and PPS units and 2 last slice headers
struct H264HeaderSet
{
H264HeaderSet(void);
FCH264SeqParSet m_SPS[MAX_NUM_SPS_PARSETS];
FCH264PicParSet m_PPS[MAX_NUM_PPS_PARSETS];
FCH264SliceHeader m_PrevSH;
FCH264SliceHeader m_LastSH;
Ipp32s iShCount;
bool bOneOfNALRefIdcEqualTo0;
bool bOneOfNALUnitTypeEqualTo5;
};
// object performs elementary bitstream operations
class BitstreamReader
{
public:
// Default constructor
BitstreamReader(void);
// Destructor
virtual ~BitstreamReader(void);
// Initialize bit stream reader
void Init(Ipp8u *pStream);
// Copy next bit
Ipp32u CopyBit(void);
// Get bit (move pointer)
Ipp32u GetBit(void);
// Get bits (move pointer)
Ipp32u GetBits(Ipp32s iNum);
// Skip bits (move pointer)
void SkipBits(Ipp32s iNum);
// Get current pointer
Ipp8u *Stream(void);
// Get unsigned integer Exp-Golomb-coded element (move pointer)
Ipp32u GetUE(void);
// Get signed integer Exp-Golomb-coded element (move pointer)
Ipp32s GetSE(void);
protected:
// Refresh pre-read bits
virtual void Refresh(void);
protected:
// pointer to source stream
Ipp8u *m_pSource;
// pre-read stream bits
Ipp32u m_nBits;
// amount of pre-read bits
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -