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 <FMediaAudioTypes.h>
24 #include <FBaseSysLog.h>
25 #include "FMedia_IAudioEncoder.h"
26 #include "FMedia_CodecFactory.h"
27 #include "FMedia_AudioEncoderImpl.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
33 namespace Tizen { namespace Media
36 _AudioEncoderImpl::_AudioEncoderImpl(void)
41 _AudioEncoderImpl::~_AudioEncoderImpl(void)
50 _AudioEncoderImpl::Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption)
52 _CodecFactory* pFactory = null;
55 SysTryReturnResult(NID_MEDIA, __pEnc == null, E_INVALID_STATE, "already constructed");
56 pFactory = _CodecFactory::GetInstance();
57 SysTryCatch(NID_MEDIA, pFactory != null, r = E_SYSTEM, E_SYSTEM,
58 "[%s] Failed to get Codec Factory Instance",GetErrorMessage(E_SYSTEM));
\r
59 r = pFactory->CreateCodecInstance(type, __pEnc);
60 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] CodecFactory failed to create Codec Instance", GetErrorMessage(r));
\r
61 r = __pEnc->Construct(pOption);
62 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Failed to construct __pEnc", GetErrorMessage(r));
\r
75 _AudioEncoderImpl::Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf)
77 result r = E_INVALID_STATE;
78 const byte* pSrcByte = null;
79 byte* pDstByte = null;
84 SysTryReturnResult(NID_MEDIA, __pEnc, E_INVALID_STATE, "not constructed");
85 pSrcByte = srcBuf.GetPointer() + srcBuf.GetPosition();
86 pDstByte = (byte*) dstBuf.GetPointer() + dstBuf.GetPosition();
87 SysTryCatch(NID_MEDIA, pDstByte != null && pSrcByte != null, r = E_INVALID_ARG, E_INVALID_ARG,
88 "[%s] Invalid argument is used. srcBuf:%x dstBuf:%d", GetErrorMessage(E_INVALID_ARG), pSrcByte, pDstByte);
\r
89 srcByteSize = srcBuf.GetRemaining();
90 dstByteSize = dstBuf.GetRemaining();
91 SysTryCatch(NID_MEDIA, srcByteSize > 0 && dstByteSize > 0, r = E_INVALID_ARG, E_INVALID_ARG,
92 "[%s] Invalid argument is used. srcSize:%d dstSize:%d", GetErrorMessage(E_INVALID_ARG), srcByteSize, dstByteSize);
\r
94 r = __pEnc->Encode(pSrcByte, srcByteSize, pDstByte, dstByteSize);
95 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Audio Encoder encode failed", GetErrorMessage(r));
\r
97 offset = srcBuf.GetPosition();
98 if (offset + srcByteSize > srcBuf.GetLimit())
100 srcBuf.SetPosition(srcBuf.GetLimit());
104 srcBuf.SetPosition(offset + srcByteSize);
107 offset = dstBuf.GetPosition();
108 if (offset + dstByteSize > dstBuf.GetLimit())
110 dstBuf.SetPosition(dstBuf.GetLimit());
114 dstBuf.SetPosition(offset + dstByteSize);
124 _AudioEncoderImpl::Encode(const byte* srcBuf, int& srcBufLength, byte*& dstBuf, int& dstBufLength)
126 result r = E_SUCCESS;
128 SysTryReturnResult(NID_MEDIA, __pEnc, E_INVALID_STATE, "not constructed");
129 r = __pEnc->Encode(srcBuf, srcBufLength, dstBuf, dstBufLength);
130 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Audio Encoder encode failed", GetErrorMessage(r));
\r
138 _AudioEncoderImpl::Reset(void)
140 result r = E_SUCCESS;
142 SysTryReturnResult(NID_MEDIA, __pEnc, E_INVALID_STATE, "not constructed");
144 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Audio Encoder reset failed", GetErrorMessage(r));
\r
151 Tizen::Base::Collection::IListT<CodecType>*
152 _AudioEncoderImpl::GetSupportedCodecListN(void)
154 _CodecFactory* pFactory = null;
155 Tizen::Base::Collection::IListT<CodecType>* pList = null;
157 pFactory = _CodecFactory::GetInstance();
158 SysTryReturn(NID_MEDIA, pFactory != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.",
\r
159 GetErrorMessage(GetLastResult()));
160 pList = pFactory->GetSupportedAudioEncoderListN();
161 SysTryReturn(NID_MEDIA, pList != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.",
\r
162 GetErrorMessage(GetLastResult()));
163 SetLastResult(E_SUCCESS);