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 FMedia_AudioRecorderImpl.h
20 * @brief This header file contains the declaration of the _AudioRecorder_Impl class.
23 #ifndef _FMEDIA_INTERNAL_AUDIORECORDER_IMPL_H_
24 #define _FMEDIA_INTERNAL_AUDIORECORDER_IMPL_H_
26 #include <unique_ptr.h>
27 #include <FBaseColArrayListT.h>
28 #include <FMediaTypes.h>
29 #include <FMediaAudioRecorderTypes.h>
30 #include "FMedia_RecorderTypes.h"
32 namespace Tizen { namespace Media
35 class IAudioRecorderEventListener;
36 class _AudioRecorderEvent;
37 class _RecorderManager;
38 class _AudioStreamCoordinator;
39 class IAudioStreamFilter;
42 * @class _AudioRecorderImpl
43 * @brief This class records the audio data into a file.
46 class _AudioRecorderImpl
47 : public Tizen::Base::Object
52 * This is the default constructor for this class.
54 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to
55 * initialize this instance.
58 _AudioRecorderImpl(void);
61 * This is the destructor for this class. @n
62 * All allocated resources are released by this method. This method should be called in the same thread in
63 * which the Construct() method is called.
67 virtual ~_AudioRecorderImpl(void);
72 * Initializes this instance of %_AudioRecorderImpl with the specified listener.
74 * @return An error code
75 * @param[in] listener An event listener instance
76 * @exception E_SUCCESS The method is successful.
77 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
78 * @exception E_SYSTEM A system error has occurred.
79 * @exception E_DEVICE_BUSY The device cannot be approached because of other operations.
81 result Construct(IAudioRecorderEventListener& listener);
84 * Creates an audio file for the recording.
86 * @return An error code
87 * @param[in] destMediaPath The file destination to write @n
88 * The available paths start with prefixes retrieved from the functions such as: @n
89 * Tizen::App::App::GetInstance()->GetAppRootPath() @n
90 * Tizen::System::Environment::GetMediaPath() @n
91 * Tizen::System::Environment::GetExternalStoragePath()
92 * @param[in] overwrite Set to @c true to overwrite a file if it already exists, @n
94 * @exception E_SUCCESS The method is successful.
95 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
96 * @exception E_RESOURCE_UNAVAILABLE The required path is unavailable.
97 * @exception E_SYSTEM A system error has occurred.
98 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
99 * @exception E_STORAGE_FULL The storage is full.
100 * @exception E_OUT_OF_MEMORY The memory is insufficient.
101 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
104 result CreateAudioFile(const Tizen::Base::String& destMediaPath, bool overwrite);
109 * @return An error code
110 * @exception E_SUCCESS The method is successful.
111 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
112 * @exception E_SYSTEM A system error has occurred.
113 * @exception E_OUT_OF_MEMORY The memory is insufficient.
114 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
115 * @see CreateAudioFile()
116 * @remarks This method is synchronous.
121 * Starts recording or resumes a recording after Pause() is called.
123 * @return An error code
124 * @exception E_SUCCESS The method is successful.
125 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
126 * @exception E_SYSTEM A system error has occurred.
127 * @exception E_DEVICE_BUSY The device cannot be approached because of other operations.
128 * @exception E_OUT_OF_MEMORY The memory is insufficient.
129 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
130 * @see Stop(), Pause()
137 * @return An error code
138 * @exception E_SUCCESS The method is successful.
139 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
140 * @exception E_SYSTEM A system error has occurred.
141 * @exception E_OUT_OF_MEMORY The memory is insufficient.
142 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
143 * @see Record(), Pause()
148 * Pauses a recording. @n
149 * To resume a recording after this method is called, the Record() method must be called.
151 * @return An error code
152 * @exception E_SUCCESS The method is successful.
153 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
154 * @exception E_SYSTEM A system error has occurred.
155 * @exception E_OUT_OF_MEMORY The memory is insufficient.
156 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
157 * @see Record(), Stop()
162 * Cancels a recording operation without saving the data.
164 * @return An error code
165 * @exception E_SUCCESS The method is successful.
166 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
167 * @exception E_SYSTEM A system error has occurred.
168 * @exception E_OUT_OF_MEMORY The memory is insufficient.
169 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
170 * @remarks If this method is called, the state is changed to ::RECORDER_STATE_STOPPING. @n
171 * After IAudioRecorderEventListener::OnAudioRecorderCanceled() is called, the state is changed
172 * to ::RECORDER_STATE_STOPPED.
173 * @see Record(), Stop()
178 * Gets the state of an audio recorder.
180 * @return The current state of an audio recorder
181 * @exception E_SUCCESS The method is successful.
182 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
183 * @exception E_OUT_OF_MEMORY The memory is insufficient.
184 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
185 * @remarks The specific error code can be accessed using the GetLastResult() method.
186 * @see CreateAudioFile(), Close(), Record(), Stop(), Pause()
188 RecorderState GetState(void) const;
191 * Gets the current recording time.
193 * @return The value indicating the current recording time in milliseconds, @n
194 * else @c -1 if the recording has not started as yet
195 * @exception E_SUCCESS The method is successful.
196 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
197 * @exception E_OUT_OF_MEMORY The memory is insufficient.
198 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
199 * @remarks The specific error code can be accessed using the GetLastResult() method.
201 long GetRecordingTime(void) const;
204 * Gets the current recording size.
206 * @return The value indicating the current recording size in bytes, @n
207 * else @c -1 if the recording has not started as yet
208 * @exception E_SUCCESS The method is successful.
209 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
210 * @exception E_OUT_OF_MEMORY The memory is insufficient.
211 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
212 * @remarks The specific error code can be accessed using the GetLastResult() method.
214 long GetRecordingSize(void) const;
217 * Sets the recording time limit for a file in milliseconds.
219 * @return An error code
220 * @param[in] msTime The maximum recording time in milliseconds @n
221 * The time must be greater than @c 0.
222 * @exception E_SUCCESS The method is successful.
223 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
224 * @exception E_OUT_OF_RANGE The specified time is out of range.
225 * @exception E_OUT_OF_MEMORY The memory is insufficient.
226 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
227 * @remarks The default time is @c 60 seconds.
228 * @see GetMaxRecordingTime()
230 result SetMaxRecordingTime(long msTime);
233 * Gets the recording time limit of a file in milliseconds.
235 * @return A @c long value indicating the maximum recording time in milliseconds
236 * @exception E_SUCCESS The method is successful.
237 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
238 * @exception E_OUT_OF_MEMORY The memory is insufficient.
239 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
240 * @remarks The specific error code can be accessed using the GetLastResult() method.
241 * @see SetMaxRecordingTime()
243 long GetMaxRecordingTime(void) const;
246 * Sets the audio format of an audio recorder. @n
247 * Initially, the default format is set using the internal configuration.
249 * @return An error code
250 * @param[in] format The audio format to set @n
251 * ::AUDIORECORDING_FORMAT_DEFAULT sets the system's default recording format.
252 * @exception E_SUCCESS The method is successful.
253 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
254 * @exception E_UNSUPPORTED_FORMAT The specified format is not supported.
255 * @exception E_OUT_OF_MEMORY The memory is insufficient.
256 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
259 result SetFormat(AudioRecordingFormat format);
262 * Gets the audio recording format of an audio recorder.
264 * @return The audio recording format, @n
265 * else default format if SetFormat() is not called before calling this method
266 * @exception E_SUCCESS The method is successful.
267 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
268 * @exception E_OUT_OF_MEMORY The memory is insufficient.
269 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
270 * @remarks The specific error code can be accessed using the GetLastResult() method.
273 AudioRecordingFormat GetFormat(void) const;
276 * Sets the audio codec and the container of an audio recorder. @n
277 * Initially, the default codec and the container format are set using the internal configuration.
279 * @return An error code
280 * @param[in] audioCodec The audio codec to set
281 * @param[in] container The media container to set
282 * @exception E_SUCCESS The method is successful.
283 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
284 * @exception E_UNSUPPORTED_CODEC The specified codec is not supported.
285 * @exception E_UNSUPPORTED_FORMAT The specified container format is not supported.
286 * @exception E_SYSTEM A system error has occurred.
287 * @exception E_OUT_OF_MEMORY The memory is insufficient.
288 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
289 * @remarks If the specified container does not support the specified codec, E_UNSUPPORTED_FORMAT may be thrown.
290 * @see GetFormat( CodecType& audioCodec, MediaContainerType& container ) const
292 result SetFormat(CodecType audioCodec, MediaContainerType container);
295 * Gets the audio codec and container of an audio recorder.
297 * @return An error code
298 * @param[out] audioCodec The retrieved audio codec
299 * @param[out] container The retrieved container
300 * @remarks If SetFormat(CodecType audioCodec, MediaContainerType container) is not called before calling
301 * this method, the default codec and container are retrieved.
302 * @see SetFormat( CodecType audioCodec, MediaContainerType container )
304 void GetFormat(CodecType& audioCodec, MediaContainerType& container) const;
307 * Gets a list of the supported audio codecs. @n
308 * Each list's item has a ::CodecType value.
310 * @return A list of supported audio codecs, @n
311 * else @c null if no codec is supported or if an exception occurs
312 * @exception E_SUCCESS The method is successful.
313 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
314 * @exception E_SYSTEM A system error has occurred.
315 * @exception E_OUT_OF_MEMORY The memory is insufficient.
316 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
317 * @remarks The specific error code can be accessed using the GetLastResult() method. @n
318 * The return value must be released by the caller.
319 * @see SetFormat(CodecType audioCodec, MediaContainerType container), GetFormat(CodecType&
320 * audioCodec, MediaContainerType& container) const
322 Tizen::Base::Collection::ArrayListT <CodecType>* GetSupportedCodecListN(void) const;
325 * Gets a list of the supported containers. @n
326 * Each list's item has a ::MediaContainerType value.
328 * @return A list of supported container list, @n
329 * else @c null if no container is supported or if an exception occurs
330 * @exception E_SUCCESS The method is successful.
331 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
332 * @exception E_SYSTEM A system error has occurred.
333 * @exception E_OUT_OF_MEMORY The memory is insufficient.
334 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
335 * @remarks The specific error code can be accessed using the GetLastResult() method. @n
336 * The return value must be released by the caller.
337 * @see SetFormat(CodecType audioCodec, MediaContainerType container), GetFormat(CodecType&
338 * audioCodec, MediaContainerType& container) const
340 Tizen::Base::Collection::ArrayListT <MediaContainerType>* GetSupportedContainerListN(void) const;
343 * Sets the audio recording quality of the audio recorder.
345 * @return An error code
346 * @param[in] quality The audio recording quality of the audio recorder @n
347 * The default value is ::RECORDING_QUALITY_MEDIUM.
348 * @exception E_SUCCESS The method is successful.
349 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
350 * @exception E_INVALID_ARG The specified @c quality is not supported.
351 * @exception E_OUT_OF_MEMORY The memory is insufficient.
352 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
355 result SetQuality(RecordingQuality quality);
358 * Gets the audio recording quality of the audio recorder.
360 * @return The current audio recording quality of the audio recorder
361 * @exception E_SUCCESS The method is successful.
362 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
363 * @exception E_OUT_OF_MEMORY The memory is insufficient.
364 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
365 * @remarks The specific error code can be accessed using the GetLastResult() method.
368 RecordingQuality GetQuality(void) const;
371 * Enables or disables the mute state of an audio recorder.
373 * @return An error code
374 * @param[in] mute The mute state @n
375 * By default, the mute state is disabled.
376 * @exception E_SUCCESS The method is successful.
377 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
378 * @exception E_OUT_OF_MEMORY The memory is insufficient.
379 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
380 * @remarks The audio recording continues even though the audio recorder is in the mute state.
383 result SetMute(bool mute);
386 * Checks whether the mute state is enabled for an audio recorder.
388 * @return @c true if the audio recorder is not recording any sound, @n
390 * @exception E_SUCCESS The method is successful.
391 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
392 * @exception E_OUT_OF_MEMORY The memory is insufficient.
393 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
394 * @remarks The specific error code can be accessed using the GetLastResult() method.
397 bool IsMuted(void) const;
402 * @param[in] state new _AudioRecorder's state
404 void SetState(RecorderState state);
407 * Sets the recording time
409 * @param[in] recTime recording time in milliseconds
411 void SetRecordingTime(long recTime);
414 * Sets the recording size
416 * @param[in] recSize recording size in bytes
418 void SetRecordingSize(long recSize);
421 * Gets the new media type from the old type.
423 * @param[in] format recording type
424 * @param[out] codec codec type matching the input format
425 * @param[out] container container type matching the input format
428 void GetMediaType(AudioRecordingFormat format, CodecType& codec, MediaContainerType& container) const;
431 * Gets the old media type from the new type.
433 * @param[in] container container type
434 * @param[out] format format type matching the input container
437 void GetMediaType(MediaContainerType container, AudioRecordingFormat& format) const;
440 * Gets the recorder's state.
445 recorder_state_e GetMmState(void) const;
448 * Get the event processing object.
450 * @return The event processing object.
451 * @remarks This event is working synchronously.
453 _AudioRecorderEvent* GetEvent(void) const;
456 * Message callback function
458 * @param[in] previous Previous recorder state
459 * @param[in] current Current recorder state
460 * @param[in] byPolicy true if the state is changed by policy, otherewise false
461 * @param[in] pUserData User data
463 static void StateChangedCb(recorder_state_e previous, recorder_state_e current, bool byPolicy, void* pUserData);
466 * Recording Status callback function
468 * @param[in] elapsedTime recording time elapsed
469 * @param[in] fileSize size of file written
470 * @param[in] pUserData User data
472 static void RecordingStatusCb(unsigned long long elapsedTime, unsigned long long fileSize, void *pUserData);
475 * Audio stream callback function
477 * @param[in] pStream Stream data
478 * @param[in] format Sample format
479 * @param[in] channel Sample channel
480 * @param[in] timeStampl The time stamp
481 * @param[in] pUserData User data
483 static void AudioStreamCb(void* pStream, int size, audio_sample_type_e format, int channel, unsigned int timeStamp, void *pUserData);
486 * Limit reached callback function
488 * @param[in] type Limit reached reason
489 * @param[in] pUserData User data
491 static void LimitReachedCb(recorder_recording_limit_type_e type, void *pUserData);
494 * Message callback function
496 * @param[in] error Error reason
497 * @param[in] state Error state
498 * @param[in] pUserData User data
500 static void ErrorCb(recorder_error_e error, recorder_state_e state, void *pUserData);
503 * Message callback function
505 * @param[in] policy The policy which occurs the interruption
506 * @param[in] previous Previous recorder state
507 * @param[in] current Current recorder state
508 * @param[in] pUserData User data
510 static void InterruptedCb(recorder_policy_e policy, recorder_state_e previous, recorder_state_e current, void *pUserData);
513 * Function check fo this object is alive.
515 * @return true if the object is alive, otherwise false.
517 static bool IsAlive(void);
520 * Gets the Impl instance.
522 * @return The pointer to %_AudioRecorderImpl
523 * @param[in] pAudioRecorder The %AudioRecorder pointer
525 static _AudioRecorderImpl* GetInstance(AudioRecorder *pAudioRecorder);
528 * Gets the Impl instance.
530 * @return The pointer to %_AudioRecorderImpl
531 * @param[in] pAudioRecorder The %AudioRecorder pointer
533 static const _AudioRecorderImpl* GetInstance(const AudioRecorder *pAudioRecorder);
536 * Adds the stream filter to process the audio stream data while recording.
538 * @return An error code
539 * @param[in] filter An instance of IAudioStreamFilter
540 * @exception E_SUCCESS The method is successful.
541 * @exception E_OBJ_ALREADY_EXIST The filter already exists.
542 * @exception E_OUT_OF_MEMORY The memory is insufficient.
544 result AddAudioStreamFilter(IAudioStreamFilter& filter);
547 * Removes the stream filter to stop processing the audio stream data.
549 * @return An error code
550 * @param[in] filter An instance of IAudioStreamFilter
551 * @exception E_SUCCESS The method is successful.
552 * @exception E_OBJ_NOT_FOUND The filter is not found.
554 result RemoveAudioStreamFilter(IAudioStreamFilter& filter);
558 * Converts the error from recorder to Result.
560 * @return An error code
561 * @param[in] err recorder error
563 result ConvertResult(int err) const;
566 * Transfer the state.
568 * @return An error code
569 * @param[in] mmDestState recorder's destinationed state
570 * @param[in] reason state changed reason
571 * @remarks This method makes the recorder's state change. @n
572 * Sometimes, acccording to this, Recorder's state is changed.
574 result ChangeStateTo(recorder_state_e mmDestState, _RecorderStateChangeReason reason);
577 * Checks the operation is for completing.
579 * @return The state change reason
580 * @remarks If the Cancel() is called, this value is false, because the Record() is not completed.
582 _RecorderStateChangeReason GetStateChangeReason(void) const;
585 * Re-load configuration.
587 * @return An error code
588 * @param[in] reload reload configuration field
589 * @exception E_SUCCESS The method is successful.
590 * @exception E_SYSTEM A system error has occurred.
591 * @remarks Multiple configuration field can be set using reloadConf parameter appending.
593 result ReloadConfiguration(int reload);
595 _AudioRecorderImpl(const _AudioRecorderImpl&);
596 _AudioRecorderImpl& operator =(const _AudioRecorderImpl& _AudioRecorderImpl);
598 std::unique_ptr <_AudioRecorderEvent> __pAudioRecorderEvent;
599 IAudioRecorderEventListener* __pAudioRecorderEventListener;
600 _RecorderManager* __pRecorderManager;
601 bool __isConstructed;
602 RecorderState __state;
606 AudioRecordingFormat __format;
607 CodecType __audioCodec;
608 MediaContainerType __container;
609 RecordingQuality __quality;
611 _RecorderHandle __handle;
612 _RecorderStateChangeReason __stateChangeReason;
613 static bool __isUsed;
614 std::unique_ptr <_AudioStreamCoordinator> __pAudioStreamCoordinator;
615 int __audioStreamTimeDuration;
616 bool __audioStreamCallback;