CAF state bug fix
[platform/framework/native/media.git] / src / FMediaVideoEncoder.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 <FMediaVideoEncoder.h>
20 #include <FBaseSysLog.h>
21 #include "FMedia_VideoEncoderImpl.h"
22
23 using namespace Tizen::Base;
24 using namespace Tizen::Base::Collection;
25
26
27 namespace Tizen { namespace Media
28 {
29
30 VideoEncoder::VideoEncoder(void)
31 {
32         __pImpl = null;
33 }
34
35 VideoEncoder::~VideoEncoder(void)
36 {
37         if (__pImpl != null)
38         {
39                 delete __pImpl;
40         }
41 }
42
43 result
44 VideoEncoder::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         _VideoEncoderImpl* pVideoEncoderImpl = new (std::nothrow) _VideoEncoderImpl();
51         SysTryCatch(NID_MEDIA, pVideoEncoderImpl != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
52                           "[%s] Memory Allocation Failed ", GetErrorMessage(E_OUT_OF_MEMORY));\r
53         r = pVideoEncoderImpl->Construct(type, pOption);
54         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Failed to construct _VideoEncoderImpl", GetErrorMessage(r));\r
55         __pImpl = pVideoEncoderImpl;
56         return E_SUCCESS;
57
58 CATCH:
59         if (pVideoEncoderImpl != null)
60         {
61                 delete pVideoEncoderImpl;
62                 pVideoEncoderImpl = null;
63         }
64         return r;
65 }
66
67 result
68 VideoEncoder::Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf)
69 {
70         result r = E_SUCCESS;
71
72         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
73         r = __pImpl->Encode(srcBuf, dstBuf);
74
75         return r;
76 }
77
78 result
79 VideoEncoder::Reset(void)
80 {
81         result r = E_SUCCESS;
82
83         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
84         r = __pImpl->Reset();
85
86         return r;
87 }
88
89 result
90 VideoEncoder::SetValue(MediaPropertyType key, int value)
91 {
92         result r = E_SUCCESS;
93
94         SysTryReturnResult(NID_MEDIA, __pImpl, E_INVALID_STATE, "not constructed");
95         r = __pImpl->SetValue(key, value);
96
97         return r;
98 }
99
100
101 result
102 VideoEncoder::SetValue(MediaPropertyType key, bool value)
103 {
104         result r = E_SUCCESS;
105
106         SysTryReturnResult(NID_MEDIA, __pImpl, E_INVALID_STATE, "not constructed");
107         r = __pImpl->SetValue(key, value);
108
109         return r;
110 }
111
112
113 Tizen::Base::Collection::IListT<MediaPropertyType>*
114 VideoEncoder::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 VideoEncoder::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 Tizen::Base::Collection::IListT<CodecType>*
129 VideoEncoder::GetSupportedCodecListN(void)
130 {
131         result r = E_SUCCESS;
132         Tizen::Base::Collection::IListT<CodecType> *pList = null;
133
134         pList = _VideoEncoderImpl::GetSupportedCodecListN();
135         r = GetLastResult();
136         SysTryReturn(NID_MEDIA, pList != null, null, r, "[%s] Propagating", GetErrorMessage(r));
137
138         SetLastResult(E_SUCCESS);
139         return pList;
140 }
141
142
143 }} // Tizen::Media