summaryrefslogtreecommitdiff
path: root/src/recorder.c
blob: 174c2c36b22d56baec35c1eab826aaeb19c42c3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <camera_internal.h>
#include <recorder.h>
#include <sound_manager.h>
#include <sound_manager_internal.h>
#include <storage.h>
#include <storage-internal.h>
#include <muse_recorder.h>
#include <muse_recorder_msg.h>
#include <muse_core_ipc.h>
#include <muse_core_module.h>
#include <recorder_private.h>
#include <glib.h>
#include <gio/gio.h>
#include <dlog.h>
#include <tzplatform_config.h>

#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "TIZEN_N_RECORDER"

/* for device changed callback */
static GMutex g_rec_dev_state_changed_cb_lock;
static GList *g_rec_dev_state_changed_cb_list;
static int g_rec_dev_state_changed_cb_id;
static GDBusConnection *g_rec_dev_state_changed_cb_conn;
static guint g_rec_dev_state_changed_cb_subscribe_id;



static void __recorder_update_api_waiting(recorder_cb_info_s *cb_info, int api, int value)
{
	if (!cb_info ||
		api < 0 || api >= MUSE_RECORDER_API_MAX) {
		LOGE("invalid param %p %d", cb_info, api);
		return;
	}

	g_mutex_lock(&(cb_info->api_mutex[api]));
	cb_info->api_waiting[api] += value;
	g_mutex_unlock(&(cb_info->api_mutex[api]));

	/*LOGD("api %d, value %d, waiting %d",
		api, value, cb_info->api_waiting[api]);*/

	return;
}


static void __recorder_device_state_changed_cb(GDBusConnection *connection,
	const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
	const gchar *signal_name, GVariant *param, gpointer user_data)
{
	int value = 0;
	recorder_type_e type = RECORDER_TYPE_AUDIO;
	recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
	GList *tmp_list = NULL;
	recorder_cb_info *info = NULL;

	g_mutex_lock(&g_rec_dev_state_changed_cb_lock);

	if (!g_rec_dev_state_changed_cb_list || !param) {
		LOGW("no callback or NULL param %p", param);
		goto _DONE;
	}

	/* get device type and state */
	g_variant_get(param, "(i)", &value);

	type = value >> 16;
	state = 0x0000ffff & value;

	LOGD("type %d, state %d", type, state);

	tmp_list = g_rec_dev_state_changed_cb_list;

	do {
		info = (recorder_cb_info *)tmp_list->data;

		if (info) {
			if (info->callback) {
				LOGD("start id[%d] callback", info->id);
				((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
				LOGD("returned id[%d] callback", info->id);
			} else {
				LOGW("NULL callback for id %d", info->id);
			}
		}

		tmp_list = tmp_list->next;
	} while (tmp_list);

_DONE:
	g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);

	return;
}


static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
{
	tbm_bo tmp_bo = NULL;
	tbm_bo_handle tmp_bo_handle = {NULL, };

	if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
		LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
		     bufmgr, bo, bo_handle, tbm_key);
		return false;
	}

	tmp_bo = tbm_bo_import(bufmgr, tbm_key);
	if (tmp_bo == NULL) {
		LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
		return false;
	}

	tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
	if (tmp_bo_handle.ptr == NULL) {
		LOGE("bo map failed %p", tmp_bo);
		tbm_bo_unref(tmp_bo);
		tmp_bo = NULL;
		return false;
	}

	/* set bo and bo_handle */
	*bo = tmp_bo;
	*bo_handle = tmp_bo_handle;

	return true;
}

static void _recorder_release_imported_bo(tbm_bo *bo)
{
	if (bo == NULL || *bo == NULL) {
		LOGW("NULL bo");
		return;
	}

	tbm_bo_unmap(*bo);
	tbm_bo_unref(*bo);
	*bo = NULL;

	return;
}

static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
{
	if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
		LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
		return;
	}

	/*LOGD("get recorder msg %s, event %d", recv_msg, event);*/

	if (cb_info->user_cb[event] == NULL) {
		LOGW("user callback for event %d is not set", event);
		return;
	}

	switch (event) {
	case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
		{
			int previous = 0;
			int current = 0;
			int by_policy = 0;

			muse_recorder_msg_get(previous, recv_msg);
			muse_recorder_msg_get(current, recv_msg);
			muse_recorder_msg_get(by_policy, recv_msg);

			((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
				(recorder_state_e)current,
				(bool)by_policy,
				cb_info->user_data[event]);
			break;
		}
	case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
		{
			int type = 0;

			muse_recorder_msg_get(type, recv_msg);

			((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
				cb_info->user_data[event]);
			break;
		}
	case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
		{
			int64_t cb_elapsed_time = 0;
			int64_t cb_file_size = 0;

			muse_recorder_msg_get(cb_elapsed_time, recv_msg);
			muse_recorder_msg_get(cb_file_size, recv_msg);

			((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
				(unsigned long long)cb_file_size,
				cb_info->user_data[event]);
			break;
		}
	case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
		{
			int policy = 0;
			int previous = 0;
			int current = 0;

			muse_recorder_msg_get(policy, recv_msg);
			muse_recorder_msg_get(previous, recv_msg);
			muse_recorder_msg_get(current, recv_msg);

			if (policy == RECORDER_POLICY_SOUND)
				LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
			else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
				LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
			else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
				LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");

			((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
				(recorder_state_e)previous,
				(recorder_state_e)current,
				cb_info->user_data[event]);
			break;
		}
	case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
		{
			int tbm_key = 0;
			int size = 0;
			int format = 0;
			int channel = 0;
			int timestamp = 0;
			tbm_bo bo = NULL;
			tbm_bo_handle bo_handle = {.ptr = NULL};
			char *send_msg = NULL;

			muse_recorder_msg_get(tbm_key, recv_msg);
			if (tbm_key == 0) {
				LOGE("invalid key");
				break;
			}

			if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
				LOGE("tbm key %d import failed", tbm_key);
				break;
			}

			muse_recorder_msg_get(size, recv_msg);
			muse_recorder_msg_get(format, recv_msg);
			muse_recorder_msg_get(channel, recv_msg);
			muse_recorder_msg_get(timestamp, recv_msg);

			((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
				size,
				(audio_sample_type_e)format,
				channel,
				(unsigned int)timestamp,
				cb_info->user_data[event]);

			/* release imported bo */
			_recorder_release_imported_bo(&bo);

			/* return buffer */
			send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
				MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);

			if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
				LOGE("sending message failed");

			muse_core_msg_json_factory_free(send_msg);
			break;
		}
	case MUSE_RECORDER_EVENT_TYPE_ERROR:
		{
			int error = 0;
			int current_state = 0;

			muse_recorder_msg_get(error, recv_msg);
			muse_recorder_msg_get(current_state, recv_msg);

			if (error == RECORDER_ERROR_SOUND_POLICY)
				LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
			else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
				LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
			else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
				LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");

			((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
				(recorder_state_e)current_state,
				cb_info->user_data[event]);
			break;
		}
	case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
		{
			int codec = 0;

			muse_recorder_msg_get(codec, recv_msg);

			if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
				cb_info->user_cb[event] = NULL;
				cb_info->user_data[event] = NULL;
				/*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
			}
			break;
		}
	case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
		{
			int format = 0;

			muse_recorder_msg_get(format, recv_msg);

			if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
				cb_info->user_cb[event] = NULL;
				cb_info->user_data[event] = NULL;
				/*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
			}
			break;
		}
	case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
		{
			int codec = 0;

			muse_recorder_msg_get(codec, recv_msg);

			if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
				cb_info->user_cb[event] = NULL;
				cb_info->user_data[event] = NULL;
				/*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
			}
			break;
		}
	default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
		{
			int width = 0;
			int height = 0;

			muse_recorder_msg_get(width, recv_msg);
			muse_recorder_msg_get(height, recv_msg);

			if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
				cb_info->user_cb[event] = NULL;
				cb_info->user_data[event] = NULL;
				/*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
			}
			break;
		}
	}

	return;
}


static bool _recorder_idle_event_callback(void *data)
{
	recorder_cb_info_s *cb_info = NULL;
	recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;

	if (rec_idle_event == NULL) {
		LOGE("rec_idle_event is NULL");
		return false;
	}

	/* lock event */
	g_mutex_lock(&rec_idle_event->event_mutex);

	cb_info = rec_idle_event->cb_info;
	if (cb_info == NULL) {
		LOGW("recorder cb_info is NULL. event %d", rec_idle_event->event);
		goto IDLE_EVENT_CALLBACK_DONE;
	}

	/* remove event from list */
	g_mutex_lock(&cb_info->idle_event_mutex);
	if (cb_info->idle_event_list)
		cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);

	/*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
	g_mutex_unlock(&cb_info->idle_event_mutex);

	/* user callback */
	_recorder_client_user_callback(rec_idle_event->cb_info, rec_idle_event->recv_msg, rec_idle_event->event);

	/* send signal for waiting thread */
	g_cond_signal(&cb_info->idle_event_cond);

IDLE_EVENT_CALLBACK_DONE:
	/* unlock and release event */
	g_mutex_unlock(&rec_idle_event->event_mutex);
	g_mutex_clear(&rec_idle_event->event_mutex);

	g_free(rec_idle_event);
	rec_idle_event = NULL;

	return false;
}


static void _recorder_remove_idle_event_all(recorder_cb_info_s *cb_info)
{
	recorder_idle_event_s *rec_idle_event = NULL;
	gboolean ret = true;
	GList *list = NULL;
	gint64 end_time = 0;

	if (cb_info == NULL) {
		LOGE("cb_info is NULL");
		return;
	}

	g_mutex_lock(&cb_info->idle_event_mutex);

	if (cb_info->idle_event_list == NULL) {
		LOGD("No event");
	} else {
		list = cb_info->idle_event_list;

		while (list) {
			rec_idle_event = list->data;
			list = g_list_next(list);

			if (!rec_idle_event) {
				LOGW("The event is NULL");
				continue;
			}

			if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
				LOGW("lock failed");

				end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;

				if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
					LOGW("signal received");
				else
					LOGW("timeout");

				continue;
			}

			ret = g_idle_remove_by_data(rec_idle_event);

			LOGD("remove event %p, ret %d", rec_idle_event, ret);

			if (!ret) {
				rec_idle_event->cb_info = NULL;
				LOGW("idle cb for event %p will be called later", rec_idle_event);
			}

			cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);

			g_mutex_unlock(&rec_idle_event->event_mutex);

			if (ret) {
				g_mutex_clear(&rec_idle_event->event_mutex);

				g_free(rec_idle_event);
				rec_idle_event = NULL;

				LOGD("remove event done");
			}
		}

		g_list_free(cb_info->idle_event_list);
		cb_info->idle_event_list = NULL;
	}

	g_mutex_unlock(&cb_info->idle_event_mutex);

	return;
}


static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
{
	recorder_message_s *rec_msg = NULL;

	if (!cb_info || !msg) {
		LOGE("NULL pointer %p %p", cb_info, msg);
		return;
	}

	rec_msg = g_new0(recorder_message_s, 1);
	if (!rec_msg) {
		LOGE("failed to alloc rec_msg for [%s]", msg);
		return;
	}

	rec_msg->api = api;
	rec_msg->event = event;
	rec_msg->event_class = event_class;

	strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);

	/*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/

	if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM) {
		g_mutex_lock(&cb_info->audio_stream_cb_info.mutex);
		g_queue_push_tail(cb_info->audio_stream_cb_info.queue, (gpointer)rec_msg);
		g_cond_signal(&cb_info->audio_stream_cb_info.cond);
		g_mutex_unlock(&cb_info->audio_stream_cb_info.mutex);
	} else {
		g_mutex_lock(&cb_info->msg_handler_info.mutex);
		g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)rec_msg);
		g_cond_signal(&cb_info->msg_handler_info.cond);
		g_mutex_unlock(&cb_info->msg_handler_info.mutex);
	}

	rec_msg = NULL;

	return;
}


static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
{
	if (!cb_info || !msg) {
		LOGE("NULL pointer %p %p", cb_info, msg);
		return;
	}

	switch (api) {
	case MUSE_RECORDER_API_GET_STATE:
		{
			int get_state = 0;
			muse_recorder_msg_get(get_state, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
		}
		break;
	case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
		{
			int get_width = 0;
			int get_height = 0;
			muse_recorder_msg_get(get_width, msg);
			muse_recorder_msg_get(get_height, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
			cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
		}
		break;
	case MUSE_RECORDER_API_GET_FILE_FORMAT:
		{
			int get_format = 0;
			muse_recorder_msg_get(get_format, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
		}
		break;
	case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
		{
			int get_codec = 0;
			muse_recorder_msg_get(get_codec, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
		}
		break;
	case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
		{
			int get_codec = 0;
			muse_recorder_msg_get(get_codec, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
		}
		break;
	case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
		{
			int get_kbyte = 0;
			muse_recorder_msg_get(get_kbyte, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
		}
		break;
	case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
		{
			int get_second = 0;
			muse_recorder_msg_get(get_second, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
		}
		break;
	case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
		{
			int get_device = 0;
			muse_recorder_msg_get(get_device, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
		}
		break;
	case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
		{
			int get_samplerate = 0;
			muse_recorder_msg_get(get_samplerate, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
		}
		break;
	case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
		{
			int get_bitrate = 0;
			muse_recorder_msg_get(get_bitrate, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
		}
		break;
	case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
		{
			int get_bitrate = 0;
			muse_recorder_msg_get(get_bitrate, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
		}
		break;
	case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
		{
			double get_rate = 0;
			muse_recorder_msg_get_double(get_rate, msg);
			cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
		}
		break;
	case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
		{
			int get_channel_count = 0;
			muse_recorder_msg_get(get_channel_count, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
		}
		break;
	case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
		{
			int get_orientation = 0;
			muse_recorder_msg_get(get_orientation, msg);
			cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
		}
		break;
	case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
		{
			double get_level = 0.0;
			muse_recorder_msg_get_double(get_level, msg);
			cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
		}
		break;
	case MUSE_RECORDER_API_GET_FILENAME:
		{
			char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
			muse_recorder_msg_get_string(get_filename, msg);
			if (cb_info->get_filename) {
				free(cb_info->get_filename);
				cb_info->get_filename = NULL;
			}
			cb_info->get_filename = strdup(get_filename);
		}
		break;
	default:
		break;
	}

	return;
}


static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg)
{
	int ret = RECORDER_ERROR_NONE;
	int api = -1;
	int api_class = -1;
	int event = -1;
	int event_class = -1;

	if (!cb_info || !msg) {
		LOGE("invalid ptr %p %p", cb_info, msg);
		return;
	}

	/*LOGD("msg [%s]", msg);*/

	if (!muse_recorder_msg_get(api, msg)) {
		LOGE("failed to get recorder api");
		return;
	}

	if (api == MUSE_RECORDER_CB_EVENT) {
		if (!muse_recorder_msg_get(event, msg) ||
			!muse_recorder_msg_get(event_class, msg)) {
			LOGE("failed to get event or event_class [%s]", msg);
			return;
		}
	} else {
		if (!muse_recorder_msg_get(api_class, msg)) {
			LOGE("failed to get api_class [%s]", msg);
			return;
		}
	}

	if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
		if (api >= MUSE_RECORDER_API_MAX) {
			LOGE("invalid api %d", api);
			return;
		}

		if (!muse_recorder_msg_get(ret, msg)) {
			LOGE("failed to get recorder ret");
			return;
		}

		g_mutex_lock(&cb_info->api_mutex[api]);

		if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
			g_atomic_int_set(&cb_info->msg_recv_running, 0);
			LOGD("get device state done. close client cb handler");
		} else {
			switch (api) {
			case MUSE_RECORDER_API_CREATE:
				if (ret != RECORDER_ERROR_NONE) {
					g_atomic_int_set(&cb_info->msg_recv_running, 0);
					LOGE("create error 0x%x. closing..", ret);
				}
				break;
			case MUSE_RECORDER_API_DESTROY:
				if (ret == RECORDER_ERROR_NONE) {
					g_atomic_int_set(&cb_info->msg_recv_running, 0);
					LOGD("destroy done. closing..");
				}
				break;
			default:
				__recorder_get_api_operation(api, cb_info, msg);
				break;
			}
		}

		if (cb_info->api_waiting[api] > 0) {
			cb_info->api_ret[api] = ret;
			cb_info->api_activating[api] = 1;

			g_cond_signal(&cb_info->api_cond[api]);
		} else {
			LOGE("no waiting for api [%d]", api);
		}

		g_mutex_unlock(&cb_info->api_mutex[api]);
	} else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
		__recorder_add_msg_to_queue(cb_info, api, event, event_class, msg);
	} else {
		LOGW("unknown recorder api %d and api_class %d", api, api_class);
	}

	return;
}


static void *_recorder_msg_handler_func(gpointer data)
{
	int api = 0;
	int type = 0;
	recorder_message_s *rec_msg = NULL;
	recorder_idle_event_s *rec_idle_event = NULL;
	recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
	recorder_cb_info_s *cb_info = NULL;

	if (!handler_info || !handler_info->cb_info) {
		LOGE("NULL handler %p", handler_info);
		return NULL;
	}

	cb_info = (recorder_cb_info_s *)handler_info->cb_info;
	type = handler_info->type;

	LOGD("t:%d start", type);

	g_mutex_lock(&handler_info->mutex);

	while (g_atomic_int_get(&handler_info->running)) {
		if (g_queue_is_empty(handler_info->queue)) {
			/*LOGD("signal wait...");*/
			g_cond_wait(&handler_info->cond, &handler_info->mutex);
			/*LOGD("signal received");*/

			if (g_atomic_int_get(&handler_info->running) == 0) {
				LOGD("stop event thread");
				break;
			}
		}

		rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
		g_mutex_unlock(&handler_info->mutex);
		if (rec_msg == NULL) {
			LOGE("NULL message");
			g_mutex_lock(&handler_info->mutex);
			continue;
		}

		api = rec_msg->api;

		if (api < MUSE_RECORDER_API_MAX) {
			int ret = 0;

			g_mutex_lock(&cb_info->api_mutex[api]);

			if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
				if (cb_info->api_waiting[api] > 0) {
					cb_info->api_ret[api] = ret;
					cb_info->api_activating[api] = 1;

					/*LOGD("recorder api %d - return 0x%x", ret);*/

					g_cond_signal(&cb_info->api_cond[api]);
				} else {
					LOGE("no waiting for api [%d]", api);
				}
			} else {
				LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
			}

			g_mutex_unlock(&cb_info->api_mutex[api]);
		} else if (api == MUSE_RECORDER_CB_EVENT) {
			switch (rec_msg->event_class) {
			case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
				_recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
				break;
			case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
				rec_idle_event = g_new0(recorder_idle_event_s, 1);
				if (rec_idle_event == NULL) {
					LOGE("event alloc failed");
					break;
				}

				rec_idle_event->event = rec_msg->event;
				rec_idle_event->cb_info = cb_info;
				g_mutex_init(&rec_idle_event->event_mutex);
				strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);

				/*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/

				g_mutex_lock(&cb_info->idle_event_mutex);
				cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
				g_mutex_unlock(&cb_info->idle_event_mutex);

				g_idle_add_full(G_PRIORITY_DEFAULT,
					(GSourceFunc)_recorder_idle_event_callback,
					(gpointer)rec_idle_event,
					NULL);
				break;
			default:
				LOGE("unknown event class %d", rec_msg->event_class);
				break;
			}
		} else {
			LOGE("unknown api[%d] message", api);
		}

		g_free(rec_msg);
		rec_msg = NULL;

		g_mutex_lock(&handler_info->mutex);
	}

	/* remove remained event */
	while (!g_queue_is_empty(handler_info->queue)) {
		rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
		if (rec_msg) {
			LOGD("remove message %p", rec_msg);
			free(rec_msg);
			rec_msg = NULL;
		} else {
			LOGW("NULL message");
		}
	}

	g_mutex_unlock(&handler_info->mutex);

	LOGD("return");

	return NULL;
}


static void *_recorder_msg_recv_func(gpointer data)
{
	int recv_length = 0;
	int single_length = 0;
	int remained_length = 0;
	char *recv_msg = NULL;
	char *single_msg = NULL;
	char *remained_msg = NULL;
	int num_msg = 0;
	int cur_pos = 0;
	int prev_pos = 0;
	recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;

	if (cb_info == NULL) {
		LOGE("cb_info NULL");
		return NULL;
	}

	LOGD("start");

	single_msg = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
	if (single_msg == NULL) {
		LOGE("single_msg malloc failed");
		goto CB_HANDLER_EXIT;
	}

	recv_msg = cb_info->recv_msg;

	while (g_atomic_int_get(&cb_info->msg_recv_running)) {
		recv_length = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
		if (recv_length <= 0) {
			cb_info->is_server_connected = FALSE;
			LOGE("receive msg failed - server disconnected");
			break;
		}

		recv_msg[recv_length] = '\0';

		cur_pos = 0;
		prev_pos = 0;
		num_msg = 0;

		/*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/

		/* Need to split the combined entering msgs */
		for (cur_pos = 0; cur_pos < recv_length; cur_pos++) {
			if (recv_msg[cur_pos] == '}') {
				single_length = cur_pos - prev_pos + 1;

				if (single_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
					/* check remained msg */
					if (remained_length > 0) {
						if (remained_msg) {
							strncpy(single_msg, remained_msg, remained_length);
							strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
							single_msg[remained_length + single_length] = '\0';

							free(remained_msg);
							remained_msg = NULL;
						} else {
							strncpy(single_msg, recv_msg + prev_pos, single_length);
							single_msg[single_length] = '\0';
							LOGE("lost msg [%s], skip...", single_msg);
						}

						remained_length = 0;
					} else {
						strncpy(single_msg, recv_msg + prev_pos, single_length);
						single_msg[single_length] = '\0';
					}

					if (single_msg[0] == '{') {
						num_msg++;
						/*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
						__recorder_process_msg(cb_info, single_msg);
					} else {
						LOGE("invalid msg [%s]", single_msg);
					}
				} else {
					LOGE("too long message [len %d] skip...", single_length);
				}

				prev_pos = cur_pos + 1;
			}
		}

		/* check incompleted message */
		if (recv_msg[recv_length - 1] != '}') {
			remained_length = recv_length - prev_pos;

			LOGW("incompleted message [len %d]", remained_length);

			remained_msg = (char *)malloc(remained_length + 1);
			if (remained_msg) {
				strncpy(remained_msg, recv_msg + prev_pos, remained_length);
				remained_msg[remained_length] = '\0';
			} else {
				LOGE("failed to alloc for remained msg");
			}
		} else {
			remained_length = 0;
		}
	}

	LOGD("client cb exit - server connected %d", cb_info->is_server_connected);

	if (!cb_info->is_server_connected) {
		/* send error msg for server disconnection */
		char *error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
			MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
			MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
			NULL);

		if (!error_msg) {
			LOGE("error_msg failed");
			goto CB_HANDLER_EXIT;
		}

		LOGE("add error msg for service disconnection done");

		__recorder_add_msg_to_queue(cb_info,
			MUSE_RECORDER_CB_EVENT,
			MUSE_RECORDER_EVENT_TYPE_ERROR,
			MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
			error_msg);

		muse_core_msg_json_factory_free(error_msg);
		error_msg = NULL;

		LOGE("add error msg for service disconnection done");
	}

CB_HANDLER_EXIT:
	if (single_msg) {
		free(single_msg);
		single_msg = NULL;
	}

	if (remained_msg) {
		free(remained_msg);
		remained_msg = NULL;
	}

	return NULL;
}


static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
	int type, const char *thread_name, recorder_cb_info_s *cb_info)
{
	if (!handler_info || !thread_name || !cb_info) {
		LOGE("t:%d NULL %p %p %p",
			type, handler_info, thread_name, cb_info);
		return false;
	}

	LOGD("t:%d", type);

	handler_info->type = type;
	handler_info->queue = g_queue_new();
	if (handler_info->queue == NULL) {
		LOGE("t:%d queue failed", type);
		return false;
	}

	g_mutex_init(&handler_info->mutex);
	g_cond_init(&handler_info->cond);

	handler_info->cb_info = (void *)cb_info;
	g_atomic_int_set(&handler_info->running, 1);

	handler_info->thread = g_thread_try_new(thread_name,
		_recorder_msg_handler_func, (gpointer)handler_info, NULL);
	if (handler_info->thread == NULL) {
		LOGE("t:%d thread failed", type);

		g_mutex_clear(&handler_info->mutex);
		g_cond_clear(&handler_info->cond);
		g_queue_free(handler_info->queue);
		handler_info->queue = NULL;

		return false;
	}

	LOGD("t:%d done", type);

	return true;
}


static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
{
	int type = 0;

	if (!handler_info) {
		LOGE("NULL handler");
		return;
	}

	if (!handler_info->thread) {
		LOGW("thread is not created");
		return;
	}

	type = handler_info->type;

	LOGD("t:%d thread %p", type, handler_info->thread);

	g_mutex_lock(&handler_info->mutex);
	g_atomic_int_set(&handler_info->running, 0);
	g_cond_signal(&handler_info->cond);
	g_mutex_unlock(&handler_info->mutex);

	g_thread_join(handler_info->thread);
	handler_info->thread = NULL;

	g_mutex_clear(&handler_info->mutex);
	g_cond_clear(&handler_info->cond);
	g_queue_free(handler_info->queue);
	handler_info->queue = NULL;

	LOGD("t:%d done", type);

	return;
}


static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
{
	recorder_cb_info_s *cb_info = NULL;
	gint i = 0;

	g_return_val_if_fail(sockfd > 0, NULL);

	cb_info = g_new0(recorder_cb_info_s, 1);
	if (cb_info == NULL) {
		LOGE("cb_info failed");
		goto ErrorExit;
	}

	cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;

	for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
		g_mutex_init(&cb_info->api_mutex[i]);
		g_cond_init(&cb_info->api_cond[i]);
	}

	g_mutex_init(&cb_info->idle_event_mutex);
	g_cond_init(&cb_info->idle_event_cond);

	/* message handler thread */
	if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
		_RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
		LOGE("msg_handler_info failed");
		goto ErrorExit;
	}

	/* message handler thread for audio stream callback */
	if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
		_RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
		LOGE("audio_stream_cb_info failed");
		goto ErrorExit;
	}

	cb_info->fd = sockfd;

	/* message receive thread */
	g_atomic_int_set(&cb_info->msg_recv_running, 1);
	cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
		_recorder_msg_recv_func, (gpointer)cb_info, NULL);
	if (cb_info->msg_recv_thread == NULL) {
		LOGE("message receive thread creation failed");
		goto ErrorExit;
	}

	cb_info->is_server_connected = TRUE;

	return cb_info;

ErrorExit:
	if (cb_info) {
		__destroy_msg_handler_thread(&cb_info->msg_handler_info);
		__destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);

		g_mutex_clear(&cb_info->idle_event_mutex);
		g_cond_clear(&cb_info->idle_event_cond);

		for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
			g_mutex_clear(&cb_info->api_mutex[i]);
			g_cond_clear(&cb_info->api_cond[i]);
		}

		g_free(cb_info);
		cb_info = NULL;
	}

	return NULL;
}

static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
{
	int ret = RECORDER_ERROR_NONE;
	gint64 end_time;

	/*LOGD("Enter api : %d", api);*/

	if (!cb_info->is_server_connected) {
		LOGE("server is disconnected");
		return RECORDER_ERROR_SERVICE_DISCONNECTED;
	}

	g_mutex_lock(&(cb_info->api_mutex[api]));

	if (cb_info->api_activating[api] == 0) {
		if (time_out == RECORDER_CB_NO_TIMEOUT) {
			LOGW("wait for api %d", api);
			g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
			ret = cb_info->api_ret[api];
			cb_info->api_activating[api] = 0;
			LOGW("api %d returned 0x%x", api, ret);
		} else {
			end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
			if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
				ret = cb_info->api_ret[api];
				cb_info->api_activating[api] = 0;
				/*LOGD("return value : 0x%x", ret);*/
			} else {
				ret = RECORDER_ERROR_INVALID_OPERATION;
				LOGE("api %d was TIMED OUT!", api);
			}
		}
	} else {
		ret = cb_info->api_ret[api];
		cb_info->api_activating[api] = 0;

		/*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
	}

	if (ret != RECORDER_ERROR_NONE) {
		LOGE("ERROR : api %d - ret 0x%x", api, ret);

		if (ret == RECORDER_ERROR_SOUND_POLICY)
			LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
		else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
			LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
		else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
			LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
	}

	g_mutex_unlock(&(cb_info->api_mutex[api]));

	return ret;
}


static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret)
{
	int send_ret = 0;
	char *msg = NULL;

	if (!cb_info || !ret) {
		LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	msg = muse_core_msg_json_factory_new(api, NULL);
	if (!msg) {
		LOGE("msg creation failed: api %d", api);
		return RECORDER_ERROR_OUT_OF_MEMORY;
	}

	/*LOGD("send msg %s", msg);*/

	if (cb_info->is_server_connected) {
		__recorder_update_api_waiting(cb_info, api, 1);

		send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
	}

	if (send_ret < 0) {
		LOGE("message send failed");
		*ret = RECORDER_ERROR_INVALID_OPERATION;
	} else {
		*ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
	}

	__recorder_update_api_waiting(cb_info, api, -1);

	muse_core_msg_json_factory_free(msg);

	return RECORDER_ERROR_NONE;
}


static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
{
	int send_ret = 0;
	char *msg = NULL;

	if (!cb_info || !ret || !param) {
		LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	/*LOGD("type %d, name %s", param->type, param->name);*/

	switch (param->type) {
	case MUSE_TYPE_INT:
		msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
		break;
	case MUSE_TYPE_DOUBLE:
		msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
		break;
	case MUSE_TYPE_STRING:
		msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
		break;
	default:
		LOGE("unknown type %d", param->type);
		break;
	}

	if (!msg) {
		LOGE("msg creation failed: api %d, type %d, param name %s",
			api, param->type, param->name);
		return RECORDER_ERROR_OUT_OF_MEMORY;
	}

	/*LOGD("send msg %s", msg);*/

	if (cb_info->is_server_connected) {
		__recorder_update_api_waiting(cb_info, api, 1);

		send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
	}

	if (send_ret < 0) {
		LOGE("message send failed");
		*ret = RECORDER_ERROR_INVALID_OPERATION;
	} else {
		*ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
	}

	__recorder_update_api_waiting(cb_info, api, -1);

	muse_core_msg_json_factory_free(msg);

	return RECORDER_ERROR_NONE;
}


static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
{
	gint i = 0;

	g_return_if_fail(cb_info != NULL);

	LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);

	g_thread_join(cb_info->msg_recv_thread);
	cb_info->msg_recv_thread = NULL;

	LOGD("msg_recv thread removed");

	__destroy_msg_handler_thread(&cb_info->msg_handler_info);
	__destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);

	g_mutex_clear(&cb_info->idle_event_mutex);
	g_cond_clear(&cb_info->idle_event_cond);

	for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
		g_mutex_clear(&cb_info->api_mutex[i]);
		g_cond_clear(&cb_info->api_cond[i]);
	}

	if (cb_info->fd > -1) {
		muse_core_connection_close(cb_info->fd);
		cb_info->fd = -1;
	}

	if (cb_info->bufmgr) {
		tbm_bufmgr_deinit(cb_info->bufmgr);
		cb_info->bufmgr = NULL;
	}
	if (cb_info->get_filename) {
		free(cb_info->get_filename);
		cb_info->get_filename = NULL;
	}

	g_free(cb_info);
	cb_info = NULL;

	return;
}


static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
{
	char **root_directory = (char **)user_data;

	if (root_directory == NULL) {
		LOGE("user data is NULL");
		return false;
	}

	LOGD("storage id %d, type %d, state %d, path %s",
		storage_id, type, state, path ? path : "NULL");

	if (type == STORAGE_TYPE_INTERNAL && path) {
		if (*root_directory) {
			free(*root_directory);
			*root_directory = NULL;
		}

		*root_directory = strdup(path);
		if (*root_directory) {
			LOGD("get root directory %s", *root_directory);
			return false;
		} else {
			LOGE("strdup %s failed", path);
		}
	}

	return true;
}

static int _recorder_client_get_root_directory(char **root_directory)
{
	int ret = STORAGE_ERROR_NONE;

	if (root_directory == NULL) {
		LOGE("user data is NULL");
		return false;
	}

	ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
	if (ret != STORAGE_ERROR_NONE) {
		LOGE("storage_foreach_device_supported failed 0x%x", ret);
		return false;
	}

	return true;
}

static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
{
	int ret = RECORDER_ERROR_NONE;
	int destroy_ret = RECORDER_ERROR_NONE;
	int sock_fd = -1;
	int send_ret = 0;
	char *send_msg = NULL;
	char *root_directory = NULL;
	intptr_t camera_handle = 0;
	intptr_t handle = 0;
	tbm_bufmgr bufmgr = NULL;
	recorder_cli_s *pc = NULL;
	recorder_msg_param param;

	LOGD("Enter - type %d", type);

	if (recorder == NULL) {
		LOGE("NULL pointer for recorder handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
		LOGE("NULL pointer for camera handle on video recorder mode");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	bufmgr = tbm_bufmgr_init(-1);
	if (bufmgr == NULL) {
		LOGE("get tbm bufmgr failed");
		return RECORDER_ERROR_INVALID_OPERATION;
	}

	pc = g_new0(recorder_cli_s, 1);
	if (pc == NULL) {
		ret = RECORDER_ERROR_OUT_OF_MEMORY;
		goto _ERR_RECORDER_EXIT;
	}

	sock_fd = muse_core_client_new();
	if (sock_fd < 0) {
		LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _ERR_RECORDER_EXIT;
	}

	if (type == MUSE_RECORDER_TYPE_AUDIO) {
		send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
			MUSE_TYPE_INT, "module", MUSE_RECORDER,
			MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
			MUSE_TYPE_INT, "pid", getpid(),
			NULL);
	} else {
		pc->camera = camera;
		camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
		send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
			MUSE_TYPE_INT, "module", MUSE_RECORDER,
			MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
			MUSE_TYPE_POINTER, "camera_handle", camera_handle,
			NULL);
	}

	if (!send_msg) {
		LOGE("NULL msg");
		ret = RECORDER_ERROR_OUT_OF_MEMORY;
		goto _ERR_RECORDER_EXIT;
	}

	LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);

	send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);

	muse_core_msg_json_factory_free(send_msg);
	send_msg = NULL;

	if (send_ret < 0) {
		LOGE("send msg failed %d", errno);
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _ERR_RECORDER_EXIT;
	}

	pc->cb_info = _recorder_client_callback_new(sock_fd);
	if (pc->cb_info == NULL) {
		ret = RECORDER_ERROR_OUT_OF_MEMORY;
		goto _ERR_RECORDER_EXIT;
	}

	sock_fd = -1;

	ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_NO_TIMEOUT);

	pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;

	if (ret != RECORDER_ERROR_NONE) {
		LOGE("API_CREATE failed 0x%x", ret);
		goto _ERR_RECORDER_EXIT;
	}

	muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
	if (handle == 0) {
		LOGE("Receiving Handle Failed!!");
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _ERR_RECORDER_AFTER_CREATE;
	}

	if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
		LOGE("failed to get root directory of internal storage");
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _ERR_RECORDER_AFTER_CREATE;
	}

	LOGD("root directory [%s]", root_directory);

	RECORDER_MSG_PARAM_SET(param, STRING, root_directory);

	_recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, &param);

	if (ret != RECORDER_ERROR_NONE) {
		LOGE("failed to set root directory %s", root_directory);
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _ERR_RECORDER_AFTER_CREATE;
	}

	free(root_directory);
	root_directory = NULL;

	pc->remote_handle = handle;
	pc->cb_info->bufmgr = bufmgr;

	LOGD("recorder[type %d] %p create success : remote handle 0x%x",
		type, pc, pc->remote_handle);

	*recorder = (recorder_h)pc;

	LOGD("done");

	return RECORDER_ERROR_NONE;

_ERR_RECORDER_AFTER_CREATE:
	_recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret);
	LOGE("destroy return 0x%x", destroy_ret);

_ERR_RECORDER_EXIT:
	tbm_bufmgr_deinit(bufmgr);
	bufmgr = NULL;

	if (root_directory) {
		free(root_directory);
		root_directory = NULL;
	}

	if (sock_fd > -1) {
		muse_core_connection_close(sock_fd);
		sock_fd = -1;
	}

	if (pc) {
		if (pc->cb_info) {
			_recorder_client_callback_destroy(pc->cb_info);
			pc->cb_info = NULL;
		}
		g_free(pc);
		pc = NULL;
	}

	return ret;
}


int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
{
	return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
}


int recorder_create_audiorecorder(recorder_h *recorder)
{
	return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
}


int recorder_get_state(recorder_h recorder, recorder_state_e *state)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (state == NULL) {
		LOGE("NULL pointer state");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, remote_handle : %x", pc->remote_handle);

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];

	LOGD("ret : 0x%x, state : %d", ret, *state);

	return ret;
}


int recorder_destroy(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	if (pc->cb_info->is_server_connected)
		_recorder_msg_send(api, pc->cb_info, &ret);
	else
		LOGW("server disconnected. release resource without send message.");

	if (ret == RECORDER_ERROR_NONE) {
		_recorder_remove_idle_event_all(pc->cb_info);
		_recorder_client_callback_destroy(pc->cb_info);
		g_free(pc);
		pc = NULL;
	}

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_prepare(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	if (ret == RECORDER_ERROR_NONE && pc->camera)
		camera_start_evas_rendering(pc->camera);

	return ret;
}


int recorder_unprepare(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	camera_state_e camera_state = CAMERA_STATE_NONE;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	if (pc->camera) {
		ret = camera_get_state(pc->camera, &camera_state);
		if (ret != CAMERA_ERROR_NONE) {
			LOGE("failed to get camera state 0x%x", ret);
			return RECORDER_ERROR_INVALID_OPERATION;
		}

		if (camera_state == CAMERA_STATE_PREVIEW) {
			ret = camera_stop_evas_rendering(pc->camera, false);
			if (ret != CAMERA_ERROR_NONE) {
				LOGE("camera_stop_evas_rendering failed 0x%x", ret);
				return RECORDER_ERROR_INVALID_OPERATION;
			}
		}
	}

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_start(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_START;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_state_e current_state = RECORDER_STATE_NONE;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	if (pc->camera) {
		ret = recorder_get_state(recorder, &current_state);
		if (ret != RECORDER_ERROR_NONE) {
			LOGE("failed to get current state 0x%x", ret);
			return RECORDER_ERROR_INVALID_OPERATION;
		}

		if (current_state == RECORDER_STATE_READY) {
			ret = camera_stop_evas_rendering(pc->camera, true);
			if (ret != CAMERA_ERROR_NONE) {
				LOGE("camera_stop_evas_rendering failed 0x%x", ret);
				return RECORDER_ERROR_INVALID_OPERATION;
			}
		}
	}

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (pc->camera && current_state == RECORDER_STATE_READY)
		camera_start_evas_rendering(pc->camera);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_pause(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_commit(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_state_e current_state = RECORDER_STATE_NONE;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	if (pc->camera) {
		ret = recorder_get_state(recorder, &current_state);
		if (ret != RECORDER_ERROR_NONE) {
			LOGE("failed to get current state 0x%x", ret);
			return RECORDER_ERROR_INVALID_OPERATION;
		}

		if (current_state >= RECORDER_STATE_RECORDING) {
			ret = camera_stop_evas_rendering(pc->camera, true);
			if (ret != CAMERA_ERROR_NONE) {
				LOGE("camera_stop_evas_rendering failed 0x%x", ret);
				return RECORDER_ERROR_INVALID_OPERATION;
			}
		}
	}

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
		camera_start_evas_rendering(pc->camera);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_cancel(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_state_e current_state = RECORDER_STATE_NONE;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	if (pc->camera) {
		ret = recorder_get_state(recorder, &current_state);
		if (ret != RECORDER_ERROR_NONE) {
			LOGE("failed to get current state 0x%x", ret);
			return RECORDER_ERROR_INVALID_OPERATION;
		}

		if (current_state >= RECORDER_STATE_RECORDING) {
			ret = camera_stop_evas_rendering(pc->camera, true);
			if (ret != CAMERA_ERROR_NONE) {
				LOGE("camera_stop_evas_rendering failed 0x%x", ret);
				return RECORDER_ERROR_INVALID_OPERATION;
			}
		}
	}

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
		camera_start_evas_rendering(pc->camera);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_set_video_resolution(recorder_h recorder, int width, int height)
{
	int ret = RECORDER_ERROR_NONE;
	int send_ret = 0;
	char *send_msg = NULL;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	send_msg = muse_core_msg_json_factory_new(api,
		MUSE_TYPE_INT, "width", width,
		MUSE_TYPE_INT, "height", height,
		NULL);
	if (send_msg) {
		if (pc->cb_info->is_server_connected) {
			__recorder_update_api_waiting(pc->cb_info, api, 1);

			send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
		}

		if (send_ret < 0) {
			LOGE("message send failed");
			ret = RECORDER_ERROR_INVALID_OPERATION;
		} else {
			ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
		}

		__recorder_update_api_waiting(pc->cb_info, api, -1);

		muse_core_msg_json_factory_free(send_msg);
	} else {
		LOGE("failed to create msg");
		ret = RECORDER_ERROR_OUT_OF_MEMORY;
	}

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (!width || !height) {
		LOGE("NULL pointer width = [%p], height = [%p]", width, height);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE) {
		*width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
		*height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
	}

	LOGD("ret : 0x%x, %dx%d", ret, *width, *height);

	return ret;
}


int recorder_foreach_supported_video_resolution(recorder_h recorder,
	recorder_supported_video_resolution_cb foreach_cb, void *user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;

	if (!pc || !pc->cb_info || foreach_cb == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, handle :%x", pc->remote_handle);

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_get_audio_level(recorder_h recorder, double *level)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info || level == NULL) {
		LOGE("NULL pointer %p %p", pc, level);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];

	LOGD("ret : 0x%x, level %lf", ret, *level);

	return ret;
}


int recorder_set_filename(recorder_h recorder,  const char *filename)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;
	char set_filename[RECORDER_FILENAME_MAX] = {0, };

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (filename == NULL) {
		LOGE("filename is NULL");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
		/* Cannot convert. Use original path. */
		strncpy(set_filename, filename, strlen(filename));
	} else {
		/* Converted. Use converted path. */
		LOGD("Converted filename : %s -> %s", filename, set_filename);
	}

	RECORDER_MSG_PARAM_SET(param, STRING, set_filename);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_get_filename(recorder_h recorder,  char **filename)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	char compat_filename[RECORDER_FILENAME_MAX] = {0, };

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (filename == NULL) {
		LOGE("filename is NULL");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE) {
		if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
			/* Cannot convert. Use original path. */
			*filename = pc->cb_info->get_filename;
		} else {
			/* Converted. Use converted path. */
			LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
			*filename = strdup(compat_filename);
			free(pc->cb_info->get_filename);
		}

		pc->cb_info->get_filename = NULL;
	}

	LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");

	return ret;
}


int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
{
	int ret = RECORDER_ERROR_NONE;
	int set_format = (int)format;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER, set_format : %d", set_format);

	RECORDER_MSG_PARAM_SET(param, INT, set_format);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);
	return ret;
}


int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (format == NULL) {
		LOGE("NULL pointer data");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];

	LOGD("ret : 0x%x, format %d", ret, *format);

	return ret;
}


int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	bool is_available = false;
	int stream_index = 0;
	char *stream_type = NULL;
	char *send_msg = NULL;
	int send_ret = 0;

	if (!pc || !pc->cb_info || stream_info == NULL) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
	if (ret != SOUND_MANAGER_ERROR_NONE) {
		LOGE("stream info verification failed");
		return RECORDER_ERROR_INVALID_OPERATION;
	}

	if (is_available == false) {
		LOGE("stream information is not available");
		return RECORDER_ERROR_INVALID_OPERATION;
	}

	ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
	ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);

	LOGD("sound manager return [0x%x]", ret);

	if (ret == SOUND_MANAGER_ERROR_NONE) {
		send_msg = muse_core_msg_json_factory_new(api,
			MUSE_TYPE_STRING, "stream_type", stream_type,
			MUSE_TYPE_INT, "stream_index", stream_index,
			NULL);
		if (send_msg) {
			if (pc->cb_info->is_server_connected) {
				__recorder_update_api_waiting(pc->cb_info, api, 1);

				send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
			}

			if (send_ret < 0) {
				LOGE("message send failed");
				ret = RECORDER_ERROR_INVALID_OPERATION;
			} else {
				ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
			}

			__recorder_update_api_waiting(pc->cb_info, api, -1);

			muse_core_msg_json_factory_free(send_msg);
		} else {
			LOGE("failed to create msg");
			ret = RECORDER_ERROR_OUT_OF_MEMORY;
		}
	} else {
		ret = RECORDER_ERROR_INVALID_OPERATION;
	}

	return ret;
}


int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;

	if (!pc || !pc->cb_info || callback == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, handle :%x", pc->remote_handle);

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_unset_state_changed_cb(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;

	if (!pc || !pc->cb_info || callback == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, handle :%x", pc->remote_handle);

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_unset_interrupted_cb(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;

	if (!pc || !pc->cb_info || callback == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, handle :%x", pc->remote_handle);

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_unset_audio_stream_cb(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;

	if (!pc || !pc->cb_info || callback == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, handle :%x", pc->remote_handle);

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_unset_error_cb(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;

	if (!pc || !pc->cb_info || callback == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, handle :%x", pc->remote_handle);

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_unset_recording_status_cb(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;

	if (!pc || !pc->cb_info || callback == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;

	if (!pc || !pc->cb_info || foreach_cb == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, handle :%x", pc->remote_handle);

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, kbyte);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_attr_set_time_limit(recorder_h recorder, int second)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, second);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
{
	int ret = RECORDER_ERROR_NONE;
	int set_device = (int)device;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	};

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, set_device);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
{
	int ret = RECORDER_ERROR_NONE;
	int set_codec = (int)codec;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, set_codec);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (codec == NULL) {
		LOGE("codec is NULL");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];

	LOGD("ret : 0x%x, codec %d", ret, *codec);

	return ret;
}


int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
{
	int ret = RECORDER_ERROR_NONE;
	int set_codec = (int)codec;
	muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, set_codec);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (codec == NULL) {
		LOGE("codec is NULL");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];

	LOGD("ret : 0x%x, codec %d", ret, *codec);

	return ret;
}


int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER, samplerate : %d", samplerate);

	RECORDER_MSG_PARAM_SET(param, INT, samplerate);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, bitrate);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, bitrate);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (kbyte == NULL) {
		LOGE("NULL pointer kbyte");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];

	LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);

	return ret;
}


int recorder_attr_get_time_limit(recorder_h recorder, int *second)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (second == NULL) {
		LOGE("NULL pointer second");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];

	LOGD("ret : 0x%x, %d second", ret, *second);

	return ret;
}


int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (device == NULL) {
		LOGE("NULL pointer device");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];

	LOGD("ret : 0x%x, device %d", ret, *device);

	return ret;
}


int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (samplerate == NULL) {
		LOGE("NULL pointer handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];

	LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);

	return ret;
}


int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (bitrate == NULL) {
		LOGE("NULL pointer");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];

	LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);

	return ret;
}


int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (bitrate == NULL) {
		LOGE("NULL pointer");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;

	if (!pc || !pc->cb_info || foreach_cb == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, handle :%x", pc->remote_handle);

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;

	if (!pc || !pc->cb_info || foreach_cb == NULL) {
		LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter, handle :%x", pc->remote_handle);

	pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
	pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;

	_recorder_msg_send(api, pc->cb_info, &ret);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_attr_set_mute(recorder_h recorder, bool enable)
{
	int ret = RECORDER_ERROR_NONE;
	int set_enable = (int)enable;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, set_enable);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


bool recorder_attr_is_muted(recorder_h recorder)
{
	int ret = false;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return false;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
		ret = false;

	LOGD("ret : %d", ret);

	return (bool)ret;
}


int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER - %.20lf", rate);

	RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (rate == NULL) {
		LOGE("rate is NULL");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);
	if (ret == RECORDER_ERROR_NONE)
		*rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];

	LOGD("ret : 0x%x - rate %.20lf", ret, *rate);

	return ret;
}


int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, channel_count);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (channel_count == NULL) {
		LOGE("channel_count is NULL");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];

	LOGD("ret : 0x%x, channel count %d", ret, *channel_count);

	return ret;
}


int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
{
	int ret = RECORDER_ERROR_NONE;
	int set_orientation = (int)orientation;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;
	recorder_msg_param param;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	RECORDER_MSG_PARAM_SET(param, INT, set_orientation);

	_recorder_msg_send_param1(api, pc->cb_info, &ret, &param);

	LOGD("ret : 0x%x", ret);

	return ret;
}


int  recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
{
	int ret = RECORDER_ERROR_NONE;
	muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
	recorder_cli_s *pc = (recorder_cli_s *)recorder;

	if (!pc || !pc->cb_info) {
		LOGE("NULL handle");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	if (orientation == NULL) {
		LOGE("orientation is NULL");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("ENTER");

	_recorder_msg_send(api, pc->cb_info, &ret);

	if (ret == RECORDER_ERROR_NONE)
		*orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];

	LOGD("ret : 0x%x, orientation %d", ret, *orientation);

	return ret;
}


int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
{
	int ret = RECORDER_ERROR_NONE;
	int sock_fd = -1;
	int get_device_state = 0;
	char *send_msg = NULL;
	char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};

	if (!state) {
		LOGE("NULL pointer");
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	LOGD("Enter - type %d", type);

	sock_fd = muse_core_client_new();
	if (sock_fd < 0) {
		LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _GET_DEVICE_STATE_EXIT;
	}

	send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
		MUSE_TYPE_INT, "module", MUSE_RECORDER,
		MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
		NULL);
	if (!send_msg) {
		LOGE("NULL msg");
		ret = RECORDER_ERROR_OUT_OF_MEMORY;
		goto _GET_DEVICE_STATE_EXIT;
	}

	LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);

	ret = muse_core_ipc_send_msg(sock_fd, send_msg);

	muse_core_msg_json_factory_free(send_msg);
	send_msg = NULL;

	if (ret < 0) {
		LOGE("send msg failed %d", errno);
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _GET_DEVICE_STATE_EXIT;
	}

	ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
	if (ret <= 0) {
		LOGE("recv msg failed %d", errno);
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _GET_DEVICE_STATE_EXIT;
	}

	if (!muse_recorder_msg_get(ret, recv_msg)) {
		LOGE("failed to get return value from msg [%s]", recv_msg);
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _GET_DEVICE_STATE_EXIT;
	}

	if (ret == RECORDER_ERROR_NONE) {
		if (muse_recorder_msg_get(get_device_state, recv_msg)) {
			*state = (recorder_device_state_e)get_device_state;
			LOGD("device type %d state %d", type, *state);
		} else {
			LOGE("failed to get device state from msg [%s]", recv_msg);
			ret = RECORDER_ERROR_INVALID_OPERATION;
		}
	} else {
		LOGE("failed 0x%x", ret);
	}

_GET_DEVICE_STATE_EXIT:
	if (sock_fd > -1) {
		muse_core_connection_close(sock_fd);
		sock_fd = -1;
	}

	return ret;
}


int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
	recorder_cb_info *info = NULL;

	if (!callback || !cb_id) {
		LOGE("invalid pointer %p %p", callback, cb_id);
		return RECORDER_ERROR_INVALID_PARAMETER;
	}

	g_mutex_lock(&g_rec_dev_state_changed_cb_lock);

	/* check recorder support */
	ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
	if (ret != RECORDER_ERROR_NONE) {
		LOGE("get device state failed");
		g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
		return ret;
	}

	info = g_new0(recorder_cb_info, 1);
	if (!info) {
		LOGE("info failed");
		ret = RECORDER_ERROR_OUT_OF_MEMORY;
		goto _DONE;
	}

	info->id = ++g_rec_dev_state_changed_cb_id;
	info->callback = (void *)callback;
	info->user_data = user_data;

	*cb_id = info->id;

	/* subscribe dbus signal for camera state change */
	if (!g_rec_dev_state_changed_cb_conn) {
		g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
		if (!g_rec_dev_state_changed_cb_conn) {
			LOGE("failed to get gdbus connection");
			ret = RECORDER_ERROR_INVALID_OPERATION;
			goto _DONE;
		}

		LOGD("subscribe signal %s - %s - %s",
			MM_CAMCORDER_DBUS_OBJECT,
			MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
			MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);

		g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
			NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
			G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
		if (!g_rec_dev_state_changed_cb_subscribe_id) {
			LOGE("failed to get gdbus connection");
			ret = RECORDER_ERROR_INVALID_OPERATION;
			goto _DONE;
		}

		LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
	}

	g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);

	LOGD("callback id %d", info->id);

_DONE:
	if (ret != RECORDER_ERROR_NONE) {
		if (info) {
			g_free(info);
			info = NULL;
		}

		if (g_rec_dev_state_changed_cb_conn) {
			g_object_unref(g_rec_dev_state_changed_cb_conn);
			g_rec_dev_state_changed_cb_conn = NULL;
		}
	}

	g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);

	return ret;
}


int recorder_remove_device_state_changed_cb(int cb_id)
{
	int ret = RECORDER_ERROR_NONE;
	recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
	GList *tmp_list = NULL;
	recorder_cb_info *info = NULL;

	/* check recorder support */
	ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
	if (ret != RECORDER_ERROR_NONE) {
		LOGE("get device state failed");
		return ret;
	}

	g_mutex_lock(&g_rec_dev_state_changed_cb_lock);

	if (!g_rec_dev_state_changed_cb_list) {
		LOGE("there is no callback info");
		ret = RECORDER_ERROR_INVALID_OPERATION;
		goto _DONE;
	}

	tmp_list = g_rec_dev_state_changed_cb_list;

	do {
		info = tmp_list->data;
		tmp_list = tmp_list->next;

		if (!info) {
			LOGW("NULL info");
			continue;
		}

		if (info->id == cb_id) {
			g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);

			g_free(info);
			info = NULL;

			if (!g_rec_dev_state_changed_cb_list) {
				/* no remained callback */
				if (g_rec_dev_state_changed_cb_conn) {
					/* unsubscribe signal */
					g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
					g_rec_dev_state_changed_cb_subscribe_id = 0;

					/* unref connection */
					g_object_unref(g_rec_dev_state_changed_cb_conn);
					g_rec_dev_state_changed_cb_conn = NULL;
				}
			}

			LOGD("id %d callback removed", cb_id);
			ret = RECORDER_ERROR_NONE;

			goto _DONE;
		}
	} while (tmp_list);

	LOGE("id %d callback not found", cb_id);
	ret = RECORDER_ERROR_INVALID_PARAMETER;

_DONE:
	g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);

	return ret;
}