2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include <FBaseColArrayListT.h>
20 #include <FBaseColHashMap.h>
21 #include <FBaseColHashMapT.h>
22 #include <FMediaTypes.h>
23 #include <FBaseSysLog.h>
24 #include "FMedia_IVideoDecoder.h"
25 #include "FMedia_VideoDecoderImpl.h"
26 #include "FMedia_CodecFactory.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
31 namespace Tizen { namespace Media
34 _VideoDecoderImpl::_VideoDecoderImpl(void)
39 _VideoDecoderImpl::~_VideoDecoderImpl(void)
48 _VideoDecoderImpl::Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption)
50 _IVideoDecoder* pVideoDecoder = null;
51 _CodecFactory* pCodecFactory = null;
54 SysTryReturnResult(NID_MEDIA, !__pDec, E_INVALID_STATE, "already constructed");
55 pCodecFactory = _CodecFactory::GetInstance();
56 SysTryCatch(NID_MEDIA, null != pCodecFactory, r = E_SYSTEM, E_SYSTEM,
58 r = pCodecFactory->CreateCodecInstance(type, pVideoDecoder);
59 SysTryCatch(NID_MEDIA, pVideoDecoder != null, , r, "Construct Failed ");
60 __pDec = pVideoDecoder;
61 r = __pDec->Construct(pOption);
62 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "Construct Failed ");
75 _VideoDecoderImpl::Probe(const Tizen::Base::ByteBuffer& srcBuf, int& width, int& height, MediaPixelFormat& pixelFormat)
78 const byte* pSrcByteBuf = null;
79 int srcByteBufSize = 0;
81 SysTryReturnResult(NID_MEDIA, __pDec, E_INVALID_STATE, "not constructed");
82 pSrcByteBuf = srcBuf.GetPointer() + srcBuf.GetPosition();
83 SysTryCatch(NID_MEDIA, null != pSrcByteBuf, r = E_INVALID_ARG, E_INVALID_ARG,
84 "[E_INVALID_ARG] Probe Failed ");
85 srcByteBufSize = srcBuf.GetRemaining();
87 SysTryCatch(NID_MEDIA, srcByteBufSize > 0, r = E_INVALID_ARG, E_INVALID_ARG,
88 "[E_INVALID_ARG] Probe Failed ");
89 r = __pDec->Probe(pSrcByteBuf, srcByteBufSize, width, height, pixelFormat);
90 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "Probe Failed ");
98 _VideoDecoderImpl::Probe(const byte* pSrcBuf, int srcBugLength, int& width, int& height, MediaPixelFormat& pixelFormat)
100 result r = E_SUCCESS;
102 SysTryReturnResult(NID_MEDIA, __pDec, E_INVALID_STATE, "not constructed");
103 r = __pDec->Probe(pSrcBuf, srcBugLength, width, height, pixelFormat);
104 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "Probe Failed ");
112 _VideoDecoderImpl::Decode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf, bool& gotFrame)
114 result r = E_INVALID_STATE;
115 const byte* pSrcByte = null;
116 byte* pDstByte = null;
121 SysTryReturnResult(NID_MEDIA, __pDec, E_INVALID_STATE, "not constructed");
122 pSrcByte = srcBuf.GetPointer() + srcBuf.GetPosition();
123 pDstByte = (byte*) dstBuf.GetPointer() + dstBuf.GetPosition();
124 SysTryCatch(NID_MEDIA, (null != pDstByte && null != pSrcByte), r = E_INVALID_ARG, E_INVALID_ARG,
125 "[E_INVALID_ARG] Decode Failed ");
126 srcByteSize = srcBuf.GetRemaining();
127 dstByteSize = dstBuf.GetRemaining();
128 SysTryCatch(NID_MEDIA, (srcByteSize > 0 && dstByteSize > 0), r = E_INVALID_ARG, E_INVALID_ARG,
129 "[E_INVALID_ARG] Decode Failed ");
131 r = __pDec->Decode(pSrcByte, srcByteSize, pDstByte, dstByteSize, gotFrame);
132 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r,
135 offset = srcBuf.GetPosition();
136 if (offset + srcByteSize > srcBuf.GetLimit())
138 srcBuf.SetPosition(srcBuf.GetLimit());
142 srcBuf.SetPosition(offset + srcByteSize);
145 offset = dstBuf.GetPosition();
146 if (offset + dstByteSize > dstBuf.GetLimit())
148 dstBuf.SetPosition(dstBuf.GetLimit());
152 dstBuf.SetPosition(offset + dstByteSize);
162 _VideoDecoderImpl::Decode(const byte* pSrcBuf, int& srcBufLength, byte* pDstBuf, int& dstBufLength, bool& gotFrame)
164 result r = E_SUCCESS;
166 SysTryReturnResult(NID_MEDIA, __pDec, E_INVALID_STATE, "not constructed");
167 r = __pDec->Decode(pSrcBuf, srcBufLength, pDstBuf, dstBufLength, gotFrame);
168 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Decode Failed", GetErrorMessage(r));
176 _VideoDecoderImpl::Reset(void)
178 result r = E_SUCCESS;
180 SysTryReturnResult(NID_MEDIA, __pDec, E_INVALID_STATE, "not constructed");
183 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Reset Failed", GetErrorMessage(r));
191 _VideoDecoderImpl::GetValue(MediaPropertyType key, int& value) const
193 result r = E_SUCCESS;
195 SysTryReturnResult(NID_MEDIA, __pDec, E_INVALID_STATE, "not constructed");
196 r = __pDec->GetValue(key, value);
197 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "Probe Failed ");
205 _VideoDecoderImpl::GetValue(MediaPropertyType key, float& value) const
207 result r = E_SUCCESS;
209 SysTryReturnResult(NID_MEDIA, __pDec, E_INVALID_STATE, "not constructed");
210 r = __pDec->GetValue(key, value);
211 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] GetValue Failed", GetErrorMessage(r));
218 Tizen::Base::Collection::IListT<MediaPropertyType>*
219 _VideoDecoderImpl::GetSupportedPropertyListN(void) const
221 SysTryReturn(NID_MEDIA, __pDec, null, E_INVALID_STATE, "[E_INVALID_STATE] not constructed");
223 return __pDec->GetSupportedPropertyListN();
227 _VideoDecoderImpl::IsPropertySupported(MediaPropertyType key) const
229 SysTryReturn(NID_MEDIA, __pDec, false, E_INVALID_STATE, "[E_INVALID_STATE] not constructed");
230 return __pDec->IsPropertySupported(key);
233 Tizen::Base::Collection::IListT<CodecType>*
234 _VideoDecoderImpl::GetSupportedCodecListN(void)
236 _CodecFactory* pFactory = null;
237 Tizen::Base::Collection::IListT<CodecType>* pList = null;
239 pFactory = _CodecFactory::GetInstance();
240 SysTryReturn(NID_MEDIA, pFactory != null, null, E_OUT_OF_MEMORY, "[%s] Propagated.",
241 GetErrorMessage(GetLastResult()));
242 pList = pFactory->GetSupportedVideoDecoderListN();
243 SysTryReturn(NID_MEDIA, pList != null, null, E_OUT_OF_MEMORY, "[%s] Propagated.",
244 GetErrorMessage(GetLastResult()));
245 SetLastResult(E_SUCCESS);