Tizen 2.0 Release
[framework/osp/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          *      @remarks        After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
120          *      @see            Construct()
121          */
122         AudioEncoder(void);
123
124         /**
125          *      This destructor overrides Tizen::Base::Object::~Object().
126          *
127          *      @since          2.0
128          */
129         virtual ~AudioEncoder(void);
130
131         /**
132          *      Initializes this instance of %AudioEncoder 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_audio.htm#encoding_audio">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_OUT_OF_RANGE          A specified input parameter has a value that is out of range.
142          *      @exception      E_OUT_OF_MEMORY         The memory is insufficient. 
143          *      @exception      E_SYSTEM                        A system error has occurred.
144          *      @remarks        The key type of the specified option is Tizen::Base::Integer, and the value type varies depending on the key type.
145          */
146         result Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption = null);
147
148
149 public:
150         /**
151          *      Encodes the audio data from the source buffer and stores the encoded data into the destination buffer. @n
152          *      The %AudioEncoder class reads the audio data from the source buffer
153          *  and it writes the encoded audio data into the destination buffer.
154          *  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.
155          *      If there is no space in the destination buffer, the encoder returns @c E_INVALID_ARG.
156          *
157          *      @since          2.0
158          *
159          *      @return  An error code
160          *      @param[in]      srcBuf                                  The source buffer that stores the uncompressed audio data
161          *      @param[out]     dstBuf                                  The destination buffer that stores the encoded audio data
162          *      @exception      E_SUCCESS                               The method is successful.
163          *      @exception      E_INVALID_ARG                   The specified source or destination buffer is invalid.
164          *      @exception      E_OUT_OF_MEMORY                 The specified destination buffer is not sufficient to store the decoded data.
165          *      @exception  E_SYSTEM                            A system error has occurred.
166          */
167         result Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf);
168
169         /**
170          *      Resets the internal state of the audio encoder to process a new audio stream.
171          *
172          *      @since          2.0
173          *
174          *      @return         An error code
175          *      @exception      E_SUCCESS                       The method is successful.
176          *      @exception      E_SYSTEM                        A system error has occurred.
177          */
178         result Reset(void);
179
180         /**
181         * Gets a list of the supported codecs.
182         *
183         * @since                2.0
184         *
185         * @return     A list of the codecs supported by the %AudioEncoder class, @n
186         *             else @c null if an exception occurs
187         * @exception  E_SUCCESS             The method is successful.
188         * @exception  E_OUT_OF_MEMORY       The memory is insufficient.
189         * @remarks    The specific error code can be accessed using the GetLastResult() method.
190         * @remarks    The return value must be deleted by the caller.
191         */
192         static Tizen::Base::Collection::IListT<CodecType>* GetSupportedCodecListN(void);
193
194 private:
195         /**
196          *      The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
197          *
198          *      @since          2.0
199          *
200          */
201         AudioEncoder(const AudioEncoder& enc);
202
203         /**
204          *      The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
205          *
206          *      @since          2.0
207          *
208          */
209         AudioEncoder& operator =(const AudioEncoder& enc);
210
211         friend class _AudioEncoderImpl;
212         class _AudioEncoderImpl* __pImpl;
213 };
214
215 }} // Tizen::Media
216
217
218 #endif