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 * @file FMediaVideoEncoder.h
20 * @brief This is the header file for the %VideoEncoder class.
22 * This header file contains the declarations of the %VideoEncoder class.
25 #ifndef _FMEDIA_VIDEO_ENCODER_H_
26 #define _FMEDIA_VIDEO_ENCODER_H_
29 #include <FMediaTypes.h>
31 namespace Tizen { namespace Media
36 * @brief This class encodes a raw video stream into a compressed video data.
40 * The %VideoEncoder class encodes a raw video stream into a compressed video data. The video encoders such as H.263, MPEG4 Part 2 are supported.
42 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_video.htm">Encoding and Decoding Video</a>.
44 * The following example demonstrates how to use the %VideoEncoder class in H.263 encoding.
51 * using namespace Tizen::Base;
52 * using namespace Tizen::Base::Collection;
53 * using namespace Tizen::Io;
54 * using namespace Tizen::Media;
57 * VideoEncoderSample(void)
61 * ByteBuffer srcBuf, dstBuf;
64 * int bitRate = 512000; // 512 Kbps
66 * MediaPixelFormat pixelFormat = MEDIA_PIXEL_FORMAT_YUV420P;
69 * int srcBufSize = width * height * 3 / 2;
72 * option.Add(*(new Integer(MEDIA_PROPERTY_VIDEO_WIDTH)), *(new Integer(width)));
73 * option.Add(*(new Integer(MEDIA_PROPERTY_VIDEO_HEIGHT)), *(new Integer(height)));
74 * option.Add(*(new Integer(MEDIA_PROPERTY_VIDEO_PIXEL_FORMAT)), *(new Integer(pixelFormat)));
75 * option.Add(*(new Integer(MEDIA_PROPERTY_VIDEO_FRAME_RATE)), *(new Integer(frameRate)));
76 * option.Add(*(new Integer(MEDIA_PROPERTY_VIDEO_BIT_RATE)), *(new Integer(bitRate)));
78 * pBuf = new byte[srcBufSize];
79 * srcBuf.Construct(pBuf, 0, srcBufSize, srcBufSize);
80 * dstBuf.Construct(width * height * 3 / 2);
82 * enc.Construct(CODEC_H263, &option);
84 * for (int i = 0; i < 255; i += 25)
86 * // Fills source buffer with a gray color
87 * memset(pBuf, i, width * height); // Y
88 * memset(pBuf + width * height, 128, width * height / 4); // Cb
89 * memset(pBuf + width * height * 5 / 4, 128, width * height / 4); // Cr
91 * srcBuf.SetPosition(0);
92 * srcBuf.SetLimit(srcBufSize);
94 * r = enc.Encode(srcBuf, dstBuf);
100 * // Adds code handling encoded data
112 class _OSP_EXPORT_ VideoEncoder
113 : public Tizen::Base::Object
117 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
125 * This destructor overrides Tizen::Base::Object::~Object().
129 virtual ~VideoEncoder(void);
132 * Initializes an instance of %VideoEncoder with the specified parameters.
136 * @return An error code
137 * @param[in] type The codec type
138 * @param[in] pOption The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_video.htm#encoding_video">optional parameters</a>
139 * @exception E_SUCCESS The method is successful.
140 * @exception E_UNSUPPORTED_CODEC The specified encoder is not supported.
141 * @exception E_INVALID_ARG A specified input parameter has invalid data.
142 * @exception E_OUT_OF_MEMORY The memory is insufficient.
143 * @exception E_SYSTEM A system error has occurred.
145 * - The key type of the specified option is Tizen::Base::Integer and the value type varies depending
147 * The unsupported keys in @c pOption are ignored.
148 * If specified @c pOption has an invalid value, @c E_INVALID_ARG is returned.
149 * - The supported codec types can vary depending on the device model or platform version.
151 result Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption = null);
155 * Encodes the video data from the source buffer and stores the encoded data in the destination buffer.
159 * @return An error code
160 * @param[in] srcBuf The source buffer that stores the raw video data
161 * @param[out] dstBuf The destination buffer that stores the encoded video data
162 * @exception E_SUCCESS The method is successful.
163 * @exception E_INVALID_ARG The specified source or destination buffer is invalid or has insufficient memory.
164 * @exception E_OUT_OF_MEMORY The memory is insufficient.
165 * @exception E_SYSTEM A system error has occurred.
167 * - The destination buffer must have sufficient free space to store the encoded frame data.
168 * - The position of the source buffer is moved to the end of the consumed data and the position of the destination buffer is moved to the end of the written data.
170 result Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf);
173 * Resets the internal state of the video encoder to process a new video stream.
177 * @return An error code
178 * @exception E_SUCCESS The method is successful.
179 * @exception E_SYSTEM A system error has occurred.
180 * @remarks This method resets the properties that were set after the execution of the Construct() method.
185 * Sets the specified property value of this instance.
189 * @return An error code
190 * @param[in] key The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_video.htm#encoding_video">key</a> value to set
191 * @param[in] value The property value to set
192 * @exception E_SUCCESS The method is successful.
193 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
194 * @exception E_OBJ_NOT_FOUND The specified @c key is not found.
195 * @exception E_INVALID_ARG A specified input parameter is invalid.
196 * @exception E_SYSTEM A system error has occurred.
197 * @remarks The media property that has the value of type enum can be set using this method.
199 result SetValue(MediaPropertyType key, int value);
202 * Sets the specified property value of this instance.
206 * @return An error code
207 * @param[in] key The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_video.htm#encoding_video">key</a> value to set
208 * @param[in] value The property value to set
209 * @exception E_SUCCESS The method is successful.
210 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
211 * @exception E_OBJ_NOT_FOUND The specified @c key is not found.
212 * @exception E_INVALID_ARG A specified input parameter is invalid.
213 * @exception E_SYSTEM A system error has occurred.
214 * @remarks The media property that has the value of type enum can be set using this method.
216 result SetValue(MediaPropertyType key, bool value);
219 * Gets the properties supported by this instance.
223 * @return A list of the supported properties, @n
224 * else @c null if no property is supported or if an exception occurs
225 * @exception E_SUCCESS The method is successful.
226 * @exception E_OUT_OF_MEMORY The memory is insufficient.
227 * @exception E_SYSTEM A system error has occurred.
228 * @exception E_OBJ_NOT_FOUND This instance does not support any property.
229 * @remarks The specific error code can be accessed using the GetLastResult() method.
230 * The returned value must be deleted.
232 Tizen::Base::Collection::IListT<MediaPropertyType>* GetSupportedPropertyListN(void) const;
235 * Checks whether the specified property is supported.
239 * @return @c true if the property is supported, @n
241 * @param[in] key The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_video.htm#encoding_video">key</a> value
242 * @exception E_SUCCESS The method is successful.
243 * @exception E_OBJ_NOT_FOUND The specified @c key is not found.
244 * @exception E_SYSTEM A system error has occurred.
245 * @remarks The specific error code can be accessed using the GetLastResult() method.
247 bool IsPropertySupported(MediaPropertyType key) const;
250 * Gets a list of the supported codecs.
254 * @return A list of the codecs supported by the %VideoEncoder class, @n
255 * else @c null if an exception occurs
256 * @exception E_SUCCESS The method is successful.
257 * @exception E_OUT_OF_MEMORY The memory is insufficient.
259 * - The specific error code can be accessed using the GetLastResult() method.
260 * - The return value must be deleted by the caller.
262 static Tizen::Base::Collection::IListT<CodecType>* GetSupportedCodecListN(void);
266 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
271 VideoEncoder(const VideoEncoder& enc);
274 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
279 VideoEncoder& operator =(const VideoEncoder& enc);
281 friend class _VideoEncoderImpl;
282 class _VideoEncoderImpl* __pImpl;