issue #880: playEffect repeatly can't work on bada platform

This commit is contained in:
dumganhar 2011-11-28 15:49:37 +08:00
parent cad4ff05f3
commit 55d9beb92e
2 changed files with 65 additions and 51 deletions

View File

@ -104,7 +104,7 @@ int CCAudioOut::DecodeOgg(const char *infile)
if(ov_seekable(&vf)) { if(ov_seekable(&vf)) {
seekable = 1; seekable = 1;
length = ov_pcm_total(&vf, 0); length = ov_pcm_total(&vf, 0);
size = bits/8 * ov_info(&vf, 0)->channels; size = 16/8 * ov_info(&vf, 0)->channels;
} }
//AppLog("enter"); //AppLog("enter");
if (ov_info(&vf,0)->channels == 2) if (ov_info(&vf,0)->channels == 2)
@ -120,13 +120,13 @@ int CCAudioOut::DecodeOgg(const char *infile)
__sampleBitdepth = AUDIO_TYPE_PCM_S16_LE; __sampleBitdepth = AUDIO_TYPE_PCM_S16_LE;
//AppLog("enter"); //AppLog("enter");
while((ret = ov_read(&vf, buf, buflen, endian, bits/8, sign, &bs)) != 0) { while((ret = ov_read(&vf, buf, buflen, 0, 16/8, 1, &bs)) != 0) {
if(bs != 0) { if(bs != 0) {
//AppLog("Only one logical bitstream currently supported\n"); //AppLog("Only one logical bitstream currently supported\n");
break; break;
} }
if(ret < 0 && !quiet) { if(ret < 0) {
//AppLog("Warning: hole in data\n"); //AppLog("Warning: hole in data\n");
continue; continue;
} }
@ -143,7 +143,7 @@ int CCAudioOut::DecodeOgg(const char *infile)
memcpy(__pAllPcmBuffer+written, buf, ret); memcpy(__pAllPcmBuffer+written, buf, ret);
written += ret; written += ret;
if(!quiet && seekable) { if(seekable) {
done += ret/size; done += ret/size;
if((double)done/(double)length * 200. > (double)percent) { if((double)done/(double)length * 200. > (double)percent) {
percent = (double)done/(double)length *200; percent = (double)done/(double)length *200;
@ -178,17 +178,14 @@ CCAudioOut::CCAudioOut()
__iAllPcmBufferSize = 0; __iAllPcmBufferSize = 0;
__iAllPcmPos = 0; __iAllPcmPos = 0;
__pAudioOut = null; __pAudioOut = null;
quiet = 0;
bits = 16;
endian = 0;
raw = 0;
sign = 1;
__iFileType = 0; __iFileType = 0;
__pFile = null; __pFile = null;
__bShortPcmBuffer = false; __bShortPcmBuffer = false;
__bBufferConstruted = false; __bBufferConstruted = false;
__checkInitFiniPair = false; __checkInitFiniPair = false;
__iUsedBufferCount = 0; __iUsedBufferCount = 0;
__bLoop = false;
__bPause = false;
} }
CCAudioOut::~CCAudioOut() CCAudioOut::~CCAudioOut()
@ -516,43 +513,24 @@ void CCAudioOut::ReFeedBuffer(void)
} }
} }
result CCAudioOut::Play(void) result CCAudioOut::Play(bool bLoop/* = false*/)
{ {
//AppLog("Enter");
result ret = E_FAILURE; result ret = E_FAILURE;
AudioOutState state = __pAudioOut->GetState(); AudioOutState state = __pAudioOut->GetState();
if(state == AUDIOOUT_STATE_PREPARED || state == AUDIOOUT_STATE_STOPPED) if(state == AUDIOOUT_STATE_PREPARED || state == AUDIOOUT_STATE_STOPPED)
{ {
//AppLog("Enter"); __bLoop = bLoop;
ret = __pAudioOut->Start(); ret = __pAudioOut->Start();
if (IsFailed(ret)) if (IsFailed(ret))
{ {
//AppLog("[Error] m_AudioOut.Start failed : %d\n", ret); AppLog("[Error] m_AudioOut.Start failed : %d\n", ret);
} }
} }
return ret; return ret;
} }
result CCAudioOut::Stop(void) result CCAudioOut::Stop(void)
{
//AppLog("Enter");
result ret = E_FAILURE;
if( __pAudioOut->GetState() == AUDIOOUT_STATE_PLAYING )
{
ret = __pAudioOut->Stop();
if (IsFailed(ret))
{
//AppLog("[Error] m_AudioOut.Stop failed : %d\n", ret);
}
}
return ret;
}
result CCAudioOut::Reset(void)
{ {
//AppLog("Enter"); //AppLog("Enter");
AudioOutState state = __pAudioOut->GetState(); AudioOutState state = __pAudioOut->GetState();
@ -572,6 +550,40 @@ result CCAudioOut::Reset(void)
return r; return r;
} }
result CCAudioOut::Pause(void)
{
result ret = E_FAILURE;
if( __pAudioOut->GetState() == AUDIOOUT_STATE_PLAYING )
{
__bPause = true;
ret = __pAudioOut->Stop();
if (IsFailed(ret))
{
AppLog("[Error] m_AudioOut.Stop failed : %d\n", ret);
}
}
return ret;
}
result CCAudioOut::Resume(void)
{
result ret = E_FAILURE;
if(__bPause && __pAudioOut->GetState() == AUDIOOUT_STATE_STOPPED )
{
__bPause = false;
ret = __pAudioOut->Start();
if (IsFailed(ret))
{
AppLog("[Error] m_AudioOut.Stop failed : %d\n", ret);
}
}
return ret;
}
void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src) void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
{ {
if (__bShortPcmBuffer) if (__bShortPcmBuffer)
@ -579,13 +591,16 @@ void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
__iUsedBufferCount--; __iUsedBufferCount--;
if (__iUsedBufferCount <= 0) if (__iUsedBufferCount <= 0)
{ {
Reset(); Stop();
//AppLog("Reset..."); if (__bLoop)
{
Play(__bLoop);
}
} }
} }
else else
{ {
int ret; int ret = 0;
// //AppLog("thread name is %S", Thread::GetCurrentThread()->GetName().GetPointer()); // //AppLog("thread name is %S", Thread::GetCurrentThread()->GetName().GetPointer());
//AppLog("__buffReadCnt = %d", __buffReadCnt); //AppLog("__buffReadCnt = %d", __buffReadCnt);
__byteBuffer[__buffReadCnt++].Clear (); __byteBuffer[__buffReadCnt++].Clear ();
@ -607,11 +622,14 @@ void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
__finishChecker--; __finishChecker--;
if(__finishChecker == 0) if(__finishChecker == 0)
{ {
//AppLog("Reset..."); Stop();
Reset();
__bufWrittenCnt = PRE_BUFFERING_NUM; __bufWrittenCnt = PRE_BUFFERING_NUM;
__buffReadCnt = 0; __buffReadCnt = 0;
__buffWriteCnt = 0; __buffWriteCnt = 0;
if (__bLoop)
{
Play(__bLoop);
}
} }
} }
} }
@ -620,19 +638,16 @@ void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
void CCAudioOut::OnAudioOutInterrupted(Osp::Media::AudioOut& src) void CCAudioOut::OnAudioOutInterrupted(Osp::Media::AudioOut& src)
{ {
//AppLog("Enter"); Pause();
Reset();
} }
void CCAudioOut::OnAudioOutReleased(Osp::Media::AudioOut& src) void CCAudioOut::OnAudioOutReleased(Osp::Media::AudioOut& src)
{ {
//AppLog("Enter"); Resume();
} }
void CCAudioOut::Finalize(void) void CCAudioOut::Finalize(void)
{ {
//AppLog("Enter");
if(__checkInitFiniPair) if(__checkInitFiniPair)
{ {
@ -650,7 +665,7 @@ void CCAudioOut::Finalize(void)
r = __pAudioOut->Reset(); r = __pAudioOut->Reset();
if(IsFailed(r)) if(IsFailed(r))
{ {
//AppLog("[Error] AudioOut Reset is failed"); AppLog("[Error] AudioOut Reset is failed");
} }
} }
@ -662,7 +677,7 @@ void CCAudioOut::Finalize(void)
r = __pAudioOut->Unprepare(); r = __pAudioOut->Unprepare();
if(IsFailed(r)) if(IsFailed(r))
{ {
//AppLog("[Error] AudioOut UnPrepare is failed"); AppLog("[Error] AudioOut UnPrepare is failed");
} }
} }
} }
@ -675,7 +690,7 @@ void CCAudioOut::Finalize(void)
__checkInitFiniPair = false; __checkInitFiniPair = false;
}else{ }else{
//AppLog("[WANRNING] This application state is not proper"); AppLog("[WANRNING] This application state is not proper");
} }
} }

View File

@ -26,9 +26,11 @@ public:
void ReFeedBuffer(void); void ReFeedBuffer(void);
void Finalize(void); void Finalize(void);
result Play(void); result Play(bool bLoop = false);
result Stop(void); result Stop(void);
result Reset(void); result Pause(void);
result Resume(void);
void SetVolume(int volume); void SetVolume(int volume);
int GetVolume(void) const; int GetVolume(void) const;
Osp::Media::AudioOutState GetState(void) const; Osp::Media::AudioOutState GetState(void) const;
@ -54,11 +56,8 @@ private:
char* __pAllPcmBuffer; char* __pAllPcmBuffer;
int __iAllPcmBufferSize; int __iAllPcmBufferSize;
int __iAllPcmPos; int __iAllPcmPos;
int quiet; bool __bLoop;
int bits; bool __bPause;
int endian;
int raw;
int sign;
}; };
} }