[Amis-vcs] SF.net SVN: amis: [2386] branches/amis3/AmisGuiMFC2
Brought to you by:
julienq,
marisademeglio
From: <dan...@us...> - 2008-03-03 05:54:56
|
Revision: 2386 http://amis.svn.sourceforge.net/amis/?rev=2386&view=rev Author: daniel_weck Date: 2008-03-02 21:54:57 -0800 (Sun, 02 Mar 2008) Log Message: ----------- - CreateThread instead of _beginthreadex, in order to match Ambulant's configuration Modified Paths: -------------- branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequencePlayer.h branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp branches/amis3/AmisGuiMFC2/src/gui/self-voicing/directshow/dx_audio_player.cpp Modified: branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequencePlayer.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequencePlayer.h 2008-03-03 05:50:56 UTC (rev 2385) +++ branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequencePlayer.h 2008-03-03 05:54:57 UTC (rev 2386) @@ -27,11 +27,10 @@ class AudioSequencePlayer { -private: +public: string stringReplaceAll(string sourceStr, string searchStr, string replaceStr); void playAudioPrompt(amis::AudioNode* pAudio); -public: static bool InstanceExists(); static AudioSequencePlayer* Instance(); @@ -41,7 +40,7 @@ void TTSAudioEndNotify(); void ClipAudioEndNotify(); void DestroyInstance(); -private: + int m_wakeUpAction; int m_wakeUpOriginator; int m_nEndEventsToExpect; @@ -52,15 +51,12 @@ AudioSequencePlayer(void); ~AudioSequencePlayer(void); - - static unsigned __stdcall ThreadProc( void* pArguments ); HANDLE m_hThread; HANDLE m_hEventWakeup; HANDLE m_hEventEnd; CRITICAL_SECTION m_csSequence; bool m_bAbort; -public: void waitForSequenceEnd(); Modified: branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp 2008-03-03 05:50:56 UTC (rev 2385) +++ branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp 2008-03-03 05:54:57 UTC (rev 2386) @@ -69,7 +69,7 @@ #if _DEBUG //get Visual Leak Detector version 1.0 here: http://dmoulding.googlepages.com/downloads -#include <vld.h> +//#include <vld.h> #endif using namespace amis::gui; @@ -293,7 +293,7 @@ new_data_reader.setAppPath(mAppPath); amis::ErrorCode did_it_work = new_data_reader.readFile(lang_xml_file.get_file(), p_new_data_tree); - if (did_it_work == amis::OK) + if (false && did_it_work == amis::OK) { //test print to an output file //p_new_data_tree->testPrint("c:\\devel\\amis\\Langpacks\\sandbox\\dataout.txt"); Modified: branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp 2008-03-03 05:50:56 UTC (rev 2385) +++ branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp 2008-03-03 05:54:57 UTC (rev 2386) @@ -28,6 +28,246 @@ #define CCS_ACTIVE + + +/* +unsigned __stdcall AudioSequencePlayer::ThreadProc(void* Arg) { +*/ + +DWORD WINAPI ThreadProc(LPVOID Arg) { + USES_CONVERSION; + + _ASSERT(Arg != NULL); + + ULONG nStream; + AudioSequencePlayer* pThis = (AudioSequencePlayer*) Arg; + + AudioSequenceComponent* comp = NULL; + BOOL bEmptyQueue; + + HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + if (hr == S_FALSE) CoUninitialize(); + _ASSERT(hr == S_OK); + + while (! pThis->m_bAbort) + { + + DWORD hr = WaitForSingleObject(pThis->m_hEventWakeup, INFINITE); + switch (hr) { + case WAIT_FAILED: { + int i = 0; + break; + } + + case WAIT_ABANDONED + : { + int i = 0; + break;} + + case WAIT_OBJECT_0 + : { + int i = 0; + break;} + + case WAIT_TIMEOUT: + { + int i = 0; + break; + } + + } + + /* + if (pThis->m_wakeUpOriginator == 0) { + break; + } else if (pThis->m_wakeUpOriginator == 1) { + + if (AmisBrain::Instance()->isAudioClipPlaying()) { + TRACE(L"### STOP AUDIO CLIP"); + ResetEvent(pThis->m_hEventWakeup); + AmisBrain::Instance()->stopAudioClip(); + continue; + } else + if (TTSPlayer::Instance()->IsSpeaking()) { + TRACE(L"### STOP TTS CLIP"); + ResetEvent(pThis->m_hEventWakeup); + TTSPlayer::Instance()->Stop(); + //TTSPlayer::Instance()->WaitUntilDone(); + continue; + } else { + pThis->m_wakeUpOriginator = -1; + } + + } + */ + + /* + if (pThis->m_wakeUpAction == 0) // INTERRUPT PROCESS BEGIN + { + if (pThis->m_wakeUpOriginator != 1) { + TRACE(L"------------ ZZ_1"); + } + + pThis->m_wakeUpAction = 1; // TTS SHUTDOWN + + if (TTSPlayer::Instance()->IsSpeaking()) { + ResetEvent(pThis->m_hEventWakeup); + TTSPlayer::Instance()->Stop(); + TTSPlayer::Instance()->WaitUntilDone(); + } + + //continue; + } + else if (pThis->m_wakeUpAction == 1) // TTS SHUTDOWN + { + + if (pThis->m_wakeUpOriginator != 2) { + TRACE(L"------------ ZZ_2"); + } + + pThis->m_wakeUpAction = 2; // AUDIO CLIP SHUTDOWN + + if (AmisBrain::Instance()->isAudioClipPlaying()) { + ResetEvent(pThis->m_hEventWakeup); + AmisBrain::Instance()->stopAudioClip(); + } + + //continue; + } + else if (pThis->m_wakeUpAction == 2) // AUDIO CLIP SHUTDOWN + { + + if (pThis->m_wakeUpOriginator != 3) { + TRACE(L"------------ ZZ_3"); + } + pThis->m_wakeUpAction = 3; // Nothing to do. Just play normally. + }*/ + + + if (pThis->m_wakeUpOriginator == 0) { + pThis->m_bAbort = true; + continue; + } + + if (pThis->m_currentAudioSequence == NULL && pThis->m_nextAudioSequence == NULL) {continue;} + + bEmptyQueue = FALSE; + { +#ifdef CCS_ACTIVE + EnterCriticalSection(&pThis->m_csSequence); +#endif + + + if (!pThis->m_bAbort && pThis->m_currentAudioSequence != NULL && pThis->m_currentAudioSequence->GetCount() > 0) + { + comp = pThis->m_currentAudioSequence->RemoveTail(); + + /*if (comp!=NULL) + { + + if (comp->m_isAudioClip) { + if (AmisBrain::Instance()->isAudioClipPlaying()) { + pThis->m_currentAudioSequence->AddTail(comp); + } + } else { + if (TTSPlayer::Instance()->IsSpeaking()) { + pThis->m_currentAudioSequence->AddTail(comp); + } + } + }*/ + + if (pThis->m_currentAudioSequence->GetCount() == 0) { + delete pThis->m_currentAudioSequence; + pThis->m_currentAudioSequence = NULL; + } + } + else + { + bEmptyQueue = TRUE; + } + + if (!pThis->m_bAbort && !bEmptyQueue) + { + if (!pThis->m_bAbort && comp!=NULL) + { + + if (!pThis->m_bAbort && comp->m_isAudioClip) { + pThis->m_wakeUpAction = 3; // Nothing to do. Just play normally. + /*if (TTSPlayer::Instance()->IsSpeaking()) { + ResetEvent(pThis->m_hEventWakeup); + TTSPlayer::Instance()->Stop(); + TTSPlayer::Instance()->WaitUntilDone(); + }*/ + + ResetEvent(pThis->m_hEventWakeup); + TRACE(L"\n============ PLAY AUDIO CLIP\n"); + if (!pThis->m_bAbort) { + /* while (ambulantX::gui::dx::audio_playerX::Instance()->isPlaying()) { + TRACE(L"\nIS PLAYING..."); + Sleep(500); + } */ + pThis->playAudioPrompt(comp->m_AudioClip); + } + delete comp; + comp=NULL; + /* + if (!AmisBrain::Instance()->isAudioClipPlaying()) { + AmisBrain::Instance()->playAudioPrompt(comp->m_AudioClip); + } else { + TRACE(L"THIS SHOULD NEVER HAPPEN ! 1"); + }*/ + + } else if (!pThis->m_bAbort) { + pThis->m_wakeUpAction = 3; // Nothing to do. Just play normally. + + /*if (AmisBrain::Instance()->isAudioClipPlaying()) { + ResetEvent(pThis->m_hEventWakeup); + AmisBrain::Instance()->stopAudioClip(); + }*/ + + + ResetEvent(pThis->m_hEventWakeup); + CString strDebug; + strDebug.Format(_T("============ PLAY AUDIO TTS: --%s--\n"), comp->m_String); + TRACE(strDebug); + if (!TTSPlayer::Instance()->IsSpeaking()) { + + //LPCWSTR str = T2W(comp->m_String); + //std::wstring str = (LPCTSTR)comp->m_String.GetBuffer(); + //comp->m_String.ReleaseBuffer(); + TTSPlayer::Instance()->Play(comp->m_String); + delete comp; + comp=NULL; + } else { + TRACE(L"THIS SHOULD NEVER HAPPEN ! 2"); + } + } + } + } else if (!pThis->m_bAbort) { + + if (pThis->m_nextAudioSequence != NULL) { + pThis->m_currentAudioSequence = pThis->m_nextAudioSequence; + pThis->m_nextAudioSequence = NULL; + SetEvent(pThis->m_hEventWakeup); + } else { + pThis->m_wakeUpAction = 3; // Nothing to do. Just play normally. + ResetEvent(pThis->m_hEventWakeup); + SetEvent(pThis->m_hEventEnd); + } + } + +#ifdef CCS_ACTIVE + LeaveCriticalSection(&pThis->m_csSequence); +#endif + } + } // while ... + + CoUninitialize(); + + //_endthreadex( 0 ); + return 0; +} + void AudioSequencePlayer::TTSAudioEndNotify() { if (m_bAbort) { @@ -137,8 +377,10 @@ if (m_hThread == NULL) { - unsigned int threadID; - m_hThread = (HANDLE) _beginthreadex(NULL, 0, ThreadProc, (void*) this, 0, &threadID); + /* + m_hThread = (HANDLE) _beginthreadex(NULL, 0, ThreadProc, (void*) this, 0, &threadID); */ + unsigned long threadID; + m_hThread = CreateThread(NULL, 0, ThreadProc, this, 0, &threadID); _ASSERT(m_hThread != NULL); } @@ -976,239 +1218,3 @@ - - -unsigned __stdcall AudioSequencePlayer::ThreadProc(void* Arg) -{ - USES_CONVERSION; - - _ASSERT(Arg != NULL); - - ULONG nStream; - AudioSequencePlayer* pThis = (AudioSequencePlayer*) Arg; - - AudioSequenceComponent* comp = NULL; - BOOL bEmptyQueue; - - HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - if (hr == S_FALSE) CoUninitialize(); - _ASSERT(hr == S_OK); - - while (! pThis->m_bAbort) - { - - DWORD hr = WaitForSingleObject(pThis->m_hEventWakeup, INFINITE); - switch (hr) { - case WAIT_FAILED: { - int i = 0; - break; - } - - case WAIT_ABANDONED - : { - int i = 0; - break;} - - case WAIT_OBJECT_0 - : { - int i = 0; - break;} - - case WAIT_TIMEOUT: - { - int i = 0; - break; - } - - } - - /* - if (pThis->m_wakeUpOriginator == 0) { - break; - } else if (pThis->m_wakeUpOriginator == 1) { - - if (AmisBrain::Instance()->isAudioClipPlaying()) { - TRACE(L"### STOP AUDIO CLIP"); - ResetEvent(pThis->m_hEventWakeup); - AmisBrain::Instance()->stopAudioClip(); - continue; - } else - if (TTSPlayer::Instance()->IsSpeaking()) { - TRACE(L"### STOP TTS CLIP"); - ResetEvent(pThis->m_hEventWakeup); - TTSPlayer::Instance()->Stop(); - //TTSPlayer::Instance()->WaitUntilDone(); - continue; - } else { - pThis->m_wakeUpOriginator = -1; - } - - } - */ - - /* - if (pThis->m_wakeUpAction == 0) // INTERRUPT PROCESS BEGIN - { - if (pThis->m_wakeUpOriginator != 1) { - TRACE(L"------------ ZZ_1"); - } - - pThis->m_wakeUpAction = 1; // TTS SHUTDOWN - - if (TTSPlayer::Instance()->IsSpeaking()) { - ResetEvent(pThis->m_hEventWakeup); - TTSPlayer::Instance()->Stop(); - TTSPlayer::Instance()->WaitUntilDone(); - } - - //continue; - } - else if (pThis->m_wakeUpAction == 1) // TTS SHUTDOWN - { - - if (pThis->m_wakeUpOriginator != 2) { - TRACE(L"------------ ZZ_2"); - } - - pThis->m_wakeUpAction = 2; // AUDIO CLIP SHUTDOWN - - if (AmisBrain::Instance()->isAudioClipPlaying()) { - ResetEvent(pThis->m_hEventWakeup); - AmisBrain::Instance()->stopAudioClip(); - } - - //continue; - } - else if (pThis->m_wakeUpAction == 2) // AUDIO CLIP SHUTDOWN - { - - if (pThis->m_wakeUpOriginator != 3) { - TRACE(L"------------ ZZ_3"); - } - pThis->m_wakeUpAction = 3; // Nothing to do. Just play normally. - }*/ - - - if (pThis->m_wakeUpOriginator == 0) { - pThis->m_bAbort = true; - continue; - } - - if (pThis->m_currentAudioSequence == NULL && pThis->m_nextAudioSequence == NULL) {continue;} - - bEmptyQueue = FALSE; - { -#ifdef CCS_ACTIVE - EnterCriticalSection(&pThis->m_csSequence); -#endif - - - if (!pThis->m_bAbort && pThis->m_currentAudioSequence != NULL && pThis->m_currentAudioSequence->GetCount() > 0) - { - comp = pThis->m_currentAudioSequence->RemoveTail(); - - /*if (comp!=NULL) - { - - if (comp->m_isAudioClip) { - if (AmisBrain::Instance()->isAudioClipPlaying()) { - pThis->m_currentAudioSequence->AddTail(comp); - } - } else { - if (TTSPlayer::Instance()->IsSpeaking()) { - pThis->m_currentAudioSequence->AddTail(comp); - } - } - }*/ - - if (pThis->m_currentAudioSequence->GetCount() == 0) { - delete pThis->m_currentAudioSequence; - pThis->m_currentAudioSequence = NULL; - } - } - else - { - bEmptyQueue = TRUE; - } - - if (!pThis->m_bAbort && !bEmptyQueue) - { - if (!pThis->m_bAbort && comp!=NULL) - { - - if (!pThis->m_bAbort && comp->m_isAudioClip) { - pThis->m_wakeUpAction = 3; // Nothing to do. Just play normally. - /*if (TTSPlayer::Instance()->IsSpeaking()) { - ResetEvent(pThis->m_hEventWakeup); - TTSPlayer::Instance()->Stop(); - TTSPlayer::Instance()->WaitUntilDone(); - }*/ - - ResetEvent(pThis->m_hEventWakeup); - TRACE(L"\n============ PLAY AUDIO CLIP\n"); - if (!pThis->m_bAbort) { - /* while (ambulantX::gui::dx::audio_playerX::Instance()->isPlaying()) { - TRACE(L"\nIS PLAYING..."); - Sleep(500); - } */ - pThis->playAudioPrompt(comp->m_AudioClip); - } - delete comp; - comp=NULL; - /* - if (!AmisBrain::Instance()->isAudioClipPlaying()) { - AmisBrain::Instance()->playAudioPrompt(comp->m_AudioClip); - } else { - TRACE(L"THIS SHOULD NEVER HAPPEN ! 1"); - }*/ - - } else if (!pThis->m_bAbort) { - pThis->m_wakeUpAction = 3; // Nothing to do. Just play normally. - - /*if (AmisBrain::Instance()->isAudioClipPlaying()) { - ResetEvent(pThis->m_hEventWakeup); - AmisBrain::Instance()->stopAudioClip(); - }*/ - - - ResetEvent(pThis->m_hEventWakeup); - CString strDebug; - strDebug.Format(_T("============ PLAY AUDIO TTS: --%s--\n"), comp->m_String); - TRACE(strDebug); - if (!TTSPlayer::Instance()->IsSpeaking()) { - - //LPCWSTR str = T2W(comp->m_String); - //std::wstring str = (LPCTSTR)comp->m_String.GetBuffer(); - //comp->m_String.ReleaseBuffer(); - TTSPlayer::Instance()->Play(comp->m_String); - delete comp; - comp=NULL; - } else { - TRACE(L"THIS SHOULD NEVER HAPPEN ! 2"); - } - } - } - } else if (!pThis->m_bAbort) { - - if (pThis->m_nextAudioSequence != NULL) { - pThis->m_currentAudioSequence = pThis->m_nextAudioSequence; - pThis->m_nextAudioSequence = NULL; - SetEvent(pThis->m_hEventWakeup); - } else { - pThis->m_wakeUpAction = 3; // Nothing to do. Just play normally. - ResetEvent(pThis->m_hEventWakeup); - SetEvent(pThis->m_hEventEnd); - } - } - -#ifdef CCS_ACTIVE - LeaveCriticalSection(&pThis->m_csSequence); -#endif - } - } // while ... - - CoUninitialize(); - - _endthreadex( 0 ); - return 0; -} \ No newline at end of file Modified: branches/amis3/AmisGuiMFC2/src/gui/self-voicing/directshow/dx_audio_player.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/self-voicing/directshow/dx_audio_player.cpp 2008-03-03 05:50:56 UTC (rev 2385) +++ branches/amis3/AmisGuiMFC2/src/gui/self-voicing/directshow/dx_audio_player.cpp 2008-03-03 05:54:57 UTC (rev 2386) @@ -58,8 +58,9 @@ #define traceX -unsigned __stdcall eventHandler(void* lpParam) { -//static DWORD WINAPI eventHandler(LPVOID lpParam) { +//unsigned __stdcall eventHandler(void* lpParam) { +DWORD __stdcall eventHandler(LPVOID lpParam) { + long lEventCode, lParam1, lParam2; HRESULT hResult = E_FAIL; bool bSelfBreak = false; @@ -85,7 +86,7 @@ } } } - _endthreadex( 0 ); + //_endthreadex( 0 ); return 0; } @@ -678,10 +679,9 @@ } if (hEventHandler == NULL) { - unsigned int lpdwThreadID; - - hEventHandler = (HANDLE) _beginthreadex(NULL, 0, eventHandler, (void*) this, 0, &lpdwThreadID); - //hEventHandler = CreateThread(NULL, 0, eventHandler, this, 0, &lpdwThreadID); + unsigned long lpdwThreadID; + //hEventHandler = (HANDLE) _beginthreadex(NULL, 0, eventHandler, (void*) this, 0, &lpdwThreadID); + hEventHandler = CreateThread(NULL, 0, &eventHandler, this, 0, &lpdwThreadID); } hr = m_media_control->Run(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |