4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include "media-thumbnail.h"
23 #include "media-thumb-debug.h"
24 #include "media-thumb-util.h"
25 #include "media-thumb-internal.h"
26 #include "media-thumb-ipc.h"
30 int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid)
32 int err = MS_MEDIA_ERR_NONE;
33 media_thumb_info thumb_info;
35 if (origin_path == NULL || thumb_path == NULL) {
36 thumb_err("Invalid parameter");
37 return MS_MEDIA_ERR_INVALID_PARAMETER;
40 if (origin_width == NULL || origin_height == NULL) {
41 thumb_err("Invalid parameter ( width or height )");
42 return MS_MEDIA_ERR_INVALID_PARAMETER;
45 if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
46 thumb_err("Original path(%s) doesn't exist.", origin_path);
47 return MS_MEDIA_ERR_INVALID_PARAMETER;
50 if (max_length <= 0) {
51 thumb_err("Length is invalid");
52 return MS_MEDIA_ERR_INVALID_PARAMETER;
56 store_type = _media_thumb_get_store_type_by_path(origin_path);
58 if ((store_type != THUMB_PHONE) && (store_type != THUMB_MMC)) {
59 thumb_err("origin path(%s) is invalid", origin_path);
60 return MS_MEDIA_ERR_INVALID_PARAMETER;
63 thumb_dbg_slog("Path : %s", origin_path);
65 /* Request for thumb file to the daemon "Thumbnail generator" */
66 err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, origin_path, thumb_path, max_length, &thumb_info, uid);
67 if (err != MS_MEDIA_ERR_NONE) {
68 thumb_err("_media_thumb_request failed : %d", err);
72 *origin_width = thumb_info.origin_width;
73 *origin_height = thumb_info.origin_height;
75 return MS_MEDIA_ERR_NONE;
78 int thumbnail_request_extract_all_thumbs(uid_t uid)
80 int err = MS_MEDIA_ERR_NONE;
82 media_thumb_info thumb_info;
83 char tmp_origin_path[MAX_PATH_SIZE] = {0,};
84 char tmp_thumb_path[MAX_PATH_SIZE] = {0,};
86 /* Request for thumb file to the daemon "Thumbnail generator" */
87 err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
88 if (err != MS_MEDIA_ERR_NONE) {
89 thumb_err("_media_thumb_request failed : %d", err);
93 return MS_MEDIA_ERR_NONE;
96 int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_path, ThumbFunc func, void *user_data, uid_t uid)
98 int err = MS_MEDIA_ERR_NONE;
100 if (origin_path == NULL) {
101 thumb_err("Invalid parameter");
102 return MS_MEDIA_ERR_INVALID_PARAMETER;
105 if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
106 thumb_err("Original path(%s) doesn't exist.", origin_path);
107 return MS_MEDIA_ERR_INVALID_PARAMETER;
111 store_type = _media_thumb_get_store_type_by_path(origin_path);
113 if ((store_type != THUMB_PHONE) && (store_type != THUMB_MMC)) {
114 thumb_err("origin path(%s) is invalid", origin_path);
115 return MS_MEDIA_ERR_INVALID_PARAMETER;
118 thumb_dbg_slog("Path : %s", origin_path);
120 thumbUserData *userData = (thumbUserData*)malloc(sizeof(thumbUserData));
121 if (userData == NULL) {
122 thumb_err("memory allocation failed");
123 return MS_MEDIA_ERR_OUT_OF_MEMORY;
125 userData->func = (ThumbFunc)func;
126 userData->user_data = user_data;
128 /* Request for thumb file to the daemon "Thumbnail generator" */
129 err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, request_id, origin_path, userData, uid);
130 if (err != MS_MEDIA_ERR_NONE) {
131 thumb_err("_media_thumb_request failed : %d", err);
136 return MS_MEDIA_ERR_NONE;
139 int thumbnail_request_extract_raw_data_async(int request_id, const char *origin_path, int width, int height, ThumbRawFunc func, void *user_data, uid_t uid)
141 int err = MS_MEDIA_ERR_NONE;
144 if (origin_path == NULL || request_id == 0) {
145 thumb_err("original path is NULL. Or there is an error in request_id.");
146 return MS_MEDIA_ERR_INVALID_PARAMETER;
149 /* check the file exits actually */
150 exist = open(origin_path, O_RDONLY);
152 thumb_err("Fail to open original_path[%s]", origin_path);
153 if (errno == EACCES || errno == EPERM)
154 return MS_MEDIA_ERR_PERMISSION_DENIED;
156 return MS_MEDIA_ERR_INVALID_PARAMETER;
160 thumb_dbg_slog("Path : %s", origin_path);
162 thumbRawUserData *userData = (thumbRawUserData*)malloc(sizeof(thumbRawUserData));
163 if (userData == NULL) {
164 thumb_err("userData malloc failed : %d", err);
165 return MS_MEDIA_ERR_OUT_OF_MEMORY;
167 userData->func = func;
168 userData->user_data = user_data;
170 err = _media_thumb_request_raw_data_async(THUMB_REQUEST_RAW_DATA, request_id, origin_path, width, height, userData, uid);
171 if (err != MS_MEDIA_ERR_NONE) {
172 thumb_err("_media_raw_thumb_request failed : %d", err);
177 return MS_MEDIA_ERR_NONE;
180 int thumbnail_request_cancel_media(unsigned int request_id, const char *origin_path)
182 int err = MS_MEDIA_ERR_NONE;
184 if (origin_path == NULL) {
185 thumb_err("Invalid parameter");
186 return MS_MEDIA_ERR_INVALID_PARAMETER;
189 err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, request_id, origin_path, NULL, 0);
190 if (err != MS_MEDIA_ERR_NONE) {
191 thumb_err("_media_thumb_request failed : %d", err);
195 return MS_MEDIA_ERR_NONE;
198 int thumbnail_request_cancel_raw_data(int request_id)
200 int err = MS_MEDIA_ERR_NONE;
202 if (request_id == 0) {
203 thumb_err("Invalid parameter");
204 return MS_MEDIA_ERR_INVALID_PARAMETER;
207 err = _media_thumb_request_raw_data_async(THUMB_REQUEST_CANCEL_RAW_DATA, request_id, NULL, 0, 0, NULL, 0);
208 if (err != MS_MEDIA_ERR_NONE) {
209 thumb_err("_media_thumb_request failed : %d", err);
213 return MS_MEDIA_ERR_NONE;
216 int thumbnail_request_cancel_all(bool is_raw_data)
218 int err = MS_MEDIA_ERR_NONE;
221 err = _media_thumb_request_cancel_all(true);
223 err = _media_thumb_request_cancel_all(false);