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 FMediaAudioFrame.h
20 * @brief This is the header file for the %AudioFrame class.
22 * This header file contains the declarations of the %AudioFrame class.
25 #ifndef _FMEDIA_AUDIO_FRAME_H_
26 #define _FMEDIA_AUDIO_FRAME_H_
29 #include <FMediaAudioTypes.h>
31 namespace Tizen { namespace Media
36 * @brief This class has the audio frame data.
40 * @final This class is not intended for extension
42 * The %AudioFrame class has the audio frame data.
43 * The frame has several plane components. @n
44 * This object is delivered to the application by IAudioStreamFilter::ProcessAudioStream() when the audio stream is coming.
46 * The following example demonstrates how to use the %AudioFrame class.
53 * using namespace Tizen::Media;
55 * class AudioFrameSample
56 * : public Tizen::Media::IAudioRecorderEventListener
57 * , public Tizen::Media::IAudioStreamFilter
60 * AudioFrameSample(void);
65 * virtual void OnAudioRecorderStopped(result r) {}
66 * virtual void OnAudioRecorderCanceled(result r) {}
67 * virtual void OnAudioRecorderPaused(result r) {}
68 * virtual void OnAudioRecorderStarted(result r) {}
69 * virtual void OnAudioRecorderEndReached(RecordingEndCondition endCondition) {}
70 * virtual void OnAudioRecorderClosed(result r) {}
71 * virtual void OnAudioRecorderErrorOccurred(RecorderErrorReason r) {}
72 * virtual void ProcessAudioStream(AudioFrame &frame);
75 * AudioRecorder __recorder;
78 * AudioFrameSample::AudioFrameSample(void)
83 * AudioFrameSample::Start(void)
85 * result r = E_SUCCESS;
86 * String destFilePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.amr";
88 * r = __recorder.Construct(*this);
94 * r = __recorder.CreateAudioFile(destFilePath, true);
100 * r = __recorder.AddAudioStreamListener(*this);
106 * r = __recorder.Record();
116 * AudioFrameSample::Stop(void)
119 * __recorder.Close();
123 * AudioFrameSample::ProcessAudioStream(AudioFrame &frame)
125 * // manipulate audio frmae data.
126 * // Get peak value from the audio frame.
127 * // This code supports only signed 16-bits sample format.
128 * if (frame.GetPlaneCount() < 1 || frame.GetSampleType() != AUDIO_TYPE_PCM_S16_LE)
132 * short* pSampleData = (short*)(frame.GetPlaneData(0)->GetPointer())
134 * int sampleCount = frame.GetPlaneSize(0) / 2;
135 * for (int i = 0; i<sampleCount; i++)
137 * if (pSampleData[i] >peakValue)
138 * peakValue = pSampleData[i];
146 class _OSP_EXPORT_ AudioFrame
147 : public Tizen::Base::Object
153 * Gets the plane count which the frame data has.
156 * @return The plane count
159 int GetPlaneCount(void) const;
163 * Gets the audio channel.
166 * @return The audio channel
169 AudioChannelType GetChannelType(void) const;
173 * Gets the audio sample type.
176 * @return The audio sample type
179 AudioSampleType GetSampleType(void) const;
183 * Gets the audio sampling rate.
186 * @return The audio sampling rate in hertz (Hz)
189 int GetSamplingRate(void) const;
193 * Gets the plane data at the specified index from the frame.
196 * @return The plane data, @n
197 * else @null if an error occurred
198 * @param[in] index The index at which the value is read
199 * @exception E_SUCCESS The method is successful.
200 * @exception E_OUT_OF_RANGE The specified index is out of range.
201 * @remarks The index should be less than the plane count. @n
202 * The buufer in ByteBuffer is shared with @c AudioFrame instance. @n
203 * The specific error code can be accessed using the GetLastResult() method.
205 Tizen::Base::ByteBuffer* GetPlaneData(int index) const;
210 * This is the default constructor for this class.
212 * @remarks The object is not fully constructed after this constructor is called. For full construction,
213 * the Construct() method must be called right after calling this constructor.
218 * This is the destructor for this class. @n
219 * All allocated resources are deallocated by this method. This polymorphic destructor should be overridden if required.
220 * This way, the destructors of the derived classes are called when the destructor of this interface is called.
223 virtual ~AudioFrame(void);
226 * Constructs the instance of this class. @n
229 * @return An error code
230 * @exception E_SUCCESS The method is successful.
233 result Construct(void);
236 * This is the copy constructor for this class.
239 * @remarks The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
241 AudioFrame(const AudioFrame& rhs);
244 * This is the copy assignment operator for this class.
247 * @remarks The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
250 AudioFrame& operator =(const AudioFrame& rhs);
252 friend class _AudioStreamCoordinator;
253 friend class _AudioFrameImpl;
254 class _AudioFrameImpl* __pImpl;