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.
23 #include <thumbnail_util.h>
24 #include <thumbnail_util_private.h>
25 #include <tzplatform_config.h>
28 GMainLoop *g_loop = NULL;
31 void thumbnail_completed_cb(thumbnail_util_error_e error, const char *request_id, int raw_width, int raw_height, unsigned char *raw_data, int raw_size, void *user_data)
35 char file_name[MAX_SIZE + 1] = {0, };
37 memset(file_name, 0, MAX_SIZE);
38 snprintf(file_name, MAX_SIZE, "test_%s.raw", request_id);
39 fp = fopen(file_name, "w");
40 fwrite(raw_data, 1, raw_size, fp);
43 thumbnail_util_debug("=================[RESULT]");
44 thumbnail_util_debug("error_code [%d]", error);
45 thumbnail_util_debug("request id [%s]", request_id);
46 thumbnail_util_debug("width [%d], height [%d]", raw_width, raw_height);
47 thumbnail_util_debug("raw_data [0x%x], size [%d]", *raw_data, raw_size);
49 if (strncmp(request_id, "50", 2) == 0)
50 g_main_loop_quit(g_loop);
52 g_main_loop_quit(g_loop);
56 void __convert_i_to_a(unsigned int request_id, char **req_str)
59 buf = malloc(MAX_SIZE * sizeof(char));
62 snprintf(buf, MAX_SIZE, "%d", request_id);
63 *req_str = strndup(buf, strlen(buf));
68 gboolean extract_thumbnail_start(gpointer data)
70 int ret = THUMBNAIL_UTIL_ERROR_NONE;
73 thumbnail_h test_info;
74 thumbnail_util_create(&test_info);
75 thumbnail_util_set_size(test_info, 512, 288);
77 for (i = 0; i < 50; i++) {
78 char filepath[255] = {0,};
79 snprintf(filepath, sizeof(filepath), "%s%d.jpg", "/home/owner/content/Images/test_image", i + 1);
80 thumbnail_util_debug("File : %s", filepath);
81 thumbnail_util_set_path(test_info, filepath);
82 ret = thumbnail_util_extract(test_info, thumbnail_completed_cb, test_info, &g_id);
83 thumbnail_util_debug("GENERATED ID [%s]", g_id);
86 thumbnail_h test_info;
87 thumbnail_util_create(&test_info);
88 thumbnail_util_set_path(test_info, tzplatform_mkpath(TZ_USER_IMAGES, "test_image1.jpg"));
89 thumbnail_util_set_size(test_info, 511, 288);
90 ret = thumbnail_util_extract(test_info, thumbnail_completed_cb, test_info, &g_id);
91 if (ret != THUMBNAIL_UTIL_ERROR_NONE)
92 thumbnail_util_error("thumbnail_util_extract failed[%d]", ret);
94 thumbnail_util_destroy(test_info);
96 if (ret == THUMBNAIL_UTIL_ERROR_NONE)
97 thumbnail_util_debug("extract raw data is success");
99 thumbnail_util_error("extract raw data is failed");
105 gboolean cancel_all(gpointer data)
107 int ret = THUMBNAIL_UTIL_ERROR_NONE;
108 thumbnail_h _media_thumb;
109 thumbnail_util_create(&_media_thumb);
113 char *req_str = NULL;
114 for (i = num - 20; i < num; i++) {
115 __convert_i_to_a(i, &req_str);
116 ret = thumbnail_util_cancel(_media_thumb, req_str);
117 if (ret == THUMBNAIL_UTIL_ERROR_NONE)
118 thumbnail_util_debug("thumbnail_util_cancel[%d] is success", i);
120 thumbnail_util_error("thumbnail_util_cancel[%d] is failed", i);
122 thumbnail_util_destroy(_media_thumb);
127 int test_extract_thumbnail(bool cancel)
129 int ret = THUMBNAIL_UTIL_ERROR_NONE;
130 GSource *source = NULL;
131 GMainContext *context = NULL;
133 g_loop = g_main_loop_new(NULL, false);
134 context = g_main_loop_get_context(g_loop);
135 source = g_idle_source_new();
136 g_source_set_callback(source, extract_thumbnail_start, NULL, NULL);
137 g_source_attach(source, context);
139 /* Logic to cancel */
141 GSource *cancel_src = NULL;
142 cancel_src = g_idle_source_new();
143 g_source_set_callback(cancel_src, cancel_all, NULL, NULL);
144 g_source_attach(cancel_src, context);
147 g_main_loop_run(g_loop);
148 g_main_loop_unref(g_loop);
153 int main(int argc, char *argv[])
155 int ret = THUMBNAIL_UTIL_ERROR_NONE;
156 unsigned char *data = NULL;
157 unsigned int width = 0;
158 unsigned int height = 0;
161 char file_name[MAX_SIZE + 1] = {0, };
163 thumbnail_util_debug("--- Thumbnail util test start ---");
165 ret = test_extract_thumbnail(false);
166 if (ret != THUMBNAIL_UTIL_ERROR_NONE)
167 thumbnail_util_debug("test_extract_thumbnail failed[%d]", ret);
169 thumbnail_util_debug("--- thumbnail_util_extract_to_file start :: IMAGE ---");
170 ret = thumbnail_util_extract_to_file(tzplatform_mkpath(TZ_USER_IMAGES, "test_image1.jpg"), 320, 240, tzplatform_mkpath(TZ_USER_IMAGES, "save_image1.jpg"));
171 if (ret != THUMBNAIL_UTIL_ERROR_NONE)
172 thumbnail_util_debug("thumbnail_util_extract_to_file failed[%d]", ret);
174 thumbnail_util_debug("--- thumbnail_util_extract_to_buffer start :: IMAGE ---");
175 ret = thumbnail_util_extract_to_buffer(tzplatform_mkpath(TZ_USER_IMAGES, "test_image1.jpg"), 320, 240, &data, &size, &width, &height);
176 if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
177 thumbnail_util_debug("thumbnail_util_extract_to_buffer failed[%d]", ret);
179 memset(file_name, 0, sizeof(file_name));
180 snprintf(file_name, MAX_SIZE, "%s/test_image1.raw", tzplatform_getenv(TZ_USER_IMAGES));
181 fp = fopen(file_name, "w");
182 fwrite(data, 1, size, fp);
188 thumbnail_util_debug("--- thumbnail_util_extract_to_file start :: VIDEO ---");
189 ret = thumbnail_util_extract_to_file(tzplatform_mkpath(TZ_USER_IMAGES, "test_video1.mp4"), 320, 240, tzplatform_mkpath(TZ_USER_IMAGES, "save_video1.jpg"));
190 if (ret != THUMBNAIL_UTIL_ERROR_NONE)
191 thumbnail_util_debug("thumbnail_util_extract_to_file failed[%d]", ret);
193 thumbnail_util_debug("--- thumbnail_util_extract_to_buffer start :: VIDEO ---");
194 ret = thumbnail_util_extract_to_buffer(tzplatform_mkpath(TZ_USER_IMAGES, "test_video1.mp4"), 320, 240, &data, &size, &width, &height);
195 if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
196 thumbnail_util_debug("thumbnail_util_extract_to_buffer failed[%d]", ret);
198 memset(file_name, 0, sizeof(file_name));
199 snprintf(file_name, MAX_SIZE, "%s/test_video1.raw", tzplatform_getenv(TZ_USER_IMAGES));
200 fp = fopen(file_name, "w");
201 fwrite(data, 1, size, fp);
207 thumbnail_util_debug("--- Thumbnail util test end ---");