/* * libmedia-thumbnail * * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Hyunjun Ko * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include "media-thumbnail.h" #include "media-thumb-debug.h" #include "media-thumb-util.h" #include "media-thumb-internal.h" #include "media-thumb-ipc.h" #include int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid) { int err = MS_MEDIA_ERR_NONE; if (origin_path == NULL || thumb_path == NULL) { thumb_err("Invalid parameter"); return MS_MEDIA_ERR_INVALID_PARAMETER; } if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { thumb_err("Original path(%s) doesn't exist.", origin_path); return MS_MEDIA_ERR_INVALID_PARAMETER; } if (max_length <= 0) { thumb_err("Length is invalid"); return MS_MEDIA_ERR_INVALID_PARAMETER; } ms_user_storage_type_e store_type = -1; err = ms_user_get_storage_type(uid, origin_path, &store_type); if((err != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) { thumb_err_slog("origin path(%s) is invalid. err : [%d] store_type [%d]", origin_path, err, store_type); return MS_MEDIA_ERR_INVALID_PARAMETER; } thumb_dbg_slog("Path : %s", origin_path); /* Request for thumb file to the daemon "Thumbnail generator" */ err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, origin_path, thumb_path, max_length, uid); if (err != MS_MEDIA_ERR_NONE) { thumb_err("_media_thumb_request failed : %d", err); return err; } return MS_MEDIA_ERR_NONE; } int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_path, ThumbFunc func, void *user_data, uid_t uid) { int err = MS_MEDIA_ERR_NONE; if (origin_path == NULL) { thumb_err("Invalid parameter"); return MS_MEDIA_ERR_INVALID_PARAMETER; } if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { thumb_err("Original path(%s) doesn't exist.", origin_path); return MS_MEDIA_ERR_INVALID_PARAMETER; } ms_user_storage_type_e store_type = -1; err = ms_user_get_storage_type(uid, origin_path, &store_type); if((err != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) { thumb_err_slog("origin path(%s) is invalid. err : [%d] store_type [%d]", origin_path, err, store_type); return MS_MEDIA_ERR_INVALID_PARAMETER; } thumb_dbg_slog("Path : %s", origin_path); thumbUserData *userData = (thumbUserData*)malloc(sizeof(thumbUserData)); if (userData == NULL) { thumb_err("memory allocation failed"); return MS_MEDIA_ERR_OUT_OF_MEMORY; } userData->func = (ThumbFunc)func; userData->user_data = user_data; /* Request for thumb file to the daemon "Thumbnail generator" */ err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, request_id, origin_path, userData, uid); if (err != MS_MEDIA_ERR_NONE) { thumb_err("_media_thumb_request failed : %d", err); SAFE_FREE(userData); return err; } return MS_MEDIA_ERR_NONE; } 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) { int err = MS_MEDIA_ERR_NONE; int exist = 0; if (origin_path == NULL || request_id == 0) { thumb_err("original path is NULL. Or there is an error in request_id."); return MS_MEDIA_ERR_INVALID_PARAMETER; } /* check the file exits actually */ exist = open(origin_path, O_RDONLY); if (exist < 0) { thumb_err("Fail to open original_path[%s]", origin_path); if (errno == EACCES || errno == EPERM) return MS_MEDIA_ERR_PERMISSION_DENIED; else return MS_MEDIA_ERR_INVALID_PARAMETER; } close(exist); thumb_dbg_slog("Path : %s", origin_path); thumbRawUserData *userData = (thumbRawUserData*)malloc(sizeof(thumbRawUserData)); if (userData == NULL) { thumb_err("userData malloc failed : %d", err); return MS_MEDIA_ERR_OUT_OF_MEMORY; } userData->func = func; userData->user_data = user_data; err = _media_thumb_request_raw_data_async(THUMB_REQUEST_RAW_DATA, request_id, origin_path, width, height, userData, uid); if (err != MS_MEDIA_ERR_NONE) { thumb_err("_media_raw_thumb_request failed : %d", err); SAFE_FREE(userData); return err; } return MS_MEDIA_ERR_NONE; } int thumbnail_request_cancel_media(unsigned int request_id) { int err = MS_MEDIA_ERR_NONE; err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, request_id, NULL, NULL, 0); if (err != MS_MEDIA_ERR_NONE) { thumb_err("_media_thumb_request failed : %d", err); return err; } return MS_MEDIA_ERR_NONE; } int thumbnail_request_cancel_raw_data(int request_id) { int err = MS_MEDIA_ERR_NONE; if (request_id == 0) { thumb_err("Invalid parameter"); return MS_MEDIA_ERR_INVALID_PARAMETER; } err = _media_thumb_request_raw_data_async(THUMB_REQUEST_CANCEL_RAW_DATA, request_id, NULL, 0, 0, NULL, 0); if (err != MS_MEDIA_ERR_NONE) { thumb_err("_media_thumb_request failed : %d", err); return err; } return MS_MEDIA_ERR_NONE; } int thumbnail_request_cancel_all() { return _media_thumb_request_cancel_all(); }