예제 #1
0
void NewCardFound(AnsiString sNewID)
{
        Form1->lCurCardID->Caption=sNewID;
        Form1->mLog->Lines->Add("обнаружена новая карта ID="+sNewID);
        AnsiString asTemp;
        char *pch;
        int index;
        Form1->lCurVideoLength->Caption="Запись не найдена";
        Form1->lCurCardFilePach->Caption="Запись не найдена";
        for (int i=0; i<iRecCounter; i++)
        {
                pch=sNewID.c_str();
                index=strcmp(myRecord[i].chCardID, pch);
                if (index==0)     //A zero value indicates that both strings are equal.
                {
                        Form1->lCurVideoLength->Caption=(AnsiString)myRecord[i].iVideoLength;
                        Form1->lCurCardFilePach->Caption=(AnsiString)myRecord[i].chVideoPach;
                        if (Form1->cbStartPlay->Checked)
                        {
                                StartPlay((AnsiString)myRecord[i].chVideoPach,myRecord[i].iVideoLength);
                                iStateVideoPlay=STATE_PLAY_VIDEO;
                        }
                }
        }
}
예제 #2
0
void SetCurrentOutputModule(CPs_PlayerContext* pContext, CPs_OutputModule* pNewOuputModule, BOOL* pbForceRefill)
{
	if (!pNewOuputModule)
		pNewOuputModule = &pContext->m_OutputModules[pContext->m_dwCurrentOutputModule];
		
	// If the output module has changed then close the existing one and open the new one
	if (pContext->m_pCurrentOutputModule == pNewOuputModule)
		return;
		
	// Close existing
	if (pContext->m_bOutputActive)
	{
		pContext->m_pCurrentOutputModule->Uninitialise(pContext->m_pCurrentOutputModule);
		pContext->m_bOutputActive = FALSE;
	}
	
	// Switch the CoDec over to the new output module
	pNewOuputModule->m_pCoDec = pContext->m_pCurrentOutputModule->m_pCoDec;
	
	// Set the new module as current
	pContext->m_pCurrentOutputModule = pNewOuputModule;
	
	if (pContext->m_bOutputActive == FALSE && pContext->m_pCurrentOutputModule->m_pCoDec)
	{
		StartPlay(pContext->m_pCurrentOutputModule->m_pCoDec, pContext);
		*pbForceRefill = TRUE;
	}
}
예제 #3
0
파일: DLGPlaywin.cpp 프로젝트: dulton/brpj
/////////////////////////////////////////////////////////////////////////////
// CDLGPlaywin message handlers
BOOL CDLGPlaywin::OnInitDialog()
{
	Language_SetWndStaticText(this);
	CDialog::OnInitDialog();
	
	LC_PLAYM4_Initial((long)this->m_hWnd);

	m_video.SDKinit();

	m_screenPannel.Create(
		NULL,
		NULL,
		WS_CHILD|WS_VISIBLE, 
		CRect(0,0,0,0), 
		this, 
		1981);
	//屏蔽
	m_screenPannel.ShowWindow(SW_SHOW);

	m_screenPannel.SetShowPlayWin(SCREEN_4MODE, m_curScreen);	

	for(int i=0;i<MAX_PLAYWIN;i++)
	{
		StartPlay(i,\
				  pCMainDlg->DlgNewDevice.device[i].name,\
				  pCMainDlg->DlgNewDevice.device[i].ip,\
				  pCMainDlg->DlgNewDevice.device[i].port,\
				  pCMainDlg->DlgNewDevice.device[i].user,\
				  pCMainDlg->DlgNewDevice.device[i].psw);
	}

	AutoSize();
	return TRUE;  // return TRUE  unless you set the focus to a control
}
HRESULT CLHTMLActiveDocument::OnPostVerbInPlaceActivate()
{
	if (m_pWindow)	// Scripting
	{
		// TODO, make a function

		HRESULT hr;

		CComQIPtr<CLDOMDocumentImplImpl> documentImpl(m_document);

		documentImpl->m_pScriptSite->m_pGlobalObject = m_pWindow->GetUnknown();
		documentImpl->m_pScriptSite->m_hWnd = NULL;	// TODO

	// Add global 'window' object to the script
		hr = documentImpl->m_pScriptSite->m_activeScript->AddNamedItem(L"globalobject", SCRIPTITEM_GLOBALMEMBERS | SCRIPTITEM_ISVISIBLE/* | SCRIPTITEM_ISSOURCE | SCRIPTITEM_ISPERSISTENT*/);
		ATLASSERT(SUCCEEDED(hr));

		//	hr = m_pScriptSite->m_activeScript->SetScriptState(SCRIPTSTATE_STARTED);
		//	ATLASSERT(SUCCEEDED(hr));

		//
		//DebugOutputTypeInfo(m_pScriptDisp);

		// Start running scripts
		hr = documentImpl->m_pScriptSite->m_activeScript->SetScriptState(SCRIPTSTATE_STARTED);
		ATLASSERT(SUCCEEDED(hr));

	// force the engine to connect any outbound interfaces to the 
	// host's objects
		hr = documentImpl->m_pScriptSite->m_activeScript->SetScriptState(SCRIPTSTATE_CONNECTED);
		ATLASSERT(SUCCEEDED(hr));

		CComPtr<ILDOMElement> documentElement;
		m_document->get_documentElement(&documentElement);
		if (documentElement)
		{
			OnSVGLoad(documentElement);
		}
	}

	if (FALSE)
	{
		StartPlay();
	}

#if 0	// ??
	// Done in m_pWindow->SetDocument()?
	if (m_spInPlaceSite)
	{
		m_spInPlaceSite->InvalidateRect(NULL, TRUE);
	}
#endif

	return S_OK;
}
예제 #5
0
void CurCardLost(void)
{
        Form1->lCurCardID->Caption="Карта не найдена" ;
        Form1->mLog->Lines->Add("карта извлечена");
        Form1->lCurVideoLength->Caption="Карта не найдена";
        Form1->lCurCardFilePach->Caption="Карта не найдена";
        bGetCardFlag=false;
        if (iStateVideoPlay==STATE_PLAY_VIDEO)
        {
                StartPlay(Form1->lPshFile->Caption,PSH_VIDEO_LEN);
                iStateVideoPlay=STATE_PLAY_PSH;
        }
}
예제 #6
0
bool CTsPlayer::StopFast()
{
	int ret;
	
	Stop();
	ret = StartPlay();
	if (!ret)
		return false;
	ret = set_sys_int("/sys/class/video/blackout_policy",1);
	if (!ret)
		return false;

	ret = codec_set_cntl_mode(pcodec, TRICKMODE_NONE);
	return !ret;
}
예제 #7
0
HRESULT CLX3DViewer::OnPostVerbInPlaceActivate()
{
	if (m_filterGraph)
	{
		m_filterGraph->Run();

	// Timer for updating slider position (update every 0.1 seconds)
	//	m_nRunTimer = SetTimer(1, 100);
	}

#if 0
	StartPlay();
#endif
	return 0;
}
예제 #8
0
// 开始前端录像回放
int CPlayback::StartPUPlayBack(const char* pCameraCode,
                               unsigned int uiProtocolType,
                               const TIME_SPAN_INTERNAL& stTimeSpanInter,
                               HWND hWnd,
                               float fSpeed,
                               const char* pFileName)
{
#if 0
    if(PLAY_TYPE_HWND == m_iStartType && NULL == hWnd)
    {
        BP_RUN_LOG_ERR(IVS_SDK_ERR_FINDVIDEOHANDLE_FAILED,"Start PU Play Back", "hwnd invalid");
        return IVS_PARA_INVALID;
    }
#endif
    CLockGuard lock(m_pMediaMutex);

    IVS_MEDIA_PARA stMediaPara;
    InitMediaPara(stMediaPara);
    stMediaPara.ProtocolType = static_cast<IVS_PROTOCOL_TYPE>(uiProtocolType);//此处转换肯定正确,前面已做检查;

    START_PLAY_PARAM stParam;
    //TODO:待更新结构体
    stParam.enServiceType = SERVICE_TYPE_PU_PLAYBACK;
    stParam.fSpeed = fSpeed;
    stParam.cbRtspDataCallBack = g_fRtspDataCallBack;
    stParam.cbNetDataCallBack = g_fNetDataCallBack;
    //开始回放;
    int iRet = StartPlay(NULL,NULL,&stMediaPara, pCameraCode, stTimeSpanInter, stParam, pFileName);
    if (IVS_SUCCEED != iRet)
    {
        BP_RUN_LOG_ERR(iRet,"Start PU Play Back", "Start play error.");
        return iRet;
    }

    SetServiceType(stParam.enServiceType);

    (void)IVS_PLAY_SetPlaySpeed(m_ulPlayerChannel, m_fSpeed);//lint !e747
    iRet = IVS_PLAY_SetPlayWindow(m_ulPlayerChannel, hWnd);
    if (IVS_SUCCEED == iRet)
    {
        m_hWnd = hWnd;
    }

    return iRet;
}
예제 #9
0
//开始平台录像回放
int CPlayback::StartPlatformOrBackupPlayBack(const IVS_CHAR* pDomainCode,const IVS_CHAR* pNVRCode,const char* pCameraCode,
        unsigned int uiProtocolType,
        const TIME_SPAN_INTERNAL& stTimeSpanInter,
        HWND hWnd,
        float fSpeed,IVS_SERVICE_TYPE playBackServiceType )
{
#if 0
    if(m_iStartType == PLAY_TYPE_HWND && NULL == hWnd)
    {
        BP_RUN_LOG_ERR(IVS_SDK_ERR_FINDVIDEOHANDLE_FAILED,"Start Platform Or Backup Play Back", "hwnd invalid");
        return IVS_PARA_INVALID;
    }
#endif

    CLockGuard lock(m_pMediaMutex);

    IVS_MEDIA_PARA stMediaPara;
    InitMediaPara(stMediaPara);
    stMediaPara.ProtocolType = static_cast<IVS_PROTOCOL_TYPE>(uiProtocolType);//此处转换肯定正确,前面已做检查;

    START_PLAY_PARAM stParam;
    stParam.enServiceType = playBackServiceType;
    if(NULL != pDomainCode && SERVICE_TYPE_DISASTEBACKUP_PLAYBACK != stParam.enServiceType)
    {
        stParam.enServiceType = SERVICE_TYPE_BACKUPRECORD_PLAYBACK;
    }
    stParam.fSpeed = fSpeed;
    stParam.cbRtspDataCallBack = g_fRtspDataCallBack;
    stParam.cbNetDataCallBack = g_fNetDataCallBack;
    //开始回放;
    int iRet = StartPlay(pDomainCode,pNVRCode,&stMediaPara, pCameraCode, stTimeSpanInter, stParam, NULL);
    if (IVS_SUCCEED != iRet)
    {
        BP_RUN_LOG_ERR(iRet,"Start Platform Or Backup Play Back", "Start play error.");
        return iRet;
    }

    SetServiceType(stParam.enServiceType);

    (void)IVS_PLAY_SetPlaySpeed(m_ulPlayerChannel,   m_fSpeed);//lint !e747
    (void)IVS_PLAY_SetPlayWindow(m_ulPlayerChannel, hWnd);
    m_hWnd = hWnd;
    return IVS_SUCCEED;
}
예제 #10
0
int CPlayback::StartPlatformPlayBackCB(const IVS_CHAR* pDomainCode,const IVS_CHAR* pNVRCode,const char* pCameraCode,
                                       unsigned int uiProtocolType,
                                       const TIME_SPAN_INTERNAL& stTimeSpanInter,
                                       PlayBackCallBackRaw fPlayBackCallBackRaw,
                                       void* pUserData,
                                       float fSpeed)
{
    CLockGuard lock(m_pMediaMutex);

    IVS_MEDIA_PARA stMediaPara;
    InitMediaPara(stMediaPara);
    stMediaPara.ProtocolType = static_cast<IVS_PROTOCOL_TYPE>(uiProtocolType);//此处转换肯定正确,前面已做检查;

    START_PLAY_PARAM stParam;
    stParam.enServiceType = SERVICE_TYPE_PLAYBACK;
    if(NULL != pDomainCode && SERVICE_TYPE_DISASTEBACKUP_PLAYBACK != stParam.enServiceType)
    {
        stParam.enServiceType = SERVICE_TYPE_BACKUPRECORD_PLAYBACK;
    }
    stParam.fSpeed = fSpeed;
    stParam.cbRtspDataCallBack = g_fRtspDataCallBack;
    stParam.cbNetDataCallBack = g_fNetDataCallBack;
    //开始回放;
    int iRet = StartPlay(pDomainCode,pNVRCode,&stMediaPara, pCameraCode, stTimeSpanInter, stParam, NULL);
    if (IVS_SUCCEED != iRet)
    {
        BP_RUN_LOG_ERR(iRet,"Start Platform Or Backup Play Back", "Start play error.");
        return iRet;
    }

    SetServiceType(stParam.enServiceType);

    (void)IVS_PLAY_SetPlaySpeed(m_ulPlayerChannel,   m_fSpeed);//lint !e747

    m_iStartType = PLAY_TYPE_CB;
    (void)VOS_MutexLock(m_pPlayBackRawCBMutex);
    m_fPlayBackCallBackRaw = fPlayBackCallBackRaw;
    m_pPlayBackUserDataRaw = pUserData;
    (void)VOS_MutexUnlock(m_pPlayBackRawCBMutex);
    iRet = IVS_PLAY_SetRawFrameCallBack(m_ulPlayerChannel, g_fReassmCallBack, this);

    return IVS_SUCCEED;
}
예제 #11
0
void VSCVWidget::dropEvent(QDropEvent *event)
{
    VDC_DEBUG( "%s Enter in dropEvent id %d\n",__FUNCTION__, m_nId);
    if (event->mimeData()->hasText() == false)
    {
    	return;
    }

    s32 nPlayId = atoi(event->mimeData()->text().toLatin1().data());
    if (nPlayId < VWIDGET_ID_OFFSET)
    {
       if (m_pStarted == TRUE)
       {
            return;
       }
       m_nPlayId = nPlayId;
        StopPlay();
        StartPlay("fake");
        return;
    }
    

    VDC_DEBUG( "%s Enter in dropEvent Play %d\n",__FUNCTION__, nPlayId);

    nPlayId = nPlayId - VWIDGET_ID_OFFSET;

    if (nPlayId == m_nId)
    {
        VDC_DEBUG( "%s Enter in dropEvent Same with me %d\n", 
            __FUNCTION__, nPlayId);
        return;
    }
    emit VideoSwitchWith(m_nId, nPlayId);
    VDC_DEBUG( "%s Enter in dropEvent  me %d switch with %d\n", 
            __FUNCTION__, m_nId, nPlayId);
}
예제 #12
0
STDMETHODIMP CLHTMLActiveDocument::put_src(/*[in]*/ BSTR newVal)
{
	ATLASSERT(0);
#if 0
	StopPlay();

	if (m_textData)
	{
		m_textData.Release();
	}

	if (m_pWindow)
	{
#if 0
		m_pWindow->Free();
#endif
		m_pWindow->Release();
		m_pWindow = NULL;

		m_spInPlaceSite->InvalidateRect(NULL, TRUE);
	}

	m_src = newVal;

	CComQIPtr<IServiceProvider> sp = m_spClientSite;
	if (sp)
	{
		CComPtr<IMoniker> imkName;

		CComPtr<IBindHost> bindHost;
		if (SUCCEEDED(sp->QueryService(SID_SBindHost, &bindHost)))
		{
			bindHost->CreateMoniker(m_src, NULL, &imkName, 0);
		}
		else
		{
			CreateURLMoniker(NULL, m_src, &imkName);
		}

		if (imkName)
		{
			// Note I'm creating the window before loading the document
			CComObject<CLHTMLWindow2>::CreateInstance(&m_pWindow);
			if (m_pWindow)
			{
				m_pWindow->AddRef();
			//	m_hWnd = m_hWnd;
#if 0	// I Had this
				m_pWindow->m_pActiveDocument = this;
#endif

			// TODO, init scripting if not already done?

				CComPtr<IBindCtx> bctx;
				if (SUCCEEDED(CreateBindCtx(0/*reserved*/, &bctx)))
				{
					Load(FALSE, imkName, bctx, 0);

					if (m_document)
					{
						CComQIPtr<ILDOMDocumentView> documentView = m_document;
						documentView->createPresentation(&m_view);
					//	SetDocument(document);

						if (FALSE)
						{
							StartPlay();
						}

						m_pWindow->m_pCanvas->m_pView = static_cast<CHTMLDocumentView*>(m_view.p);
						m_pWindow->m_pCanvas->m_htmTree = m_pWindow->m_pCanvas->m_pView->m_pRootElement;

					//	CComQIPtr<ILDOMDocumentView> documentView = m_document;
					//	documentView->createPresentation(&m_view);
					//	ATLASSERT(0);
#if 0
						m_pView->SetDocument(m_document);
#endif
					}
				}
			}
		}
	}

#endif
	return S_OK;
}
예제 #13
0
// MP3 decode player
void MP3Player(void)
{
    FRESULT res;
    uint8_t *ReadStart;
    uint8_t *GuardPtr;
    volatile uint8_t u8PCMBufferTargetIdx = 0;
    volatile uint32_t pcmbuf_idx, i;
    volatile unsigned int Mp3FileOffset=0;
    uint16_t sampleL, sampleR;

    pcmbuf_idx = 0;
    memset((void *)&audioInfo, 0, sizeof(audioInfo));

    /* Parse MP3 header */
    MP3_ParseHeaderInfo(MP3_FILE);

    /* First the structures used by libmad must be initialized. */
    mad_stream_init(&Stream);
    mad_frame_init(&Frame);
    mad_synth_init(&Synth);

    /* Open MP3 file */
    res = f_open(&mp3FileObject, MP3_FILE, FA_OPEN_EXISTING | FA_READ);
    if (res != FR_OK) {
        printf("Open file error \r\n");
        return;
    }

    /* Open I2S1 interface and set to slave mode, stereo channel, I2S format */
    I2S_Open(I2S1, I2S_MODE_SLAVE, 16000, I2S_DATABIT_16, I2S_STEREO, I2S_FORMAT_I2S, I2S_I2S);

    /* Initialize WAU8822 codec */
    WAU8822_Setup();

    /* Configure wau8822 for specific sampling rate */
    WAU8822_ConfigSampleRate(audioInfo.mp3SampleRate);

    /* Set MCLK and enable MCLK */
    I2S_EnableMCLK(I2S1, 12000000);

    while(1) {
        if(Stream.buffer==NULL || Stream.error==MAD_ERROR_BUFLEN) {
            if(Stream.next_frame != NULL) {
                /* Get the remaining frame */
                Remaining = Stream.bufend - Stream.next_frame;
                memmove(MadInputBuffer, Stream.next_frame, Remaining);
                ReadStart = MadInputBuffer + Remaining;
                ReadSize = FILE_IO_BUFFER_SIZE - Remaining;
            } else {
                ReadSize = FILE_IO_BUFFER_SIZE,
                ReadStart = MadInputBuffer,
                Remaining = 0;
            }

            /* read the file from SDCard */
            res = f_read(&mp3FileObject, ReadStart, ReadSize, &ReturnSize);
            if((res != FR_OK) || f_eof(&mp3FileObject)) {
                printf("Stop !(%x)\n\r", res);
                goto stop;
            }

            /* if the file is over */
            if (ReadSize > ReturnSize) {
                GuardPtr=ReadStart+ReadSize;
                memset(GuardPtr,0,MAD_BUFFER_GUARD);
                ReadSize+=MAD_BUFFER_GUARD;
            }

            Mp3FileOffset = Mp3FileOffset + ReturnSize;
            /* Pipe the new buffer content to libmad's stream decoder
                     * facility.
            */
            mad_stream_buffer(&Stream,MadInputBuffer,ReadSize+Remaining);
            Stream.error=(enum  mad_error)0;
        }

        /* decode a frame from the mp3 stream data */
        if(mad_frame_decode(&Frame,&Stream)) {
            if(MAD_RECOVERABLE(Stream.error)) {
                /*if(Stream.error!=MAD_ERROR_LOSTSYNC ||
                   Stream.this_frame!=GuardPtr)
                {
                }*/
                continue;
            } else {
                /* the current frame is not full, need to read the remaining part */
                if(Stream.error==MAD_ERROR_BUFLEN) {
                    continue;
                } else {
                    printf("Something error!!\n");

                    /* play the next file */
                    audioInfo.mp3FileEndFlag = 1;
                    goto stop;
                }
            }
        }

        /* Once decoded the frame is synthesized to PCM samples. No errors
        * are reported by mad_synth_frame();
        */
        mad_synth_frame(&Synth,&Frame);

        //
        // decode finished, try to copy pcm data to audio buffer
        //

        if(audioInfo.mp3Playing) {
            //if next buffer is still full (playing), wait until it's empty
            if(aPCMBuffer_Full[u8PCMBufferTargetIdx] == 1)
                while(aPCMBuffer_Full[u8PCMBufferTargetIdx]);
        } else {

            if((aPCMBuffer_Full[0] == 1) && (aPCMBuffer_Full[1] == 1 )) {       //all buffers are full, wait
                StartPlay();
            }
        }

        for(i=0; i<(int)Synth.pcm.length; i++) {
            /* Get the left/right samples */
            sampleL = Synth.pcm.samples[0][i];
            sampleR = Synth.pcm.samples[1][i];

            /* Fill PCM data to I2S(PDMA) buffer */
            aPCMBuffer[u8PCMBufferTargetIdx][pcmbuf_idx++] = sampleR | (sampleL << 16);

            /* Need change buffer ? */
            if(pcmbuf_idx == PCM_BUFFER_SIZE) {
                aPCMBuffer_Full[u8PCMBufferTargetIdx] = 1;      //set full flag
                u8PCMBufferTargetIdx ^= 1;

                pcmbuf_idx = 0;
//               printf("change to ==>%d ..\n", u8PCMBufferTargetIdx);
                /* if next buffer is still full (playing), wait until it's empty */
                if((aPCMBuffer_Full[u8PCMBufferTargetIdx] == 1) && (audioInfo.mp3Playing))
                    while(aPCMBuffer_Full[u8PCMBufferTargetIdx]);
            }
        }
    }

stop:

    printf("Exit MP3\r\n");

    mad_synth_finish(&Synth);
    mad_frame_finish(&Frame);
    mad_stream_finish(&Stream);

    f_close(&mp3FileObject);
    StopPlay();
}
예제 #14
0
DWORD WINAPI CPI_Player__EngineEP(void* pCookie)
{
	BOOL bTerminateThread = FALSE;
	HRESULT hr_ComState;
	CPs_PlayerContext playercontext;
	
	playercontext.m_pBaseEngineParams = (CPs_PlayEngine*)pCookie;
	playercontext.m_bOutputActive = FALSE;
	playercontext.m_iProportion_TrackLength = 0;
	playercontext.m_iLastSentTime_Secs = -1;
	playercontext.m_iLastSentTime_Proportion = -1;
	playercontext.m_iInternalVolume = 100;
	CP_CHECKOBJECT(playercontext.m_pBaseEngineParams);
	
	CP_TRACE0("Cooler Engine Startup");
	hr_ComState = CoInitialize(NULL);
		
	// Initialise CoDecs
	CP_InitialiseCodec_MPEG(&playercontext.m_CoDecs[CP_CODEC_MPEG]);
	CP_InitialiseCodec_WAV(&playercontext.m_CoDecs[CP_CODEC_WAV]);
	CP_InitialiseCodec_OGG(&playercontext.m_CoDecs[CP_CODEC_OGG]);
	CP_InitialiseCodec_WinAmpPlugin(&playercontext.m_CoDecs[CP_CODEC_WINAMPPLUGIN]);
	
	// Initialise output module
	
	if (options.decoder_output_mode > CP_OUTPUT_last)
		options.decoder_output_mode = CP_OUTPUT_last;
		
	playercontext.m_dwCurrentOutputModule = options.decoder_output_mode;
	
	CPI_Player_Output_Initialise_WaveMapper(&playercontext.m_OutputModules[CP_OUTPUT_WAVE]);
	CPI_Player_Output_Initialise_DirectSound(&playercontext.m_OutputModules[CP_OUTPUT_DIRECTSOUND]);
	CPI_Player_Output_Initialise_File(&playercontext.m_OutputModules[CP_OUTPUT_FILE]);
	
	playercontext.m_pCurrentOutputModule = &playercontext.m_OutputModules[playercontext.m_dwCurrentOutputModule];
	
	// Initialise EQ
	CPI_Player_Equaliser_Initialise_Basic(&playercontext.m_Equaliser);
	
	{
		CPs_PlayEngine* player = (CPs_PlayEngine*)pCookie;
		player->m_pContext = &playercontext;
	}
	
	// Initialise USER32.DLL for this thread
	{
		MSG msgDummy;
		PeekMessage(&msgDummy, 0, WM_USER, WM_USER, PM_NOREMOVE);
		
		// Signal this thread ready for input
		SetEvent(playercontext.m_pBaseEngineParams->m_hEvtThreadReady);
	}
	
	do
	{
		// Process any pending messages
		BOOL bForceRefill = FALSE;
		MSG msg;
		DWORD dwWaitResult;
		
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			// Decode engine message
			switch (msg.message)
			{
			
				case CPTM_QUIT:
					bTerminateThread = TRUE;
					break;
					
				case CPTM_OPENFILE:
				{
					char* pcFilename = (char*)msg.wParam;
					
					// If there is another pending openfile then ignore this one
					// This helps when this thread is non responsive (on an http connect for example)
					// and the user is hammering the hell out of the play button (as I always
					// do) - this will cause a number of open/closes to be placed into the
					// message queue which will tie up this thread for ages!!
					MSG msg2;
					
					if (PeekMessage(&msg2, NULL, CPTM_OPENFILE, CPTM_OPENFILE, PM_NOREMOVE) == FALSE)
					{
						CPs_CoDecModule* pNewCoDec;
						
						// If there is a CoDec playing then shut it down
						
						if (playercontext.m_pCurrentOutputModule->m_pCoDec)
						{
							playercontext.m_pCurrentOutputModule->m_pCoDec->CloseFile(playercontext.m_pCurrentOutputModule->m_pCoDec);
							playercontext.m_pCurrentOutputModule->m_pCoDec = NULL;
						}
						
						CP_TRACE1("Openfile \"%s\"", pcFilename);
						
						pNewCoDec = OpenCoDec(&playercontext, pcFilename);
						
						// If the open failed then request a new stream from the interface
						
						if (pNewCoDec == NULL)
						{
							PostMessage(playercontext.m_pBaseEngineParams->m_hWndNotify, CPNM_PLAYERSTATE, (WPARAM)cppsEndOfStream, 0);
						}
						
						// Check the file's format - if the sample rate, nChannels or sample size has changed
						// then clear the current output and shutdown output device (this will cause a gap
						// - but only when the format changes)
						
						else if (playercontext.m_bOutputActive == TRUE)
						{
							CPs_FileInfo FileInfo;
							pNewCoDec->GetFileInfo(pNewCoDec, &FileInfo);
							
							if (FileInfo.m_iFreq_Hz != playercontext.m_iOpenDevice_Freq_Hz
									|| FileInfo.m_bStereo != playercontext.m_bOpenDevice_Stereo
									|| FileInfo.m_b16bit != playercontext.m_bOpenDevice_16bit)
							{
								CP_TRACE0("Stream format changes - clearing stream");
								EmptyOutputStream(&playercontext);
								StartPlay(pNewCoDec, &playercontext);
								bForceRefill = TRUE;
							}
						}
						
						playercontext.m_pCurrentOutputModule->m_pCoDec = pNewCoDec;
					}
					
					#ifdef _DEBUG
					else
					{
						CP_TRACE1("Openfile of \"%s\" ignored due to other opens in the queue", pcFilename);
					}
					#endif
					
					// Cleanup
					free(pcFilename);
				}
				
				break;
				
				case CPTM_SEEK:
				
					if (playercontext.m_bOutputActive == TRUE)
					{
						// Ignore message if there is another on it's way!
						MSG msg2;
						
						if (PeekMessage(&msg2, NULL, CPTM_SEEK, CPTM_SEEK, PM_NOREMOVE) == FALSE)
						{
							if (playercontext.m_pCurrentOutputModule->m_pCoDec)
								playercontext.m_pCurrentOutputModule->m_pCoDec->Seek(playercontext.m_pCurrentOutputModule->m_pCoDec, (int)msg.wParam, (int)msg.lParam);
								
							playercontext.m_pCurrentOutputModule->Flush(playercontext.m_pCurrentOutputModule);
							
							bForceRefill = TRUE;
						}
					}
					// FALLTHROUGH - to let coolplayer know playing has resumed (bugfix from seeking when paused)  */
					
				case CPTM_PLAY:
					if (playercontext.m_pCurrentOutputModule->m_pCoDec)
					{
						// If we don't have an output stage - initialise one now
						if (playercontext.m_bOutputActive == FALSE)
						{
							StartPlay(playercontext.m_pCurrentOutputModule->m_pCoDec, &playercontext);
							bForceRefill = TRUE;
						}
						
						playercontext.m_pCurrentOutputModule->SetPause(playercontext.m_pCurrentOutputModule, FALSE);
						
						PostMessage(playercontext.m_pBaseEngineParams->m_hWndNotify, CPNM_PLAYERSTATE, (WPARAM)cppsPlaying, 0);
						playercontext.m_iLastSentTime_Secs = -1;
						playercontext.m_iLastSentTime_Proportion = -1;
						UpdateProgress(&playercontext);
					}
					
					break;
					
				case CPTM_STOP:
				
					if (playercontext.m_pCurrentOutputModule->m_pCoDec)
					{
						playercontext.m_pCurrentOutputModule->m_pCoDec->CloseFile(playercontext.m_pCurrentOutputModule->m_pCoDec);
						playercontext.m_pCurrentOutputModule->m_pCoDec = NULL;
					}
					
					if (playercontext.m_bOutputActive == TRUE)
					{
						playercontext.m_bOutputActive = FALSE;
						playercontext.m_pCurrentOutputModule->Uninitialise(playercontext.m_pCurrentOutputModule);
					}
					
					PostMessage(playercontext.m_pBaseEngineParams->m_hWndNotify, CPNM_PLAYERSTATE, (WPARAM)cppsStopped, 0);
					
					break;
					
				case CPTM_PAUSE:
					CP_TRACE0("Pause");
					
					if (playercontext.m_bOutputActive == TRUE)
						playercontext.m_pCurrentOutputModule->SetPause(playercontext.m_pCurrentOutputModule, TRUE);
						
					PostMessage(playercontext.m_pBaseEngineParams->m_hWndNotify, CPNM_PLAYERSTATE, (WPARAM)cppsPaused, 0);
					
					break;
					
				case CPTM_SETPROGRESSTRACKLENGTH:
					playercontext.m_iProportion_TrackLength = (int)msg.wParam;
					
					break;
					
				case CPTM_SENDSYNCCOOKIE:
					PostMessage(playercontext.m_pBaseEngineParams->m_hWndNotify, CPNM_SYNCCOOKIE, msg.wParam, 0);
					
					break;
					
				case CPTM_BLOCKMSGUNTILENDOFSTREAM:
					EmptyOutputStream(&playercontext);
					
					break;
					
				case CPTM_ENUMOUTPUTDEVICES:
					EnumOutputDevices(&playercontext);
					
					break;
					
				case CPTM_SETEQSETTINGS:
				{
					MSG msg2;
					CPs_EQSettings* pEQ = (CPs_EQSettings*)msg.wParam;
					
					// If there is another pending EQ message do no processing for this one (try to reduce noise)
					
					if (PeekMessage(&msg2, NULL, CPTM_SETEQSETTINGS, CPTM_OPENFILE, PM_NOREMOVE) == FALSE)
					{
						BOOL bEQEnableStateChanged;
						playercontext.m_Equaliser.ApplySettings(&playercontext.m_Equaliser, pEQ, &bEQEnableStateChanged);
						
						// Empty the buffers (this will cause a discontinuity in the music but at least
						// the EQ setting change will be immediate
						
						if (playercontext.m_bOutputActive == TRUE && playercontext.m_pCurrentOutputModule->OnEQChanged)
							playercontext.m_pCurrentOutputModule->OnEQChanged(playercontext.m_pCurrentOutputModule);
					}
					
					free(pEQ);
				}
				
				break;
				
				case CPTM_ONOUTPUTMODULECHANGE:
				{
					playercontext.m_dwCurrentOutputModule = options.decoder_output_mode;
					SetCurrentOutputModule(&playercontext, NULL, &bForceRefill);
				}
				
				break;
				
				case CPTM_ASSOCIATEFILEEXTENSIONS:
					AssociateFileExtensions(&playercontext);
					break;
					
				case CPTM_SETINTERNALVOLUME:
					playercontext.m_iInternalVolume = (int)msg.wParam;
					
					if (playercontext.m_bOutputActive == TRUE && playercontext.m_pCurrentOutputModule->SetInternalVolume)
						playercontext.m_pCurrentOutputModule->SetInternalVolume(playercontext.m_pCurrentOutputModule, playercontext.m_iInternalVolume);
						
					break;
			}
		}
		
		if (bTerminateThread)
			break;
			
		// Wait for either another message or a buffer expiry (if we have a player)
		if (playercontext.m_bOutputActive)
		{
			dwWaitResult = 0L;
			
			if (bForceRefill == FALSE)
			{
				if (playercontext.m_pCurrentOutputModule->m_evtBlockFree)
					dwWaitResult = MsgWaitForMultipleObjects(1, &playercontext.m_pCurrentOutputModule->m_evtBlockFree, FALSE, 1000, QS_POSTMESSAGE);
				else
					dwWaitResult = WAIT_OBJECT_0;
			}
			
			// If the buffer event is signaled then request a refill
			
			if (bForceRefill == TRUE || dwWaitResult == WAIT_OBJECT_0)
			{
				if (playercontext.m_pCurrentOutputModule->m_pCoDec)
				{
					playercontext.m_pCurrentOutputModule->RefillBuffers(playercontext.m_pCurrentOutputModule);
					
					if (playercontext.m_pCurrentOutputModule->m_pCoDec == NULL)
					{
						// Tell UI that we need another file to play
						PostMessage(playercontext.m_pBaseEngineParams->m_hWndNotify, CPNM_PLAYERSTATE, (WPARAM)cppsEndOfStream, 0);
					}
					
					else
						UpdateProgress(&playercontext);
				}
				
				// If output has finished everything that it was doing - close the engine
				
				else if (playercontext.m_pCurrentOutputModule->IsOutputComplete(playercontext.m_pCurrentOutputModule) == TRUE)
				{
					playercontext.m_bOutputActive = FALSE;
					playercontext.m_pCurrentOutputModule->Uninitialise(playercontext.m_pCurrentOutputModule);
					PostMessage(playercontext.m_pBaseEngineParams->m_hWndNotify, CPNM_PLAYERSTATE, (WPARAM)cppsStopped, 0);
				}
			}
		}
		
		else
		{
			WaitMessage();
		}
	}
	
	while (bTerminateThread == FALSE);
	
	// Clean up output (if it's still active)
	if (playercontext.m_pCurrentOutputModule->m_pCoDec)
	{
		playercontext.m_pCurrentOutputModule->m_pCoDec->CloseFile(playercontext.m_pCurrentOutputModule->m_pCoDec);
		playercontext.m_pCurrentOutputModule->m_pCoDec = NULL;
	}
	
	if (playercontext.m_bOutputActive == TRUE)
		playercontext.m_pCurrentOutputModule->Uninitialise(playercontext.m_pCurrentOutputModule);
		
	// Clean up modules
	playercontext.m_Equaliser.Uninitialise(&playercontext.m_Equaliser);
	
	CleanupCoDecs(&playercontext);
	
	if (hr_ComState == S_OK)
		CoUninitialize();
		
	CP_TRACE0("Cooler Engine terminating");
	
	return 0;
}
예제 #15
0
bool CTsPlayer::Seek()
{	
	Stop();
	return StartPlay();
}
예제 #16
0
tBool DAXAudio::Start()
{
	return StartRecord() && StartPlay();
}
예제 #17
0
//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的: 处理主窗口的消息。
//
//  WM_COMMAND	- 处理应用程序菜单
//  WM_PAINT	- 绘制主窗口
//  WM_DESTROY	- 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_CREATE:
		{
			g_hWndMain = hWnd;
			CreateControlButtons(hWnd);
			UpdateButtonStatus();
		}
		break;
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 分析菜单选择:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		case START_CAPTURE_ID:
			StartRecord();
			break;
		case STOP_CAPTURE_ID:
			StopRecord();
			break;
		case START_PLAY_ID:
			StartPlay();
			break;
		case STOP_PLAY_ID:
			StopPlay();
			break;
		case START_EXTRACT_ID:
			StartExtract();
			break;
		case STOP_EXTRACT_ID:
			StopExtract();
			break;
		case ADD_SCALE_ID:
			AddScale();
			break;
		case SUB_SCALE_ID:
			SubScale();
			break;
		case PAINT_RECORD_ID:
			PaintRecorder();
			break;
		case PAINT_EXTRACT_ID:
			PaintExtractor();
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: 在此添加任意绘图代码...

		if (g_pAudioPainter->IsEnable())
		{
			RECT rect;
			::GetWindowRect(hWnd, &rect);

			rect.right = rect.right - rect.left - 20;
			rect.left = 10;
			rect.bottom = (rect.bottom - rect.top) / 2;
			rect.top = 200;

			g_pAudioPainter->Paint(hWnd, hdc, rect, 10.0f);
		}

		wchar_t buf[20];
		wsprintf(buf, L"Scale: %d%%", (int)(g_pAudioPainter->GetScale() * 100));
		::TextOut(hdc, 0, 0, buf, ::wcslen(buf));

		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_TIMER:
		if (g_pAudioPainter->IsEnable())
		{
			RECT rect = { 0, 0,  WINDOW_WIDTH, WINDOW_HEIGHT };
			::InvalidateRect(hWnd, &rect, true);
		}
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
예제 #18
0
void __fastcall TForm1::Timer3Timer(TObject *Sender)
{
        if (Form1->cbStartPlay->Checked) StartPlay(lPshFile->Caption,PSH_VIDEO_LEN);
        iStateVideoPlay=STATE_PLAY_PSH;
}
예제 #19
0
void DDuplexAudio::Execute(Thread::Arg arg)
{
	DWORD dwResult;
	HRESULT hr;

	LOGINFO("DDuplexAudio Starting up ...");

	ResetCapture();
	ResetPlay();
	FillBufferWithSound(TRUE);	//full it first with silence first.

	if (FAILED(hr = StartCapture()) || FAILED(hr = StartPlay()))
	{
		LOGWARNING("DDuplexAudio::Execute:Failed to start Capturing or Playing,shutting down...");
		Shutdown();
	}

	while (!_is_shutdown_requested)
	{
		dwResult = MsgWaitForMultipleObjects( 2, &_events[0], 
                                              FALSE, INFINITE, QS_ALLEVENTS );

		switch( dwResult )
        {
            case WAIT_OBJECT_0 + 0:
                // rendering notification is signaled
                // This means that DirectSound just finished playing 
                // a piece of the buffer, so we need to fill the circular 
                // buffer with new sound from the wav file

                if( FAILED( hr = HandleRenderNotification() ) )
                {
                    //DXTRACE_ERR( TEXT("RecordCapturedData"), hr );
                    //MessageBox( NULL, TEXT("Error handling DirectSound notifications. Sample will now exit."), TEXT("DirectSound Sample"), 
                    //           MB_OK | MB_ICONERROR );
					LOGDEBUG("DDuplexAudio::Execute:Failed to HandleRenderNotification,shutting down...");
                    _is_shutdown_requested = TRUE;
                }
                break;

			case WAIT_OBJECT_0 + 1:
				// capturing notification is signaled
                // This means that DirectSound just finished capturing 
                // a piece of the buffer, so we can copy the captured data from the recorder buffer.

                if( FAILED( hr = HandleCaptureNotification() ) )
                {
                    //DXTRACE_ERR( TEXT("RecordCapturedData"), hr );
                    //MessageBox( NULL, TEXT("Error handling DirectSound notifications. Sample will now exit."), TEXT("DirectSound Sample"), 
                    //           MB_OK | MB_ICONERROR );
					LOGDEBUG("DDuplexAudio::Execute:Failed to HandleCaptureNotification,shutting down...");
                    _is_shutdown_requested = TRUE;
                }
                break;

            case WAIT_OBJECT_0 + 2:
                //// Windows messages are available
                //while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
                //{ 
                //    if( !IsDialogMessage( hDlg, &msg ) )  
                //    {
                //        TranslateMessage( &msg ); 
                //        DispatchMessage( &msg ); 
                //    }

                //    if( msg.message == WM_QUIT )
                //        bDone = TRUE;
			default :
				break;
		}
	}

	StopCapture();
	StopPlay();

	LOGINFO("DDuplexAudio shutdowned.");
}
예제 #20
0
/**
 * Server command receiver routine.
 *
 * @param pkt
 *        packet node.
 * @return
 *        15 to exit command thread, all other value
 *        are considered normal.
 */
int
SrvRxCmd( void * pkt )
{
	int ret = 0;
	int acked = 0;

	pkt_node_t * p = (pkt_node_t *)pkt;

	DBGLOG("command: %d", p->hdr.cmd);
	switch (p->hdr.cmd) 
	{
	case CMD_GET_VERSION:
		DBGLOG("CMD_GET_VERSION.");
		CoolCmdSendPacket(p->fd, CMD_GET_VERSION|NMS_CMD_ACK, 
					  (void*)version, strlen(version)+1);
		acked = 1;
		break;

		// careful: this will be the last command server responds to.
	case CMD_STOP_SERVER: 
		DBGLOG("CMD_STOP_SERVER.");
		ret = 15;
		break;
		
	case CMD_SET_INPUT_MODE:
		DBGLOG("CMD_SET_INPUT_MODE.");
		EncInputSetMode(*(int*)p->data);
		break;
		
	case CMD_SET_OUTPUT_MODE:
		DBGLOG("CMD_SET_OUTPUT_MODE.");
	  	{
			OutputSetMode(*(int*)p->data);
			if (SrvIsMonitorActive())
			{
				SrvStartMonitorInternal();
			}
			else if (SrvIsRecording())
			{
			}
			else if (SrvIsPlaying())
			{
				OutputActivateMode(0);
			}
	  	}
	  	break;

	case CMD_SET_OUTPUT_PROPORTIONS:
		DBGLOG("CMD_SET_OUTPUT_PROPORTIONS.");
		SrvSetProportions((*(int*)p->data));
		break;

	case CMD_GET_OUTPUT_PROPORTIONS:
		DBGLOG("CMD_GET_OUTPUT_PROPORTIONS.");
		int proportions = SrvGetProportions();
		CoolCmdSendPacket(p->fd, CMD_GET_OUTPUT_PROPORTIONS|NMS_CMD_ACK, 
		                  (void*)&proportions, sizeof(int));
		acked = 1;
		break;

	case CMD_START_SLIDE_SHOW:
		DBGLOG("CMD_START_SLIDE_SHOW.");
		{
			int startslideshow;
			startslideshow = SrvStartSlideShow();
			CoolCmdSendPacket(p->fd, CMD_START_SLIDE_SHOW|NMS_CMD_ACK, 
						  (void*)&startslideshow, sizeof(int));
			acked = 1;
			DBGLOG("CMD_START_SLIDE_SHOW completed.");
		}
		break;
		
	case CMD_SET_SLIDE_SHOW_IMAGE:
		DBGLOG("CMD_SLIDE_SHOW_SET_IMAGE.");
		{
			SrvSlideShowSetImage((char *)p->data);
		}
		break;
		
	case CMD_STOP_SLIDE_SHOW:
		DBGLOG("CMD_SLIDE_SHOW_STOP.");
		SrvStopSlideShow();
		break;
		
	case CMD_PLAY:
		DBGLOG("CMD_PLAY.");
		int ret = StartPlay(p->data, p->hdr.dataLen);
		CoolCmdSendPacket(p->fd, CMD_PLAY|NMS_CMD_ACK, 
					  (void*)&ret, sizeof(int));
		acked = 1;
		break;
		
	case CMD_PAUSE_UNPAUSE:
		DBGLOG("CMD_PAUSE_UNPAUSE.");
		SrvPauseUnpause();
		break;
		
	case CMD_STOP_PLAY:
		DBGLOG("CMD_STOP_PLAY.");
		SrvStop();
		break;
		
	case CMD_GET_SRV_STATUS:
		DBGLOG("CMD_GET_SRV_STATUS.");
	  	{
			int status;
			status = SrvGetSrvStatus();
			CoolCmdSendPacket(p->fd, CMD_GET_SRV_STATUS|NMS_CMD_ACK,                                                 
						  (void*)&status, sizeof(int));
			acked = 1;
	  	}
	  	break;
		
	case CMD_GET_VOLUME:
		DBGLOG("CMD_GET_VOLUME.");
		{
			int vol[2];
			SrvGetVolume(&vol[0], &vol[1]);
			CoolCmdSendPacket(p->fd, CMD_GET_VOLUME|NMS_CMD_ACK, 
						  (void*)vol, sizeof(vol));
			acked = 1;
		}
		break;
		
	case CMD_SET_VOLUME:
		DBGLOG("CMD_SET_VOLUME.");
		{
			int vol[2];
			int * pv;
			pv = (int*)p->data;
			vol[0] = *pv++;
			vol[1] = *pv;
			SrvSetVolume(vol[0], vol[1]);
		}
		break;
		
	case CMD_GET_PLAY_TIME:
		DBGLOG("CMD_GET_PLAYTIME.");
		{
			int t;
			t = SrvGetPlaytime();
			CoolCmdSendPacket(p->fd, CMD_GET_PLAY_TIME|NMS_CMD_ACK,                                                 
						  (void*)&t, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_SEEK:
		DBGLOG("CMD_SEEK.");
		{
			int t;
			int *pv;
			pv = (int*)p->data;
			t = *pv;
			t = SrvSeek(t);
			CoolCmdSendPacket(p->fd, CMD_SEEK|NMS_CMD_ACK, 
						  (void*)&t, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_TRACK_CHANGE:
		DBGLOG("CMD_TRACK_CHANGE.");
		{
			int track;
			int *pv;
			int retv;
			pv = (int*)p->data;
			track = *pv;
			retv = SrvTrackChange(track);
			CoolCmdSendPacket(p->fd, CMD_TRACK_CHANGE|NMS_CMD_ACK, 
						  (void*)&retv, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_FF_RW:
		DBGLOG("CMD_FF_RW.");
		SrvFfRw(*(int*)p->data);
		break;
		
	case CMD_GET_FFRW_LEVEL:
		DBGLOG("CMD_GET_FFRW_LEVEL.");
	 	{
			int level = SrvGetFFRWLevel();
			CoolCmdSendPacket(p->fd, CMD_GET_FFRW_LEVEL|NMS_CMD_ACK, 
						  (void*)&level, sizeof(int));
			acked = 1;
	 	}
		break;

	case CMD_SF_RW:
		DBGLOG("CMD_SF_RW.");
		SrvSfRw(*(int*)p->data);
		break;
		
	case CMD_GET_SFRW_LEVEL:
		DBGLOG("CMD_GET_SFRW_LEVEL.");
	 	{
			int level = SrvGetSFRWLevel();
			CoolCmdSendPacket(p->fd, CMD_GET_SFRW_LEVEL|NMS_CMD_ACK, 
						  (void*)&level, sizeof(int));
			acked = 1;
	 	}
		break;
		
	case CMD_FRAME_BY_FRAME:	
		DBGLOG("CMD_FRAME_BY_FRAME.");	
		SrvFrameByFrame(*(int*)p->data);	
		break;

	case CMD_REPEAT_A_B:
		DBGLOG("CMD_REPEAT_A_B.");	
		SrvRepeatAB(*(int*)p->data);	
		break;
		
	case CMD_GET_REPEAT_AB_STATUS:
		DBGLOG("CMD_GET_REPEAT_AB_STATUS.");
		{
			int status = SrvGetRepeatABStatus();
			CoolCmdSendPacket(p->fd, CMD_GET_REPEAT_AB_STATUS|NMS_CMD_ACK, 
						  (void*)&status, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_IS_PLAYING:
		DBGLOG("CMD_IS_PLAYING.");
		{
			int playing = SrvIsPlaying();
			CoolCmdSendPacket(p->fd, CMD_IS_PLAYING|NMS_CMD_ACK, 
						  (void*)&playing, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_GET_PLAYMODE:
		DBGLOG("CMD_GET_PLAYMODE.");
		{
			int mode = SrvGetPlaymode();
			CoolCmdSendPacket(p->fd, CMD_GET_PLAYMODE|NMS_CMD_ACK, 
						  (void*)&mode, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_SET_PLAYMODE:
		DBGLOG("CMD_SET_PLAYMODE.");
		{
			SrvSetPlaymode(*((int*)p->data));
		}
		break;
		
	case CMD_SET_EDITMODE:
		DBGLOG("CMD_SET_EDITMODE.");
		{
			SrvSetEditmode(*((int*)p->data));
		}
		break;	
		
	case CMD_GET_REPEATMODE:
		DBGLOG("CMD_GET_REPEATMODE.");
		{
			int mode = SrvGetRepeatmode();
			CoolCmdSendPacket(p->fd, CMD_GET_REPEATMODE|NMS_CMD_ACK, 
						  (void*)&mode, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_SET_REPEATMODE:
		DBGLOG("CMD_SET_REPEATMODE.");
		{
			SrvSetRepeatmode(*((int*)p->data));
		}
		break;
		
	case CMD_GET_TOTAL_FILES:
		DBGLOG("CMD_GET_TOTAL_FILES.");
		{
			int num = SrvGetTotalFiles();
			CoolCmdSendPacket(p->fd, CMD_GET_TOTAL_FILES|NMS_CMD_ACK, 
						  (void*)&num, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_GET_FILE_INDEX:
		DBGLOG("CMD_GET_FILE_INDEX.");
		{
			int idx = SrvGetFileIndex();
			CoolCmdSendPacket(p->fd, CMD_GET_FILE_INDEX|NMS_CMD_ACK, 
						  (void*)&idx, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_GET_FILE_PATH:
		DBGLOG("CMD_GET_FILE_PATH.");
		{
			char path[PATH_MAX];
			int idx;
			int *pv;
			
			pv = (int*)p->data;
			idx = *pv;
			SrvGetFilePath(idx, path,PATH_MAX);
			
			CoolCmdSendPacket(p->fd, CMD_GET_FILE_PATH|NMS_CMD_ACK, 
						  (void*)path, strlen(path)+1);
			acked = 1;
		}
		break;
		
	case CMD_MEDIA_INFO:
		DBGLOG("CMD_MEDIA_INFO.");
		{
			media_info_t media_info;
			
			memset(&media_info, 0 , sizeof(media_info_t));
			SrvGetMediaInfo((char *)p->data, &media_info);
			
			CoolCmdSendPacket(p->fd,CMD_MEDIA_INFO|NMS_CMD_ACK,
						  (void *)(&media_info),sizeof(media_info_t));
			acked = 1;
		}
		break;		

		/* start of encoder interface. */
	case CMD_RECORD:
		DBGLOG("CMD_RECORD.");

		NMS_SRV_ERROR_DETAIL result;
		StartRecord(p->data, p->hdr.dataLen, &result);

		CoolCmdSendPacket(p->fd, CMD_RECORD | NMS_CMD_ACK,
		                  (void *)(&result), sizeof(NMS_SRV_ERROR_DETAIL));
		acked = 1;

		break;

	case CMD_PAUSE_UNPAUSE_RECORD:
		DBGLOG("CMD_PAUSE_UNPAUSE_RECORD.");
		SrvPauseRecord(*(int*)p->data);
		break;
		
	case CMD_STOP_RECORD:
		DBGLOG("CMD_STOP_RECORD.");
		SrvStopRecord();
		break;
		
	case CMD_GET_GAIN:
		DBGLOG("CMD_GET_GAIN.");
		{
			int gain[2];
			SrvGetGain(&gain[0], &gain[1]);
			CoolCmdSendPacket(p->fd, CMD_GET_GAIN|NMS_CMD_ACK, 
						  (void*)gain, sizeof(gain));
			acked = 1;
		}
		break;
		
	case CMD_SET_GAIN:
		DBGLOG("CMD_SET_GAIN.");
		{
			int gain[2];
			int * pg;
			pg = (int*)p->data;
			gain[0] = *pg++;
			gain[1] = *pg;
			SrvSetGain(gain[0], gain[1]);
		}
		break;
		
	case CMD_GET_RECORD_TIME:
		DBGLOG("CMD_GET_RECORD_TIME.");
		{
			int t;
			t = SrvGetRecordtime();
			CoolCmdSendPacket(p->fd, CMD_GET_RECORD_TIME|NMS_CMD_ACK, 
						  (void*)&t, sizeof(int));
			acked = 1;
		}
		break;

	case CMD_GET_RECORD_SIZE:
		DBGLOG("CMD_GET_RECORD_SIZE.");
		{
			unsigned int t;
			t = SrvGetRecordsize();
			CoolCmdSendPacket(p->fd, CMD_GET_RECORD_SIZE|NMS_CMD_ACK, 
						  (void*)&t, sizeof(unsigned int));
			acked = 1;
		}
		break;

	case CMD_GET_RECORD_ERROR:
		DBGLOG("CMD_GET_RECORD_ERROR.");
		{
			NMS_SRV_ERROR_DETAIL det;
			SrvGetRecordError(&det);
			
			CoolCmdSendPacket(p->fd, CMD_GET_RECORD_ERROR|NMS_CMD_ACK,
			                  (void*)&det, sizeof(NMS_SRV_ERROR_DETAIL));
			acked = 1;
		}
		break;
		
	case CMD_IS_RECORDING:
		DBGLOG("CMD_IS_RECORDING.");
		{
			int recording = SrvIsRecording();
			CoolCmdSendPacket(p->fd, CMD_IS_RECORDING|NMS_CMD_ACK, 
						  (void*)&recording, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_START_MONITOR:
		DBGLOG("CMD_START_MONITOR.");
		{
			int startmonitor;
			int pid = (*(int*)p->data);
			startmonitor = SrvStartMonitor(pid);
			CoolCmdSendPacket(p->fd, CMD_START_MONITOR|NMS_CMD_ACK, 
						  (void*)&startmonitor, sizeof(int));
			acked = 1;
			DBGLOG("CMD_START_MONITOR completed.");
		}
		break;
		
	case CMD_STOP_MONITOR:
		DBGLOG("CMD_STOP_MONITOR.");

		int pid = (*(int*)p->data);
		SrvStopMonitor(pid);
		break;

	case CMD_IS_MONITOR_ENABLED:
		DBGLOG("CMD_IS_MONITOR_ENABLED.");
		{
			int monitoractive = SrvIsMonitorActive();
			CoolCmdSendPacket(p->fd, CMD_IS_MONITOR_ENABLED|NMS_CMD_ACK, 
						  (void*)&monitoractive, sizeof(int));
			acked = 1;
		}
		break;
		
	case CMD_CAP_INIT:
		DBGLOG("CMD_CAP_INIT.");
		{
			capture_desc_t desc;
			capture_ret_t capret;
			desc.capture_type = (*(int*)p->data);
			int suc = CaptureInit(&desc);
			if(suc)
			{
				capret.width = -1;
				capret.height = -1;
			}
			else
			{
				capret.width = desc.width;
				capret.height = desc.height;
			}
			capret.ret = suc;
			CoolCmdSendPacket(p->fd,CMD_CAP_INIT|NMS_CMD_ACK,
						  (void *)(&capret),sizeof(capture_ret_t));
			acked = 1;
		}
		break;	

	case CMD_CAP_GET_FRAME:
		DBGLOG("CMD_CAP_GET_FRAME.");
		{
			frame_desc_t desc;
			int suc = CaptureGetFrame(&desc);
			if(suc)
			{
				CoolCmdSendPacket(p->fd, CMD_CAP_GET_FRAME|NMS_CMD_ACK, 
						  (void *)(&suc), sizeof(int));
			}
			else
			{
				CoolCmdSendPacket(p->fd, CMD_CAP_GET_FRAME|NMS_CMD_ACK, 
						  (void *)(desc.data), desc.size);
				CaptureReleaseFrame();
			}
			acked = 1;
		}
		break;
			
	case CMD_CAP_FINISH:
		DBGLOG("CMD_CAP_FINISH.");
		{
			int suc = CaptureFinish();
			CoolCmdSendPacket(p->fd, CMD_CAP_FINISH|NMS_CMD_ACK, 
						  (void*)&suc, sizeof(int));
			acked = 1;
		}
		break;

	case CMD_PING:
		DBGLOG("CMD_PING.");
		break;

	default:
		/* retain the data for now. */
		WPRINT("unknown command, data retained.");
	    ret = 1; 
		break;
	}
	
	/* send back original command as ack. */
	if (!acked)	
	{
		CoolCmdSendPacket(p->fd, p->hdr.cmd|NMS_CMD_ACK, NULL, 0);
		DBGLOG("server acked.");
	}
	close(p->fd);
	
	/* release data. */
	if ( 0 == ret ) 
	{
		if (p->hdr.dataLen)  free(p->data);
	} 
	
	return ret;
}