(TDIS-5787)Fixed CMakelist to write information of osp-media.pc
[platform/framework/native/media.git] / inc / FMediaAudioEncoder.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        FMediaAudioEncoder.h
20  * @brief       This is the header file for the %AudioEncoder class.
21  *
22  * This header file contains the declarations of the %Tizen::Media::AudioEncoder class.
23  */
24
25 #ifndef _FMEDIA_AUDIO_ENCODER_H_
26 #define _FMEDIA_AUDIO_ENCODER_H_
27
28 #include <FBase.h>
29 #include <FMediaAudioTypes.h>
30 #include <FMediaTypes.h>
31
32 namespace Tizen { namespace Media
33 {
34
35 /**
36  * @class AudioEncoder
37  * @brief This class encodes raw audio data into compressed audio stream.
38  *
39  * @since               2.0
40  *
41  * The %AudioEncoder class encodes raw audio data into compressed audio stream.
42  * It supports the audio encoding formats such as CODE_AAC and CODEC_AMR_NB. @n
43  *
44  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_audio.htm">Encoding and Decoding Audio</a>. @n
45  *
46  * The following example demonstrates how to use the %AudioEncoder class in Advanced Audio Coding (AAC) encoding.
47  * @code
48  *
49  * #include <FBase.h>
50  * #include <FIo.h>
51  * #include <FApp.h>
52  * #include <FMedia.h>
53  *
54  * using namespace Tizen::Base;
55  * using namespace Tizen::Base::Collection;
56  * using namespace Tizen::Io;
57  * using namespace Tizen::Media;
58  *
59  * #define DST_BUF_SIZE   (1024*8)
60  *
61  * result
62  * AudioEncoderSample(void)
63  * {
64  *       AudioEncoder enc;
65  *       result r;
66  *       ByteBuffer srcBuf, dstBuf;
67  *       File srcFile;
68  *       FileAttributes attr;
69  *       int sampleRate = 44100;
70  *       AudioChannelType channelType = AUDIO_CHANNEL_TYPE_STEREO;
71  *       int bitRate = 128000; // 128Kbps
72  *       HashMap option;
73  *       String filePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.wav";
74  *
75  *       option.Construct();
76  *       option.Add(*(new Integer(MEDIA_PROPERTY_AUDIO_CHANNEL_TYPE)), *(new Integer(channelType)));
77  *       option.Add(*(new Integer(MEDIA_PROPERTY_AUDIO_SAMPLE_RATE)), *(new Integer(sampleRate)));
78  *       option.Add(*(new Integer(MEDIA_PROPERTY_AUDIO_BIT_RATE)), *(new Integer(bitRate)));
79  *
80  *       // Loads src file into buffer
81  *       File::GetAttributes(filePath, attr);
82  *       srcBuf.Construct(attr.GetFileSize());
83  *       srcFile.Construct(filePath, L"rb");
84  *       srcFile.Read(srcBuf);
85  *       srcBuf.Flip();  // Sets the position of source buffer to zero
86  *
87  *       // Adds code that skips WAV header in srcBuf
88  *
89  *       dstBuf.Construct(DST_BUF_SIZE);
90  *
91  *       enc.Construct(CODEC_AAC, &option);
92  *
93  *       while (srcBuf.GetRemaining() > 0)
94  *       {
95  *               r = enc.Encode(srcBuf, dstBuf);
96  *               if (IsFailed(r))
97  *               {
98  *                       break;
99  *               }
100  *               // Adds code handling encoded data
101  *
102  *               dstBuf.Clear();
103  *       }
104  *
105  *       return r;
106  * }
107  * @endcode
108  *
109  */
110 class _OSP_EXPORT_ AudioEncoder
111         : public Tizen::Base::Object
112 {
113 public:
114         /**
115          *      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.
116          *
117          *      @since          2.0
118          *
119          */
120         AudioEncoder(void);
121
122         /**
123          *      This destructor overrides Tizen::Base::Object::~Object().
124          *
125          *      @since          2.0
126          */
127         virtual ~AudioEncoder(void);
128
129         /**
130          *      Initializes this instance of %AudioEncoder with the specified parameters.
131          *
132          *      @since          2.0
133          *
134          *      @return         An error code
135          *      @param[in]      type                            The codec type
136          *      @param[in]      pOption                         The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_audio.htm#encoding_audio">optional parameters</a>
137          *      @exception      E_SUCCESS                       The method is successful.
138          *      @exception      E_UNSUPPORTED_CODEC The specified encoder is not supported.
139          *      @exception      E_OUT_OF_RANGE          A specified input parameter has a value that is out of range.
140          *      @exception      E_OUT_OF_MEMORY         The memory is insufficient. 
141          *      @exception      E_SYSTEM                        A system error has occurred.
142          *      @remarks        The key type of the specified option is Tizen::Base::Integer, and the value type varies depending on the key type.
143          */
144         result Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption = null);
145
146
147 public:
148         /**
149          *      Encodes the audio data from the source buffer and stores the encoded data into the destination buffer. @n
150          *      The %AudioEncoder class reads the audio data from the source buffer
151          *  and it writes the encoded audio data into the destination buffer.
152          *  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.
153          *      If there is no space in the destination buffer, the encoder returns @c E_INVALID_ARG.
154          *
155          *      @since          2.0
156          *
157          *      @return  An error code
158          *      @param[in]      srcBuf                                  The source buffer that stores the uncompressed audio data
159          *      @param[out]     dstBuf                                  The destination buffer that stores the encoded audio data
160          *      @exception      E_SUCCESS                               The method is successful.
161          *      @exception      E_INVALID_ARG                   The specified source or destination buffer is invalid.
162          *      @exception      E_OUT_OF_MEMORY                 The specified destination buffer is not sufficient to store the decoded data.
163          *      @exception  E_SYSTEM                            A system error has occurred.
164          */
165         result Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf);
166
167         /**
168          *      Resets the internal state of the audio encoder to process a new audio stream.
169          *
170          *      @since          2.0
171          *
172          *      @return         An error code
173          *      @exception      E_SUCCESS                       The method is successful.
174          *      @exception      E_SYSTEM                        A system error has occurred.
175          */
176         result Reset(void);
177
178         /**
179         * Gets a list of the supported codecs.
180         *
181         * @since                2.0
182         *
183         * @return     A list of the codecs supported by the %AudioEncoder class, @n
184         *             else @c null if an exception occurs
185         * @exception  E_SUCCESS             The method is successful.
186         * @exception  E_OUT_OF_MEMORY       The memory is insufficient.
187         * @remarks
188         *                       - The specific error code can be accessed using the GetLastResult() method.
189         *                       - The return value must be deleted by the caller.
190         */
191         static Tizen::Base::Collection::IListT<CodecType>* GetSupportedCodecListN(void);
192
193 private:
194         /**
195          *      The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
196          *
197          *      @since          2.0
198          *
199          */
200         AudioEncoder(const AudioEncoder& enc);
201
202         /**
203          *      The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
204          *
205          *      @since          2.0
206          *
207          */
208         AudioEncoder& operator =(const AudioEncoder& enc);
209
210         friend class _AudioEncoderImpl;
211         class _AudioEncoderImpl* __pImpl;
212 };
213
214 }} // Tizen::Media
215
216
217 #endif