Camera&Recorder doxygen update
[platform/framework/native/media.git] / inc / FMediaVideoEncoder.h
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 /**
19  *      @file   FMediaVideoEncoder.h
20  *      @brief  This is the header file for the %VideoEncoder class.
21  *
22  *      This header file contains the declarations of the %VideoEncoder class.
23  */
24
25 #ifndef _FMEDIA_VIDEO_ENCODER_H_
26 #define _FMEDIA_VIDEO_ENCODER_H_
27
28 #include <FBase.h>
29 #include <FMediaTypes.h>
30
31 namespace Tizen { namespace Media
32 {
33
34 /**
35  * @class VideoEncoder
36  * @brief This class encodes a raw video stream into a compressed video data.
37  *
38  * @since               2.0
39  *
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.
41  *
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>.
43  *
44  * The following example demonstrates how to use the %VideoEncoder class in H.263 encoding.
45  * @code
46  *
47  * #include <FBase.h>
48  * #include <FIo.h>
49  * #include <FMedia.h>
50  *
51  * using namespace Tizen::Base;
52  * using namespace Tizen::Base::Collection;
53  * using namespace Tizen::Io;
54  * using namespace Tizen::Media;
55  *
56  * result
57  * VideoEncoderSample(void)
58  * {
59  *       VideoEncoder enc;
60  *       result r;
61  *       ByteBuffer srcBuf, dstBuf;
62  *       int width = 352;
63  *       int height = 288;
64  *       int bitRate = 512000; // 512 Kbps
65  *       int frameRate = 15;
66  *       MediaPixelFormat pixelFormat = MEDIA_PIXEL_FORMAT_YUV420P;
67  *       HashMap option;
68  *       byte* pBuf = null;
69  *       int srcBufSize = width * height * 3 / 2;
70  *
71  *       option.Construct();
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)));
77  *
78  *       pBuf = new byte[srcBufSize];
79  *       srcBuf.Construct(pBuf, 0, srcBufSize, srcBufSize);
80  *       dstBuf.Construct(width * height * 3 / 2);
81  *
82  *       enc.Construct(CODEC_H263, &option);
83  *
84  *       for (int i = 0; i < 255; i += 25)
85  *       {
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
90  *
91  *               srcBuf.SetPosition(0);
92  *               srcBuf.SetLimit(srcBufSize);
93  *
94  *               r = enc.Encode(srcBuf, dstBuf);
95  *               if (IsFailed(r))
96  *               {
97  *                       break;
98  *               }
99  *
100  *               // Adds code handling encoded data
101  *
102  *               dstBuf.Clear();
103  *       }
104  *
105  *       delete pBuf;
106  *       return r;
107  * }
108  *
109  * @endcode
110  *
111  */
112 class _OSP_EXPORT_ VideoEncoder
113         : public Tizen::Base::Object
114 {
115 public:
116         /**
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.
118          *
119          *      @since          2.0
120          *
121          */
122         VideoEncoder(void);
123
124         /**
125          *      This destructor overrides Tizen::Base::Object::~Object().
126          *
127          *      @since          2.0
128          */
129         virtual ~VideoEncoder(void);
130
131         /**
132          *      Initializes an instance of %VideoEncoder with the specified parameters.
133          *
134          *      @since          2.0
135          *
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.
144          *      @remarks
145          *                        - The key type of the specified option is Tizen::Base::Integer and the value type varies depending
146          *                              on the key type.
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.
150          */
151         result Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption = null);
152
153 public:
154         /**
155          *      Encodes the video data from the source buffer and stores the encoded data in the destination buffer.
156          *
157          *      @since          2.0
158          *
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.
166          *      @remarks
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.
169          */
170         result Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf);
171
172         /**
173          *      Resets the internal state of the video encoder to process a new video stream.
174
175          *      @since          2.0
176          *
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.
181          */
182         result Reset(void);
183
184         /**
185          *      Sets the specified property value of this instance.
186          *
187          *      @since          2.0
188          *
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.
198          */
199         result SetValue(MediaPropertyType key, int value);
200
201         /**
202          *      Sets the specified property value of this instance.
203          *
204          *      @since          2.0
205          *
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.
215          */
216         result SetValue(MediaPropertyType key, bool value);
217
218         /**
219          *      Gets the properties supported by this instance.
220          *
221          *      @since          2.0
222          *
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.
231          */
232         Tizen::Base::Collection::IListT<MediaPropertyType>* GetSupportedPropertyListN(void) const;
233
234         /**
235          *      Checks whether the specified property is supported.
236          *
237          *      @since          2.0
238          *
239          *      @return  @c true if the property is supported, @n
240          *                              else @c false
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.
246          */
247         bool IsPropertySupported(MediaPropertyType key) const;
248
249         /**
250          * Gets a list of the supported codecs.
251          *
252          * @since               2.0
253          *
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.
258          * @remarks
259          *                       - The specific error code can be accessed using the GetLastResult() method.
260          *                       - The return value must be deleted by the caller.
261          */
262         static Tizen::Base::Collection::IListT<CodecType>* GetSupportedCodecListN(void);
263
264 private:
265         /**
266          *      The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
267          *
268          *      @since          2.0
269          *
270          */
271         VideoEncoder(const VideoEncoder& enc);
272
273         /**
274          *      The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
275          *
276          *      @since          2.0
277          *
278          */
279         VideoEncoder& operator =(const VideoEncoder& enc);
280
281         friend class _VideoEncoderImpl;
282         class _VideoEncoderImpl* __pImpl;
283 };
284
285 }} // Tizen::Media
286
287 #endif