2 * media-thumbnail-server
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 "thumb-server-internal.h"
23 #include "media-thumb-util.h"
24 #include "media-thumb-debug.h"
31 #include <Ecore_Evas.h>
38 #define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
39 #define THUMB_DEFAULT_WIDTH 320
40 #define THUMB_DEFAULT_HEIGHT 240
41 #define THUMB_BLOCK_SIZE 512
42 #define THUMB_COMM_SOCK_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcomm.socket")
43 #define THUMB_EMPTY_STR ""
45 static __thread char **arr_path;
46 static __thread uid_t *arr_uid;
47 static __thread int g_idx = 0;
48 static __thread int g_cur_idx = 0;
50 GMainLoop *g_thumb_server_mainloop; // defined in thumb-server.c as extern
52 static gboolean __thumb_server_send_msg_to_agent(int msg_type);
53 static void __thumb_daemon_stop_job(void);
54 static int __thumb_daemon_all_extract(uid_t uid);
55 int _thumb_daemon_process_queue_jobs(gpointer data);
56 static gboolean _thumb_server_send_deny_message(int sockfd);
58 gboolean _thumb_daemon_start_jobs(gpointer data)
61 /* Initialize ecore-evas to use evas library */
64 __thumb_server_send_msg_to_agent(MS_MSG_THUMB_SERVER_READY);
69 void _thumb_daemon_finish_jobs(void)
71 sqlite3 *sqlite_db_handle = _media_thumb_db_get_handle();
73 if (sqlite_db_handle != NULL) {
74 _media_thumb_db_disconnect();
75 thumb_dbg("sqlite3 handle is alive. So disconnect to sqlite3");
78 /* Shutdown ecore-evas */
79 ecore_evas_shutdown();
80 g_main_loop_quit(g_thumb_server_mainloop);
85 int _thumb_daemon_mmc_status(void)
90 err = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &status);
93 } else if (err == -1) {
94 thumb_err("vconf_get_int failed : %d", err);
96 thumb_err("vconf_get_int Unexpected error code: %d", err);
102 void _thumb_daemon_mmc_eject_vconf_cb(void *data)
107 thumb_warn("_thumb_daemon_vconf_cb called");
109 err = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &status);
111 if (status == VCONFKEY_SYSMAN_MMC_REMOVED || status == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
112 thumb_warn("SD card is ejected or not mounted. So media-thumbnail-server stops jobs to extract all thumbnails");
114 __thumb_daemon_stop_job();
116 } else if (err == -1) {
117 thumb_err("vconf_get_int failed : %d", err);
119 thumb_err("vconf_get_int Unexpected error code: %d", err);
125 void _thumb_daemon_vconf_cb(void *data)
130 thumb_warn("_thumb_daemon_vconf_cb called");
132 err = vconf_get_int(VCONFKEY_SYSMAN_MMC_FORMAT, &status);
134 if (status == VCONFKEY_SYSMAN_MMC_FORMAT_COMPLETED) {
135 thumb_warn("SD card format is completed. So media-thumbnail-server stops jobs to extract all thumbnails");
137 __thumb_daemon_stop_job();
139 thumb_dbg("not completed");
141 } else if (err == -1) {
142 thumb_err("vconf_get_int failed : %d", err);
144 thumb_err("vconf_get_int Unexpected error code: %d", err);
150 static void __thumb_daemon_stop_job()
155 thumb_warn("There are %d jobs in the queue. But all jobs will be stopped", g_idx - g_cur_idx);
157 for (i = g_cur_idx; i < g_idx; i++) {
158 path = arr_path[g_cur_idx++];
165 int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
167 int err = MS_MEDIA_ERR_NONE;
169 err = _media_thumb_process(req_msg, res_msg);
170 if (err != MS_MEDIA_ERR_NONE)
171 thumb_warn("_media_thumb_process is failed: %d", err);
176 static int __thumb_daemon_process_job_raw(thumbMsg *req_msg, thumbMsg *res_msg)
178 int err = MS_MEDIA_ERR_NONE;
180 err = _media_thumb_process_raw(req_msg, res_msg);
181 if (err != MS_MEDIA_ERR_NONE)
182 thumb_warn("_media_thumb_process_raw is failed: %d", err);
187 static int __thumb_daemon_all_extract(uid_t uid)
189 int err = MS_MEDIA_ERR_NONE;
190 char query_string[MAX_PATH_SIZE + 1] = { 0, };
191 char path[MAX_PATH_SIZE + 1] = { 0, };
192 sqlite3 *sqlite_db_handle = NULL;
193 sqlite3_stmt *sqlite_stmt = NULL;
195 err = _media_thumb_db_connect(uid);
196 if (err != MS_MEDIA_ERR_NONE) {
197 thumb_err("_media_thumb_db_connect failed: %d", err);
201 sqlite_db_handle = _media_thumb_db_get_handle();
202 if (sqlite_db_handle == NULL) {
203 thumb_err("sqlite handle is NULL");
204 return MS_MEDIA_ERR_INTERNAL;
207 if (_thumb_daemon_mmc_status() == VCONFKEY_SYSMAN_MMC_MOUNTED) {
208 snprintf(query_string, sizeof(query_string), SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA);
210 snprintf(query_string, sizeof(query_string), SELECT_PATH_FROM_UNEXTRACTED_THUMB_INTERNAL_MEDIA);
213 thumb_warn("Query: %s", query_string);
215 err = sqlite3_prepare_v2(sqlite_db_handle, query_string, strlen(query_string), &sqlite_stmt, NULL);
216 if (SQLITE_OK != err) {
217 thumb_err("prepare error [%s]", sqlite3_errmsg(sqlite_db_handle));
218 _media_thumb_db_disconnect();
219 return MS_MEDIA_ERR_INTERNAL;
223 err = sqlite3_step(sqlite_stmt);
224 if (err != SQLITE_ROW) {
225 thumb_dbg("end of row [%s]", sqlite3_errmsg(sqlite_db_handle));
229 strncpy(path, (const char *)sqlite3_column_text(sqlite_stmt, 0), sizeof(path));
230 path[sizeof(path) - 1] = '\0';
232 thumb_dbg_slog("Path : %s", path);
235 arr_path = (char**)malloc(sizeof(char*));
236 arr_uid = (uid_t*)malloc(sizeof(uid_t));
238 arr_path = (char**)realloc(arr_path, (g_idx + 1) * sizeof(char*));
239 arr_uid = (uid_t*)realloc(arr_uid, (g_idx + 1) * sizeof(uid_t));
241 arr_uid[g_idx] = uid;
242 arr_path[g_idx++] = strdup(path);
245 sqlite3_finalize(sqlite_stmt);
246 _media_thumb_db_disconnect();
248 return MS_MEDIA_ERR_NONE;
251 int _thumb_daemon_process_queue_jobs(gpointer data)
253 int err = MS_MEDIA_ERR_NONE;
257 if (g_cur_idx < g_idx) {
258 thumb_warn("There are %d jobs in the queue", g_idx - g_cur_idx);
259 thumb_dbg("Current idx : [%d]", g_cur_idx);
260 uid = arr_uid[g_cur_idx];
261 path = arr_path[g_cur_idx++];
263 thumbMsg recv_msg, res_msg;
264 memset(&recv_msg, 0x00, sizeof(thumbMsg));
265 memset(&res_msg, 0x00, sizeof(thumbMsg));
267 recv_msg.msg_type = THUMB_REQUEST_DB_INSERT;
269 strncpy(recv_msg.org_path, path, sizeof(recv_msg.org_path));
270 recv_msg.org_path[sizeof(recv_msg.org_path) - 1] = '\0';
272 err = _thumb_daemon_process_job(&recv_msg, &res_msg);
273 if (err != MS_MEDIA_ERR_NONE)
274 thumb_err("Thumbnail processing is failed : %d", err);
280 thumb_warn("Deleting array");
283 //_media_thumb_db_disconnect();
285 __thumb_server_send_msg_to_agent(MS_MSG_THUMB_EXTRACT_ALL_DONE); // MS_MSG_THUMB_EXTRACT_ALL_DONE
293 gboolean _thumb_server_read_socket(GIOChannel *src,
294 GIOCondition condition,
297 struct sockaddr_un client_addr;
298 unsigned int client_addr_len;
301 ms_peer_credentials credentials;
304 int client_sock = -1;
306 memset((void *)&recv_msg, 0, sizeof(recv_msg));
307 memset((void *)&res_msg, 0, sizeof(res_msg));
308 memset((void *)&credentials, 0, sizeof(credentials));
310 sock = g_io_channel_unix_get_fd(src);
312 thumb_err("sock fd is invalid!");
316 client_addr_len = sizeof(client_addr);
318 if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
319 thumb_stderror("accept failed : %s");
323 if (ms_cynara_receive_untrusted_message_thumb(client_sock, &recv_msg, &credentials) != MS_MEDIA_ERR_NONE) {
324 thumb_err("ms_cynara_receive_untrusted_message_thumb failed");
329 if (recv_msg.msg_type != THUMB_REQUEST_KILL_SERVER) {
330 if (ms_cynara_check(&credentials, MEDIA_STORAGE_PRIVILEGE) != MS_MEDIA_ERR_NONE) {
331 thumb_err("Cynara denied access to process request");
332 _thumb_server_send_deny_message(client_sock);
338 SAFE_FREE(credentials.smack);
339 SAFE_FREE(credentials.uid);
341 thumb_warn_slog("Received [%d] %s(%d) from PID(%d)", recv_msg.msg_type, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
343 if (recv_msg.msg_type == THUMB_REQUEST_ALL_MEDIA) {
344 thumb_dbg("All thumbnails are being extracted now");
345 __thumb_daemon_all_extract(recv_msg.uid);
346 g_idle_add(_thumb_daemon_process_queue_jobs, NULL);
347 } else if (recv_msg.msg_type == THUMB_REQUEST_RAW_DATA) {
348 __thumb_daemon_process_job_raw(&recv_msg, &res_msg);
349 } else if (recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
350 thumb_warn("received KILL msg from thumbnail agent.");
352 _thumb_daemon_process_job(&recv_msg, &res_msg);
355 if (res_msg.msg_type == 0)
356 res_msg.msg_type = recv_msg.msg_type;
357 res_msg.request_id = recv_msg.request_id;
358 strncpy(res_msg.org_path, recv_msg.org_path, recv_msg.origin_path_size);
359 res_msg.origin_path_size = recv_msg.origin_path_size;
360 if (res_msg.msg_type != THUMB_RESPONSE_RAW_DATA) {
361 res_msg.dest_path_size = strlen(res_msg.dst_path)+1;
362 res_msg.thumb_size = 0;
364 res_msg.dest_path_size = 1;
365 res_msg.dst_path[0] = '\0';
369 int sending_block = 0;
370 int block_size = sizeof(res_msg) - MAX_FILEPATH_LEN*2 - sizeof(unsigned char *);
371 unsigned char *buf = NULL;
372 _media_thumb_set_buffer(&res_msg, &buf, &buf_size);
374 while (buf_size > 0) {
375 if (buf_size < THUMB_BLOCK_SIZE) {
376 block_size = buf_size;
378 if (send(client_sock, buf+sending_block, block_size, 0) != block_size) {
379 thumb_stderror("sendto failed : %s");
381 sending_block += block_size;
382 buf_size -= block_size;
383 if (block_size < THUMB_BLOCK_SIZE) {
384 block_size = THUMB_BLOCK_SIZE;
388 thumb_dbg_slog("Sent data(%d) from %s", res_msg.thumb_size, res_msg.org_path);
391 SAFE_FREE(res_msg.thumb_data);
393 if (recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
394 thumb_warn("Shutting down...");
395 g_main_loop_quit(g_thumb_server_mainloop);
403 static gboolean __thumb_server_send_msg_to_agent(int msg_type)
406 ms_sock_info_s sock_info;
407 struct sockaddr_un serv_addr;
408 ms_thumb_server_msg send_msg;
409 sock_info.port = MS_THUMB_COMM_PORT;
411 if (ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock_info) < 0) {
412 thumb_err("ms_ipc_create_server_socket failed");
416 memset(&serv_addr, 0, sizeof(serv_addr));
418 sock = sock_info.sock_fd;
419 serv_addr.sun_family = AF_UNIX;
420 strncpy(serv_addr.sun_path, THUMB_COMM_SOCK_PATH, strlen(THUMB_COMM_SOCK_PATH));
423 /* Connecting to the thumbnail server */
424 if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
425 thumb_stderror("connect");
426 ms_ipc_delete_client_socket(&sock_info);
427 return MS_MEDIA_ERR_SOCKET_CONN;
430 send_msg.msg_type = msg_type;
432 if (send(sock, &send_msg, sizeof(ms_thumb_server_msg), 0) != sizeof(ms_thumb_server_msg)) {
433 thumb_stderror("sendto failed");
434 ms_ipc_delete_client_socket(&sock_info);
438 thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type);
440 ms_ipc_delete_client_socket(&sock_info);
445 static gboolean _thumb_server_send_deny_message(int sockfd)
448 int bytes_to_send = sizeof(msg) - sizeof(msg.org_path) - sizeof(msg.dst_path);
450 msg.msg_type = THUMB_RESPONSE;
451 msg.status = MS_MEDIA_ERR_PERMISSION_DENIED;
453 if (send(sockfd, &msg, bytes_to_send, 0) != bytes_to_send) {
454 thumb_stderror("send failed");
461 gboolean _thumb_server_prepare_socket(int *sock_fd)
464 unsigned short serv_port;
469 memset((void *)&recv_msg, 0, sizeof(recv_msg));
470 memset((void *)&res_msg, 0, sizeof(res_msg));
471 serv_port = MS_THUMB_DAEMON_PORT;
473 if (ms_ipc_create_server_socket(serv_port, &sock) < 0) {
474 thumb_err("ms_ipc_create_server_socket failed");
478 if (ms_cynara_enable_credentials_passing(sock) != MS_MEDIA_ERR_NONE) {
479 thumb_err("ms_cynara_enable_credentials_passing failed");
489 int _thumbnail_get_data(const char *origin_path,
490 media_thumb_format format,
492 unsigned char **data,
501 int err = MS_MEDIA_ERR_NONE;
502 int thumb_width = -1;
503 int thumb_height = -1;
505 if (origin_path == NULL || size == NULL
506 || width == NULL || height == NULL) {
507 thumb_err("Invalid parameter");
508 return MS_MEDIA_ERR_INVALID_PARAMETER;
511 if (format < MEDIA_THUMB_BGRA || format > MEDIA_THUMB_RGB888) {
512 thumb_err("parameter format is invalid");
513 return MS_MEDIA_ERR_INVALID_PARAMETER;
517 (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
518 thumb_err("Original path (%s) does not exist", origin_path);
519 return MS_MEDIA_ERR_INVALID_PARAMETER;
522 thumb_dbg("Origin path : %s", origin_path);
524 int file_type = THUMB_NONE_TYPE;
525 media_thumb_info thumb_info = {0,};
526 file_type = _media_thumb_get_file_type(origin_path);
527 thumb_width = *width;
528 thumb_height = *height;
529 if (thumb_width == 0 || thumb_height == 0) {
530 thumb_width = THUMB_DEFAULT_WIDTH;
531 thumb_height = THUMB_DEFAULT_HEIGHT;
534 thumb_info.is_raw = FALSE;
536 if (file_type == THUMB_IMAGE_TYPE) {
537 err = _media_thumb_image(origin_path, thumb_path, thumb_width, thumb_height, format, &thumb_info);
538 if (err != MS_MEDIA_ERR_NONE) {
539 thumb_err("_media_thumb_image failed");
542 } else if (file_type == THUMB_VIDEO_TYPE) {
543 err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info);
544 if (err != MS_MEDIA_ERR_NONE) {
545 thumb_err("_media_thumb_image failed");
549 thumb_err("invalid file type");
550 return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
553 if (size) *size = thumb_info.size;
554 if (width) *width = thumb_info.width;
555 if (height) *height = thumb_info.height;
556 *data = thumb_info.data;
557 if (origin_width) *origin_width = thumb_info.origin_width;
558 if (origin_height) *origin_height = thumb_info.origin_height;
559 if (alpha) *alpha = thumb_info.alpha;
560 if (is_saved) *is_saved = thumb_info.is_saved;
562 thumb_dbg("Thumb data is generated successfully (Size:%d, W:%d, H:%d) 0x%x", *size, *width, *height, *data);
564 return MS_MEDIA_ERR_NONE;
567 int _thumbnail_get_raw_data(const char *origin_path,
568 media_thumb_format format,
571 unsigned char **data,
574 int err = MS_MEDIA_ERR_NONE;
575 int thumb_width = -1;
576 int thumb_height = -1;
577 const char * thumb_path = NULL;
579 if (origin_path == NULL || *width <= 0 || *height <= 0) {
580 thumb_err("Invalid parameter");
581 return MS_MEDIA_ERR_INVALID_PARAMETER;
584 if (format < MEDIA_THUMB_BGRA || format > MEDIA_THUMB_RGB888) {
585 thumb_err("parameter format is invalid");
586 return MS_MEDIA_ERR_INVALID_PARAMETER;
589 if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
590 thumb_err("Original path (%s) does not exist", origin_path);
591 return MS_MEDIA_ERR_INVALID_PARAMETER;
594 int file_type = THUMB_NONE_TYPE;
595 media_thumb_info thumb_info = {0,};
596 file_type = _media_thumb_get_file_type(origin_path);
597 thumb_width = *width;
598 thumb_height = *height;
599 thumb_info.is_raw = TRUE;
601 if (file_type == THUMB_IMAGE_TYPE) {
602 err = _media_thumb_image(origin_path, thumb_path, thumb_width, thumb_height, format, &thumb_info);
603 if (err != MS_MEDIA_ERR_NONE) {
604 thumb_err("_media_thumb_image failed");
607 } else if (file_type == THUMB_VIDEO_TYPE) {
608 err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info);
609 if (err != MS_MEDIA_ERR_NONE) {
610 thumb_err("_media_thumb_image failed");
614 thumb_err("invalid file type");
615 return MS_MEDIA_ERR_INVALID_PARAMETER;
618 if (size) *size = thumb_info.size;
619 *data = thumb_info.data;
620 *width = thumb_info.width;
621 *height = thumb_info.height;
623 return MS_MEDIA_ERR_NONE;
626 int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
628 int err = MS_MEDIA_ERR_NONE;
629 unsigned char *data = NULL;
636 char *thumb_path = NULL;
637 int need_update_db = 0;
639 bool is_saved = FALSE;
641 if (req_msg == NULL || res_msg == NULL) {
642 thumb_err("Invalid msg!");
643 return MS_MEDIA_ERR_INVALID_PARAMETER;
646 int msg_type = req_msg->msg_type;
647 const char *origin_path = req_msg->org_path;
649 media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
650 thumb_w = req_msg->thumb_width;
651 thumb_h = req_msg->thumb_height;
652 thumb_path = res_msg->dst_path;
653 thumb_path[0] = '\0';
654 max_length = sizeof(res_msg->dst_path) -1;
655 res_msg->status = MS_MEDIA_ERR_NONE;
657 if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
658 thumb_err("origin_path does not exist in file system.");
659 res_msg->status = MS_MEDIA_ERR_FILE_NOT_EXIST;
660 return MS_MEDIA_ERR_FILE_NOT_EXIST;
663 err = _media_thumb_db_connect(req_msg->uid);
664 if (err != MS_MEDIA_ERR_NONE) {
665 thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
666 res_msg->status = MS_MEDIA_ERR_DB_CONNECT_FAIL;
670 if (msg_type == THUMB_REQUEST_DB_INSERT) {
671 err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, max_length, &need_update_db, &origin_w, &origin_h);
672 if (err == MS_MEDIA_ERR_NONE) {
673 res_msg->origin_width = origin_w;
674 res_msg->origin_height = origin_h;
675 _media_thumb_db_disconnect();
676 return MS_MEDIA_ERR_NONE;
678 if (strlen(thumb_path) == 0) {
679 err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length, req_msg->uid);
680 if (err != MS_MEDIA_ERR_NONE) {
681 thumb_err("_media_thumb_get_hash_name failed - %d", err);
682 strncpy(thumb_path, THUMB_EMPTY_STR, max_length);
683 _media_thumb_db_disconnect();
684 res_msg->status = err;
688 thumb_path[strlen(thumb_path)] = '\0';
692 } else if (msg_type == THUMB_REQUEST_ALL_MEDIA) {
693 err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length, req_msg->uid);
694 if (err != MS_MEDIA_ERR_NONE) {
695 thumb_err("_media_thumb_get_hash_name failed - %d", err);
696 strncpy(thumb_path, THUMB_EMPTY_STR, max_length);
697 _media_thumb_db_disconnect();
698 res_msg->status = err;
702 thumb_path[strlen(thumb_path)] = '\0';
705 thumb_dbg_slog("Thumb path : %s", thumb_path);
707 if (g_file_test(thumb_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
708 thumb_warn("thumb path already exists in file system.. remove the existed file");
709 _media_thumb_remove_file(thumb_path);
712 err = _thumbnail_get_data(origin_path, thumb_format, thumb_path, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, &is_saved);
713 if (err != MS_MEDIA_ERR_NONE) {
714 thumb_err("_thumbnail_get_data failed - %d", err);
716 strncpy(thumb_path, THUMB_EMPTY_STR, max_length);
717 res_msg->status = err;
722 res_msg->msg_type = THUMB_RESPONSE;
723 res_msg->thumb_size = thumb_size;
724 res_msg->thumb_width = thumb_w;
725 res_msg->thumb_height = thumb_h;
726 res_msg->origin_width = origin_w;
727 res_msg->origin_height = origin_h;
729 /* If the image is transparent PNG format, make png file as thumbnail of this image */
732 err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext));
733 if (strncasecmp(file_ext, "png", 3) == 0) {
734 int len = strlen(thumb_path);
735 thumb_path[len - 3] = 'p';
736 thumb_path[len - 2] = 'n';
737 thumb_path[len - 1] = 'g';
739 thumb_dbg_slog("Thumb path is changed : %s", thumb_path);
742 if (is_saved == FALSE && data != NULL) {
743 err = _media_thumb_save_to_file_with_evas(data, thumb_w, thumb_h, alpha, thumb_path);
744 if (err != MS_MEDIA_ERR_NONE) {
745 thumb_err("save_to_file_with_evas failed - %d", err);
748 if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA) {
749 strncpy(thumb_path, THUMB_EMPTY_STR, max_length);
751 _media_thumb_db_disconnect();
752 res_msg->status = err;
755 thumb_dbg("file save success");
758 thumb_dbg("file is already saved");
763 fd = open(thumb_path, O_WRONLY);
765 thumb_warn("open failed");
769 thumb_warn("fsync failed");
770 res_msg->status = MS_MEDIA_ERR_INTERNAL;
779 /* DB update if needed */
780 if (need_update_db == 1) {
781 err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height, req_msg->uid);
782 if (err != MS_MEDIA_ERR_NONE) {
783 thumb_err("_media_thumb_update_db failed : %d", err);
784 res_msg->status = err;
788 _media_thumb_db_disconnect();
794 _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg)
796 int err = MS_MEDIA_ERR_NONE;
797 unsigned char *data = NULL;
802 if (req_msg == NULL || res_msg == NULL) {
803 thumb_err("Invalid msg!");
804 return MS_MEDIA_ERR_INVALID_PARAMETER;
807 const char *origin_path = req_msg->org_path;
809 media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
810 thumb_w = req_msg->thumb_width;
811 thumb_h = req_msg->thumb_height;
812 res_msg->status = MS_MEDIA_ERR_NONE;
814 err = _thumbnail_get_raw_data(origin_path, thumb_format, &thumb_w, &thumb_h, &data, &thumb_size);
816 if (err != MS_MEDIA_ERR_NONE) {
817 thumb_err("_thumbnail_get_data failed - %d", err);
818 res_msg->status = err;
822 res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
823 res_msg->thumb_width = thumb_w;
824 res_msg->thumb_height = thumb_h;
825 res_msg->thumb_size = thumb_size;
826 res_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
827 memcpy(res_msg->thumb_data, data, thumb_size);