Tizen 2.0 Release
[framework/osp/media.git] / src / FMediaVideoDecoder.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 <FBaseColArrayListT.h>
19 #include <FMediaVideoDecoder.h>
20 #include <FBaseSysLog.h>
21 #include "FMedia_VideoDecoderImpl.h"
22
23 using namespace Tizen::Base;
24 using namespace Tizen::Base::Collection;
25
26
27 namespace Tizen { namespace Media
28 {
29
30 VideoDecoder::VideoDecoder(void)
31 {
32         __pImpl = null;
33 }
34
35 VideoDecoder::~VideoDecoder(void)
36 {
37         if (__pImpl != null)
38         {
39                 delete __pImpl;
40         }
41 }
42
43 result
44 VideoDecoder::Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption)
45 {
46         result r = E_SUCCESS;
47
48         SysAssertf(__pImpl == null,
49                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
50         _VideoDecoderImpl* pVideoDecoderImpl = new (std::nothrow) _VideoDecoderImpl();
51         SysTryCatch(NID_MEDIA, pVideoDecoderImpl != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
52                           "[E_OUT_OF_MEMORY] Construct Failed ");
53         r = pVideoDecoderImpl->Construct(type, pOption);
54         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated", GetErrorMessage(r));
55         __pImpl = pVideoDecoderImpl;
56         return E_SUCCESS;
57 CATCH:
58         if (pVideoDecoderImpl != null)
59         {
60                 delete pVideoDecoderImpl;
61                 pVideoDecoderImpl = null;
62         }
63         return r;
64 }
65
66 result
67 VideoDecoder::Probe(const Tizen::Base::ByteBuffer& srcBuf,
68                                         int& width, int& height, MediaPixelFormat& pixelFormat)
69 {
70         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
71         return __pImpl->Probe(srcBuf, width, height, pixelFormat);
72 }
73
74 result
75 VideoDecoder::Decode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf, bool& gotFrame)
76 {
77         result r = E_SUCCESS;
78
79         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
80         r = __pImpl->Decode(srcBuf, dstBuf, gotFrame);
81         return r;
82 }
83
84 result
85 VideoDecoder::Reset(void)
86 {
87         result r = E_SUCCESS;
88         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
89         r = __pImpl->Reset();
90         return r;
91 }
92
93 result
94 VideoDecoder::GetValue(MediaPropertyType key, int& value) const
95 {
96         result r = E_SUCCESS;
97         SysTryReturnResult(NID_MEDIA, __pImpl, E_INVALID_STATE, "not constructed");
98         r = __pImpl->GetValue(key, value);
99         return r;
100 }
101
102 result
103 VideoDecoder::GetValue(MediaPropertyType key, float& value) const
104 {
105         result r = E_SUCCESS;
106
107         SysTryReturnResult(NID_MEDIA, __pImpl, E_INVALID_STATE, "not constructed");
108         r = __pImpl->GetValue(key, value);
109
110         return r;
111 }
112
113 Tizen::Base::Collection::IListT<MediaPropertyType>*
114 VideoDecoder::GetSupportedPropertyListN(void) const
115 {
116         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
117         return  __pImpl->GetSupportedPropertyListN();
118
119 }
120
121 bool
122 VideoDecoder::IsPropertySupported(MediaPropertyType key) const
123 {
124         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
125         return __pImpl->IsPropertySupported(key);
126
127 }
128
129 Tizen::Base::Collection::IListT<CodecType>*
130 VideoDecoder::GetSupportedCodecListN(void)
131 {
132         result r = E_SUCCESS;
133         Tizen::Base::Collection::IListT<CodecType> *pList = null;
134
135         pList = _VideoDecoderImpl::GetSupportedCodecListN();
136         r = GetLastResult();
137         SysTryReturn(NID_MEDIA, pList != null, null, r, "[%s] Propagating", GetErrorMessage(r));
138
139         SetLastResult(E_SUCCESS);
140         return pList;
141 }
142
143 }}  // Tizen::Media