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.
121 * @remarks After creating an instance of this class, the Construct() method must be
122 * called explicitly to initialize this instance.
128 * This destructor overrides Tizen::Base::Object::~Object().
132 virtual ~VideoEncoder(void);
135 * Initializes an instance of %VideoEncoder with the specified parameters.
139 * @return An error code
140 * @param[in] type The codec type
141 * @param[in] pOption The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_video.htm#encoding_video">optional parameters</a>
142 * @exception E_SUCCESS The method is successful.
143 * @exception E_UNSUPPORTED_CODEC The specified encoder is not supported.
144 * @exception E_INVALID_ARG A specified input parameter has invalid data.
145 * @exception E_OUT_OF_MEMORY The memory is insufficient.
146 * @exception E_SYSTEM A system error has occurred.
147 * @remarks The key type of the specified option is Tizen::Base::Integer and the value type varies depending
149 * The unsupported keys in @c pOption are ignored.
150 * If specified @c pOption has an invalid value, @c E_INVALID_ARG is returned.
151 * @remarks The supported codec types can vary depending on the device model or platform version.
153 result Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption = null);
157 * Encodes the video data from the source buffer and stores the encoded data in the destination buffer.
161 * @return An error code
162 * @param[in] srcBuf The source buffer that stores the raw video data
163 * @param[out] dstBuf The destination buffer that stores the encoded video data
164 * @exception E_SUCCESS The method is successful.
165 * @exception E_INVALID_ARG The specified source or destination buffer is invalid or has insufficient memory.
166 * @exception E_OUT_OF_MEMORY The memory is insufficient.
167 * @exception E_SYSTEM A system error has occurred.
168 * @remarks The destination buffer must have sufficient free space to store the encoded frame data.
169 * @remarks 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.
171 result Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf);
174 * Resets the internal state of the video encoder to process a new video stream.
178 * @return An error code
179 * @exception E_SUCCESS The method is successful.
180 * @exception E_SYSTEM A system error has occurred.
181 * @remarks This method resets the properties that were set after the execution of the Construct() method.
186 * Sets the specified property value of this instance.
190 * @return An error code
191 * @param[in] key The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_video.htm#encoding_video">key</a> value to set
192 * @param[in] value The property value to set
193 * @exception E_SUCCESS The method is successful.
194 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
195 * @exception E_OBJ_NOT_FOUND The specified @c key is not found.
196 * @exception E_INVALID_ARG A specified input parameter is invalid.
197 * @exception E_SYSTEM A system error has occurred.
198 * @remarks The media property that has the value of type enum can be set using this method.
200 result SetValue(MediaPropertyType key, int value);
203 * Sets the specified property value of this instance.
207 * @return An error code
208 * @param[in] key The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_video.htm#encoding_video">key</a> value to set
209 * @param[in] value The property value to set
210 * @exception E_SUCCESS The method is successful.
211 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
212 * @exception E_OBJ_NOT_FOUND The specified @c key is not found.
213 * @exception E_INVALID_ARG A specified input parameter is invalid.
214 * @exception E_SYSTEM A system error has occurred.
215 * @remarks The media property that has the value of type enum can be set using this method.
217 result SetValue(MediaPropertyType key, bool value);
220 * Gets the properties supported by this instance.
224 * @return A list of the supported properties, @n
225 * else @c null if no property is supported or if an exception occurs
226 * @exception E_SUCCESS The method is successful.
227 * @exception E_OUT_OF_MEMORY The memory is insufficient.
228 * @exception E_SYSTEM A system error has occurred.
229 * @exception E_OBJ_NOT_FOUND This instance does not support any property.
230 * @remarks The specific error code can be accessed using the GetLastResult() method.
231 * The returned value must be deleted.
233 Tizen::Base::Collection::IListT<MediaPropertyType>* GetSupportedPropertyListN(void) const;
236 * Checks whether the specified property is supported.
240 * @return @c true if the property is supported, @n
242 * @param[in] key The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_video.htm#encoding_video">key</a> value
243 * @exception E_SUCCESS The method is successful.
244 * @exception E_OBJ_NOT_FOUND The specified @c key is not found.
245 * @exception E_SYSTEM A system error has occurred.
246 * @remarks The specific error code can be accessed using the GetLastResult() method.
248 bool IsPropertySupported(MediaPropertyType key) const;
251 * Gets a list of the supported codecs.
255 * @return A list of the codecs supported by the %VideoEncoder class, @n
256 * else @c null if an exception occurs
257 * @exception E_SUCCESS The method is successful.
258 * @exception E_OUT_OF_MEMORY The memory is insufficient.
259 * @remarks The specific error code can be accessed using the GetLastResult() method.
260 * @remarks 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;