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 andW
15 // limitations under the License.
18 #include <FBaseColArrayListT.h>
19 #include <FMediaTypes.h>
20 #include <FMediaAudioTypes.h>
21 #include <FBaseColHashMap.h>
22 #include <FBaseColHashMapT.h>
24 #include <FBaseSysLog.h>
26 #include "FMedia_IAudioDecoder.h"
27 #include "FMedia_CodecFactory.h"
28 #include "FMedia_AudioDecoderImpl.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
34 namespace Tizen { namespace Media
37 _AudioDecoderImpl::_AudioDecoderImpl(void)
42 _AudioDecoderImpl::~_AudioDecoderImpl(void)
51 _AudioDecoderImpl::Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption)
53 _CodecFactory* pFactory = null;
56 SysTryReturn(NID_MEDIA, __pDec == null, E_INVALID_STATE, E_INVALID_STATE,
57 "[E_INVALID_STATE] Already Constructed");
58 SysAssertf(__pDec == null, " Already Constructed .");
\r
61 pFactory = _CodecFactory::GetInstance();
62 SysTryCatch(NID_MEDIA, pFactory != null, r = E_SYSTEM, E_SYSTEM,
63 "[%s] GetFactoryInstance Failed",GetErrorMessage(E_SYSTEM));
\r
64 r = pFactory->CreateCodecInstance(type, __pDec);
65 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r,
66 "[%s] CreateCodecInstance failed:%d", GetErrorMessage(r), type);
67 r = __pDec->Construct(pOption);
68 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] dec.Construct Failed", GetErrorMessage(r));
81 _AudioDecoderImpl::Probe(const Tizen::Base::ByteBuffer& srcBuf, AudioSampleType& sampleType,
82 AudioChannelType& channelType, int& sampleRate)
85 const byte* pSrcBuf = null;
88 SysTryReturn(NID_MEDIA, __pDec != null, E_INVALID_STATE, E_INVALID_STATE,
89 "[%s] The instance is in invalid state",GetErrorMessage(E_INVALID_STATE));
\r
91 SysTryCatch(NID_MEDIA, srcBuf.GetPointer() != null, r = E_INVALID_ARG, E_INVALID_ARG,
92 "[%s] The input argument is invalid",GetErrorMessage(E_INVALID_ARG));
\r
94 pSrcBuf = srcBuf.GetPointer() + srcBuf.GetPosition();
95 srcBufSize = srcBuf.GetRemaining();
96 SysTryCatch(NID_MEDIA, srcBufSize > 0, r = E_INVALID_ARG, E_INVALID_ARG,
97 "[%s] The input argument is invalid",GetErrorMessage(E_INVALID_ARG));
\r
98 r = __pDec->Probe(pSrcBuf, srcBufSize, sampleType, channelType, sampleRate);
99 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Probe Failed", GetErrorMessage(r));
109 _AudioDecoderImpl::Decode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf)
111 result r = E_SUCCESS;
112 const byte* pSrcBuf = null;
113 byte* pDstBuf = null;
119 SysTryReturn(NID_MEDIA, __pDec != null, E_INVALID_STATE, E_INVALID_STATE,
120 "[%s] The instance is in invalid state",GetErrorMessage(E_INVALID_STATE));
\r
122 SysTryCatch(NID_MEDIA, srcBuf.GetPointer() != null && dstBuf.GetPointer() != null,
123 r = E_INVALID_ARG, E_INVALID_ARG,
124 "[%s] srcBuf:0x%x dstBuf:0x%x", GetErrorMessage(E_INVALID_ARG), srcBuf.GetPointer(), dstBuf.GetPointer());
\r
125 pSrcBuf = srcBuf.GetPointer() + srcBuf.GetPosition();
126 pDstBuf = (byte*)dstBuf.GetPointer() + dstBuf.GetPosition();
127 srcBufSize = srcBuf.GetRemaining();
128 dstBufSize = dstBuf.GetRemaining();
129 SysTryCatch(NID_MEDIA, srcBufSize > 0 && dstBufSize > 0, r = E_INVALID_ARG, E_INVALID_ARG,
130 "[%s] srcSize:%d dstSize:%d", GetErrorMessage(E_INVALID_ARG), srcBufSize, dstBufSize);
\r
132 r = __pDec->Decode(pSrcBuf, srcBufSize, srcBufUsed, pDstBuf, dstBufSize, dstBufUsed);
134 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] dec.Decode", GetErrorMessage(r));
136 r = srcBuf.SetPosition(srcBuf.GetPosition() + srcBufUsed);
137 SysTryCatch(NID_MEDIA, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM,
138 "[%s] srcBuf overflow", GetErrorMessage(r));
140 r = dstBuf.SetPosition(dstBuf.GetPosition() + dstBufUsed);
141 SysTryCatch(NID_MEDIA, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM,
142 "[%s] dstBuf overflow", GetErrorMessage(r));
152 _AudioDecoderImpl::Reset(void)
155 SysTryReturn(NID_MEDIA, __pDec != null, E_INVALID_STATE, E_INVALID_STATE,
156 "[E_INVALID_STATE] Not Constructed");
157 return __pDec->Reset();
161 _AudioDecoderImpl::GetValue(MediaPropertyType key, int& value) const
163 SysTryReturn(NID_MEDIA, __pDec != null, E_INVALID_STATE, E_INVALID_STATE,
164 "[E_INVALID_STATE] Not Constructed");
165 return __pDec->GetValue(key, value);
168 Tizen::Base::Collection::IListT<MediaPropertyType>*
169 _AudioDecoderImpl::GetSupportedPropertyListN(void) const
172 SysTryReturn(NID_MEDIA, __pDec != null, null, E_INVALID_STATE,
173 "[E_INVALID_STATE] Not Constructed");
174 return __pDec->GetSupportedPropertyListN();
178 _AudioDecoderImpl::IsPropertySupported(MediaPropertyType key) const
180 SysTryReturn(NID_MEDIA, __pDec != null, false, E_INVALID_STATE,
181 "[E_INVALID_STATE] Not Constructed");
182 return __pDec->IsPropertySupported(key);
185 Tizen::Base::Collection::IListT<CodecType>*
186 _AudioDecoderImpl::GetSupportedCodecListN(void)
188 _CodecFactory* pFactory = null;
189 Tizen::Base::Collection::IListT<CodecType>* pList = null;
191 pFactory = _CodecFactory::GetInstance();
192 SysTryReturn(NID_MEDIA, pFactory != null, null, E_OUT_OF_MEMORY, "[%s] Propagated.",
193 GetErrorMessage(GetLastResult()));
194 pList = pFactory->GetSupportedAudioDecoderListN();
195 SysTryReturn(NID_MEDIA, pList != null, null, E_OUT_OF_MEMORY, "[%s] Propagated.",
196 GetErrorMessage(GetLastResult()));
197 SetLastResult(E_SUCCESS);