summaryrefslogtreecommitdiff
path: root/test/camera_test.c
blob: dbad1b348ae7db1da13517b772adddb2e14948fe (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
/*
 * camera_test
 *
 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
 *
 * 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 f(r the specific language governing permissions and
 * limitations under the License.
 *
 */

/*=======================================================================================
|  INCLUDE FILES                                                                        |
=======================================================================================*/
#include "camera_test.h"

/*-----------------------------------------------------------------------
|    GLOBAL VARIABLE DEFINITIONS:                                       |
-----------------------------------------------------------------------*/
#define EXPORT_API __attribute__((__visibility__("default")))

static cam_handle_t *hcamcorder;
static camera_device_e camera_device;
static int g_camera_device_state_changed_cb_id;
static int g_camera_device_connection_changed_cb_id;
static int g_camera_preview_cb_dump;
static int g_camera_extra_preview_cb_dump;
static int g_camera_mp_preview_cb_dump;

static struct timeval previous_time;
static struct timeval current_time;
static struct timeval result_time;

static media_bridge_h bridge;

/*-----------------------------------------------------------------------
|    GLOBAL CONSTANT DEFINITIONS:                                       |
-----------------------------------------------------------------------*/


/*-----------------------------------------------------------------------
|    IMPORTED VARIABLE DECLARATIONS:                                    |
-----------------------------------------------------------------------*/


/*-----------------------------------------------------------------------
|    IMPORTED FUNCTION DECLARATIONS:                                    |
-----------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
  |    LOCAL VARIABLE DEFINITIONS:                                            |
  ---------------------------------------------------------------------------*/
static camera_device_manager_h g_device_manager;

const char *wb[SENSOR_WHITEBALANCE_NUM] = {
	"None",
	"Auto",
	"Daylight",
	"Cloudy",
	"Fluoroscent",
	"Incandescent",
	"Shade",
	"Horizon",
	"Flash",
	"Custom",
};

const char *ct[SENSOR_COLOR_TONE_NUM] = {
	"NONE",
	"MONO",
	"SEPIA",
	"NEGATIVE",
	"BLUE",
	"GREEN",
	"AQUA",
	"VIOLET",
	"ORANGE",
	"GRAY",
	"RED",
	"ANTIQUE",
	"WARM",
	"PINK",
	"YELLOW",
	"PURPLE",
	"EMBOSS",
	"OUTLINE",
	"SOLARIZATION",
	"SKETCH",
	"WASHED",
	"VINTAGE_WARM",
	"VINTAGE_COLD",
	"POSTERIZATION",
	"CARTOON",
	"SELECTVE_COLOR_RED",
	"SELECTVE_COLOR_GREEN",
	"SELECTVE_COLOR_BLUE",
	"SELECTVE_COLOR_YELLOW",
	"SELECTVE_COLOR_RED_YELLOW",
	"GRAPHICS"
};

const char *sensor_flip[SENSOR_FLIP_NUM] = {
	"NONE",
	"HORIZONTAL",
	"VERTICAL",
	"BOTH"
};

const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
	"NORMAL",
	"PORTRAIT",
	"LANDSCAPE",
	"SPORTS",
	"PARTY_N_INDOOR",
	"BEACH_N_INDOOR",
	"SUNSET",
	"DUSK_N_DAWN",
	"FALL_COLOR",
	"NIGHT_SCENE",
	"FIREWORK",
	"TEXT",
	"SHOW_WINDOW",
	"CANDLE_LIGHT",
	"BACKLIGHT",
};

const char *focus_mode[SENSOR_FOCUS_NUM] = {
	"None",
	"Pan",
	"Auto",
	"Manual",
	"Touch Auto",
	"Continuous Auto",
};

const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
	"None",
	"90",
	"180",
	"270",
};

const char *iso_mode[SENSOR_ISO_NUM] = {
	"ISO Auto",
	"ISO 50",
	"ISO 100",
	"ISO 200",
	"ISO 400",
	"ISO 800",
	"ISO 1600",
	"ISO 3200",
};

const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
	"AE off",
	"AE all mode",
	"AE center mode",
	"AE spot 1 mode",
	"AE custom mode",
};

const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
	"NV12",
	"NV12T",
	"NV16",
	"NV21",
	"YUYV",
	"UYVY",
	"422P",
	"I420",
	"YV12",
	"RGB565",
	"RGB888",
	"RGBA",
	"ARGB",
	"JPEG",
	"ITLV(YUYV+JPEG, but should not be seen)",
	"H264",
	"INVZ",
	"MJPEG",
	"VP8",
	"VP9"
};

const char *face_zoom_mode[] = {
	"Face Zoom OFF",
	"Face Zoom ON",
};

const char *display_mode[] = {
	"Letter Box mode",
	"Original Size mode",
	"Full Screen mode",
	"Cropped Full Screen mode",
	"ROI mode",
};

const char *capture_sound[] = {
	"Default",
	"Extra 01",
	"Extra 02",
};

const char *rotate_mode[] = {
	"0",
	"90",
	"180",
	"270",
};

const char* strobe_mode[] = {
	"Strobe OFF",
	"Strobe ON",
	"Strobe Auto",
	"Strobe RedEyeReduction",
	"Strobe SlowSync",
	"Strobe FrontCurtain",
	"Strobe RearCurtain",
	"Strobe Permanent",
};

const char *detection_mode[2] = {
	"Face Detection OFF",
	"Face Detection ON",
};

const char *wdr_mode[] = {
	"WDR OFF",
	"WDR ON",
	"WDR AUTO",
};

const char *af_scan[SENSOR_AF_SCAN_NUM] = {
	"None",
	"Normal",
	"Macro mode",
	"Full mode",
};

const char *hdr_mode[] = {
	"HDR OFF",
	"HDR ON",
	"HDR ON and Original",
};

const char *ahs_mode[] = {
	"Anti-handshake OFF",
	"Anti-handshake ON",
	"Anti-handshake AUTO",
	"Anti-handshake MOVIE",
};

const char *vs_mode[] = {
	"Video-stabilization OFF",
	"Video-stabilization ON",
};

const char *visible_mode[] = {
	"Display OFF",
	"Display ON",
};

const char *facing_direction[] = {
	"REAR",
	"FRONT",
};


/*---------------------------------------------------------------------------
  |    LOCAL FUNCTION PROTOTYPES:                                             |
  ---------------------------------------------------------------------------*/
static gboolean mode_change(gchar buf);
int camcordertest_set_attr_int(const char* attr_subcategory, int value);


static void __release_media_bridge()
{
	if (bridge) {
		media_bridge_unset_source(bridge); /* not mandatory, it will be done in media_bridge_destroy() */
		media_bridge_destroy(bridge);
		bridge = NULL;
	}
}

void flush_stdin()
{
	int ch;
	while ((ch = getchar()) != EOF && ch != '\n');
}

static gboolean _release_idle_event_callback(void *data)
{
	g_print("destroy camera handle\n\n");

	camera_destroy(hcamcorder->camera);
	hcamcorder->camera = NULL;
	hcamcorder->menu_state = MENU_STATE_INIT;

	print_menu();

	return 0;
}

static void _camera_error_cb(int error, camera_state_e current_state, void *user_data)
{
	g_print("\n\n\tERROR [0x%x], current state %d\n", error, current_state);

	switch (error) {
	case CAMERA_ERROR_RESOURCE_CONFLICT:
		g_print("\t\t[CAMERA_ERROR_RESOURCE_CONFLICT]\n\n");
		break;
	case CAMERA_ERROR_SECURITY_RESTRICTED:
		g_print("\t\t[CAMERA_ERROR_SECURITY_RESTRICTED]\n\n");
		break;
	case CAMERA_ERROR_SERVICE_DISCONNECTED:
		g_print("\t\t[CAMERA_ERROR_SERVICE_DISCONNECTED]\n\n");
		g_idle_add_full(G_PRIORITY_DEFAULT,
			(GSourceFunc)_release_idle_event_callback,
			NULL, NULL);
		break;
	default:
		break;
	}
}

static void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
{
	g_print("\n\tcamera state changed %d -> %d\n", previous, current);
}

static void _camera_device_state_changed_cb(camera_device_e device, camera_device_state_e state, void *user_data)
{
	g_print("\n\tcamera device[%d] state changed to %d\n", device, state);
}

static void _camera_device_connection_changed_cb(camera_device_s *device, bool is_connected, void *user_data)
{
	g_print("\n\tcamera device changed[is_connected:%d][Type:%d,index:%d,name:%s,id:%s,exstream:%d]\n",
		is_connected, device->type, device->index, device->name, device->id, device->extra_stream_num);
}

static bool _camera_supported_device_cb(camera_device_s *device, void *user_data)
{
	g_print("\n\tcamera supported device[Type:%d,index:%d,name:%s,id:%s,exstream:%d]\n",
		device->type, device->index, device->name, device->id, device->extra_stream_num);

	return true;
}

static void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
{
	g_print("\n\tcamera interrupted callback called[state %d -> %d, policy %d]\n",
		previous, current, policy);
}

static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
{
	g_print("\n\tcamera interrupt started callback called[state %d, policy %d]\n", state, policy);
}

static void _dump_preview_data(camera_preview_data_s *frame, const char *file_name)
{
	char dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
	FILE *fp = NULL;

	if (!frame) {
		g_print("\n[DUMP_PREVIEW_DATA] NULL frame\n");
		return;
	}

	snprintf(dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, file_name);

	fp = fopen(dump_path, "a");
	if (fp == NULL) {
		g_print("\n[DUMP_PREVIEW_DATA] file[%s] open failed\n", dump_path);
		return;
	}

	switch (frame->format) {
	case CAMERA_PIXEL_FORMAT_RGBA:
		/* fall through */
	case CAMERA_PIXEL_FORMAT_ARGB:
		fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp);
		break;
	case CAMERA_PIXEL_FORMAT_INVZ:
		fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp);
		break;
	case CAMERA_PIXEL_FORMAT_H264:
		/* fall through */
	case CAMERA_PIXEL_FORMAT_MJPEG:
		/* fall through */
	case CAMERA_PIXEL_FORMAT_VP8:
		/* fall through */
	case CAMERA_PIXEL_FORMAT_VP9:
		fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp);
		break;
	default:
		switch (frame->num_of_planes) {
		case 1:
			fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
			break;
		case 2:
			fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
			fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
			break;
		case 3:
			fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
			fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
			fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
			break;
		default:
			break;
		}
		break;
	}

	g_print("[DUMP_PREVIEW_DATA] file[%s] write done\n", dump_path);

	fclose(fp);
}

static void _camera_print_preview_info(camera_preview_data_s *frame)
{
	if (!frame) {
		g_print("\n[PREVIEW_CB] NULL frame!\n");
		return;
	}

	g_print("format[%d] res[%dx%d] num plane[%d] ",
		frame->format, frame->width, frame->height, frame->num_of_planes);

	if (frame->num_of_planes == 1) {
		g_print("size [%d]\n",
			frame->data.single_plane.size);
	} else if (frame->num_of_planes == 2) {
		g_print("size Y[%d] UV[%d]\n",
			frame->data.double_plane.y_size,
			frame->data.double_plane.uv_size);
	} else if (frame->num_of_planes == 3) {
		g_print("size Y[%d] U[%d] V[%d]\n",
			frame->data.triple_plane.y_size,
			frame->data.triple_plane.u_size,
			frame->data.triple_plane.v_size);
	}
}

static void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
{
	int ret = CAMERA_ERROR_NONE;
	camera_h cam_handle = (camera_h)user_data;
	camera_rotation_e rotation = CAMERA_ROTATION_NONE;

	if (!cam_handle || !frame) {
		g_print("\n[PREVIEW_CB] NULL param! %p %p\n", cam_handle, frame);
		return;
	}

	ret = camera_attr_get_preview_frame_rotation(cam_handle, &rotation);
	if (ret != CAMERA_ERROR_NONE)
		g_print("[PREVIEW_CB] get preview frame rotation failed[0x%x]\n", ret);

	g_print("[PREVIEW_CB] preview[rotation:%d] callback - ", rotation);

	_camera_print_preview_info(frame);

	if (g_camera_preview_cb_dump)
		_dump_preview_data(frame, PREVIEW_CB_DUMP_FILE_NAME);
}

static void _camera_extra_preview_cb(camera_preview_data_s *frame, int stream_id, void *user_data)
{
	if (!frame) {
		g_print("\n[PREVIEW_CB] NULL frame!\n");
		return;
	}

	g_print("[EXTRA_PREVIEW_CB][stream_id:%d] preview callback - ", stream_id);

	_camera_print_preview_info(frame);

	if (g_camera_extra_preview_cb_dump)
		_dump_preview_data(frame, EXTRA_PREVIEW_CB_DUMP_FILE_NAME);
}

static void _dump_media_packet_data(media_packet_h pkt, const char *file_name)
{
	int ret = 0;
	unsigned int i = 0;
	bool has_surface = false;
	FILE *fp = NULL;
	char dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
	tbm_surface_h surface = NULL;
	tbm_surface_info_s s_info;
	void *data = NULL;
	uint64_t data_size = 0;

	if (!pkt) {
		g_print("\n[DUMP_MEDIA_PACKET_DATA] NULL packet\n");
		return;
	}

	snprintf(dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, file_name);
	fp = fopen(dump_path, "a");
	if (fp == NULL) {
		g_print("\n[DUMP_MEDIA_PACKET_DATA] file[%s] open failed ====\n", dump_path);
		goto _DUMP_MEDIA_PACKET_DATA_OUT;
	}

	ret = media_packet_has_tbm_surface_buffer(pkt, &has_surface);
	if (ret != MEDIA_PACKET_ERROR_NONE) {
		g_print("\n[DUMP_MEDIA_PACKET_DATA] has tbm surface failed[0x%x] ====\n", ret);
		goto _DUMP_MEDIA_PACKET_DATA_OUT;
	}

	if (has_surface) {
		ret = media_packet_get_tbm_surface(pkt, &surface);
		if (ret != MEDIA_PACKET_ERROR_NONE) {
			g_print("\n[DUMP_MEDIA_PACKET_DATA] get tbm surface failed[0x%x] ====\n", ret);
			goto _DUMP_MEDIA_PACKET_DATA_OUT;
		}

		ret = tbm_surface_get_info(surface, &s_info);
		if (ret != TBM_SURFACE_ERROR_NONE) {
			g_print("\n[DUMP_MEDIA_PACKET_DATA] get tbm surface info failed[0x%x] ====\n", ret);
			goto _DUMP_MEDIA_PACKET_DATA_OUT;
		}

		g_print("    tbm surface [%dx%d], total size[%u]\n",
			s_info.width, s_info.height, s_info.size);

		for (i = 0 ; i < s_info.num_planes ; i++) {
			g_print("        plane[%d][%p] stride[%u] size[%u]\n",
				i, s_info.planes[i].ptr, s_info.planes[i].stride, s_info.planes[i].size);
			fwrite(s_info.planes[i].ptr, 1, s_info.planes[i].size, fp);
		}
	} else {
		ret = media_packet_get_buffer_data_ptr(pkt, &data);
		if (ret != MEDIA_PACKET_ERROR_NONE) {
			g_print("\n[DUMP_MEDIA_PACKET_DATA] get data ptr failed[0x%x] ====\n", ret);
			goto _DUMP_MEDIA_PACKET_DATA_OUT;
		}

		ret = media_packet_get_buffer_size(pkt, &data_size);
		if (ret != MEDIA_PACKET_ERROR_NONE) {
			g_print("\n[DUMP_MEDIA_PACKET_DATA] get data size failed[0x%x] ====\n", ret);
			goto _DUMP_MEDIA_PACKET_DATA_OUT;
		}

		g_print("    no tbm surface, data[%p], size[%"PRIu64"]\n", data, data_size);

		fwrite(data, 1, data_size, fp);
	}

_DUMP_MEDIA_PACKET_DATA_OUT:
	if (fp)
		fclose(fp);
}

static void _camera_media_packet_preview_cb(media_packet_h pkt, void *user_data)
{
	int ret = 0;
	int width = 0;
	int height = 0;
	media_format_h fmt = NULL;
	media_format_mimetype_e type = MEDIA_FORMAT_I420;

	if (!pkt) {
		g_print("\n[MP_PREVIEW_CB] NULL packet!\n");
		return;
	}

	ret = media_packet_get_format(pkt, &fmt);
	if (ret != MEDIA_PACKET_ERROR_NONE) {
		g_print("\n[MP_PREVIEW_CB] get media format failed[0x%x]", ret);
		goto _MEDIA_PACKET_PREVIEW_CB_OUT;
	}

	ret = media_format_get_video_info(fmt, &type, &width, &height, NULL, NULL);
	if (ret != MEDIA_FORMAT_ERROR_NONE) {
		g_print("\n[MP_PREVIEW_CB] get video info failed[0x%x]", ret);
		goto _MEDIA_PACKET_PREVIEW_CB_OUT;
	}

	g_print("[MP_PREVIEW_CB] media_packet_preview_cb[mimetype:0x%x, %dx%d]\n", type, width, height);

	if (g_camera_mp_preview_cb_dump)
		_dump_media_packet_data(pkt, MP_PREVIEW_CB_DUMP_FILE_NAME);

_MEDIA_PACKET_PREVIEW_CB_OUT:
	if (fmt) {
		media_format_unref(fmt);
		fmt = NULL;
	}

	media_packet_unref(pkt);
}

static bool _resolution_cb(int width, int height, void *user_data)
{
	resolution_stack *data = (resolution_stack *)user_data;

	if (data == NULL) {
		g_print("NULL data\n");
		return false;
	}

	data->width[data->count] = width;
	data->height[data->count] = height;

	g_print("\t%d. %dx%d\n", data->count, width, height);

	data->count++;

	return true;
}

static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
{
	g_print("\t%d. %s\n", mode, af_scan[mode]);
	return true;
}

static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
{
	exposure_stack *data = (exposure_stack *)user_data;

	if (data == NULL) {
		g_print("NULL data\n");
		return false;
	}

	data->mode = mode;
	data->count++;

	g_print("\t%d. %s\n", mode, exposure_mode[mode]);
	return true;
}

static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
{
	g_print("\t%d. %s\n", mode, iso_mode[mode]);
	return true;
}

static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
{
	g_print("\t%d. %s\n", mode, camera_rotation[mode]);
	return true;
}

static bool camera_flip_cb(camera_flip_e mode, void *user_data)
{
	g_print("\t%d. %s\n", mode, sensor_flip[mode]);
	return true;
}

static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
{
	g_print("\t%d. %s\n", mode, image_fmt[mode]);
	return true;
}

static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
{
	g_print("\t%d. %s\n", mode, wb[mode]);
	return true;
}

static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
{
	g_print("\t%d. %s\n", mode, ct[mode]);
	return true;
}

static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
{
	g_print("\t%d. %s\n", mode, program_mode[mode]);
	return true;
}

static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
{
	g_print("\t%d. %s\n", mode, strobe_mode[mode]);
	return true;
}

static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
{
	int i;

	g_print("\tface detected!! - count %d\n", count);

	for (i = 0 ; i < count ; i++)
		g_print("\t%d] %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
}

static void _file_write(char *path, void *data, int size)
{
	FILE *fp = NULL;

	if (!path || !data || size <= 0) {
		g_print("\n\tERROR %p %p %d\n", path, data, size);
		return;
	}

	fp = fopen(path, "w");
	if (fp) {
		g_print("\n\topen success [%s]\n", path);
		if (fwrite(data, size, 1, fp) != 1)
			g_print("\n\twrite error! errno %d\n", errno);
		else
			g_print("\n\twrite success [%s]\n", path);

		fclose(fp);
		fp = NULL;
	} else {
		g_print("\n\topen error! [%s], errno %d\n", path, errno);
	}
}

static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
{
	char m_filename[MAX_FILE_NAME_LENGTH];

	/* main image */
	if (image) {
		if (hcamcorder->is_multishot) {
			snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
				hcamcorder->file_path, hcamcorder->multishot_count++);
		} else {
			snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
				hcamcorder->file_path, hcamcorder->stillshot_count++);
		}

		_file_write(m_filename, image->data, image->size);
	}
}

static void capture_completed_cb(void *user_data)
{
	camera_start_preview(hcamcorder->camera);
}

void print_menu()
{
	switch (hcamcorder->menu_state) {
	case MENU_STATE_INIT:
		g_print("\n\t=======================================\n");
		g_print("\t   CAMERA_TESTSUITE\n");
		g_print("\t=======================================\n");
		g_print("\t   '1' Video Capture\n");
		g_print("\t   '2' Device State\n");
		g_print("\t   '3' Device Manager\n");
		g_print("\t   'q' Exit\n");
		g_print("\t=======================================\n");
		break;
	case MENU_STATE_MAIN:
		g_print("\n\t=======================================\n");
		g_print("\t   Video Capture (CAMERA%d)\n", camera_device);
		g_print("\t=======================================\n");
		g_print("\t   '1' Stillshot test\n");
		g_print("\t   '2' Multishot test\n");
		g_print("\t   '3' Setting\n");
		g_print("\t   '4' Change device (CAMERA0 <-> CAMERA1)\n");
		g_print("\t   '5' Set/Unset preview callback\n");
		g_print("\t   '6' Set/Unset extra preview callback\n");
		g_print("\t   '7' Set/Unset media packet preview callback\n");
		g_print("\t   'b' back\n");
		g_print("\t=======================================\n");
		break;
	case MENU_STATE_DEVICE_STATE:
		g_print("\n\t=======================================\n");
		g_print("\t   Device State\n");
		g_print("\t=======================================\n");
		g_print("\t   '1' Get camera device state\n");
		g_print("\t   '2' Add camera device state changed callback\n");
		g_print("\t   '3' Remove camera device state changed callback\n");
		g_print("\t   'b' back\n");
		g_print("\t=======================================\n");
		break;
	case MENU_STATE_DEVICE_MANAGER:
		g_print("\n\t=======================================\n");
		g_print("\t   Device List\n");
		g_print("\t=======================================\n");
		g_print("\t   '1' Initialize device manager\n");
		g_print("\t   '2' Foreach supported camera device\n");
		g_print("\t   '3' Add camera device connection changed callback\n");
		g_print("\t   '4' Remove camera device connection changed callback\n");
		g_print("\t   '9' Deinitialize device manager\n");
		g_print("\t   'b' back\n");
		g_print("\t=======================================\n");
		break;
	case MENU_STATE_MAIN_SETTING:
		g_print("\n\t=======================================\n");
		g_print("\t   Video Capture > Setting\n");
		g_print("\t=======================================\n");
		g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera]  \n");
		g_print("\t     '0' Preview resolution \n");
		g_print("\t     '1' Capture resolution \n");
		g_print("\t     '2' Digital zoom level \n");
		g_print("\t     '3' AF mode \n");
		g_print("\t     '4' AF scan range \n");
		g_print("\t     '5' Exposure mode \n");
		g_print("\t     '6' Exposure value \n");
		g_print("\t     '7' F number \n");
		g_print("\t     '8' Display reuse hint \n");
		g_print("\t     '9' Manual Focus \n");
		g_print("\t     'i' ISO \n");
		g_print("\t     'r' Rotate camera input \n");
		g_print("\t     'f' Flip camera input \n");
		g_print("\t     'j' Jpeg quality \n");
		g_print("\t     'p' Picture format \n");
		g_print("\t     'E' EXIF orientation \n");
		g_print("\t     'F' Get facing direction of camera module\n");
		g_print("\t     's' Extra preview stream format\n");
		g_print("\t     'B' Extra preview bitrate\n");
		g_print("\t     'V' Extra preview GOP interval\n");
		g_print("\t     'D' Request codec config\n");
		g_print("\t  >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
		g_print("\t     'v' Visible \n");
		g_print("\t     'o' Output mode \n");
		g_print("\t     'y' Rotate display \n");
		g_print("\t     'Y' Flip display \n");
		g_print("\t     'g' Brightness \n");
		g_print("\t     'c' Contrast \n");
		g_print("\t     'h' Hue \n");
		g_print("\t     'w' White balance \n");
		g_print("\t     't' Color tone \n");
		g_print("\t     'd' WDR \n");
		g_print("\t     'e' EV program mode \n");
		g_print("\t     'R' Display ROI area \n");
		g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
		g_print("\t     'z' Strobe (Flash) \n");
		g_print("\t     'S' Strobe (Flash) state\n");
		g_print("\t     'G' Strobe (Flash) brightness\n");
		g_print("\t     'x' Capture mode (Still/Multishot/HDR)\n");
		g_print("\t     'l' Face detection \n");
		g_print("\t     'k' Anti-handshake \n");
		g_print("\t     'K' Video-stabilization \n");
		g_print("\t     'u' Touch AF area \n");
		g_print("\t     'n' Set file path to write captured image\n");
		g_print("\t     'm' Set media bridge\n");
		g_print("\t     'b' back\n");
		g_print("\t=======================================\n");
		break;
	default:
		g_print("\n\tunknow menu state !!\n");
		return;
	}

	g_print("\tCommand >> ");
}


static void main_menu(gchar buf)
{
	int err = 0;
	int interval = 0;
	int count = 0;
	int set_cb = 0;

	switch (buf) {
	case '1': /* Capture */
		hcamcorder->is_multishot = FALSE;
		camera_attr_set_image_quality(hcamcorder->camera, 100);
		camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
		camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
		break;
	case '2': /* multishot Capture */
		g_print("multishot capture");
		hcamcorder->is_multishot = TRUE;
		g_print("\n\tinput interval(ms) : ");
		err = scanf("%d", &interval);
		flush_stdin();
		g_print("\n\tinput count : ");
		err = scanf("%d", &count);
		flush_stdin();
		camera_attr_set_image_quality(hcamcorder->camera, 100);
		camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
		camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
		sleep(3);
		camera_start_preview(hcamcorder->camera);
		break;
	case '3': /* Setting */
		hcamcorder->menu_state = MENU_STATE_MAIN_SETTING;
		break;
	case '4': /* Change device (CAMERA0 <-> CAMERA1) */
		camera_set_display_reuse_hint(hcamcorder->camera, true);

		camera_stop_preview(hcamcorder->camera);

		if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
			hcamcorder->type = CAMERA_DEVICE_CAMERA1;
		else
			hcamcorder->type = CAMERA_DEVICE_CAMERA0;

		camera_change_device(hcamcorder->camera, hcamcorder->type);

		camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
		camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
		camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
		camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);

		camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);

		camera_start_preview(hcamcorder->camera);
		break;
	case '5':
		g_print("* Preview Callback\n");
		g_print("\tUnset[0] / Set[Others] :");
		err = scanf("%d", &set_cb);
		flush_stdin();
		if (set_cb) {
			g_print("\n\tDump preview data to file - NO[0], YES[Others] : ");
			err = scanf("%d", &g_camera_preview_cb_dump);
			flush_stdin();
			err = camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
		} else {
			err = camera_unset_preview_cb(hcamcorder->camera);
		}
		g_print("\tresult[0x%x]\n\n", err);
		break;
	case '6':
		g_print("* Extra Preview Callback\n");
		g_print("\tUnset[0] / Set[Others] :");
		err = scanf("%d", &set_cb);
		flush_stdin();
		if (set_cb) {
			g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
			err = scanf("%d", &g_camera_extra_preview_cb_dump);
			flush_stdin();
			err = camera_set_extra_preview_cb(hcamcorder->camera, _camera_extra_preview_cb, hcamcorder->camera);
		} else {
			err = camera_unset_extra_preview_cb(hcamcorder->camera);
		}
		g_print("\tresult[0x%x]\n\n", err);
		break;
	case '7':
		g_print("* Media Packet Preview Callback\n");
		g_print("\tUnset[0] / Set[Others] :");
		err = scanf("%d", &set_cb);
		flush_stdin();
		if (set_cb) {
			g_print("\n\tDump media packet preview data to file - NO[0], YES[Others] : ");
			err = scanf("%d", &g_camera_mp_preview_cb_dump);
			flush_stdin();
			err = camera_set_media_packet_preview_cb(hcamcorder->camera, _camera_media_packet_preview_cb, hcamcorder->camera);
		} else {
			err = camera_unset_media_packet_preview_cb(hcamcorder->camera);
		}
		g_print("\tresult[0x%x]\n\n", err);
		break;
	case 'b': /* back */
		__release_media_bridge();

		camera_stop_preview(hcamcorder->camera);
		camera_destroy(hcamcorder->camera);
		hcamcorder->camera = NULL;
		hcamcorder->menu_state = MENU_STATE_INIT;
		break;
	default:
		g_print("\t Invalid input \n");
		break;
	}
}


static void setting_menu(gchar buf)
{
	int bret = FALSE;
	int idx = 0;
	int min = 0;
	int max = 0;
	int i = 0;
	int err = 0;
	int x = 0;
	int y = 0;
	int width = 0;
	int height = 0;
	int result = 0;
	int set_bridge = 0;
	int stream_id;
	int pixel_format;
	int fps;
	int bitrate;
	int interval;

	switch (buf) {
	/* Camera setting */
	case '0':  /* Setting > Preview Resolution setting */
		g_print("\t* Select the preview resolution!\n");
		resolution_stack resolution_list;
		resolution_list.count = 0;

		camera_foreach_supported_preview_resolution(hcamcorder->camera,
			_resolution_cb, &resolution_list);

		g_print("\tCommand >> ");

		err = scanf("%d", &idx);
		flush_stdin();
		if (resolution_list.count > idx && idx >= 0) {
			g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
				resolution_list.width[idx], resolution_list.height[idx]);

			result = camera_set_preview_resolution(hcamcorder->camera,
				resolution_list.width[idx], resolution_list.height[idx]);
		} else {
			g_print("\tInvalid command [%d]\n", idx);
			result = -1;
		}
		resolution_list.count = 0;
		if (result == CAMERA_ERROR_NONE)
			g_print("\tPASS\n");
		else
			g_print("\tFAIL\n");
		break;
	case '1': /* Setting > Capture Resolution setting */
		g_print("\t* Select the capture resolution!\n");
		resolution_list.count = 0;

		camera_foreach_supported_capture_resolution(hcamcorder->camera,
			_resolution_cb, &resolution_list);

		g_print("\tCommand > ");

		err = scanf("%d", &idx);
		flush_stdin();
		if (resolution_list.count > idx && idx >= 0) {
			g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
				resolution_list.width[idx], resolution_list.height[idx]);

			result = camera_set_capture_resolution(hcamcorder->camera,
				resolution_list.width[idx], resolution_list.height[idx]);
		} else {
			g_print("\tInvalid command [%d]\n", idx);
			result = -1;
		}
		resolution_list.count = 0;
		if (result == CAMERA_ERROR_NONE)
			g_print("\tPASS\n");
		else
			g_print("\tFAIL\n");
		break;
	case '2': /* Setting > Digital zoom level */
		camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
		if (min > max) {
			g_print("\tDigital Zoom Not supported\n");
		} else {
			g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
			err = scanf("%d", &idx);
			flush_stdin();
			bret = camera_attr_set_zoom(hcamcorder->camera, idx);
		}
		break;
	case '3': /* Setting > AF mode */
		g_print("\tAuto Focus [1:Start, 2:Stop] > ");
		err = scanf("%d", &idx);
		flush_stdin();
		switch (idx) {
		case 1:
			camera_start_focusing(hcamcorder->camera, 0);
			break;
		case 2:
			camera_cancel_focusing(hcamcorder->camera);
			break;
		default:
			g_print("\tInvalid command [%d]\n", idx);
			break;
		}
		break;
	case '4': /* Setting > AF scan range */
		g_print("\t* AF scan range !\n");
		camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
		g_print("\tCommand > ");
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
		break;
	case '5': /* Setting > Exposure mode */
		g_print("* Exposure mode!\n");
		camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
		g_print("\n Select  Exposure mode \n");
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
		break;

	case '6': /* Setting > Exposure value */
		camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
		if (min >= max)
			g_print("Not supported !! \n");
		else {
			g_print("\n Select  Exposure mode min%d -max %d\n", min, max);
			err = scanf("%d", &idx);
			flush_stdin();
			bret = camera_attr_set_exposure(hcamcorder->camera, idx);
		}
		break;
	case '7': /* Setting > F number */
		g_print("Not supported !! \n");
		break;
	case '8': /* Setting > Display reuse hint */
		{
			bool reuse_hint = false;

			err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
			if (err != CAMERA_ERROR_NONE) {
				g_print("failed to get display reuse hint 0x%x\n", err);
				break;
			}

			g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
			reuse_hint = !reuse_hint;
			err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
			g_print("set display reuse hint result : 0x%x\n", err);
		}
		break;
	case '9': /* Setting > Manual focus */
		g_print("*Manual focus !\n");
		camera_attr_get_focus_level_range(hcamcorder->camera, &min, &max);
		if (min > max) {
			g_print("\n\tManual focus is NOT SUPPORTED\n");
			break;
		}
		camera_attr_get_focus_level(hcamcorder->camera, &idx);
		g_print("\tCurrent focus level (%d)\n", idx);
		g_print("\tSelect focus level min(%d) - max(%d) > ", min, max);
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_focus_level(hcamcorder->camera, idx);
		idx = -1;
		if (bret == CAMERA_ERROR_NONE) {
			bret = camera_attr_get_focus_level(hcamcorder->camera, &idx);
			g_print("\tfocus level[%d] after set\n", idx);
		} else {
			g_print("\tset focus level failed[0x%x]\n", bret);
		}
		break;
	case 'i': /* Setting > ISO */
		g_print("*ISO !\n");
		camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
		err = scanf("%d", &idx);
		flush_stdin();
		bret =  camera_attr_set_iso(hcamcorder->camera, idx);
		break;
	case 'r': /* Setting > Rotate camera input when recording */
		g_print("*Rotate camera input\n");
		camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
		err = scanf("%d", &idx);
		flush_stdin();
		CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
		bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
		CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
		break;
	case 'f': /* Setting > Flip camera input */
		g_print("*Flip camera input\n");
		camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
		err = scanf("%d", &idx);
		flush_stdin();
		CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
		bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
		CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
		break;
	case 'j': /* Setting > Jpeg quality */
		g_print("*Jpeg quality !\n");
		g_print("\n Select  Jpeg quality \n");
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
		break;
	case 'p': /* Setting > Picture format */
		g_print("* Picture format!\n");
		camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
		err = scanf("%d", &idx);
		flush_stdin();
		CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
		bret = camera_set_preview_format(hcamcorder->camera, idx);
		CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
		break;
	case 'E': /* Setting > EXIF orientation */
		g_print("* EXIF Orientation\n");
		g_print("\t 1. TOP_LEFT\n");
		g_print("\t 2. TOP_RIGHT(flipped)\n");
		g_print("\t 3. BOTTOM_RIGHT\n");
		g_print("\t 4. BOTTOM_LEFT(flipped)\n");
		g_print("\t 5. LEFT_TOP(flipped)\n");
		g_print("\t 6. RIGHT_TOP\n");
		g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
		g_print("\t 8. LEFT_BOTTOM\n");
		err = scanf("%d", &idx);
		flush_stdin();
		if (idx < 1 || idx > 8)
			g_print("Wrong INPUT[%d]!! \n", idx);
		else
			camera_attr_set_tag_orientation(hcamcorder->camera, idx);
		break;
	case 'F': /* Setting > Get Facing direction */
		g_print("* Get facing direction of camera module\n");
		err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
		if (CAMERA_ERROR_NONE == err)
			g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
		else
			g_print("* Error : %d\n", err);
		break;
	case 's': /* Setting > Set extra preview stream format */
		g_print("* Set extra preview stream format\n");

		g_print("\tstream_id,pixel format[NV12:0,H264:15,VP8:18],width,height,fps : ");
		err = scanf("%d,%d,%d,%d,%d", &stream_id, &pixel_format, &width, &height, &fps);
		flush_stdin();

		err = camera_set_extra_preview_stream_format(hcamcorder->camera,
			stream_id, pixel_format, width, height, fps);
		if (err != CAMERA_ERROR_NONE) {
			g_print("* Set Error : 0x%x\n", err);
			break;
		}

		pixel_format = width = height = fps = -1;

		err = camera_get_extra_preview_stream_format(hcamcorder->camera,
			stream_id, &pixel_format, &width, &height, &fps);
		if (err != CAMERA_ERROR_NONE) {
			g_print("* Get Error : 0x%x\n", err);
			break;
		}

		g_print("\tGet stream_id[%d],pixel format[%d],res[%dx%d],fps[%d]\n",
			stream_id, pixel_format, width, height, fps);
		break;
	case 'B': /* Setting > Set extra preview bitrate */
		g_print("* Set extra preview bitrate\n");
		g_print("\tstream_id : ");
		err = scanf("%d", &stream_id);
		flush_stdin();

		err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
		if (err != CAMERA_ERROR_NONE) {
			g_print("\tFailed to get bitrate for stream_id[%d]\n", stream_id);
			break;
		}

		g_print("\tCurrent bitrate[%d]bps for stream_id[%d]\n", bitrate, stream_id);

		g_print("\tSet bitrate(bps) : ");
		err = scanf("%d", &bitrate);
		flush_stdin();

		err = camera_attr_set_extra_preview_bitrate(hcamcorder->camera, stream_id, bitrate);
		if (err != CAMERA_ERROR_NONE) {
			g_print("* Set Error : 0x%x\n", err);
			break;
		}

		bitrate = -1;

		err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
		if (err != CAMERA_ERROR_NONE) {
			g_print("* Get Error : 0x%x\n", err);
			break;
		}

		g_print("\tResult bitrate[%d]bps for stream_id[%d]\n", bitrate, stream_id);
		break;
	case 'V': /* Setting > Set extra preview GOP interval */
		g_print("* Set extra preview GOP interval\n");
		g_print("\tstream_id : ");
		err = scanf("%d", &stream_id);
		flush_stdin();

		err = camera_attr_get_extra_preview_gop_interval(hcamcorder->camera, stream_id, &interval);
		if (err != CAMERA_ERROR_NONE) {
			g_print("\tFailed to get GOP interval for stream_id[%d]\n", stream_id);
			break;
		}

		g_print("\tCurrent GOP interval[%d]bps for stream_id[%d]\n", interval, stream_id);

		g_print("\tSet GOP interval(ms) : ");
		err = scanf("%d", &interval);
		flush_stdin();

		err = camera_attr_set_extra_preview_gop_interval(hcamcorder->camera, stream_id, interval);
		if (err != CAMERA_ERROR_NONE) {
			g_print("* Set Error : 0x%x\n", err);
			break;
		}

		interval = -1;

		err = camera_attr_get_extra_preview_gop_interval(hcamcorder->camera, stream_id, &interval);
		if (err != CAMERA_ERROR_NONE) {
			g_print("* Get Error : 0x%x\n", err);
			break;
		}

		g_print("\tResult GOP interval[%d]bps for stream_id[%d]\n", interval, stream_id);
		break;
	case 'D': /* Setting > Request codec config */
		g_print("* Request codec config\n");

		err = camera_request_codec_config(hcamcorder->camera);
		if (err != CAMERA_ERROR_NONE) {
			g_print("\tFailed to request codec config\n");
			break;
		}
		break;
		/* Display / Filter setting */
	case 'v': /* Display visible */
		g_print("* Display visible setting !\n");
		g_print("\n Select Display visible \n");
		for (i = 0 ; i < 2 ; i++)
			g_print("\t %d. %s\n", i, visible_mode[i]);
		err = scanf("%d", &idx);
		flush_stdin();
		if (idx == 0 || idx == 1)
			bret = camera_set_display_visible(hcamcorder->camera, idx);
		else
			g_print("invalid input %d", idx);
		break;
	case 'o': /* Setting > Display Mode */
		g_print("* Display mode!\n");
		for (i = 0 ; i < 5 ; i++)
			g_print("%d. %s\n", i, display_mode[i]);
		err = scanf("%d", &idx);
		flush_stdin();
		bret =  camera_set_display_mode(hcamcorder->camera, idx);
		break;
	case 'y': /* Setting > Rotate Display */
		g_print("\n Select Rotate mode\n");
		g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
		err = scanf("%d", &idx);
		flush_stdin();
		CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
		bret = camera_set_display_rotation(hcamcorder->camera, idx);
		CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
		break;
	case 'Y': /* Setting > Flip Display */
		g_print("\n Select Rotate mode\n");
		g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_set_display_flip(hcamcorder->camera, idx);
		break;
	case 'g': /* Setting > Brightness */
		g_print("*Brightness !\n");
		camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
		g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_brightness(hcamcorder->camera, idx);
		break;
	case 'c': /* Setting > Contrast */
		g_print("*Contrast !\n");
		camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
		g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_contrast(hcamcorder->camera, idx);
		break;
	case 'h': /* Setting > Hue */
		g_print("*Hue !\n");
		camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
		if (max >= min) {
			g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
			err = scanf("%d", &idx);
			flush_stdin();
			bret = camera_attr_set_hue(hcamcorder->camera, idx);
		} else {
			g_print("\n Hue is not supported (%d,%d)\n", min, max);
		}
		break;
	case 'w': /* Setting > White balance */
		g_print("*White balance !\n");
		g_print("\n Select White balance \n");
		camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
		break;
	case 't': /* Setting > Color tone */
		g_print("*Color tone !\n");
		camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
		g_print("\n Select Color tone \n");
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_effect(hcamcorder->camera, idx);
		break;
	case 'd': /* Setting > WDR */
		g_print("*WDR !\n");
		g_print("\n Select WDR Mode \n");
		for (i = 0 ; i < 2 ; i++)
			g_print("\t %d. %s\n", i+1, wdr_mode[i]);
		err = scanf("%d", &idx);
		flush_stdin();
		if (idx == 1)
			bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
		else if (idx == 2)
			bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
		break;
	case 'e': /* Setting > EV program mode */
		g_print("* EV program mode!\n");
		camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
		g_print("\n Select EV program mode \n");
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
		break;
	case 'R': /* Setting > Display ROI area */
		g_print("* Set display roi area. Select x y width height \n");
		err = scanf("%d %d %d %d", &x, &y, &width, &height);
		flush_stdin();
		camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
		err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
		if (CAMERA_ERROR_NONE != err)
			g_print("* Error : %d\n", err);

		err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
		if (CAMERA_ERROR_NONE == err)
			g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
		else
			g_print("* Error : %d\n", err);
		break;

		/* ext. setting */
	case 'z': /* Setting > Strobe setting */
		g_print("*Strobe Mode\n");
		camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
		g_print("\n Select Strobe Mode \n");
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
		break;
	case 'S': /* Setting > flash state */
		g_print("*flash state\n");
		err = camera_get_flash_state(camera_device, (camera_flash_state_e *)&idx);
		if (CAMERA_ERROR_NONE == err)
			g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
		else
			g_print("* Error : %d\n", err);
		break;
	case 'G': /* Setting > flash brightness */
		g_print("*Flash brightness !\n");
		camera_attr_get_flash_brightness_range(hcamcorder->camera, &min, &max);
		g_print("\n Select flash brightness min(%d) - max(%d) > ", min, max);
		err = scanf("%d", &idx);
		flush_stdin();
		bret = camera_attr_set_flash_brightness(hcamcorder->camera, idx);
		break;
	case 'x': /* Setting > Capture mode ,Muitishot? */
		g_print("*Select Capture mode!\n");
		g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
		err = scanf("%d", &idx);
		flush_stdin();

		switch (idx) {
		case 1:
			g_print("stillshot mode selected and capture callback is set!!!!\n");
			hcamcorder->is_multishot = FALSE;
			camera_attr_set_hdr_mode(hcamcorder->camera, 0);
			break;
		case 2:
			g_print("HDR Capture mode selected\n");
			hcamcorder->is_multishot = FALSE;
			g_print("\nSelect HDR capture mode\n");
			for (i = 0 ; i < 3 ; i++)
				g_print("\t %d. %s\n", i, hdr_mode[i]);
			err = scanf("%d", &idx);
			flush_stdin();
			if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
				bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
			else
				g_print("invalid input %d\n", idx);
			break;
		default:
			g_print("Wrong input, select again!!\n");
			break;
		}
		break;
	case 'l': /* Setting > Face detection setting */
		if (camera_is_supported_face_detection(hcamcorder->camera)) {
			g_print("* Face detect mode !\n");
			for (i = 0 ; i < 2 ; i++)
				g_print("\t %d. %s \n", i, detection_mode[i]);
			err = scanf("%d", &idx);
			flush_stdin();
			if (idx == 0)
				bret = camera_stop_face_detection(hcamcorder->camera);
			else if (idx == 1)
				bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
			else
				g_print("\n invalid input [%d]\n\n", idx);
		} else {
			g_print("face detection_not supported");
		}
		break;
	case 'k': /* Setting > Anti-handshake */
		g_print("*Anti-handshake !\n");
		g_print("\n Select Anti-handshake mode \n");
		for (i = 0; i < 2; i++)
			g_print("\t %d. %s\n", i, ahs_mode[i]);
		err = scanf("%d", &idx);
		flush_stdin();
		if (idx == 0 || idx == 1)
			bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
		else
			g_print("invalid input %d\n", idx);
		break;
	case 'K': /* Setting > Video-stabilization */
		g_print("*Video-stabilization !\n");
		g_print("\n Select Video-stabilization mode \n");
		for (i = 0 ; i < 2 ; i++)
			g_print("\t %d. %s\n", i, vs_mode[i]);
		err = scanf("%d", &idx);
		flush_stdin();
		if (idx < 0 || idx > 1) {
			g_print("invalid input %d\n", idx);
			break;
		}

		if (idx == 1) {
			g_print("\n Restart preview with NV12 and 720p resolution\n");
			err = camera_stop_preview(hcamcorder->camera);
			g_print("stop preview result 0x%x\n", err);
			camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
			camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
		}

		bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);

		if (idx == 1) {
			err = camera_start_preview(hcamcorder->camera);
			if (err != CAMERA_ERROR_NONE)
				g_print("\n Restart FAILED! 0x%x\n", err);
		}
		break;
	case 'u': /* Touch AF area */
		g_print("* Touch AF area !\n");
		g_print("\n Input x,y,width,height \n");
		err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
		flush_stdin();
		err = camera_attr_set_af_area(hcamcorder->camera, width, height);
		if (err != 0)
			g_print("Failed to set touch AF area.(%x)\n", err);
		else
			g_print("Succeed to set touch AF area.\n");
		break;
	case 'n': /* file path */
		g_print("* File path !\n");
		g_print("\n Input file path to save captured data(string) : ");
		if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin))
			g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
		else
			g_print("\nset file path failed\n");
		break;
	case 'm': /* media bridge */
		g_print("* Media Bridge !\n");
		g_print("\tUnset[0] / Set[Others] :");
		err = scanf("%d", &set_bridge);
		flush_stdin();
		if (set_bridge) {
			__release_media_bridge();

			err = media_bridge_create(&bridge);
			err |= media_bridge_set_source(bridge, MEDIA_BRIDGE_MODULE_CAMERA, hcamcorder->camera);
		} else {
			__release_media_bridge();
		}
		g_print("\tresult[0x%x]\n\n", err);
		break;
	case 'b': /* back */
		hcamcorder->menu_state = MENU_STATE_MAIN;
		break;
	default:
		g_print("\t Invalid input \n");
		break;
	}

	g_print("\t bret : 0x%x \n", bret);
}


static void device_state_menu(gchar buf)
{
	int ret = 0;
	camera_device_e device = CAMERA_DEVICE_CAMERA0;
	camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;

	switch (buf) {
	case '1': /* Get device state */
		while (1) {
			g_print("\n\tEnter Camera Index[0~9]: ");

			ret = scanf("%d", (int *)&device);
			flush_stdin();

			if (ret == EOF) {
				g_print("\n\t!!!read input error!!!\n");
				return;
			}

			if (device < CAMERA_DEVICE_CAMERA0 ||
				device > CAMERA_DEVICE_CAMERA9) {
				g_print("\n\tinvalid input:[%d], try again...\n", device);
				continue;
			}

			ret = camera_get_device_state(device, &device_state);
			g_print("\n\tDevice[%d] state[%d], ret[0x%x]",
				device, device_state, ret);
			break;
		}
		break;
	case '2': /* Add device state changed callback */
		ret = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
			NULL, &g_camera_device_state_changed_cb_id);
		g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
		break;
	case '3': /* Remove device state changed callback */
		if (g_camera_device_state_changed_cb_id > 0) {
			ret = camera_remove_device_state_changed_cb(g_camera_device_state_changed_cb_id);
			g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
			g_camera_device_state_changed_cb_id = 0;
		} else {
			g_print("\n\tinvalid cb id[%d]\n", g_camera_device_state_changed_cb_id);
		}
		break;
	case 'b': /* back */
		hcamcorder->menu_state = MENU_STATE_INIT;
		break;
	default:
		g_print("\n\tinvalid input[%c]\n", buf);
		break;
	}
}

static void device_manager_menu(gchar buf)
{
	int ret = 0;

	switch (buf) {
	case '1': /* Initialize device manager */
		ret = camera_device_manager_initialize(&g_device_manager);
		g_print("\n\tDevice manager[%p] initialize result[0x%x]\n",
			g_device_manager, ret);
		break;
	case '2': /* Foreach supported camera device */
		ret = camera_device_manager_foreach_supported_device(g_device_manager, _camera_supported_device_cb, NULL);
		if (ret != CAMERA_ERROR_NONE) {
			g_print("\n\tGet device list failed[0x%x]\n", ret);
			return;
		}
		break;
	case '3': /* Add device connection changed callback */
		ret = camera_device_manager_add_device_connection_changed_cb(g_device_manager,
			_camera_device_connection_changed_cb, NULL, &g_camera_device_connection_changed_cb_id);
		g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
		break;
	case '4': /* Remove device connection changed callback */
		if (g_camera_device_connection_changed_cb_id > 0) {
			ret = camera_device_manager_remove_device_connection_changed_cb(g_device_manager,
				g_camera_device_connection_changed_cb_id);
			g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
			g_camera_device_connection_changed_cb_id = 0;
		} else {
			g_print("\n\tinvalid cb id[%d]\n", g_camera_device_connection_changed_cb_id);
		}
		break;
	case '9': /* Deinitialize device manager */
		ret = camera_device_manager_deinitialize(g_device_manager);
		g_print("\n\tDevice manager[%p] deinitialize result[0x%x]\n",
			g_device_manager, ret);
		g_device_manager = NULL;
		break;
	case 'b': /* back */
		hcamcorder->menu_state = MENU_STATE_INIT;
		break;
	default:
		g_print("\n\tinvalid input[%c]\n", buf);
		break;
	}
}


/**
 * This function is to execute command.
 *
 * @param   channel [in]    1st parameter
 *
 * @return  This function returns TRUE/FALSE
 * @remark
 * @see
 */
gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
{
	gchar *buf = NULL;
	gsize read_size;
	GError *g_error = NULL;

	g_print("\n\tENTER\n");

	g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
	if (g_error) {
		g_print("\n\tg_io_channel_read_chars error\n");
		g_error_free(g_error);
		g_error = NULL;
	}

	if (buf) {
		g_strstrip(buf);

		g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
		switch (hcamcorder->menu_state) {
		case MENU_STATE_INIT:
			mode_change(buf[0]);
			break;
		case MENU_STATE_MAIN:
			main_menu(buf[0]);
			break;
		case MENU_STATE_MAIN_SETTING:
			setting_menu(buf[0]);
			break;
		case MENU_STATE_DEVICE_STATE:
			device_state_menu(buf[0]);
			break;
		case MENU_STATE_DEVICE_MANAGER:
			device_manager_menu(buf[0]);
			break;
		default:
			break;
		}

		g_free(buf);
		buf = NULL;

		print_menu();
	} else {
		g_print("\n\tNo read input\n");
	}

	return TRUE;
}


cam_handle_t *init_handle()
{
	hcamcorder = (cam_handle_t *)g_malloc0(sizeof(cam_handle_t));

	hcamcorder->is_multishot =  FALSE;
	hcamcorder->stillshot_count = 0;
	hcamcorder->multishot_count = 0;
	snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
	hcamcorder->menu_state = MENU_STATE_INIT;

	return hcamcorder;
}


static void __enable_extra_preview_and_callback(camera_h camera)
{
	int err = 0;
	int stream_id = 0;
	int width = 0;
	int height = 0;
	int fps = 0;
	int pixel_format = 0;
	int device = 0;

	g_print("\n\t- Format list");
	g_print("\n\t0:NV12, 1:NV12T, 2:NV16, 3:NV21, 4:YUYV, 5:UYVY, 6:422P, 7:I420, 8:YV12, 9:RGB565, 10:RGB888");
	g_print("\n\t11:RGBA, 12:ARGB, 13:ENCODED(JPEG), 14:INTERLEAVED_JPEG_UYVY, 15:H264, 16:INVZ, 17:MJPEG, 18:VP8, 19:VP9");
	g_print("\n\tSet extra preview format[stream_id width height fps format] : ");

	err = scanf("%d %d %d %d %d", &stream_id, &width, &height, &fps, &pixel_format);
	flush_stdin();

	err = camera_set_extra_preview_stream_format(camera, stream_id, pixel_format, width, height, fps);
	if (err != CAMERA_ERROR_NONE) {
		g_print("\n\tcamera_set_extra_preview_stream_format failed[0x%x]\n", err);
		return;
	}

	err = camera_set_extra_preview_cb(camera, _camera_extra_preview_cb, camera);
	if (err != CAMERA_ERROR_NONE) {
		g_print("\n\tcamera_set_extra_preview_cb failed[0x%x]\n", err);
		return;
	}

	g_print("\n\t## for MM_CAMCORDER_EXTRA_PREVIEW_MODE_PIPELINE_ELEMENT ##\n");
	g_print("\n\tSet device for extra preview[0 ~ 9] : ");
	err = scanf("%d", &device);
	flush_stdin();

	err = camera_set_extra_preview_device(hcamcorder->camera, 0, device);
	g_print("\n\tcamera_set_extra_preview_device(device:%d) 0x%x\n", device, err);

	g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
	err = scanf("%d", &g_camera_extra_preview_cb_dump);
	flush_stdin();
}


/**
 * This function is to change camcorder mode.
 *
 * @param   buf    [in]    user input
 *
 * @return  This function returns TRUE/FALSE
 * @remark
 * @see     other functions
 */
static gboolean mode_change(gchar buf)
{
	int err = 0;
	int camera_type = 0;
	int enable_extra_preview = 0;

	switch (buf) {
	case '1':
		while (1) {
			g_print("\n\tEnter the Camera Type[0:Local, 1:Network] : ");
			err = scanf("%d", &camera_type);
			flush_stdin();
			if (err == EOF) {
				g_print("\t!!!read input error!!!\n");
				continue;
			}

			if (camera_type != 0 && camera_type != 1) {
				g_print("\t Invalid camera type(%d)\n", camera_type);
				continue;
			}

			g_print("\n\tEnter the Camera Device[0 ~ 9] : ");
			err = scanf("%d", (int *)&camera_device);
			flush_stdin();
			if (err == EOF) {
				g_print("\t!!!read input error!!!\n");
				continue;
			}

			if (camera_device < 0 || camera_device > 9) {
				g_print("\t Invalid camera device(%d)\n", camera_device);
				continue;
			}

			hcamcorder->type = camera_device;
			break;
		}
		break;
	case '2':
		hcamcorder->menu_state = MENU_STATE_DEVICE_STATE;
		return TRUE;
	case '3':
		hcamcorder->menu_state = MENU_STATE_DEVICE_MANAGER;
		return TRUE;
	case 'q':
		g_print("\t Quit Camcorder Testsuite!!\n");
		quit_test();
		return FALSE;
	default:
		g_print("\t Invalid media type(%c)\n", buf);
		return FALSE;
	}

	g_print("\n[camcorder_create - type %d, device %d]\n", camera_type, camera_device);

	gettimeofday(&previous_time, NULL);

	if (camera_type)
		err = camera_create_network(camera_device, &hcamcorder->camera);
	else
		err = camera_create(camera_device, &hcamcorder->camera);

	if (err != 0) {
		g_print("\n\tmmcamcorder_create = 0x%x\n", err);
		return FALSE;
	}

	set_display(hcamcorder);

	camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
	camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
	camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
	camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
	camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
	/*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
	/*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
	/*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/

	if (camera_is_supported_extra_preview(hcamcorder->camera)) {
		g_print("\n\tEnable extra preview callback - NO[0], YES[Others] : ");
		err = scanf("%d", (int *)&enable_extra_preview);
		flush_stdin();

		if (enable_extra_preview)
			__enable_extra_preview_and_callback(hcamcorder->camera);
	}

	camera_start_preview(hcamcorder->camera);

	gettimeofday(&current_time, NULL);
	timersub(&current_time, &previous_time, &result_time);

	g_print("\n\tCamera Starting Time  : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);

	hcamcorder->menu_state = MENU_STATE_MAIN;

	return TRUE;
}
/*EOF*/