4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Haejeong Kim <backto.kim@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.
24 #include <unistd.h> /*for access*/
25 #include <string.h> /*for strXXX*/
28 /* exported MM header files */
32 /* internal MM File headers */
33 #include "mm_file_debug.h"
34 #include "mm_file_formats.h"
35 #include "mm_file_format_frame.h"
36 #include "mm_file_codecs.h"
37 #include "mm_file_utils.h"
42 /*#define CHECK_TIME */
48 gettimeofday(&tv, NULL);
49 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
59 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
62 #define _SEEK_POINT_ 3000 /*1000 = 1 seconds*/
64 #define MM_FILE_TAG_SYNCLYRICS "tag-synclyrics" /**< Synchronized Lyrics Information*/
74 MM_FILE_PARSE_TYPE_SIMPLE, /*parse audio/video track num only*/
75 MM_FILE_PARSE_TYPE_NORMAL, /*parse infomation without thumbnail*/
76 MM_FILE_PARSE_TYPE_ALL, /*parse all infomation*/
77 MM_FILE_PARSE_TYPE_SAFE, /*parse infomation without both thumbnail and stream full-searching*/
88 void *formatFuncHandle;
89 void *codecFuncHandle;
97 static MMAttrsConstructInfo g_tag_attrs[] = {
98 {(char *)"tag-artist", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
99 {(char *)"tag-title", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
100 {(char *)"tag-album", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
101 {(char *)"tag-album-artist", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
102 {(char *)"tag-genre", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
103 {(char *)"tag-author", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
104 {(char *)"tag-copyright", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
105 {(char *)"tag-date", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
106 {(char *)"tag-description", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
107 {(char *)"tag-comment", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
108 {(char *)"tag-artwork", MM_ATTRS_TYPE_DATA, MM_ATTRS_FLAG_RW, (void *)NULL},
109 {(char *)"tag-artwork-size", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
110 {(char *)"tag-artwork-mime", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
111 {(char *)"tag-track-num", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
112 {(char *)"tag-classification", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
113 {(char *)"tag-rating", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
114 {(char *)"tag-longitude", MM_ATTRS_TYPE_DOUBLE, MM_ATTRS_FLAG_RW, (void *)0},
115 {(char *)"tag-latitude", MM_ATTRS_TYPE_DOUBLE, MM_ATTRS_FLAG_RW, (void *)0},
116 {(char *)"tag-altitude", MM_ATTRS_TYPE_DOUBLE, MM_ATTRS_FLAG_RW, (void *)0},
117 {(char *)"tag-conductor", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
118 {(char *)"tag-unsynclyrics", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
119 {(char *)"tag-synclyrics-num", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
120 {(char *)"tag-synclyrics", MM_ATTRS_TYPE_DATA, MM_ATTRS_FLAG_RW, (void *)NULL},
121 {(char *)"tag-recdate", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
122 {(char *)"tag-part-of-set", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
123 {(char *)"tag-rotate", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
124 {(char *)"tag-cdis", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
125 {(char *)"tag-smta", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
126 {(char *)"tag-spherical", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
127 {(char *)"tag-stitched", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
128 {(char *)"tag-stitching-software", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
129 {(char *)"tag-projection-type", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
130 {(char *)"tag-stereo-mode", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
131 {(char *)"tag-source-count", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
132 {(char *)"tag-init-view-heading", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
133 {(char *)"tag-init-view-pitch", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
134 {(char *)"tag-init-view-roll", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
135 {(char *)"tag-timestamp", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
136 {(char *)"tag-full-pano-width", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
137 {(char *)"tag-full-pano-height", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
138 {(char *)"tag-cropped-area-image-width", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
139 {(char *)"tag-cropped-area-image-height", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
140 {(char *)"tag-cropped-area-left", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
141 {(char *)"tag-cropped-area-top", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
142 {(char *)"tag-ambisonic-type", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
143 {(char *)"tag-ambisonic-format", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
144 {(char *)"tag-ambisonic-order", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
145 {(char *)"stereo-mode-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
146 {(char *)"metadata-source-v2", MM_ATTRS_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
147 {(char *)"proj-type-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
148 {(char *)"pose-yaw-degrees-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
149 {(char *)"pose-pitch-degrees-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
150 {(char *)"pose-roll-degrees-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
151 {(char *)"cbmp-layout-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
152 {(char *)"cbmp-padding-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
153 {(char *)"equi-projection-bounds-top-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
154 {(char *)"equi-projection-bounds-bottom-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
155 {(char *)"equi-projection-bounds-left-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
156 {(char *)"equi-projection-bounds-right-v2", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
159 static MMAttrsConstructInfo g_content_attrs[] = {
160 {(char *)"content-duration", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
161 {(char *)"content-video-codec", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
162 {(char *)"content-video-format", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
163 {(char *)"content-video-bitrate", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
164 {(char *)"content-video-fps", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
165 {(char *)"content-video-width", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
166 {(char *)"content-video-height", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
167 {(char *)"content-video-thumbnail", MM_ATTRS_TYPE_DATA, MM_ATTRS_FLAG_RW, (void *)NULL},
168 {(char *)"content-video-track-index", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
169 {(char *)"content-video-track-count", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
170 {(char *)"content-audio-codec", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
171 {(char *)"content-audio-bitrate", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
172 {(char *)"content-audio-channels", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
173 {(char *)"content-audio-samplerate", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
174 {(char *)"content-audio-track-index", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
175 {(char *)"content-audio-track-count", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
176 {(char *)"content-audio-bitpersample", MM_ATTRS_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
179 #ifdef __MMFILE_DYN_LOADING__
180 #define MMFILE_FORMAT_SO_FILE_NAME LIBDIR"/libmmfile_formats.so"
181 #define MMFILE_CODEC_SO_FILE_NAME LIBDIR"/libmmfile_codecs.so"
183 int (*mmfile_format_open)(MMFileFormatContext **formatContext, MMFileSourceType *fileSrc);
184 int (*mmfile_format_read_stream)(MMFileFormatContext *formatContext);
185 int (*mmfile_format_read_frame)(MMFileFormatContext *formatContext, unsigned int timestamp, MMFileFormatFrame *frame);
186 int (*mmfile_format_read_tag)(MMFileFormatContext *formatContext);
187 int (*mmfile_format_close)(MMFileFormatContext *formatContext);
188 int (*mmfile_codec_open)(MMFileCodecContext **codecContext, int codecType, int codecId, MMFileCodecFrame *input);
189 int (*mmfile_codec_decode)(MMFileCodecContext *codecContext, MMFileCodecFrame *output);
190 int (*mmfile_codec_close)(MMFileCodecContext *codecContext);
191 int (*mmfile_format_get_frame)(const char *path, double timestamp, bool is_accurate, unsigned char **frame, int *size, int *width, int *height);
192 int (*mmfile_format_get_frame_from_memory)(const void *data, unsigned int datasize, double timestamp, bool is_accurate, unsigned char **frame, int *size, int *width, int *height);
195 #ifdef __MMFILE_DYN_LOADING__
196 static int _load_dynamic_functions(MMFILE_FUNC_HANDLE *pHandle)
198 /* static int dll_func_initialized = 0; //disabled */
202 /* Get from function argument */
203 void *formatFuncHandle = NULL;
204 void *codecFuncHandle = NULL;
207 if (dll_func_initialized) {
212 formatFuncHandle = dlopen(MMFILE_FORMAT_SO_FILE_NAME, RTLD_LAZY);
213 if (!formatFuncHandle) {
214 debug_error(DEBUG, "error: %s %s\n", "libmmfile_formats.so open error", dlerror());
219 mmfile_format_open = dlsym(formatFuncHandle, "mmfile_format_open");
220 mmfile_format_read_stream = dlsym(formatFuncHandle, "mmfile_format_read_stream");
221 mmfile_format_read_frame = dlsym(formatFuncHandle, "mmfile_format_read_frame");
222 mmfile_format_read_tag = dlsym(formatFuncHandle, "mmfile_format_read_tag");
223 mmfile_format_close = dlsym(formatFuncHandle, "mmfile_format_close");
225 if (!mmfile_format_open ||
226 !mmfile_format_read_stream ||
227 !mmfile_format_read_frame ||
228 !mmfile_format_read_tag ||
229 !mmfile_format_close) {
231 debug_error(DEBUG, "error: %s\n", "format function load error");
236 /*closed at app termination.*/
237 /*dlclose (formatFuncHandle); */
239 codecFuncHandle = dlopen(MMFILE_CODEC_SO_FILE_NAME, RTLD_LAZY | RTLD_GLOBAL);
240 if (!codecFuncHandle) {
241 debug_error(DEBUG, "error: %s\n", "libmmfile_codecs.so open error");
246 mmfile_codec_open = dlsym(codecFuncHandle, "mmfile_codec_open");
247 mmfile_codec_decode = dlsym(codecFuncHandle, "mmfile_codec_decode");
248 mmfile_codec_close = dlsym(codecFuncHandle, "mmfile_codec_close");
250 if (!mmfile_codec_open || !mmfile_codec_decode || !mmfile_codec_close) {
251 debug_error(DEBUG, "error: %s\n", "codec function load error");
256 /*closed at app termination.*/
257 /*dlclose (codecFuncHandle); */
259 /* dll_func_initialized = 1; // disabled */
261 pHandle->codecFuncHandle = codecFuncHandle;
262 pHandle->formatFuncHandle = formatFuncHandle;
267 if (formatFuncHandle) dlclose(formatFuncHandle);
268 if (codecFuncHandle) dlclose(codecFuncHandle);
273 static void _unload_dynamic_functions(MMFILE_FUNC_HANDLE *pHandle)
275 debug_fenter(RELEASE);
277 if (pHandle->formatFuncHandle) {
278 dlclose(pHandle->formatFuncHandle);
280 if (pHandle->codecFuncHandle) {
281 dlclose(pHandle->codecFuncHandle);
284 debug_fleave(RELEASE);
288 #endif /* __MMFILE_DYN_LOADING__ */
294 _is_file_exist(const char *filename)
296 int ret = FILEINFO_ERROR_NONE;
298 const char *to_access = (strstr(filename, "file://") != NULL) ? filename + 7 : filename;
299 ret = access(to_access, R_OK);
301 if (errno == EACCES || errno == EPERM) {
302 debug_error(DEBUG, "Permission denied [%s]", to_access);
303 ret = FILEINFO_ERROR_PERMISSION_DENIED;
305 debug_error(DEBUG, "Not exist file [%s]", to_access);
306 ret = FILEINFO_ERROR_FILE_NOT_FOUND;
314 _info_set_attr_media(MMHandleType attrs, MMFileFormatContext *formatContext)
318 if (formatContext->commandType == MM_FILE_TAG) {
319 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_TITLE, formatContext->title);
320 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_ARTIST, formatContext->artist);
321 if (formatContext->author)
322 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_AUTHOR, formatContext->author);
324 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_AUTHOR, formatContext->composer);
325 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_ALBUM, formatContext->album);
326 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_ALBUM_ARTIST, formatContext->album_artist);
327 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_COPYRIGHT, formatContext->copyright);
328 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_DESCRIPTION, formatContext->description);
329 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_COMMENT, formatContext->comment);
330 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_GENRE, formatContext->genre);
331 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_CLASSIFICATION, formatContext->classification);
332 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_DATE, formatContext->year);
333 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_TRACK_NUM, formatContext->tagTrackNum);
334 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_RATING, formatContext->rating);
335 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_CONDUCTOR, formatContext->conductor);
336 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_RECDATE, formatContext->recDate);
337 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_POS, formatContext->part_of_set);
339 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_ROTATE, formatContext->rotate);
340 mm_attrs_set_double_by_name(attrs, MM_FILE_TAG_LONGITUDE, formatContext->longitude);
341 mm_attrs_set_double_by_name(attrs, MM_FILE_TAG_LATIDUE, formatContext->latitude);
342 mm_attrs_set_double_by_name(attrs, MM_FILE_TAG_ALTIDUE, formatContext->altitude);
343 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SYNCLYRICS_NUM, formatContext->syncLyricsNum);
344 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_CDIS, formatContext->cdis);
345 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SMTA, formatContext->smta);
347 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL, formatContext->isSpherical);
348 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_STITCHED, formatContext->isStitched);
349 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_SPHERICAL_STITCHING_SOFTWARE, formatContext->stitchingSoftware);
350 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_SPHERICAL_PROJECTION_TYPE, formatContext->projectionType);
351 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_SPHERICAL_STEREO_MODE, formatContext->stereoMode);
352 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_SOURCE_COUNT, formatContext->sourceCount);
353 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_INIT_VIEW_HEADING, formatContext->initViewHeading);
354 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_INIT_VIEW_PITCH, formatContext->initViewPitch);
355 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_INIT_VIEW_ROLL, formatContext->initViewRoll);
356 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_TIMESTAMP, formatContext->timestamp);
357 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_FULL_PANO_WIDTH, formatContext->fullPanoWidth);
358 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_FULL_PANO_HEIGHT, formatContext->fullPanoHeight);
359 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_CROPPED_AREA_IMAGE_WIDTH, formatContext->croppedAreaImageWidth);
360 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_CROPPED_AREA_IMAGE_HEIGHT, formatContext->croppedAreaImageHeight);
361 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_CROPPED_AREA_LEFT, formatContext->croppedAreaLeft);
362 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_CROPPED_AREA_TOP, formatContext->croppedAreaTop);
364 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_AMBISONIC_TYPE, formatContext->ambisonicType);
365 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_AMBISONIC_FORMAT, formatContext->ambisonicFormat);
366 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_AMBISONIC_ORDER, formatContext->ambisonicOrder);
368 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_STEREO_MODE, formatContext->stereoModeV2);
369 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_METADATA_SOURCE, formatContext->metadataSourceV2);
370 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_PROJ_TYPE, formatContext->projTypeV2);
371 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_POSE_YAW, formatContext->poseYawV2);
372 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_POSE_PITCH, formatContext->posePitchV2);
373 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_POSE_ROLL, formatContext->poseRollV2);
374 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_CBMP_LAYOUT, formatContext->cbmpLayoutV2);
375 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_CBMP_PADDING, formatContext->cbmpPaddingV2);
376 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_EQUI_BOUNDS_TOP, formatContext->equiBoundsTopV2);
377 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_EQUI_BOUNDS_BOTTOM, formatContext->equiBoundsBottomV2);
378 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_EQUI_BOUNDS_LEFT, formatContext->equiBoundsLeftV2);
379 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_SPHERICAL_V2_EQUI_BOUNDS_RIGHT, formatContext->equiBoundsRightV2);
381 mm_attrs_set_data_by_name(attrs, MM_FILE_TAG_SYNCLYRICS, formatContext->syncLyrics, formatContext->syncLyricsNum);
383 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_UNSYNCLYRICS, formatContext->unsyncLyrics);
385 if (formatContext->artwork && formatContext->artworkSize > 0) {
386 void *artworkCopy = NULL;
387 artworkCopy = mmfile_malloc((formatContext->artworkSize));
389 memcpy(artworkCopy, formatContext->artwork, formatContext->artworkSize);
390 mm_attrs_set_data_by_name(attrs, MM_FILE_TAG_ARTWORK, artworkCopy, formatContext->artworkSize);
391 mm_attrs_set_int_by_name(attrs, MM_FILE_TAG_ARTWORK_SIZE, formatContext->artworkSize);
392 mm_attrs_set_string_by_name(attrs, MM_FILE_TAG_ARTWORK_MIME, formatContext->artworkMime);
395 } else if (formatContext->commandType == MM_FILE_CONTENTS) {
397 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_DURATION, formatContext->duration);
398 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_AUDIO_TRACK_COUNT, formatContext->audioTotalTrackNum);
399 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, formatContext->videoTotalTrackNum);
401 if (formatContext->videoTotalTrackNum > 0 &&
402 formatContext->nbStreams > 0 &&
403 formatContext->streams[MMFILE_VIDEO_STREAM]) {
405 MMFileFormatStream *videoStream = formatContext->streams[MMFILE_VIDEO_STREAM];
407 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_VIDEO_FORMAT, formatContext->formatType);
408 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_VIDEO_CODEC, videoStream->codecId);
409 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_VIDEO_BITRATE, videoStream->bitRate);
410 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_VIDEO_FPS, videoStream->framePerSec);
411 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_VIDEO_WIDTH, videoStream->width);
412 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_VIDEO_HEIGHT, videoStream->height);
414 if (formatContext->thumbNail && formatContext->thumbNail->frameData) {
415 void *thumbNailCopy = NULL;
416 thumbNailCopy = mmfile_malloc(formatContext->thumbNail->frameSize);
419 memcpy(thumbNailCopy, formatContext->thumbNail->frameData, formatContext->thumbNail->frameSize);
420 mm_attrs_set_data_by_name(attrs, MM_FILE_CONTENT_VIDEO_THUMBNAIL, thumbNailCopy, formatContext->thumbNail->frameSize);
421 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_VIDEO_WIDTH, formatContext->thumbNail->frameWidth);
422 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_VIDEO_HEIGHT, formatContext->thumbNail->frameHeight);
427 if (formatContext->audioTotalTrackNum > 0 &&
428 formatContext->nbStreams > 0 &&
429 formatContext->streams[MMFILE_AUDIO_STREAM]) {
431 MMFileFormatStream *audioStream = formatContext->streams[MMFILE_AUDIO_STREAM];
433 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_AUDIO_CODEC, audioStream->codecId);
434 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_AUDIO_CHANNELS, audioStream->nbChannel);
435 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_AUDIO_BITRATE, audioStream->bitRate);
436 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_AUDIO_SAMPLERATE, audioStream->samplePerSec);
437 mm_attrs_set_int_by_name(attrs, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, audioStream->bitPerSample);
444 mm_attrs_commit_all(attrs);
450 * @param frameContext [in] frame for decoding.
451 * @param videoStream [in] information of video codec for frameContext.
452 * @param decodedFrame [inout] frame after decoding frameContext.
455 __decode_contents_frame(MMFileFormatFrame *frameContext, MMFileFormatStream *videoStream, MMFileCodecFrame *decodedFrame)
457 int ret = FILEINFO_ERROR_NONE;
458 MMFileCodecContext *codecContext = NULL;
459 MMFileCodecFrame codecFrame = {0, };
461 if (!frameContext || !videoStream || !decodedFrame) {
462 debug_error(DEBUG, "error: invalid parameters (%p %p %p)\n", frameContext, videoStream, decodedFrame);
463 return FILEINFO_ERROR_FILE_INTERNAL;
466 codecFrame.frameDataSize = frameContext->frameSize;
467 codecFrame.width = frameContext->frameWidth;
468 codecFrame.height = frameContext->frameHeight;
469 codecFrame.frameData = frameContext->frameData;
470 codecFrame.configLen = frameContext->configLenth;
471 codecFrame.configData = frameContext->configData;
472 codecFrame.version = videoStream->version;
474 if (MMFILE_FORMAT_FAIL == mmfile_codec_open(&codecContext, MMFILE_VIDEO_DECODE, videoStream->codecId, &codecFrame)) {
475 debug_error(DEBUG, "error: mmfile_codec_open\n");
476 mmfile_codec_close(codecContext);
477 return FILEINFO_ERROR_FILE_INTERNAL;
480 if (MMFILE_FORMAT_FAIL == mmfile_codec_decode(codecContext, decodedFrame)) {
481 debug_error(DEBUG, "error: mmfile_codec_decode\n");
482 ret = FILEINFO_ERROR_FILE_INTERNAL;
485 mmfile_codec_close(codecContext);
491 __get_contents_thumbnail(MMFileFormatContext *formatContext)
493 int ret = FILEINFO_ERROR_NONE;
494 MMFileFormatFrame frameContext = {0, };
495 MMFileCodecFrame decodedFrame = {0, };
496 MMFileFormatFrame *thumbnail = NULL;
498 if (!formatContext) {
499 debug_error(DEBUG, "error: invalid parameter (%p)\n", formatContext);
500 return FILEINFO_ERROR_FILE_INTERNAL;
503 if (MMFILE_FORMAT_FAIL == mmfile_format_read_frame(formatContext, _SEEK_POINT_, &frameContext)) {
504 debug_error(DEBUG, "error: mmfile_format_read_frame\n");
505 ret = FILEINFO_ERROR_FILE_INTERNAL;
509 /* set video thumbnail */
510 thumbnail = mmfile_malloc(sizeof(MMFileFormatFrame));
512 debug_error(DEBUG, "error: mmfile_malloc\n");
513 ret = FILEINFO_ERROR_FILE_INTERNAL;
517 if (frameContext.bCompressed) {
518 ret = __decode_contents_frame(&frameContext, formatContext->streams[MMFILE_VIDEO_STREAM], &decodedFrame);
519 if (FILEINFO_ERROR_NONE != ret) {
520 debug_error(DEBUG, "error: __decode_contents_thumbnail\n");
524 /* after decoding frameContext is done, it is no needed */
525 mmfile_free(frameContext.frameData);
526 mmfile_free(frameContext.configData);
528 thumbnail->frameSize = decodedFrame.frameDataSize;
529 thumbnail->frameWidth = decodedFrame.width;
530 thumbnail->frameHeight = decodedFrame.height;
531 thumbnail->frameData = decodedFrame.frameData;
532 thumbnail->configLenth = 0;
533 thumbnail->configData = NULL;
535 thumbnail->frameSize = frameContext.frameSize;
536 thumbnail->frameWidth = frameContext.frameWidth;
537 thumbnail->frameHeight = frameContext.frameHeight;
538 thumbnail->frameData = frameContext.frameData;
539 thumbnail->configLenth = 0;
540 thumbnail->configData = NULL;
543 #ifdef __MMFILE_TEST_MODE__
544 mmfile_format_print_frame(thumbnail);
547 formatContext->thumbNail = thumbnail;
549 /* because #MMFILE_FORMAT_SUCCESS is different with #FILEINFO_ERROR_NONE */
550 return FILEINFO_ERROR_NONE;
552 if (frameContext.bCompressed) {
553 mmfile_free(decodedFrame.frameData);
554 mmfile_free(decodedFrame.configData);
557 mmfile_free(thumbnail);
558 mmfile_free(frameContext.frameData);
559 mmfile_free(frameContext.configData);
565 _get_contents_info(MMHandleType attrs, MMFileSourceType *src, MMFILE_PARSE_INFO *parse)
567 MMFileFormatContext *formatContext = NULL;
570 if (!src || !parse) {
571 debug_error(DEBUG, "error: invalid parameters (%p, %p)\n", src, parse);
572 return FILEINFO_ERROR_FILE_INTERNAL;
575 if (MMFILE_FORMAT_FAIL == mmfile_format_open(&formatContext, src) || formatContext == NULL) {
576 debug_error(DEBUG, "error: mmfile_format_open\n");
577 ret = FILEINFO_ERROR_FILE_INTERNAL;
581 if (parse->type >= MM_FILE_PARSE_TYPE_NORMAL) {
582 if (parse->type == MM_FILE_PARSE_TYPE_SAFE)
583 formatContext->cdis = 1;
585 if (MMFILE_FORMAT_FAIL == mmfile_format_read_stream(formatContext)) {
586 debug_error(DEBUG, "error: mmfile_format_read_stream\n");
587 ret = FILEINFO_ERROR_FILE_INTERNAL;
591 parse->audio_track_num = formatContext->audioTotalTrackNum;
592 parse->video_track_num = formatContext->videoTotalTrackNum;
594 /* check uhqa content*/
595 if (formatContext->streams[MMFILE_AUDIO_STREAM] != NULL)
596 parse->is_uhqa = formatContext->streams[MMFILE_AUDIO_STREAM]->is_uhqa;
598 parse->is_uhqa = FALSE;
600 if (parse->type >= MM_FILE_PARSE_TYPE_ALL && formatContext->videoTotalTrackNum > 0) {
601 /*why below code needed?
602 This API is for extracting some attributes not metadata(TAG). mm_file_create_content_attrs() use this API.
603 but MMFileUtilGetMetaDataFromMP4() Extract just TAG info. That is needed for mm_file_create_tag_attrs()*/
605 if (parse->type != MM_FILE_PARSE_TYPE_SAFE) {
606 if (formatContext->formatType == MM_FILE_FORMAT_3GP || formatContext->formatType == MM_FILE_FORMAT_MP4) {
607 MMFileUtilGetMetaDataFromMP4(formatContext);
611 ret = __get_contents_thumbnail(formatContext);
612 if (FILEINFO_ERROR_NONE != ret) {
613 debug_error(DEBUG, "error: __get_contents_thumbnail\n");
614 ret = FILEINFO_ERROR_NONE;
619 * if MM_FILE_PARSE_TYPE_SIMPLE, just get number of each stream.
621 parse->audio_track_num = formatContext->audioTotalTrackNum;
622 parse->video_track_num = formatContext->videoTotalTrackNum;
625 formatContext->commandType = MM_FILE_CONTENTS;
627 if (parse->type >= MM_FILE_PARSE_TYPE_NORMAL)
628 _info_set_attr_media(attrs, formatContext);
630 if (formatContext->thumbNail) {
631 mmfile_free(formatContext->thumbNail->frameData);
632 mmfile_free(formatContext->thumbNail->configData);
633 mmfile_free(formatContext->thumbNail);
638 mmfile_format_close(formatContext);
645 _get_tag_info(MMHandleType attrs, MMFileSourceType *src)
647 MMFileFormatContext *formatContext = NULL;
650 ret = mmfile_format_open(&formatContext, src);
651 if (MMFILE_FORMAT_FAIL == ret || formatContext == NULL) {
652 debug_error(DEBUG, "error: mmfile_format_open\n");
653 ret = FILEINFO_ERROR_FILE_INTERNAL;
657 ret = mmfile_format_read_tag(formatContext);
658 if (MMFILE_FORMAT_FAIL == ret) {
659 debug_warning(DEBUG, "reading tag is fail\n");
660 ret = FILEINFO_ERROR_FILE_INTERNAL;
664 formatContext->commandType = MM_FILE_TAG;
666 _info_set_attr_media(attrs, formatContext);
669 mmfile_format_close(formatContext);
672 return FILEINFO_ERROR_NONE;
677 mmfile_format_close(formatContext);
680 return FILEINFO_ERROR_FILE_INTERNAL;
687 int mm_file_get_attrs(MMHandleType attrs, char **err_attr_name, const char *first_attribute_name, ...)
689 int ret = FILEINFO_ERROR_NONE;
693 debug_error(DEBUG, "Invalid arguments [attrs 0]\n");
694 return FILEINFO_ERROR_INVALID_ARGUMENT;
697 if (first_attribute_name == NULL) {
698 debug_error(DEBUG, "Invalid arguments [first_attribute_name null]\n");
699 return FILEINFO_ERROR_INVALID_ARGUMENT;
702 /* get requested attributes */
703 va_start(var_args, first_attribute_name);
704 ret = mm_attrs_get_valist(attrs, err_attr_name, first_attribute_name, var_args);
707 if (ret != FILEINFO_ERROR_NONE) {
709 debug_error(DEBUG, "failed to get %s\n", *err_attr_name);
716 int mm_file_get_synclyrics_info(MMHandleType tag_attrs, int index, unsigned long *time_info, char **lyrics)
718 int ret = FILEINFO_ERROR_NONE;
719 AvSynclyricsInfo *sync_lyric_item = NULL;
720 GList *synclyrics_list = NULL;
722 debug_fenter(RELEASE);
724 if (tag_attrs == NULL) {
725 debug_error(DEBUG, "invalid handle");
726 return FILEINFO_ERROR_INVALID_ARGUMENT;
729 ret = mm_attrs_get_data_by_name(tag_attrs, MM_FILE_TAG_SYNCLYRICS, (void **)&synclyrics_list);
730 if (ret != FILEINFO_ERROR_NONE) {
731 debug_warning(RELEASE, "get data fail");
735 if (synclyrics_list != NULL) {
737 sync_lyric_item = (AvSynclyricsInfo *)g_list_nth_data(synclyrics_list, index);
739 if (sync_lyric_item == NULL) {
740 debug_warning(RELEASE, "synclyric item is NULL");
741 return FILEINFO_ERROR_ATTR_NOT_EXIST;
744 *time_info = sync_lyric_item->time_info;
745 *lyrics = sync_lyric_item->lyric_info;
748 debug_warning(RELEASE, "synclyrics_list is NULL");
749 return FILEINFO_ERROR_ATTR_NOT_EXIST;
756 int mm_file_create_tag_attrs(MMHandleType *tag_attrs, const char *filename)
758 int ret = FILEINFO_ERROR_NONE;
759 MMHandleType attrs = NULL;
760 MMFileSourceType src;
762 debug_fenter(RELEASE);
764 /* Check argument here */
765 if (tag_attrs == NULL) {
766 debug_error(DEBUG, "Invalid arguments [tag null]\n");
767 return FILEINFO_ERROR_INVALID_ARGUMENT;
769 if (filename == NULL) {
770 debug_error(DEBUG, "Invalid arguments [filename null]\n");
771 return FILEINFO_ERROR_INVALID_ARGUMENT;
773 if (strlen(filename) == 0) {
774 debug_error(DEBUG, "Invalid arguments [filename size 0]\n");
775 return FILEINFO_ERROR_INVALID_ARGUMENT;
779 #ifdef __MMFILE_DYN_LOADING__
780 MMFILE_FUNC_HANDLE func_handle;
782 ret = _load_dynamic_functions(&func_handle);
784 debug_error(DEBUG, "load library error\n");
785 return FILEINFO_ERROR_FILE_INTERNAL;
789 /*set source file infomation*/
790 MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
792 ret = _is_file_exist(filename);
793 if (ret != FILEINFO_ERROR_NONE) {
798 ret = mm_attrs_new(g_tag_attrs, ARRAY_SIZE(g_tag_attrs), "tag", NULL, NULL, &attrs);
800 debug_error(DEBUG, "attribute internal error.\n");
801 ret = FILEINFO_ERROR_FILE_INTERNAL;
805 ret = _get_tag_info(attrs, &src);
806 if (ret != FILEINFO_ERROR_NONE) {
807 mm_attrs_free(attrs);
809 debug_error(DEBUG, "failed to get tag: %s\n", filename);
815 #ifdef __MMFILE_DYN_LOADING__
816 _unload_dynamic_functions(&func_handle);
819 debug_fleave(RELEASE);
826 int mm_file_destroy_tag_attrs(MMHandleType tag_attrs)
828 void *artwork = NULL;
829 GList *synclyrics_list = NULL;
830 int ret = FILEINFO_ERROR_NONE;
832 debug_fenter(RELEASE);
834 if (tag_attrs == NULL) {
835 debug_error(DEBUG, "invalid handle.\n");
836 return FILEINFO_ERROR_INVALID_ARGUMENT;
839 ret = mm_attrs_get_data_by_name(tag_attrs, MM_FILE_TAG_ARTWORK, &artwork);
840 mmfile_free(artwork);
842 ret = mm_attrs_get_data_by_name(tag_attrs, MM_FILE_TAG_SYNCLYRICS, (void **)&synclyrics_list);
843 mm_file_free_synclyrics_list(synclyrics_list);
844 mm_attrs_free(tag_attrs);
846 debug_fleave(RELEASE);
852 int mm_file_create_content_attrs(MMHandleType *contents_attrs, const char *filename)
854 MMHandleType attrs = NULL;
855 MMFileSourceType src = {0, };
856 MMFILE_PARSE_INFO parse = {0, };
859 debug_fenter(RELEASE);
861 /* Check argument here */
862 if (contents_attrs == NULL) {
863 debug_error(DEBUG, "Invalid arguments [contents null]\n");
864 return FILEINFO_ERROR_INVALID_ARGUMENT;
866 if (filename == NULL) {
867 debug_error(DEBUG, "Invalid arguments [filename null]\n");
868 return FILEINFO_ERROR_INVALID_ARGUMENT;
870 if (strlen(filename) == 0) {
871 debug_error(DEBUG, "Invalid arguments [filename size 0]\n");
872 return FILEINFO_ERROR_INVALID_ARGUMENT;
876 #ifdef __MMFILE_DYN_LOADING__
877 MMFILE_FUNC_HANDLE func_handle;
884 ret = _load_dynamic_functions(&func_handle);
886 debug_error(DEBUG, "load library error\n");
887 return FILEINFO_ERROR_FILE_INTERNAL;
891 debug_msg(DEBUG, "_load_dynamic_functions() = %lld\n", gettime() - ti);
896 /*set source file infomation*/
897 MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
899 ret = _is_file_exist(filename);
900 if (ret != FILEINFO_ERROR_NONE) {
905 ret = mm_attrs_new(g_content_attrs, ARRAY_SIZE(g_content_attrs), "content", NULL, NULL, &attrs);
907 debug_error(DEBUG, "attribute internal error.\n");
908 ret = FILEINFO_ERROR_FILE_INTERNAL;
913 parse.type = MM_FILE_PARSE_TYPE_ALL;
914 ret = _get_contents_info(attrs, &src, &parse);
915 if (ret != FILEINFO_ERROR_NONE) {
916 mm_attrs_free(attrs);
918 debug_error(DEBUG, "failed to get contents: %s\n", filename);
921 *contents_attrs = attrs;
925 #ifdef __MMFILE_DYN_LOADING__
931 _unload_dynamic_functions(&func_handle);
934 debug_msg(DEBUG, "_unload_dynamic_functions() = %lld\n", gettime() - ti);
939 debug_fleave(RELEASE);
946 int mm_file_create_tag_attrs_from_memory(MMHandleType *tag_attrs, const void *data, unsigned int size, int format)
948 MMHandleType attrs = NULL;
949 MMFileSourceType src;
950 /*MMFILE_PARSE_INFO parse = {0, };*/
953 debug_fenter(RELEASE);
955 /* Check argument here */
956 if (tag_attrs == NULL || data == NULL) {
957 debug_error(DEBUG, "Invalid arguments\n");
958 return FILEINFO_ERROR_INVALID_ARGUMENT;
961 #ifdef __MMFILE_DYN_LOADING__
962 MMFILE_FUNC_HANDLE func_handle;
964 ret = _load_dynamic_functions(&func_handle);
966 debug_error(DEBUG, "load library error\n");
967 return FILEINFO_ERROR_FILE_INTERNAL;
971 MM_FILE_SET_MEDIA_MEM_SRC(src, data, size, format);
974 ret = mm_attrs_new(g_tag_attrs, ARRAY_SIZE(g_tag_attrs), "tag", NULL, NULL, &attrs);
976 debug_error(DEBUG, "attribute internal error.\n");
977 ret = FILEINFO_ERROR_FILE_INTERNAL;
981 /*parse.type = MM_FILE_PARSE_TYPE_ALL;*/
982 ret = _get_tag_info(attrs, &src);
983 if (ret != FILEINFO_ERROR_NONE) {
984 mm_attrs_free(attrs);
986 debug_error(DEBUG, "failed to get tag");
992 #ifdef __MMFILE_DYN_LOADING__
993 _unload_dynamic_functions(&func_handle);
996 debug_fleave(RELEASE);
1003 int mm_file_create_content_attrs_from_memory(MMHandleType *contents_attrs, const void *data, unsigned int size, int format)
1005 MMHandleType attrs = NULL;
1006 MMFileSourceType src;
1007 MMFILE_PARSE_INFO parse = {0, };
1010 debug_fenter(RELEASE);
1012 /* Check argument here */
1013 if (contents_attrs == NULL || data == NULL) {
1014 debug_error(DEBUG, "Invalid arguments\n");
1015 return FILEINFO_ERROR_INVALID_ARGUMENT;
1018 #ifdef __MMFILE_DYN_LOADING__
1019 MMFILE_FUNC_HANDLE func_handle;
1021 ret = _load_dynamic_functions(&func_handle);
1023 debug_error(DEBUG, "load library error\n");
1024 return FILEINFO_ERROR_FILE_INTERNAL;
1028 MM_FILE_SET_MEDIA_MEM_SRC(src, data, size, format);
1031 ret = mm_attrs_new(g_content_attrs, ARRAY_SIZE(g_content_attrs), "content", NULL, NULL, &attrs);
1033 debug_error(DEBUG, "attribute internal error.\n");
1034 ret = FILEINFO_ERROR_FILE_INTERNAL;
1038 parse.type = MM_FILE_PARSE_TYPE_ALL;
1039 ret = _get_contents_info(attrs, &src, &parse);
1040 if (ret != FILEINFO_ERROR_NONE) {
1041 mm_attrs_free(attrs);
1043 debug_error(DEBUG, "failed to get contents");
1046 *contents_attrs = attrs;
1049 #ifdef __MMFILE_DYN_LOADING__
1050 _unload_dynamic_functions(&func_handle);
1053 debug_fleave(RELEASE);
1060 int mm_file_destroy_content_attrs(MMHandleType contents_attrs)
1062 void *thumbnail = NULL;
1063 int ret = FILEINFO_ERROR_NONE;
1065 debug_fenter(RELEASE);
1067 if (contents_attrs == NULL) {
1068 debug_error(DEBUG, "invalid handle.\n");
1069 return FILEINFO_ERROR_INVALID_ARGUMENT;
1072 ret = mm_attrs_get_data_by_name(contents_attrs, MM_FILE_CONTENT_VIDEO_THUMBNAIL, &thumbnail);
1073 mmfile_free(thumbnail);
1075 mm_attrs_free(contents_attrs);
1077 debug_fleave(RELEASE);
1084 int mm_file_get_stream_info(const char *filename, int *audio_stream_num, int *video_stream_num)
1086 MMFileSourceType src = {0, };
1087 MMFILE_PARSE_INFO parse = {0, };
1091 debug_fenter(RELEASE);
1093 if (filename == NULL || strlen(filename) == 0 || audio_stream_num == NULL || video_stream_num == NULL) {
1094 debug_error(DEBUG, "Invalid arguments\n");
1095 return FILEINFO_ERROR_INVALID_ARGUMENT;
1098 #ifdef __MMFILE_DYN_LOADING__
1099 MMFILE_FUNC_HANDLE func_handle;
1101 ret = _load_dynamic_functions(&func_handle);
1103 debug_error(DEBUG, "load library error\n");
1104 return FILEINFO_ERROR_FILE_INTERNAL;
1108 /*set source file infomation*/
1109 MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
1111 ret = _is_file_exist(filename);
1112 if (ret != FILEINFO_ERROR_NONE) {
1116 parse.type = MM_FILE_PARSE_TYPE_SIMPLE;
1117 ret = _get_contents_info(NULL, &src, &parse);
1118 if (ret != FILEINFO_ERROR_NONE) {
1119 debug_error(DEBUG, "failed to get stream info: %s\n", filename);
1121 if (parse.audio_track_num == 0 && parse.video_track_num == 0) {
1122 debug_error(DEBUG, "empty header. retry to get stream info: %s\n", filename);
1123 parse.type = MM_FILE_PARSE_TYPE_NORMAL;
1124 ret = _get_contents_info(NULL, &src, &parse);
1128 /*set number of each stream*/
1129 *audio_stream_num = parse.audio_track_num;
1130 *video_stream_num = parse.video_track_num;
1133 #ifdef __MMFILE_DYN_LOADING__
1134 _unload_dynamic_functions(&func_handle);
1137 debug_fleave(RELEASE);
1143 int mm_file_create_content_attrs_simple(MMHandleType *contents_attrs, const char *filename)
1145 MMHandleType attrs = NULL;
1146 MMFileSourceType src = {0, };
1147 MMFILE_PARSE_INFO parse = {0, };
1150 debug_fenter(RELEASE);
1152 #ifdef __MMFILE_DYN_LOADING__
1153 MMFILE_FUNC_HANDLE func_handle;
1155 ret = _load_dynamic_functions(&func_handle);
1157 debug_error(DEBUG, "load library error\n");
1158 return FILEINFO_ERROR_FILE_INTERNAL;
1161 if (filename == NULL) {
1162 ret = FILEINFO_ERROR_INVALID_ARGUMENT;
1165 if (strlen(filename) == 0) {
1166 ret = FILEINFO_ERROR_INVALID_ARGUMENT;
1171 /*set source file infomation*/
1172 MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
1174 ret = _is_file_exist(filename);
1175 if (ret != FILEINFO_ERROR_NONE) {
1180 ret = mm_attrs_new(g_content_attrs, ARRAY_SIZE(g_content_attrs), "content", NULL, NULL, &attrs);
1182 debug_error(DEBUG, "attribute internal error.\n");
1183 ret = FILEINFO_ERROR_FILE_INTERNAL;
1187 parse.type = MM_FILE_PARSE_TYPE_NORMAL;
1188 ret = _get_contents_info(attrs, &src, &parse);
1189 if (ret != FILEINFO_ERROR_NONE) {
1190 mm_attrs_free(attrs);
1192 debug_error(DEBUG, "failed to get contents: %s\n", filename);
1195 *contents_attrs = attrs;
1198 #ifdef __MMFILE_DYN_LOADING__
1199 _unload_dynamic_functions(&func_handle);
1202 debug_fleave(RELEASE);
1208 int mm_file_create_content_attrs_safe(MMHandleType *contents_attrs, const char *filename)
1210 MMHandleType attrs = NULL;
1211 MMFileSourceType src = {0, };
1212 MMFILE_PARSE_INFO parse = {0, };
1215 debug_fenter(RELEASE);
1217 #ifdef __MMFILE_DYN_LOADING__
1218 MMFILE_FUNC_HANDLE func_handle;
1220 ret = _load_dynamic_functions(&func_handle);
1222 debug_error(DEBUG, "load library error\n");
1223 return FILEINFO_ERROR_FILE_INTERNAL;
1226 if (filename == NULL) {
1227 ret = FILEINFO_ERROR_INVALID_ARGUMENT;
1230 if (strlen(filename) == 0) {
1231 ret = FILEINFO_ERROR_INVALID_ARGUMENT;
1236 /*set source file infomation*/
1237 MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
1239 ret = _is_file_exist(filename);
1240 if (ret != FILEINFO_ERROR_NONE) {
1245 ret = mm_attrs_new(g_content_attrs, ARRAY_SIZE(g_content_attrs), "content", NULL, NULL, &attrs);
1247 debug_error(DEBUG, "attribute internal error.\n");
1248 ret = FILEINFO_ERROR_FILE_INTERNAL;
1252 parse.type = MM_FILE_PARSE_TYPE_SAFE;
1253 ret = _get_contents_info(attrs, &src, &parse);
1254 if (ret != FILEINFO_ERROR_NONE) {
1255 mm_attrs_free(attrs);
1257 debug_error(DEBUG, "failed to get contents: %s\n", filename);
1260 *contents_attrs = attrs;
1263 #ifdef __MMFILE_DYN_LOADING__
1264 _unload_dynamic_functions(&func_handle);
1267 debug_fleave(RELEASE);
1273 int mm_file_get_video_frame(const char *path, double timestamp, bool is_accurate, unsigned char **frame, int *size, int *width, int *height)
1276 void *formatFuncHandle = NULL;
1279 debug_error(DEBUG, "Invalid arguments [Path is Null]\n");
1280 return FILEINFO_ERROR_INVALID_ARGUMENT;
1283 #ifdef __MMFILE_DYN_LOADING__
1284 /* Get from function argument */
1285 formatFuncHandle = dlopen(MMFILE_FORMAT_SO_FILE_NAME, RTLD_LAZY);
1286 if (!formatFuncHandle) {
1287 debug_error(DEBUG, "error : dlopen");
1291 mmfile_format_get_frame = dlsym(formatFuncHandle, "mmfile_format_get_frame");
1292 if (!mmfile_format_get_frame) {
1293 debug_error(DEBUG, "error : load library");
1298 debug_msg(RELEASE, "file path [%s] is_accurate [%d]", path, is_accurate);
1300 ret = mmfile_format_get_frame(path, timestamp, is_accurate, frame, size, width, height);
1301 if (ret == MMFILE_FORMAT_FAIL) {
1302 debug_error(DEBUG, "error : get frame");
1306 if (formatFuncHandle) dlclose(formatFuncHandle);
1308 return FILEINFO_ERROR_NONE;
1311 if (formatFuncHandle) dlclose(formatFuncHandle);
1313 return FILEINFO_ERROR_FILE_INTERNAL;
1317 int mm_file_get_video_frame_from_memory(const void *data, unsigned int datasize, double timestamp, bool is_accurate, unsigned char **frame, int *size, int *width, int *height)
1320 void *formatFuncHandle = NULL;
1323 debug_error(DEBUG, "Invalid arguments [data is Null]\n");
1324 return FILEINFO_ERROR_INVALID_ARGUMENT;
1327 if (datasize == 0) {
1328 debug_error(DEBUG, "Invalid arguments [datasize is zero]\n");
1329 return FILEINFO_ERROR_INVALID_ARGUMENT;
1332 #ifdef __MMFILE_DYN_LOADING__
1333 /* Get from function argument */
1334 formatFuncHandle = dlopen(MMFILE_FORMAT_SO_FILE_NAME, RTLD_LAZY);
1335 if (!formatFuncHandle) {
1336 debug_error(DEBUG, "error : dlopen");
1340 mmfile_format_get_frame_from_memory = dlsym(formatFuncHandle, "mmfile_format_get_frame_from_memory");
1341 if (!mmfile_format_get_frame_from_memory) {
1342 debug_error(DEBUG, "error : load library");
1347 debug_msg(RELEASE, "data [%p], data_size[%d], is_accurate [%d]", data, datasize, is_accurate);
1349 ret = mmfile_format_get_frame_from_memory(data, datasize, timestamp, is_accurate, frame, size, width, height);
1350 if (ret == MMFILE_FORMAT_FAIL) {
1351 debug_error(DEBUG, "error : get frame");
1355 if (formatFuncHandle) dlclose(formatFuncHandle);
1357 return FILEINFO_ERROR_NONE;
1360 if (formatFuncHandle) dlclose(formatFuncHandle);
1362 return FILEINFO_ERROR_FILE_INTERNAL;
1366 int mm_file_check_uhqa(const char *filename, bool *is_uhqa)
1368 MMHandleType attrs = NULL;
1369 MMFileSourceType src = {0, };
1370 MMFILE_PARSE_INFO parse = {0, };
1373 #ifdef __MMFILE_DYN_LOADING__
1374 MMFILE_FUNC_HANDLE func_handle;
1376 ret = _load_dynamic_functions(&func_handle);
1378 debug_error(DEBUG, "load library error\n");
1379 return FILEINFO_ERROR_FILE_INTERNAL;
1382 if (filename == NULL) {
1383 ret = FILEINFO_ERROR_INVALID_ARGUMENT;
1386 if (strlen(filename) == 0) {
1387 ret = FILEINFO_ERROR_INVALID_ARGUMENT;
1392 /*set source file infomation*/
1393 MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
1395 ret = _is_file_exist(filename);
1396 if (ret != FILEINFO_ERROR_NONE) {
1401 ret = mm_attrs_new(g_content_attrs, ARRAY_SIZE(g_content_attrs), "content", NULL, NULL, &attrs);
1403 debug_error(DEBUG, "attribute internal error.\n");
1404 ret = FILEINFO_ERROR_FILE_INTERNAL;
1408 parse.type = MM_FILE_PARSE_TYPE_NORMAL;
1409 ret = _get_contents_info(attrs, &src, &parse);
1410 if (ret == FILEINFO_ERROR_NONE) {
1411 *is_uhqa = parse.is_uhqa;
1413 debug_error(DEBUG, "_get_contents_info failed\n");
1417 mm_attrs_free(attrs);
1421 #ifdef __MMFILE_DYN_LOADING__
1422 _unload_dynamic_functions(&func_handle);
1425 debug_fleave(RELEASE);