2 * To apply the Flora License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
4 * Copyright [2012] [JongDong Lee <jongdong.lee@samsung.com>, ChangSun Lee <cs78.lee@samsung.com>]
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <libexif/exif-data.h>
22 #include <metadata_extractor.h>
24 #include <unicode/udat.h>
25 #include <unicode/ustring.h>
26 #include <unicode/uloc.h>
27 #include <unicode/ucal.h>
28 #include <unicode/udatpg.h>
29 #include <unicode/utmscale.h>
32 #include "mp-drm-ctrl.h"
33 #include "mp-video-log.h"
34 #include "video-player.h"
35 #include "mp-video-info-ctrl.h"
37 enum VIDEO_PLAYER_FILE_SIZE_TYPE
45 bool MpVideoInfoCtrlGetGPS(char *szUriPath, double *nLongtitude, double *nLatitude)
48 VideoLogInfo("[ERR] No exist szUriPath.");
54 if (MpVideoDrmIsDrmFile(szUriPath)) {
55 VideoLogInfo("It's drm file.");
59 metadata_extractor_h pMetadata;
66 if(metadata_extractor_create(&pMetadata) != METADATA_EXTRACTOR_ERROR_NONE)
68 VideoLogInfo("[ERR] - metadata_extractor_create()");
72 if(metadata_extractor_set_path(pMetadata, szUriPath) != METADATA_EXTRACTOR_ERROR_NONE)
74 VideoLogInfo("[ERR] - metadata_extractor_set_path()");
78 if(metadata_extractor_get_metadata(pMetadata, METADATA_LATITUDE, &szTmp) != METADATA_EXTRACTOR_ERROR_NONE)
80 VideoLogInfo("[ERR] - metadata_extractor_get_metadata() - METADATA_LATITUDE");
81 metadata_extractor_destroy(pMetadata);
88 VideoLogInfo("METADATA_LATITUDE : %s", szTmp);
89 *nLatitude = atof(szTmp);
100 if(metadata_extractor_get_metadata(pMetadata, METADATA_LONGITUDE, &szTmp) != METADATA_EXTRACTOR_ERROR_NONE)
102 VideoLogInfo("[ERR] - metadata_extractor_get_metadata() - METADATA_LONGITUDE");
103 metadata_extractor_destroy(pMetadata);
110 VideoLogInfo("METADATA_LONGITUDE : %s", szTmp);
111 *nLongtitude = atof(szTmp);
116 VideoLogInfo("METADATA_LONGITUDE : %s", szTmp);
123 metadata_extractor_destroy(pMetadata);
128 bool MpVideoInfoCtrlGetResolution(char *szWidthResolution, char *szHeightResolution, void *pUserData)
131 VideoLogInfo("[ERR] No exist pUserData.");
137 VideoAppData *pAppData = (VideoAppData *)pUserData;
139 pAppData->VideoAppCtrlCallbackFunc.VideoAppCtrlGetVideoResolution(pAppData);
141 if (pAppData->nVideoWidthResolution > 0 && pAppData->nVideoHeightResolution > 0) {
142 snprintf(szWidthResolution, STR_LEN_MAX, "%d", pAppData->nVideoWidthResolution);
143 snprintf(szHeightResolution, STR_LEN_MAX, "%d", pAppData->nVideoHeightResolution);
151 static char *MpVideoInfoCtrlConvertingString(const char *szLocale, const char *szCustomSkeleton, const char *szTimezone, UDate st_Date)
153 #define UG_ICU_ARR_LENGTH 256
155 // Copy a byte string encoded in the default codepage to a ustring.
156 // Copies at most n characters. The result will be null terminated if the length of src is less than n.
157 // Performs a host byte to UChar conversion.
159 UChar ucustomSkeleton[UG_ICU_ARR_LENGTH] = {0,};
161 if (u_uastrncpy(ucustomSkeleton, szCustomSkeleton, UG_ICU_ARR_LENGTH) == NULL) {
162 VideoLogInfo("u_uastrncpy() error.");
166 UChar utimezone[UG_ICU_ARR_LENGTH] = {0,};
168 if (u_uastrncpy(utimezone, szTimezone, UG_ICU_ARR_LENGTH) == NULL) {
169 VideoLogInfo("u_uastrncpy() error.");
173 UErrorCode status = U_ZERO_ERROR;
174 UDateTimePatternGenerator *generator;
175 UDateFormat *formatter;
177 UChar bestPattern[UG_ICU_ARR_LENGTH] = {0,};
178 UChar formatted[UG_ICU_ARR_LENGTH] = {0,};
179 char formattedString[UG_ICU_ARR_LENGTH] = {0,};
180 int32_t bestPatternLength, formattedLength;
182 ucal_setDefaultTimeZone(utimezone , &status);
184 if (U_FAILURE(status)) {
185 VideoLogInfo("ucal_setDefaultTimeZone() is failed.");
189 uloc_setDefault(getenv("LC_TIME"), &status);
191 if (U_FAILURE(status)) {
192 VideoLogInfo("ucal_setDefaultTimeZone() is failed.");
196 generator = udatpg_open(szLocale, &status);
197 if (generator == NULL) {
201 bestPatternLength = udatpg_getBestPattern(generator, ucustomSkeleton, u_strlen(ucustomSkeleton), bestPattern, UG_ICU_ARR_LENGTH, &status);
202 if (bestPatternLength <= 0) {
206 formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, szLocale, NULL, -1, bestPattern, -1, &status);
207 if (formatter == 0) {
211 formattedLength = udat_format(formatter, st_Date, formatted, UG_ICU_ARR_LENGTH, NULL, &status);
212 if (formattedLength <= 0) {
216 u_austrcpy(formattedString, formatted);
217 udatpg_close(generator);
218 udat_close(formatter);
220 if (strlen(formattedString) == 0) {
224 return strdup(formattedString);
227 static char* MpVideoInfoCtrlGetDateOfFile(time_t mtime)
229 #define UG_DATE_FORMAT_12 "yMMMdhms"
230 #define UG_DATE_FORMAT_24 "yMMMdHms"
234 char* szSkeleton = NULL;
238 enum appcore_time_format nTimeformat;
240 int nRet = appcore_get_timeformat(&nTimeformat);
243 VideoLogInfo("Cannot get timeformat.");
244 nTimeformat = APPCORE_TIME_FORMAT_12;
247 if(nTimeformat == APPCORE_TIME_FORMAT_12)
249 szSkeleton = UG_DATE_FORMAT_12;
251 else if(nTimeformat == APPCORE_TIME_FORMAT_24)
253 szSkeleton = UG_DATE_FORMAT_24;
257 VideoLogInfo("Invalid time format : %d", nTimeformat);
258 szSkeleton = UG_DATE_FORMAT_12; // Default value.
261 szSkeleton = UG_DATE_FORMAT_12;
263 char *szLocale = vconf_get_str(VCONFKEY_REGIONFORMAT); // eg en_US.UTF-8
266 VideoLogInfo("Cannot get region format.");
267 szLocale = "en_US.UTF-8"; // Default value.
270 char *szTimezone = NULL;
271 szTimezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID); // eg Asia/Seoul
272 if(szTimezone == NULL)
274 VideoLogInfo("Cannot get time zone.");
275 return strdup("N/A");
278 VideoLogInfo("Locale : %s TimeZone : %s TimeFormat : %s", szLocale, szSkeleton, szTimezone);
280 char* szDatestr = NULL;
281 szDatestr = MpVideoInfoCtrlConvertingString(szLocale, szSkeleton, szTimezone, (UDate)mtime * 1000);
284 VideoLogInfo("Cannot get time string.");
285 return strdup("N/A");
288 VideoLogInfo("ICU Date : %s", szDatestr);
293 static char* MpVideoInfoCtrlGetDrmFileExtension(char* szPath)
296 #define EXT_SPLITTER '.'
299 VideoLogInfo("[ERR] No exist szPath.");
303 char szDrmContentType[STR_LEN_MAX] = {0};
305 MpVideoDrmGetFileExtension(szPath, szDrmContentType, STR_LEN_MAX);
306 VideoLogInfo("szDrmContentType : %s", szDrmContentType);
308 char szTmpExt[EXT_SIZE] = {0,};
312 nErr = aul_get_mime_extension(szDrmContentType, szTmpExt, sizeof(szTmpExt));
315 szExt = strrchr(szTmpExt, EXT_SPLITTER);
316 if((szExt == NULL) || (szExt + 1 == NULL)) {
323 return strdup(szExt + 1);
327 char* MpVideoInfoCtrlGetFileExtension(char *szPath)
330 VideoLogInfo("Cannot get file extension. path is NULL");
331 return strdup("Unknown");
334 if (MpVideoDrmIsDrmFile(szPath)) {
335 VideoLogInfo("It's drm file.");
337 char *szFileExtension = MpVideoInfoCtrlGetDrmFileExtension(szPath);
338 if (szFileExtension) {
339 VideoLogInfo("Drm file extension. - %s", szFileExtension);
340 return szFileExtension;
342 VideoLogInfo("No have file extension.");
343 return strdup("Unknown");
347 szExt = strrchr(szPath, '.');
349 if ((szExt != NULL) && ((szExt+1) != NULL)) {
350 return strdup(szExt + 1);
354 return strdup("Unknown");
357 char* MpVideoInfoCtrlGetFileSize(size_t size)
361 #define FILE_SIZE_LEN_MAX 64
362 #define BASIC_SIZE 1024 //used for file size check
366 unsigned long int lsize = (unsigned long int)size;
368 char *pTmp = (char *)calloc(1, sizeof(char) * FILE_SIZE_LEN_MAX + 1);
373 while (size >= (BASIC_SIZE)) {
379 if (nCount == SIZE_BYTE) {
380 snprintf(pTmp, FILE_SIZE_LEN_MAX,"%zu B", size);
381 } else if (nCount == SIZE_KB) {
382 snprintf(pTmp, FILE_SIZE_LEN_MAX,"%zu KB", size);
383 } else if (nCount == SIZE_MB) {
384 snprintf(pTmp, FILE_SIZE_LEN_MAX,"%zu MB", size);
385 } else if(nCount == SIZE_GB) {
386 snprintf(pTmp, FILE_SIZE_LEN_MAX,"%zu GB", size);
389 VideoLogInfo("Size = %lu, OrigSize=%zu", lsize, size);
394 bool MpVideoInfoCtrlGetFileInfo(char *szUriPath, char *szFileDate, int nFileDateSize, char *szFileExtension, int nFileExtensionSize, char *szFileSize, int nFilesizeSize)
397 VideoLogInfo("[ERR] No exist szUriPath.");
405 if (stat(szUriPath, &statbuf) == -1) {
406 VideoLogInfo("%s file is NULL", szUriPath);
410 memset(szFileDate, 0, nFileDateSize);
411 memset(szFileExtension, 0, nFileExtensionSize);
412 memset(szFileSize, 0, nFilesizeSize);
414 char *szTmpDateOfFile = MpVideoInfoCtrlGetDateOfFile(statbuf.st_mtime);
415 char *szTmpFileExtension = MpVideoInfoCtrlGetFileExtension(szUriPath);
416 char *szTmpFileSize = MpVideoInfoCtrlGetFileSize(statbuf.st_size);
418 if (szTmpDateOfFile) {
419 VideoLogInfo("szTmpDateOfFile : %s", szTmpDateOfFile);
420 strncpy(szFileDate, szTmpDateOfFile, nFileDateSize);
421 free(szTmpDateOfFile);
424 if (szTmpFileExtension) {
425 VideoLogInfo("szTmpFileExtension : %s", szTmpFileExtension);
426 strncpy(szFileExtension, szTmpFileExtension, nFileExtensionSize);
427 free(szTmpFileExtension);
431 VideoLogInfo("szTmpFileSize : %s", szTmpFileSize);
432 strncpy(szFileSize, szTmpFileSize, nFilesizeSize);