From 8d189e5d7b7ff56e47fffbebc319fe435430187b Mon Sep 17 00:00:00 2001 From: mamata pattanaik Date: Sat, 16 Mar 2013 15:05:21 +0530 Subject: [PATCH] Changes to stop DecodeUrl activity when Image object is deleted. Change-Id: If7b53051aae6f5c8daddadfb8fd1a7393dc16aca Signed-off-by: mamata pattanaik --- src/FMedia_ImageImpl.cpp | 35 +++++++++++++++++++++ src/FMedia_ImageUriDataFactory.cpp | 63 ++++++++++++++++++++++++++++++++++++++ src/FMedia_ImageUriDataFactory.h | 1 + src/inc/FMedia_ImageImpl.h | 1 + 4 files changed, 100 insertions(+) diff --git a/src/FMedia_ImageImpl.cpp b/src/FMedia_ImageImpl.cpp index a89f3ff..28a1ba3 100644 --- a/src/FMedia_ImageImpl.cpp +++ b/src/FMedia_ImageImpl.cpp @@ -56,10 +56,37 @@ static const int _MAX_ENCODE_RESIZE_LOOP = 2; _ImageImpl::_ImageImpl(void) { + __pUrlReqIDList.reset(null); } _ImageImpl::~_ImageImpl(void) { + _ImageUriDataFactory *pFactory = null; + + pFactory = _ImageUriDataFactory::GetInstance(); + SysTryReturn(NID_MEDIA, pFactory != null, , GetLastResult(), "[%s] Failed to get Factory instance.", + GetErrorMessage(GetLastResult())); + + if (__pUrlReqIDList.get() != null) + { + int num = 0; + Object* pObj = null; + + // free the memory + num = __pUrlReqIDList->GetCount(); + for (int i = 0; i < num; i++) + { + pObj = __pUrlReqIDList->GetAt(i); + if (pObj != null) + { + Integer *pValue = dynamic_cast(pObj); + RequestId reqId = (RequestId)(pValue->ToInt()); + + pFactory->Remove(reqId); + } + } + __pUrlReqIDList->RemoveAll(true); + } } _ImageImpl* @@ -350,6 +377,14 @@ _ImageImpl::DecodeUrl(const Tizen::Base::Utility::Uri& srcImageUrl, r = pFactory->DecodeUrl(srcImageUrl, colorFormat, destWidth,destHeight, reqId, listener, timeout); SysTryCatch(NID_MEDIA, r == E_SUCCESS , , r,"[%s] Propagated.", GetErrorMessage(r)); + if (__pUrlReqIDList.get() == null) + { + __pUrlReqIDList.reset(new (std::nothrow)Collection::LinkedList()); + SysTryCatch(NID_MEDIA, __pUrlReqIDList.get() != null, r = E_OUT_OF_MEMORY, r, + "[E_OUT_OF_MEMORY] Propagated. Failed to allocate a LinkedList.", GetErrorMessage(r)); + } + __pUrlReqIDList->Add(new (std::nothrow) Integer(reqId)); + return r; CATCH: diff --git a/src/FMedia_ImageUriDataFactory.cpp b/src/FMedia_ImageUriDataFactory.cpp index 730415f..e7b9605 100644 --- a/src/FMedia_ImageUriDataFactory.cpp +++ b/src/FMedia_ImageUriDataFactory.cpp @@ -309,6 +309,69 @@ _ImageUriDataFactory::OnMediaSessionEnded(RequestId requestId) Watchout(); } +void +_ImageUriDataFactory::Remove(RequestId reqId) +{ + Object* pObj = null; + int num = 0; + bool deleted = false; + result r = E_SUCCESS; + + // Remove ImageUriData for this request id from the working list. + num = __pImageUriDataWorkingList->GetCount(); + for (int i = 0; i < num; i++) + { + pObj = __pImageUriDataWorkingList->GetAt(i); + if (pObj != null) + { + _ImageUriData* pImageUriData = dynamic_cast<_ImageUriData*>(pObj); + if (pImageUriData != null) + { + if (reqId == pImageUriData->GetRequestId()) + { + pImageUriData->Cancel(reqId, r); + __pImageUriDataWorkingList->RemoveAt(i, true); + deleted = true; + break; + } + } + } + } + + // If ImageUriData for this request id is not present in working list, + // remove it from the holder queue. + if (deleted != true) + { + num = __pImageUriDataHolderQueue->GetCount(); + for (int i = 0; i < num; i++) + { + // Dequeue elements one by one to check for reqId. + pObj = __pImageUriDataHolderQueue->Dequeue(); + if (pObj != null) + { + _ImageUriData* pImageUriData = dynamic_cast<_ImageUriData*>(pObj); + if (pImageUriData != null) + { + if (reqId == pImageUriData->GetRequestId()) + { + pImageUriData->Cancel(reqId, r); + delete pImageUriData; + deleted = true; + break; + } + // if Dequeued data does not have the same reqId, Enqueue is again. + __pImageUriDataHolderQueue->Enqueue(*pObj); + } + } + } + } + + if(deleted != true) + { + SysLog(NID_MEDIA, "Could not find ReqId %ld in both queues!!", reqId); + } +} + int _ImageUriDataFactory::GetHolderCount(void) { diff --git a/src/FMedia_ImageUriDataFactory.h b/src/FMedia_ImageUriDataFactory.h index cd7df71..ee9bfc3 100644 --- a/src/FMedia_ImageUriDataFactory.h +++ b/src/FMedia_ImageUriDataFactory.h @@ -47,6 +47,7 @@ public: int GetHolderCount(void); int GetWorkerCount(void); + void Remove(RequestId reqId); void OnMediaSessionEnded(RequestId requestId); diff --git a/src/inc/FMedia_ImageImpl.h b/src/inc/FMedia_ImageImpl.h index 48ce65c..b61894d 100644 --- a/src/inc/FMedia_ImageImpl.h +++ b/src/inc/FMedia_ImageImpl.h @@ -245,6 +245,7 @@ private: // Tizen::Graphics::Dimension& destDim); // + std::unique_ptr __pUrlReqIDList; _ImageImpl(const _ImageImpl& impl); _ImageImpl& operator =(const _ImageImpl& impl); -- 2.7.4