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

📄 cmediasocketclient.cpp

📁 WINCE下的播放器
💻 CPP
字号:
// 
// CMediaSocketClient.cpp
// 

#include "stdafx.h"
#include "CMediaSocketClient.h"
#include "CDataAdmin.h"

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

//////////////////////////////////////////////////////////////////////////////
CMediaSocketClient::CMediaSocketClient()
{
	m_dwRecvCount   = 0;
	m_bGraphStarted = false;
	m_pDataList = NULL;
	m_hCountWnd = NULL;
	m_LocalFile = NULL;	
	
/*  //for debuging
    pFileName = "receive.mp3";
	WCHAR  szFile[MAX_PATH];
	MultiByteToWideChar(CP_ACP, 0, pFileName, -1, szFile, MAX_PATH);
	RETAILMSG(1,(TEXT(" szFile = %s\r\n"),szFile));
	m_LocalFile = new CFile(szFile, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
*/
}

CMediaSocketClient::~CMediaSocketClient()
{
	if (m_LocalFile)
	{
		m_LocalFile->Close();
		delete m_LocalFile;
		m_LocalFile = NULL;
	}
	m_pDataList = NULL;
}

void CMediaSocketClient::ReceivingLoop(void)
{
	int    nret     = 0;
	int    nMsgType = 0;
	int    nDataLen = 0;
	char   buff[sizeof(MSG_HEADER) + MPEG1_PACK_SIZE];

	while (m_bReceiving)
	{
		// Receive the message header
		while ((nret = Receive(buff, sizeof(MSG_HEADER))) == E_SOCKET_NOT_READY)
		{
			Sleep(100);
		}
		// When errors occur or socket closed, terminate this loop
		if (nret == E_SOCKET_FAIL || nret == E_SOCKET_CLOSE)
			break;

		// See what type the payload is...
		PMSG_HEADER  pMsg = (PMSG_HEADER) buff;
		nMsgType = pMsg->nMsgType;   // Payload type retrieved
		nDataLen = pMsg->nDataSize;  // Payload size retrieved
		// Continue to receive the payload
		if (nDataLen > 0)
		{
			while ((nret = Receive(buff, nDataLen)) == E_SOCKET_NOT_READY)
			{
				Sleep(100);
			}
			// When errors occur or socket closed, terminate this loop
			if (nret == E_SOCKET_FAIL || nret == E_SOCKET_CLOSE)
				break;
		}

		// Data processing
		switch (nMsgType)
		{
		case DATA_MEDIA: // Mpeg content data!!!
		
			// Write to file for debuging
/*			if (m_LocalFile)
			{
				if( nDataLen >= MPEG1_PACK_SIZE )
				{
					m_LocalFile->Write( buff, MPEG1_PACK_SIZE );
				}
				else
				{
					m_LocalFile->Write( buff, nDataLen );	
				}
			}
*/	
			// Add to buffer list for filter graph using
			if (m_pDataList)
			{
				PMPEG1_PACK pData = m_pDataList->GetPoolBuffer();
				if (pData == NULL && m_pDataList->GetListSize() < PACK_MAX_COUNT)
				{
					// Allocate more buffer
					pData = new MPEG1_PACK;
				}
				if (pData != NULL)
				{
					memcpy(pData, buff, nDataLen);
					m_pDataList->ReleasePoolBuffer(pData);
				}

				// Receive data pack counting...
				m_dwRecvCount++;
				if ((m_dwRecvCount >= PACK_INIT_COUNT) && 
					!m_bGraphStarted)
				{
					::SetEvent(m_pDataList->m_hBufEnough);
					m_bGraphStarted = true;
				}
//#ifdef _DEBUG
				if (m_hCountWnd != NULL)
				{
					char buff[15];
					_itoa(m_dwRecvCount, buff,10);
					::SendMessage(m_hCountWnd, WM_SETTEXT, 0, (LPARAM)buff);
				}
//#endif
			}
			break;

		case RECV_EXIT: // Exit this thread
			m_bReceiving = false;
			break;

		default:
			break;
		}
	}

	// If no more data receiving, flush data
	if (m_pDataList)
	{
		m_pDataList->SetFlushing();
	}
}

void CMediaSocketClient::SetRecvBuffer(CDataAdmin * inBuf)
{
	if (m_pDataList == NULL)
	{
		m_pDataList = inBuf;
	}
}

void CMediaSocketClient::SetCountWnd(HWND inWnd)
{
	m_hCountWnd = inWnd;
}

⌨️ 快捷键说明

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