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;
689 int *width_array = NULL;
690 int *height_array = NULL;
691 str_xypair_t input_pair;
692 int err = MM_ERROR_NONE;
694 if (hstreamrecorder->mode == MODE_VIDEO_CAPTURE) {
696 case '0': /* Setting */
697 g_print("*Select the preview resolution!\n");
698 streamrecordertest_get_attr_valid_intarray(MMSTR_VIDEO_RESOLUTION_WIDTH, &width_array, &width_count);
699 streamrecordertest_get_attr_valid_intarray(MMSTR_VIDEO_RESOLUTION_HEIGHT, &height_array, &height_count);
701 if (width_count != height_count) {
702 err_msg_t("System has wrong information!!\n");
703 } else if (width_count == 0) {
704 g_print("Not supported!!\n");
708 for (i = 0; i < width_count; i++)
709 g_print("\t %d. %d*%d\n", i+1, width_array[i], height_array[i]);
711 err = scanf("%d", &index_menu);
713 printf("\nscanf error : errno %d\n", errno);
715 if (index_menu > 0 && index_menu <= width_count) {
716 input_pair.x = width_array[index_menu-1];
717 input_pair.y = height_array[index_menu-1];
718 bret = streamrecordertest_set_attr_xypair(input_pair);
724 case '1': /* Setting > Capture Resolution setting */
727 case 'r': /* Setting > Rotate input when recording */
728 g_print("Not supported !! \n");
731 case 'H': /* Setting > Hybrid mode */
732 g_print("* Hybrid mode\n");
734 g_print("\t 0. DISABLE\n");
735 g_print("\t 1. ENABLE\n");
738 err = scanf("%d", &index_menu);
740 if (index_menu < 0 || index_menu > 1)
741 g_print("Wrong INPUT[%d]!! \n", index_menu);
745 case 'R': /* Setting > Stream Recorder-rotation setting */
746 g_print("*Stream Recorder-Rotation setting!\n");
748 g_print("\t0. 0 degree\n");
749 g_print("\t1. 90 degree\n");
750 g_print("\t2. 180 degree\n");
751 g_print("\t3. 270 degree\n");
753 err = scanf("%d", &index_menu);
754 if (index_menu < 0 || index_menu > 3)
755 g_print("Wrong Input[%d] !!\n\n", index_menu);
757 g_print("*Stream Recorder-Flip setting!\n");
758 g_print("\t0. NONE\n");
759 g_print("\t1. HORIZONTAL\n");
760 g_print("\t2. VERTICAL\n");
761 g_print("\t3. BOTH\n");
763 err = scanf("%d", &index_menu);
764 if (index_menu < 0 || index_menu > 3)
765 g_print("Wrong Input[%d] !!\n\n", index_menu);
769 case 'T': /* Setting > videobuffer-type setting */
770 g_print("*videobuffer type !\n");
771 streamrecordertest_get_attr_valid_intrange("videobuffer-type", &min, &max);
774 g_print("Not supported !! \n");
777 g_print("\n Select videobuffer type (%d ~ %d)\n", min, max);
778 err = scanf("%d", &index_menu);
779 bret = streamrecordertest_set_attr_int("videobuffer-type", index_menu);
783 case 'F': /* Setting > videosource-format setting */
784 g_print("*videosource format !\n");
785 streamrecordertest_get_attr_valid_intrange("videosource-format", &min, &max);
788 g_print("Not supported !! \n");
791 g_print("\n Select videosource-format (%d ~ %d)\n", min, max);
792 err = scanf("%d", &index_menu);
793 bret = streamrecordertest_set_attr_int("videosource-format", index_menu);
797 case 'A': /* Setting > video framerate setting */
798 g_print("*video framerate !\n");
799 streamrecordertest_get_attr_valid_intrange("video-framerate", &min, &max);
802 g_print("Not supported !! \n");
805 g_print("\n Select video-framerate (%d ~ %d)\n", min, max);
806 err = scanf("%d", &index_menu);
807 bret = streamrecordertest_set_attr_int("video-framerate", index_menu);
811 case 'B': /* Setting > video bitrate setting */
812 g_print("*video bitrate !\n");
813 streamrecordertest_get_attr_valid_intrange("video-bitrate", &min, &max);
816 g_print("Not supported !! \n");
819 g_print("\n Select video-bitrate (%d ~ %d)\n", min, max);
820 err = scanf("%d", &index_menu);
821 bret = streamrecordertest_set_attr_int("video-bitrate", index_menu);
825 case 'D': /* Setting > audio-source-format setting */
826 g_print("*audio-source-format !\n");
827 streamrecordertest_get_attr_valid_intrange("audio-source-format", &min, &max);
830 g_print("Not supported !! \n");
833 g_print("\n Select audio-source-format (%d ~ %d)\n", min, max);
834 err = scanf("%d", &index_menu);
835 bret = streamrecordertest_set_attr_int("audio-source-format", index_menu);
839 case 'I': /* Setting > audio-bitrate setting */
840 g_print("*audio-bitrate !\n");
841 streamrecordertest_get_attr_valid_intrange("audio-bitrate", &min, &max);
844 g_print("Not supported !! \n");
847 g_print("\n Select audio-bitrate (%d ~ %d)\n", min, max);
848 err = scanf("%d", &index_menu);
849 bret = streamrecordertest_set_attr_int("audio-bitrate", index_menu);
853 case 'S': /* Setting > audio-samplerate setting */
854 g_print("*audio-samplerate !\n");
855 streamrecordertest_get_attr_valid_intrange("audio-samplerate", &min, &max);
858 g_print("Not supported !! \n");
861 g_print("\n Select audio-samplerate (%d ~ %d)\n", min, max);
862 err = scanf("%d", &index_menu);
863 bret = streamrecordertest_set_attr_int("audio-samplerate", index_menu);
867 case 'O': /* Setting > video-encoder setting */
868 g_print("*video-encoder!\n");
869 streamrecordertest_get_attr_valid_intrange("video-encoder", &min, &max);
872 g_print("Not supported !! \n");
875 g_print("\n Select video-encoder (%d ~ %d)\n", min, max);
876 err = scanf("%d", &index_menu);
877 bret = streamrecordertest_set_attr_int("video-encoder", index_menu);
881 case 'C': /* Setting >audio-encoder setting */
882 g_print("*audio-encoder!\n");
883 streamrecordertest_get_attr_valid_intrange("audio-encoder", &min, &max);
886 g_print("Not supported !! \n");
889 g_print("\n Select audio-encoder (%d ~ %d)\n", min, max);
890 err = scanf("%d", &index_menu);
891 bret = streamrecordertest_set_attr_int("audio-encoder", index_menu);
895 case 'N': /* Setting >audio-channel-count setting */
896 g_print("*audio-channel-count!\n");
897 streamrecordertest_get_attr_valid_intrange("audio-channel-count", &min, &max);
900 g_print("Not supported !! \n");
903 g_print("\n Select audio-channel-count(%d ~ %d)\n", min, max);
904 err = scanf("%d", &index_menu);
905 bret = streamrecordertest_set_attr_int("audio-channel-count", index_menu);
910 hstreamrecorder->menu_state = MENU_STATE_MAIN;
914 g_print("\t Invalid input \n");
918 g_print("\t Invalid mode, back to upper menu \n");
919 hstreamrecorder->menu_state = MENU_STATE_MAIN;
925 * This function is to execute command.
927 * @param channel [in] 1st parameter
929 * @return This function returns TRUE/FALSE
933 static gboolean cmd_input(GIOChannel *channel)
937 GError *g_error = NULL;
939 debug_msg_t("ENTER");
941 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
943 debug_msg_t("g_io_channel_read_chars error");
944 g_error_free(g_error);
951 debug_msg_t("Menu Status : %d", hstreamrecorder->menu_state);
952 switch (hstreamrecorder->menu_state) {
953 case MENU_STATE_MAIN:
956 case MENU_STATE_SETTING:
957 setting_menu(buf[0]);
968 debug_msg_t("No read input");
975 * This function is to initiate streamrecorder attributes .
977 * @param type [in] image(capture)/video(recording) mode
979 * @return This function returns TRUE/FALSE
981 * @see other functions
983 static gboolean init(int type)
985 MMHandleType str_handle = 0;
987 char *err_attr_name = NULL;
988 int video_codec = MM_VIDEO_CODEC_INVALID;
989 int file_format = MM_FILE_FORMAT_INVALID;
992 int video_height = 0;
994 int video_src_format = 0;
996 const char *filename = "/opt/usr/media/test.mp4";
998 if (!hstreamrecorder)
1001 if (!hstreamrecorder->streamrecorder)
1004 str_handle = (MMHandleType)(hstreamrecorder->streamrecorder);
1006 /*================================================================================
1008 *=================================================================================*/
1009 if (type == MODE_VIDEO_CAPTURE) {
1010 video_codec = MM_VIDEO_CODEC_MPEG4;
1011 /* audio_codec = MM_AUDIO_CODEC_AAC; */
1012 file_format = MM_FILE_FORMAT_MP4;
1013 /* audio_enc = MM_AUDIO_CODEC_PCM; */
1015 /* v_bitrate = 8000000; */
1016 /* a_bitrate = 64000; */
1020 /* audio_samplerate = 48000; */
1021 /* audio_src_format = 2; */
1023 video_src_format = MM_STREAMRECORDER_INPUT_FORMAT_NV12;
1024 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1025 MMSTR_VIDEO_ENABLE, TRUE,
1026 MMSTR_AUDIO_ENABLE, FALSE,
1029 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1030 MMSTR_VIDEO_ENCODER, video_codec,
1031 /*MMSTR_AUDIO_ENCODER, audio_codec,*/
1032 MMSTR_FILE_FORMAT, file_format,
1033 MMSTR_VIDEO_BITRATE, v_bitrate,
1034 MMSTR_VIDEO_RESOLUTION_WIDTH , video_width,
1035 MMSTR_VIDEO_RESOLUTION_HEIGHT, video_height,
1036 MMSTR_VIDEO_FRAMERATE, video_fps,
1037 /*MMSTR_AUDIO_CHANNEL, channel,*/
1038 /*MMSTR_AUDIO_SAMPLERATE, audio_samplerate,*/
1039 /*MMSTR_AUDIO_BITRATE, a_bitrate,*/
1040 /*MMSTR_AUDIO_SOURCE_FORMAT, audio_src_format,*/
1041 MMSTR_VIDEO_SOURCE_FORMAT, video_src_format,
1042 MMSTR_RECORDER_MODE, rec_mode,
1044 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1045 MMSTR_FILENAME, filename, strlen(filename), NULL);
1049 /*================================================================================
1051 *=================================================================================*/
1052 debug_msg_t("Init DONE.");
1057 static gboolean init_handle()
1059 hstreamrecorder->mode = MODE_VIDEO_CAPTURE; /* image(capture)/video(recording) mode */
1060 hstreamrecorder->isMultishot = FALSE;
1061 hstreamrecorder->stillshot_count = 0; /* total stillshot count */
1062 hstreamrecorder->multishot_count = 0; /* total multishot count */
1063 hstreamrecorder->stillshot_filename = STILL_CAPTURE_FILE_PATH_NAME; /* stored filename of stillshot */
1064 hstreamrecorder->multishot_filename = MULTI_CAPTURE_FILE_PATH_NAME; /* stored filename of multishot */
1065 hstreamrecorder->menu_state = MENU_STATE_MAIN;
1066 hstreamrecorder->isMute = FALSE;
1067 hstreamrecorder->elapsed_time = 0;
1068 hstreamrecorder->fps = SRC_VIDEO_FRAME_RATE_15; /*SRC_VIDEO_FRAME_RATE_30;*/
1073 * This function is to change streamrecorder mode.
1075 * @param type [in] image(capture)/video(recording) mode
1077 * @return This function returns TRUE/FALSE
1079 * @see other functions
1081 static gboolean mode_change()
1083 int err = MM_ERROR_NONE;
1084 int state = STREAMRECORDER_NONE;
1085 int device_count = 0;
1086 int facing_direction = 0;
1087 char media_type = '\0';
1088 char *evassink_name = NULL;
1091 state = streamrecorder_get_state();
1092 debug_msg_t("MMStreamrecorder State : %d", state);
1093 if (state != STREAMRECORDER_NULL) {
1094 if ((state == STREAMRECORDER_STARTED)) {
1095 debug_msg_t("mm_streamrecorder_cancel");
1096 err = mm_streamrecorder_cancel(hstreamrecorder->streamrecorder);
1099 warn_msg_t("exit mm_streamrecorder_cancel = %x", err);
1104 state = streamrecorder_get_state();
1105 if (state == STREAMRECORDER_CREATED) {
1106 debug_msg_t("mm_streamreorder_unrealize");
1107 mm_streamrecorder_unrealize(hstreamrecorder->streamrecorder);
1108 streamrecorder_set_state(STREAMRECORDER_NONE);
1111 state = streamrecorder_get_state();
1112 if (state == STREAMRECORDER_NONE) {
1113 debug_msg_t("mm_streamrecorder_destroy");
1114 mm_streamrecorder_destroy(hstreamrecorder->streamrecorder);
1116 streamrecorder_set_state(STREAMRECORDER_NULL);
1122 g_print("\n\t=======================================\n");
1123 g_print("\t MM_STREAMRECORDER_TESTSUIT\n");
1124 g_print("\t=======================================\n");
1125 g_print("\t '1' STREAM RECORDER CREATE\n");
1126 g_print("\t 'q' Exit\n");
1127 g_print("\t=======================================\n");
1129 g_print("\t Enter the media type:\n\t");
1131 err = scanf("%c", &media_type);
1133 switch (media_type) {
1135 hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1139 hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1143 hstreamrecorder->mode = MODE_AUDIO;
1147 hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1151 g_print("\t Quit streamrecorder Testsuite!!\n");
1152 hstreamrecorder->mode = -1;
1153 if (g_main_loop_is_running(g_loop))
1154 g_main_loop_quit(g_loop);
1158 g_print("\t Invalid media type(%d)\n", media_type);
1163 debug_msg_t("mm_streamrecorder_create");
1164 g_get_current_time(&previous);
1165 g_timer_reset(timer);
1169 fp = fopen("/opt/usr/media/test.nv12", "a+");
1172 nread = fread(&buffer, sizeof(char), sizeof(buffer), fp);
1173 time_msg_t("mm_streamrecorder_create() : nread %d, sizeof(buffer) %d", nread, sizeof(buffer));
1176 err = mm_streamrecorder_create(&hstreamrecorder->streamrecorder);
1177 time_msg_t("mm_streamrecorder_create() : %12.6lfs", g_timer_elapsed(timer, NULL));
1179 if (err != MM_ERROR_NONE) {
1180 err_msg_t("mmstreamrecorder_create = %x", err);
1186 debug_msg_t("evassink name[%s], device count[%d], facing direction[%d]", evassink_name, device_count, facing_direction);
1188 if (!init(hstreamrecorder->mode)) {
1189 err_msg_t("testsuite init() failed.");
1193 debug_msg_t("mm_streamrecorder_realize");
1195 g_timer_reset(timer);
1197 err = mm_streamrecorder_realize(hstreamrecorder->streamrecorder);
1198 streamrecorder_set_state(STREAMRECORDER_CREATED);
1199 time_msg_t("mm_streamrecorder_realize() : %12.6lfs", g_timer_elapsed(timer, NULL));
1200 if (err != MM_ERROR_NONE) {
1201 err_msg_t("mm_streamrecorder_realize = %x", err);
1205 g_timer_reset(timer);
1207 g_get_current_time(¤t);
1208 timersub(¤t, &previous, &result);
1209 time_msg_t("streamrecorder Starting Time : %ld.%lds", result.tv_sec, result.tv_usec);
1216 * This function is the example main function for mmstreamrecorder API.
1220 * @return This function returns 0.
1222 * @see other functions
1224 int main(int argc, char **argv)
1228 timer = g_timer_new();
1230 gst_init(&argc, &argv);
1232 time_msg_t("gst_init() : %12.6lfs", g_timer_elapsed(timer, NULL));
1234 hstreamrecorder = (streamrecorder_handle_t *) g_malloc0(sizeof(streamrecorder_handle_t));
1236 g_timer_reset(timer);
1238 bret = mode_change();
1244 g_loop = g_main_loop_new(NULL, FALSE);
1246 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1247 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1249 debug_msg_t("RUN main loop");
1251 g_main_loop_run(g_loop);
1253 debug_msg_t("STOP main loop");
1256 g_timer_stop(timer);
1257 g_timer_destroy(timer);
1261 g_free(hstreamrecorder);
1262 g_main_loop_unref(g_loop);
1263 g_io_channel_unref(stdin_channel);