performance improve. reduced the count of files open and change the if else to switch. 97/40497/3 tizen_3.0.2015.q2_common accepted/tizen/common/20150605.124244 accepted/tizen/mobile/20150606.052943 accepted/tizen/tv/20150606.053648 accepted/tizen/wearable/20150606.054511 submit/tizen/20150604.122320
authorji.yong.seo <ji.yong.seo@samsung.com>
Thu, 4 Jun 2015 10:38:15 +0000 (19:38 +0900)
committerji.yong.seo <ji.yong.seo@samsung.com>
Thu, 4 Jun 2015 10:49:13 +0000 (19:49 +0900)
Change-Id: Ie17b2ba9698a53499f72a61152a7e89bad93197f

formats/ffmpeg/mm_file_format_aac.c
formats/ffmpeg/mm_file_format_frame.c
formats/ffmpeg/mm_file_format_imelody.c
formats/ffmpeg/mm_file_format_midi.c
formats/ffmpeg/mm_file_format_mmf.c
formats/ffmpeg/mm_file_format_mp3.c
formats/ffmpeg/mm_file_format_wav.c
formats/ffmpeg/mm_file_formats.c
packaging/libmm-fileinfo.spec
utils/include/mm_file_utils.h
utils/mm_file_util_validity.c

index df6f9db..11d19f8 100755 (executable)
@@ -765,10 +765,10 @@ int mmfile_format_open_aac (MMFileFormatContext *formatContext)
        }
 
        if (formatContext->pre_checked == 0) {
-               res = MMFileFormatIsValidAAC (formatContext->uriFileName);
+               res = MMFileFormatIsValidAAC (NULL, formatContext->uriFileName);
                if (res == 0) {
                        debug_error("It is not AAC file\n");
-                       return MMFILE_FORMAT_FAIL;        
+                       return MMFILE_FORMAT_FAIL;
                }
        }
 
index 51adabb..eb28c73 100755 (executable)
@@ -135,18 +135,29 @@ static int __getMimeType(int formatId, char *mimeType)
 static int __get_fileformat(const char *urifilename, int *format)
 {
        int index;
+       int ret = 0;
+       MMFileIOHandle *fp = NULL;
 
        debug_error("%s\n", urifilename);
 
+       ret = mmfile_open (&fp, urifilename, MMFILE_RDONLY);
+
+       if (ret == MMFILE_IO_FAILED) {
+               debug_error ("error: mmfile_open\n");
+               if(fp)
+                       mmfile_close(fp);
+               return MMFILE_FORMAT_FAIL;
+       }
+
        for (index = 0; index < MM_FILE_FORMAT_NUM; index++) {
                debug_msg ("search index = [%d]\n", index);
                switch (index) {
                        case MM_FILE_FORMAT_QT:
                        case MM_FILE_FORMAT_3GP:
                        case MM_FILE_FORMAT_MP4: {
-                               if (MMFileFormatIsValidMP4 (urifilename)) {
+                               if (MMFileFormatIsValidMP4 (fp, NULL)) {
                                        *format = MM_FILE_FORMAT_3GP;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
@@ -154,34 +165,34 @@ static int __get_fileformat(const char *urifilename, int *format)
                        case MM_FILE_FORMAT_ASF:
                        case MM_FILE_FORMAT_WMA:
                        case MM_FILE_FORMAT_WMV: {
-                               if (MMFileFormatIsValidASF (urifilename)) {
+                               if (MMFileFormatIsValidASF (fp, NULL)) {
                                        *format = MM_FILE_FORMAT_ASF;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_DIVX:
                        case MM_FILE_FORMAT_AVI: {
-                               if (MMFileFormatIsValidAVI(urifilename)) {
+                               if (MMFileFormatIsValidAVI(fp, NULL)) {
                                        *format = MM_FILE_FORMAT_AVI;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_MATROSKA: {
-                               if (MMFileFormatIsValidMatroska (urifilename)) {
+                               if (MMFileFormatIsValidMatroska (fp, NULL)) {
                                        *format = MM_FILE_FORMAT_MATROSKA;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_FLV: {
-                               if (MMFileFormatIsValidFLV (urifilename)) {
+                               if (MMFileFormatIsValidFLV (fp, NULL)) {
                                        *format = MM_FILE_FORMAT_FLV;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
@@ -217,7 +228,17 @@ static int __get_fileformat(const char *urifilename, int *format)
        }
 
        *format = -1;
+
+       if(fp)
+               mmfile_close(fp);
+
        return MMFILE_FORMAT_FAIL;
+
+FILE_FORMAT_SUCCESS:
+       if(fp)
+               mmfile_close(fp);
+
+       return MMFILE_FORMAT_SUCCESS;
 }
 
 static int __mmfile_get_frame(AVFormatContext *pFormatCtx, double timestamp, bool is_accurate, unsigned char **frame, int *size, int *width, int *height)
index 5baefbd..eda11f2 100755 (executable)
@@ -107,10 +107,10 @@ int mmfile_format_open_imy (MMFileFormatContext *formatContext)
        }
 
        if (formatContext->pre_checked == 0) {
-               ret = MMFileFormatIsValidIMY (formatContext->uriFileName);
+               ret = MMFileFormatIsValidIMY (NULL, formatContext->uriFileName);
                if (ret == 0) {
                        debug_error("It is not imelody file\n");
-                       return MMFILE_FORMAT_FAIL;        
+                       return MMFILE_FORMAT_FAIL;
                }
        }
 
index c05e5b2..f919fb3 100755 (executable)
@@ -266,7 +266,7 @@ int mmfile_format_open_mid (MMFileFormatContext *formatContext)
        }
 
        if (formatContext->pre_checked == 0) {
-               res = MMFileFormatIsValidMID (formatContext->uriFileName);
+               res = MMFileFormatIsValidMID (NULL, formatContext->uriFileName);
                if ( res == 0 ) {
                        debug_error("It is not MIDI file\n");
                        return MMFILE_FORMAT_FAIL;
index 37a4bb1..e5ed1ae 100755 (executable)
@@ -598,19 +598,19 @@ int mmfile_format_close_mmf       (MMFileFormatContext *formatContext);
 
 EXPORT_API
 int mmfile_format_open_mmf (MMFileFormatContext *formatContext)
-{   
+{
        int ret = 0;
 
        if (NULL == formatContext) {
                debug_error ("error: formatContext is NULL\n");
-               return MMFILE_FORMAT_FAIL;        
+               return MMFILE_FORMAT_FAIL;
        }
 
        if (formatContext->pre_checked == 0) {
-               ret = MMFileFormatIsValidMMF (formatContext->uriFileName);
+               ret = MMFileFormatIsValidMMF (NULL, formatContext->uriFileName);
                if (ret == 0) {
                        debug_error ("error: it is not MMF file\n");
-                       return MMFILE_FORMAT_FAIL;         
+                       return MMFILE_FORMAT_FAIL;
                }
        }
 
index 2fc7740..f8c35d8 100755 (executable)
@@ -89,7 +89,7 @@ int mmfile_format_open_mp3 (MMFileFormatContext *formatContext)
     int ret = 0;
 
        debug_fenter();
-       
+
     if (NULL == formatContext)
     {
         debug_error("formatContext is NULL\n");
@@ -97,15 +97,14 @@ int mmfile_format_open_mp3 (MMFileFormatContext *formatContext)
     }
 
        if (formatContext->pre_checked == 0) {
-               ret = MMFileFormatIsValidMP3 (formatContext->uriFileName,5);
+               ret = MMFileFormatIsValidMP3 (NULL, formatContext->uriFileName, 5);
                if ( ret == 0 )
                {
                        debug_error("It is not mp3 file\n");
-                       return MMFILE_FORMAT_FAIL;        
+                       return MMFILE_FORMAT_FAIL;
                }
        }
 
-    
     formatContext->ReadStream   = mmfile_format_read_stream_mp3;
     formatContext->ReadFrame    = mmfile_format_read_frame_mp3;
     formatContext->ReadTag      = mmfile_format_read_tag_mp3;
index 38ff860..8d6cdfe 100755 (executable)
@@ -201,11 +201,11 @@ int mmfile_format_open_wav (MMFileFormatContext *formatContext)
        }
 
        if (formatContext->pre_checked == 0) {
-               ret = MMFileFormatIsValidWAV (formatContext->uriFileName);
+               ret = MMFileFormatIsValidWAV (NULL, formatContext->uriFileName);
                if ( ret == 0 )
                {
                        debug_error("It is not wav file\n");
-                       return MMFILE_FORMAT_FAIL;        
+                       return MMFILE_FORMAT_FAIL;
                }
        }
 
index d7bc5f5..cac4fed 100755 (executable)
 
 #define _MMF_FILE_FILEEXT_MAX 128
 
+#define MMFILE_EXT_MP4         0x6D7034
+#define MMFILE_EXT_MPEG4       0x6D70656734
+#define MMFILE_EXT_M4A         0x6D3461
+#define MMFILE_EXT_MPG         0x6D7067
+#define MMFILE_EXT_MPG4                0x6D706734
+#define MMFILE_EXT_M4V         0x6D3476
+#define MMFILE_EXT_3GP         0x336770
+#define MMFILE_EXT_AMR         0x616D72
+#define MMFILE_EXT_AWB         0x617762
+#define MMFILE_EXT_WAV         0x776176
+#define MMFILE_EXT_MID         0x6D6964
+#define MMFILE_EXT_MIDI                0x6D696D69
+#define MMFILE_EXT_SPM         0x73706D
+#define MMFILE_EXT_MP3         0x6D7033
+#define MMFILE_EXT_AAC         0x616163
+#define MMFILE_EXT_XMF         0x786D66
+#define MMFILE_EXT_MXMF                0x6D786D66
+#define MMFILE_EXT_MMF         0x6D6D66
+#define MMFILE_EXT_MA2         0x6D6132
+#define MMFILE_EXT_IMY         0x696D79
+#define MMFILE_EXT_AVI         0x617669
+#define MMFILE_EXT_DIVX                0x64697678
+#define MMFILE_EXT_ASF         0x617366
+#define MMFILE_EXT_ASX         0x617378
+#define MMFILE_EXT_WMA         0x776D61
+#define MMFILE_EXT_WMV         0x776D76
+#define MMFILE_EXT_OGG         0x6F6767
+#define MMFILE_EXT_MKV         0x6D6B76
+#define MMFILE_EXT_MKA         0x6D6B61
+#define MMFILE_EXT_MOV         0x6D6F76
+#define MMFILE_EXT_FLAC                0x666C6163
+#define MMFILE_EXT_FLV         0x666C76
+
 int (*MMFileOpenFunc[MM_FILE_FORMAT_NUM+1]) (MMFileFormatContext *fileContext) = {
        mmfile_format_open_ffmpg,       /* 3GP */
        mmfile_format_open_ffmpg,       /* ASF */
@@ -125,39 +158,16 @@ static int
 _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum, int *isdrm)
 {
        const char      *fileName = NULL;
-       char            extansion_name[_MMF_FILE_FILEEXT_MAX];
-       int                     pos = 0;
        int                     filename_len = 0;
        int                     index = 0, skip_index = 0;
+       int ret = 0;
+       MMFileIOHandle *fp = NULL;
 
        if (fileSrc->type == MM_FILE_SRC_TYPE_FILE) {
+               unsigned long long file_extansion = 0;
+
                fileName = (const char *)(fileSrc->file.path);
                filename_len = strlen (fileName);
-               pos = filename_len;
-
-               /**
-                * Get file extension from file's name
-                */
-               while (pos > 0) {
-                       pos--;
-                       if (fileName[pos] == '.')
-                               break;
-               }
-
-               memset (extansion_name, 0x00, _MMF_FILE_FILEEXT_MAX);
-
-               /*extract metadata for all file. ex)a , a. , a.mp3*/
-               if (pos == 0) {
-                       /*even though there is no file extension, extracto metadata*/
-                       debug_msg ("no file extension");
-               }
-               else if (_MMF_FILE_FILEEXT_MAX > (filename_len - pos - 1)) {
-                       strncpy (extansion_name, fileName + pos +1 , (filename_len - pos - 1));
-                       extansion_name[filename_len - pos - 1] = '\0';
-               } else {
-                       debug_error ("invalid filename. destination length: %d, source length: %d.\n", _MMF_FILE_FILEEXT_MAX, (filename_len - pos - 1));
-                       return MMFILE_FORMAT_FAIL;              /*invalid file name*/
-               }
 
 #ifdef DRM_SUPPORT
                /**
@@ -174,7 +184,39 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        ret = drm_get_file_type(fileSrc->file.path, &file_type);
                        if((ret == DRM_RETURN_SUCCESS) && ((file_type == DRM_TYPE_OMA_V1) ||(file_type == DRM_TYPE_OMA_V2)))
                        {
+                               char extansion_name[_MMF_FILE_FILEEXT_MAX];
+                               int i = 0;
                                is_drm = TRUE;
+
+                               memset(&contentInfo, 0x0, sizeof(drm_content_info_s));
+
+                               if (DRM_RETURN_SUCCESS != drm_get_content_info (fileSrc->file.path, &contentInfo)) {
+                                       debug_error ("error: drm_get_content_info\n");
+                                       goto FILE_FORMAT_FAIL;
+                               }
+
+                               memset (extansion_name, 0x00, _MMF_FILE_FILEEXT_MAX);
+                               if (MMFILE_UTIL_SUCCESS != mmfile_util_get_file_ext (contentInfo.mime_type, extansion_name)) {
+                                       debug_error ("error: mmfile_util_get_ffmpeg_format\n");
+                                       goto FILE_FORMAT_FAIL;
+                               }
+
+                               file_extansion = 0;
+
+                               for(i=0; i<stlen(extansion_name); i++) {
+                                       file_extansion |= (extansion_name[i] >= 'A' && extansion_name[i] <= 'Z' ? extansion_name[i] + 0x20 : extansion_name[i]) << i * 8;
+                               }
+
+                               *urifilename = mmfile_malloc (MMFILE_DRM_URI_LEN + filename_len + 1);
+                               if (!*urifilename) {
+                                       debug_error ("error: mmfile_malloc uriname\n");
+                                       goto FILE_FORMAT_FAIL;
+                               }
+
+                               memset (*urifilename, 0x00, MMFILE_DRM_URI_LEN + filename_len + 1);
+                               strncpy (*urifilename, MMFILE_DRM_URI, MMFILE_DRM_URI_LEN);
+                               strncat (*urifilename, fileName, filename_len);
+                               (*urifilename)[MMFILE_DRM_URI_LEN + filename_len] = '\0';
                        }
                }
 
@@ -182,17 +224,18 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                {
                        *isdrm = MM_FILE_DRM_OMA;
                        debug_error ("OMA DRM detected. Not Support DRM Content\n");
-                       return MMFILE_FORMAT_FAIL;              /*Not Support DRM Content*/
-               } 
-               else 
-#endif // DRM_SUPPORT                  
+                       goto FILE_FORMAT_FAIL;          /*Not Support DRM Content*/
+               }
+               else
+#endif // DRM_SUPPORT
                {
+                       int pos = filename_len;
                        *isdrm = MM_FILE_DRM_NONE;
 #ifdef __MMFILE_MMAP_MODE__
                        *urifilename = mmfile_malloc (MMFILE_MMAP_URI_LEN + filename_len + 1);
                        if (!*urifilename) {
                                debug_error ("error: mmfile_malloc uriname\n");
-                               return MMFILE_FORMAT_FAIL;
+                               goto FILE_FORMAT_FAIL;
                        }
 
                        memset (*urifilename, 0x00, MMFILE_MMAP_URI_LEN + filename_len + 1);
@@ -204,7 +247,7 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        *urifilename = mmfile_malloc (MMFILE_FILE_URI_LEN + filename_len + 1);
                        if (!*urifilename) {
                                debug_error ("error: mmfile_malloc uriname\n");
-                               return MMFILE_FORMAT_FAIL;
+                               goto FILE_FORMAT_FAIL;
                        }
 
                        memset (*urifilename, 0x00, MMFILE_FILE_URI_LEN + filename_len + 1);
@@ -212,6 +255,22 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        strncat (*urifilename, fileName, filename_len);
                        (*urifilename)[MMFILE_FILE_URI_LEN + filename_len] = '\0';
 #endif
+                       /**
+                        * Get file extension from file's name
+                        */
+                       while (pos > 0) {
+                               pos--;
+                               if (fileName[pos] == '.')
+                                       break;
+                               file_extansion |= (fileName[pos] >= 'A' && fileName[pos] <= 'Z' ? fileName[pos] + 0x20 : fileName[pos]) << (filename_len - pos - 1) * 8;
+                       }
+               }
+
+               ret = mmfile_open (&fp, *urifilename, MMFILE_RDONLY);
+
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto FILE_FORMAT_FAIL;
                }
 
                ///////////////////////////////////////////////////////////////////////
@@ -222,179 +281,204 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                debug_msg ("Get codec type of [%s].\n", extansion_name);
                #endif
 
-               if (strcasecmp (extansion_name, "mp4") == 0   ||
-                       strcasecmp (extansion_name, "mpeg4") == 0 ||
-                       strcasecmp (extansion_name, "m4a") == 0   ||
-                       strcasecmp (extansion_name, "mpg") == 0   ||
-                       strcasecmp (extansion_name, "mpg4") == 0  ||
-                       strcasecmp (extansion_name, "m4v") == 0 ) {
-
-                       if (MMFileFormatIsValidMP4 (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_MP4;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_MP4;
-                       goto PROBE_PROPER_FILE_TYPE;
+               switch(file_extansion) {
+                       case MMFILE_EXT_MP4:
+                       case MMFILE_EXT_MPEG4:
+                       case MMFILE_EXT_M4A:
+                       case MMFILE_EXT_MPG:
+                       case MMFILE_EXT_MPG4:
+                       case MMFILE_EXT_M4V:
+                               if (MMFileFormatIsValidMP4 (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_MP4;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_MP4;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_3GP:
+                               if (MMFileFormatIsValidMP4 (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_3GP;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_3GP;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_AMR:
+                       case MMFILE_EXT_AWB:
+                               if (MMFileFormatIsValidAMR (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_AMR;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_AMR;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_WAV:
+                               if (MMFileFormatIsValidWAV (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_WAV;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_WAV;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_MID:
+                       case MMFILE_EXT_MIDI:
+                       case MMFILE_EXT_SPM:
+                               if (MMFileFormatIsValidMID (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_MID;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_MID;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_MP3:
+                               if (MMFileFormatIsValidMP3 (fp, NULL, 5)) {
+                                       *formatEnum = MM_FILE_FORMAT_MP3;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_MP3;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_AAC:
+                               if (MMFileFormatIsValidAAC (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_AAC;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_AAC;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_XMF:
+                       case MMFILE_EXT_MXMF:
+                               if (MMFileFormatIsValidMID (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_MID;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_MID;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_MMF:
+                       case MMFILE_EXT_MA2:
+                               if (MMFileFormatIsValidMMF (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_MMF;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_MMF;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_IMY:
+                               if (MMFileFormatIsValidIMY (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_IMELODY;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_IMELODY;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
 
-               } else if (strcasecmp (extansion_name, "3gp") == 0) {
-                       if (MMFileFormatIsValidMP4 (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_3GP;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_3GP;
-                       goto PROBE_PROPER_FILE_TYPE;
+                       case MMFILE_EXT_AVI:
+                               if (MMFileFormatIsValidAVI (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_AVI;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_AVI;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_DIVX:
+                               if (MMFileFormatIsValidAVI (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_DIVX;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_DIVX;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
 
-               } else if (strcasecmp (extansion_name, "amr") == 0 ||
-                                  strcasecmp (extansion_name, "awb") == 0) {
+                       case MMFILE_EXT_ASF:
+                       case MMFILE_EXT_ASX:
+                               if (MMFileFormatIsValidASF (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_ASF;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_ASF;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_WMA:
+                               if (MMFileFormatIsValidWMA (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_WMA;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_WMA;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_WMV:
+                               if (MMFileFormatIsValidWMV (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_WMV;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_WMV;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_OGG:
+                               if (MMFileFormatIsValidOGG (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_OGG;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_OGG;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
 
-                       if (MMFileFormatIsValidAMR (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_AMR;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_AMR;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "wav") == 0) {
-                       if (MMFileFormatIsValidWAV (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_WAV;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_WAV;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "mid")  == 0 ||
-                                  strcasecmp (extansion_name, "midi") == 0 ||
-                                  strcasecmp (extansion_name, "spm")  == 0 ) {
-
-                       if (MMFileFormatIsValidMID (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_MID;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_MID;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "mp3") == 0) {
-                       if (MMFileFormatIsValidMP3 (*urifilename,5)) {
-                               *formatEnum = MM_FILE_FORMAT_MP3;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_MP3;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "aac") == 0) {
-                       if (MMFileFormatIsValidAAC (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_AAC;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_AAC;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "xmf") == 0 ||
-                                strcasecmp (extansion_name, "mxmf") == 0) {
-                       if (MMFileFormatIsValidMID (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_MID;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_MID;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (!strcasecmp (extansion_name, "mmf") ||
-                                  !strcasecmp (extansion_name, "ma2")) {
-                       if (MMFileFormatIsValidMMF (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_MMF;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_MMF;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "imy") == 0) {
-                       if (MMFileFormatIsValidIMY (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_IMELODY;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_IMELODY;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "avi") == 0) {
-                       if (MMFileFormatIsValidAVI (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_AVI;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_AVI;
-                       goto PROBE_PROPER_FILE_TYPE;
-               } else if (strcasecmp (extansion_name, "divx") == 0) {
-                       if (MMFileFormatIsValidAVI (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_DIVX;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_DIVX;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "asf") == 0 ||
-                                  strcasecmp (extansion_name, "asx") == 0 ) {
-                       if (MMFileFormatIsValidASF (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_ASF;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_ASF;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "wma") == 0) {
-                       if (MMFileFormatIsValidWMA (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_WMA;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_WMA;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "wmv") == 0) {
-                       if (MMFileFormatIsValidWMV (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_WMV;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_WMV;
-                       goto PROBE_PROPER_FILE_TYPE;
-
-               } else if (strcasecmp (extansion_name, "ogg") == 0) {
-                       if (MMFileFormatIsValidOGG (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_OGG;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_OGG;
-                       goto PROBE_PROPER_FILE_TYPE;
-               } else if (strcasecmp (extansion_name, "mkv") == 0 ||
-                                  strcasecmp (extansion_name, "mka") == 0) {
-                       if (MMFileFormatIsValidMatroska (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_MATROSKA;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_MATROSKA;
-                       goto PROBE_PROPER_FILE_TYPE;
-               } else if (strcasecmp (extansion_name, "mov") == 0) {
-                       if (MMFileFormatIsValidMP4 (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_QT;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_QT;
-                       goto PROBE_PROPER_FILE_TYPE;
-               } else if (strcasecmp (extansion_name, "flac") == 0) {
-                       if (MMFileFormatIsValidFLAC (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_FLAC;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_FLAC;
-                       goto PROBE_PROPER_FILE_TYPE;
-               } else if (strcasecmp (extansion_name, "flv") == 0) {
-                       if (MMFileFormatIsValidFLV (*urifilename)) {
-                               *formatEnum = MM_FILE_FORMAT_FLV;
-                               return MMFILE_FORMAT_SUCCESS;
-                       }
-                       skip_index = MM_FILE_FORMAT_FLV;
-                       goto PROBE_PROPER_FILE_TYPE;
-               } else {
-                       debug_warning ("probe file type=%s\n", fileName);
-                       skip_index = -1;
-                       goto PROBE_PROPER_FILE_TYPE;
+                       case MMFILE_EXT_MKV:
+                       case MMFILE_EXT_MKA:
+                               if (MMFileFormatIsValidMatroska (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_MATROSKA;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_MATROSKA;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_MOV:
+                               if (MMFileFormatIsValidMP4 (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_QT;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_QT;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_FLAC:
+                               if (MMFileFormatIsValidFLAC (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_FLAC;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_FLAC;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       case MMFILE_EXT_FLV:
+                               if (MMFileFormatIsValidFLV (fp, NULL)) {
+                                       *formatEnum = MM_FILE_FORMAT_FLV;
+                                       goto FILE_FORMAT_SUCCESS;
+                               }
+                               skip_index = MM_FILE_FORMAT_FLV;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
+
+                       default :
+                               debug_warning ("probe file type=%s\n", fileName);
+                               skip_index = -1;
+                               goto PROBE_PROPER_FILE_TYPE;
+                               break;
                }
        } else if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) {
                char tempURIBuffer[MMFILE_URI_MAX_LEN] = {0,};
@@ -403,7 +487,14 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                *urifilename = mmfile_strdup (tempURIBuffer);
                if (!*urifilename) {
                        debug_error ("error: uri is NULL\n");
-                       return MMFILE_FORMAT_FAIL;
+                       goto FILE_FORMAT_FAIL;
+               }
+
+               ret = mmfile_open (&fp, *urifilename, MMFILE_RDONLY);
+
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto FILE_FORMAT_FAIL;
                }
 
                #ifdef __MMFILE_TEST_MODE__
@@ -412,9 +503,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
 
                switch (fileSrc->memory.format) {
                        case MM_FILE_FORMAT_3GP: {
-                               if (MMFileFormatIsValidMP4 (*urifilename)) {
+                               if (MMFileFormatIsValidMP4 (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_3GP;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_3GP;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -422,9 +513,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_MP4: {
-                               if (MMFileFormatIsValidMP4 (*urifilename)) {
+                               if (MMFileFormatIsValidMP4 (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_MP4;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_MP4;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -432,9 +523,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_AMR: {
-                               if (MMFileFormatIsValidAMR (*urifilename)) {
+                               if (MMFileFormatIsValidAMR (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_AMR;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_AMR;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -442,9 +533,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_WAV: {
-                               if (MMFileFormatIsValidWAV (*urifilename)) {
+                               if (MMFileFormatIsValidWAV (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_WAV;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_WAV;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -452,9 +543,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_MID: {
-                               if (MMFileFormatIsValidMID (*urifilename)) {
+                               if (MMFileFormatIsValidMID (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_MID;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_MID;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -462,9 +553,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_MP3: {
-                               if (MMFileFormatIsValidMP3 (*urifilename,5)) {
+                               if (MMFileFormatIsValidMP3 (fp, NULL, 5)) {
                                        *formatEnum = MM_FILE_FORMAT_MP3;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_MP3;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -472,9 +563,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_AAC: {
-                               if (MMFileFormatIsValidAAC (*urifilename)) {
+                               if (MMFileFormatIsValidAAC (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_AAC;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_AAC;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -482,9 +573,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_MMF: {
-                               if (MMFileFormatIsValidMMF (*urifilename)) {
+                               if (MMFileFormatIsValidMMF (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_MMF;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_MMF;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -492,9 +583,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_IMELODY: {
-                               if (MMFileFormatIsValidIMY (*urifilename)) {
+                               if (MMFileFormatIsValidIMY (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_IMELODY;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_IMELODY;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -502,9 +593,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_AVI: {
-                               if (MMFileFormatIsValidAVI (*urifilename)) {
+                               if (MMFileFormatIsValidAVI (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_AVI;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_AVI;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -512,9 +603,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_DIVX: {
-                               if (MMFileFormatIsValidAVI (*urifilename)) {
+                               if (MMFileFormatIsValidAVI (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_DIVX;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_DIVX;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -522,9 +613,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_ASF: {
-                               if (MMFileFormatIsValidASF (*urifilename)) {
+                               if (MMFileFormatIsValidASF (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_ASF;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_ASF;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -532,9 +623,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_WMA: {
-                               if (MMFileFormatIsValidWMA (*urifilename)) {
+                               if (MMFileFormatIsValidWMA (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_WMA;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_WMA;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -542,9 +633,9 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_WMV: {
-                               if (MMFileFormatIsValidWMV (*urifilename)) {
+                               if (MMFileFormatIsValidWMV (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_WMV;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_WMV;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -552,45 +643,45 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                        }
 
                        case MM_FILE_FORMAT_OGG: {
-                               if (MMFileFormatIsValidOGG (*urifilename)) {
+                               if (MMFileFormatIsValidOGG (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_OGG;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_OGG;
                                goto PROBE_PROPER_FILE_TYPE;
                        }
 
                        case MM_FILE_FORMAT_MATROSKA: {
-                               if (MMFileFormatIsValidMatroska (*urifilename)) {
+                               if (MMFileFormatIsValidMatroska (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_MATROSKA;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_MATROSKA;
                                goto PROBE_PROPER_FILE_TYPE;
                        }
 
                        case MM_FILE_FORMAT_QT: {
-                               if (MMFileFormatIsValidMP4 (*urifilename)) {
+                               if (MMFileFormatIsValidMP4 (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_QT;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_QT;
                                goto PROBE_PROPER_FILE_TYPE;
                        }
 
                        case MM_FILE_FORMAT_FLAC: {
-                               if (MMFileFormatIsValidFLAC (*urifilename)) {
+                               if (MMFileFormatIsValidFLAC (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_FLAC;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_FLAC;
                                goto PROBE_PROPER_FILE_TYPE;
                        }
 
                        case MM_FILE_FORMAT_FLV: {
-                               if (MMFileFormatIsValidFLV (*urifilename)) {
+                               if (MMFileFormatIsValidFLV (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_FLV;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                skip_index = MM_FILE_FORMAT_FLV;
                                goto PROBE_PROPER_FILE_TYPE;
@@ -605,7 +696,7 @@ _PreprocessFile (MMFileSourceType *fileSrc, char **urifilename, int *formatEnum,
                }
        } else {
                debug_error ("error: invaild input type[memory|file]\n");
-               return MMFILE_FORMAT_FAIL;
+               goto FILE_FORMAT_FAIL;
        }
 
 PROBE_PROPER_FILE_TYPE:
@@ -619,12 +710,12 @@ PROBE_PROPER_FILE_TYPE:
                        case MM_FILE_FORMAT_3GP:
                        case MM_FILE_FORMAT_MP4: {
                                if (skip_index == MM_FILE_FORMAT_QT || skip_index == MM_FILE_FORMAT_3GP || skip_index == MM_FILE_FORMAT_MP4)
-                                       break;
+                                       goto FILE_FORMAT_FAIL;
 
-                               if (MMFileFormatIsValidMP4 (*urifilename)) {
+                               if (MMFileFormatIsValidMP4 (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_3GP;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_3GP;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
@@ -633,12 +724,12 @@ PROBE_PROPER_FILE_TYPE:
                        case MM_FILE_FORMAT_WMA:
                        case MM_FILE_FORMAT_WMV: {
                                if (skip_index == MM_FILE_FORMAT_ASF || skip_index == MM_FILE_FORMAT_WMA || skip_index == MM_FILE_FORMAT_WMV)
-                                       break;
+                                       goto FILE_FORMAT_FAIL;
 
-                               if (MMFileFormatIsValidASF (*urifilename)) {
+                               if (MMFileFormatIsValidASF (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_ASF;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_ASF;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
@@ -646,111 +737,111 @@ PROBE_PROPER_FILE_TYPE:
                        case MM_FILE_FORMAT_DIVX:
                        case MM_FILE_FORMAT_AVI: {
                                if (skip_index == MM_FILE_FORMAT_DIVX || skip_index == MM_FILE_FORMAT_AVI)
-                                       break;
+                                       goto FILE_FORMAT_FAIL;
 
-                               if (MMFileFormatIsValidAVI(*urifilename)) {
+                               if (MMFileFormatIsValidAVI(fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_AVI;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_AVI;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_OGG: {
-                               if (MMFileFormatIsValidOGG (*urifilename)) {
+                               if (MMFileFormatIsValidOGG (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_OGG;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_OGG;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_AMR: {
-                               if (MMFileFormatIsValidAMR (*urifilename)) {
+                               if (MMFileFormatIsValidAMR (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_AMR;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_AMR;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_AAC: {
-                               if (MMFileFormatIsValidAAC (*urifilename)) {
+                               if (MMFileFormatIsValidAAC (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_AAC;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_AAC;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_MP3: {
-                               if (MMFileFormatIsValidMP3 (*urifilename,50)) {
+                               if (MMFileFormatIsValidMP3 (fp, NULL, 50)) {
                                        *formatEnum = MM_FILE_FORMAT_MP3;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_MP3;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_WAV: {
-                               if (MMFileFormatIsValidWAV (*urifilename)) {
+                               if (MMFileFormatIsValidWAV (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_WAV;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_WAV;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_MID: {
-                               if (MMFileFormatIsValidMID (*urifilename)) {
+                               if (MMFileFormatIsValidMID (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_MID;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_MID;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_MMF: {
-                               if (MMFileFormatIsValidMMF (*urifilename)) {
+                               if (MMFileFormatIsValidMMF (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_MMF;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_MMF;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_IMELODY: {
-                               if (MMFileFormatIsValidIMY (*urifilename)) {
+                               if (MMFileFormatIsValidIMY (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_IMELODY;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_IMELODY;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_MATROSKA: {
-                               if (MMFileFormatIsValidMatroska (*urifilename)) {
+                               if (MMFileFormatIsValidMatroska (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_MATROSKA;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_MATROSKA;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_FLAC: {
-                               if (MMFileFormatIsValidFLAC (*urifilename)) {
+                               if (MMFileFormatIsValidFLAC (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_FLAC;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_FLAC;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
 
                        case MM_FILE_FORMAT_FLV: {
-                               if (MMFileFormatIsValidFLV (*urifilename)) {
+                               if (MMFileFormatIsValidFLV (fp, NULL)) {
                                        *formatEnum = MM_FILE_FORMAT_FLV;
                                        if (fileSrc->type == MM_FILE_SRC_TYPE_MEMORY) fileSrc->memory.format = MM_FILE_FORMAT_FLV;
-                                       return MMFILE_FORMAT_SUCCESS;
+                                       goto FILE_FORMAT_SUCCESS;
                                }
                                break;
                        }
@@ -762,20 +853,31 @@ PROBE_PROPER_FILE_TYPE:
                        case MM_FILE_FORMAT_AU:
                        case MM_FILE_FORMAT_VOB:
                        case MM_FILE_FORMAT_JPG:
-                               break;
                        default: {
                                debug_error ("error: invaild format enum[%d]\n", index);
+                               goto FILE_FORMAT_FAIL;
                                break;
                        }
                }
        }
 
+FILE_FORMAT_FAIL:
        if (index == MM_FILE_FORMAT_NUM)
                debug_error("Can't probe file type\n");
 
        *formatEnum = -1;
+
+       if(fp)
+               mmfile_close(fp);
+
        return MMFILE_FORMAT_FAIL;
 
+
+FILE_FORMAT_SUCCESS:
+       if(fp)
+               mmfile_close(fp);
+
+       return MMFILE_FORMAT_SUCCESS;
 }
 
 static int _mmfile_format_close (MMFileFormatContext *formatContext, bool clean_all)
index ef2e80e..071a605 100755 (executable)
@@ -1,6 +1,6 @@
 Name:      libmm-fileinfo
 Summary:    Media Fileinfo
-Version:    0.6.3
+Version:    0.6.31
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 62f649f..ce11701 100755 (executable)
@@ -66,27 +66,34 @@ inline unsigned short   mmfile_io_le_uint16 (unsigned short value);
 inline short            mmfile_io_be_int16  (unsigned short value);
 inline short            mmfile_io_le_int16  (unsigned short value);
 
+typedef struct MMFileIOHandle
+{
+    struct MMFileIOFunc *iofunc;
+    int     flags;         /* file flags */
+    void   *privateData;
+    char   *fileName;
+} MMFileIOHandle;
 
 ////////////////////////////////////////////////////////////////////////
 //                     FILE HEADER CHECK API                          //
 ////////////////////////////////////////////////////////////////////////
-int MMFileFormatIsValidMP3 (const char *mmfileuri, int frameCnt);
-int MMFileFormatIsValidAAC (const char *mmfileuri);
-int MMFileFormatIsValidASF (const char *mmfileuri);
-int MMFileFormatIsValidMP4 (const char *mmfileuri);
-int MMFileFormatIsValidAVI (const char *mmfileuri);
-int MMFileFormatIsValidAMR (const char *mmfileuri);
-int MMFileFormatIsValidWAV (const char *mmfileuri);
-int MMFileFormatIsValidMMF (const char *mmfileuri);
-int MMFileFormatIsValidMID (const char *mmfileuri);
-int MMFileFormatIsValidIMY (const char *mmfileuri);
-int MMFileFormatIsValidWMA (const char *mmfileuri);
-int MMFileFormatIsValidWMV (const char *mmfileuri);
-int MMFileFormatIsValidOGG (const char *mmfileuri);
-int MMFileFormatIsValidMatroska (const char *mmfileuri);
-int MMFileFormatIsValidQT (const char *mmfileuri);
-int MMFileFormatIsValidFLAC (const char *mmfileuri);
-int MMFileFormatIsValidFLV (const char *mmfileuri);
+int MMFileFormatIsValidMP3 (MMFileIOHandle *pFileIO, const char *mmfileuri, int frameCnt);
+int MMFileFormatIsValidAAC (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidASF (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidMP4 (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidAVI (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidAMR (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidWAV (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidMMF (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidMID (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidIMY (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidWMA (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidWMV (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidOGG (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidMatroska (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidQT (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidFLAC (MMFileIOHandle *pFileIO, const char *mmfileuri);
+int MMFileFormatIsValidFLV (MMFileIOHandle *pFileIO, const char *mmfileuri);
 
 
 ////////////////////////////////////////////////////////////////////////
@@ -110,14 +117,6 @@ int MMFileFormatIsValidFLV (const char *mmfileuri);
 #define MMFILE_SEEK_CUR                SEEK_CUR
 #define MMFILE_SEEK_END                SEEK_END
 
-typedef struct MMFileIOHandle
-{
-    struct MMFileIOFunc *iofunc;
-    int     flags;         /* file flags */
-    void   *privateData;
-    char   *fileName;
-} MMFileIOHandle;
-
 typedef struct MMFileIOFunc
 {
        const char      *handleName;
index e345f7a..06cd0dd 100755 (executable)
@@ -53,13 +53,13 @@ static int _MMFileIsFLVHeader  (void *header);
 /*                     MP3 Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidMP3 (const char *mmfileuri, int frameCnt)
+int MMFileFormatIsValidMP3 (MMFileIOHandle *pFileIO, const char *mmfileuri, int frameCnt)
 {
 #define _MMFILE_MP3_HEADER_LENGTH   4
 #define _MMFILE_MP3_BUFFER_LENGTH   8200
 
-       MMFileIOHandle *fp = NULL;
-       unsigned char *buffer=NULL;
+       MMFileIOHandle *fp = pFileIO;
+       unsigned char buffer[_MMFILE_MP3_BUFFER_LENGTH] = {0,};
        long long  filesize = 0;
        unsigned int  sizeID3 = 0;
        int           readed = 0;
@@ -68,12 +68,16 @@ int MMFileFormatIsValidMP3 (const char *mmfileuri, int frameCnt)
        unsigned int  i = 0, j = 0;
        int ret = 0,frameSize,count,offset;
 
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if(ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if(ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
+
        mmfile_seek (fp, 0L, MMFILE_SEEK_END);
        filesize = mmfile_tell (fp);
        mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
@@ -98,17 +102,10 @@ int MMFileFormatIsValidMP3 (const char *mmfileuri, int frameCnt)
        endoffset = startoffset + 102400;
        if(endoffset > filesize - _MMFILE_MP3_HEADER_LENGTH)
                endoffset = filesize - _MMFILE_MP3_HEADER_LENGTH;
-       
+
        /* find sync bit */
        i = startoffset;
        count = 0;
-       
-       buffer =  mmfile_malloc (_MMFILE_MP3_BUFFER_LENGTH * sizeof(char));
-
-       if (NULL == buffer) {
-               debug_error("Error in allocating memory for MP3 buffer\n");
-               goto exit;
-       }
 
        while (i < endoffset) {
                mmfile_seek (fp, i, MMFILE_SEEK_SET);
@@ -163,14 +160,8 @@ failMP3:
        debug_msg ( "Header Not Detected at: %d\n",i+j);
        #endif
 exit:
-
-       if(buffer) {
-               mmfile_free (buffer);
-       }
-
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -181,13 +172,13 @@ exit:
 /*                     AAC Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidAAC (const char *mmfileuri)
+int MMFileFormatIsValidAAC (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_AAC_HEADER_LENGTH   4
 #define _MMFILE_AAC_BUFFER_LENGTH   8200
 
-       MMFileIOHandle *fp = NULL;
-       unsigned char *buffer=NULL;
+       MMFileIOHandle *fp = pFileIO;
+       unsigned char buffer[_MMFILE_AAC_BUFFER_LENGTH] = {0,};
        unsigned int  sizeID3 = 0;
        long long     filesize = 0;
        int           readed = 0;
@@ -197,16 +188,15 @@ int MMFileFormatIsValidAAC (const char *mmfileuri)
        int ret = 0;
        unsigned int sync,frameSize;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        /* Initialize the members of handle */
        mmfile_seek (fp, 0, MMFILE_SEEK_END);
@@ -233,21 +223,14 @@ int MMFileFormatIsValidAAC (const char *mmfileuri)
        endoffset = startoffset + 10240;
        if(endoffset > filesize - _MMFILE_AAC_HEADER_LENGTH)
                endoffset = filesize - _MMFILE_AAC_HEADER_LENGTH;
-       
-       buffer = mmfile_malloc (_MMFILE_AAC_BUFFER_LENGTH * sizeof(char));
 
-       if (NULL == buffer) {
-               debug_error("Error in allocating memory for AAC buffer\n");
-               goto exit;
-       }
-       
        i = startoffset;
 
        while (i < endoffset) {
                mmfile_seek (fp, i, MMFILE_SEEK_SET);
 
                readed = mmfile_read (fp, buffer, _MMFILE_AAC_BUFFER_LENGTH);
-       
+
                if (readed < _MMFILE_AAC_HEADER_LENGTH) {
                        debug_error ( "read error. size = %d. Maybe end of file.\n", readed);
                        ret = 0;
@@ -305,13 +288,8 @@ fail:
        #endif
 
 exit:
-       if (buffer) {
-               mmfile_free (buffer);
-       }
-
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -322,13 +300,13 @@ exit:
 /*                     OGG Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidOGG (const char *mmfileuri)
+int MMFileFormatIsValidOGG (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_OGG_HEADER_LENGTH   4
 #define _MMFILE_OGG_BUFFER_LENGTH   512
 #define _MMFILE_OGG_CHECK_LIMIT                (_MMFILE_OGG_HEADER_LENGTH * 1000)
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_OGG_BUFFER_LENGTH] = {0,};
        unsigned int  sizeID3 = 0;
        long long     filesize = 0;
@@ -339,18 +317,16 @@ int MMFileFormatIsValidOGG (const char *mmfileuri)
        int ret = 0;
        unsigned int check_limit = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               ret = 0;
-               return ret;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       ret = 0;
+                       goto exit;
+               }
        }
 
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               ret = 0;
-               goto exit;
-       }
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        /* Initialize the members of handle */
        mmfile_seek (fp, 0, MMFILE_SEEK_END);
@@ -404,9 +380,8 @@ int MMFileFormatIsValidOGG (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -417,13 +392,13 @@ exit:
 /*                     MIDI Header Check API                           */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidMID (const char *mmfileuri)
+int MMFileFormatIsValidMID (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_MIDI_HEADER_LENGTH 4
 #define _MMFILE_MIDI_BUFFER_LENGTH 512
 #define _MMFILE_MIDI_CHECK_LIMIT       (_MMFILE_MIDI_HEADER_LENGTH * 1024)
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_MIDI_BUFFER_LENGTH] = {0,};
        long long     filesize = 0;
        int           readed = 0;
@@ -433,16 +408,15 @@ int MMFileFormatIsValidMID (const char *mmfileuri)
        int ret = 0;
        unsigned int check_limit = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        /* Initialize the members of handle */
        mmfile_seek (fp, 0, MMFILE_SEEK_END);
@@ -489,9 +463,8 @@ int MMFileFormatIsValidMID (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -501,45 +474,24 @@ exit:
 /*                     WAV Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidWAV (const char *mmfileuri)
+int MMFileFormatIsValidWAV (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_WAV_HEADER_LENGTH 15
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_WAV_HEADER_LENGTH] = {0,};
-       long long     filesize = 0;
        int           readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-        /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_WAV_HEADER_LENGTH) {
-               debug_error ( "header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;
-       
-       /* set begin and end point at the file */
-       startoffset = 0;
-       
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_WAV_HEADER_LENGTH);
        if (_MMFILE_WAV_HEADER_LENGTH != readed) {
@@ -556,11 +508,9 @@ int MMFileFormatIsValidWAV (const char *mmfileuri)
                goto exit;
        }
 
-
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -571,11 +521,11 @@ exit:
 /*                     MP4 Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidMP4 (const char *mmfileuri)
+int MMFileFormatIsValidMP4 (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_MP4_HEADER_LENGTH 4
 #define _MMFILE_MP4_CHECK_LIMIT                (1024*10)       /*10Kbyte*/
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_MP4_HEADER_LENGTH] = {0,};
        long long     filesize = 0;
        int           readed = 0;
@@ -583,16 +533,15 @@ int MMFileFormatIsValidMP4 (const char *mmfileuri)
        int ret = 0;
        unsigned int check_limit = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        /* Initialize the members of handle */
        mmfile_seek (fp, 0, MMFILE_SEEK_END);
@@ -630,9 +579,8 @@ int MMFileFormatIsValidMP4 (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -642,45 +590,27 @@ exit:
 /*                     AVI Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidAVI (const char *mmfileuri)
+int MMFileFormatIsValidAVI (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_AVI_HEADER_LENGTH 12
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_AVI_HEADER_LENGTH] = {0,};
-       long long     filesize = 0;
        int           readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-        /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_AVI_HEADER_LENGTH) {
-               debug_error ( "header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;        
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);    
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_AVI_HEADER_LENGTH);
+
        if (_MMFILE_AVI_HEADER_LENGTH != readed) {
                debug_error ( "read error. size = %d. Maybe end of file.\n", readed);
                ret = 0;
@@ -696,9 +626,8 @@ int MMFileFormatIsValidAVI (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -709,44 +638,26 @@ exit:
 /*                     ASF Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidASF (const char *mmfileuri)
+int MMFileFormatIsValidASF (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_ASF_HEADER_LENGTH 16
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_ASF_HEADER_LENGTH] = {0,};
-       long long     filesize = 0;
        int           readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-       /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_ASF_HEADER_LENGTH) {
-               debug_error ( "header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);        
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_ASF_HEADER_LENGTH);
+
        if (_MMFILE_ASF_HEADER_LENGTH != readed) {
                debug_error ( "read error. size = %d. Maybe end of file.\n", readed);
                ret = 0;
@@ -762,9 +673,8 @@ int MMFileFormatIsValidASF (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -773,44 +683,26 @@ exit:
 /*                     WMA Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidWMA (const char *mmfileuri)
+int MMFileFormatIsValidWMA (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_ASF_HEADER_LENGTH 16
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_ASF_HEADER_LENGTH] = {0,};
-       long long     filesize = 0;
        int           readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-       /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_ASF_HEADER_LENGTH) {
-               debug_error ( "header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);        
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_ASF_HEADER_LENGTH);
+
        if (_MMFILE_ASF_HEADER_LENGTH != readed) {
                debug_error ( "read error. size = %d. Maybe end of file.\n", readed);
                ret = 0;
@@ -826,9 +718,8 @@ int MMFileFormatIsValidWMA (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -839,44 +730,26 @@ exit:
 /*                     WMV Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidWMV (const char *mmfileuri)
+int MMFileFormatIsValidWMV (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
  #define _MMFILE_ASF_HEADER_LENGTH 16
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_ASF_HEADER_LENGTH] = {0,};
-       long long     filesize = 0;
        int           readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-       /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_ASF_HEADER_LENGTH) {
-               debug_error ( "header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);        
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_ASF_HEADER_LENGTH);
+
        if (_MMFILE_ASF_HEADER_LENGTH != readed) {
                debug_error ( "read error. size = %d. Maybe end of file.\n", readed);
                ret = 0;
@@ -892,9 +765,8 @@ int MMFileFormatIsValidWMV (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -904,45 +776,27 @@ exit:
 /*                     MMF Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidMMF (const char *mmfileuri)
+int MMFileFormatIsValidMMF (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_MMF_HEADER_LENGTH 18
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_MMF_HEADER_LENGTH] = {0,};
-       long long     filesize = 0;
        int           readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-       /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_MMF_HEADER_LENGTH) {
-               debug_error ( "header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);    
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_MMF_HEADER_LENGTH);
+
        if (_MMFILE_MMF_HEADER_LENGTH != readed) {
                debug_error ( "read error. size = %d. Maybe end of file.\n", readed);
                ret = 0;
@@ -958,9 +812,8 @@ int MMFileFormatIsValidMMF (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -971,45 +824,27 @@ exit:
 /*                     MMF Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidIMY (const char *mmfileuri)
+int MMFileFormatIsValidIMY (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_IMY_HEADER_LENGTH 13
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_IMY_HEADER_LENGTH] = {0,};
-       long long     filesize = 0;
        int           readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-        /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_IMY_HEADER_LENGTH) {
-               debug_error ( "header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);    
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_IMY_HEADER_LENGTH);
+
        if (_MMFILE_IMY_HEADER_LENGTH != readed) {
                debug_error ( "read error. size = %d. Maybe end of file.\n", readed);
                ret = 0;
@@ -1025,9 +860,8 @@ int MMFileFormatIsValidIMY (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -1038,46 +872,28 @@ exit:
 /*                     AMR Header Check API                            */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidAMR (const char *mmfileuri)
+int MMFileFormatIsValidAMR (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_AMR_MAX_HEADER_SIZE 15
 #define _MMFILE_AMR_MIN_HEADER_SIZE 6
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_AMR_MAX_HEADER_SIZE] = {0,};
-       long long     filesize = 0;
        int           readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-       /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_AMR_MAX_HEADER_SIZE) {
-               debug_error ("header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);        
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_AMR_MAX_HEADER_SIZE);
+
        if (_MMFILE_AMR_MAX_HEADER_SIZE != readed) {
                debug_error ("read error. size = %d. Maybe end of file.\n", readed);
                ret = 0;
@@ -1093,9 +909,8 @@ int MMFileFormatIsValidAMR (const char *mmfileuri)
        }
 
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -1103,45 +918,27 @@ exit:
 /***********************************************************************/
 /*                     Matroska Header Check API                       */
 /***********************************************************************/
-
 EXPORT_API
-int MMFileFormatIsValidMatroska (const char *mmfileuri)
+int MMFileFormatIsValidMatroska (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_EBML_MARKER_LENGTH     4
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char* buffer = NULL;
-       long long     filesize = 0;
        int           readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
-
        int len_mask = 0x80, size = 1, n = 1, total = 0;
        char probe_data[] = { 'm', 'a', 't', 'r', 'o', 's', 'k', 'a' };
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       debug_msg ( "[%s][%d]\n", __func__, __LINE__);
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-        /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       ret = 0;
-
-       /* set begin and end point at the file */
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        buffer = mmfile_malloc (_MMFILE_EBML_MARKER_LENGTH * sizeof(char));
        readed = mmfile_read (fp, buffer, _MMFILE_EBML_MARKER_LENGTH);
@@ -1199,9 +996,8 @@ exit:
                mmfile_free (buffer);
        }
 
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
        return ret;
 }
@@ -1210,7 +1006,7 @@ exit:
 /*                     QT Header Check API                       */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidQT (const char *mmfileuri)
+int MMFileFormatIsValidQT (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
        return 1;
 }
@@ -1219,47 +1015,27 @@ int MMFileFormatIsValidQT (const char *mmfileuri)
 /*                     Flac Header Check API                       */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidFLAC (const char *mmfileuri)
+int MMFileFormatIsValidFLAC (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_FLAC_HEADER_LENGTH 5   /*fLaC*/
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_FLAC_HEADER_LENGTH] = {0,};
-       long long         filesize = 0;
        int               readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-       /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_FLAC_HEADER_LENGTH) {
-               debug_error ( "header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;
-
-       /* set begin and end point at the file */
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_FLAC_HEADER_LENGTH);
+
        if (_MMFILE_FLAC_HEADER_LENGTH != readed) {
                debug_error ( "read error. size = %d. Maybe end of file.\n", readed);
                ret = 0;
@@ -1274,60 +1050,38 @@ int MMFileFormatIsValidFLAC (const char *mmfileuri)
                goto exit;
        }
 
-
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
-return ret;
+       return ret;
 }
 
 /***********************************************************************/
 /*                     FLV(flash video) Header Check API                       */
 /***********************************************************************/
 EXPORT_API
-int MMFileFormatIsValidFLV (const char *mmfileuri)
+int MMFileFormatIsValidFLV (MMFileIOHandle *pFileIO, const char *mmfileuri)
 {
 #define _MMFILE_FLV_HEADER_LENGTH 4    /*FLV*/
 
-       MMFileIOHandle *fp = NULL;
+       MMFileIOHandle *fp = pFileIO;
        unsigned char buffer[_MMFILE_FLV_HEADER_LENGTH] = {0,};
-       long long         filesize = 0;
        int               readed = 0;
-       unsigned int  startoffset = 0;
        int ret = 0;
 
-       if (NULL == mmfileuri) {
-               debug_error ("file source is NULL\n");
-               return ret;
-       }
-
-       ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
-       if (ret == MMFILE_UTIL_FAIL) {
-               debug_error ("error: mmfile_open\n");
-               goto exit;
-       }
-
-       /* Initialize the members of handle */
-       mmfile_seek (fp, 0, MMFILE_SEEK_END);
-       filesize = mmfile_tell(fp);
-       mmfile_seek (fp, 0, MMFILE_SEEK_SET);
-
-       if (filesize < _MMFILE_FLV_HEADER_LENGTH) {
-               debug_error ( "header is too small.\n");
-               ret = 0;
-               goto exit;
+       if(fp == NULL) {
+               ret = mmfile_open (&fp, mmfileuri, MMFILE_RDONLY);
+               if (ret == MMFILE_IO_FAILED) {
+                       debug_error ("error: mmfile_open\n");
+                       goto exit;
+               }
        }
 
-       ret = 0;
-
-       /* set begin and end point at the file */
-       startoffset = 0;
-
-       mmfile_seek (fp, startoffset, MMFILE_SEEK_SET);
+       mmfile_seek (fp, 0L, MMFILE_SEEK_SET);
 
        readed = mmfile_read (fp, buffer, _MMFILE_FLV_HEADER_LENGTH);
+
        if (_MMFILE_FLV_HEADER_LENGTH != readed) {
                debug_error ( "read error. size = %d. Maybe end of file.\n", readed);
                ret = 0;
@@ -1342,21 +1096,20 @@ int MMFileFormatIsValidFLV (const char *mmfileuri)
                goto exit;
        }
 
-
 exit:
-       if (fp) {
-               mmfile_close (fp);
-       }
+       if(pFileIO == NULL && fp != NULL)
+               mmfile_close(fp);
 
-return ret;
+       return ret;
 }
 
+
 /***********************************************************************/
 /*            Implementation of Internal Functions                     */
 /***********************************************************************/
 static int _MMFileIsASFHeader  (void *header)
 {
-       /* ID: 30 26 B2 75 8E 66 CF 11 A6 D9 00 AA 00 62 CE 6C */    
+       /* ID: 30 26 B2 75 8E 66 CF 11 A6 D9 00 AA 00 62 CE 6C */
        unsigned char *s = header;
 
        if ( (*(s +  0) == 0x30) &&