2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
22 #include <Elementary.h>
23 #include <appcore-efl.h>
24 #include <video_util.h>
26 #define PACKAGE "video_util_test"
27 #define MAX_STRING_LEN 256
33 #define LOG_TAG "VIDEO_UTIL_TEST"
36 CURRENT_STATUS_MAINMENU,
37 CURRENT_STATUS_FILENAME,
38 CURRENT_STATUS_SET_FORMAT,
39 CURRENT_STATUS_SET_VIDEO_CODEC,
40 CURRENT_STATUS_SET_AUDIO_CODEC,
41 CURRENT_STATUS_SET_ACCURATE_MODE,
42 CURRENT_STATUS_SET_RESOLUTION,
43 CURRENT_STATUS_SET_FPS,
44 CURRENT_STATUS_SET_TIME,
45 CURRENT_STATUS_SET_OUTFILENAME,
49 static video_util_h video_h = NULL;
50 char g_uri[MAX_STRING_LEN] = { 0, };
52 int g_menu_state = CURRENT_STATUS_MAINMENU;
54 int format = VIDEO_UTIL_FILE_FORMAT_3GP;
55 int video_codec = VIDEO_UTIL_VIDEO_CODEC_MPEG4;
56 int audio_codec = VIDEO_UTIL_AUDIO_CODEC_AAC;
57 int accurate_mode = 0;
61 unsigned long start_position = 0;
62 unsigned long duration = 5000;
63 int make_video_cnt = 1;
64 char g_out[MAX_STRING_LEN] = { 0, };
69 unsigned long start_time;
70 unsigned long duration;
73 static void display_sub_basic();
75 static int _create_app(void *data)
77 LOGD("My app is going alive!\n");
81 static int _terminate_app(void *data)
83 LOGD("My app is going gone!\n");
87 struct appcore_ops ops = {
88 .create = _create_app,
89 .terminate = _terminate_app,
92 void _quit_program(void)
97 bool test_transcode_spec_cb(int value, void *user_data)
100 LOGE("user_data is NULL");
104 if (!strcmp(user_data, "format_check")) {
107 LOGI("[%s] --- [3gp]", user_data);
110 LOGI("[%s] --- [mp4]", user_data);
115 } else if (!strcmp(user_data, "video_codec_check")) {
118 LOGI("[%s] --- [m4v]", user_data);
121 LOGI("[%s] --- [h263]", user_data);
124 LOGI("[%s] --- [h264]", user_data);
129 } else if (!strcmp(user_data, "audio_codec_check")) {
132 LOGI("[%s] --- [aac]", user_data);
135 LOGI("[%s] --- [amrnb]", user_data);
145 bool _supported_spec_check(video_util_h handle)
148 ret = video_util_foreach_supported_file_format(handle, (video_util_supported_file_format_cb)test_transcode_spec_cb, "format_check");
149 printf("video_util_foreach_supported_file_format [%d]\n", ret);
150 ret = video_util_foreach_supported_video_codec(handle, (video_util_supported_video_encoder_cb)test_transcode_spec_cb, "video_codec_check");
151 printf("video_util_foreach_supported_video_codec [%d]\n", ret);
152 ret = video_util_foreach_supported_audio_codec(handle, (video_util_supported_audio_encoder_cb)test_transcode_spec_cb, "audio_codec_check");
153 printf("video_util_foreach_supported_audio_codec [%d]\n", ret);
158 void _transcode_completed_cb(video_util_error_e error, void *user_data)
161 unsigned long ntn_start_position = 0;
163 test_util_s *_util_s = (test_util_s *)user_data;
165 LOGI("transcode_completed_cb============= [%2d / %2d][%d]\n", _util_s->idx, make_video_cnt, error);
166 printf("transcode_completed_cb============= [%2d / %2d][%d]\n", _util_s->idx, make_video_cnt, error);
168 if (_util_s->idx == (make_video_cnt - 1)) {
169 LOGI("End trascoding");
170 video_util_destroy(_util_s->video_h);
171 _util_s->video_h = NULL;
176 idx = _util_s->idx + 1;
177 ntn_start_position = _util_s->start_time + duration;
179 _util_s->start_time = ntn_start_position;
181 _video_util_start_transcoding((test_util_s *)_util_s);
186 void _transcode_progress_cb(unsigned long current_position, unsigned long duration, void *user_data)
188 test_util_s *_util_s = (test_util_s *)user_data;
190 LOGD("transcode_progress_cb-------------- [%2d][%ld][%ld]\n", _util_s->idx, current_position, duration);
195 void _video_util_start_transcoding(test_util_s *util_s)
197 int ret = VIDEO_UTIL_ERROR_NONE;
198 char output_file_path[MAX_STRING_LEN] = { 0, };
201 LOGE("video_util handle is NULL, please set format after create");
205 LOGI("video_util set below");
206 LOGI("format: %d, video codec: %d, audio codec: %d, accurate mode: %d", format, video_codec, audio_codec, accurate_mode);
207 LOGI("width: %d, height: %d, fps: %d", width, height, fps);
208 LOGI("start time: %lu, durtation: %lu", start_position, duration);
210 ret = video_util_set_file_format(video_h, format);
211 if (ret != VIDEO_UTIL_ERROR_NONE) {
212 LOGE("video_util_set_file_format is failed (%d)", ret);
216 ret = video_util_set_video_codec(video_h, video_codec);
217 if (ret != VIDEO_UTIL_ERROR_NONE) {
218 LOGE("video_util_set_video_codec is failed (%d)", ret);
222 ret = video_util_set_audio_codec(video_h, audio_codec);
223 if (ret != VIDEO_UTIL_ERROR_NONE) {
224 LOGE("video_util_set_audio_codec is failed (%d)", ret);
228 ret = video_util_set_accurate_mode(video_h, accurate_mode);
229 if (ret != VIDEO_UTIL_ERROR_NONE) {
230 LOGE("video_util_set_accurate_mode is failed (%d)", ret);
234 ret = video_util_set_resolution(video_h, width, height);
235 if (ret != VIDEO_UTIL_ERROR_NONE) {
236 LOGE("video_util_set_resolution is failed (%d)", ret);
240 ret = video_util_set_fps(video_h, fps);
241 if (ret != VIDEO_UTIL_ERROR_NONE) {
242 LOGE("video_util_set_fps is failed (%d)", ret);
246 memset(output_file_path, 0x00, MAX_STRING_LEN);
248 snprintf(output_file_path, MAX_STRING_LEN, "%s_%d.%s", g_out, util_s->idx, format ? "mp4" : "3gp");
250 LOGI("input start_time: %lu, duration: %lu, output_file_path: %s", util_s->start_time, util_s->duration, output_file_path);
251 ret = video_util_start_transcoding(util_s->video_h, util_s->start_time, util_s->duration, output_file_path, _transcode_progress_cb, _transcode_completed_cb, util_s);
253 if (ret != VIDEO_UTIL_ERROR_NONE) {
254 LOGE("video_util_start_transcoding is failed (%d)", ret);
262 video_util_destroy(video_h);
265 memset(g_uri, 0x00, MAX_STRING_LEN);
266 memset(g_out, 0x00, MAX_STRING_LEN);
267 g_menu_state = CURRENT_STATUS_MAINMENU;
269 format = VIDEO_UTIL_FILE_FORMAT_3GP;
270 video_codec = VIDEO_UTIL_VIDEO_CODEC_MPEG4;
271 audio_codec = VIDEO_UTIL_AUDIO_CODEC_AAC;
276 start_position = 5000;
281 static void input_filename(char *filename)
283 int len = strlen(filename);
285 int ret = VIDEO_UTIL_ERROR_NONE;
287 if (len < 0 || len > MAX_STRING_LEN) {
288 LOGE("Input file name is wrong");
295 ret = video_util_cancel_transcoding(video_h);
296 ret = video_util_destroy(video_h);
301 ret = video_util_create(&video_h);
303 if (ret != VIDEO_UTIL_ERROR_NONE) {
304 LOGE("video_util create is failed (%d)", ret);
308 strncpy(g_uri, filename, len);
310 ret = video_util_set_file_path(video_h, g_uri);
312 if (ret != VIDEO_UTIL_ERROR_NONE) {
313 LOGE("video_util_set_file_path is failed");
317 _supported_spec_check(video_h);
320 void reset_menu_state()
322 g_menu_state = CURRENT_STATUS_MAINMENU;
326 void _interpret_main_menu(char *cmd)
328 int len = strlen(cmd);
331 if (strncmp(cmd, "a", 1) == 0) {
332 g_menu_state = CURRENT_STATUS_FILENAME;
333 } else if (strncmp(cmd, "s", 1) == 0) {
335 test_util_s *_util_s = (test_util_s *)calloc(1, sizeof(test_util_s));
337 g_print("test util calloc failed");
341 _util_s->video_h = video_h;
343 _util_s->start_time = start_position;
344 _util_s->duration = duration;
346 _video_util_start_transcoding(_util_s);
348 } else if (strncmp(cmd, "c", 1) == 0) {
349 int ret = VIDEO_UTIL_ERROR_NONE;
351 g_print("video_util handle is NULL, please set format after create");
354 ret = video_util_cancel_transcoding(video_h);
355 if (ret != VIDEO_UTIL_ERROR_NONE) {
356 g_print("video_util_cancel_transcoding is failed (%d)", ret);
359 } else if (strncmp(cmd, "f", 1) == 0) {
360 g_menu_state = CURRENT_STATUS_SET_FORMAT;
361 } else if (strncmp(cmd, "m", 1) == 0) {
362 g_menu_state = CURRENT_STATUS_SET_ACCURATE_MODE;
363 } else if (strncmp(cmd, "t", 1) == 0) {
364 g_menu_state = CURRENT_STATUS_SET_TIME;
365 } else if (strncmp(cmd, "o", 1) == 0) {
366 g_menu_state = CURRENT_STATUS_SET_OUTFILENAME;
367 } else if (strncmp(cmd, "q", 1) == 0) {
370 g_print("unknown menu \n");
372 } else if (len == 2) {
373 if (strncmp(cmd, "vc", 2) == 0)
374 g_menu_state = CURRENT_STATUS_SET_VIDEO_CODEC;
375 else if (strncmp(cmd, "ac", 2) == 0)
376 g_menu_state = CURRENT_STATUS_SET_AUDIO_CODEC;
377 else if (strncmp(cmd, "vr", 2) == 0)
378 g_menu_state = CURRENT_STATUS_SET_RESOLUTION;
379 else if (strncmp(cmd, "vf", 2) == 0)
380 g_menu_state = CURRENT_STATUS_SET_FPS;
382 g_print("unknown menu \n");
384 g_print("unknown menu \n");
389 static void displaymenu(void)
391 if (g_menu_state == CURRENT_STATUS_MAINMENU) {
393 } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
394 g_print("*** input mediapath.\n");
395 } else if (g_menu_state == CURRENT_STATUS_SET_FORMAT) {
396 g_print("*** input file format.(0:3gp, 1:mp4)\n");
397 } else if (g_menu_state == CURRENT_STATUS_SET_VIDEO_CODEC) {
398 g_print("*** input video codec.(0:m4v, 1:h263, 2:h264)\n");
399 } else if (g_menu_state == CURRENT_STATUS_SET_AUDIO_CODEC) {
400 g_print("*** input audio codec.(0:aac, 1:amrnb)\n");
401 } else if (g_menu_state == CURRENT_STATUS_SET_ACCURATE_MODE) {
402 g_print("*** input accurate mode.(0: OFF, 1: ON)\n");
403 } else if (g_menu_state == CURRENT_STATUS_SET_RESOLUTION) {
404 g_print("*** input video resolution.(width, height)\n");
405 } else if (g_menu_state == CURRENT_STATUS_SET_FPS) {
406 g_print("*** input video fps.(5<=fps<=30)\n");
407 } else if (g_menu_state == CURRENT_STATUS_SET_FPS) {
408 g_print("*** input video fps.(5<=fps<=30)\n");
409 } else if (g_menu_state == CURRENT_STATUS_SET_TIME) {
410 g_print("*** input transcode start/duration time(ms), run nth.(start time, duration, n)\n");
411 } else if (g_menu_state == CURRENT_STATUS_SET_OUTFILENAME) {
412 g_print("*** input output filename.(defaunt path /opt/usr/media/)\n");
414 g_print("*** unknown status.\n");
420 gboolean timeout_menu_display(void *data)
426 static void interpret(char *cmd)
428 switch (g_menu_state) {
430 case CURRENT_STATUS_MAINMENU:
432 _interpret_main_menu(cmd);
435 case CURRENT_STATUS_FILENAME:
441 case CURRENT_STATUS_SET_FORMAT:
443 int ret = VIDEO_UTIL_ERROR_NONE;
445 if (format < 0 || format >= VIDEO_UTIL_FILE_FORMAT_MAX) {
446 LOGE("input cmd is out of range.");
451 LOGE("video_util handle is NULL, please set format after create");
455 ret = video_util_set_file_format(video_h, format);
456 if (ret != VIDEO_UTIL_ERROR_NONE) {
457 LOGE("video_util_set_file_format is failed (%d)", ret);
465 case CURRENT_STATUS_SET_VIDEO_CODEC:
467 int ret = VIDEO_UTIL_ERROR_NONE;
468 video_codec = atoi(cmd);
469 if (video_codec < 0 || video_codec >= VIDEO_UTIL_VIDEO_CODEC_NONE) {
470 LOGE("input cmd is out of range");
475 LOGE("video_util handle is NULL, please set format after create");
479 ret = video_util_set_video_codec(video_h, video_codec);
480 if (ret != VIDEO_UTIL_ERROR_NONE) {
481 LOGE("video_util_set_video_codec is failed (%d)", ret);
489 case CURRENT_STATUS_SET_AUDIO_CODEC:
491 int ret = VIDEO_UTIL_ERROR_NONE;
492 audio_codec = atoi(cmd);
493 if (audio_codec < 0 || audio_codec >= VIDEO_UTIL_VIDEO_CODEC_NONE) {
494 LOGE("input cmd is out of range");
499 LOGE("video_util handle is NULL, please set format after create");
503 ret = video_util_set_video_codec(video_h, audio_codec);
504 if (ret != VIDEO_UTIL_ERROR_NONE) {
505 LOGE("video_util_set_video_codec is failed (%d)", ret);
513 case CURRENT_STATUS_SET_ACCURATE_MODE:
515 int ret = VIDEO_UTIL_ERROR_NONE;
516 accurate_mode = atoi(cmd);
519 LOGE("video_util handle is NULL, please set format after create");
523 ret = video_util_set_accurate_mode(video_h, (bool)accurate_mode);
524 if (ret != VIDEO_UTIL_ERROR_NONE) {
525 LOGE("video_util_set_video_codec is failed (%d)", ret);
533 case CURRENT_STATUS_SET_RESOLUTION:
535 int ret = VIDEO_UTIL_ERROR_NONE;
536 int value = atoi(cmd);
537 static int resolution_cnt = 0;
540 LOGE("video_util handle is NULL, please set format after create");
545 switch (resolution_cnt) {
554 ret = video_util_set_resolution(video_h, width, height);
555 if (ret != VIDEO_UTIL_ERROR_NONE) {
556 LOGE("video_util_set_resolution is failed (%d)", ret);
566 case CURRENT_STATUS_SET_FPS:
568 int ret = VIDEO_UTIL_ERROR_NONE;
571 if (fps < 5 || fps > 30) {
572 LOGE("input cmd is out of range");
577 LOGE("video_util handle is NULL, please set format after create");
581 ret = video_util_set_fps(video_h, fps);
582 if (ret != VIDEO_UTIL_ERROR_NONE) {
583 LOGE("video_util_set_fps is failed (%d)", ret);
591 case CURRENT_STATUS_SET_TIME:
593 int ret = VIDEO_UTIL_ERROR_NONE;
594 int value = atoi(cmd);
595 static int set_time_cnt = 0;
597 switch (set_time_cnt) {
599 start_position = value;
608 make_video_cnt = value;
615 case CURRENT_STATUS_SET_OUTFILENAME:
617 LOGI("output file is %s", g_out);
618 snprintf(g_out, MAX_STRING_LEN, "/opt/usr/media/%s", cmd);
619 g_out[MAX_STRING_LEN - 1] = '\0';
620 LOGI("output file is %s", g_out);
628 g_timeout_add(100, timeout_menu_display, 0);
631 static void display_sub_basic()
634 g_print("=========================================================================================\n");
635 g_print(" video_util_test test\n");
636 g_print("-----------------------------------------------------------------------------------------\n");
637 g_print(" a. Create \t\t\t");
638 g_print(" s. Start transcoding \t");
639 g_print(" c. Cancel transcoding \n");
640 g_print(" f. Set file format\t\t");
641 g_print("vc. Set video codec\t");
642 g_print("ac. Set audio codec\n");
643 g_print(" m. Set accurate mode\t\t");
644 g_print("vr. Set resolution\t");
645 g_print("vf. Set video fps\n");
646 g_print(" t. Set start/duration time \t");
647 g_print(" o. Set output filename\t");
648 g_print(" q. quite test suite\t");
650 g_print("=========================================================================================\n");
653 gboolean input(GIOChannel *channel)
655 gchar buf[MAX_STRING_LEN];
657 GError *error = NULL;
659 g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
667 int main(int argc, char *argv[])
669 GIOChannel *stdin_channel;
670 stdin_channel = g_io_channel_unix_new(0);
671 g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
672 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
678 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);