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

📄 playerdlg.cpp

📁 播放H.264压缩算法文件(C++源程序)
💻 CPP
📖 第 1 页 / 共 5 页
字号:
////////////////////////////////////////////////////////////////////////////////
//File:PlayerDlg.cpp 
/////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Player.h"
#include "PlayerDlg.h"
#include "mmsystem.h"
#include "vkey.h"
#include "Hikplaympeg4.h"
#include "info.h"
#include "cutfile.h"

#include "AVIFMt.H"
#include "WRIFF.H"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BOOL g_bCapPic=FALSE;				
UINT WM_FILE_END=WM_USER +33;		//User message. Be posted when the file is end.
UINT WM_ENC_CHANGE=WM_USER +100; 
UINT PLAY_TIMER	=1;					//TIMER ID;
UINT PORT=0;	//uesed port;can be from 0 to 15;

					
#define WRITE_REC_LIST

#define WRITE_INDEX

#define ALIGN_VIDEO_FRAMES

//////////////////////////////////////////////////////////////////////////////

#define FORMAT_CIF        //If Want to Convert 4cif or qcif Format to AVI File,
                           //Please Redefine this MACRO

#ifdef FORMAT_CIF          //CIF Format
#define MAX_FRAMES 13980   //If the Converted Frame Number  are Larger than MAX_FRAMES
#endif                     // the AVI File will exceed 2G

#ifdef FORMAT_4CIF         //4CIF Format
#define MAX_FRAMES 3518   
#endif

#ifdef FORMAT_QCIF         //QCIF Format
#define MAX_FRAMES 55180
#endif

#ifdef FORMAT_2CIF         //2CIF Format
#define MAX_FRAMES 7035
#endif
///////////////////////////////////////////////////////////////////////////////

#define PADDING_GRANULARITY 2048

BOOL				 m_bConvert=FALSE;
CString				 szFileName;
BOOL				 m_bFirstWrite=FALSE;
BOOL				 m_bFirst=FALSE;
int                  frameNum=0;
char				 *yuvBuf;
riffFile			 *outFile;
long				 numFrames;
long				 frameWidth;
long				 frameHeight;
long				 fps;
long				 maxFrameSize;

int					 Y_PLANE_SIZE;
//int				 U4_PLANE_SIZE;
//int				 V4_PLANE_SIZE;
int					 U2_PLANE_SIZE;
int					 V2_PLANE_SIZE;

int					 inputFrameSize;
int					 outputFrameSize;
static int  pic=0;

#ifdef WRITE_INDEX
AVIINDEXENTRY		 indexes[MAX_FRAMES];
long				 moviOffset;
#endif // WRITE_INDEX
long				 firstFrameOffset;
//#define _FILE_POS
//#define _TEST_CALLBACK			//if defined only decode,and not display!
//#define WAVE_ADJ					//if defined will addjust the wave value, else will set the voluem of the sound card; 

#define WIDTH				352		//Initialize width;
#define HEIGHT_PAL			288		//Initialize height;

#define APP_VERSION			4.3   //3.6	//player version;
//Define the controls size and position;
#define PLAY_SLIDER_UP		10
#define PLAY_SLIDER_HEIGHT	20
#define BUTTON_UP			4
#define BUTTON_SIZE			20
#define STATE_UP			10
#define STATE_HEIGHT		23
#define PANNEL_HEIGHT		(STATE_HEIGHT+STATE_UP+BUTTON_SIZE+BUTTON_UP+2*(PLAY_SLIDER_HEIGHT+PLAY_SLIDER_UP))
#define INTERVAL_SIZE		2
#define INTERVAL			5
#define LEFT_EDGE			5
#define SOUND_SLIDER_HEIGHT	15
#define SOUND_SLIDER_WIDTH  60

//File locate reference call back function;
void CALLBACK FileRefDone(DWORD nReserved,DWORD nUser);
//capture call back function;
void CALLBACK DisplayCBFun(long nPort,char * pBuf,long nSize,long nWidth,long nHeight,long nStamp,long nType,long nReceaved);
//wave call back funtion
void CALLBACK WaveCBFun(long nPort, char * pAudioBuf, long nSize, long nStamp, long nType, long nUser);
//Decode call back funtion;
void CALLBACK DecCBFun(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2);
void CALLBACK SourceBufFun(long nPort,DWORD nBufSize,DWORD dwUser,void*pContext);
// From v3.6; verify water mask;
void CALLBACK VerifyFun(long nPort, FRAME_POS * pFilePos, DWORD bIsVideo, DWORD nUser);
DWORD WINAPI InputStreamThread( LPVOID lpParameter);
void CALLBACK funEncChange(long nPort, long nUser); 
bool writeHeaders();
bool addFileToAVI(long frameNumber);
bool closeWriffFiles();
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}
BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	//显示版本信息;
	CString csVer;
	DWORD nVer=Hik_PlayM4_GetSdkVersion();
	DWORD nVersion=nVer&0x0000ffff;
	DWORD nBuild=(nVer>>16)&0x0000ffff;
	csVer.Format("HikPlayer ver is %.1f\n\rHikPlayM4.dll ver is %04x build is %04x",APP_VERSION,nVersion,nBuild);
	GetDlgItem(IDC_VER)->SetWindowText(csVer);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPlayerDlg dialog

CPlayerDlg::CPlayerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPlayerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPlayerDlg)
	m_strPlayStateText = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	
	m_hIcon =					AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_hPlayEnableIcon =			AfxGetApp()->LoadIcon(IDI_PLAY_ENABLE);
	m_hPlayDisableIcon =		AfxGetApp()->LoadIcon(IDI_PLAY_DISABLE);
	m_hPauseEnableIcon =		AfxGetApp()->LoadIcon(IDI_PAUSE_ENABLE);
	m_hPauseDisableIcon =		AfxGetApp()->LoadIcon(IDI_PAUSE_DISABLE);
	m_hStopEnableIcon =			AfxGetApp()->LoadIcon(IDI_STOP_ENABLE);
	m_hStopDisableIcon =		AfxGetApp()->LoadIcon(IDI_STOP_DISABLE);
	m_hSoundStartIcon=			AfxGetApp()->LoadIcon(IDI_SOUND_ENABLE);
	m_hSoundStopIcon=			AfxGetApp()->LoadIcon(IDI_SOUND_DISABLE);
	m_hGotoStartDisableIcon =	AfxGetApp()->LoadIcon(IDI_GOTOSTART_DISABLE);
	m_hGotoEndDisableIcon =		AfxGetApp()->LoadIcon(IDI_GOTOEND_DISABLE);
	m_hFastForwardDisableIcon = AfxGetApp()->LoadIcon(IDI_FASTFORWARD_DISABLE);
	m_hFastBackwardDisableIcon= AfxGetApp()->LoadIcon(IDI_FASTBACKWARD_DISABLE);
	m_hGotoStartEnableIcon =	AfxGetApp()->LoadIcon(IDI_GOTOSTART_ENABLE);
	m_hGotoEndEnableIcon =		AfxGetApp()->LoadIcon(IDI_GOTOEND_ENABLE);
	m_hFastForwardEnableIcon =	AfxGetApp()->LoadIcon(IDI_FASTFORWARD_ENABLE);
	m_hFastBackwardEnableIcon = AfxGetApp()->LoadIcon(IDI_FASTBACKWARD_ENABLE);
	m_bInitialized=FALSE;
	m_bPicQuality=		FALSE;
	m_nPrePlayPos=		0;
	m_bFileRefCreated=	FALSE;
	m_nDisplayType=		DISPLAY_NORMAL;
}

void CPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPlayerDlg)
	DDX_Control(pDX, IDC_SLIDERB, m_SliderB);
	DDX_Control(pDX, IDC_SLIDERS, m_SliderS);
	DDX_Control(pDX, IDC_SLIDERH, m_SliderH);
	DDX_Control(pDX, IDC_SLIDERC, m_SliderC);
	DDX_Control(pDX, IDC_SHOW, m_ShowFrame);
	DDX_Control(pDX, IDC_SOUND_SLIDER, m_SoundSlider);
	DDX_Control(pDX, IDC_PLAY_SLIDER, m_PlaySlider);
	DDX_Text(pDX, IDC_PLAYSTATETEXT, m_strPlayStateText);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPlayerDlg, CDialog)
	//{{AFX_MSG_MAP(CPlayerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	ON_BN_CLICKED(IDC_PAUSE, OnPause)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_GOTOSTART, OnGotoStart)
	ON_BN_CLICKED(IDC_SLOW, OnFastBackward)
	ON_BN_CLICKED(IDC_FAST, OnFastForward)
	ON_BN_CLICKED(IDC_GOTOEND, OnGotoEnd)
	ON_WM_DESTROY()
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_VIEW_FULLSCREEN, OnViewFullscreen)
	ON_WM_KEYDOWN()
	ON_WM_HSCROLL()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_CLOSE()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_SOUND, OnSound)
	ON_BN_CLICKED(IDC_STEP, OnStep)
	ON_WM_SIZE()
	ON_WM_DROPFILES()
	ON_BN_CLICKED(IDC_CAPPIC, OnCappic)
	ON_WM_SIZING()
	ON_COMMAND(ID_REPEAT, OnRepeat)
	ON_COMMAND(ID_QUALITY, OnQuality)
	ON_COMMAND(ID_VIEW_ZOOM_100, OnViewZoom100)
	ON_COMMAND(ID_VIEW_ZOOM_200, OnViewZoom200)
	ON_COMMAND(ID_VIEW_ZOOM_50, OnViewZoom50)
	ON_WM_WINDOWPOSCHANGED()
	ON_COMMAND(ID_STREAM_TYPE, OnStreamType)
	ON_BN_CLICKED(IDC_STEPBACK, OnStepback)
	ON_WM_MOVE()
	ON_COMMAND(ID_INFO, OnInfo)
	ON_COMMAND(ID_SEEK, OnSeek)
	ON_COMMAND(ID_CUT_FILE, OnCutFile)
	ON_COMMAND(ID_THROW0, OnThrow0)
	ON_COMMAND(ID_THROW1, OnThrow1)
	ON_COMMAND(ID_THROW2, OnThrow2)
	ON_COMMAND(ID_DISNORMAL, OnDisnormal)
	ON_COMMAND(ID_DISQUARTER, OnDisquarter)
	ON_COMMAND(ID_SETDISPLAY, OnSetDisplay)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_COMMAND(ID_TIMER1, OnTimer1)
	ON_COMMAND(ID_TIMER2, OnTimer2)
	ON_COMMAND(ID_RESET_BUF, OnResetBuf)
	ON_COMMAND(ID_CONVERT, OnConvertToAVI)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_FILE_END, PlayMessage)
	ON_MESSAGE(WM_ENC_CHANGE,EncChangeMessage)
	ON_MESSAGE(WM_SEEKOK, SeekOk)
	ON_MESSAGE(WM_DISPLAY_OK, DisplayOk)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPlayerDlg message handlers

#define COLOR_DEFAULT 64 //brightness, contrast, saturation, hue default value(0~128);

BOOL CPlayerDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_pMainMenu = GetMenu();
	if(m_pMainMenu == NULL)
	{
		TRACE("GetMenu is Error!");
		return FALSE;
	}
	m_nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
	m_nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
	// Init Play Slider
	m_dwPlaySliderMax = 200;
	m_PlaySlider.SetRangeMin(0);
	m_PlaySlider.SetRangeMax(m_dwPlaySliderMax);
	m_PlaySlider.SetPos(0);
	m_PlaySlider.SetLineSize(1);
	m_PlaySlider.SetPageSize(5);
	m_PlaySlider.EnableWindow(FALSE);
	
	//Init color slider
	m_SliderB.SetRange(0, 128);
	m_SliderB.SetPos(COLOR_DEFAULT);
	m_SliderC.SetRange(0, 128);
	m_SliderC.SetPos(COLOR_DEFAULT);
	m_SliderS.SetRange(0, 128);
	m_SliderS.SetPos(COLOR_DEFAULT);
	m_SliderH.SetRange(0, 128);
	m_SliderH.SetPos(COLOR_DEFAULT);

	// Init Sound Slider
#ifdef WAVE_ADJ
	m_SoundSlider.SetRangeMin(MIN_WAVE_COEF);
	m_SoundSlider.SetRangeMax(MAX_WAVE_COEF);
	m_SoundSlider.SetPos(0);
#else
	m_SoundSlider.SetRangeMin(0);
	m_SoundSlider.SetRangeMax(0xffff-1);
	m_SoundSlider.SetPos(0xffff>>1);
#endif

	m_SoundSlider.SetLineSize(1);
	m_SoundSlider.SetPageSize(5);
	m_SoundSlider.EnableWindow(FALSE);


	Hik_PlayM4_SetVolume(PORT,m_SoundSlider.GetPos());

	// init button;
	CButton *pButton;

	pButton = (CButton *)GetDlgItem(IDC_PLAY);
	pButton->SetIcon(m_hPlayDisableIcon);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_PAUSE);
	pButton->SetIcon(m_hPauseDisableIcon);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_STOP);
	pButton->SetIcon(m_hStopDisableIcon);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_GOTOSTART);
	pButton->SetIcon(m_hGotoStartDisableIcon);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_GOTOEND);
	pButton->SetIcon(m_hGotoEndDisableIcon);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_FAST);
	pButton->SetIcon(m_hFastForwardDisableIcon);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_SLOW);
	pButton->SetIcon(m_hFastBackwardDisableIcon);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_SOUND);
	pButton->SetIcon(m_hSoundStopIcon);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_STEP);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_STEPBACK);
	pButton->EnableWindow(FALSE);

	pButton = (CButton *)GetDlgItem(IDC_CAPPIC);
	pButton->EnableWindow(FALSE);

	InitWindowSize(WIDTH,HEIGHT_PAL);
	m_bStartDraw=			FALSE;
	m_StartPoint.x=			0;
	m_StartPoint.y=			0;
	m_nTotalFrames=			0;
	m_nMaxFileTime=			0;
	m_bSound=				FALSE;
	m_bOpen=				FALSE;
	m_bPlaying=				FALSE;
	m_bPaused=				FALSE;
	m_bFullScreen=			FALSE;
	m_bFastForwardPlay=		FALSE;
	m_bRepeatPlay=			FALSE;
	m_strPlayStateText=		"Ready";
	m_bPause=				FALSE;
	m_nTotalHour=			0;
	m_nTotalMinute=			0;
	m_nTotalSecond=			0;
	m_nTotalFrames=			0;
	m_bStreamType=			FALSE;

	m_pSeek=				new CSeek(this);
	m_pDisplayRegion=		new CDisplayRect(this);
	//set the capture picture call back function;
	Hik_PlayM4_SetDisplayCallBack(PORT,DisplayCBFun);
	//set the wave audio call back funtion;
	Hik_PlayM4_SetAudioCallBack(PORT,WaveCBFun, (long)this);
	m_BlackBmp.LoadBitmap(IDB_BLACK);
	m_OverlayBmp.LoadBitmap(IDB_OVERLAY);
	m_HikvisionBmp.LoadBitmap(IDB_HIKVISION);
	Hik_PlayM4_SetEncTypeChangeCallBack(PORT,funEncChange,(long)this);
#if (WINVER > 0x0400)
	//If do not support multi monitor,may not call!

⌨️ 快捷键说明

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