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 */
33 /* internal MM header files */
34 #include <mm_attrs_private.h>
37 /* internal MM File headers */
38 #include "mm_file_formats.h"
39 #include "mm_file_format_frame.h"
40 #include "mm_file_codecs.h"
41 #include "mm_file_utils.h"
52 gettimeofday(&tv,NULL);
53 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
63 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
66 #define _SEEK_POINT_ 3000 /*1000 = 1 seconds*/
68 #define MM_FILE_TAG_SYNCLYRICS "tag-synclyrics" /**< Synchronized Lyrics Information*/
78 MM_FILE_PARSE_TYPE_SIMPLE, /*parse audio/video track num only*/
79 MM_FILE_PARSE_TYPE_NORMAL, /*parse infomation without thumbnail*/
80 MM_FILE_PARSE_TYPE_ALL, /*parse all infomation*/
90 void *formatFuncHandle;
91 void *codecFuncHandle;
99 static mmf_attrs_construct_info_t g_tag_attrs[] = {
100 {"tag-artist", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
101 {"tag-title", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
102 {"tag-album", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
103 {"tag-genre", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
104 {"tag-author", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
105 {"tag-copyright", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
106 {"tag-date", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
107 {"tag-description", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
108 {"tag-comment", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
109 {"tag-artwork", MMF_VALUE_TYPE_DATA, MM_ATTRS_FLAG_RW, (void *)NULL},
110 {"tag-artwork-size", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
111 {"tag-artwork-mime", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
112 {"tag-track-num", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
113 {"tag-classification", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
114 {"tag-rating", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
115 {"tag-longitude", MM_ATTRS_TYPE_DOUBLE, MM_ATTRS_FLAG_RW, (void *)0},
116 {"tag-latitude", MM_ATTRS_TYPE_DOUBLE, MM_ATTRS_FLAG_RW, (void *)0},
117 {"tag-altitude", MM_ATTRS_TYPE_DOUBLE, MM_ATTRS_FLAG_RW, (void *)0},
118 {"tag-conductor", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
119 {"tag-unsynclyrics", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
120 {"tag-synclyrics-num", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
121 {"tag-synclyrics", MMF_VALUE_TYPE_DATA, MM_ATTRS_FLAG_RW, (void *)NULL},
122 {"tag-recdate", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
123 {"tag-rotate", MMF_VALUE_TYPE_STRING, MM_ATTRS_FLAG_RW, (void *)NULL},
126 static mmf_attrs_construct_info_t g_content_attrs[] = {
127 {"content-duration", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
128 {"content-video-codec", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
129 {"content-video-bitrate", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
130 {"content-video-fps", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
131 {"content-video-width", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
132 {"content-video-height", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
133 {"content-video-thumbnail", MMF_VALUE_TYPE_DATA, MM_ATTRS_FLAG_RW, (void *)NULL},
134 {"content-video-track-index", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
135 {"content-video-track-count", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
136 {"content-audio-codec", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
137 {"content-audio-bitrate", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
138 {"content-audio-channels", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
139 {"content-audio-samplerate", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
140 {"content-audio-track-index", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
141 {"content-audio-track-count", MMF_VALUE_TYPE_INT, MM_ATTRS_FLAG_RW, (void *)0},
144 #ifdef __MMFILE_DYN_LOADING__
145 #define MMFILE_FORMAT_SO_FILE_NAME "libmmfile_formats.so"
146 #define MMFILE_CODEC_SO_FILE_NAME "libmmfile_codecs.so"
148 int (*mmfile_format_open) (MMFileFormatContext **formatContext, MMFileSourceType *fileSrc);
149 int (*mmfile_format_read_stream) (MMFileFormatContext *formatContext);
150 int (*mmfile_format_read_frame) (MMFileFormatContext *formatContext, unsigned int timestamp, MMFileFormatFrame *frame);
151 int (*mmfile_format_read_tag) (MMFileFormatContext *formatContext);
152 int (*mmfile_format_close) (MMFileFormatContext *formatContext);
153 int (*mmfile_codec_open) (MMFileCodecContext **codecContext, int codecType, int codecId, MMFileCodecFrame *input);
154 int (*mmfile_codec_decode) (MMFileCodecContext *codecContext, MMFileCodecFrame *output);
155 int (*mmfile_codec_close) (MMFileCodecContext *codecContext);
156 int (*mmfile_format_get_frame) (const char* path, double timestamp, bool is_accurate, unsigned char **frame, int *size, int *width, int *height);
157 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);
160 #ifdef __MMFILE_DYN_LOADING__
161 static int _load_dynamic_functions (MMFILE_FUNC_HANDLE* pHandle)
163 // static int dll_func_initialized = 0; //disabled
167 /* Get from function argument */
168 void *formatFuncHandle = NULL;
169 void *codecFuncHandle = NULL;
172 if (dll_func_initialized) {
177 formatFuncHandle = dlopen (MMFILE_FORMAT_SO_FILE_NAME, RTLD_LAZY);
178 if (!formatFuncHandle) {
179 debug_error ("error: %s\n", dlerror());
184 mmfile_format_open = dlsym (formatFuncHandle, "mmfile_format_open");
185 mmfile_format_read_stream = dlsym (formatFuncHandle, "mmfile_format_read_stream");
186 mmfile_format_read_frame = dlsym (formatFuncHandle, "mmfile_format_read_frame");
187 mmfile_format_read_tag = dlsym (formatFuncHandle, "mmfile_format_read_tag");
188 mmfile_format_close = dlsym (formatFuncHandle, "mmfile_format_close");
190 if ( !mmfile_format_open ||
191 !mmfile_format_read_stream ||
192 !mmfile_format_read_frame ||
193 !mmfile_format_read_tag ||
194 !mmfile_format_close) {
196 debug_error ("error: %s\n", dlerror());
201 /*closed at app termination.*/
202 //dlclose (formatFuncHandle);
204 codecFuncHandle = dlopen (MMFILE_CODEC_SO_FILE_NAME, RTLD_LAZY | RTLD_GLOBAL);
205 if (!codecFuncHandle) {
206 debug_error ("error: %s\n", dlerror());
211 mmfile_codec_open = dlsym (codecFuncHandle, "mmfile_codec_open");
212 mmfile_codec_decode = dlsym (codecFuncHandle, "mmfile_codec_decode");
213 mmfile_codec_close = dlsym (codecFuncHandle, "mmfile_codec_close");
215 if ( !mmfile_codec_open || !mmfile_codec_decode || !mmfile_codec_close) {
216 debug_error ("error: %s\n", dlerror());
221 /*closed at app termination.*/
222 //dlclose (codecFuncHandle);
224 // dll_func_initialized = 1; // disabled
226 pHandle->codecFuncHandle = codecFuncHandle;
227 pHandle->formatFuncHandle = formatFuncHandle;
232 if (formatFuncHandle) dlclose (formatFuncHandle);
233 if (codecFuncHandle) dlclose (codecFuncHandle);
238 static void _unload_dynamic_functions (MMFILE_FUNC_HANDLE* pHandle)
242 if (pHandle->formatFuncHandle)
244 dlclose (pHandle->formatFuncHandle);
246 if (pHandle->codecFuncHandle)
248 dlclose (pHandle->codecFuncHandle);
255 #endif /* __MMFILE_DYN_LOADING__ */
261 _is_file_exist (const char *filename)
265 const char* to_access = (strstr(filename,"file://")!=NULL)? filename+7:filename;
266 ret = access (to_access, R_OK );
268 debug_error ("file [%s] not found.\n", to_access);
275 _info_set_attr_media (mmf_attrs_t *attrs, MMFileFormatContext *formatContext)
278 MMHandleType hattrs = CAST_MM_HANDLE(attrs);
280 if (formatContext->commandType == MM_FILE_TAG)
282 if (formatContext->title) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_TITLE, formatContext->title);
283 if (formatContext->artist) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_ARTIST, formatContext->artist);
284 if (formatContext->author) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_AUTHOR, formatContext->author);
285 if (formatContext->composer && formatContext->author == NULL)
286 mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_AUTHOR, formatContext->composer);
287 if (formatContext->album) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_ALBUM , formatContext->album);
288 if (formatContext->copyright) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_COPYRIGHT, formatContext->copyright);
289 if (formatContext->description) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_DESCRIPTION, formatContext->description);
290 if (formatContext->comment) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_COMMENT, formatContext->comment);
291 if (formatContext->genre) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_GENRE, formatContext->genre);
292 if (formatContext->classification) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_CLASSIFICATION, formatContext->classification);
293 if (formatContext->year) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_DATE, formatContext->year);
294 if (formatContext->tagTrackNum) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_TRACK_NUM, formatContext->tagTrackNum);
295 if (formatContext->rating) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_RATING, formatContext->rating);
296 if (formatContext->conductor) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_CONDUCTOR, formatContext->conductor);
297 if (formatContext->recDate) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_RECDATE, formatContext->recDate);
298 if (formatContext->rotate) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_ROTATE, formatContext->rotate);
299 mm_attrs_set_double_by_name(hattrs, MM_FILE_TAG_LONGITUDE, formatContext->longitude);
300 mm_attrs_set_double_by_name(hattrs, MM_FILE_TAG_LATIDUE, formatContext->latitude);
301 mm_attrs_set_double_by_name(hattrs, MM_FILE_TAG_ALTIDUE, formatContext->altitude);
302 mm_attrs_set_int_by_name(hattrs, MM_FILE_TAG_SYNCLYRICS_NUM, formatContext->syncLyricsNum);
304 if ((formatContext->syncLyricsNum > 0) && (formatContext->syncLyrics))
305 mm_attrs_set_data_by_name (hattrs, MM_FILE_TAG_SYNCLYRICS, formatContext->syncLyrics, formatContext->syncLyricsNum);
307 if (formatContext->unsyncLyrics) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_UNSYNCLYRICS, formatContext->unsyncLyrics);
309 if (formatContext->artwork && formatContext->artworkSize > 0) {
310 void *artworkCopy = NULL;
311 artworkCopy = mmfile_malloc ((formatContext->artworkSize));
312 if ( NULL != artworkCopy ) {
313 memcpy (artworkCopy, formatContext->artwork, formatContext->artworkSize);
314 mm_attrs_set_data_by_name (hattrs, MM_FILE_TAG_ARTWORK,artworkCopy, formatContext->artworkSize);
315 mm_attrs_set_int_by_name (hattrs, MM_FILE_TAG_ARTWORK_SIZE, formatContext->artworkSize);
316 if (formatContext->artworkMime) mm_attrs_set_string_by_name(hattrs, MM_FILE_TAG_ARTWORK_MIME, formatContext->artworkMime);
320 else if (formatContext->commandType == MM_FILE_CONTENTS)
323 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_DURATION, formatContext->duration);
324 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_AUDIO_TRACK_COUNT, formatContext->audioTotalTrackNum);
325 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, formatContext->videoTotalTrackNum);
327 if (formatContext->videoTotalTrackNum > 0 &&
328 formatContext->nbStreams > 0 &&
329 formatContext->streams[MMFILE_VIDEO_STREAM]) {
331 MMFileFormatStream *videoStream = formatContext->streams[MMFILE_VIDEO_STREAM];
333 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_VIDEO_CODEC, videoStream->codecId);
334 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_VIDEO_BITRATE, videoStream->bitRate);
335 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_VIDEO_FPS, videoStream->framePerSec);
336 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_VIDEO_WIDTH, videoStream->width);
337 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_VIDEO_HEIGHT, videoStream->height);
339 if (formatContext->thumbNail && formatContext->thumbNail->frameData) {
340 void *thumbNailCopy = NULL;
341 thumbNailCopy = mmfile_malloc (formatContext->thumbNail->frameSize);
343 if (NULL != thumbNailCopy) {
344 memcpy (thumbNailCopy, formatContext->thumbNail->frameData, formatContext->thumbNail->frameSize);
345 mm_attrs_set_data_by_name (hattrs, MM_FILE_CONTENT_VIDEO_THUMBNAIL, thumbNailCopy, formatContext->thumbNail->frameSize);
346 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_VIDEO_WIDTH, formatContext->thumbNail->frameWidth);
347 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_VIDEO_HEIGHT, formatContext->thumbNail->frameHeight);
352 if (formatContext->audioTotalTrackNum > 0 &&
353 formatContext->nbStreams > 0 &&
354 formatContext->streams[MMFILE_AUDIO_STREAM]) {
356 MMFileFormatStream *audioStream = formatContext->streams[MMFILE_AUDIO_STREAM];
358 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_AUDIO_CODEC, audioStream->codecId);
359 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_AUDIO_CHANNELS, audioStream->nbChannel);
360 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_AUDIO_BITRATE, audioStream->bitRate);
361 mm_attrs_set_int_by_name (hattrs, MM_FILE_CONTENT_AUDIO_SAMPLERATE, audioStream->samplePerSec);
370 ret = mmf_attrs_commit ((MMHandleType)hattrs);
376 _get_contents_info (mmf_attrs_t *attrs, MMFileSourceType *src, MMFILE_PARSE_INFO *parse)
378 MMFileFormatContext *formatContext = NULL;
379 MMFileCodecContext *codecContext = NULL;
380 MMFileFormatFrame frameContext = {0,};
381 MMFileCodecFrame codecFrame = {0,};
382 MMFileCodecFrame decodedFrame = {0,};
387 return MM_ERROR_FILE_INTERNAL;
389 ret = mmfile_format_open (&formatContext, src);
390 if (MMFILE_FORMAT_FAIL == ret || formatContext == NULL) {
391 debug_error ("error: mmfile_format_open\n");
392 ret = MM_ERROR_FILE_INTERNAL;
397 * if MM_FILE_PARSE_TYPE_SIMPLE, just get number of each stream.
399 parse->audio_track_num = formatContext->audioTotalTrackNum;
400 parse->video_track_num = formatContext->videoTotalTrackNum;
402 if (parse->type >= MM_FILE_PARSE_TYPE_NORMAL) {
403 ret = mmfile_format_read_stream (formatContext);
404 if (MMFILE_FORMAT_FAIL == ret) {
405 debug_error ("error: mmfile_format_read_stream\n");
406 ret = MM_ERROR_FILE_INTERNAL;
410 if (parse->type >= MM_FILE_PARSE_TYPE_ALL) {
411 if (formatContext->videoTotalTrackNum > 0) {
412 MMFileFormatStream *videoStream = formatContext->streams[MMFILE_VIDEO_STREAM];
413 unsigned int timestamp = _SEEK_POINT_;
415 ret = mmfile_format_read_frame (formatContext, timestamp, &frameContext);
416 if (MMFILE_FORMAT_FAIL == ret) {
417 debug_error ("error: mmfile_format_read_frame\n");
418 ret = MM_ERROR_FILE_INTERNAL;
422 if (frameContext.bCompressed) {
423 codecFrame.frameDataSize = frameContext.frameSize;
424 codecFrame.width = frameContext.frameWidth;
425 codecFrame.height = frameContext.frameHeight;
426 codecFrame.frameData = frameContext.frameData;
427 codecFrame.configLen = frameContext.configLenth;
428 codecFrame.configData = frameContext.configData;
429 codecFrame.version = videoStream->version;
431 ret = mmfile_codec_open (&codecContext, MMFILE_VIDEO_DECODE, videoStream->codecId, &codecFrame);
432 if (MMFILE_FORMAT_FAIL == ret) {
433 debug_error ("error: mmfile_codec_open\n");
434 ret = MM_ERROR_FILE_INTERNAL;
438 ret = mmfile_codec_decode (codecContext, &decodedFrame);
439 if (MMFILE_FORMAT_FAIL == ret) {
440 debug_error ("error: mmfile_codec_decode\n");
441 ret = MM_ERROR_FILE_INTERNAL;
445 /* set video thumbnail */
446 formatContext->thumbNail = mmfile_malloc (sizeof(MMFileFormatFrame));
447 if (NULL == formatContext->thumbNail) {
448 debug_error ("error: mmfile_malloc\n");
449 ret = MM_ERROR_FILE_INTERNAL;
453 formatContext->thumbNail->frameSize = decodedFrame.frameDataSize;
454 formatContext->thumbNail->frameWidth = decodedFrame.width;
455 formatContext->thumbNail->frameHeight = decodedFrame.height;
456 formatContext->thumbNail->frameData = decodedFrame.frameData;
457 formatContext->thumbNail->configLenth = 0;
458 formatContext->thumbNail->configData = NULL;
460 formatContext->thumbNail = mmfile_malloc (sizeof(MMFileFormatFrame));
461 if (NULL == formatContext->thumbNail) {
462 debug_error ("error: mmfile_format_read_frame\n");
463 ret = MM_ERROR_FILE_INTERNAL;
467 formatContext->thumbNail->frameSize = frameContext.frameSize;
468 formatContext->thumbNail->frameWidth = frameContext.frameWidth;
469 formatContext->thumbNail->frameHeight = frameContext.frameHeight;
470 formatContext->thumbNail->frameData = frameContext.frameData;
471 formatContext->thumbNail->configLenth = 0;
472 formatContext->thumbNail->configData = NULL;
478 #ifdef __MMFILE_TEST_MODE__
479 mmfile_format_print_frame (&frameContext);
482 formatContext->commandType = MM_FILE_CONTENTS;
484 if (parse->type >= MM_FILE_PARSE_TYPE_NORMAL)
485 _info_set_attr_media (attrs, formatContext);
487 if (frameContext.bCompressed) {
488 if (frameContext.frameData) mmfile_free (frameContext.frameData);
489 if (frameContext.configData) mmfile_free (frameContext.configData);
491 if (decodedFrame.frameData) {
492 mmfile_free (decodedFrame.frameData);
493 formatContext->thumbNail->frameData = NULL;
495 if (decodedFrame.configData) {
496 mmfile_free (decodedFrame.configData);
497 formatContext->thumbNail->configData = NULL;
500 if (frameContext.frameData) {
501 mmfile_free (frameContext.frameData);
502 formatContext->thumbNail->frameData = NULL;
504 if (frameContext.configData) {
505 mmfile_free (frameContext.configData);
506 formatContext->thumbNail->configData = NULL;
510 if (formatContext) { mmfile_format_close (formatContext); }
511 if (codecContext) { mmfile_codec_close (codecContext); }
513 return MM_ERROR_NONE;
516 formatContext->commandType = MM_FILE_CONTENTS;
518 if (frameContext.bCompressed) {
519 if (frameContext.frameData)
520 mmfile_free (frameContext.frameData);
522 if (frameContext.configData)
523 mmfile_free (frameContext.configData);
525 if (decodedFrame.frameData) {
526 mmfile_free (decodedFrame.frameData);
527 formatContext->thumbNail->frameData = NULL;
530 if (decodedFrame.configData) {
531 mmfile_free (decodedFrame.configData);
532 formatContext->thumbNail->configData = NULL;
535 if (frameContext.frameData) {
536 mmfile_free (frameContext.frameData);
537 formatContext->thumbNail->frameData = NULL;
540 if (frameContext.configData) {
541 mmfile_free (frameContext.configData);
542 formatContext->thumbNail->configData = NULL;
546 if (parse->type >= MM_FILE_PARSE_TYPE_NORMAL)
547 _info_set_attr_media (attrs, formatContext);
549 if (formatContext) { mmfile_format_close (formatContext); }
550 if (codecContext) { mmfile_codec_close (codecContext); }
551 return MM_ERROR_NONE;
555 if (frameContext.bCompressed) {
556 if (frameContext.frameData)
557 mmfile_free (frameContext.frameData);
559 if (frameContext.configData)
560 mmfile_free (frameContext.configData);
562 if (decodedFrame.frameData) {
563 mmfile_free (decodedFrame.frameData);
564 formatContext->thumbNail->frameData = NULL;
567 if (decodedFrame.configData) {
568 mmfile_free (decodedFrame.configData);
569 formatContext->thumbNail->configData = NULL;
572 if (frameContext.frameData) {
573 mmfile_free (frameContext.frameData);
574 formatContext->thumbNail->frameData = NULL;
577 if (frameContext.configData) {
578 mmfile_free (frameContext.configData);
579 formatContext->thumbNail->configData = NULL;
583 if (formatContext) { mmfile_format_close (formatContext); }
584 // if (codecContext) { mmfile_codec_close (codecContext); } /*dead code*/
591 _get_tag_info (mmf_attrs_t *attrs, MMFileSourceType *src)
593 MMFileFormatContext *formatContext = NULL;
596 ret = mmfile_format_open (&formatContext, src);
597 if (MMFILE_FORMAT_FAIL == ret || formatContext == NULL) {
598 debug_error ("error: mmfile_format_open\n");
599 ret = MM_ERROR_FILE_INTERNAL;
603 ret = mmfile_format_read_tag (formatContext);
604 if (MMFILE_FORMAT_FAIL == ret) {
605 debug_warning ("reading tag is fail\n");
606 ret = MM_ERROR_FILE_INTERNAL;
610 formatContext->commandType = MM_FILE_TAG;
612 _info_set_attr_media (attrs, formatContext);
614 if (formatContext) { mmfile_format_close (formatContext); }
616 return MM_ERROR_NONE;
620 if (formatContext) { mmfile_format_close (formatContext); }
622 return MM_ERROR_FILE_INTERNAL;
629 int mm_file_get_attrs(MMHandleType attrs, char **err_attr_name, const char *first_attribute_name, ...)
631 int ret = MM_ERROR_NONE;
636 debug_error ("Invalid arguments [attrs 0]\n");
637 return MM_ERROR_INVALID_ARGUMENT;
640 if ( first_attribute_name == NULL)
642 debug_error ("Invalid arguments [first_attribute_name null]\n");
643 return MM_ERROR_INVALID_ARGUMENT;
646 /* get requested attributes */
647 va_start (var_args, first_attribute_name);
648 ret = mm_attrs_get_valist(attrs, err_attr_name, first_attribute_name, var_args);
651 if (ret != MM_ERROR_NONE)
655 debug_error ("failed to get %s\n", *err_attr_name);
662 int mm_file_get_synclyrics_info(MMHandleType tag_attrs, int index, unsigned long *time_info, char **lyrics)
664 int ret = MM_ERROR_NONE;
665 AvSynclyricsInfo* sync_lyric_item = NULL;
666 GList *synclyrics_list = NULL;
670 if ( (mmf_attrs_t*)tag_attrs == NULL) {
671 debug_error ("invalid handle");
672 return MM_ERROR_INVALID_ARGUMENT;
675 ret = mm_attrs_get_data_by_name (tag_attrs, MM_FILE_TAG_SYNCLYRICS, (void **)&synclyrics_list);
676 if(ret != MM_ERROR_NONE) {
677 #ifdef __MMFILE_TEST_MODE__
678 debug_warning ( "get data fail");
683 if(synclyrics_list != NULL) {
685 sync_lyric_item = (AvSynclyricsInfo*)g_list_nth_data(synclyrics_list, index);
687 if(sync_lyric_item == NULL) {
688 #ifdef __MMFILE_TEST_MODE__
689 debug_warning ( "synclyric item is NULL");
691 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
694 *time_info = sync_lyric_item->time_info;
695 *lyrics = sync_lyric_item->lyric_info;
698 #ifdef __MMFILE_TEST_MODE__
699 debug_warning ( "synclyrics_list is NULL");
701 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
708 int mm_file_create_tag_attrs(MMHandleType *tag_attrs, const char *filename)
710 int ret = MM_ERROR_NONE;
711 mmf_attrs_t *attrs = NULL;
712 MMFileSourceType src;
716 /* Check argument here */
717 if (tag_attrs == NULL) {
718 debug_error ("Invalid arguments [tag null]\n");
719 return MM_ERROR_INVALID_ARGUMENT;
721 if (filename == NULL) {
722 debug_error ("Invalid arguments [filename null]\n");
723 return MM_ERROR_INVALID_ARGUMENT;
725 if ( strlen (filename) == 0) {
726 debug_error ("Invalid arguments [filename size 0]\n");
727 return MM_ERROR_INVALID_ARGUMENT;
731 #ifdef __MMFILE_DYN_LOADING__
732 MMFILE_FUNC_HANDLE func_handle;
734 ret = _load_dynamic_functions (&func_handle);
736 debug_error ("load library error\n");
737 return MM_ERROR_FILE_INTERNAL;
741 /*set source file infomation*/
742 MM_FILE_SET_MEDIA_FILE_SRC (src, filename);
744 ret = _is_file_exist (filename);
746 return MM_ERROR_FILE_NOT_FOUND;
749 attrs = (mmf_attrs_t *) mmf_attrs_new_from_data ("tag", g_tag_attrs, ARRAY_SIZE (g_tag_attrs), NULL, NULL);
751 debug_error ("attribute internal error.\n");
752 return MM_ERROR_FILE_INTERNAL;
755 ret = _get_tag_info (attrs, &src);
757 #ifdef __MMFILE_TEST_MODE__
758 if (ret != MM_ERROR_NONE) {
759 debug_error ("failed to get tag: %s\n", filename);
763 *tag_attrs = (MMHandleType)attrs;
765 #ifdef __MMFILE_DYN_LOADING__
766 _unload_dynamic_functions (&func_handle);
776 int mm_file_destroy_tag_attrs(MMHandleType tag_attrs)
778 void *artwork = NULL;
779 GList *synclyrics_list = NULL;
780 int ret = MM_ERROR_NONE;
783 if ( (mmf_attrs_t*)tag_attrs == NULL) {
784 debug_error ("invalid handle.\n");
785 return MM_ERROR_INVALID_ARGUMENT;
788 ret = mm_attrs_get_data_by_name (tag_attrs, MM_FILE_TAG_ARTWORK, &artwork);
790 if (artwork != NULL) {
791 mmfile_free (artwork);
794 ret = mm_attrs_get_data_by_name (tag_attrs, MM_FILE_TAG_SYNCLYRICS, (void **)&synclyrics_list);
796 if(synclyrics_list != NULL) {
797 mm_file_free_synclyrics_list(synclyrics_list);
800 mmf_attrs_free (tag_attrs);
808 int mm_file_create_content_attrs (MMHandleType *contents_attrs, const char *filename)
810 mmf_attrs_t *attrs = NULL;
811 MMFileSourceType src = {0,};
812 MMFILE_PARSE_INFO parse = {0,};
817 /* Check argument here */
818 if (contents_attrs == NULL) {
819 debug_error ("Invalid arguments [contents null]\n");
820 return MM_ERROR_INVALID_ARGUMENT;
822 if (filename == NULL) {
823 debug_error ("Invalid arguments [filename null]\n");
824 return MM_ERROR_INVALID_ARGUMENT;
826 if ( strlen (filename) == 0) {
827 debug_error ("Invalid arguments [filename size 0]\n");
828 return MM_ERROR_INVALID_ARGUMENT;
832 #ifdef __MMFILE_DYN_LOADING__
833 MMFILE_FUNC_HANDLE func_handle;
840 ret = _load_dynamic_functions (&func_handle);
842 debug_error ("load library error\n");
843 return MM_ERROR_FILE_INTERNAL;
847 printf ("%s, %d, _load_dynamic_functions() = %lld\n", __func__, __LINE__, gettime() - ti);
852 /*set source file infomation*/
853 MM_FILE_SET_MEDIA_FILE_SRC (src, filename);
855 ret = _is_file_exist (filename);
857 return MM_ERROR_FILE_NOT_FOUND;
860 attrs = (mmf_attrs_t *) mmf_attrs_new_from_data ("content", g_content_attrs, ARRAY_SIZE (g_content_attrs), NULL, NULL);
862 debug_error ("attribute internal error.\n");
863 return MM_ERROR_FILE_INTERNAL;
867 parse.type = MM_FILE_PARSE_TYPE_ALL;
868 ret = _get_contents_info (attrs, &src, &parse);
869 if (ret != MM_ERROR_NONE) {
870 debug_error ("failed to get contents: %s\n", filename);
873 *contents_attrs = (MMHandleType) attrs;
876 #ifdef __MMFILE_DYN_LOADING__
882 _unload_dynamic_functions (&func_handle);
885 printf ("%s, %d, _unload_dynamic_functions() = %lld\n", __func__, __LINE__, gettime() - ti);
898 int mm_file_create_tag_attrs_from_memory (MMHandleType *tag_attrs, const void *data, unsigned int size, int format)
900 mmf_attrs_t *attrs = NULL;
901 MMFileSourceType src;
902 MMFILE_PARSE_INFO parse = {0,};
907 /* Check argument here */
908 if (tag_attrs == NULL || data == NULL) {
909 debug_error ("Invalid arguments\n");
910 return MM_ERROR_INVALID_ARGUMENT;
913 #ifdef __MMFILE_DYN_LOADING__
914 MMFILE_FUNC_HANDLE func_handle;
916 ret = _load_dynamic_functions (&func_handle);
918 debug_error ("load library error\n");
919 return MM_ERROR_FILE_INTERNAL;
923 MM_FILE_SET_MEDIA_MEM_SRC (src, data, size, format);
926 attrs = (mmf_attrs_t *) mmf_attrs_new_from_data ("tag", g_tag_attrs, ARRAY_SIZE (g_tag_attrs), NULL, NULL);
928 debug_error ("attribute internal error.\n");
929 return MM_ERROR_FILE_INTERNAL;
932 parse.type = MM_FILE_PARSE_TYPE_ALL;
933 ret = _get_tag_info (attrs, &src);
935 *tag_attrs = (MMHandleType)attrs;
937 #ifdef __MMFILE_DYN_LOADING__
938 _unload_dynamic_functions (&func_handle);
948 int mm_file_create_content_attrs_from_memory (MMHandleType *contents_attrs, const void *data, unsigned int size, int format)
950 mmf_attrs_t *attrs = NULL;
951 MMFileSourceType src;
952 MMFILE_PARSE_INFO parse = {0,};
957 /* Check argument here */
958 if (contents_attrs == NULL || data == NULL) {
959 debug_error ("Invalid arguments\n");
960 return MM_ERROR_INVALID_ARGUMENT;
963 #ifdef __MMFILE_DYN_LOADING__
964 MMFILE_FUNC_HANDLE func_handle;
966 ret = _load_dynamic_functions (&func_handle);
968 debug_error ("load library error\n");
969 return MM_ERROR_FILE_INTERNAL;
973 MM_FILE_SET_MEDIA_MEM_SRC (src, data, size, format);
976 attrs = (mmf_attrs_t *) mmf_attrs_new_from_data ("content", g_content_attrs, ARRAY_SIZE (g_content_attrs), NULL, NULL);
978 debug_error ("attribute internal error.\n");
979 return MM_ERROR_FILE_INTERNAL;
982 parse.type = MM_FILE_PARSE_TYPE_ALL;
983 ret = _get_contents_info (attrs, &src, &parse);
984 if (ret != MM_ERROR_NONE) {
985 debug_error ("failed to get contents");
988 *contents_attrs = (MMHandleType)attrs;
990 #ifdef __MMFILE_DYN_LOADING__
991 _unload_dynamic_functions (&func_handle);
1001 int mm_file_destroy_content_attrs (MMHandleType contents_attrs)
1003 void *thumbnail = NULL;
1004 int ret = MM_ERROR_NONE;
1007 if ((mmf_attrs_t*)contents_attrs == NULL) {
1008 debug_error ("invalid handle.\n");
1009 return MM_ERROR_INVALID_ARGUMENT;
1012 ret = mm_attrs_get_data_by_name(contents_attrs, MM_FILE_CONTENT_VIDEO_THUMBNAIL, &thumbnail);
1013 if (thumbnail != NULL) {
1014 mmfile_free (thumbnail);
1017 mmf_attrs_free (contents_attrs);
1026 int mm_file_get_stream_info(const char* filename, int *audio_stream_num, int *video_stream_num)
1028 MMFileSourceType src = {0,};
1029 MMFILE_PARSE_INFO parse = {0,};
1035 if (filename == NULL || strlen (filename) == 0 || audio_stream_num == NULL || video_stream_num == NULL) {
1036 debug_error ("Invalid arguments\n");
1037 return MM_ERROR_INVALID_ARGUMENT;
1040 #ifdef __MMFILE_DYN_LOADING__
1041 MMFILE_FUNC_HANDLE func_handle;
1043 ret = _load_dynamic_functions (&func_handle);
1045 debug_error ("load library error\n");
1046 return MM_ERROR_FILE_INTERNAL;
1050 /*set source file infomation*/
1051 MM_FILE_SET_MEDIA_FILE_SRC (src, filename);
1053 ret = _is_file_exist (filename);
1055 return MM_ERROR_FILE_NOT_FOUND;
1057 parse.type = MM_FILE_PARSE_TYPE_SIMPLE;
1058 ret = _get_contents_info (NULL, &src, &parse);
1059 if (ret != MM_ERROR_NONE) {
1060 debug_error ("failed to get stream info: %s\n", filename);
1063 /*set number of each stream*/
1064 *audio_stream_num = parse.audio_track_num;
1065 *video_stream_num = parse.video_track_num;
1067 #ifdef __MMFILE_DYN_LOADING__
1068 _unload_dynamic_functions (&func_handle);
1077 int mm_file_create_content_attrs_simple(MMHandleType *contents_attrs, const char *filename)
1079 mmf_attrs_t *attrs = NULL;
1080 MMFileSourceType src = {0,};
1081 MMFILE_PARSE_INFO parse = {0,};
1086 #ifdef __MMFILE_DYN_LOADING__
1087 MMFILE_FUNC_HANDLE func_handle;
1089 ret = _load_dynamic_functions (&func_handle);
1091 debug_error ("load library error\n");
1092 return MM_ERROR_FILE_INTERNAL;
1095 if (filename == NULL) {
1096 return MM_ERROR_INVALID_ARGUMENT;
1098 if (strlen (filename) == 0)
1099 return MM_ERROR_INVALID_ARGUMENT;
1102 /*set source file infomation*/
1103 MM_FILE_SET_MEDIA_FILE_SRC (src, filename);
1105 ret = _is_file_exist (filename);
1107 return MM_ERROR_FILE_NOT_FOUND;
1110 attrs = (mmf_attrs_t *) mmf_attrs_new_from_data ("content", g_content_attrs, ARRAY_SIZE (g_content_attrs), NULL, NULL);
1112 debug_error ("attribute internal error.\n");
1113 return MM_ERROR_FILE_INTERNAL;
1116 parse.type = MM_FILE_PARSE_TYPE_NORMAL;
1117 ret = _get_contents_info (attrs, &src, &parse);
1118 if (ret != MM_ERROR_NONE) {
1119 debug_error ("failed to get contents: %s\n", filename);
1122 *contents_attrs = (MMHandleType) attrs;
1124 #ifdef __MMFILE_DYN_LOADING__
1125 _unload_dynamic_functions (&func_handle);
1134 int mm_file_get_video_frame(const char* path, double timestamp, bool is_accurate, unsigned char **frame, int *size, int *width, int *height)
1137 void *formatFuncHandle = NULL;
1140 debug_error ("Invalid arguments [Path is Null]\n");
1141 return MM_ERROR_INVALID_ARGUMENT;
1144 #ifdef __MMFILE_DYN_LOADING__
1145 /* Get from function argument */
1146 formatFuncHandle = dlopen (MMFILE_FORMAT_SO_FILE_NAME, RTLD_LAZY);
1147 if (!formatFuncHandle) {
1148 debug_error ("error : dlopen");
1152 mmfile_format_get_frame = dlsym (formatFuncHandle, "mmfile_format_get_frame");
1153 if ( !mmfile_format_get_frame ) {
1154 debug_error ("error : load library");
1159 #ifdef __MMFILE_TEST_MODE__
1160 debug_msg("file path [%s] is_accurate [%d]", path, is_accurate);
1163 ret = mmfile_format_get_frame(path, timestamp, is_accurate, frame, size, width, height);
1164 if (ret == MMFILE_FORMAT_FAIL) {
1165 debug_error ("error : get frame");
1169 if (formatFuncHandle) dlclose (formatFuncHandle);
1171 return MM_ERROR_NONE;
1174 if (formatFuncHandle) dlclose (formatFuncHandle);
1176 return MM_ERROR_FILE_INTERNAL;
1180 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)
1183 void *formatFuncHandle = NULL;
1186 debug_error ("Invalid arguments [data is Null]\n");
1187 return MM_ERROR_INVALID_ARGUMENT;
1190 if (datasize == 0) {
1191 debug_error ("Invalid arguments [datasize is zero]\n");
1192 return MM_ERROR_INVALID_ARGUMENT;
1195 #ifdef __MMFILE_DYN_LOADING__
1196 /* Get from function argument */
1197 formatFuncHandle = dlopen (MMFILE_FORMAT_SO_FILE_NAME, RTLD_LAZY);
1198 if (!formatFuncHandle) {
1199 debug_error ("error : dlopen");
1203 mmfile_format_get_frame_from_memory = dlsym (formatFuncHandle, "mmfile_format_get_frame_from_memory");
1204 if ( !mmfile_format_get_frame_from_memory ) {
1205 debug_error ("error : load library");
1210 #ifdef __MMFILE_TEST_MODE__
1211 debug_msg("data [%p], data_size[%d], is_accurate [%d]", data, datasize, is_accurate);
1214 ret = mmfile_format_get_frame_from_memory(data, datasize, timestamp, is_accurate, frame, size, width, height);
1215 if (ret == MMFILE_FORMAT_FAIL) {
1216 debug_error ("error : get frame");
1220 if (formatFuncHandle) dlclose (formatFuncHandle);
1222 return MM_ERROR_NONE;
1225 if (formatFuncHandle) dlclose (formatFuncHandle);
1227 return MM_ERROR_FILE_INTERNAL;