4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>,
7 * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
31 #include <unicode/ucsdet.h>
34 #include <tzplatform_config.h>
35 #include "mm_player_utils.h"
37 #define MEDIA_PATH_EXTERNAL tzplatform_getenv(TZ_SYS_STORAGE) /* external storage, sd card, usb */
39 int util_exist_file_path(const char *file_path)
42 struct stat stat_results = {0, };
44 if (!file_path || !strlen(file_path))
45 return MM_ERROR_PLAYER_FILE_NOT_FOUND;
47 fd = open(file_path, O_RDONLY);
51 strerror_r(errno, str_error, sizeof(str_error));
52 LOGE("failed to open file by %s (%d)", str_error, errno);
55 return MM_ERROR_PLAYER_PERMISSION_DENIED;
57 return MM_ERROR_PLAYER_FILE_NOT_FOUND;
60 if (fstat(fd, &stat_results) < 0) {
61 LOGE("failed to get file status");
62 } else if (stat_results.st_size == 0) {
63 LOGE("file size is zero");
65 return MM_ERROR_PLAYER_FILE_NOT_FOUND;
67 LOGW("file size : %lld bytes", (long long)stat_results.st_size);
75 util_get_cookie_list(const char *cookies)
77 char **cookie_list = NULL;
81 if (!cookies || !strlen(cookies))
84 SECURE_LOGD("cookies : %d[bytes] - %s \n", strlen(cookies), cookies);
86 temp = g_strdup(cookies);
88 /* trimming. it works inplace */
92 cookie_list = g_strsplit(temp, ";", 100);
94 for (i = 0; i < g_strv_length(cookie_list); i++) {
96 if (strlen(cookie_list[i])) {
97 g_strstrip(cookie_list[i]);
98 SECURE_LOGD("cookie_list[%d] : %d[bytes] - %s \n", i, strlen(cookie_list[i]), cookie_list[i]);
100 cookie_list[i][0] = '\0';
111 /* check the given path is indicating sdp file */
113 util_is_sdp_file(const char *path)
115 gboolean ret = FALSE;
120 MMPLAYER_RETURN_VAL_IF_FAIL(path, FALSE);
122 uri = g_ascii_strdown(path, -1);
130 /* strlen(".sdp") == 4 */
131 if (strlen(uri) <= 4) {
132 LOGW("path is too short.\n");
137 /* first, check extension name */
138 ret = g_str_has_suffix(uri, "sdp");
140 /* second, if no suffix is there, check it's contents */
142 /* FIXIT : do it soon */
152 util_get_charset(const char *file_path)
154 UCharsetDetector* ucsd;
155 const UCharsetMatch* ucm;
156 UErrorCode status = U_ZERO_ERROR;
158 const char* charset = NULL;
163 fin = fopen(file_path, "r");
165 SECURE_LOGE("fail to open file %s\n", file_path);
169 ucsd = ucsdet_open(&status);
170 if (U_FAILURE(status)) {
171 LOGE("fail to ucsdet_open\n");
175 ucsdet_enableInputFilter(ucsd, TRUE);
177 buf = g_malloc(1024*1024);
179 LOGE("fail to alloc\n");
183 n_size = fread(buf, 1, 1024*1024, fin);
184 buf[1024 * 1024 - 1] = '\0';
188 ucsdet_setText(ucsd, buf, strlen(buf), &status);
189 if (U_FAILURE(status)) {
190 LOGE("fail to ucsdet_setText\n");
194 ucm = ucsdet_detect(ucsd, &status);
195 if (U_FAILURE(status)) {
196 LOGE("fail to ucsdet_detect\n");
200 charset = ucsdet_getName(ucm, &status);
201 if (U_FAILURE(status)) {
202 LOGE("fail to ucsdet_getName\n");
206 /* CP949 encoding is an extension of the EUC-KR and it is backwards compatible.*/
207 if (charset && !strcmp(charset, "EUC-KR"))
223 int util_get_pixtype(unsigned int fourcc)
225 int pixtype = MM_PIXEL_FORMAT_INVALID;
228 char *pfourcc = (char*)&fourcc;
230 LOGD("fourcc(%c%c%c%c)",
231 pfourcc[0], pfourcc[1], pfourcc[2], pfourcc[3]);
235 case GST_MAKE_FOURCC('S', 'N', '1', '2'):
236 case GST_MAKE_FOURCC('N', 'V', '1', '2'):
237 pixtype = MM_PIXEL_FORMAT_NV12;
239 case GST_MAKE_FOURCC('S', 'T', '1', '2'):
240 pixtype = MM_PIXEL_FORMAT_NV12T;
242 case GST_MAKE_FOURCC('S', 'N', '2', '1'):
243 case GST_MAKE_FOURCC('N', 'V', '2', '1'):
244 pixtype = MM_PIXEL_FORMAT_NV21;
246 case GST_MAKE_FOURCC('S', 'U', 'Y', 'V'):
247 case GST_MAKE_FOURCC('Y', 'U', 'Y', 'V'):
248 case GST_MAKE_FOURCC('Y', 'U', 'Y', '2'):
249 pixtype = MM_PIXEL_FORMAT_YUYV;
251 case GST_MAKE_FOURCC('S', 'Y', 'V', 'Y'):
252 case GST_MAKE_FOURCC('U', 'Y', 'V', 'Y'):
253 pixtype = MM_PIXEL_FORMAT_UYVY;
255 case GST_MAKE_FOURCC('S', '4', '2', '0'):
256 case GST_MAKE_FOURCC('I', '4', '2', '0'):
257 pixtype = MM_PIXEL_FORMAT_I420;
259 case GST_MAKE_FOURCC('Y', 'V', '1', '2'):
260 pixtype = MM_PIXEL_FORMAT_YV12;
262 case GST_MAKE_FOURCC('4', '2', '2', 'P'):
263 pixtype = MM_PIXEL_FORMAT_422P;
265 case GST_MAKE_FOURCC('R', 'G', 'B', 'P'):
266 pixtype = MM_PIXEL_FORMAT_RGB565;
268 case GST_MAKE_FOURCC('R', 'G', 'B', '3'):
269 pixtype = MM_PIXEL_FORMAT_RGB888;
271 case GST_MAKE_FOURCC('A', 'R', 'G', 'B'):
272 case GST_MAKE_FOURCC('x', 'R', 'G', 'B'):
273 pixtype = MM_PIXEL_FORMAT_ARGB;
275 case GST_MAKE_FOURCC('B', 'G', 'R', 'A'):
276 case GST_MAKE_FOURCC('B', 'G', 'R', 'x'):
277 case GST_MAKE_FOURCC('S', 'R', '3', '2'):
278 pixtype = MM_PIXEL_FORMAT_RGBA;
280 case GST_MAKE_FOURCC('J', 'P', 'E', 'G'):
281 case GST_MAKE_FOURCC('P', 'N', 'G', ' '):
282 pixtype = MM_PIXEL_FORMAT_ENCODED;
284 case GST_MAKE_FOURCC('I', 'T', 'L', 'V'):
285 pixtype = MM_PIXEL_FORMAT_ITLV_JPEG_UYVY;
288 LOGE("Not supported fourcc type(%c%c%c%c)",
289 fourcc, fourcc>>8, fourcc>>16, fourcc>>24);
290 pixtype = MM_PIXEL_FORMAT_INVALID;
297 static int _util_storage_supported_cb(int storage_id, storage_type_e type,
298 storage_state_e state, const char *path, void *user_data)
300 MMPlayerStorageInfo *storage_info = (MMPlayerStorageInfo *)user_data;
302 MMPLAYER_RETURN_VAL_IF_FAIL(storage_info, FALSE);
304 if (type == storage_info->type && strstr(storage_info->path, path)) {
305 storage_info->id = storage_id;
306 storage_info->state = state;
313 bool util_get_storage_info(const char *path, MMPlayerStorageInfo *storage_info)
316 const char *file_path = path;
318 MMPLAYER_RETURN_VAL_IF_FAIL(file_path && storage_info, false);
320 if (strncmp(file_path, "file://", strlen("file://")) == 0)
321 file_path = path+7; /* remove file prefix */
323 if (strncmp(file_path, MEDIA_PATH_EXTERNAL, strlen(MEDIA_PATH_EXTERNAL)) == 0) {
324 storage_info->type = STORAGE_TYPE_EXTERNAL;
326 memset(storage_info->path, 0x00, MM_MAX_URL_LEN);
327 g_snprintf(storage_info->path, MM_MAX_URL_LEN, "%s", file_path);
329 ret = storage_foreach_device_supported((storage_device_supported_cb)_util_storage_supported_cb, storage_info);
330 if (ret != STORAGE_ERROR_NONE) {
331 LOGE("failed to check supported storage 0x%x", ret);
335 if (storage_info->state <= STORAGE_STATE_REMOVED) {
336 LOGE("need to check the external storage state %d:%d", storage_info->id, storage_info->state);
340 storage_info->type = STORAGE_TYPE_INTERNAL;
341 storage_info->state = STORAGE_STATE_MOUNTED;
344 LOGD("storage info %d:%d:%d", storage_info->type, storage_info->id, storage_info->state);