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_IVideoEncoder.h"
25 #include "FMedia_CodecFactory.h"
26 #include "FMedia_VideoEncoderImpl.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
31 namespace Tizen { namespace Media
34 _VideoEncoderImpl::_VideoEncoderImpl(void)
39 _VideoEncoderImpl::~_VideoEncoderImpl(void)
48 _VideoEncoderImpl::Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption)
50 _IVideoEncoder* pVideoEncoder = null;
51 _CodecFactory* pCodecFactory = null;
54 SysTryReturnResult(NID_MEDIA, __pEnc == null, E_INVALID_STATE, "already constructed");
56 pCodecFactory = _CodecFactory::GetInstance();
57 SysTryCatch(NID_MEDIA, pCodecFactory != null, r = E_SYSTEM, E_SYSTEM,
59 r = pCodecFactory->CreateCodecInstance(type, pVideoEncoder);
60 SysTryCatch(NID_MEDIA, pVideoEncoder != null, , r, "Construct Failed:%d", type);
61 __pEnc = pVideoEncoder;
62 r = __pEnc->Construct(pOption);
63 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s]Construct Failed ", GetErrorMessage(r));
76 _VideoEncoderImpl::Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf)
78 result r = E_INVALID_STATE;
79 const byte* pSrcByte = null;
80 byte* pDstByte = null;
85 SysTryReturnResult(NID_MEDIA, __pEnc, E_INVALID_STATE, "not constructed");
87 pSrcByte = srcBuf.GetPointer() + srcBuf.GetPosition();
88 pDstByte = (byte*) dstBuf.GetPointer() + dstBuf.GetPosition();
89 SysTryCatch(NID_MEDIA, (null != pDstByte && null != pSrcByte), r = E_INVALID_ARG, E_INVALID_ARG,
90 "[E_INVALID_ARG] Encode Failed ");
91 srcByteSize = srcBuf.GetRemaining();
92 dstByteSize = dstBuf.GetRemaining();
93 SysTryCatch(NID_MEDIA, (srcByteSize > 0 && dstByteSize > 0), r = E_INVALID_ARG, E_INVALID_ARG,
94 "[E_INVALID_ARG] Encode Failed ");
96 r = __pEnc->Encode(pSrcByte, srcByteSize, pDstByte, dstByteSize);
97 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r,
98 "[%s] Encode Failed", GetErrorMessage(r));
100 offset = srcBuf.GetPosition();
101 if (offset + srcByteSize > srcBuf.GetLimit())
103 srcBuf.SetPosition(srcBuf.GetLimit());
107 srcBuf.SetPosition(offset + srcByteSize);
110 offset = dstBuf.GetPosition();
111 if (offset + dstByteSize > dstBuf.GetLimit())
113 dstBuf.SetPosition(dstBuf.GetLimit());
117 dstBuf.SetPosition(offset + dstByteSize);
127 _VideoEncoderImpl::Encode(const byte* srcBuf, int& srcBufLength, byte* dstBuf, int& dstBufLength)
129 result r = E_SUCCESS;
131 SysTryReturnResult(NID_MEDIA, __pEnc, E_INVALID_STATE, "not constructed");
133 r = __pEnc->Encode(srcBuf, srcBufLength, dstBuf, dstBufLength);
134 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r,
135 "[%s] Encode Failed", GetErrorMessage(r));
144 _VideoEncoderImpl::Reset(void)
146 result r = E_SUCCESS;
148 SysTryReturnResult(NID_MEDIA, __pEnc, E_INVALID_STATE, "not constructed");
151 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Reset Failed", GetErrorMessage(r));
160 _VideoEncoderImpl::SetValue(MediaPropertyType key, int value)
162 result r = E_SUCCESS;
164 SysTryReturnResult(NID_MEDIA, __pEnc, E_INVALID_STATE, "not constructed");
166 r = __pEnc->SetValue(key, value);
167 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] SetValue Failed", GetErrorMessage(r));
176 _VideoEncoderImpl::SetValue(MediaPropertyType key, bool value)
178 result r = E_SUCCESS;
180 SysTryReturnResult(NID_MEDIA, __pEnc, E_INVALID_STATE, "not constructed");
182 r = __pEnc->SetValue(key, value);
183 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] SetValue Failed", GetErrorMessage(r));
191 Tizen::Base::Collection::IListT<MediaPropertyType>*
192 _VideoEncoderImpl::GetSupportedPropertyListN(void) const
194 SysTryReturn(NID_MEDIA, __pEnc, null, E_INVALID_STATE, "[E_INVALID_STATE] not constructed");
196 return __pEnc->GetSupportedPropertyListN();
200 _VideoEncoderImpl::IsPropertySupported(MediaPropertyType key) const
202 SysTryReturnResult(NID_MEDIA, __pEnc, E_INVALID_STATE, "not constructed");
204 return __pEnc->IsPropertySupported(key);
207 Tizen::Base::Collection::IListT<CodecType>*
208 _VideoEncoderImpl::GetSupportedCodecListN(void)
210 _CodecFactory* pFactory = null;
211 Tizen::Base::Collection::IListT<CodecType>* pList = null;
213 pFactory = _CodecFactory::GetInstance();
214 SysTryReturn(NID_MEDIA, pFactory != null, null, E_OUT_OF_MEMORY, "[%s] Propagated.",
215 GetErrorMessage(GetLastResult()));
216 pList = pFactory->GetSupportedVideoEncoderListN();
217 SysTryReturn(NID_MEDIA, pList != null, null, E_OUT_OF_MEMORY, "[%s] Propagated.",
218 GetErrorMessage(GetLastResult()));
219 SetLastResult(E_SUCCESS);