?? serverdlg.cpp
字號(hào):
// ServerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Server.h"
#include "ServerDlg.h"
#include "CMediaInfo.h"
#include "GlobalDefs.h"
#include "CServerSocket.h"
#include "UFilterUtils.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CServerDlg dialog
CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CServerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CServerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
mSliderTimer=0;
mGraph=NULL;
mMediaControl=NULL;
mFile=NULL;
mSplitter=NULL;
mSeeking=NULL;
mState=STOP;
mInfinitePin=NULL;
mTempInfinitePin=NULL;
mAudioInfinitePin=NULL;
mVideoDecom=NULL;
mAudioDecom=NULL;
mVideoRenderer=NULL;
mAudioRenderer=NULL;
mVideoSender=NULL;
mAudioSender=NULL;
}
void CServerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CServerDlg)
DDX_Control(pDX, IDC_PROGRESS, mProgress);
DDX_Control(pDX, IDC_VIDEOWINDOW, mVideoWnd);
DDX_Control(pDX, IDC_LIST_PROGRAM, mProgramListCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CServerDlg, CDialog)
//{{AFX_MSG_MAP(CServerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
ON_MESSAGE(WM_ModifyFilterGraph, OnModifyFilterGraph)
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_HSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CServerDlg message handlers
BOOL CServerDlg::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);
mProgramListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
mProgramListCtrl.InsertColumn(0, "File", LVCFMT_CENTER, 120);
mProgramListCtrl.InsertColumn(1, "Type", LVCFMT_CENTER, 80);
mProgramListCtrl.InsertColumn(2, "Size", LVCFMT_CENTER, 80);
mProgramListCtrl.InsertColumn(3, "PID", LVCFMT_CENTER, 60);// Set small icon
// TODO: Add extra initialization here
mControll.AddMsgReceiver(this);
BOOL pass=mControll.Create();
if(pass)
{
pass=mControll.StartListening();
if(!pass)
{
MessageBox("Fail to create controll listener");
}
}
mVideo.SetListenPort(SERVER_VIDEO_PORT);
pass=mVideo.Create();
if(pass)
{
pass=mVideo.StartListening();
if(!pass)
{
MessageBox("Fail to create video listener");
}
}
mAudio.SetListenPort(SERVER_AUDIO_PORT);
pass=mAudio.Create();
if(pass)
{
pass=mAudio.StartListening();
if(!pass)
{
MessageBox("Fail to create audio listener");
}
}
mProgress.SetRange(0,1000);
mProgress.SetPos(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CServerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CServerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CServerDlg::OnBtnAdd()
{
CMediaInfo media;
BOOL isSourceOK = FALSE;
CString strFilter = "AVI Files (*.avi)|*.avi|";
strFilter += "MPEG Files (*.mpg;*.mpeg)|*.mpg;*.mpeg|";
strFilter += "REAL Files (*.rm;*rmvb)|*.rm;*rmvb|";
strFilter += "All Files (*.*)|*.*|";
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, strFilter, NULL);
if (IDOK == dlg.DoModal())
{
isSourceOK = media.SetFilePath(dlg.GetPathName());
}
if (isSourceOK)
{
int count = mProgramListCtrl.GetItemCount();
mProgramListCtrl.InsertItem(count, media.mFilePath);
CString str;
switch (media.mFileType)
{
case FT_MPEG1:
str = "MPEG1";
break;
case FT_MPEG2:
str = "MPEG2";
break;
case FT_AVI:
str = "AVI";
break;
case FT_OGG:
str = "OGG";
break;
case FT_MP3:
str = "MP3";
break;
case FT_REAL:
str = "REAL";
break;
default:
str = "Unknown";
break;
}
mProgramListCtrl.SetItemText(count, 1, str);
str.Format("%.3fM", media.mFileSize / 1024. / 1024.);
mProgramListCtrl.SetItemText(count, 2, str);
media.SetProgramId(mPin);
mPin++;
str.Format("%d", media.mProgramId);
mProgramListCtrl.SetItemText(count, 3, str);
mPrgrmList.AddTail(media);
}
}
void CServerDlg::OnBtnDelete()
{
int index = mProgramListCtrl.GetNextItem(-1, LVNI_SELECTED);
if (index >= 0)
{
CString filename = mProgramListCtrl.GetItemText(index, 0);
POSITION pos = mPrgrmList.GetHeadPosition();
while (pos)
{
POSITION previous = pos;
CMediaInfo media = mPrgrmList.GetNext(pos);
if (filename.CompareNoCase(media.mFilePath) == 0)
{
mPrgrmList.RemoveAt(previous);
break;
}
}
mProgramListCtrl.DeleteItem(index);
}
}
bool CServerDlg::ReceiveMessage(MessageT inMessage,
void * ioParam,
void * ioParam2)
{
if (inMessage == msg_CommandReceived)
{
ProcessCommand(ioParam);
return true;
}
else if(inMessage==msg_NewSocketAccepted)
{
mControll.StartReceiving();
}
return CMsgReceiver::ReceiveMessage(inMessage, ioParam, ioParam2);
}
void CServerDlg::ProcessCommand(void * inCommand)
{
long * pCmd = (long *) inCommand;
switch (ntohl(*pCmd))
{
case Cmd_RequestTCPDisconnect:
{
mControll.DeleteAccepted();
}
break;
case Cmd_RequestProgramList:
SendProgramList();
break;
case Cmd_RequestPlay:
{
{
pCmd++;
Media_Control * pData = (Media_Control *) pCmd;
pData->my_ntoh();
POSITION pos = mPrgrmList.GetHeadPosition();
while (pos)
{
CMediaInfo info = mPrgrmList.GetNext(pos);
if (info.mProgramId == pData->program_id)
{
mPlayingMedia=info;
Deactivate();
PostMessage(WM_ModifyFilterGraph,TRUE);
break;
}
}
}
}
break;
case Cmd_RequestPause:
{
if(mMediaControl)
{
mMediaControl->Pause();
mState=PAUSE;
}
}
break;
case Cmd_RequestResume:
{
if(mMediaControl)
{
mMediaControl->Run();
mState=PLAY;
}
}
break;
case Cmd_SetProgress:
{
pCmd++;
Media_Progress * pData = (Media_Progress *) pCmd;
pData->my_ntoh();
mProgress.SetPos(pData->program_Progress);
double duration=1;
GetDuration(&duration);
double pos =duration*mProgress.GetPos()/1000.;
SetCurrentPosition(pos);
}
break;
case Cmd_RequestStop:
Deactivate();
break;
default:
break;
}
}
void CServerDlg::SendProgramList(void)
{
char buffer[MAX_COMMAND_SIZE];
long len = sizeof(Net_Command) + sizeof(Program_List);
long * pCmd = (long *) buffer;
*pCmd = Cmd_ProgramList;
*pCmd = htonl(*pCmd);
pCmd++;
Program_List * pData = (Program_List *) pCmd;
POSITION pos = mPrgrmList.GetHeadPosition();
while (pos)
{
CMediaInfo info = mPrgrmList.GetNext(pos);
info.CopyTo(pData);
pData->my_hton();
mControll.Send(buffer, len);
}
}
LRESULT CServerDlg::OnModifyFilterGraph(WPARAM inWParam, LPARAM inLParam)
{
if (inWParam)
{
Activate();
}
else
{
Deactivate();
}
return 0;
}
BOOL CServerDlg::Activate()
{
Deactivate();
BOOL pass=CreateGraph();
if(pass)
{
if(mPlayingMedia.mFileType==FT_AVI)
pass=CreateAVIFilters();
else if(mPlayingMedia.mFileType==FT_REAL)
pass=CreateREALFilters();
else if(mPlayingMedia.mFileType==FT_OGG)
pass=CreateOGGFilters();
else if(mPlayingMedia.mFileType==FT_MPEG1)
pass=CreateMPEGFilters();
}
if(pass)
{
pass=AfterBuildGraph();
}
if(!pass)
{
SendSimpleCommand(Cmd_Error);
Deactivate();
}
return pass;
}
BOOL CServerDlg::CreateGraph()
{
if (!mGraph)
{
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -