From a23e9e020bfa61ecd22846f2c4d7e0e36674e1de Mon Sep 17 00:00:00 2001 From: "srinivasa.mr" Date: Mon, 17 Jun 2013 20:57:27 +0900 Subject: [PATCH] Add Error coditions to GlesPlayerForm Change-Id: Id6fa3f80c32513998bea3468cbe7d03072dccebe Signed-off-by: srinivasa.mr --- project/src/Audio/GlesCubePlayer.cpp | 252 +++++++++++++++-------------------- project/src/Audio/GlesCubePlayer.h | 38 +----- 2 files changed, 114 insertions(+), 176 deletions(-) diff --git a/project/src/Audio/GlesCubePlayer.cpp b/project/src/Audio/GlesCubePlayer.cpp index 458e655..22345fd 100755 --- a/project/src/Audio/GlesCubePlayer.cpp +++ b/project/src/Audio/GlesCubePlayer.cpp @@ -136,107 +136,11 @@ const GLfloat COLORS[] = 0.0, 0.0, 1.0, 1.0, }; -result -EventThreadTimer::Construct(Tizen::Base::Runtime::ITimerEventListener &listener) -{ - result r; - AppLog("Enter %x", &listener); - __pListener = &listener; - r = EventDrivenThread::Construct(); - AppLog("Enter: %s", GetErrorMessage(r)); - EventDrivenThread::Start(); - return r; -} - -result -EventThreadTimer::Start(int interval) -{ - __interval = interval; - Tizen::Base::Collection::ArrayList *pArg = new (std::nothrow) Tizen::Base::Collection::ArrayList(); - pArg->Construct(1); - pArg->Add(new (std::nothrow) Integer(interval)); - AppLog("Enter %d", interval); - SendUserEvent(EventThreadTimer::REQ_START, pArg); - return E_SUCCESS; -} - -result -EventThreadTimer::StartAsRepeatable(int interval) -{ - result r = E_SUCCESS; - __interval = interval; - Tizen::Base::Collection::ArrayList *pArg = new (std::nothrow ) Tizen::Base::Collection::ArrayList(); - pArg->Construct(1); - pArg->Add(new (std::nothrow) Integer(interval)); - r = SendUserEvent(EventThreadTimer::REQ_START_AS_REPEATABLE, pArg); - AppLog("Enter %d %s", interval, GetErrorMessage(r)); - return E_SUCCESS; -} - -result -EventThreadTimer::Cancel() -{ - AppLog("Enter"); - SendUserEvent(EventThreadTimer::REQ_CANCEL, null); - return E_SUCCESS; -} - -bool -EventThreadTimer::OnStart(void) -{ - result r; - AppLog("Enter"); - r = __timer.Construct(*__pListener); - TryReturn(r == E_SUCCESS, false," [%s]Timer.Construct() failed", GetErrorMessage(r)); - return true; -} - -void -EventThreadTimer::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs) -{ - AppLog("Enter %d %x", requestId, pArgs); - - switch (requestId) - { - case REQ_CONSTRUCT: - break; - case REQ_START: - { - AppLog("REQ_START"); - - Integer *pInt = (Integer*)pArgs->GetAt(0); - int interval = pInt->ToInt(); //pInt->GetValue(); - __timer.Start(interval); - break; - } - case REQ_START_AS_REPEATABLE: - { - Integer *pInt = (Integer*)pArgs->GetAt(0); - int interval = pInt->ToInt(); //pInt->GetValue(); - AppLog("REQ_START_AS_REPEATABLE %d", interval); - __timer.StartAsRepeatable(interval); - break; - } - case REQ_CANCEL: - __timer.Cancel(); - break; - default: - break; - } -} - -void -EventThreadTimer::OnStop(void) -{ - AppLog("Enter"); - __timer.Cancel(); -} - OpenAlPlayer::OpenAlPlayer() { __alBufCount = 0; __alSource = 0; - __openalPlayerState = OPENAL_PLAYER_STATE_INITIALIZED; + __openalPlayerState = OPENAL_PLAYER_STATE_NONE; } OpenAlPlayer::~OpenAlPlayer() { @@ -249,7 +153,32 @@ OpenAlPlayer::~OpenAlPlayer() alDeleteBuffers(__alBufCount, __alBuffers); } } - +result +OpenAlPlayer::ConvertError(ALenum error) +{ + switch(error) + { + case AL_NO_ERROR: + return E_SUCCESS; + break; + case AL_INVALID_NAME: + return E_INVALID_ARG; + break; + case AL_INVALID_ENUM: + return E_OUT_OF_RANGE; + break; + case AL_INVALID_VALUE: + return E_INVALID_ARG; + break; + case AL_INVALID_OPERATION: + return E_INVALID_OPERATION;; + break; + case AL_OUT_OF_MEMORY: + return E_OUT_OF_MEMORY; + default: + return E_FAILURE; + } +} /** * Construct OpenAL based player. * @return An error code @@ -262,9 +191,23 @@ OpenAlPlayer::Construct(const Tizen::Base::String &filePath) { result r = E_SUCCESS; Tizen::Io::FileAttributes attr; + ALenum openAlResult = AL_NO_ERROR; + + alutInit(0,0); + openAlResult = alGetError(); + if (openAlResult != AL_NO_ERROR) + { + AppLog("alutInit Failed with %d", openAlResult); + return ConvertError(openAlResult); + } alGenSources(1, &__alSource); - __streamingMode = false; + openAlResult = alGetError(); + if (openAlResult != AL_NO_ERROR) + { + AppLog("alGenSources Failed with %d", openAlResult); + return ConvertError(openAlResult); + } __channelType = AUDIO_CHANNEL_TYPE_NONE; r = Tizen::Io::File::GetAttributes(filePath, attr); @@ -309,7 +252,6 @@ OpenAlPlayer::Construct(const Tizen::Base::String &filePath) r = __pcmBuf.Construct(MAX_AL_BUFFER_SIZE); TryReturn(r == E_SUCCESS, r, "buffer.Construct:%s %d", GetErrorMessage(r), MAX_AL_BUFFER_SIZE); - __streamingMode = true; __alBufCount = 0; alGenBuffers(MAX_AL_BUFFER_COUNT, __alBuffers); for (int i=0; iGetContentPath(L"GlesCubePlayer", "audioFile")); + TryReturn(r == E_SUCCESS, r, "player.Construct faile with %s", GetErrorMessage(r)); + } + if (__openalPlayerState == OPENAL_PLAYER_STATE_STOPPED) + { __alBufCount = 0; for (int i=0; i< MAX_AL_BUFFER_COUNT; i++) { @@ -376,51 +324,65 @@ OpenAlPlayer::Play() } alSourceQueueBuffers(__alSource, __alBufCount, __alBuffers); - __streamingMode = false; + openAlResult = alGetError(); + if (openAlResult != AL_NO_ERROR) + { + AppLog("alSourceQueueBuffers Failed with %d", openAlResult); + return ConvertError(openAlResult); + } } alSourcePlay(__alSource); + openAlResult = alGetError(); + if (openAlResult != AL_NO_ERROR) + { + AppLog("alSourcePlay Failed with %d", openAlResult); + return ConvertError(openAlResult); + } + __openalPlayerState = OPENAL_PLAYER_STATE_PLAYING; - AppLog("Error Returned - %d", alGetError()); return E_SUCCESS; } result OpenAlPlayer::Stop() { + __srcBuf.SetPosition(0); alSourceStop(__alSource); for (int i=0; i< MAX_AL_BUFFER_COUNT; i++) { ALuint buffer; alSourceUnqueueBuffers(__alSource, 1, &buffer); } - __streamingMode = true; __openalPlayerState = OPENAL_PLAYER_STATE_STOPPED; return E_SUCCESS; } result -OpenAlPlayer::Reset() +OpenAlPlayer::Pause() { - __srcBuf.SetPosition(0); - int queued = MAX_AL_BUFFER_COUNT; - - while (queued-- > 0) + ALenum openAlResult = AL_NO_ERROR; + alSourcePause(__alSource); + openAlResult = alGetError(); + if (openAlResult != AL_NO_ERROR) { - ALuint buffer; - alSourceUnqueueBuffers(__alSource, 1, &buffer); + AppLog("alSourceQueueBuffers Failed with %d", openAlResult); + return ConvertError(openAlResult); } - __streamingMode = true; - __openalPlayerState = OPENAL_PLAYER_STATE_INITIALIZED; + __openalPlayerState = OPENAL_PLAYER_STATE_PAUSED; return E_SUCCESS; } -result -OpenAlPlayer::Pause() +void +OpenAlPlayer::CleanUp(void) { - alSourcePause(__alSource); - __openalPlayerState = OPENAL_PLAYER_STATE_PAUSED; - return E_SUCCESS; + if (__openalPlayerState != OPENAL_PLAYER_STATE_NONE) + { + Quit(); + Join(); + alutExit(); + __openalPlayerState = OPENAL_PLAYER_STATE_NONE; + } } bool @@ -732,10 +694,12 @@ GlesCubePlayerForm::OnTimerExpired(Timer& timer) #else draw=Draw(); #endif - TryLog(draw, "GlesCubePlayerForm::Draw() failed."); - //Update OpenAL Player - player.Update(); + //Update OpenAL Player only if it is in playing state + if (player.GetState() == OpenAlPlayer::OPENAL_PLAYER_STATE_PLAYING) + { + player.Update(); + } } result GlesCubePlayerForm::OnInitializing() @@ -765,10 +729,6 @@ GlesCubePlayerForm::OnInitializing() SetFormBackEventListener(this); - alutInit(0,0); - r = player.Construct(AppConfig::GetInstance()->GetContentPath(L"GlesCubePlayer", "audioFile")); - TryCatch(r == E_SUCCESS, , "playerThread.Construct:%s", GetErrorMessage(r)); - if (__pTimer != null) { __pTimer->StartAsRepeatable(TIME_OUT); @@ -821,9 +781,7 @@ GlesCubePlayerForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source) { AppLog("Cleaning"); Cleanup(); - player.Quit(); - player.Join(); - alutExit(); + player.CleanUp(); __isInitialized = false; } Deactivate(); @@ -852,6 +810,10 @@ GlesCubePlayerForm::OnActionPerformed(const Tizen::Ui::Control& source, int acti ShowFooterItem(PLAY_INDEX, false); ShowFooterItem(STOP_INDEX, true); } + else + { + ShowMessagePopup(String("Error"), String("OpenAL Player Play failed with\n")+ String(GetErrorMessage(r)), ID_ERROR_POPUP); + } break; case ID_STOP: r = player.Stop(); diff --git a/project/src/Audio/GlesCubePlayer.h b/project/src/Audio/GlesCubePlayer.h index 6db4e6f..59c5809 100755 --- a/project/src/Audio/GlesCubePlayer.h +++ b/project/src/Audio/GlesCubePlayer.h @@ -36,32 +36,9 @@ #define MIN_STREAMING_MODE_SIZE (1024*256) // 256kb -class EventThreadTimer - : public Tizen::Base::Runtime::EventDrivenThread -{ -public: - EventThreadTimer() {} - virtual ~EventThreadTimer() {} - result Construct(Tizen::Base::Runtime::ITimerEventListener &listener); - result Start(int interval); - result StartAsRepeatable(int interval); - result Cancel(); - -protected: - static const int REQ_CONSTRUCT = 100; - static const int REQ_START = 101; - static const int REQ_START_AS_REPEATABLE = 102; - static const int REQ_CANCEL = 103; - - virtual bool OnStart(void); - virtual void OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs); - virtual void OnStop(void); - -private: - Tizen::Base::Runtime::ITimerEventListener *__pListener; - Tizen::Base::Runtime::Timer __timer; - int __interval; -}; +/* Note presently OpenAL Player does not use EventDriven Thread and ITimerEventListner + * But this is necessary to keep it to test the performance in those conditions too + */ class OpenAlPlayer : public Tizen::Base::Runtime::EventDrivenThread @@ -69,6 +46,7 @@ class OpenAlPlayer { public: enum OpenAlPlayerState{ + OPENAL_PLAYER_STATE_NONE, OPENAL_PLAYER_STATE_INITIALIZED, OPENAL_PLAYER_STATE_PLAYING, OPENAL_PLAYER_STATE_PAUSED, @@ -79,9 +57,9 @@ public: result Construct(const Tizen::Base::String &filePath); result Play(void); result Stop(void); - result Reset(void); - bool Update(void); result Pause(void); + void CleanUp(void); + bool Update(void); OpenAlPlayerState GetState(void){return __openalPlayerState;} protected: static const int REQ_UPDATE_QUEUE = 101; @@ -90,7 +68,7 @@ protected: virtual void OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs); virtual void OnStop(void) {} void OnTimerExpired(Tizen::Base::Runtime::Timer& timer); - + result ConvertError(ALenum error); bool UpdateQueue(); int FillAlBuffer(ALuint alBuffer); private: @@ -101,12 +79,10 @@ private: Tizen::Base::ByteBuffer __srcBuf; Tizen::Base::ByteBuffer __pcmBuf; std::unique_ptr __pDec; - bool __streamingMode; Tizen::Media::CodecType __codecType; Tizen::Media::AudioChannelType __channelType; Tizen::Media::AudioSampleType __sampleType; int __sampleRate; - bool __eof; OpenAlPlayerState __openalPlayerState; }; -- 2.7.4