2 * mm_streamrecorder_testsuite
4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyuntae Kim <ht1211.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 /*=======================================================================================
24 =======================================================================================*/
30 #include "../src/include/mm_streamrecorder.h"
31 #include "../src/include/mm_streamrecorder_internal.h"
32 #include "../src/include/mm_streamrecorder_util.h"
33 #include "../src/include/mm_streamrecorder_attribute.h"
34 #include <gst/video/colorbalance.h>
36 /*-----------------------------------------------------------------------
37 | GLOBAL VARIABLE DEFINITIONS: |
38 -----------------------------------------------------------------------*/
39 #define EXPORT_API __attribute__((__visibility__("default")))
41 #define PACKAGE "mm_streamrecorder_testsuite"
44 GIOChannel *stdin_channel;
51 static int audio_stream_cb_cnt;
52 static int video_stream_cb_cnt;
53 static GTimer *timer = NULL;
59 STREAMRECORDER_CREATED,
60 STREAMRECORDER_STARTED,
61 STREAMRECORDER_COMMITED
64 void streamrecorder_set_state(int new_state)
70 int streamrecorder_get_state()
77 /*-----------------------------------------------------------------------
78 | GLOBAL CONSTANT DEFINITIONS: |
79 -----------------------------------------------------------------------*/
82 /*-----------------------------------------------------------------------
83 | IMPORTED VARIABLE DECLARATIONS: |
84 -----------------------------------------------------------------------*/
87 /*-----------------------------------------------------------------------
88 | IMPORTED FUNCTION DECLARATIONS: |
89 -----------------------------------------------------------------------*/
92 /*-----------------------------------------------------------------------
94 -----------------------------------------------------------------------*/
95 #define test_ffmux_mp4
97 #define DISPLAY_X_0 0 /* for direct FB */
98 #define DISPLAY_Y_0 0 /* for direct FB */
100 #define SRC_VIDEO_FRAME_RATE_15 15 /* video input frame rate */
101 #define SRC_VIDEO_FRAME_RATE_30 30 /* video input frame rate */
103 #define STILL_CAPTURE_FILE_PATH_NAME "/opt/StillshotCapture"
104 #define MULTI_CAPTURE_FILE_PATH_NAME "/opt/MultishotCapture"
105 #define TARGET_FILENAME_PATH "/opt/"
106 #define CAPTURE_FILENAME_LEN 256
108 #define AUDIO_SOURCE_SAMPLERATE_AAC 44100
109 #define AUDIO_SOURCE_SAMPLERATE_AMR 8000
110 #define AUDIO_SOURCE_FORMAT MM_STREAMRECORDER_AUDIO_FORMAT_PCM_S16_LE
111 #define AUDIO_SOURCE_CHANNEL_AAC 2
112 #define AUDIO_SOURCE_CHANNEL_AMR 1
113 #define VIDEO_ENCODE_BITRATE 40000000 /* bps */
115 * D E B U G M E S S A G E
117 #define MMF_DEBUG "** (mmstreamrecorder testsuite) DEBUG: "
118 #define MMF_ERR "** (mmstreamrecorder testsuite) ERROR: "
119 #define MMF_INFO "** (mmstreamrecorder testsuite) INFO: "
120 #define MMF_WARN "** (mmstreamrecorder testsuite) WARNING: "
121 #define MMF_TIME "** (mmstreamrecorder testsuite) TIME: "
123 #define CHECK_MM_ERROR(expr) \
127 if (ret != MM_ERROR_NONE) {\
128 printf("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
133 #define time_msg_t(fmt, arg...) \
135 fprintf(stderr, "\x1b[44m\x1b[37m"MMF_TIME"[%s:%05d] " fmt , __func__, __LINE__, ##arg); \
136 fprintf(stderr, "\x1b[0m\n"); \
139 #define debug_msg_t(fmt, arg...)\
141 fprintf(stderr, MMF_DEBUG"[%s:%05d] " fmt "\n", __func__, __LINE__, ##arg); \
144 #define err_msg_t(fmt, arg...) \
146 fprintf(stderr, MMF_ERR"[%s:%05d] " fmt "\n", __func__, __LINE__, ##arg); \
149 #define info_msg_t(fmt, arg...) \
151 fprintf(stderr, MMF_INFO"[%s:%05d] " fmt "\n", __func__, __LINE__, ##arg); \
154 #define warn_msg_t(fmt, arg...) \
156 fprintf(stderr, MMF_WARN"[%s:%05d] " fmt "\n", __func__, __LINE__, ##arg); \
160 #define SAFE_FREE(x) if (x) {g_free(x); x = NULL; }
167 /* temporary buffer */
168 char buffer[460800] = {0x0,};
172 * Enumerations for command
174 #define SENSOR_FLIP_NUM 3
175 #define SENSOR_PROGRAM_MODE_NUM 15
176 #define SENSOR_FOCUS_NUM 6
177 #define SENSOR_INPUT_ROTATION 4
178 #define SENSOR_AF_SCAN_NUM 4
179 #define SENSOR_ISO_NUM 8
180 #define SENSOR_EXPOSURE_NUM 9
181 #define SENSOR_IMAGE_FORMAT 9
184 /*-----------------------------------------------------------------------
185 | LOCAL CONSTANT DEFINITIONS: |
186 -----------------------------------------------------------------------*/
188 MODE_VIDEO_CAPTURE, /* recording and image capture mode */
189 MODE_AUDIO, /* audio recording*/
199 /*-----------------------------------------------------------------------
200 | LOCAL DATA TYPE DEFINITIONS: |
201 -----------------------------------------------------------------------*/
202 typedef struct _streamrecorder_handle {
203 MMHandleType streamrecorder;
204 int mode; /* image(capture)/video(recording) mode */
205 bool isMultishot; /* flag for multishot mode */
206 int stillshot_count; /* total stillshot count */
207 int multishot_count; /* total multishot count */
208 const char *stillshot_filename; /* stored filename of stillshot */
209 const char *multishot_filename; /* stored filename of multishot */
213 unsigned long long elapsed_time;
214 } streamrecorder_handle_t;
216 typedef struct _str_xypair {
223 /*---------------------------------------------------------------------------
224 | LOCAL VARIABLE DEFINITIONS: |
225 ---------------------------------------------------------------------------*/
226 static streamrecorder_handle_t *hstreamrecorder ;
228 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
240 const char *face_zoom_mode[] = {
245 const char *display_mode[] = {
247 "Primary Video ON and Secondary Video Full Screen",
248 "Primary Video OFF and Secondary Video Full Screen",
251 const char *output_mode[] = {
253 "Original Size mode",
255 "Cropped Full Screen mode",
259 const char *rotate_mode[] = {
266 const char* strobe_mode[] = {
270 "Strobe RedEyeReduction",
272 "Strobe FrontCurtain",
273 "Strobe RearCurtain",
277 const char *detection_mode[2] = {
278 "Face Detection OFF",
282 const char *wdr_mode[] = {
288 const char *hdr_mode[] = {
291 "HDR ON and Original",
294 const char *ahs_mode[] = {
295 "Anti-handshake OFF",
297 "Anti-handshake AUTO",
298 "Anti-handshake MOVIE",
301 const char *vs_mode[] = {
302 "Video-stabilization OFF",
303 "Video-stabilization ON",
306 const char *visible_mode[] = {
312 /*---------------------------------------------------------------------------
313 | LOCAL FUNCTION PROTOTYPES: |
314 ---------------------------------------------------------------------------*/
315 static void print_menu();
317 static gboolean cmd_input(GIOChannel *channel);
318 static gboolean init(int type);
319 static gboolean mode_change();
320 int streamrecordertest_set_attr_int(const char* attr_subcategory, int value);
323 static inline void flush_stdin()
326 while ((ch = getchar()) != EOF && ch != '\n');
330 static gboolean test_idle_capture_start()
334 streamrecordertest_set_attr_int(MMSTR_VIDEO_SOURCE_FORMAT, MM_STREAMRECORDER_INPUT_FORMAT_NV12);
335 streamrecordertest_set_attr_int(MMSTR_VIDEO_ENCODER, MM_VIDEO_CODEC_H264);
336 streamrecordertest_set_attr_int(MMSTR_AUDIO_SOURCE_FORMAT, MM_STREAMRECORDER_AUDIO_FORMAT_PCM_U8);
337 streamrecordertest_set_attr_int(MMSTR_AUDIO_ENCODER, MM_AUDIO_CODEC_AAC);
339 g_timer_reset(timer);
340 err = mm_streamrecorder_record(hstreamrecorder->streamrecorder);
346 int streamrecordertest_set_attr_int(const char * attr_subcategory, int value)
348 char * err_attr_name = NULL;
351 if (hstreamrecorder) {
352 if (hstreamrecorder->streamrecorder) {
353 debug_msg_t("streamrecordertest_set_attr_int(%s, %d)", attr_subcategory, value);
355 err = mm_streamrecorder_set_attributes(hstreamrecorder->streamrecorder, &err_attr_name, attr_subcategory, value, NULL);
356 if (err != MM_ERROR_NONE) {
357 err_msg_t("streamrecordertest_set_attr_int : Error(%s:%x)!!!!!!!", err_attr_name, err);
358 SAFE_FREE(err_attr_name);
365 debug_msg_t("streamrecordertest_set_attr_int(!hstreamrecorder->streamrecorder)");
368 debug_msg_t("streamrecordertest_set_attr_int(!hstreamrecorder)");
373 int streamrecordertest_set_attr_string(const char * attr_subcategory, char *value)
375 char * err_attr_name = NULL;
378 err_msg_t("streamrecordertest_set_attr_string : value is null !");
381 if (hstreamrecorder) {
382 if (hstreamrecorder->streamrecorder) {
383 debug_msg_t("streamrecordertest_set_attr_string(%s, %s)", attr_subcategory, value);
385 err = mm_streamrecorder_set_attributes(hstreamrecorder->streamrecorder, &err_attr_name, attr_subcategory, value, NULL);
386 if (err != MM_ERROR_NONE) {
387 err_msg_t("streamrecordertest_set_attr_string : Error(%s:%x)!!!!!!!", err_attr_name, err);
388 SAFE_FREE(err_attr_name);
395 debug_msg_t("streamrecordertest_set_attr_string(!hstreamrecorder->streamrecorder)");
398 debug_msg_t("streamrecordertest_set_attr_string(!hstreamrecorder)");
403 int streamrecordertest_set_attr_xypair(str_xypair_t pair)
405 char * err_attr_name = NULL;
408 if (hstreamrecorder) {
409 if (hstreamrecorder->streamrecorder) {
410 debug_msg_t("streamrecordertest_set_attr_xypair((%s, %s), (%d, %d))", pair.attr_subcat_x, pair.attr_subcat_y, pair.x, pair.y);
412 err = mm_streamrecorder_set_attributes(hstreamrecorder->streamrecorder, &err_attr_name,
413 pair.attr_subcat_x, pair.x,
414 pair.attr_subcat_y, pair.y,
417 err_msg_t("streamrecordertest_set_attr_xypair : Error(%s:%x)!!", err_attr_name, err);
418 SAFE_FREE(err_attr_name);
425 debug_msg_t("streamrecordertest_set_attr_xypair(!hstreamrecorder->streamrecorder)");
428 debug_msg_t("streamrecordertest_set_attr_xypair(!hstreamrecorder)");
432 int streamrecordertest_get_attr_valid_intarray(const char * attr_name, int ** array, int *count)
434 MMStreamRecorderAttrsInfo info;
435 int err = MM_ERROR_NONE;
437 if (hstreamrecorder) {
438 if (hstreamrecorder->streamrecorder) {
439 debug_msg_t("streamrecordertest_get_attr_valid_intarray(%s)", attr_name);
441 err = mm_streamrecorder_get_attribute_info(hstreamrecorder->streamrecorder, attr_name, &info);
442 if (err != MM_ERROR_NONE) {
443 err_msg_t("streamrecordertest_get_attr_valid_intarray : Error(%x)!!", err);
446 if (info.type == MM_STR_REC_ATTRS_TYPE_INT) {
447 if (info.validity_type == MM_STR_REC_ATTRS_VALID_TYPE_INT_ARRAY) {
448 *array = info.int_array.array;
449 *count = info.int_array.count;
450 debug_msg_t("INT ARRAY - default value : %d", info.int_array.def);
455 err_msg_t("streamrecordertest_get_attr_valid_intarray : Type mismatched!!");
460 debug_msg_t("streamrecordertest_get_attr_valid_intarray(!hstreamrecorder->streamrecorder)");
464 debug_msg_t("streamrecordertest_get_attr_valid_intarray(!hstreamrecorder)");
468 int streamrecordertest_get_attr_valid_intrange(const char * attr_name, int *min, int *max)
470 MMStreamRecorderAttrsInfo info;
471 int err = MM_ERROR_NONE;
473 if (hstreamrecorder) {
474 if (hstreamrecorder->streamrecorder) {
475 debug_msg_t("streamrecordertest_get_attr_valid_intrange(%s)", attr_name);
477 err = mm_streamrecorder_get_attribute_info(hstreamrecorder->streamrecorder, attr_name, &info);
478 if (err != MM_ERROR_NONE) {
479 err_msg_t("streamrecordertest_get_attr_valid_intarray : Error(%x)!!", err);
482 if (info.type == MM_STR_REC_ATTRS_TYPE_INT) {
483 if (info.validity_type == MM_STR_REC_ATTRS_VALID_TYPE_INT_RANGE) {
484 *min = info.int_range.min;
485 *max = info.int_range.max;
486 debug_msg_t("INT RANGE - default : %d", info.int_range.def);
491 err_msg_t("streamrecordertest_get_attr_valid_intarray : Type mismatched!!");
497 debug_msg_t("streamrecordertest_get_attr_valid_intarray(!hstreamrecorder->streamrecorder)");
500 debug_msg_t("streamrecordertest_get_attr_valid_intarray(!hstreamrecorder)");
509 static void print_menu()
511 switch (hstreamrecorder->menu_state) {
512 case MENU_STATE_MAIN:
513 g_print("\n\t=======================================\n");
514 g_print("\t Stream Recorder Menu \n");
515 g_print("\t=======================================\n");
516 if (hstreamrecorder->mode == MODE_VIDEO_CAPTURE) {
517 if (streamrecorder_get_state() <= STREAMRECORDER_CREATED) {
518 g_print("\t '1' Start Recording\n");
519 g_print("\t '2' Setting\n");
520 g_print("\t '3' Print frame rate\n");
521 g_print("\t 'b' back\n");
522 } else if (streamrecorder_get_state() == STREAMRECORDER_STARTED) {
523 g_print("\t 'r' Resume\n");
524 g_print("\t 'c' Cancel Recording\n");
525 g_print("\t 's' Save\n");
527 } else if (hstreamrecorder->mode == MODE_AUDIO) {
528 if (streamrecorder_get_state() <= STREAMRECORDER_CREATED) {
529 g_print("\t '1' Start Recording\n");
530 g_print("\t 'b' back\n");
531 } else if (streamrecorder_get_state() == STREAMRECORDER_STARTED) {
532 g_print("\t 'r' Resume Recording\n");
533 g_print("\t 'c' Cancel Recording\n");
534 g_print("\t 's' Save Recording\n");
538 case MENU_STATE_SETTING:
539 g_print("\n\t=======================================\n");
540 g_print("\t Stream Recorder > Setting\n");
541 g_print("\t=======================================\n");
542 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Stream Recorder] \n");
543 g_print("\t 'T' videobuffer type \n");
544 g_print("\t 'F' videosource format \n");
545 g_print("\t 'A' video framerate \n");
546 g_print("\t 'B' video bitrate \n");
547 g_print("\t 'D' audio source format\n");
548 g_print("\t 'I' audio bitrate \n");
549 g_print("\t 'S' audio samplerate \n");
550 g_print("\t 'O' video encoder \n");
551 g_print("\t 'C' audio encoder \n");
552 g_print("\t 'N' audio channel count \n");
553 g_print("\t 'm' file format\n");
554 g_print("\t 'b' back \n");
555 g_print("\t=======================================\n");
558 warn_msg_t("unknow menu state !!\n");
565 static void main_menu(gchar buf)
569 if (hstreamrecorder->mode == MODE_VIDEO_CAPTURE) {
570 if (streamrecorder_get_state() == STREAMRECORDER_CREATED) {
572 case '1': /* Start Recording */
573 g_print("*Recording start!\n");
574 video_stream_cb_cnt = 0;
575 audio_stream_cb_cnt = 0;
577 g_timer_reset(timer);
578 err = mm_streamrecorder_record(hstreamrecorder->streamrecorder);
580 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 1000, buffer, (640*480*3/2));
581 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 2000, buffer, (640*480*3/2));
582 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 3000, buffer, (640*480*3/2));
583 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 4000, buffer, (640*480*3/2));
584 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 5000, buffer, (640*480*3/2));
585 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 6000, buffer, (640*480*3/2));
586 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 7000, buffer, (640*480*3/2));
587 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 8000, buffer, (640*480*3/2));
588 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 9000, buffer, (640*480*3/2));
589 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 10000, buffer, (640*480*3/2));
590 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 11000, buffer, (640*480*3/2));
592 if (err != MM_ERROR_NONE)
593 warn_msg_t("Rec start mm_streamrecorder_record 0x%x", err);
595 streamrecorder_set_state(STREAMRECORDER_STARTED);
598 case '2': /* Setting */
599 hstreamrecorder->menu_state = MENU_STATE_SETTING;
602 case '3': /* Print frame rate */
606 hstreamrecorder->menu_state = MENU_STATE_MAIN;
611 g_print("\t Invalid input \n");
614 } else if (streamrecorder_get_state() == STREAMRECORDER_STARTED) {
616 case 'r': /* Resume Recording */
617 g_print("*Resume!\n");
620 case 'c': /* Cancel */
621 g_print("*Cancel Recording !\n");
622 err = mm_streamrecorder_cancel(hstreamrecorder->streamrecorder);
625 warn_msg_t("Cancel recording mm_streamrecorder_cancel = %x", err);
630 g_print("*Save Recording!\n");
631 g_timer_reset(timer);
633 err = mm_streamrecorder_commit(hstreamrecorder->streamrecorder);
634 streamrecorder_set_state(STREAMRECORDER_CREATED);
637 warn_msg_t("Save recording mm_streamrecorder_commit = %x", err);
641 case 'n': /* Capture video snapshot */
645 g_print("\t Invalid input \n");
649 err_msg_t("Wrong streamrecorder state, check status!!");
651 } else if (hstreamrecorder->mode == MODE_AUDIO) {
653 case '1': /* Start Recording */
654 g_print("*Recording start!\n");
655 g_timer_reset(timer);
656 err = mm_streamrecorder_record(hstreamrecorder->streamrecorder);
659 warn_msg_t("Rec start mm_streamrecorder_record = %x", err);
664 hstreamrecorder->menu_state = MENU_STATE_MAIN;
669 g_print("\t Invalid input \n");
673 g_print("\t Invalid mode, back to upper menu \n");
674 hstreamrecorder->menu_state = MENU_STATE_MAIN;
680 static void setting_menu(gchar buf)
682 gboolean bret = FALSE;
687 int height_count = 0;
692 int *width_array = NULL;
693 int *height_array = NULL;
694 char *err_attr_name = NULL;
695 str_xypair_t input_pair;
697 int err = MM_ERROR_NONE;
698 int x = 0, y = 0, width = 0, height = 0;
700 if (hstreamrecorder->mode == MODE_VIDEO_CAPTURE) {
702 case '0': /* Setting */
703 g_print("*Select the preview resolution!\n");
704 streamrecordertest_get_attr_valid_intarray(MMSTR_VIDEO_RESOLUTION_WIDTH, &width_array, &width_count);
705 streamrecordertest_get_attr_valid_intarray(MMSTR_VIDEO_RESOLUTION_HEIGHT, &height_array, &height_count);
707 if (width_count != height_count) {
708 err_msg_t("System has wrong information!!\n");
709 } else if (width_count == 0) {
710 g_print("Not supported!!\n");
714 for (i = 0; i < width_count; i++)
715 g_print("\t %d. %d*%d\n", i+1, width_array[i], height_array[i]);
717 err = scanf("%d", &index_menu);
719 printf("\nscanf error : errno %d\n", errno);
721 if (index_menu > 0 && index_menu <= width_count) {
722 input_pair.x = width_array[index_menu-1];
723 input_pair.y = height_array[index_menu-1];
724 bret = streamrecordertest_set_attr_xypair(input_pair);
730 case '1': /* Setting > Capture Resolution setting */
733 case 'r': /* Setting > Rotate input when recording */
734 g_print("Not supported !! \n");
737 case 'H': /* Setting > Hybrid mode */
738 g_print("* Hybrid mode\n");
740 g_print("\t 0. DISABLE\n");
741 g_print("\t 1. ENABLE\n");
744 err = scanf("%d", &index_menu);
746 if (index_menu < 0 || index_menu > 1)
747 g_print("Wrong INPUT[%d]!! \n", index_menu);
751 case 'R': /* Setting > Stream Recorder-rotation setting */
752 g_print("*Stream Recorder-Rotation setting!\n");
754 g_print("\t0. 0 degree\n");
755 g_print("\t1. 90 degree\n");
756 g_print("\t2. 180 degree\n");
757 g_print("\t3. 270 degree\n");
759 err = scanf("%d", &index_menu);
760 if (index_menu < 0 || index_menu > 3)
761 g_print("Wrong Input[%d] !!\n\n", index_menu);
763 g_print("*Stream Recorder-Flip setting!\n");
764 g_print("\t0. NONE\n");
765 g_print("\t1. HORIZONTAL\n");
766 g_print("\t2. VERTICAL\n");
767 g_print("\t3. BOTH\n");
769 err = scanf("%d", &index_menu);
770 if (index_menu < 0 || index_menu > 3)
771 g_print("Wrong Input[%d] !!\n\n", index_menu);
775 case 'T': /* Setting > videobuffer-type setting */
776 g_print("*videobuffer type !\n");
777 streamrecordertest_get_attr_valid_intrange("videobuffer-type", &min, &max);
780 g_print("Not supported !! \n");
783 g_print("\n Select videobuffer type (%d ~ %d)\n", min, max);
784 err = scanf("%d", &index_menu);
785 bret = streamrecordertest_set_attr_int("videobuffer-type", index_menu);
789 case 'F': /* Setting > videosource-format setting */
790 g_print("*videosource format !\n");
791 streamrecordertest_get_attr_valid_intrange("videosource-format", &min, &max);
794 g_print("Not supported !! \n");
797 g_print("\n Select videosource-format (%d ~ %d)\n", min, max);
798 err = scanf("%d", &index_menu);
799 bret = streamrecordertest_set_attr_int("videosource-format", index_menu);
803 case 'A': /* Setting > video framerate setting */
804 g_print("*video framerate !\n");
805 streamrecordertest_get_attr_valid_intrange("video-framerate", &min, &max);
808 g_print("Not supported !! \n");
811 g_print("\n Select video-framerate (%d ~ %d)\n", min, max);
812 err = scanf("%d", &index_menu);
813 bret = streamrecordertest_set_attr_int("video-framerate", index_menu);
817 case 'B': /* Setting > video bitrate setting */
818 g_print("*video bitrate !\n");
819 streamrecordertest_get_attr_valid_intrange("video-bitrate", &min, &max);
822 g_print("Not supported !! \n");
825 g_print("\n Select video-bitrate (%d ~ %d)\n", min, max);
826 err = scanf("%d", &index_menu);
827 bret = streamrecordertest_set_attr_int("video-bitrate", index_menu);
831 case 'D': /* Setting > audio-source-format setting */
832 g_print("*audio-source-format !\n");
833 streamrecordertest_get_attr_valid_intrange("audio-source-format", &min, &max);
836 g_print("Not supported !! \n");
839 g_print("\n Select audio-source-format (%d ~ %d)\n", min, max);
840 err = scanf("%d", &index_menu);
841 bret = streamrecordertest_set_attr_int("audio-source-format", index_menu);
845 case 'I': /* Setting > audio-bitrate setting */
846 g_print("*audio-bitrate !\n");
847 streamrecordertest_get_attr_valid_intrange("audio-bitrate", &min, &max);
850 g_print("Not supported !! \n");
853 g_print("\n Select audio-bitrate (%d ~ %d)\n", min, max);
854 err = scanf("%d", &index_menu);
855 bret = streamrecordertest_set_attr_int("audio-bitrate", index_menu);
859 case 'S': /* Setting > audio-samplerate setting */
860 g_print("*audio-samplerate !\n");
861 streamrecordertest_get_attr_valid_intrange("audio-samplerate", &min, &max);
864 g_print("Not supported !! \n");
867 g_print("\n Select audio-samplerate (%d ~ %d)\n", min, max);
868 err = scanf("%d", &index_menu);
869 bret = streamrecordertest_set_attr_int("audio-samplerate", index_menu);
873 case 'O': /* Setting > video-encoder setting */
874 g_print("*video-encoder!\n");
875 streamrecordertest_get_attr_valid_intrange("video-encoder", &min, &max);
878 g_print("Not supported !! \n");
881 g_print("\n Select video-encoder (%d ~ %d)\n", min, max);
882 err = scanf("%d", &index_menu);
883 bret = streamrecordertest_set_attr_int("video-encoder", index_menu);
887 case 'C': /* Setting >audio-encoder setting */
888 g_print("*audio-encoder!\n");
889 streamrecordertest_get_attr_valid_intrange("audio-encoder", &min, &max);
892 g_print("Not supported !! \n");
895 g_print("\n Select audio-encoder (%d ~ %d)\n", min, max);
896 err = scanf("%d", &index_menu);
897 bret = streamrecordertest_set_attr_int("audio-encoder", index_menu);
901 case 'N': /* Setting >audio-channel-count setting */
902 g_print("*audio-channel-count!\n");
903 streamrecordertest_get_attr_valid_intrange("audio-channel-count", &min, &max);
906 g_print("Not supported !! \n");
909 g_print("\n Select audio-channel-count(%d ~ %d)\n", min, max);
910 err = scanf("%d", &index_menu);
911 bret = streamrecordertest_set_attr_int("audio-channel-count", index_menu);
916 hstreamrecorder->menu_state = MENU_STATE_MAIN;
920 g_print("\t Invalid input \n");
924 g_print("\t Invalid mode, back to upper menu \n");
925 hstreamrecorder->menu_state = MENU_STATE_MAIN;
931 * This function is to execute command.
933 * @param channel [in] 1st parameter
935 * @return This function returns TRUE/FALSE
939 static gboolean cmd_input(GIOChannel *channel)
943 GError *g_error = NULL;
945 debug_msg_t("ENTER");
947 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
949 debug_msg_t("g_io_channel_read_chars error");
950 g_error_free(g_error);
957 debug_msg_t("Menu Status : %d", hstreamrecorder->menu_state);
958 switch (hstreamrecorder->menu_state) {
959 case MENU_STATE_MAIN:
962 case MENU_STATE_SETTING:
963 setting_menu(buf[0]);
974 debug_msg_t("No read input");
981 * This function is to initiate streamrecorder attributes .
983 * @param type [in] image(capture)/video(recording) mode
985 * @return This function returns TRUE/FALSE
987 * @see other functions
989 static gboolean init(int type)
991 MMHandleType str_handle = 0;
993 char *err_attr_name = NULL;
994 int video_codec = MM_VIDEO_CODEC_INVALID;
995 int audio_codec = MM_AUDIO_CODEC_INVALID;
996 int file_format = MM_FILE_FORMAT_INVALID;
997 int audio_enc = MM_AUDIO_CODEC_INVALID;
1001 int video_width = 0;
1002 int video_height = 0;
1004 int audio_samplerate = 0;
1005 int audio_src_format = 0;
1006 int video_src_format = 0;
1008 const char *filename = "/opt/usr/media/test.mp4";
1010 if (!hstreamrecorder)
1013 if (!hstreamrecorder->streamrecorder)
1016 str_handle = (MMHandleType)(hstreamrecorder->streamrecorder);
1018 /*================================================================================
1020 *=================================================================================*/
1021 if (type == MODE_VIDEO_CAPTURE) {
1022 video_codec = MM_VIDEO_CODEC_MPEG4;
1023 /*audio_codec = MM_AUDIO_CODEC_AAC;*/
1024 file_format = MM_FILE_FORMAT_MP4;
1025 /*audio_enc = MM_AUDIO_CODEC_PCM;*/
1027 v_bitrate = 8000000;
1028 /*a_bitrate = 64000;*/
1032 /*audio_samplerate = 48000;*/
1033 /*audio_src_format = 2;*/
1035 video_src_format = MM_STREAMRECORDER_INPUT_FORMAT_NV12;
1036 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1037 MMSTR_VIDEO_ENABLE, TRUE,
1038 MMSTR_AUDIO_ENABLE, FALSE,
1041 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1042 MMSTR_VIDEO_ENCODER, video_codec,
1043 /*MMSTR_AUDIO_ENCODER, audio_codec,*/
1044 MMSTR_FILE_FORMAT, file_format,
1045 MMSTR_VIDEO_BITRATE, v_bitrate,
1046 MMSTR_VIDEO_RESOLUTION_WIDTH , video_width,
1047 MMSTR_VIDEO_RESOLUTION_HEIGHT, video_height,
1048 MMSTR_VIDEO_FRAMERATE, video_fps,
1049 /*MMSTR_AUDIO_CHANNEL, channel,*/
1050 /*MMSTR_AUDIO_SAMPLERATE, audio_samplerate,*/
1051 /*MMSTR_AUDIO_BITRATE, a_bitrate,*/
1052 /*MMSTR_AUDIO_SOURCE_FORMAT, audio_src_format,*/
1053 MMSTR_VIDEO_SOURCE_FORMAT, video_src_format,
1054 MMSTR_RECORDER_MODE, rec_mode,
1056 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1057 MMSTR_FILENAME, filename, strlen(filename), NULL);
1061 /*================================================================================
1063 *=================================================================================*/
1064 debug_msg_t("Init DONE.");
1069 static gboolean init_handle()
1071 hstreamrecorder->mode = MODE_VIDEO_CAPTURE; /* image(capture)/video(recording) mode */
1072 hstreamrecorder->isMultishot = FALSE;
1073 hstreamrecorder->stillshot_count = 0; /* total stillshot count */
1074 hstreamrecorder->multishot_count = 0; /* total multishot count */
1075 hstreamrecorder->stillshot_filename = STILL_CAPTURE_FILE_PATH_NAME; /* stored filename of stillshot */
1076 hstreamrecorder->multishot_filename = MULTI_CAPTURE_FILE_PATH_NAME; /* stored filename of multishot */
1077 hstreamrecorder->menu_state = MENU_STATE_MAIN;
1078 hstreamrecorder->isMute = FALSE;
1079 hstreamrecorder->elapsed_time = 0;
1080 hstreamrecorder->fps = SRC_VIDEO_FRAME_RATE_15; /*SRC_VIDEO_FRAME_RATE_30;*/
1085 * This function is to change streamrecorder mode.
1087 * @param type [in] image(capture)/video(recording) mode
1089 * @return This function returns TRUE/FALSE
1091 * @see other functions
1093 static gboolean mode_change()
1095 int err = MM_ERROR_NONE;
1096 int state = STREAMRECORDER_NONE;
1097 int device_count = 0;
1098 int facing_direction = 0;
1099 char media_type = '\0';
1100 char *evassink_name = NULL;
1103 state = streamrecorder_get_state();
1104 debug_msg_t("MMStreamrecorder State : %d", state);
1105 if (state != STREAMRECORDER_NULL) {
1106 if ((state == STREAMRECORDER_STARTED)) {
1107 debug_msg_t("mm_streamrecorder_cancel");
1108 err = mm_streamrecorder_cancel(hstreamrecorder->streamrecorder);
1111 warn_msg_t("exit mm_streamrecorder_cancel = %x", err);
1116 state = streamrecorder_get_state();
1117 if (state == STREAMRECORDER_CREATED) {
1118 debug_msg_t("mm_streamreorder_unrealize");
1119 mm_streamrecorder_unrealize(hstreamrecorder->streamrecorder);
1120 streamrecorder_set_state(STREAMRECORDER_NONE);
1123 state = streamrecorder_get_state();
1124 if (state == STREAMRECORDER_NONE) {
1125 debug_msg_t("mm_streamrecorder_destroy");
1126 mm_streamrecorder_destroy(hstreamrecorder->streamrecorder);
1128 streamrecorder_set_state(STREAMRECORDER_NULL);
1134 g_print("\n\t=======================================\n");
1135 g_print("\t MM_STREAMRECORDER_TESTSUIT\n");
1136 g_print("\t=======================================\n");
1137 g_print("\t '1' STREAM RECORDER CREATE\n");
1138 g_print("\t 'q' Exit\n");
1139 g_print("\t=======================================\n");
1141 g_print("\t Enter the media type:\n\t");
1143 err = scanf("%c", &media_type);
1145 switch (media_type) {
1147 hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1151 hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1155 hstreamrecorder->mode = MODE_AUDIO;
1159 hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1163 g_print("\t Quit streamrecorder Testsuite!!\n");
1164 hstreamrecorder->mode = -1;
1165 if (g_main_loop_is_running(g_loop))
1166 g_main_loop_quit(g_loop);
1170 g_print("\t Invalid media type(%d)\n", media_type);
1175 debug_msg_t("mm_streamrecorder_create");
1176 g_get_current_time(&previous);
1177 g_timer_reset(timer);
1181 fp = fopen("/opt/usr/media/test.nv12", "a+");
1184 nread = fread(&buffer, sizeof(char), sizeof(buffer), fp);
1185 time_msg_t("mm_streamrecorder_create() : nread %d, sizeof(buffer) %d", nread, sizeof(buffer));
1188 err = mm_streamrecorder_create(&hstreamrecorder->streamrecorder);
1189 time_msg_t("mm_streamrecorder_create() : %12.6lfs", g_timer_elapsed(timer, NULL));
1191 if (err != MM_ERROR_NONE) {
1192 err_msg_t("mmstreamrecorder_create = %x", err);
1198 debug_msg_t("evassink name[%s], device count[%d], facing direction[%d]", evassink_name, device_count, facing_direction);
1200 if (!init(hstreamrecorder->mode)) {
1201 err_msg_t("testsuite init() failed.");
1205 debug_msg_t("mm_streamrecorder_realize");
1207 g_timer_reset(timer);
1209 err = mm_streamrecorder_realize(hstreamrecorder->streamrecorder);
1210 streamrecorder_set_state(STREAMRECORDER_CREATED);
1211 time_msg_t("mm_streamrecorder_realize() : %12.6lfs", g_timer_elapsed(timer, NULL));
1212 if (err != MM_ERROR_NONE) {
1213 err_msg_t("mm_streamrecorder_realize = %x", err);
1217 g_timer_reset(timer);
1219 g_get_current_time(¤t);
1220 timersub(¤t, &previous, &result);
1221 time_msg_t("streamrecorder Starting Time : %ld.%lds", result.tv_sec, result.tv_usec);
1228 * This function is the example main function for mmstreamrecorder API.
1232 * @return This function returns 0.
1234 * @see other functions
1236 int main(int argc, char **argv)
1240 timer = g_timer_new();
1242 gst_init(&argc, &argv);
1244 time_msg_t("gst_init() : %12.6lfs", g_timer_elapsed(timer, NULL));
1246 hstreamrecorder = (streamrecorder_handle_t *) g_malloc0(sizeof(streamrecorder_handle_t));
1248 g_timer_reset(timer);
1250 bret = mode_change();
1256 g_loop = g_main_loop_new(NULL, FALSE);
1258 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1259 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1261 debug_msg_t("RUN main loop");
1263 g_main_loop_run(g_loop);
1265 debug_msg_t("STOP main loop");
1268 g_timer_stop(timer);
1269 g_timer_destroy(timer);
1273 g_free(hstreamrecorder);
1274 g_main_loop_unref(g_loop);
1275 g_io_channel_unref(stdin_channel);