merge with master
[platform/core/multimedia/libmm-sound.git] / include / mm_sound.h
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 /**
23  * @file                mm_sound.h
24  * @brief               Application interface library for sound module.
25  * @date
26  * @version             Release
27  *
28  * Application interface library for sound module.
29  */
30
31 #ifndef __MM_SOUND_H__
32 #define __MM_SOUND_H__
33
34 #include <mm_types.h>
35 #include <mm_error.h>
36 #include <mm_message.h>
37
38 #ifdef __cplusplus
39         extern "C" {
40 #endif
41
42 /**
43         @addtogroup SOUND
44         @{
45         @par
46         This part is describes the sound module of multimedia framework. Sound
47         module provides APIs to implement play wav file with simple api, to handle volume information,
48         to handle audio route policy.
49
50         @par
51         There is six different volume type for normal usage. application should set proper volume type to multimedia playback APIs.
52         <div> <table>
53         <tr>
54         <td><B>Type</B></td>
55         <td><B>Description</B></td>
56         </tr>
57         <tr>
58         <td>VOLUME_TYPE_SYSTEM</td>
59         <td>volume for normal system sound (e.g. keysound, camera shutter)</td>
60         </tr>
61         <tr>
62         <td>VOLUME_TYPE_NOTIFICATION</td>
63         <td>volume for notification (e.g. message, email notification)</td>
64         </tr>
65         <tr>
66         <td>VOLUME_TYPE_RINGTONE</td>
67         <td>volume for incoming call ring</td>
68         </tr>
69         <tr>
70         <td>VOLUME_TYPE_MEDIA</td>
71         <td>volume for media playback (e.g. music, video playback)</td>
72         </tr>
73         <tr>
74         <td>VOLUME_TYPE_CALL</td>
75         <td>volume for call</td>
76         </tr>
77         </table> </div>
78
79         @par
80         application can change audio route policy with mm-sound API.
81         Audio route is input and output of audio stream.
82
83         @par
84         @image html             audio_device.png        "Figure1. Audio Devices of mobile phone"        width=12cm
85         @image latex    audio_device.png        "Figure1. Audio Devices of mobile phone"        width=12cm
86
87         @par
88         Default audio route policy is like follows
89         @par
90         for playback
91         <div><table>
92         <tr>
93         <td><B>Bluetooth headset</B></td>
94         <td><B>Wired headset</B></td>
95         <td><B>Playback Device</B></td>
96         </tr>
97         <tr>
98         <td>connected</td>
99         <td>plugged</td>
100         <td>Bluetooth headset</td>
101         </tr>
102         <tr>
103         <td>connected</td>
104         <td>unplugged</td>
105         <td>Bluetooth headset</td>
106         </tr>
107         <tr>
108         <td>disconnected</td>
109         <td>plugged</td>
110         <td>Wired headset</td>
111         </tr>
112         <tr>
113         <td>disconnected</td>
114         <td>unplugged</td>
115         <td>Loud speaker</td>
116         </tr>
117         </table></div>
118
119         @par
120         for capture (bluetooth headset mic used only in call mode)
121         <div><table>
122         <tr>
123         <td><B>Bluetooth headset mic</B></td>
124         <td><B>Wired headset mic</B></td>
125         <td><B>Capture Device</B></td>
126         </tr>
127         <tr>
128         <td>connected</td>
129         <td>plugged</td>
130         <td>Wired headset mic</td>
131         </tr>
132         <tr>
133         <td>connected</td>
134         <td>unplugged</td>
135         <td>microphone</td>
136         </tr>
137         <tr>
138         <td>disconnected</td>
139         <td>plugged</td>
140         <td>Wired headset mic</td>
141         </tr>
142         <tr>
143         <td>disconnected</td>
144         <td>unplugged</td>
145         <td>Wired headset mic</td>
146         </tr>
147         </table></div>
148
149         @par
150         If application changes routing policy to SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP with mm_sound_route_set_system_policy
151         audio routing policy has changed to ignore bluetooth headset connection.
152         @par
153         for playback
154         <div><table>
155         <tr>
156         <td><B>Bluetooth headset</B></td>
157         <td><B>Wired headset</B></td>
158         <td><B>Playback Device</B></td>
159         </tr>
160         <tr>
161         <td>connected</td>
162         <td>plugged</td>
163         <td>Wired headset</td>
164         </tr>
165         <tr>
166         <td>connected</td>
167         <td>unplugged</td>
168         <td>Loud speaker</td>
169         </tr>
170         <tr>
171         <td>disconnected</td>
172         <td>plugged</td>
173         <td>Wired headset</td>
174         </tr>
175         <tr>
176         <td>disconnected</td>
177         <td>unplugged</td>
178         <td>Loud speaker</td>
179         </tr>
180         </table></div>
181
182         @par
183         for capture (bluetooth headset mic used only in call mode)
184         <div><table>
185         <tr>
186         <td><B>Bluetooth headset mic</B></td>
187         <td><B>Wired headset mic</B></td>
188         <td><B>Capture Device</B></td>
189         </tr>
190         <tr>
191         <td>connected</td>
192         <td>plugged</td>
193         <td>Wired headset mic</td>
194         </tr>
195         <tr>
196         <td>connected</td>
197         <td>unplugged</td>
198         <td>microphone</td>
199         </tr>
200         <tr>
201         <td>disconnected</td>
202         <td>plugged</td>
203         <td>Wired headset mic</td>
204         </tr>
205         <tr>
206         <td>disconnected</td>
207         <td>unplugged</td>
208         <td>Wired headset mic</td>
209         </tr>
210         </table></div>
211
212         @par
213         If application changes routing policy to SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY with mm_sound_route_set_system_policy
214         audio routing policy has changed to use only loud speaker and microphone.
215         @par
216         for playback
217         <div><table>
218         <tr>
219         <td><B>Bluetooth headset</B></td>
220         <td><B>Wired headset</B></td>
221         <td><B>Playback Device</B></td>
222         </tr>
223         <tr>
224         <td>connected</td>
225         <td>plugged</td>
226         <td>Loud speaker</td>
227         </tr>
228         <tr>
229         <td>connected</td>
230         <td>unplugged</td>
231         <td>Loud speaker</td>
232         </tr>
233         <tr>
234         <td>disconnected</td>
235         <td>plugged</td>
236         <td>Loud speaker</td>
237         </tr>
238         <tr>
239         <td>disconnected</td>
240         <td>unplugged</td>
241         <td>Loud speaker</td>
242         </tr>
243         </table></div>
244
245         @par
246         for capture (bluetooth headset mic used only in call mode)
247         <div><table>
248         <tr>
249         <td><B>Bluetooth headset mic</B></td>
250         <td><B>Wired headset mic</B></td>
251         <td><B>Capture Device</B></td>
252         </tr>
253         <tr>
254         <td>connected</td>
255         <td>plugged</td>
256         <td>microphone</td>
257         </tr>
258         <tr>
259         <td>connected</td>
260         <td>unplugged</td>
261         <td>microphone</td>
262         </tr>
263         <tr>
264         <td>disconnected</td>
265         <td>plugged</td>
266         <td>microphone</td>
267         </tr>
268         <tr>
269         <td>disconnected</td>
270         <td>unplugged</td>
271         <td>microphone</td>
272         </tr>
273         </table></div>
274
275  */
276
277 /*
278  * MMSound Volume APIs
279  */
280
281 /**
282  * Enumerations of Volume type.
283  */
284
285 typedef enum {
286         VOLUME_TYPE_SYSTEM,                             /**< System volume type */
287         VOLUME_TYPE_NOTIFICATION,               /**< Notification volume type */
288         VOLUME_TYPE_ALARM,                              /**< Alarm volume type */
289         VOLUME_TYPE_RINGTONE,                   /**< Ringtone volume type */
290         VOLUME_TYPE_MEDIA,                              /**< Media volume type */
291         VOLUME_TYPE_CALL,                               /**< Call volume type */
292         VOLUME_TYPE_VOIP,                               /**< VOIP volume type */
293         VOLUME_TYPE_FIXED,                              /**< Volume type for fixed acoustic level */
294         VOLUME_TYPE_EXT_JAVA,                   /**< External system volume for Java */
295         VOLUME_TYPE_MAX,                                /**< Volume type count */
296         VOLUME_TYPE_EXT_ANDROID = VOLUME_TYPE_FIXED,            /**< External system volume for Android */
297 } volume_type_t;
298
299 typedef enum {
300         VOLUME_GAIN_DEFAULT             = 0,
301         VOLUME_GAIN_DIALER              = 1<<8,
302         VOLUME_GAIN_TOUCH               = 2<<8,
303         VOLUME_GAIN_AF                  = 3<<8,
304         VOLUME_GAIN_SHUTTER1    = 4<<8,
305         VOLUME_GAIN_SHUTTER2    = 5<<8,
306         VOLUME_GAIN_CAMCORDING  = 6<<8,
307         VOLUME_GAIN_MIDI                = 7<<8,
308         VOLUME_GAIN_BOOTING             = 8<<8,
309         VOLUME_GAIN_VIDEO               = 9<<8,
310         VOLUME_GAIN_VIDEO_HDMI  = 10<<8,
311 } volume_gain_t;
312
313 /**
314  * Volume change callback function type.
315  *
316  * @param       user_data               [in]    Argument passed when callback has called
317  *
318  * @return      No return value
319  * @remark      None.
320  * @see         mm_sound_volume_add_callback mm_sound_volume_remove_callback
321  */
322 typedef void (*volume_callback_fn)(void* user_data);
323
324 /**
325  * This function is to retrieve number of volume level.
326  *
327  * @param       type                    [in]    volume type to query
328  * @param       step                    [out]   number of volume steps
329  *
330  * @return      This function returns MM_ERROR_NONE on success, or negative value
331  *                      with error code.
332  * @remark      step means number of steps. so actual volume step can be 0 ~ step-1
333  * @see         volume_type_t
334  * @pre         None.
335  * @post        None.
336  * @par Example
337  * @code
338 int step = 0;
339 int ret = 0;
340 int max = 0;
341
342 ret = mm_sound_volume_get_step(VOLUME_TYPE_SYSTEM, &step);
343 if(ret < 0)
344 {
345         printf("Can not get volume step\n");
346 }
347 else
348 {
349         max = step - 1;
350         //set system volume to max value
351         mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, max);
352 }
353  * @endcode
354  */
355 int mm_sound_volume_get_step(volume_type_t type, int *step);
356
357
358 /**
359  * This function is to add volume changed callback.
360  *
361  * @param       type                    [in]    volume type to set change callback function
362  * @param       func                    [in]    callback function pointer
363  * @param       user_data               [in]    user data passing to callback function
364  *
365  * @return      This function returns MM_ERROR_NONE on success, or negative value
366  *                      with error code.
367  * @remark      Only one callback function per volume type will be registered.
368  *                      if you want to change callback function for certain volume type,
369  *                      remove callback first via mm_sound_volume_remove_callback().
370  * @see         volume_type_t volume_callback_fn
371  * @pre         There should be not be pre-registered callback fuction to given volume type.
372  * @post        Callback function will be registered to given volume type
373  * @par Example
374  * @code
375 volume_type_t g_vol_type = VOLUME_TYPE_MEDIA;
376
377 void _volume_callback(void *data)
378 {
379         unsigned int value = 0;
380         int result = 0;
381         volume_type_t *type = (volume_type_t*)data;
382
383         result = mm_sound_volume_get_value(*type, &value);
384         if(result == MM_ERROR_NONE)
385         {
386                 printf("Current volume value is %d\n", value);
387         }
388         else
389         {
390                 printf("Can not get volume\n");
391         }
392 }
393
394 int volume_control()
395 {
396         int ret = 0;
397
398         ret = mm_sound_volume_add_callback(g_vol_type, _volume_callback, (void*)&g_vol_type);
399         if ( MM_ERROR_NONE != ret)
400         {
401                 printf("Can not add callback\n");
402         }
403         else
404         {
405                 printf("Add callback success\n");
406         }
407
408         return 0;
409 }
410
411  * @endcode
412  */
413 int mm_sound_volume_add_callback(volume_type_t type, volume_callback_fn func, void* user_data);
414
415
416 /**
417  * This function is to remove volume changed callback.
418  *
419  * @param       type                    [in]    volume type to set change callback function
420  *
421  * @return      This function returns MM_ERROR_NONE on success, or negative value
422  *                      with error code.
423  * @remark      None.
424  * @pre         Callback function should be registered previously for given volume type.
425  * @post        Callback function will not be called anymore.
426  * @see         volume_type_t
427  * @par Example
428  * @code
429 void _volume_callback(void *data)
430 {
431         printf("Callback function\n");
432 }
433
434 int volume_callback()
435 {
436         int ret = 0;
437         int vol_type = VOLUME_TYPE_MEDIA;
438
439         mm_sound_volume_add_callback(vol_type, _volume_callback, NULL);
440
441         ret = mm_sound_volume_remove_callback(vol_type);
442         if ( MM_ERROR_NONE == ret)
443         {
444                 printf("Remove callback success\n");
445         }
446         else
447         {
448                 printf("Remove callback failed\n");
449         }
450
451         return ret;
452 }
453
454  * @endcode
455  */
456 int mm_sound_volume_remove_callback(volume_type_t type);
457
458
459 /**
460  * This function is to set volume level of certain volume type.
461  *
462  * @param       type                    [in]    volume type to set value.
463  * @param       value                   [in]    volume value.
464  *
465  * @return      This function returns MM_ERROR_NONE on success, or negative value
466  *                      with error code.
467  * @remark      value should be 0 ~ mm_sound_volume_get_step() -1
468  * @see         mm_sound_volume_get_step, mm_sound_volume_get_value volume_type_t
469  * @pre         None.
470  * @post        Volume value will be changed to given value for given volume type.
471  * @par Example
472  * @code
473 int step = 0;
474 int ret = 0;
475 int max = 0;
476
477 ret = mm_sound_volume_get_step(VOLUME_TYPE_SYSTEM, &step);
478 if(ret < 0)
479 {
480         printf("Can not get volume step\n");
481 }
482 else
483 {
484         max = step - 1;
485         //set system volume to max value
486         ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, max);
487         if(ret < 0)
488         {
489                 printf("Can not set volume value\n");
490         }
491 }
492  * @endcode
493  */
494 int mm_sound_volume_set_value(volume_type_t type, const unsigned int value);
495
496
497
498 /**
499  * This function is to get volume level of certain volume type.
500  *
501  * @param       type                    [in]    volume type to get value.
502  * @param       value                   [out]   volume value.
503  *
504  * @return      This function returns MM_ERROR_NONE on success, or negative value
505  *                      with error code.
506  * @remark      None.
507  * @pre         None.
508  * @post        None.
509  * @see         volume_type_t mm_sound_volume_set_value
510  * @par Example
511  * @code
512 int value = 0;
513 int ret = 0;
514
515 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
516 if(ret < 0)
517 {
518         printf("Can not get volume\n");
519 }
520 else
521 {
522         printf("System type volume is %d\n", value);
523 }
524  * @endcode
525  * @see         mm_sound_volume_set_value
526  */
527 int mm_sound_volume_get_value(volume_type_t type, unsigned int *value);
528
529
530
531 /**
532  * This function is to set primary volume type.
533  *
534  * @param       type                    [in]    volume type to set as primary volume type.
535  *
536  * @return      This function returns MM_ERROR_NONE on success, or negative value
537  *                      with error code.
538  * @remark      Application should use this function during foreground.
539  *                      Application should clear primary volume type by mm_sound_volume_primary_type_clear() when it goes background.
540  * @pre         None.
541  * @post        Volume app. will be update given volume type when H/W volume control key pressed.
542  * @see         mm_sound_volume_primary_type_clear volume_type_t
543  * @par Example
544  * @code
545 static int _resume(void *data)
546 {
547         int ret = 0;
548
549         ret = mm_sound_volume_primary_type_set(VOLUME_TYPE_MEDIA);
550         if(ret < 0)
551         {
552                 printf("Can not set primary volume type\n");
553         }
554         ...
555 }
556
557 static int _pause(void* data)
558 {
559         int ret = 0;
560
561         ret = mm_sound_volume_primary_type_clear();
562         if(ret < 0)
563         {
564                 printf("Can not clear primary volume type\n");
565         }
566         ...
567 }
568
569 int main()
570 {
571         ...
572         struct appcore_ops ops = {
573                 .create = _create,
574                 .terminate = _terminate,
575                 .pause = _pause,
576                 .resume = _resume,
577                 .reset = _reset,
578         };
579         ...
580         return appcore_efl_main(PACKAGE, ..., &ops);
581 }
582  * @endcode
583  */
584 int mm_sound_volume_primary_type_set(volume_type_t type);
585
586
587
588 /**
589  * This function is to clear primary volume type.
590  *
591  *
592  * @return      This function returns MM_ERROR_NONE on success, or negative value
593  *                      with error code.
594  * @remark      mm_sound_volume_primary_type_set() and mm_sound_volume_primary_type_clear() should be used as pair
595  * @see         mm_sound_volume_primary_type_set
596  * @pre         primary volume should be set at same process.
597  * @post        primary volume will be cleared.
598  * @par Example
599  * @code
600 static int _resume(void *data)
601 {
602         int ret = 0;
603
604         ret = mm_sound_volume_primary_type_set(VOLUME_TYPE_MEDIA);
605         if(ret < 0)
606         {
607                 printf("Can not set primary volume type\n");
608         }
609         ...
610 }
611
612 static int _pause(void* data)
613 {
614         int ret = 0;
615
616         ret = mm_sound_volume_primary_type_clear();
617         if(ret < 0)
618         {
619                 printf("Can not clear primary volume type\n");
620         }
621         ...
622 }
623
624 int main()
625 {
626         ...
627         struct appcore_ops ops = {
628                 .create = _create,
629                 .terminate = _terminate,
630                 .pause = _pause,
631                 .resume = _resume,
632                 .reset = _reset,
633         };
634         ...
635         return appcore_efl_main(PACKAGE, ..., &ops);
636 }
637  * @endcode
638  */
639 int mm_sound_volume_primary_type_clear();
640
641
642
643 /**
644  * This function is to get current playing volume type
645  *
646  * @param       type                    [out]   current playing volume type
647  *
648  * @return      This function returns MM_ERROR_NONE on success,
649  *          or MM_ERROR_SOUND_VOLUME_NO_INSTANCE when there is no existing playing instance,
650  *          or MM_ERROR_SOUND_VOLUME_CAPTURE_ONLY when only capture audio instances are exist.
651  *          or negative value with error code for other errors.
652  * @remark      None.
653  * @pre         None.
654  * @post        None.
655  * @see         mm_sound_volume_get_value, mm_sound_volume_set_value
656  * @par Example
657  * @code
658 int ret=0;
659 volume_type_t type = 0;
660
661 ret = mm_sound_volume_get_current_playing_type(&type);
662 switch(ret)
663 {
664 case MM_ERROR_NONE:
665         printf("Current playing is %d\n", type);
666         break;
667 case MM_ERROR_SOUND_VOLUME_NO_INSTANCE:
668         printf("No sound instance\n");
669         break;
670 case MM_ERROR_SOUND_VOLUME_CAPTURE_ONLY:
671         printf("Only sound capture instances are exist\n");
672         break;
673 default:
674         printf("Error\n");
675         break;
676 }
677
678  * @endcode
679  */
680 int mm_sound_volume_get_current_playing_type(volume_type_t *type);
681
682
683 /*
684  * MMSound PCM APIs
685  */
686 typedef void*   MMSoundPcmHandle_t;     /**< MMsound PCM handle type */
687
688 /**
689  * Enumerations of Format used in MMSoundPcm operation.
690  */
691 typedef enum {
692         MMSOUND_PCM_U8 = 0x70, /**< unsigned 8bit audio */
693         MMSOUND_PCM_S16_LE,   /**< signed 16bit audio */
694 } MMSoundPcmFormat_t;
695
696 /**
697  * Enumerations of Channel count used in MMSoundPcm operation.
698  */
699 typedef enum {
700         MMSOUND_PCM_MONO = 0x80,        /**< Mono channel */
701         MMSOUND_PCM_STEREO,                     /**< Stereo channel */
702 }MMSoundPcmChannel_t;
703
704
705 /**
706  * This function is to create handle for PCM playback.
707  *
708  * @param       handle  [out] handle to play pcm data
709  * @param       rate    [in] sample rate (8000Hz ~ 44100Hz)
710  * @param       channel [in] number of channels (mono or stereo)
711  * @param       format  [in] S8 or S16LE
712  * @param       volume  [in] volume type
713  *
714  * @return      This function returns suggested buffer size (in bytes) on success, or negative value
715  *                      with error code.
716  * @remark      use mm_sound_volume_set_value() function to change volume
717  * @see         mm_sound_pcm_play_write, mm_sound_pcm_play_close, mm_sound_volume_set_value, MMSoundPcmFormat_t, MMSoundPcmChannel_t volume_type_t
718  * @pre         None.
719  * @post        PCM play handle will be created.
720  * @par Example
721  * @code
722 #include <mm_sound.h>
723 #include <stdio.h>
724 #include <alloca.h>
725
726 int main(int argc, char* argv[])
727 {
728         FILE *fp = NULL;
729         char *buffer = NULL;
730         int ret = 0;
731         int size = 0;
732         int readed = 0;
733         MMSoundPcmHandle_t handle;
734         char *filename = NULL;
735
736         if(argc !=2 )
737         {
738                 printf("Usage) %s filename\n", argv[0]);
739                 return -1;
740         }
741         filename = argv[1];
742
743         fp = fopen(filename,"r");
744         if(fp ==NULL)
745         {
746                 printf("Can not open file %s\n", filename);
747                 return -1;
748         }
749
750         size = mm_sound_pcm_play_open(&handle, 44100, MMSOUND_PCM_STEREO, MMSOUND_PCM_S16_LE, VOLUME_TYPE_SYSTEM);
751         if(size < 0)
752         {
753                 printf("Can not open playback handle\n");
754                 return -2;
755         }
756
757         buffer = alloca(size);
758         while((readed = fread(buffer, size, sizeof(char), fp)) > 0 )
759         {
760                 ret = mm_sound_pcm_play_write(handle, (void*)buffer, readed);
761                 if(ret < 0)
762                 {
763                         printf("write fail\n");
764                         break;
765                 }
766                 memset(buffer, '\0', sizeof(buffer));
767         }
768
769         fclose(fp);
770         mm_sound_pcm_play_close(handle);
771         return 0;
772 }
773  * @endcode
774  */
775 int mm_sound_pcm_play_open(MMSoundPcmHandle_t *handle, const unsigned int rate, MMSoundPcmChannel_t channel, MMSoundPcmFormat_t format, const volume_type_t volume);
776
777 /**
778  * This function start pcm playback
779  *
780  * @param       handle  [in] handle to start playback
781  *
782  * @return      This function returns MM_ERROR_NONE on success, or negative value
783  *                      with error code.
784  * @remark
785  * @see
786  * @pre         PCM playback handle should be allocated.
787  * @post        PCM playback is ready to write.
788  */
789 int mm_sound_pcm_play_start(MMSoundPcmHandle_t handle);
790
791 /**
792  * This function stop pcm playback
793  *
794  * @param       handle  [in] handle to stop playback
795  *
796  * @return      This function returns MM_ERROR_NONE on success, or negative value
797  *                      with error code.
798  * @remark
799  * @see
800  * @pre         PCM playback handle should be allocated.
801  * @post        PCM playback data will not be buffered.
802  */
803 int mm_sound_pcm_play_stop(MMSoundPcmHandle_t handle);
804
805 /**
806  * This function is to play PCM memory buffer.
807  *
808  * @param       handle  [in] handle to play pcm data
809  * @param       ptr             [in] pcm buffer address
810  * @param       length_byte     [in] size of pcm buffer (in bytes)
811  *
812  * @return      This function returns written data size on success, or negative value
813  *                      with error code.
814  * @remark      Make pcm buffer size with returned value of mm_sound_pcm_play_open()
815  * @see         mm_sound_pcm_play_open, mm_sound_pcm_play_close
816  * @pre         PCM play handle should be created.
817  * @post        Sound will be generated with given PCM buffer data.
818  * @par Example
819  * @code
820 #include <mm_sound.h>
821 #include <stdio.h>
822 #include <alloca.h>
823
824 int main(int argc, char* argv[])
825 {
826         FILE *fp = NULL;
827         char *buffer = NULL;
828         int ret = 0;
829         int size = 0;
830         int readed = 0;
831         MMSoundPcmHandle_t handle;
832         char *filename = NULL;
833
834         if(argc !=2 )
835         {
836                 printf("Usage) %s filename\n", argv[0]);
837                 return -1;
838         }
839         filename = argv[1];
840
841         fp = fopen(filename,"r");
842         if(fp ==NULL)
843         {
844                 printf("Can not open file %s\n", filename);
845                 return -1;
846         }
847
848         size = mm_sound_pcm_play_open(&handle, 44100, MMSOUND_PCM_STEREO, MMSOUND_PCM_S16_LE, VOLUME_TYPE_SYSTEM);
849         if(size < 0)
850         {
851                 printf("Can not open playback handle\n");
852                 return -2;
853         }
854
855         buffer = alloca(size);
856         while((readed = fread(buffer, size, sizeof(char), fp)) > 0 )
857         {
858                 ret = mm_sound_pcm_play_write(handle, (void*)buffer, readed);
859                 if(ret < 0)
860                 {
861                         printf("write fail\n");
862                         break;
863                 }
864                 memset(buffer, '\0', sizeof(buffer));
865         }
866
867         fclose(fp);
868         mm_sound_pcm_play_close(handle);
869         return 0;
870 }
871  * @endcode
872  */
873 int mm_sound_pcm_play_write(MMSoundPcmHandle_t handle, void* ptr, unsigned int length_byte);
874
875
876
877 /**
878  * This function is to close PCM memory playback handle
879  *
880  * @param       handle  [in] handle to play pcm data
881  *
882  * @return      This function returns MM_ERROR_NONE on success, or negative value
883  *                      with error code.
884  * @remark      None
885  * @see         mm_sound_pcm_play_open, mm_sound_pcm_play_write
886  * @pre         PCM play handle should be created
887  * @post        PCM play handle will be terminated.
888  * @par Example
889  * @code
890 #include <mm_sound.h>
891 #include <stdio.h>
892 #include <alloca.h>
893
894 int main(int argc, char* argv[])
895 {
896         FILE *fp = NULL;
897         char *buffer = NULL;
898         int ret = 0;
899         int size = 0;
900         int readed = 0;
901         MMSoundPcmHandle_t handle;
902         char *filename = NULL;
903
904         if(argc !=2 )
905         {
906                 printf("Usage) %s filename\n", argv[0]);
907                 return -1;
908         }
909         filename = argv[1];
910
911         fp = fopen(filename,"r");
912         if(fp ==NULL)
913         {
914                 printf("Can not open file %s\n", filename);
915                 return -1;
916         }
917
918         size = mm_sound_pcm_play_open(&handle, 44100, MMSOUND_PCM_STEREO, MMSOUND_PCM_S16_LE, VOLUME_TYPE_SYSTEM);
919         if(size < 0)
920         {
921                 printf("Can not open playback handle\n");
922                 return -2;
923         }
924
925         buffer = alloca(size);
926         while((readed = fread(buffer, size, sizeof(char), fp)) > 0 )
927         {
928                 ret = mm_sound_pcm_play_write(handle, (void*)buffer, readed);
929                 if(ret < 0)
930                 {
931                         printf("write fail\n");
932                         break;
933                 }
934                 memset(buffer, '\0', sizeof(buffer));
935         }
936
937         fclose(fp);
938         mm_sound_pcm_play_close(handle);
939         return 0;
940 }
941  * @endcode
942  */
943 int mm_sound_pcm_play_close(MMSoundPcmHandle_t handle);
944
945 /**
946  * This function is to ignore session for playback
947  *
948  * @param       handle  [in] handle to play pcm data
949  *
950  * @return      This function returns MM_ERROR_NONE on success, or negative value
951  *                      with error code.
952  * @remark      This function only works for not started pcm handle and can't be reversed.
953  * @see
954  * @pre         PCM play handle should be created and not started.
955  * @post        PCM play session will be set to mix.
956  */
957 int mm_sound_pcm_play_ignore_session(MMSoundPcmHandle_t *handle);
958
959 /**
960  * This function is to create handle for PCM capture.
961  *
962  * @param       handle  [out] handle to capture pcm data
963  * @param       rate    [in] sample rate (8000Hz ~ 44100Hz)
964  * @param       channel [in] number of channels (mono or stereo)
965  * @param       format  [in] S8 or S16LE
966  *
967  * @return      This function returns suggested buffer size (in bytes) on success, or negative value
968  *                      with error code.
969  * @remark      only mono channel is valid for now.
970  * @see         mm_sound_pcm_capture_read, mm_sound_pcm_capture_close, MMSoundPcmFormat_t, MMSoundPcmChannel_t
971  * @pre         None.
972  * @post        PCM capture handle will be allocated.
973  * @par Example
974  * @code
975 #include <mm_sound.h>
976 #include <stdio.h>
977 #include <alloca.h>
978
979 int main(int argc, char* argv[])
980 {
981         FILE *fp = NULL;
982         char *buffer = NULL;
983         int ret = 0;
984         int size = 0;
985         int count = 0;
986         MMSoundPcmHandle_t handle;
987         char *filename = NULL;
988
989         if(argc !=2 )
990         {
991                 printf("Usage) %s filename\n", argv[0]);
992                 return -1;
993         }
994         filename = argv[1];
995
996         fp = fopen(filename,"w");
997         if(fp ==NULL)
998         {
999                 printf("Can not open file %s\n", filename);
1000                 return -1;
1001         }
1002
1003         size = mm_sound_pcm_capture_open(&handle, 44100, MMSOUND_PCM_MONO, MMSOUND_PCM_S16_LE);
1004         if(size < 0)
1005         {
1006                 printf("Can not open capture handle\n");
1007                 return -2;
1008         }
1009
1010         buffer = alloca(size);
1011         while(1)
1012         {
1013                 ret = mm_sound_pcm_capture_read(handle, (void*)buffer, size);
1014                 if(ret < 0)
1015                 {
1016                         printf("read fail\n");
1017                         break;
1018                 }
1019                 fwrite(buffer, ret, sizeof(char), fp);
1020                 if(count++ > 20) {
1021                         break;
1022                 }
1023         }
1024
1025         fclose(fp);
1026         mm_sound_pcm_capture_close(handle);
1027         return 0;
1028 }
1029
1030  * @endcode
1031  */
1032 int mm_sound_pcm_capture_open(MMSoundPcmHandle_t *handle, const unsigned int rate, MMSoundPcmChannel_t channel, MMSoundPcmFormat_t format);
1033
1034 /**
1035  * This function start pcm capture
1036  *
1037  * @param       handle  [in] handle to start capture
1038  *
1039  * @return      This function returns read data size on success, or negative value
1040  *                      with error code.
1041  * @remark
1042  * @see
1043  * @pre         PCM capture handle should be allocated.
1044  * @post        PCM capture data will be buffered.
1045  */
1046 int mm_sound_pcm_capture_start(MMSoundPcmHandle_t handle);
1047
1048 /**
1049  * This function stop pcm capture
1050  *
1051  * @param       handle  [in] handle to stop capture
1052  *
1053  * @return      This function returns read data size on success, or negative value
1054  *                      with error code.
1055  * @remark
1056  * @see
1057  * @pre         PCM capture handle should be allocated.
1058  * @post        PCM capture data will not be buffered.
1059  */
1060 int mm_sound_pcm_capture_stop(MMSoundPcmHandle_t handle);
1061
1062 /**
1063  * This function captures PCM to memory buffer. (Samsung extension)
1064  *
1065  * @param       handle  [in] handle to play pcm data
1066  * @param       buffer  [in] pcm buffer address
1067  * @param       length  [in] size of pcm buffer (in bytes)
1068  *
1069  * @return      This function returns read data size on success, or negative value
1070  *                      with error code.
1071  * @remark      Make pcm buffer size with returned value of mm_sound_pcm_capture_open()
1072  * @see         mm_sound_pcm_capture_open, mm_sound_pcm_capture_close
1073  * @pre         PCM capture handle should be allcated.
1074  * @post        PCM data will be filled to given memory pointer.
1075  * @par Example
1076  * @code
1077 #include <mm_sound.h>
1078 #include <stdio.h>
1079 #include <alloca.h>
1080
1081 int main(int argc, char* argv[])
1082 {
1083         FILE *fp = NULL;
1084         char *buffer = NULL;
1085         int ret = 0;
1086         int size = 0;
1087         int count = 0;
1088         MMSoundPcmHandle_t handle;
1089         char *filename = NULL;
1090
1091         if(argc !=2 )
1092         {
1093                 printf("Usage) %s filename\n", argv[0]);
1094                 return -1;
1095         }
1096         filename = argv[1];
1097
1098         fp = fopen(filename,"w");
1099         if(fp ==NULL)
1100         {
1101                 printf("Can not open file %s\n", filename);
1102                 return -1;
1103         }
1104
1105         size = mm_sound_pcm_capture_open(&handle, 44100, MMSOUND_PCM_MONO, MMSOUND_PCM_S16_LE);
1106         if(size < 0)
1107         {
1108                 printf("Can not open capture handle\n");
1109                 return -2;
1110         }
1111
1112         buffer = alloca(size);
1113         while(1)
1114         {
1115                 ret = mm_sound_pcm_capture_read(handle, (void*)buffer, size);
1116                 if(ret < 0)
1117                 {
1118                         printf("read fail\n");
1119                         break;
1120                 }
1121                 fwrite(buffer, ret, sizeof(char), fp);
1122                 if(count++ > 20) {
1123                         break;
1124                 }
1125         }
1126
1127         fclose(fp);
1128         mm_sound_pcm_capture_close(handle);
1129         return 0;
1130 }
1131
1132  * @endcode
1133  */
1134 int mm_sound_pcm_capture_read(MMSoundPcmHandle_t handle, void *buffer, const unsigned int length );
1135
1136 /**
1137  * This function captures PCM memory to memory buffer (Samsung extension)
1138  *
1139  * @param       handle  [in] handle to capture pcm data
1140  *
1141  * @return      This function returns MM_ERROR_NONE on success, or negative value
1142  *                      with error code.
1143  * @remark      None.
1144  * @see         mm_sound_pcm_capture_open, mm_sound_pcm_capture_read
1145  * @pre         PCM capture handle should be opend.
1146  * @post        PCM capture handle will be freed.
1147  * @par Example
1148  * @code
1149 #include <mm_sound.h>
1150 #include <stdio.h>
1151 #include <alloca.h>
1152
1153 int main(int argc, char* argv[])
1154 {
1155         FILE *fp = NULL;
1156         char *buffer = NULL;
1157         int ret = 0;
1158         int size = 0;
1159         int count = 0;
1160         MMSoundPcmHandle_t handle;
1161         char *filename = NULL;
1162
1163         if(argc !=2 )
1164         {
1165                 printf("Usage) %s filename\n", argv[0]);
1166                 return -1;
1167         }
1168         filename = argv[1];
1169
1170         fp = fopen(filename,"w");
1171         if(fp ==NULL)
1172         {
1173                 printf("Can not open file %s\n", filename);
1174                 return -1;
1175         }
1176
1177         size = mm_sound_pcm_capture_open(&handle, 44100, MMSOUND_PCM_MONO, MMSOUND_PCM_S16_LE);
1178         if(size < 0)
1179         {
1180                 printf("Can not open capture handle\n");
1181                 return -2;
1182         }
1183
1184         buffer = alloca(size);
1185         while(1)
1186         {
1187                 ret = mm_sound_pcm_capture_read(handle, (void*)buffer, size);
1188                 if(ret < 0)
1189                 {
1190                         printf("read fail\n");
1191                         break;
1192                 }
1193                 fwrite(buffer, ret, sizeof(char), fp);
1194                 if(count++ > 20) {
1195                         break;
1196                 }
1197         }
1198
1199         fclose(fp);
1200         mm_sound_pcm_capture_close(handle);
1201         return 0;
1202 }
1203
1204  * @endcode
1205  */
1206 int mm_sound_pcm_capture_close(MMSoundPcmHandle_t handle);
1207
1208 /**
1209  * This function is to ignore session for capture
1210  *
1211  * @param       handle  [in] handle to capture pcm data
1212  *
1213  * @return      This function returns MM_ERROR_NONE on success, or negative value
1214  *                      with error code.
1215  * @remark      This function only works for not started pcm handle and can't be reversed.
1216  * @see
1217  * @pre         PCM capture handle should be created and not started.
1218  * @post        PCM capture session will be set to mix.
1219  */
1220 int mm_sound_pcm_capture_ignore_session(MMSoundPcmHandle_t *handle);
1221
1222 /**
1223  * This function sets callback function for receiving messages from pcm API.
1224  *
1225  * @param       handle          [in]    Handle of pcm.
1226  * @param       callback        [in]    Message callback function.
1227  * @param       user_param      [in]    User parameter which is passed to callback function.
1228  *
1229  * @return      This function returns MM_ERROR_NONE on success, or negative value with error code.
1230  * @see         MMMessageCallback
1231  * @remark      None
1232  * @par Example
1233  * @code
1234 int msg_callback(int message, MMMessageParamType *param, void *user_param)
1235 {
1236         switch (message)
1237         {
1238                 case MM_MESSAGE_SOUND_PCM_CAPTURE_RESTRICTED:
1239                         //do something
1240                         break;
1241
1242                 case MM_MESSAGE_SOUND_PCM_INTERRUPTED:
1243                         //do something
1244                         break;
1245
1246                 default:
1247                         break;
1248         }
1249         return TRUE;
1250 }
1251
1252 mm_sound_pcm_set_message_callback(pcmHandle, msg_callback, (void *)pcmHandle);
1253  * @endcode
1254  */
1255 int mm_sound_pcm_set_message_callback (MMSoundPcmHandle_t handle, MMMessageCallback callback, void *user_param);
1256
1257 /**
1258  * Terminate callback function type.
1259  *
1260  * @param       param           [in]    Argument passed when callback was set
1261  *
1262  * @return      No return value
1263  * @remark      It is not allowed to call MMSound API recursively or do time-consuming
1264  *                      task in this callback because this callback is called synchronously.
1265  * @see         mm_sound_play_sound
1266  */
1267 typedef void (*mm_sound_stop_callback_func) (void *data);
1268
1269 /*
1270  * MMSound Play APIs
1271  */
1272
1273 /**
1274  * This function is to play system sound.
1275  *
1276  * @param       filename                [in] Sound filename to play
1277  * @param       volume config   [in] Volume type & volume gain
1278  * @param       callback                [in] Callback function pointer when playing is terminated.
1279  * @param       data                    [in] Pointer to user data when callback is called.
1280  * @param       handle                  [out] Handle of sound play.
1281  *
1282  * @return      This function returns MM_ERROR_NONE on success, or negative value
1283  *                      with error code.
1284  * @remark      When the stop callback is set, it will be called when system sound is
1285  *                      terminated. If mm_sound_stop_sound() is called apparently before
1286  *                      system sound is terminated, stop_callback will not be called.
1287  * @see         mm_sound_stop_sound mm_sound_stop_callback_func volume_type_t volume_gain_t
1288  * @pre         None.
1289  * @post        Sound will be generated with given filename.
1290  * @par Example
1291  * @code
1292 int g_stop=0;
1293 void _stop_callback(void* data)
1294 {
1295         printf("Stop callback\n");
1296         g_stop = 1;
1297 }
1298
1299 int play_file()
1300 {
1301         char filename[] ="/opt/media/Sound/testfile.wav";
1302         volume_type_t volume = VOLUME_TYPE_SYSTEM;
1303         int ret = 0;
1304         int handle = -1;
1305
1306         ret = mm_sound_play_sound(filename, volume, _stop_callback, NULL, &handle);
1307         if(ret < 0)
1308         {
1309                 printf("play file failed\n");
1310         }
1311         else
1312         {
1313                 printf("play file success\n");
1314         }
1315         while(g_stop == 0)
1316         {
1317                 sleep(1);
1318         }
1319         printf("play stopped\n");
1320         return 0;
1321 }
1322  * @endcode
1323  */
1324 int mm_sound_play_sound(const char *filename, int volume_config, mm_sound_stop_callback_func callback, void *data, int *handle);
1325
1326 /**
1327  * This function is to play system sound. And other audio stream will be mute during playing time
1328  *
1329  * @param       filename                [in] Sound filename to play
1330  * @param       volume config   [in] Volume type & volume gain
1331  * @param       callback                [in] Callback function pointer when playing is terminated.
1332  * @param       data                    [in] Pointer to user data when callback is called.
1333  * @param       handle                  [out] Handle of sound play.
1334  *
1335  * @return      This function returns MM_ERROR_NONE on success, or negative value
1336  *                      with error code.
1337  * @remark      This function is almost same with mm_sound_play_sound,
1338  *                      but this make other audio playback stream to mute during playing time.
1339  * @see         mm_sound_stop_sound mm_sound_stop_callback_func volume_type_t volume_gain_t
1340  * @pre         None.
1341  * @post        Sound will be generated with given filename.
1342  * @par Example
1343  * @code
1344 int g_stop=0;
1345 void _stop_callback(void* data)
1346 {
1347         printf("Stop callback\n");
1348         g_stop = 1;
1349 }
1350
1351 int play_file()
1352 {
1353         char filename[] ="/opt/media/Sound/testfile.wav";
1354         volume_type_t volume = VOLUME_TYPE_SYSTEM;
1355         int ret = 0;
1356         int handle = -1;
1357
1358         ret = mm_sound_play_loud_solo_sound(filename, volume, _stop_callback, NULL, &handle);
1359         if(ret < 0)
1360         {
1361                 printf("play file failed\n");
1362         }
1363         else
1364         {
1365                 printf("play file success\n");
1366         }
1367         while(g_stop == 0)
1368         {
1369                 sleep(1);
1370         }
1371         printf("play stopped\n");
1372         return 0;
1373 }
1374  * @endcode
1375  */
1376 int mm_sound_play_loud_solo_sound(const char *filename, int volume_config, mm_sound_stop_callback_func callback, void *data, int *handle);
1377
1378 int mm_sound_play_loud_solo_sound_no_restore(const char *filename, int volume_config, mm_sound_stop_callback_func callback, void *data, int *handle);
1379
1380 /**
1381  * This function is to stop playing system sound.
1382  *
1383  * @param       handle  [in] Handle of mm_sound_play_sound
1384  *
1385  * @return      This function returns MM_ERROR_NONE on success, or negative value
1386  *                      with error code.
1387  *
1388  * @remark      When system sound is terminated with this function call, it does not
1389  *                      call stop callback which was set when start playing system sound.
1390  * @see         mm_sound_play_sound
1391  * @pre         An sound play handle should be valid.
1392  * @post        Playing sound file will be stopped.
1393  * @par Example
1394  * @code
1395 int g_stop=0;
1396 void _stop_callback(void* data)
1397 {
1398         printf("Stop callback\n");
1399         g_stop = 1;
1400 }
1401
1402 int play_file_one_second()
1403 {
1404         char filename[] ="/opt/media/Sound/testfile.wav";
1405         volume_type_t volume = VOLUME_TYPE_SYSTEM;
1406         int ret = 0;
1407         int handle = -1;
1408
1409         ret = mm_sound_play_sound(filename, volume, _stop_callback, NULL, &handle);
1410         if(ret < 0)
1411         {
1412                 printf("play file failed\n");
1413         }
1414         else
1415         {
1416                 printf("play file success\n");
1417         }
1418
1419         sleep(1); //wait 1 second
1420
1421         ret = mm_sound_stop_sound(handle);
1422         if(ret < 0)
1423         {
1424                 printf("stop failed\n");
1425         }
1426         else
1427         {
1428                 printf("play stopped\n");
1429         }
1430         return 0;
1431 }
1432  * @endcode
1433  */
1434 int mm_sound_stop_sound(int handle);
1435
1436
1437 /**
1438  * Enumerations for TONE
1439  */
1440
1441 typedef enum  {
1442         MM_SOUND_TONE_DTMF_0 = 0,                       /**< Predefined DTMF 0 */
1443         MM_SOUND_TONE_DTMF_1,                           /**< Predefined DTMF 1 */
1444         MM_SOUND_TONE_DTMF_2,                           /**< Predefined DTMF 2 */
1445         MM_SOUND_TONE_DTMF_3,                           /**< Predefined DTMF 3 */
1446         MM_SOUND_TONE_DTMF_4,                           /**< Predefined DTMF 4 */
1447         MM_SOUND_TONE_DTMF_5,                           /**< Predefined DTMF 5 */
1448         MM_SOUND_TONE_DTMF_6,                           /**< Predefined DTMF 6 */
1449         MM_SOUND_TONE_DTMF_7,                           /**< Predefined DTMF 7 */
1450         MM_SOUND_TONE_DTMF_8,                           /**< Predefined DTMF 8 */
1451         MM_SOUND_TONE_DTMF_9,                           /**< Predefined DTMF 9 */
1452         MM_SOUND_TONE_DTMF_S,                           /**< Predefined DTMF Star - Asterisk (*) */
1453         MM_SOUND_TONE_DTMF_P,                           /**< Predefined DTMF sharP (#) */
1454         MM_SOUND_TONE_DTMF_A,                           /**< Predefined DTMF A (A) */
1455         MM_SOUND_TONE_DTMF_B,                           /**< Predefined DTMF B (B) */
1456         MM_SOUND_TONE_DTMF_C,                           /**< Predefined DTMF C (C) */
1457         MM_SOUND_TONE_DTMF_D,                           /**< Predefined DTMF D (D) */
1458
1459         /**< Pre-defined TONE */
1460         MM_SOUND_TONE_SUP_DIAL,                                 /**Call supervisory tone, Dial tone: CEPT: 425Hz, continuous */
1461         MM_SOUND_TONE_ANSI_DIAL,                                /**Call supervisory tone, Dial tone: ANSI (IS-95): 350Hz+440Hz, continuous */
1462         MM_SOUND_TONE_JAPAN_DIAL,                               /**Call supervisory tone, Dial tone: JAPAN: 400Hz, continuous*/
1463         MM_SOUND_TONE_SUP_BUSY,                         /**Call supervisory tone, Busy: CEPT: 425Hz, 500ms ON, 500ms OFF... */
1464         MM_SOUND_TONE_ANSI_BUSY,                                /**Call supervisory tone, Busy: ANSI (IS-95): 480Hz+620Hz, 500ms ON, 500ms OFF... */
1465         MM_SOUND_TONE_JAPAN_BUSY,                               /**Call supervisory tone, Busy: JAPAN: 400Hz, 500ms ON, 500ms OFF...*/
1466         MM_SOUND_TONE_SUP_CONGESTION,           /**Call supervisory tone, Congestion: CEPT, JAPAN: 425Hz, 200ms ON, 200ms OFF */
1467         MM_SOUND_TONE_ANSI_CONGESTION,          /**Call supervisory tone, Congestion: ANSI (IS-95): 480Hz+620Hz, 250ms ON, 250ms OFF... */
1468         MM_SOUND_TONE_SUP_RADIO_ACK,                    /**Call supervisory tone, Radio path acknowlegment : CEPT, ANSI: 425Hz, 200ms ON  */
1469         MM_SOUND_TONE_JAPAN_RADIO_ACK,          /**Call supervisory tone, Radio path acknowlegment : JAPAN: 400Hz, 1s ON, 2s OFF...*/
1470         MM_SOUND_TONE_SUP_RADIO_NOTAVAIL,               /**Call supervisory tone, Radio path not available: 425Hz, 200ms ON, 200 OFF 3 bursts */
1471         MM_SOUND_TONE_SUP_ERROR,                                /**Call supervisory tone, Error/Special info: 950Hz+1400Hz+1800Hz, 330ms ON, 1s OFF... */
1472         MM_SOUND_TONE_SUP_CALL_WAITING,         /**Call supervisory tone, Call Waiting: CEPT, JAPAN: 425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF...  */
1473         MM_SOUND_TONE_ANSI_CALL_WAITING,                /**Call supervisory tone, Call Waiting: ANSI (IS-95): 440 Hz, 300 ms ON, 9.7 s OFF, (100 ms ON, 100 ms OFF, 100 ms ON, 9.7s OFF ...) */
1474         MM_SOUND_TONE_SUP_RINGTONE,                     /**Call supervisory tone, Ring Tone: CEPT, JAPAN: 425Hz, 1s ON, 4s OFF... */
1475         MM_SOUND_TONE_ANSI_RINGTONE,                    /**Call supervisory tone, Ring Tone: ANSI (IS-95): 440Hz + 480Hz, 2s ON, 4s OFF... */
1476         MM_SOUND_TONE_PROP_BEEP,                                /**General beep: 400Hz+1200Hz, 35ms ON */
1477         MM_SOUND_TONE_PROP_ACK,                                 /**Proprietary tone, positive acknowlegement: 1200Hz, 100ms ON, 100ms OFF 2 bursts */
1478         MM_SOUND_TONE_PROP_NACK,                                /**Proprietary tone, negative acknowlegement: 300Hz+400Hz+500Hz, 400ms ON */
1479         MM_SOUND_TONE_PROP_PROMPT,                      /**Proprietary tone, prompt tone: 400Hz+1200Hz, 200ms ON         */
1480         MM_SOUND_TONE_PROP_BEEP2,                               /**Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON */
1481         MM_SOUND_TONE_SUP_INTERCEPT,                                            /**Call supervisory tone (IS-95), intercept tone: alternating 440 Hz and 620 Hz tones, each on for 250 ms */
1482         MM_SOUND_TONE_SUP_INTERCEPT_ABBREV,                             /**Call supervisory tone (IS-95), abbreviated intercept: intercept tone limited to 4 seconds */
1483         MM_SOUND_TONE_SUP_CONGESTION_ABBREV,                            /**Call supervisory tone (IS-95), abbreviated congestion: congestion tone limited to 4 seconds */
1484         MM_SOUND_TONE_SUP_CONFIRM,                                              /**Call supervisory tone (IS-95), confirm tone: a 350 Hz tone added to a 440 Hz tone repeated 3 times in a 100 ms on, 100 ms off cycle */
1485         MM_SOUND_TONE_SUP_PIP,                                                  /**Call supervisory tone (IS-95), pip tone: four bursts of 480 Hz tone (0.1 s on, 0.1 s off). */
1486         MM_SOUND_TONE_CDMA_DIAL_TONE_LITE,                              /**425Hz continuous */
1487         MM_SOUND_TONE_CDMA_NETWORK_USA_RINGBACK,                /**CDMA USA Ringback: 440Hz+480Hz 2s ON, 4000 OFF ...*/
1488         MM_SOUND_TONE_CDMA_INTERCEPT,                                   /**CDMA Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON ...*/
1489         MM_SOUND_TONE_CDMA_ABBR_INTERCEPT,                              /**CDMA Abbr Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON */
1490         MM_SOUND_TONE_CDMA_REORDER,                                             /**CDMA Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF... */
1491         MM_SOUND_TONE_CDMA_ABBR_REORDER,                                /**CDMA Abbr Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF repeated for 8 times */
1492         MM_SOUND_TONE_CDMA_NETWORK_BUSY,                                /**CDMA Network Busy tone: 480Hz+620Hz 500ms ON, 500ms OFF continuous */
1493         MM_SOUND_TONE_CDMA_CONFIRM,                                             /**CDMA Confirm tone: 350Hz+440Hz 100ms ON, 100ms OFF repeated for 3 times */
1494         MM_SOUND_TONE_CDMA_ANSWER,                                              /**CDMA answer tone: silent tone - defintion Frequency 0, 0ms ON, 0ms OFF */
1495         MM_SOUND_TONE_CDMA_NETWORK_CALLWAITING,                         /**CDMA Network Callwaiting tone: 440Hz 300ms ON */
1496         MM_SOUND_TONE_CDMA_PIP,                                                         /**CDMA PIP tone: 480Hz 100ms ON, 100ms OFF repeated for 4 times */
1497         MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL,             /**ISDN Call Signal Normal tone: {2091Hz 32ms ON, 2556 64ms ON} 20 times, 2091 32ms ON, 2556 48ms ON, 4s OFF */
1498         MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP,         /**ISDN Call Signal Intergroup tone: {2091Hz 32ms ON, 2556 64ms ON} 8 times, 2091Hz 32ms ON, 400ms OFF, {2091Hz 32ms ON, 2556Hz 64ms ON} 8times, 2091Hz 32ms ON, 4s OFF.*/
1499         MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI,             /**ISDN Call Signal SP PRI tone:{2091Hz 32ms ON, 2556 64ms ON} 4 times 2091Hz 16ms ON, 200ms OFF, {2091Hz 32ms ON, 2556Hz 64ms ON} 4 times, 2091Hz 16ms ON, 200ms OFF */
1500         MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PAT3,               /**SDN Call sign PAT3 tone: silent tone */
1501         MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING,  /**ISDN Ping Ring tone: {2091Hz 32ms ON, 2556Hz 64ms ON} 5 times 2091Hz 20ms ON */
1502         MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PAT5,               /**ISDN Pat5 tone: silent tone */
1503         MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PAT6,               /**ISDN Pat6 tone: silent tone */
1504         MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PAT7,               /**ISDN Pat7 tone: silent tone */
1505         MM_SOUND_TONE_CDMA_HIGH_L,                                              /**TONE_CDMA_HIGH_L tone: {3700Hz 25ms, 4000Hz 25ms} 40 times 4000ms OFF, Repeat .... */
1506         MM_SOUND_TONE_CDMA_MED_L,                                               /**TONE_CDMA_MED_L tone: {2600Hz 25ms, 2900Hz 25ms} 40 times 4000ms OFF, Repeat .... */
1507         MM_SOUND_TONE_CDMA_LOW_L,                                               /**TONE_CDMA_LOW_L tone: {1300Hz 25ms, 1450Hz 25ms} 40 times, 4000ms OFF, Repeat .... */
1508         MM_SOUND_TONE_CDMA_HIGH_SS,                                             /**CDMA HIGH SS tone: {3700Hz 25ms, 4000Hz 25ms} repeat 16 times, 400ms OFF, repeat .... */
1509         MM_SOUND_TONE_CDMA_MED_SS,                                              /**CDMA MED SS tone: {2600Hz 25ms, 2900Hz 25ms} repeat 16 times, 400ms OFF, repeat .... */
1510         MM_SOUND_TONE_CDMA_LOW_SS,                                              /**CDMA LOW SS tone: {1300z 25ms, 1450Hz 25ms} repeat 16 times, 400ms OFF, repeat .... */
1511         MM_SOUND_TONE_CDMA_HIGH_SSL,                                            /**CDMA HIGH SSL tone: {3700Hz 25ms, 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} repeat 8 times, 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} repeat 16 times, 4000ms OFF, repeat ... */
1512         MM_SOUND_TONE_CDMA_MED_SSL,                                             /**CDMA MED SSL tone: {2600Hz 25ms, 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} repeat 8 times, 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} repeat 16 times, 4000ms OFF, repeat ... */
1513         MM_SOUND_TONE_CDMA_LOW_SSL,                                             /**CDMA LOW SSL tone: {1300Hz 25ms, 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} repeat 8 times, 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} repeat 16 times, 4000ms OFF, repeat ... */
1514         MM_SOUND_TONE_CDMA_HIGH_SS_2,                                   /**CDMA HIGH SS2 tone: {3700Hz 25ms, 4000Hz 25ms} 20 times, 1000ms OFF, {3700Hz 25ms, 4000Hz 25ms} 20 times, 3000ms OFF, repeat .... */
1515         MM_SOUND_TONE_CDMA_MED_SS_2,                                            /**CDMA MED SS2 tone: {2600Hz 25ms, 2900Hz 25ms} 20 times, 1000ms OFF, {2600Hz 25ms, 2900Hz 25ms} 20 times, 3000ms OFF, repeat .... */
1516         MM_SOUND_TONE_CDMA_LOW_SS_2,                                            /**CDMA LOW SS2 tone: {1300Hz 25ms, 1450Hz 25ms} 20 times, 1000ms OFF, {1300Hz 25ms, 1450Hz 25ms} 20 times, 3000ms OFF, repeat .... */
1517         MM_SOUND_TONE_CDMA_HIGH_SLS,                                            /**CDMA HIGH SLS tone: {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 20 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 10 times, 3000ms OFF, REPEAT */
1518         MM_SOUND_TONE_CDMA_MED_SLS,                                             /**CDMA MED SLS tone: {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 20 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 3000ms OFF, REPEAT */
1519         MM_SOUND_TONE_CDMA_LOW_SLS,                                             /**CDMA LOW SLS tone: {1300Hz 25ms, 1450Hz 25ms} 10 times, 500ms OFF, {1300Hz 25ms, 1450Hz 25ms} 20 times, 500ms OFF, {1300Hz 25ms, 1450Hz 25ms} 10 times, 3000ms OFF, REPEAT */
1520         MM_SOUND_TONE_CDMA_HIGH_S_X4,                                   /**CDMA HIGH S X4 tone: {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 10 times, 2500ms OFF, REPEAT.... */
1521         MM_SOUND_TONE_CDMA_MED_S_X4,                                            /**CDMA MED S X4 tone: {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 2500ms OFF, REPEAT.... */
1522         MM_SOUND_TONE_CDMA_LOW_S_X4,                                            /**CDMA LOW S X4 tone: {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 2500ms OFF, REPEAT....*/
1523         MM_SOUND_TONE_CDMA_HIGH_PBX_L,                                  /**CDMA HIGH PBX L: {3700Hz 25ms, 4000Hz 25ms}20 times, 2000ms OFF, REPEAT.... */
1524         MM_SOUND_TONE_CDMA_MED_PBX_L,                                   /**CDMA MED PBX L: {2600Hz 25ms, 2900Hz 25ms}20 times, 2000ms OFF, REPEAT.... */
1525         MM_SOUND_TONE_CDMA_LOW_PBX_L,                                   /**CDMA LOW PBX L: {1300Hz 25ms,1450Hz 25ms}20 times, 2000ms OFF, REPEAT.... */
1526         MM_SOUND_TONE_CDMA_HIGH_PBX_SS,                                         /**CDMA HIGH PBX SS tone: {3700Hz 25ms, 4000Hz 25ms} 8 times 200 ms OFF, {3700Hz 25ms 4000Hz 25ms}8 times, 2000ms OFF, REPEAT.... */
1527         MM_SOUND_TONE_CDMA_MED_PBX_SS,                                  /**CDMA MED PBX SS tone: {2600Hz 25ms, 2900Hz 25ms} 8 times 200 ms OFF, {2600Hz 25ms 2900Hz 25ms}8 times, 2000ms OFF, REPEAT.... */
1528         MM_SOUND_TONE_CDMA_LOW_PBX_SS,                                  /**CDMA LOW PBX SS tone: {1300Hz 25ms, 1450Hz 25ms} 8 times 200 ms OFF, {1300Hz 25ms 1450Hz 25ms}8 times, 2000ms OFF, REPEAT.... */
1529         MM_SOUND_TONE_CDMA_HIGH_PBX_SSL,                                        /**CDMA HIGH PBX SSL tone:{3700Hz 25ms, 4000Hz 25ms} 8 times 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 16 times, 1000ms OFF, REPEAT.... */
1530         MM_SOUND_TONE_CDMA_MED_PBX_SSL,                                         /**CDMA MED PBX SSL tone:{2600Hz 25ms, 2900Hz 25ms} 8 times 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 16 times, 1000ms OFF, REPEAT.... */
1531         MM_SOUND_TONE_CDMA_LOW_PBX_SSL,                                         /**CDMA LOW PBX SSL tone:{1300Hz 25ms, 1450Hz 25ms} 8 times 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 16 times, 1000ms OFF, REPEAT.... */
1532         MM_SOUND_TONE_CDMA_HIGH_PBX_SLS,                                        /**CDMA HIGH PBX SLS tone:{3700Hz 25ms, 4000Hz 25ms} 8 times 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 16 times, 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 8 times, 1000ms OFF, REPEAT....  */
1533         MM_SOUND_TONE_CDMA_MED_PBX_SLS,                                         /**CDMA MED PBX SLS tone:{2600Hz 25ms, 2900Hz 25ms} 8 times 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 16 times, 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 8 times, 1000ms OFF, REPEAT.... */
1534         MM_SOUND_TONE_CDMA_LOW_PBX_SLS,                                         /**CDMA LOW PBX SLS tone:{1300Hz 25ms, 1450Hz 25ms} 8 times 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 16 times, 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 8 times, 1000ms OFF, REPEAT.... */
1535         MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4,                               /**CDMA HIGH PBX X S4 tone: {3700Hz 25ms 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms 4000Hz 25ms} 8 times, 200ms OFF, {3700Hz 25ms 4000Hz 25ms} 8 times, 800ms OFF, REPEAT... */
1536         MM_SOUND_TONE_CDMA_MED_PBX_S_X4,                                        /**CDMA MED PBX X S4 tone: {2600Hz 25ms 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms 2900Hz 25ms} 8 times, 200ms OFF, {2600Hz 25ms 2900Hz 25ms} 8 times, 800ms OFF, REPEAT... */
1537         MM_SOUND_TONE_CDMA_LOW_PBX_S_X4,                                        /**CDMA LOW PBX X S4 tone: {1300Hz 25ms 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms 1450Hz 25ms} 8 times, 200ms OFF, {1300Hz 25ms 1450Hz 25ms} 8 times, 800ms OFF, REPEAT... */
1538         MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE,                  /**CDMA Alert Network Lite tone: 1109Hz 62ms ON, 784Hz 62ms ON, 740Hz 62ms ON 622Hz 62ms ON, 1109Hz 62ms ON */
1539         MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE,               /**CDMA Alert Auto Redial tone: {1245Hz 62ms ON, 659Hz 62ms ON} 3 times, 1245 62ms ON */
1540         MM_SOUND_TONE_CDMA_ONE_MIN_BEEP,                                        /**CDMA One Min Beep tone: 1150Hz+770Hz 400ms ON */
1541         MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE,              /**CDMA KEYPAD Volume key lite tone: 941Hz+1477Hz 120ms ON */
1542         MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE,                   /**CDMA PRESSHOLDKEY LITE tone: 587Hz 375ms ON, 1175Hz 125ms ON */
1543         MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE,                           /**CDMA ALERT INCALL LITE tone: 587Hz 62ms, 784 62ms, 831Hz 62ms, 784Hz 62ms, 1109 62ms, 784Hz 62ms, 831Hz 62ms, 784Hz 62ms*/
1544         MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK,                  /**CDMA EMERGENCY RINGBACK tone: {941Hz 125ms ON, 10ms OFF} 3times 4990ms OFF, REPEAT... */
1545         MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD,                    /**CDMA ALERT CALL GUARD tone: {1319Hz 125ms ON, 125ms OFF} 3 times */
1546         MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE,                             /**CDMA SOFT ERROR LITE tone: 1047Hz 125ms ON, 370Hz 125ms */
1547         MM_SOUND_TONE_CDMA_CALLDROP_LITE,                               /**CDMA CALLDROP LITE tone: 1480Hz 125ms, 1397Hz 125ms, 784Hz 125ms */
1548         MM_SOUND_TONE_CDMA_NETWORK_BUSY_ONE_SHOT,               /**CDMA_NETWORK_BUSY_ONE_SHOT tone: 425Hz 500ms ON, 500ms OFF. */
1549         MM_SOUND_TONE_CDMA_ABBR_ALERT,                                  /**CDMA_ABBR_ALERT tone: 1150Hz+770Hz 400ms ON */
1550         MM_SOUND_TONE_CDMA_SIGNAL_OFF,                                  /**CDMA_SIGNAL_OFF - silent tone */
1551         MM_SOUND_TONE_NUM,
1552 }MMSoundTone_t;
1553
1554 typedef unsigned long sound_time_msec_t;                /**< millisecond unit */
1555
1556 /**
1557  * This function is to play tone sound.
1558  *
1559  * @param       num                             [in] predefined tone type (MMSoundTone_t)
1560  *                      volume config   [in] volume type & volume gain
1561  *                      volume                  [in] volume ratio (0.0 ~1.0)
1562  *                      duration                [in] millisecond (-1 for infinite)
1563  *                      handle                  [in] Handle of mm_sound_play_tone
1564  *
1565  * @return      This function returns MM_ERROR_NONE on success, or negative value
1566  *                      with error code.
1567  *
1568  * @remark      It doesn't provide stop
1569  * @see volume_type_t volume_gain_t MMSoundTone_t
1570  * @pre         None.
1571  * @post        TONE sound will be played.
1572  * @par Example
1573  * @code
1574 int ret = 0;
1575
1576 ret = mm_sound_play_tone(MM_SOUND_TONE_DTMF_9, VOLUME_TYPE_SYSTEM, 1.0, 1000, &handle); //play 1 second with volume ratio 1.0
1577 if(ret < 0)
1578 {
1579         printf("play tone failed\n");
1580 }
1581 else
1582 {
1583         printf("play tone success\n");
1584 }
1585  * @endcode
1586  */
1587 int mm_sound_play_tone (MMSoundTone_t num, int volume_config, const double volume, const int duration, int *handle);
1588
1589 /*
1590  * Enumerations of System audio route policy
1591  */
1592 typedef enum {
1593         SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT,                      /**< Play via a2dp headset if connected. or play via headset if connected. or play via speaker.
1594                                                                                                         And capture via 4pole headset-mic if connected. or capture via mic */
1595         SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP,          /**< Play via headset if connected. or play via speaker
1596                                                                                                          And capture via 4pole headset-mic if connected. or capture via mic */
1597         SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY,         /**< Play via speaker. and capture via mic  */
1598         SYSTEM_AUDIO_ROUTE_POLICY_MAX
1599 }system_audio_route_t;
1600
1601 typedef enum {
1602         SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_NONE,                        /**< Abnormal case */
1603         SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_HANDSET,             /**< Speaker or Headset or Earpiece */
1604         SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_BLUETOOTH,   /**< Bluetooth */
1605         SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_EARPHONE,    /**< Earphone */
1606         SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_MAX,
1607 }system_audio_route_device_t;
1608
1609 typedef enum {
1610         SYSTEM_AUDIO_CAPTURE_NONE,      /**< Capture device is not in use */
1611         SYSTEM_AUDIO_CAPTURE_ACTIVE,    /**< Capture device is in use */
1612         SYSTEM_AUDIO_CAPTURE_MAX,
1613 }system_audio_capture_status_t;
1614
1615
1616 /**
1617  * This function set system route policy.
1618  *
1619  * @param       route           [in] audio route type
1620  *
1621  * @return      This function returns MM_ERROR_NONE on success, or negative value
1622  *                      with error code.
1623  * @remark      If bluetooth has disconnected during SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP policy,
1624  *                      The audio route policy will be changed to SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT.
1625  * @see         mm_sound_route_get_system_policy system_audio_route_t mm_sound_route_is_a2dp_on
1626  * @pre         None.
1627  * @post        Audio routing policy will be changed with given type. And route change callback function will be called if registered.
1628  * @par Example
1629  * @code
1630 int g_stop = 0;
1631 void _stop_callback()
1632 {
1633         g_stop = 1;
1634 }
1635
1636 int play_file_via_speaker()
1637 {
1638         int ret = 0;
1639         system_audio_route_t route, original_route;
1640
1641         //get backup current policy
1642         ret = mm_sound_route_get_system_policy(&original_route);
1643         if(ret < 0)
1644         {
1645                 printf("Can not get system audio route policy\n");
1646         }
1647         else
1648         {
1649                 //set route policy to ignore a2dp
1650                 route = SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP;
1651                 ret = mm_sound_route_set_system_policy(route);
1652                 if(ret < 0)
1653                 {
1654                         printf("Ca not set route policy\n");
1655                 }
1656                 else
1657                 {
1658                         int handle;
1659                         //play wav file
1660                         ret = mm_sound_play_sound("/opt/media/Sound/alert.wav", VOLUME_TYPE_SYSTEM, NULL, NULL, &handle);
1661                         if(ret < 0)
1662                         {
1663                                 printf("Can not play wav file\n");
1664                         }
1665                         else
1666                         {
1667                                 while(g_stop == 0)
1668                                 {
1669                                         sleep(1);
1670                                 }
1671                                 //restore original policy
1672                                 mm_sound_route_set_system_policy(original_route);
1673                         }
1674                 }
1675         }
1676         return 0;
1677 }
1678  * @endcode
1679  */
1680 int mm_sound_route_set_system_policy (system_audio_route_t route);
1681
1682 /**
1683  * This function get sysytem route policy.
1684  *
1685  * @param       route           [out] audio route type
1686  *
1687  * @return      This function returns MM_ERROR_NONE on success, or negative value
1688  *                      with error code.
1689  * @remark      None.
1690  * @see         mm_sound_route_set_system_policy system_audio_route_t mm_sound_route_is_a2dp_on
1691  * @pre         None.
1692  * @post        None.
1693  * @par Example
1694  * @code
1695 int g_stop = 0;
1696 void _stop_callback()
1697 {
1698         g_stop = 1;
1699 }
1700
1701 int play_file_via_speaker()
1702 {
1703         int ret = 0;
1704         system_audio_route_t route, original_route;
1705
1706         //get backup current policy
1707         ret = mm_sound_route_get_system_policy(&original_route);
1708         if(ret < 0)
1709         {
1710                 printf("Can not get system audio route policy\n");
1711         }
1712         else
1713         {
1714                 //set route policy to ignore a2dp
1715                 route = SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP;
1716                 ret = mm_sound_route_set_system_policy(route);
1717                 if(ret < 0)
1718                 {
1719                         printf("Can not set route policy\n");
1720                 }
1721                 else
1722                 {
1723                         int handle;
1724                         //play wav file
1725                         ret = mm_sound_play_sound("/opt/media/Sound/alert.wav", VOLUME_TYPE_SYSTEM, NULL, NULL, &handle);
1726                         if(ret < 0)
1727                         {
1728                                 printf("Can not play wav file\n");
1729                         }
1730                         else
1731                         {
1732                                 while(g_stop == 0)
1733                                 {
1734                                         sleep(1);
1735                                 }
1736                                 //restore original policy
1737                                 mm_sound_route_set_system_policy(original_route);
1738                         }
1739                 }
1740         }
1741         return 0;
1742 }
1743  * @endcode
1744  */
1745 int mm_sound_route_get_system_policy (system_audio_route_t *route);
1746
1747
1748
1749 /**
1750  * This function get a2dp activation information.
1751  *
1752  * @param        connected                  [out] is Bluetooth A2DP connected (1:connected, 0:not connected)
1753  *              bt_name         [out] Bluetooth A2DP connected device name (allocated by internal when connected=1 otherwise set to null)
1754  *
1755  *
1756  * @return      This function returns MM_ERROR_NONE on success, or negative value
1757  *                      with error code.
1758  * @remark      This function allocation memory to given bt_name pointer internally.
1759  *          So application should free given memory pointer later after use.
1760  *          bt_name will be null if there's no a2dp device is connected (connected is 0)
1761  * @see         mm_sound_route_set_system_policy mm_sound_route_get_system_policy
1762  * @pre         None.
1763  * @post        memory buffer will be allocated and fill with bluetooth device name.
1764  * @par Example
1765  * @code
1766 int ret;
1767 int connected = 0;
1768 char* bt_name = NULL;
1769 ret = mm_sound_route_get_a2dp_status (&connected, &bt_name);
1770
1771 if (ret == MM_ERROR_NONE) {
1772         g_print ("### Is Bluetooth A2DP On Success : connected=[%d] name=[%s]\n", connected, bt_name);
1773         if (bt_name)
1774                 free (bt_name);
1775 } else {
1776         g_print ("### Is Bluetooth A2DP On Error : errno [%d]\n", ret);
1777
1778  * @endcode
1779  */
1780 int mm_sound_route_get_a2dp_status (bool* connected, char** bt_name);
1781
1782
1783 /**
1784  * This function get current playing device.
1785  *
1786  * @param       dev             [out] current playing device information
1787  *
1788  * @return      This function returns MM_ERROR_NONE on success, or negative value
1789  *                      with error code.
1790  * @remark      if there is no running instance in system,
1791  *                      output parameter dev can be SYSTEM_AUDIO_ROUTE_PLAYING_DEVICE_NONE.
1792  *
1793  * @see         system_audio_route_device_t
1794  * @pre         None.
1795  * @post        None.
1796  * @par Example
1797  * @code
1798 int ret = 0;
1799 system_audio_route_device_t dev;
1800
1801 ret = mm_sound_route_get_playing_device (&dev);
1802 if(ret == MM_ERROR_NONE)
1803 {
1804         switch(dev)
1805         {
1806         case SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_HANDSET:
1807                 printf("Handset is playing\n");
1808                 break;
1809         case SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_BLUETOOTH:
1810                 printf("Bluetooth is playing\n");
1811                 break;
1812         case SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_NONE:
1813         default:
1814                 printf("Unexptected\n");
1815                 break;
1816         }
1817 }
1818 else
1819 {
1820         printf ("Can not get current running device\n");
1821 }
1822
1823  * @endcode
1824  */
1825 int mm_sound_route_get_playing_device(system_audio_route_device_t *dev);
1826
1827
1828 /**
1829  * Audio route policy change callback function type.
1830  *
1831  * @param       user_data               [in]    Argument passed when callback has called
1832  * @param       policy                  [in]    changed policy type
1833  *
1834  * @return      No return value
1835  * @remark
1836  * @see         mm_sound_volume_add_callback mm_sound_volume_remove_callback
1837  */
1838 typedef void (*audio_route_policy_changed_callback_fn)(void* user_data, system_audio_route_t policy);
1839
1840 /**
1841  * This function set system audio policy changed callback function.
1842  *
1843  * @param       func            [in] callback function pointer
1844  * @param       user_data       [in] user data will be called with func
1845  *
1846  * @return      This function returns MM_ERROR_NONE on success, or negative value
1847  *                      with error code.
1848  * @remark      None.
1849  * @see         mm_sound_route_remove_change_callback mm_sound_route_set_system_policy mm_sound_route_get_system_policy system_audio_route_t
1850  * @pre         None.
1851  * @post        None.
1852  * @par Example
1853  * @code
1854 void audio_route_policy_changed_callback(void* data, system_audio_route_t policy)
1855 {
1856         int value = (int) data;
1857         system_audio_route_t lv_policy;
1858         char *str_route[SYSTEM_AUDIO_ROUTE_POLICY_MAX] = {
1859                         "DEFAULT","IGN_A2DP","HANDSET"
1860                 };
1861         printf("Audio Route Policy has changed to [%s]\n", str_route[policy]);
1862         printf("user data : %d\n", value);
1863         if(0 > mm_sound_route_get_system_policy(&lv_policy)) {
1864                 printf("Can not get policy...in callback function\n");
1865         }
1866         else {
1867                 printf("readed policy [%s]\n", str_route[lv_policy]);
1868         }
1869 }
1870 int make_callback()
1871 {
1872         int ret = 0;
1873         ret = mm_sound_route_add_change_callback(audio_route_policy_changed_callback, (void*)111);
1874         if(ret < 0)
1875         {
1876                 printf("Can not add callback\n");
1877         }
1878         return 0;
1879 }
1880  * @endcode
1881  */
1882 int mm_sound_route_add_change_callback(audio_route_policy_changed_callback_fn func, void* user_data);
1883
1884 /**
1885  * This function remove system audio policy changed callback function.
1886  *
1887  * @return      This function returns MM_ERROR_NONE on success, or negative value
1888  *                      with error code.
1889  * @remark      None.
1890  * @see         mm_sound_route_add_change_callback mm_sound_route_set_system_policy mm_sound_route_get_system_policy system_audio_route_t
1891  * @pre         Sound route change callback should be registered.
1892  * @post        Sound route change callback deregistered and does not be called anymore.
1893  * @par Example
1894  * @code
1895 void audio_route_policy_changed_callback(void* data, system_audio_route_t policy)
1896 {
1897         int value = (int) data;
1898         system_audio_route_t lv_policy;
1899         char *str_route[SYSTEM_AUDIO_ROUTE_POLICY_MAX] = {
1900                         "DEFAULT","IGN_A2DP","HANDSET"
1901                 };
1902         printf("Audio Route Policy has changed to [%s]\n", str_route[policy]);
1903         printf("user data : %d\n", value);
1904         if(0 > mm_sound_route_get_system_policy(&lv_policy)) {
1905                 printf("Can not get policy...in callback function\n");
1906         }
1907         else {
1908                 printf("readed policy [%s]\n", str_route[lv_policy]);
1909         }
1910 }
1911 int make_callback()
1912 {
1913         int ret = 0;
1914         ret = mm_sound_route_add_change_callback(audio_route_policy_changed_callback, (void*)111);
1915         if(ret < 0)
1916         {
1917                 printf("Can not add callback\n");
1918         }
1919         else
1920         {
1921                 ret = mm_sound_route_remove_change_callback();
1922                 if(ret < 0)
1923                 {
1924                         printf("Can not remove callback\n");
1925                 }
1926         }
1927         return 0;
1928 }
1929  * @endcode
1930  */
1931 int mm_sound_route_remove_change_callback(void);
1932
1933 /*
1934  * Enumerations of device & route
1935  */
1936
1937 typedef enum{
1938         MM_SOUND_DEVICE_IN_NONE                         = 0x00,
1939         MM_SOUND_DEVICE_IN_MIC                          = 0x01,         /**< Device builtin mic. */
1940         MM_SOUND_DEVICE_IN_WIRED_ACCESSORY      = 0x02,         /**< Wired input devices */
1941         MM_SOUND_DEVICE_IN_BT_SCO                       = 0x04,         /**< Bluetooth SCO device */
1942 } mm_sound_device_in;
1943
1944 typedef enum{
1945         MM_SOUND_DEVICE_OUT_NONE                        = 0x000,
1946         MM_SOUND_DEVICE_OUT_SPEAKER                     = 0x001<<8,     /**< Device builtin speaker */
1947         MM_SOUND_DEVICE_OUT_RECEIVER            = 0x002<<8,     /**< Device builtin receiver */
1948         MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY     = 0x004<<8,     /**< Wired output devices such as headphone, headset, and so on. */
1949         MM_SOUND_DEVICE_OUT_BT_SCO                      = 0x008<<8,     /**< Bluetooth SCO device */
1950         MM_SOUND_DEVICE_OUT_BT_A2DP                     = 0x010<<8,     /**< Bluetooth A2DP device */
1951         MM_SOUND_DEVICE_OUT_DOCK                        = 0x020<<8,     /**< DOCK device */
1952         MM_SOUND_DEVICE_OUT_HDMI                        = 0x040<<8,     /**< HDMI device */
1953         MM_SOUND_DEVICE_OUT_WFD                         = 0x080<<8,     /**< WFD device */
1954         MM_SOUND_DEVICE_OUT_USB_AUDIO           = 0x100<<8,     /**< USB Audio device */
1955 } mm_sound_device_out;
1956
1957 #define MM_SOUND_ROUTE_NUM 14
1958
1959 typedef enum{
1960         MM_SOUND_ROUTE_OUT_SPEAKER = MM_SOUND_DEVICE_OUT_SPEAKER, /**< Routing audio output to builtin device such as internal speaker. */
1961         MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY = MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,/**< Routing audio output to wired accessory such as headphone, headset, and so on. */
1962         MM_SOUND_ROUTE_OUT_BLUETOOTH = MM_SOUND_DEVICE_OUT_BT_A2DP, /**< Routing audio output to bluetooth A2DP. */
1963         MM_SOUND_ROUTE_OUT_DOCK = MM_SOUND_DEVICE_OUT_DOCK, /**< Routing audio output to DOCK */
1964         MM_SOUND_ROUTE_OUT_HDMI = MM_SOUND_DEVICE_OUT_HDMI, /**< Routing audio output to HDMI */
1965         MM_SOUND_ROUTE_OUT_WFD = MM_SOUND_DEVICE_OUT_WFD, /**< Routing audio output to WFD */
1966         MM_SOUND_ROUTE_OUT_USB_AUDIO = MM_SOUND_DEVICE_OUT_USB_AUDIO, /**< Routing audio output to USB Audio */
1967         MM_SOUND_ROUTE_IN_MIC = MM_SOUND_DEVICE_IN_MIC, /**< Routing audio input to device builtin mic. */
1968         MM_SOUND_ROUTE_IN_WIRED_ACCESSORY = MM_SOUND_DEVICE_IN_WIRED_ACCESSORY, /**< Routing audio input to wired accessory. */
1969         MM_SOUND_ROUTE_IN_MIC_OUT_RECEIVER = MM_SOUND_DEVICE_IN_MIC | MM_SOUND_DEVICE_OUT_RECEIVER, /**< Routing audio input to device builtin mic and routing audio output to builtin receiver*/
1970         MM_SOUND_ROUTE_IN_MIC_OUT_SPEAKER = MM_SOUND_DEVICE_IN_MIC | MM_SOUND_DEVICE_OUT_SPEAKER , /**< Routing audio input to device builtin mic and routing audio output to builtin speaker */
1971         MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE = MM_SOUND_DEVICE_IN_MIC | MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,/**< Routing audio input to device builtin mic and routing audio output to headphone */
1972         MM_SOUND_ROUTE_INOUT_HEADSET = MM_SOUND_DEVICE_IN_WIRED_ACCESSORY | MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,        /**< Routing audio input and output to headset*/
1973         MM_SOUND_ROUTE_INOUT_BLUETOOTH = MM_SOUND_DEVICE_IN_BT_SCO | MM_SOUND_DEVICE_OUT_BT_SCO /**< Routing audio input and output to bluetooth SCO */
1974 } mm_sound_route;
1975
1976 typedef int (*mm_sound_available_route_cb)(mm_sound_route route, void *user_data);
1977
1978 int mm_sound_is_route_available(mm_sound_route route, bool *is_available);
1979
1980 int mm_sound_foreach_available_route_cb(mm_sound_available_route_cb, void *user_data);
1981
1982 int mm_sound_set_active_route(mm_sound_route route);
1983
1984 /**
1985  * This function is to get active playback device and capture device.
1986  *
1987  * @param       playback_device                 [out]   playback device.
1988  * @param       capture_device                  [out]   capture device.
1989  *
1990  * @return      This function returns MM_ERROR_NONE on success, or negative value
1991  *                      with error code.
1992  * @remark      None.
1993  * @pre         None.
1994  * @post        None.
1995  * @see         mm_sound_set_active_route mm_sound_device_in mm_sound_device_out
1996  */
1997 int mm_sound_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
1998
1999 /**
2000  * Active device changed callback function type.
2001  *
2002  * @param       user_data               [in]    Argument passed when callback has called
2003  *
2004  * @return      No return value
2005  * @remark      None.
2006  * @see         mm_sound_add_active_device_changed_callback mm_sound_remove_active_device_changed_callback
2007  */
2008 typedef void (*mm_sound_active_device_changed_cb) (mm_sound_device_in device_in, mm_sound_device_out device_out, void *user_data);
2009
2010 /**
2011  * This function is to add active device callback.
2012  *
2013  * @param       func                    [in]    callback function pointer
2014  * @param       user_data               [in]    user data passing to callback function
2015  *
2016  * @return      This function returns MM_ERROR_NONE on success, or negative value
2017  *                      with error code.
2018  * @remark      None.
2019  * @see         mm_sound_remove_active_device_changed_callback mm_sound_active_device_changed_cb
2020  * @pre         None.
2021  * @post        None.
2022  * @par Example
2023  * @code
2024
2025 void __active_device_callback(void *user_data)
2026 {
2027         printf("Callback function\n");
2028 }
2029
2030 int active_device_control()
2031 {
2032         int ret = 0;
2033
2034         ret = mm_sound_add_active_device_changed_callback(__active_device_callback, NULL);
2035         if ( MM_ERROR_NONE != ret)
2036         {
2037                 printf("Can not add callback\n");
2038         }
2039         else
2040         {
2041                 printf("Add callback success\n");
2042         }
2043
2044         return ret;
2045 }
2046
2047  * @endcode
2048  */
2049 int mm_sound_add_active_device_changed_callback(mm_sound_active_device_changed_cb func, void *user_data);
2050
2051 /**
2052  * This function is to remove active device callback.
2053  *
2054  * @return      This function returns MM_ERROR_NONE on success, or negative value
2055  *                      with error code.
2056  * @remark      None.
2057  * @pre         Active device callback should be registered.
2058  * @post        Active device callback deregistered and does not be called anymore.
2059  * @see         mm_sound_add_active_device_changed_callback mm_sound_active_device_changed_cb
2060  * @par Example
2061  * @code
2062 void __active_device_callback(void *data)
2063 {
2064         printf("Callback function\n");
2065 }
2066
2067 int active_device_control()
2068 {
2069         int ret = 0;
2070
2071         mm_sound_add_active_device_changed_callback(__active_device_callback, NULL);
2072
2073         ret = mm_sound_remove_active_device_changed_callback();
2074         if ( MM_ERROR_NONE == ret)
2075         {
2076                 printf("Remove callback success\n");
2077         }
2078         else
2079         {
2080                 printf("Remove callback failed\n");
2081         }
2082
2083         return ret;
2084 }
2085
2086  * @endcode
2087  */
2088 int mm_sound_remove_active_device_changed_callback(void);
2089
2090 /**
2091  * Available route changed callback function type.
2092  *
2093  * @param       user_data               [in]    Argument passed when callback has called
2094  *
2095  * @return      No return value
2096  * @remark      None.
2097  * @see         mm_sound_add_active_device_changed_callback mm_sound_remove_active_device_changed_callback
2098  */
2099 typedef void (*mm_sound_available_route_changed_cb) (mm_sound_route route, bool available, void *user_data);
2100
2101 /**
2102  * This function is to add available device callback.
2103  *
2104  * @param       func                    [in]    callback function pointer
2105  * @param       user_data               [in]    user data passing to callback function
2106  *
2107  * @return      This function returns MM_ERROR_NONE on success, or negative value
2108  *                      with error code.
2109  * @remark      None.
2110  * @see         mm_sound_remove_available_route_changed_callback mm_sound_active_device_changed_cb
2111  * @pre         None.
2112  * @post        None.
2113  * @par Example
2114  * @code
2115
2116 void __available_device_callback(void *user_data)
2117 {
2118         printf("Callback function\n");
2119 }
2120
2121 int available_device_control()
2122 {
2123         int ret = 0;
2124
2125         ret = mm_sound_add_available_route_changed_callback(__available_device_callback, NULL);
2126         if ( MM_ERROR_NONE != ret)
2127         {
2128                 printf("Can not add callback\n");
2129         }
2130         else
2131         {
2132                 printf("Add callback success\n");
2133         }
2134
2135         return ret;
2136 }
2137
2138  * @endcode
2139  */
2140 int mm_sound_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void *user_data);
2141
2142 /**
2143  * This function is to remove available device callback.
2144  *
2145  * @return      This function returns MM_ERROR_NONE on success, or negative value
2146  *                      with error code.
2147  * @remark      None.
2148  * @pre         available device callback should be registered.
2149  * @post        available device callback deregistered and does not be called anymore.
2150  * @see         mm_sound_add_available_route_changed_callback mm_sound_active_device_changed_cb
2151  * @par Example
2152  * @code
2153 void __available_device_callback(void *data)
2154 {
2155         printf("Callback function\n");
2156 }
2157
2158 int available_device_control()
2159 {
2160         int ret = 0;
2161
2162         mm_sound_add_available_route_changed_callback(__available_device_callback, NULL);
2163
2164         ret = mm_sound_remove_available_route_changed_callback();
2165         if ( MM_ERROR_NONE == ret)
2166         {
2167                 printf("Remove callback success\n");
2168         }
2169         else
2170         {
2171                 printf("Remove callback failed\n");
2172         }
2173
2174         return ret;
2175 }
2176
2177  * @endcode
2178  */
2179 int mm_sound_remove_available_route_changed_callback(void);
2180 /**
2181         @}
2182  */
2183
2184 #ifdef __cplusplus
2185 }
2186 #endif
2187
2188 #endif  /* __MM_SOUND_H__ */
2189