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

📄 global_old.h

📁 mpeg2 decoder filter过滤服务端
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */

/*
 * Disclaimer of Warranty
 *
 * These software programs are available to the user without any license fee or
 * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
 * any and all warranties, whether express, implied, or statuary, including any
 * implied warranties or merchantability or of fitness for a particular
 * purpose.  In no event shall the copyright-holder be liable for any
 * incidental, punitive, or consequential damages of any kind whatsoever
 * arising from the use of these programs.
 *
 * This disclaimer of warranty extends to the user of these programs and user's
 * customers, employees, agents, transferees, successors, and assigns.
 *
 * The MPEG Software Simulation Group does not represent or warrant that the
 * programs furnished hereunder are free of infringement of any third-party
 * patents.
 *
 * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
 * are subject to royalty fees to patent holders.  Many of these patents are
 * general enough such that they are unavoidable regardless of implementation
 * design.
 *
 */

#include <windows.h>
//#include <commctrl.h>
#include <stdio.h>
//#include <ddraw.h>
//#include <vfw.h>
//#include <winreg.h>
//#include <direct.h>
#include <io.h>
//#include <fcntl.h>
//#include "resource.h"

/* code definition */
#define PICTURE_START_CODE			0x100
#define SLICE_START_CODE_MIN		0x101
#define SLICE_START_CODE_MAX		0x1AF
#define USER_DATA_START_CODE		0x1B2
#define SEQUENCE_HEADER_CODE		0x1B3
#define EXTENSION_START_CODE		0x1B5
#define SEQUENCE_END_CODE			0x1B7
#define GROUP_START_CODE			0x1B8

#define SYSTEM_END_CODE				0x1B9
#define PACK_START_CODE				0x1BA
#define SYSTEM_START_CODE			0x1BB

#define VIDEO_ELEMENTARY_STREAM		0x1E0

#define PRIVATE_STREAM_1			0x1BD
#define PRIVATE_STREAM_2			0x1BF
#define AUDIO_ELEMENTARY_STREAM_0	0x1C0
#define AUDIO_ELEMENTARY_STREAM_1	0x1C1
#define AUDIO_ELEMENTARY_STREAM_2	0x1C2
#define AUDIO_ELEMENTARY_STREAM_3	0x1C3
#define AUDIO_ELEMENTARY_STREAM_4	0x1C4
#define AUDIO_ELEMENTARY_STREAM_5	0x1C5
#define AUDIO_ELEMENTARY_STREAM_6	0x1C6
#define AUDIO_ELEMENTARY_STREAM_7	0x1C7

#define SUB_SUB						0x20
#define SUB_AC3						0x80
#define SUB_PCM						0xA0

/* extension start code IDs */
#define SEQUENCE_EXTENSION_ID					1
#define SEQUENCE_DISPLAY_EXTENSION_ID			2
#define QUANT_MATRIX_EXTENSION_ID				3
#define COPYRIGHT_EXTENSION_ID					4
#define PICTURE_DISPLAY_EXTENSION_ID			7
#define PICTURE_CODING_EXTENSION_ID				8

#define ZIG_ZAG									0
#define MB_WEIGHT								32
#define MB_CLASS4								64

#define I_TYPE			1
#define P_TYPE			2
#define B_TYPE			3

#define MACROBLOCK_INTRA				1
#define MACROBLOCK_PATTERN				2
#define MACROBLOCK_MOTION_BACKWARD		4
#define MACROBLOCK_MOTION_FORWARD		8
#define MACROBLOCK_QUANT				16

#define TOP_FIELD		1
#define BOTTOM_FIELD	2
#define FRAME_PICTURE	3

#define MC_FIELD		1
#define MC_FRAME		2
#define MC_16X8			2
#define MC_DMV			3

#define MV_FIELD		0
#define MV_FRAME		1

#define CHROMA420		1
#define CHROMA422		2
#define CHROMA444		3

#define BUFFER_SIZE				2048
#define MAX_FILE_NUMBER			256

#define STORE_RGB24		1
#define STORE_YUY2		2

#define IDCT_MMX		1
#define	IDCT_FPU		2
#define IDCT_REF		3

#define LOCATE_INIT			0
#define LOCATE_FORWARD		1
#define LOCATE_BACKWARD		-1
#define LOCATE_SCROLL		2
#define LOCATE_RIP			3

#define CHANNEL				8

#define TRACK_NONE		15	// DANGEROUS!
#define TRACK_1			0
#define TRACK_2			1
#define TRACK_3			2
#define TRACK_4			3
#define TRACK_5			4
#define TRACK_6			5
#define TRACK_7			6
#define TRACK_8			7

#define FORMAT_AUTO			0
#define FORMAT_AC3			1
#define FORMAT_MPA			2
#define FORMAT_LPCM			3

#define AUDIO_DEMUXALL		0
#define AUDIO_DEMUXONE		1
#define AUDIO_DECODE		2

#define FO_NONE			0
#define FO_FILM			1
#define FO_SWAP			2

#define SRC_NONE		0
#define SRC_LOW			1
#define SRC_MID			2
#define SRC_HIGH		3
#define SRC_UHIGH		4

#define NORM_NONE		0
#define NORM_DYNAMIC	1
#define NORM_MAXIMUM	2

#define TRACK_PITCH		500

#define CRITICAL_ERROR_LEVEL	50

// Added by luqiming
#define ERROR_FLUSH       200
BOOL    gIsPictureDecoding;
BOOL    gIsEOS;    // Indicating no more data will be received


typedef struct {
	int			type;
//	int			file;
//	__int64		lba;
	int			pf;
	int			trf;
}	D2VData;
D2VData d2v_backward, d2v_forward, d2v_current;

//int CH[CHANNEL];
//short Sound_Max;

typedef struct {
	FILE					*file;
	char					filename[_MAX_PATH];
	int						rip;
	int						size;
	int						delay;
	unsigned int			mode;
	unsigned int			rate;
}	AC3Stream;
AC3Stream ac3[CHANNEL];

typedef struct {
	FILE					*file;
	int						rip;
	int						delay;
}	MPAStream;
MPAStream mpa[CHANNEL];

struct PCMStream {
	FILE					*file;
	char					filename[_MAX_PATH];
	int						rip;
	int						size;
	int						delay;
}	pcm;

struct PROCESS {
	__int64					length[MAX_FILE_NUMBER];
	__int64					total;
	__int64					run;
	__int64					start;
	__int64					end;
	int						trackleft;
	int						trackright;
	int						locate;
	int						startfile;
	__int64					startloc;
	int						endfile;
	__int64					endloc;
	int						file;
	__int64					lba;
	int						leftfile;
	__int64					leftlba;
	int						rightfile;
	__int64					rightlba;
	unsigned int			op;
	unsigned int			ed;
	unsigned int			elapsed;
	unsigned int			remain;
	float					percent;
}	process;

struct CPU {
	BOOL					mmx;
	BOOL					amd;
	BOOL					sse;
}	cpu;

/* decoder operation control flags */
//int AVI_Flag;
int Check_Flag;
//int D2V_Flag;
//int DDOverlay_Flag;
//int Display_Flag;
int Fault_Flag;
//int File_Flag;
//int File_Limit;
int FO_Flag;  // Field operation
int iDCT_Flag;
int Luminance_Flag;
//int Pause_Flag;
int Rip_Flag;
int Scale_Flag;
//int Statistics_Flag;
int Stop_Flag;
int Store_Flag;  // Store RGB24 or YUY2
int SystemStream_Flag;


BITMAPINFOHEADER birgb;
LPBITMAPINFOHEADER lpbirgb
#ifdef GLOBAL
= &birgb
#endif
;

BITMAPINFOHEADER biyuv;
LPBITMAPINFOHEADER lpbiyuv
#ifdef GLOBAL
= &biyuv
#endif
;

/* Global Value */
/*
FILE *D2VFile;
HWND hWnd, hDlg, hTrack, hLeftButton, hLeftArrow, hRightArrow, hRightButton;
char szInput[_MAX_PATH], szOutput[_MAX_PATH], szBuffer[_MAX_PATH], szBlank[1];
*/

unsigned char *backward_reference_frame[3], *forward_reference_frame[3];
unsigned char *auxframe[3], *current_frame[3];
unsigned char *u422, *v422, *u444, *v444, *rgb24, *yuy2, *lum;
__int64 YUVRGB_Scale, YUVRGB_Offset, LumOffsetMask, LumGainMask;

unsigned int hwidth, hwidthd8, dwidth, qwidth, hheightd2, qheightd2, nwidth;
int VideoPTS, AudioPTS;

int Edge_Width, Edge_Height;
unsigned short VOB_ID, CELL_ID;
unsigned int Frame_Number;

int Coded_Picture_Width, Coded_Picture_Height, Chroma_Width, Chroma_Height;
int block_count, Second_Field;
int horizontal_size, vertical_size, mb_width, mb_height;

float frame_rate, Frame_Rate;
int Video_Type, FILM_Purity, NTSC_Purity, Bitrate_Meter;

//int Infile[MAX_FILE_NUMBER];
//char Infilename[MAX_FILE_NUMBER][_MAX_PATH];

int intra_quantizer_matrix[64];
int non_intra_quantizer_matrix[64];
int chroma_intra_quantizer_matrix[64];
int chroma_non_intra_quantizer_matrix[64];

int load_intra_quantizer_matrix;
int load_non_intra_quantizer_matrix;
int load_chroma_intra_quantizer_matrix;
int load_chroma_non_intra_quantizer_matrix;

int q_scale_type;
int alternate_scan;
int quantizer_scale;

short *block[8]
#ifdef GLOBAL
=
{
	0, 0, 0, 0, 0, 0, 0, 0
}
#endif
;
short *p_block[8]
#ifdef GLOBAL
=
{
	0, 0, 0, 0, 0, 0, 0, 0
}
#endif
;


/* ISO/IEC 13818-2 section 6.2.2.1:  sequence_header() */
int frame_rate_code;
int aspect_ratio_information;

/* ISO/IEC 13818-2 section 6.2.2.3:  sequence_extension() */
int progressive_sequence;
int chroma_format;

/* ISO/IEC 13818-2 section 6.2.3: picture_header() */
int picture_coding_type;
int temporal_reference;

/* ISO/IEC 13818-2 section 6.2.3.1: picture_coding_extension() header */
int f_code[2][2];
int picture_structure;
int frame_pred_frame_dct;
int progressive_frame;
int concealment_motion_vectors;
int intra_dc_precision;
int top_field_first;
int repeat_first_field;
int intra_vlc_format;

/* gethdr.c */
int Get_Hdr(void);
void next_start_code(void);
void sequence_header(void);
int slice_header(void);

/* getpic.c */
int Decode_Picture(void);

/* gui.cpp */
//void ThreadKill(void);
//void CheckDirectDraw(void);
//void ResizeWindow(int width, int height);

/* idct */
void MMX_IDCT(short *block);
void Initialize_FPU_IDCT(void);
void FPU_IDCT(short *block);
void Initialize_REF_IDCT(void);
void REF_IDCT(short *block);

/* motion.c */
void motion_vectors(int PMV[2][2][2], int dmvector[2], int motion_vertical_field_select[2][2], 
	int s, int motion_vector_count, int mv_format, int h_r_size, int v_r_size, int dmv, int mvscale);
void Dual_Prime_Arithmetic(int DMV[][2], int *dmvector, int mvx, int mvy);

/* mpeg2dec.c */
//DWORD WINAPI MPEG2Dec(PVOID pvoid);

/* norm.c */
//void Normalize(FILE *WaveIn, int WaveInPos, char *filename, FILE *WaveOut, int WaveOutPos, int size);

/* store.c */
void Write_Frame(unsigned char *src[], D2VData d2v, DWORD frame);
//void FinalDecodedOut(unsigned char * outBuffer);
int DetectVideoType(int frame, int rff);

/* wavefs44.c */
/*
void InitialSRC(void);
void Wavefs44(FILE *file, int size, unsigned char *buffer);
void EndSRC(FILE *file);
void Wavefs44File(int delay, int now, int total);
void EndWAV(FILE *file, int size);
void DownWAV(FILE *file);
BOOL CheckWAV(void);*/

unsigned char WAVHeader[44]
#ifdef GLOBAL
=
{
	0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00,
	0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20,
	0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
	0x80, 0xbb, 0x00, 0x00, 0x00, 0xee, 0x02, 0x00,
	0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61,
	0x00, 0x00, 0x00, 0x00
}
#endif
;

char *NormType[3]
#ifdef GLOBAL
=
{
	"", " drc", " max"
}
#endif
;

char *AC3Mode[8]
#ifdef GLOBAL
=
{
	"1+1", "1/0", "2/0", "3/0", "2/1", "3/1", "2/2", "3/2"
}
#endif
;

int AC3Rate[32]
#ifdef GLOBAL
=
{
	32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
	192, 224, 256, 320, 384, 448, 512, 576, 640,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}
#endif
;

unsigned char AC3Flush[768]
#ifdef GLOBAL
=
{
	0x0b, 0x77, 0xe3, 0x7a, 0x14, 0x40, 0x4b, 0x73, 
	0xf7, 0x2e, 0x0e, 0xff, 0xeb, 0xc7, 0x08, 0x08, 
	0x28, 0x60, 0x64, 0x1a, 0xc7, 0xcf, 0x9f, 0x3e, 
	0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 
	0xf9, 0xf3, 0xef, 0xf9, 0xd5, 0xf3, 0xe7, 0xcf, 
	0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 
	0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 
	0x7c, 0xf9, 0xf3, 0xef, 0xfe, 0x75, 0x7c, 0xf9, 
	0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 
	0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9,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0xb3, 0x7f, 0xd6, 0xe8, 0x7e, 0x21, 0x84, 0xbd, 
	0x69, 0x40, 0xf0, 0x45, 0x80, 0xd9, 0x06, 0x5d, 
	0x10, 0x66, 0xf2, 0x9f, 0xe4, 0x65, 0xa1, 0x29, 
	0xc8, 0x91, 0xfd, 0xd7, 0x08, 0xde, 0x35, 0xa6, 
	0x00, 0x02, 0x78, 0x00, 0x9c, 0xd4, 0x0e, 0xc6, 
	0x86, 0xc9, 0x2d, 0x3a, 0xf6, 0x87, 0x28, 0xae, 
	0xda, 0xbe, 0x71, 0x54, 0x24, 0x1e, 0x77, 0x5b, 
	0xc2, 0x58, 0xaa, 0xf3, 0xa6, 0x1a, 0x7a, 0x4b, 
	0xbe, 0x15, 0x57, 0x95, 0xfb, 0xf9, 0xb1, 0x00, 
	0x4e, 0x76, 0xf8, 0xbb, 0xa5, 0x3d, 0x9c, 0xf8, 
	0xf2, 0xfc, 0x0d, 0xe6, 0x23, 0x64, 0xbb, 0xb4, 
	0x2a, 0x25, 0x16, 0x94, 0xf5, 0xef, 0x8e, 0xb5, 
	0x76, 0x72, 0x93, 0x46, 0x9b, 0x5f, 0x95, 0x79, 

⌨️ 快捷键说明

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