1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*
* libmedia-thumbnail
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Hyunjun Ko <zzoon.ko@samsung.com>
*
* 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-thumb-util.h"
#include "media-thumb-internal.h"
#include "media-thumb-debug.h"
#include <glib.h>
#include <aul.h>
#include <string.h>
int
_media_thumb_get_file_type(const char *file_full_path)
{
int ret = 0;
char mimetype[255] = {0,};
const char *unsupported_type = "image/tiff";
const char *supported_type = "application/vnd.ms-asf";
if (file_full_path == NULL)
return MS_MEDIA_ERR_INVALID_PARAMETER;
/* get content type and mime type from file. */
ret = aul_get_mime_from_file(file_full_path, mimetype, sizeof(mimetype));
if (ret < 0) {
thumb_warn
("aul_get_mime_from_file fail.. Now trying to get type by extension");
char ext[255] = { 0 };
ret = _media_thumb_get_file_ext(file_full_path, ext, sizeof(ext));
if (ret < 0) {
thumb_err("_media_thumb_get_file_ext failed");
return THUMB_NONE_TYPE;
}
if (strcasecmp(ext, "JPG") == 0 ||
strcasecmp(ext, "JPEG") == 0 ||
strcasecmp(ext, "PNG") == 0 ||
strcasecmp(ext, "GIF") == 0 ||
strcasecmp(ext, "AGIF") == 0 ||
strcasecmp(ext, "XWD") == 0 ||
strcasecmp(ext, "BMP") == 0 ||
strcasecmp(ext, "WBMP") == 0) {
return THUMB_IMAGE_TYPE;
} else if (strcasecmp(ext, "AVI") == 0 ||
strcasecmp(ext, "MPEG") == 0 ||
strcasecmp(ext, "MP4") == 0 ||
strcasecmp(ext, "DCF") == 0 ||
strcasecmp(ext, "WMV") == 0 ||
strcasecmp(ext, "3GPP") == 0 ||
strcasecmp(ext, "3GP") == 0) {
return THUMB_VIDEO_TYPE;
} else {
return THUMB_NONE_TYPE;
}
}
thumb_dbg("mime type : %s", mimetype);
/* categorize from mimetype */
if (strstr(mimetype, "image") != NULL) {
if (!strcmp(mimetype, unsupported_type)) {
thumb_warn("This is unsupport file type");
return THUMB_NONE_TYPE;
}
return THUMB_IMAGE_TYPE;
} else if (strstr(mimetype, "video") != NULL) {
return THUMB_VIDEO_TYPE;
} else if (strstr(mimetype, supported_type) != NULL) {
return THUMB_VIDEO_TYPE;
}
return THUMB_NONE_TYPE;
}
int _media_thumb_remove_file(const char *path)
{
int result = -1;
result = remove(path);
if (result == 0) {
thumb_dbg("success to remove file");
return TRUE;
} else {
thumb_stderror("fail to remove file");
return FALSE;
}
}
int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len)
{
int i = 0;
for (i = (int)strlen(file_path); i >= 0; i--) {
if ((file_path[i] == '.') && (i < (int)strlen(file_path))) {
strncpy(file_ext, &file_path[i + 1], max_len);
return 0;
}
/* meet the dir. no ext */
if (file_path[i] == '/') {
return -1;
}
}
return -1;
}
|