2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <video_util.h>
23 /* #define CANCEL_TEST */
32 GMainLoop *g_loop = NULL;
33 int g_make_video_cnt = 5;
34 int g_make_video_interval = 10000;
35 int g_duration = 5000;
37 static int test_transcode_do(test_util_s *_util_s);
39 void test_transcode_completed_cb(video_util_error_e error, void *user_data)
42 int start_position = 0;
44 test_util_s *_util_s = (test_util_s *)user_data;
45 g_print("transcode_completed_cb============= [%2d][%d]\n", _util_s->idx, error);
47 if (_util_s->idx == (g_make_video_cnt - 1)) {
49 g_main_loop_quit(g_loop);
53 idx = _util_s->idx + 1;
54 start_position = _util_s->start_time + g_make_video_interval;
56 _util_s->start_time = start_position;
58 test_transcode_do(_util_s);
61 int ret = VIDEO_UTIL_ERROR_NONE;
62 if (_util_s->idx == 3) {
63 g_print("Try cancel============= [%2d]]\n", _util_s->idx);
64 ret = video_util_cancel_transcoding(_util_s->video_h);
65 if (ret != VIDEO_UTIL_ERROR_NONE) {
66 g_print("[%d]error video_util_cancel_transcoding [%d]\n", __LINE__, ret);
68 g_main_loop_quit(g_loop);
73 test_transcode_do(_util_s);
80 void test_transcode_progress_cb(unsigned long current_position, unsigned long duration, void *user_data)
82 test_util_s *_util_s = (test_util_s *)user_data;
84 g_print("transcode_progress_cb-------------- [%2d][%ld][%ld]\n", _util_s->idx, current_position, duration);
87 unsigned long pos = 0;
88 unsigned long dur = 0;
89 video_util_get_progress_transcoding(_util_s->video_h, &pos, &dur);
90 g_print("transcode_progress_cb-------------- [%2d][%ld][%ld]\n", _util_s->idx, pos, dur);
95 bool test_transcode_spec_cb(int value, void *user_data)
97 if (user_data != NULL)
98 g_print("[%s]-----------", (char*)user_data);
100 g_print("[%d] \n", value);
105 bool supported_spec_check(video_util_h handle)
108 ret = video_util_foreach_supported_file_format(handle, (video_util_supported_file_format_cb)test_transcode_spec_cb, "format_check");
109 g_print("video_util_foreach_supported_file_format [%d]\n", ret);
110 ret = video_util_foreach_supported_video_codec(handle, (video_util_supported_video_encoder_cb)test_transcode_spec_cb, "video_codec_check");
111 g_print("video_util_foreach_supported_video_codec [%d]\n", ret);
112 ret = video_util_foreach_supported_audio_codec(handle, (video_util_supported_audio_encoder_cb)test_transcode_spec_cb, "audio_codec_check");
113 g_print("video_util_foreach_supported_audio_codec [%d]\n", ret);
118 static int test_transcode_do(test_util_s *util_s)
120 int ret = VIDEO_UTIL_ERROR_NONE;
121 char test_output_file_path[128] = {0, };
123 memset(test_output_file_path, 0x00, sizeof(test_output_file_path));
124 snprintf(test_output_file_path, sizeof(test_output_file_path), "/opt/usr/media/Videos/transcode_test_%d.mp4", util_s->idx);
126 g_print("g_start_time[%d] duration[%d] [%s]\n", util_s->start_time, util_s->duration, test_output_file_path);
128 ret = video_util_start_transcoding(util_s->video_h, util_s->start_time, util_s->duration, test_output_file_path, test_transcode_progress_cb, test_transcode_completed_cb, util_s);
129 if (ret != VIDEO_UTIL_ERROR_NONE) {
130 g_print("[%d]error video_util_start_transcoding [%d]\n", __LINE__, ret);
132 g_main_loop_quit(g_loop);
140 int main(int argc, char *argv[])
142 int ret = VIDEO_UTIL_ERROR_NONE;
143 video_util_h video_h = NULL;
144 test_util_s *_util_s = NULL;
148 g_print("type file path plz. [%d]\n", cnt);
152 ret = video_util_create(&video_h);
153 if (ret != VIDEO_UTIL_ERROR_NONE)
154 g_print("[%d]error video_util_create [%d]\n", __LINE__, ret);
157 supported_spec_check(video_h);
160 ret = video_util_set_file_path(video_h, argv[1]);
161 ret = video_util_set_file_format(video_h, VIDEO_UTIL_FILE_FORMAT_3GP);
162 ret = video_util_set_video_codec(video_h, VIDEO_UTIL_VIDEO_CODEC_MPEG4);
163 ret = video_util_set_audio_codec(video_h, VIDEO_UTIL_AUDIO_CODEC_AAC);
164 ret = video_util_set_accurate_mode(video_h, 0);
165 ret = video_util_set_resolution(video_h, 176, 144);
166 ret = video_util_set_fps(video_h, 10);
168 if (ret != VIDEO_UTIL_ERROR_NONE) {
169 g_print("[%d]error video_util_set condition [%d]\n", __LINE__, ret);
173 _util_s = (test_util_s *)calloc(1, sizeof(test_util_s));
174 if (_util_s == NULL) {
175 g_print("[%d]error calloc\n", __LINE__);
179 _util_s->video_h = video_h;
181 _util_s->start_time = 0;
182 _util_s->duration = g_duration;
184 ret = test_transcode_do(_util_s);
185 if (ret != VIDEO_UTIL_ERROR_NONE)
188 g_loop = g_main_loop_new(NULL, FALSE);
190 g_main_loop_run(g_loop);
191 g_main_loop_unref(g_loop);
194 /* destory handle in cb */
195 ret = video_util_destroy(video_h);
196 if (ret != VIDEO_UTIL_ERROR_NONE)
197 g_print("[%d]error video_util_destroy [%d]\n", __LINE__, ret);
199 g_print("[%d]Success video_util_destroy [%d]\n", __LINE__, ret);