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 file is streaming.
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 * // Manipulates the audio frame data
126 * // Gets a 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())
133 * int minPeakValue = 0;
134 * int maxPeakValue = 0;
135 * int sampleCount = frame.GetPlaneData(0)->GetCapacity() / 2;
136 * for (int i = 0; i<sampleCount; i++)
138 * if (pSampleData[i] < minPeakValue)
140 * minPeakValue = pSampleData[i];
142 * if (pSampleData[i] > maxPeakValue)
144 * maxPeakValue = pSampleData[i];
153 class _OSP_EXPORT_ AudioFrame
154 : public Tizen::Base::Object
160 * Gets the plane count that a frame data has.
163 * @return The plane count
166 int GetPlaneCount(void) const;
170 * Gets the type of an audio channel.
173 * @return The audio channel
176 AudioChannelType GetChannelType(void) const;
180 * Gets the audio sample type.
183 * @return The audio sample type
186 AudioSampleType GetSampleType(void) const;
190 * Gets the audio sampling rate.
193 * @return The audio sampling rate in Hertz (Hz)
196 int GetSamplingRate(void) const;
200 * Gets the plane data at the specified @c index from a frame.
203 * @return The plane data, @n
204 * else @c null if an error has occurred
205 * @param[in] index The index at which the value is read
206 * @exception E_SUCCESS The method is successful.
207 * @exception E_OUT_OF_RANGE The specified @c index is out of range.
209 * - The @c index should be less than the plane count.
210 * - The buffer in Tizen::Base::ByteBuffer is shared with the %AudioFrame instance.
211 * - The specific error code can be accessed using the GetLastResult() method.
213 Tizen::Base::ByteBuffer* GetPlaneData(int index) const;
218 * This is the default constructor for this class.
220 * @remarks The object is not fully constructed after this constructor is called. For full construction,
221 * the Construct() method must be called right after calling this constructor.
226 * This is the destructor for this class. @n
227 * All allocated resources are deallocated by this method. This polymorphic destructor should be overridden if required.
228 * This way, the destructors of the derived classes are called when the destructor of this interface is called.
231 virtual ~AudioFrame(void);
234 * Constructs an instance of this class. @n
237 * @return An error code
238 * @exception E_SUCCESS The method is successful.
241 result Construct(void);
244 * This is the copy constructor for this class.
247 * @remarks The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
249 AudioFrame(const AudioFrame& rhs);
252 * This is the copy assignment operator for this class.
255 * @remarks The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
258 AudioFrame& operator =(const AudioFrame& rhs);
260 friend class _AudioStreamCoordinator;
261 friend class _AudioFrameImpl;
262 class _AudioFrameImpl* __pImpl;