Tizen 2.0 Release
[framework/osp/media.git] / src / FMediaAudioDecoder.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include <FMediaAudioDecoder.h>
19 #include <FBaseSysLog.h>
20 #include "FMedia_AudioDecoderImpl.h"
21
22 using namespace Tizen::Base;
23 using namespace Tizen::Base::Collection;
24
25 namespace Tizen { namespace Media
26 {
27
28 AudioDecoder::AudioDecoder(void)
29 {
30         __pImpl = null;
31 }
32
33 AudioDecoder::~AudioDecoder(void)
34 {
35         if (__pImpl != null)
36         {
37                 delete __pImpl;
38         }
39 }
40
41 result
42 AudioDecoder::Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption)
43 {
44         result r = E_SUCCESS;
45
46         SysAssertf(__pImpl == null,
47                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
48
49         _AudioDecoderImpl* pAudioDecoderImpl = new (std::nothrow) _AudioDecoderImpl();
50         SysTryCatch(NID_MEDIA, pAudioDecoderImpl != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
51                           "[%s] Memory Allocation  Failed. Propagating. ",GetErrorMessage(E_OUT_OF_MEMORY));    \r
52
53         r = pAudioDecoderImpl->Construct(type, pOption);
54         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
55
56         SetLastResult(r);
57         __pImpl = pAudioDecoderImpl;
58         return E_SUCCESS;
59
60 CATCH:
61         if (pAudioDecoderImpl != null)
62         {
63                 delete pAudioDecoderImpl;
64                 pAudioDecoderImpl = null;
65         }
66         return r;
67 }
68
69 result
70 AudioDecoder::Probe(const Tizen::Base::ByteBuffer& srcBuf, AudioSampleType& sampleType,
71                                         AudioChannelType& channelType, int& sampleRate)
72 {
73         result r = E_SUCCESS;
74
75         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
76
77         r = __pImpl->Probe(srcBuf, sampleType, channelType, sampleRate);
78         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
79
80         SetLastResult(r);
81         return r;
82
83 CATCH:
84         return r;
85 }
86
87 result
88 AudioDecoder::Decode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf)
89 {
90         result r = E_SUCCESS;
91
92         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
93
94         r = __pImpl->Decode(srcBuf, dstBuf);
95         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
96
97         SetLastResult(r);
98         return r;
99
100 CATCH:
101         return r;
102 }
103
104 result
105 AudioDecoder::Reset(void)
106 {
107         result r = E_SUCCESS;
108
109         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
110
111         r = __pImpl->Reset();
112         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
113
114         SetLastResult(r);
115         return r;
116
117 CATCH:
118         return r;
119 }
120
121 result
122 AudioDecoder::GetValue(MediaPropertyType GetValue, int& value) const
123 {
124         result r = E_SUCCESS;
125
126         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
127
128         r = __pImpl->GetValue(GetValue, value);
129         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
130
131         SetLastResult(r);
132         return r;
133
134 CATCH:
135         return r;
136 }
137
138
139 Tizen::Base::Collection::IListT<MediaPropertyType>*
140 AudioDecoder::GetSupportedPropertyListN(void) const
141 {
142         result r = E_SUCCESS;
143         Tizen::Base::Collection::IListT<MediaPropertyType> *pList = null;
144
145         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
146
147         pList = __pImpl->GetSupportedPropertyListN();
148         SysTryCatch(NID_MEDIA, pList != null, , GetLastResult(), "[%s] Propagating", GetErrorMessage(GetLastResult()));
149
150         SetLastResult(E_SUCCESS);
151         return pList;
152
153 CATCH:
154         return null;
155 }
156
157 bool
158 AudioDecoder::IsPropertySupported(MediaPropertyType key) const
159 {
160         result r = E_SUCCESS;
161         bool supported = false;
162
163         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
164
165         supported = __pImpl->IsPropertySupported(key);
166         r = GetLastResult();
167         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
168
169         SetLastResult(r);
170         return supported;
171
172 CATCH:
173         return false;
174 }
175
176 Tizen::Base::Collection::IListT<CodecType>*
177 AudioDecoder::GetSupportedCodecListN(void)
178 {
179         result r = E_SUCCESS;
180         Tizen::Base::Collection::IListT<CodecType> *pList = null;
181
182         pList = _AudioDecoderImpl::GetSupportedCodecListN();
183         r = GetLastResult();
184         SysTryReturn(NID_MEDIA, pList != null, null, r, "[%s] Propagating", GetErrorMessage(r));
185
186         SetLastResult(E_SUCCESS);
187         return pList;
188 }
189
190 } } // Tizen::Media