hxsym_filetype.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:4k
- /************************************************************************
- * hxsym_filetype.cpp
- * --------------
- *
- * Synopsis:
- * mime and file type utilities
- *
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *****************************************************************************/
-
- #include <apgcli.h> // RApaLsSession
- #include <apmrec.h> // CApaDataRecognizerType
- #include <f32file.h> // RFs
- #include "hxsym_debug.h"
- #include "chxavfileutil.h"
- #include "chxavcleanupstack.h"
- #include "chxavmisc.h"
- #include "hxsym_mimetypes.h"
- #include "hxsym_filetype.h"
- namespace CHXAvFile
- {
- //////////////////////////////////
- // look up the mimetype for the given file via
- // system recognizer API
- //
- TDataType GetFileMimeTypeL(const TDesC& path)
- {
- // length of buffer read from file and passed to recognizer
- const TInt KRecogLength=512;
- TDataType type;
- RApaLsSession ls;
- if (ls.Connect() == KErrNone)
- {
- AUTO_PUSH_POP_CLOSE(ls);
- RFs fs;
- if( fs.Connect() == KErrNone )
- {
- AUTO_PUSH_POP_CLOSE(fs);
- HBufC8* pBuf = HBufC8::NewL(KRecogLength);
- AUTO_PUSH_POP_DEL(pBuf);
- TPtr8 ptr = pBuf->Des();
- TInt err = fs.ReadFileSection(path, 0, ptr, KRecogLength);
- if (KErrNone == err)
- {
- TDataRecognitionResult rr;
- ls.RecognizeData(path, *pBuf, rr);
- if (rr.iConfidence != CApaDataRecognizerType::ENotRecognized)
- {
- type = rr.iDataType;
- }
- }
- else
- {
- DPRINTF(SYMP_INFO, ("GetFileMimeTypeL(): failed to read file for recognition(%d)n", err));
- }
- }
- }
- return type;
- }
- ////////////////////////////////////////
- // lookup filetype enum for given file
- //
- FileType GetFileType(const TDesC& path)
- {
- FileType type = ftUnknown;
- if( HasFolderSuffix(path) )
- {
- // folder
- type = ftFolder;
- }
- else
- {
- TDataType dataType = GetFileMimeTypeL(path);
- type = MimeToFileType(dataType.Des8());
- }
- return type;
- }
- /////////////////////////////////////////////////////
- // these should match mimetype associations in application aif
- //
- // if we return ftUnknown the UI will not display the file
- //
- FileType MimeToFileType(const TDesC8& dataType)
- {
- struct
- {
- const TText8* pszMimeType;
- FileType fileType;
- }
- const mimeTypeTable[] =
- {
- {HXSYM_MIMETYPE_RM, ftRm },
- {HXSYM_MIMETYPE_RM_ALT1, ftRm },
- {HXSYM_MIMETYPE_RM_ALT2, ftRm },
- {HXSYM_MIMETYPE_RM_ALT3, ftRm },
- {HXSYM_MIMETYPE_RM_ALT4, ftRm },
- {HXSYM_MIMETYPE_AMR, ftAmr },
- {HXSYM_MIMETYPE_RAM, ftRam },
- {HXSYM_MIMETYPE_SDP, ftSdp },
- #if defined(HELIX_FEATURE_AUDIO_MPA_LAYER3)
- //HELIX_FEATURE_AUDIO_MPA_LAYER3
- {HXSYM_MIMETYPE_MP3, ftMp3 },
- //HELIX_FEATURE_AUDIO_MPA_LAYER3
- #endif
- #if defined(HELIX_FEATURE_SMIL2)
- //HELIX_FEATURE_SMIL2
- {HXSYM_MIMETYPE_SMIL, ftSmil},
- {HXSYM_MIMETYPE_SMIL1, ftSmil},
- {HXSYM_MIMETYPE_SMIL1_ALT1, ftSmil},
- //HELIX_FEATURE_SMIL2
- #endif
- #if defined(HELIX_FEATURE_3GPP)
- // HELIX_FEATURE_3GPP
- {HXSYM_MIMETYPE_3GPAUDIO, ftMp4 },
- {HXSYM_MIMETYPE_3GPVIDEO, ftMp4 },
- {HXSYM_MIMETYPE_MP4AUDIO, ftMp4 },
- {HXSYM_MIMETYPE_MP4VIDEO, ftMp4 },
- {HXSYM_MIMETYPE_MP4AUDIO_ALT1, ftMp4 },
- {HXSYM_MIMETYPE_3GPPVIDEO_ALT1, ftMp4 },
- {HXSYM_MIMETYPE_3GPPAUDIO_ALT1, ftMp4 }
- //HELIX_FEATURE_3GPP
- #endif
- };
- const TUint TABLE_COUNT = ARRAY_COUNT(mimeTypeTable);
- for(TInt idx = 0; idx < TABLE_COUNT; ++idx)
- {
- if(0 == dataType.CompareF(TPtrC8(mimeTypeTable[idx].pszMimeType)))
- {
- return mimeTypeTable[idx].fileType;
- }
- }
- return ftUnknown;
- }
- } // CHXAvFile