Exemplo n.º 1
0
	CReader& CCardLayer::getReader(const std::string & csReaderName)
	{
		// Do an SCardEstablishContext() if not done yet
		m_oPCSC.EstablishContext();

		CReader *pRet = NULL;

		// If csReaderName == "", take the default (= first found) reader name
		const std::string * pcsReaderName = (csReaderName.size() == 0) ? GetDefaultReader() : &csReaderName;
		if (pcsReaderName->size() == 0)
		{
			throw CMWEXCEPTION(EIDMW_ERR_NO_READER);
		}
		// First check if the reader doesn't exist already
		for (unsigned long i = 0; i < MAX_READERS; i++)
		{
			if (m_tpReaders[i] != NULL)
			{
				if (m_tpReaders[i]->GetReaderName() == *pcsReaderName)
				{
					pRet = m_tpReaders[i];
					break;
				}
			}
		}

		// No CReader object for this readername -> make one
		if (pRet == NULL)
		{
			for (unsigned long i = 0; i < MAX_READERS; i++)
			{
				if (m_tpReaders[i] == NULL)
				{
					pRet = new CReader(*pcsReaderName, &m_oPCSC);
					m_tpReaders[i] = pRet;
					break;
				}
			}
		}
		// No room in m_tpReaders -> throw an exception
		if (pRet == NULL)
		{
			throw CMWEXCEPTION(EIDMW_ERR_LIMIT);
		}

		return *pRet;
	}
Exemplo n.º 2
0
void *ipcMediaSendThread(void *p)
{
	void *pRdd;
	BYTE *pBuff;
	DWORD timestamp=0, media_type, size, isKeyFrame;
	DWORD tick0;
	MYSESSDATA *pMyData = (MYSESSDATA*)p;
	READER *pRd = GetDefaultReader();

	//read  the  record
	if(pRd->BeginReading("test.v264", &pRdd) != 0)
	{
		printf("cann't open file: test.v264\n");
		return NULL;
	}	

	pBuff = (BYTE*)malloc(300*1024);
	tick0 = PA_GetTickCount();
	while(pMyData->bRunPb)
	{
		size = 300*1024;
		int err = pRd->Read(&media_type, &timestamp, pBuff, &size, &isKeyFrame, pRdd);
		if(err == 0)
		{
			//dbg_msg("mt: %d, ts: %d\n", media_type, timestamp);
			while(PA_GetTickCount() - tick0 < timestamp)
				PA_Sleep(1); //sleep 1 ms
			{
				int chno, snd = 0;
				if(media_type == MEDIATYPE_VIDEO_H264)
				{
					chno = LIVE_VIDEO_CHNO;//0
					snd = (pMyData->dwMediaMask & 1);
				}
				else
				{
					chno = LIVE_AUDIO_CHNO;//1
					snd = (pMyData->dwMediaMask & 2);
				}
				if(snd)//send the message
				{
					err = P2pMplxSendMediaFrame(pMyData->hSess, chno, media_type, timestamp, isKeyFrame, pBuff, size, 0);
					if(err) fprintf(stderr, "P2pMplxSendMediaFrame: %d\n", err);
				}
			}
		}
		else if(err == E_EOF)
		{
			pRd->SeekKeyFrame(0, pRdd);
			tick0 = PA_GetTickCount();
			PA_Sleep(40);
		}
		else
		{
			printf("read file error: %u\n", err);
			break;
		}
	}
	OurReader.EndReading(pRdd);
	free(pBuff);
	return NULL;
}