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))
50 g_main_loop_quit(g_loop);
54 idx = _util_s->idx + 1;
55 start_position = _util_s->start_time + g_make_video_interval;
57 _util_s->start_time = start_position;
59 test_transcode_do(_util_s);
62 int ret = VIDEO_UTIL_ERROR_NONE;
65 printf("Try cancel============= [%2d]]\n", _util_s->idx);
66 ret = video_util_cancel_transcoding(_util_s->video_h);
67 if(ret != VIDEO_UTIL_ERROR_NONE)
69 printf("[%d]error video_util_cancel_transcoding [%d]\n", __LINE__, ret);
70 g_main_loop_quit(g_loop);
75 test_transcode_do(_util_s);
82 void test_transcode_progress_cb(unsigned long current_position, unsigned long duration, void *user_data)
84 test_util_s *_util_s = (test_util_s *)user_data;
86 printf("transcode_progress_cb-------------- [%2d][%ld][%ld]\n", _util_s->idx, current_position, duration);
89 unsigned long pos = 0;
90 unsigned long dur = 0;
91 video_util_get_progress_transcoding(_util_s->video_h, &pos, &dur);
92 printf("transcode_progress_cb-------------- [%2d][%ld][%ld]\n", _util_s->idx, pos, dur);
97 bool test_transcode_spec_cb(int value, void *user_data)
100 printf("[%s]-----------", (char*)user_data);
101 printf("[%d] \n", value);
106 bool supported_spec_check(video_util_h handle)
109 ret = video_util_foreach_supported_file_format(handle, (video_util_supported_file_format_cb)test_transcode_spec_cb, "format_check");
110 printf("[%d] video_util_foreach_supported_file_format [%d]\n", __LINE__, ret);
111 ret = video_util_foreach_supported_video_codec(handle, (video_util_supported_video_encoder_cb)test_transcode_spec_cb, "video_codec_check");
112 printf("[%d] video_util_foreach_supported_video_codec [%d]\n", __LINE__, ret);
113 ret = video_util_foreach_supported_audio_codec(handle, (video_util_supported_audio_encoder_cb)test_transcode_spec_cb, "audio_codec_check");
114 printf("[%d] video_util_foreach_supported_audio_codec [%d]\n", __LINE__, ret);
119 static int test_transcode_do(test_util_s *util_s)
122 char test_output_file_path[128] = {0, };
124 memset(test_output_file_path, 0x00, sizeof(test_output_file_path));
125 snprintf(test_output_file_path, sizeof(test_output_file_path), "/opt/media/Videos/transcode_test_%d.mp4", util_s->idx);
127 printf("g_start_time[%d] duration[%d] [%s]\n", util_s->start_time, util_s->duration, test_output_file_path);
129 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);
130 if(ret != VIDEO_UTIL_ERROR_NONE)
132 printf("[%d]error video_util_start_transcoding [%d]\n", __LINE__, ret);
133 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;
145 char * test_video_file_path = "/opt/usr/media/Videos/Color.mp4";
147 ret = video_util_create(&video_h);
148 if(ret != VIDEO_UTIL_ERROR_NONE)
150 printf("[%d]error video_util_create [%d]\n", __LINE__, ret);
154 supported_spec_check(video_h);
157 ret = video_util_set_file_path(video_h, test_video_file_path);
158 ret = video_util_set_file_format(video_h, VIDEO_UTIL_FILE_FORMAT_3GP);
159 ret = video_util_set_video_codec(video_h, VIDEO_UTIL_VIDEO_CODEC_MPEG4);
160 ret = video_util_set_audio_codec(video_h, VIDEO_UTIL_AUDIO_CODEC_AAC);
161 ret = video_util_set_accurate_mode(video_h, 0);
162 ret = video_util_set_resolution(video_h, 176, 144);
163 ret = video_util_set_fps(video_h, 10);
165 if(ret != VIDEO_UTIL_ERROR_NONE)
167 printf("[%d]error video_util_set condition [%d]\n", __LINE__, ret);
171 _util_s = (test_util_s*)calloc(1,sizeof(test_util_s));
174 printf("[%d]error calloc\n", __LINE__);
178 _util_s->video_h = video_h;
180 _util_s->start_time = 0;
181 _util_s->duration = g_duration;
183 test_transcode_do(_util_s);
185 g_loop = g_main_loop_new(NULL, FALSE);
187 g_main_loop_run(g_loop);
188 g_main_loop_unref(g_loop);
190 ret = video_util_destroy(video_h); //destory handle in cb
191 if(ret != VIDEO_UTIL_ERROR_NONE)
193 printf("[%d]error video_util_destroy [%d]\n", __LINE__, ret);
197 printf("[%d]Success video_util_destroy [%d]\n", __LINE__, ret);