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>
33 GMainLoop *g_loop = NULL;
34 int g_make_video_cnt = 5;
35 int g_make_video_interval = 10000;
36 int g_duration = 5000;
38 static int test_transcode_do(test_util_s *_util_s);
40 void test_transcode_completed_cb(video_util_error_e error, void *user_data)
43 int start_position = 0;
45 test_util_s *_util_s = (test_util_s *)user_data;
46 printf("transcode_completed_cb============= [%2d][%d]\n", _util_s->idx, error);
48 if(_util_s->idx == (g_make_video_cnt-1))
51 g_main_loop_quit(g_loop);
55 idx = _util_s->idx + 1;
56 start_position = _util_s->start_time + g_make_video_interval;
58 _util_s->start_time = start_position;
60 test_transcode_do(_util_s);
63 int ret = VIDEO_UTIL_ERROR_NONE;
66 printf("Try cancel============= [%2d]]\n", _util_s->idx);
67 ret = video_util_cancel_transcoding(_util_s->video_h);
68 if(ret != VIDEO_UTIL_ERROR_NONE)
70 printf("[%d]error video_util_cancel_transcoding [%d]\n", __LINE__, ret);
72 g_main_loop_quit(g_loop);
77 test_transcode_do(_util_s);
84 void test_transcode_progress_cb(unsigned long current_position, unsigned long duration, void *user_data)
86 test_util_s *_util_s = (test_util_s *)user_data;
88 printf("transcode_progress_cb-------------- [%2d][%ld][%ld]\n", _util_s->idx, current_position, duration);
91 unsigned long pos = 0;
92 unsigned long dur = 0;
93 video_util_get_progress_transcoding(_util_s->video_h, &pos, &dur);
94 printf("transcode_progress_cb-------------- [%2d][%ld][%ld]\n", _util_s->idx, pos, dur);
99 bool test_transcode_spec_cb(int value, void *user_data)
101 if(user_data != NULL)
102 printf("[%s]-----------", (char*)user_data);
103 printf("[%d] \n", value);
108 bool supported_spec_check(video_util_h handle)
111 ret = video_util_foreach_supported_file_format(handle, (video_util_supported_file_format_cb)test_transcode_spec_cb, "format_check");
112 printf("video_util_foreach_supported_file_format [%d]\n", ret);
113 ret = video_util_foreach_supported_video_codec(handle, (video_util_supported_video_encoder_cb)test_transcode_spec_cb, "video_codec_check");
114 printf("video_util_foreach_supported_video_codec [%d]\n", ret);
115 ret = video_util_foreach_supported_audio_codec(handle, (video_util_supported_audio_encoder_cb)test_transcode_spec_cb, "audio_codec_check");
116 printf("video_util_foreach_supported_audio_codec [%d]\n", ret);
121 static int test_transcode_do(test_util_s *util_s)
123 int ret = VIDEO_UTIL_ERROR_NONE;
124 char test_output_file_path[128] = {0, };
126 memset(test_output_file_path, 0x00, sizeof(test_output_file_path));
127 snprintf(test_output_file_path, sizeof(test_output_file_path), "/opt/usr/media/Videos/transcode_test_%d.mp4", util_s->idx);
129 printf("g_start_time[%d] duration[%d] [%s]\n", util_s->start_time, util_s->duration, test_output_file_path);
131 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);
132 if(ret != VIDEO_UTIL_ERROR_NONE)
134 printf("[%d]error video_util_start_transcoding [%d]\n", __LINE__, ret);
136 g_main_loop_quit(g_loop);
143 int main(int argc, char *argv[])
145 int ret = VIDEO_UTIL_ERROR_NONE;
146 video_util_h video_h = NULL;
147 test_util_s *_util_s = NULL;
152 printf("type file path plz. [%d]\n", cnt);
156 ret = video_util_create(&video_h);
157 if(ret != VIDEO_UTIL_ERROR_NONE)
159 printf("[%d]error video_util_create [%d]\n", __LINE__, ret);
163 supported_spec_check(video_h);
166 ret = video_util_set_file_path(video_h, argv[1]);
167 ret = video_util_set_file_format(video_h, VIDEO_UTIL_FILE_FORMAT_3GP);
168 ret = video_util_set_video_codec(video_h, VIDEO_UTIL_VIDEO_CODEC_MPEG4);
169 ret = video_util_set_audio_codec(video_h, VIDEO_UTIL_AUDIO_CODEC_AAC);
170 ret = video_util_set_accurate_mode(video_h, 0);
171 ret = video_util_set_resolution(video_h, 176, 144);
172 ret = video_util_set_fps(video_h, 10);
174 if(ret != VIDEO_UTIL_ERROR_NONE)
176 printf("[%d]error video_util_set condition [%d]\n", __LINE__, ret);
180 _util_s = (test_util_s*)calloc(1,sizeof(test_util_s));
183 printf("[%d]error calloc\n", __LINE__);
187 _util_s->video_h = video_h;
189 _util_s->start_time = 0;
190 _util_s->duration = g_duration;
192 ret = test_transcode_do(_util_s);
193 if(ret != VIDEO_UTIL_ERROR_NONE)
196 g_loop = g_main_loop_new(NULL, FALSE);
198 g_main_loop_run(g_loop);
199 g_main_loop_unref(g_loop);
202 ret = video_util_destroy(video_h); //destory handle in cb
203 if(ret != VIDEO_UTIL_ERROR_NONE)
205 printf("[%d]error video_util_destroy [%d]\n", __LINE__, ret);
209 printf("[%d]Success video_util_destroy [%d]\n", __LINE__, ret);