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

📄 pg_defs.h

📁 这是DVD中伺服部分的核心代码
💻 H
字号:
/*****************************************************************************
******************************************************************************
**                                                                          **
**  Copyright (c) 2005-2006 Videon Central, Inc.                            **
**  All rights reserved.                                                    **
**                                                                          **
**  The computer program contained herein contains proprietary information  **
**  which is the property of Videon Central, Inc.  The program may be used  **
**  and/or copied only with the written permission of Videon Central, Inc.  **
**  or in accordance with the terms and conditions stipulated in the        **
**  agreement/contract under which the programs have been supplied.         **
**                                                                          **
******************************************************************************
*****************************************************************************/
/**
 * @file pg_defs.h
 *
 * $Revision: 1.6 $ 
 *
 * PG module defines and data structures
 *
 */

#ifndef PG_DEFS_H
#define PG_DEFS_H

#ifdef __cplusplus
extern "C" {
#endif

#include "vdvd_types.h"
#include "osapi.h"
#include "cStream.h"
#include "pg_api.h"
#include <directfb.h>


/* what to do about these?  they are local to file not external return codes */
#define PG_STILL_SCANNING_SC        0x00000400
#define PG_MORE_DATA                0x00000401
#define PG_WRAP_BUFFER              0x00000402
#define PG_STATUS_RLE_ERROR         0x00000403
#define PG_STATUS_DROPPED_UPDATE    0x00000404

/* spec -> ISO/IEC 13818-1: 1994(E) */
#define PRIVATE_STREAM_1_START_CODE     0x000001BD

/* mpeg related defines */
#define PTS_ONLY                        2
#define PTS_AND_DTS                     3
#define SIZE_START_CODE                 4
#define SIZE_PG_CODED_DATA_BUFFER       (0x400000) /* 4MB */

/* queue depth and priorities */
#define PG_PARSE_PRIORITY               OS_TASK_NORMAL_PRIORITY
#define PG_RENDER_PRIORITY              OS_TASK_HIGH_PRIORITY  // high??
#define PG_PARSE_STACK_SIZE             (16*1024)
#define PG_RENDER_STACK_SIZE            (16*1024)
#define PG_PARSE_Q_DEPTH                400
#define PG_RENDER_Q_DEPTH               8  /* max 8 PG PCS allowed at one time */
#define PG_MAX_ODS                      64
#define PG_MAX_PALETTES                 8
#define PG_MAX_PALETTE_COLORS           256
#define MAX_WINDOWS                     2
#define ODS_HEADER_SIZE                 14
#define ODS_HEADER_SIZE_NO_FRAGMENT     7
#define MAX_GRFX_WIDTH                  1920
#define MAX_GRFX_HEIGHT                 1080

/* these are all Stream sizes of the data types given, they are NOT the sizes
    of the structures we actually store, this allows us to "jump past" a struct
    once we have read it and not need single byte alignment on our data structures
    be careful parsing data and only use sizeof() when directly refering to a structure */
#define SIZE_PALETTE_ENTRY              5
#define SIZE_RGB_PIXEL                  3
#define SIZE_COMPOSITION_OBJECT         16
#define SIZE_CROPPING_RECTANGLE         8
#define SIZE_SEGMENT_DESCRIPTOR         3
#define SIZE_COMPOSITION_DESCRIPTOR     3
#define SIZE_VIDEO_DESCRIPTOR           5
#define SIZE_WINDOW                     9

/* segment types */
/* 00 - 0x13, 0x19 - 0x7F, 0x83-0xFF reserved */
#define PALETTE_DEFINITION              0x14
#define OBJECT_DEFINITION               0x15
#define PRESENTATION_COMPOSITION        0x16
#define WINDOW_DEFINITION               0x17
#define INTERACTIVE_COMPOSITION         0x18
#define END_OF_DISPLAY_SET              0x80
#define SUBTITLE_STREAM_1               0x81
#define SUBTITLE_STREAM_2               0x82

#define COMP_STATE_NORMAL               0
#define COMP_STATE_ACQUISITION_POINT    1
#define COMP_STATE_EPOCH_START          2
#define COMP_STATE_EPOCH_CONT           3

/* macros */
#define SWITCH_1(byte)                  (0x80 & byte)
#define SWITCH_2(byte)                  (0x40 & byte)
#define RLZERO(byte)                    (0x3f & byte)
#define RL3TO63(byte)                   (0x3f & byte)
#define RL64TO16K_TOP(byte)             (0x3f & byte)

#define FIRST_IN_SEQUENCE               0x80
#define LAST_IN_SEQUENCE                0x40

/* some bit masks for clarity */
#define BIT0                            0x01
#define BIT1                            0x02
#define BIT2                            0x04
#define BIT3                            0x08
#define BIT4                            0x10
#define BIT5                            0x20
#define BIT6                            0x40
#define BIT7                            0x80


/* info about the current pes packet we are processing */
typedef struct tag_PESHdrInfo
{
    ULONG PTS;                  /* Presentation Time Stamp (upper 32 bits of 33) */
    ULONG DTS;                  /* Decode Time Stamp (upper 32 bits of 33) */
    BYTE PTSDTSFlags;           /* some bits that determine if we have PTS or PTS and DTS or non */
    BYTE SegAligned;            /* segment is aligned (PES header) */
    ULONG PacketSize;           /* Size of the PES packet */
    USHORT PesHeaderLen;        /* length of the PES header */
    BYTE HeaderComplete;        /* is the PES header complete? */
    BYTE HeaderNeedBytes;       /* how many bytes we need to complete a PES header*/
    USHORT PesHdrIndex;         /* index into the PesHdrBuff, so we can see if we have enough data */
    BYTE PesHdrBuff[259];       /* 8 bits of pes header max length + 3 bytes from pes packet header */
    ULONG ESRemaining;          /* size of the ES data in the PES packet */
    BYTE StartCodeBuff[6];      /* temp buffer to store start code for across buffer startcode sync */
    BYTE StartCodeBuffSize;     /* index into start code buffer */

    /* reading into the ES data we need to store some data */
    BYTE NeedSegmentBytes;      /* this field is used on 0xffff sized packets to get data sizes for buffer allocations */
    BYTE SegmentTemp[ODS_HEADER_SIZE]; /* size of a segment header and fragment header for parsing 0xffff  */
    BYTE SegmentIndex;          /* index into the segment temp buffer */

} PES_HDR_INFO;

/* flags to shutdown or stop the Parse and Render tasks  */
typedef enum tag_Quit_Flags
{
    PG_FLAGS_RUN,
    PG_FLAGS_STOP,
    PG_FLAGS_EXIT,
    PG_FLAGS_MAX
} QUIT_FLAGS;


/* wait for a PTS */
typedef struct tag_PGWaitTime
{
    BYTE Enabled;   /* set enabled when waiting for call */
    ULONG WaitPTS;  /* wait till this PTS shows up */
} PG_WAIT_TIME;

/* a wait time, with a sem to block on */
typedef struct tag_PGWaitTimeSem
{
    PG_WAIT_TIME WaitTime;
    OS_SEM_ID WaitSem;  /* a semaphore to block on */
} PG_WAIT_TIME_SEM;

/* palette */
typedef struct tag_Palette
{
    /* palettes are static sized and always have 256 entries */
    BYTE PaletteVersion;
    DFBColor Colors[PG_MAX_PALETTE_COLORS];
    IDirectFBPalette *DFBPal;
} PALETTE;

/* segment descriptor */
typedef struct tag_SegmentDescriptor
{
    BYTE SegmentType;
    uint16 SegmentLength;
} SEGMENT_DESCRIPTOR;

/* sequence descriptor */
typedef struct tag_SequenceDescriptor
{
    BYTE FirstInSequenceFlag : 1;
    BYTE LastInSequenceFlag : 1;
    BYTE Reserved : 6;
} SEQUENCE_DESCRIPTOR;

/* object data */
typedef struct tag_ObjectData
{
    ULONG DataLength;
    USHORT Width;
    USHORT Height;
} OBJECT_DATA;

/* object defintion segment */
typedef struct tag_ObjectDefinitionSegment
{
    BYTE VersionNumber;
    SEQUENCE_DESCRIPTOR SeqDesc;
    OBJECT_DATA ObjData;
    BYTE InUse;
    IDirectFBSurface *SurfaceLUT8; /* a directFB surface to RLE decode into */
    int pitch; /* returned from directfb surface->lock() */
} OBJECT_DEFINITION_SEGMENT;

/* window */
typedef struct tag_PG_Window
{
    uint16 X;
    uint16 Y;
    uint16 Width;
    uint16 Height;
} PG_WINDOW;

/* cropping rectangle */
typedef struct tag_CroppingRectangle
{
    uint16 X;
    uint16 Y;
    uint16 Width;
    uint16 Height;
} CROPPING_RECTANGLE;

/* composition object */
typedef struct tag_CompositionObject
{
    uint16 ObjectIDRef;
    BYTE WindowIDRef;
    BYTE CroppedFlag : 1;
    BYTE ForcedOnFlag : 1;
    BYTE Reserved : 6;
    uint16 XPosition;
    uint16 YPosition;
    CROPPING_RECTANGLE Rect;
} COMPOSITION_OBJECT;

/* video descriptor */
typedef struct _tag_VideoDescriptor
{
    uint16 Width;
    uint16 Height;
    BYTE FrameRate : 4;
    BYTE Reserved : 4;
} VIDEO_DESCRIPTOR;

/* composition descriptor */
typedef struct tag_CompositionDescriptor
{
    uint16 CompositionNumber;
    BYTE CompositionState : 2;
    BYTE Reserved : 6;
} COMPOSITION_DESCRIPTOR;


/* window definition segment */
typedef struct tag_WindowDefintionSegment
{
    SEGMENT_DESCRIPTOR SegDesc;
    BYTE NumberOfWindows;
} WINDOW_DEFINITION_SEGMENT;


/* presentation composition segment */
typedef struct tag_PresentationCompositionSegment
{
    BOOLEAN fPCSShowing;
    BOOLEAN fPCSHasForced;
    VIDEO_DESCRIPTOR VideoDesc;
    COMPOSITION_DESCRIPTOR CompDesc;
    BYTE PaletteUpdateFlag; /* spec 1:7 we store in lowest bit bit0 */
    BYTE PaletteIDRef;
    BYTE NumCompositionObjects;
    COMPOSITION_OBJECT *CompObjs;
    ULONG PTSDisplayTime;
} PRESENTATION_COMPOSITION_SEGMENT;

/* message to the pg parse thread */
typedef struct tag_PG_PARSE_MSG
{
    ULONG PTS;
    ULONG DTS;
    BYTE PTS_DTS_Flags;
    BYTE *DataStart;
    ULONG DataLength;
    BYTE MultiPES;
} PG_PARSE_MSG;

/* messages to the render contain the PCS to render and some flags */
typedef struct tag_PG_RENDER_MSG
{
    PRESENTATION_COMPOSITION_SEGMENT *PCS;
    ULONG PTSRenderTime;  /* time we are waiting for to begin render of this PCS */
} PG_RENDER_MSG;

/* maintains handles to important DFB info */
typedef struct tag_PGDFB_INFO
{
    IDirectFB               *pDFBHandle;
    IDirectFBSurface        *PrimarySurface;
    IDirectFBSurfaceManager *SurfaceManager;
    IDirectFBDisplayLayer   *DispLayer;
    int                     ScreenWidth;
    int                     ScreenHeight;
} PGDFB_INFO;

/* 601 or 709 color space is used based on resolution of source content, SD=601 HD=709 */
typedef enum tag_PG_COLOR_SPACE
{
    REC_601,
    REC_709
} PG_COLOR_SPACE;

/* local state info for all of the PG module - holds handles and flags for the module */
typedef struct tag_PGInfo
{
    PG_STATE CurrentState;      /* one of the allowed state machine states */

    ULONG PESWritePtr;          /* our write ptr to the PGParseBuffer  */
    ULONG PESWriteStart;        /* our write ptr to the PGParseBuffer where a segment begins */
    BYTE* PGParseBuffer;        /* buffer to receive data from the decoder */

    BYTE SequenceDesc;          /* first or last in seqence flags, only used on multipes packets */
    BYTE CopyingPES;            /* we are in the middle of finishing a PES packet */
    BYTE CopyingMultiPES;       /* we are copying a multiple PES packet segment */
    BYTE fGotStartPtr;          /* flags if we got some data or not */
    PES_HDR_INFO CurPesInfo;    /* current state of the PES info structure */
    QUIT_FLAGS QuitFlags;       /* tell the PG threads to stop (but not exit) */
    OS_STATUS PGParseTask;      /* PGParse Thread handle */
    cStream *PGParseQ;          /* holds messages to the PGParse task */
    PVOID PGParseQPool;         /* holds messages to the PGParse task */
    OS_SEM_ID RenderLock;       /* sema access to renderer */
    OS_SEM_ID BlitLock;         /* sema access to flip/blit */
    OS_SEM_ID StateLock;         /* sema access to pgrun pgstop pgadddata */
    PG_WAIT_TIME_SEM ParseWait; /* a wait timer for the parse task */
    PG_WAIT_TIME_SEM RenderWait; /* a wait timer for rendering */
    OS_TIMER_ID PGFlipTimer;    /* call pggraphics flip in another task with this */
    BYTE *FrameBuffer;          /* pointer to the frame buffer */
    ULONG CurPTS;               /* the current PTS */
    PG_SHOW_HIDE ShowGraphics;  /* flag telling the renderer to show or hide it's display */
    BYTE StreamAcquired;        /* stream acquired by getting an epoch start, contiue or acq point */
    PG_RENDER_MSG *pPCSMessage; /* hold onto pcs message till EDS comes in */
    PGDFB_INFO DFBInfo;         /* holds needed directfb handles */
    PRESENTATION_COMPOSITION_SEGMENT *RenderPCS; /* current PCS for display */
    PRESENTATION_COMPOSITION_SEGMENT *ParserPCS; /* the current pcs in the parser */
    ULONG RLEHalfWidth;         /* decode images at half width */
    ULONG CoordsHalfWidth;      /* make output coordinates half sized in x direction, uses RLEHalfWidth */
    ULONG FrameDropping;        /* flag which gets the value of the env var for frame dropping */
    ULONG ParseReadPtr;         /* read pointer in parse buffer */
    PG_COLOR_SPACE ColorSpace;  /* the colorspace in use 601 or 709 */
} PGINFO;


typedef struct tag_PGStats
{
    ULONG Profiling;             /* profiling is enabled with this set to one */
    ULONG PGTotalCreateSurfaceTicks;
    ULONG PGTotalRLETicks;
    ULONG PGTotalBlitTicks;
    ULONG PGTotalFlipTicks;
    ULONG PGTotalAddDataTicks;
    ULONG PGTotalFrameDrops;
    ULONG PGTotalParseMsgDrops;
    ULONG PGTotalRLEFailures;
    ULONG PGPixelsDecoded;
} PGSTATS;

#ifdef __cplusplus
}
#endif


#endif /* PG_DEFS_H */

⌨️ 快捷键说明

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