update tizen source
[framework/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginAvCodec.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #include "MmsPluginAvCodec.h"
32 #include <string.h>
33
34 AvCodecType     AvGetFileCodecType(const char *szFileName)
35 {
36         char szFileExt[FILEEXT_MAX] = {0, };
37         int iPos = 0;
38         int iStrLen = 0;
39         bool bMIME = false;
40
41         iStrLen = strlen(szFileName);
42
43         iPos = iStrLen;
44
45         while (iPos > 0) {
46                 iPos--;
47
48                 if (szFileName[iPos] == '.')
49                         break;
50                 if (szFileName[iPos] == '/') {
51                         bMIME = true;
52                         break;
53                 }
54         }
55
56         if (iPos == 0) {
57                 return AV_CODEC_NONE;
58         }
59
60         if (FILEEXT_MAX > (iStrLen - iPos - 1)) {
61                 strncpy(szFileExt, szFileName + iPos + 1, (iStrLen - iPos - 1));
62                 szFileExt[iStrLen - iPos - 1] = '\0';
63         } else
64                 return AV_CODEC_NONE;
65
66         if (strcasecmp(szFileExt, "mp3") == 0 || strcasecmp(szFileExt, "MP3") == 0)
67                 return AV_DEC_AUDIO_MP3;
68
69         if (strcasecmp(szFileExt, "pvx") == 0 || strcasecmp(szFileExt, "PVX") == 0)
70                 return AV_DEC_VIDEO_PVX;
71         else if (strcasecmp(szFileExt, "wav") == 0 || strcasecmp(szFileExt, "WAV") == 0) {
72 #ifdef AV_DEBUG_MODE
73                 if (!bMIME) {
74                         if (__AvValidWAVE(szFileName) == true)
75                                 return AV_DEC_AUDIO_WAVE;
76                         else
77                                 return AV_CODEC_NONE;
78                 } else
79 #endif
80                         return AV_DEC_AUDIO_WAVE;
81         } else if (strcasecmp(szFileExt, "aac") == 0 || strcasecmp(szFileExt, "AAC") == 0)
82                 return AV_DEC_AUDIO_AAC;
83 #ifdef AV_DEBUG_MODE
84         else if (strcasecmp(szFileExt, "wma") == 0 || strcasecmp(szFileExt, "WMA") == 0)
85                 return AvWMFFGetFileType(szFileName);
86         else if (strcasecmp(szFileExt, "wmv") == 0 || strcasecmp(szFileExt, "WMV") == 0)
87                 return AvWMFFGetFileType(szFileName);
88         else if (strcasecmp(szFileExt, "asf") == 0 || strcasecmp(szFileExt, "ASF") == 0)
89                 return AvWMFFGetFileType(szFileName);
90 #endif
91         else if (strcasecmp(szFileExt, "amr") == 0 || strcasecmp(szFileExt, "AMR") == 0 ||
92                         strcasecmp(szFileExt, "x-amr") == 0 || strcasecmp(szFileExt, "X-AMR") == 0) {
93 #ifdef AV_DEBUG_MODE
94                 if (!bMIME) {
95                         if (__AvValidAMR(szFileName) == true)
96                                 return AV_DEC_AUDIO_AMR;
97                         else
98                                 return AV_CODEC_NONE;
99                 } else
100 #endif
101                         return AV_DEC_AUDIO_AMR;
102         } else if (strcasecmp(szFileExt, "g7231") == 0 || strcasecmp(szFileExt, "G7231") == 0)
103                 return AV_DEC_AUDIO_G723_1;
104         else if ((strcasecmp(szFileExt, "mid") == 0 || strcasecmp(szFileExt, "MID") == 0) ||
105                         (strcasecmp(szFileExt, "midi") == 0 || strcasecmp(szFileExt, "MIDI") == 0)) {
106 #ifdef AV_DEBUG_MODE
107                 if (!bMIME) {
108                         if (__AvValidMIDI(szFileName) == true)
109                                 return AV_DEC_AUDIO_MIDI;
110                         else
111                                 return AV_CODEC_NONE;
112                 } else
113 #endif
114                         return AV_DEC_AUDIO_MIDI;
115         } else if (strcasecmp(szFileExt, "mmf") == 0 || strcasecmp(szFileExt, "MMF") == 0 || strcasecmp(szFileExt, "x-mmf") == 0) {
116 #ifdef AV_DEBUG_MODE
117                 if (!bMIME) {
118                         if (__AvValidMMF(szFileName) == true)
119                                 return AV_DEC_AUDIO_MMF;
120                         else
121                                 return AV_CODEC_NONE;
122                 } else
123 #endif
124                         return AV_DEC_AUDIO_MMF;
125         } else if (strcasecmp(szFileExt, "pmd") == 0 || strcasecmp(szFileExt, "PMD") == 0) {
126                         return AV_DEC_AUDIO_MIDI;
127         } else if (strcasecmp(szFileExt, "xmf") == 0 || strcasecmp(szFileExt, "XMF") == 0 ||
128                                 strcasecmp(szFileExt,  "mxmf") == 0 || strcasecmp(szFileExt,  "MXMF") == 0) {
129                 return AV_DEC_AUDIO_XMF;
130         } else if (strcasecmp(szFileExt, "smp") == 0 || strcasecmp(szFileExt, "SMP") == 0) {
131 #ifdef AV_DEBUG_MODE
132                 if (!bMIME) {
133                         if (__AvValidSMP(szFileName) == true)
134                                 return AV_DEC_AUDIO_ADPCM;
135                         else
136                                 return AV_CODEC_NONE;
137                 } else
138 #endif
139                         return AV_DEC_AUDIO_ADPCM;
140         } else if (strcasecmp(szFileExt, "spm") == 0 || strcasecmp(szFileExt, "SPM") == 0) {
141 #ifdef AV_DEBUG_MODE
142                 if (!bMIME) {
143                         if (__AvValidMIDI(szFileName) == true)
144                                 return AV_DEC_AUDIO_SPM;
145                         else
146                                 return AV_CODEC_NONE;
147                 } else
148 #endif
149                         return AV_DEC_AUDIO_SPM;
150         } else if (strcasecmp(szFileExt, "spf") == 0 || strcasecmp(szFileExt, "SPF") == 0) {
151 #ifdef AV_DEBUG_MODE
152                 if (!bMIME) {
153                         if (__AvValidMMF(szFileName) == true)
154                                 return AV_DEC_AUDIO_MMF_PHRASE_L1;
155                         else
156                                 return AV_CODEC_NONE;
157                 } else
158 #endif
159                         return AV_DEC_AUDIO_MMF_PHRASE_L1;
160         } else if (strcasecmp(szFileExt, "imy") == 0 || strcasecmp(szFileExt, "IMY") == 0 ||
161                 strcasecmp(szFileExt, "iMelody") == 0 || strcasecmp(szFileExt, "x-iMelody") == 0 ||
162                 strcasecmp(szFileExt, "Melody") == 0) {
163 #ifdef AV_DEBUG_MODE
164                 if (!bMIME) {
165                         if (__AvValidIMELODY(szFileName) == true)
166                                 return AV_DEC_AUDIO_IMELODY;
167                         else
168                                 return AV_CODEC_NONE;
169                 } else
170 #endif
171                         return AV_DEC_AUDIO_IMELODY;
172         } else if (strcasecmp(szFileExt, "dtmf") == 0)
173                 return AV_DEC_AUDIO_DTMF_TONE;
174         else if (strcasecmp(szFileExt, "h263") == 0 || strcasecmp(szFileExt, "H263") == 0)
175                 return AV_DEC_VIDEO_H263;
176         else if (strcasecmp(szFileExt, "mp4") == 0 || strcasecmp(szFileExt, "MP4") == 0 ||
177                         strcasecmp(szFileExt, "mpeg4") == 0 || strcasecmp(szFileExt, "MPEG4") == 0 ||
178                         strcasecmp(szFileExt, "m4a") == 0 || strcasecmp(szFileExt, "M4A") == 0) {
179 #ifdef AV_DEBUG_MODE
180                 if (!bMIME) {
181                         AvCodecType avCodecType = AV_CODEC_NONE;
182                         FmFileAttribute fileAttrib;
183                         size_t strLen;
184                         UINT32  dateTime = 0;
185
186                         if (!DrmGetFileAttributes(szFileName, &fileAttrib)) {
187                                 return AV_CODEC_NONE;
188                         } else {
189                                 dateTime =  TmDateTimeToSeconds(&fileAttrib.dt);
190                                 strLen = strlen(szFileName);
191                                 if ((strnicmp(lastAccessFileInfo.szFileName, szFileName, strLen) == 0) &&
192                                         (lastAccessFileInfo.fileSize == fileAttrib.fileSize) &&
193                                         (lastAccessFileInfo.dateTime == dateTime)) {
194                                         return lastAccessFileInfo.codecType;
195                                 } else {
196                                         avCodecType = AvMP4FFGetFileType(szFileName);
197
198                                         if (strcasecmp(szFileExt, "3ga") == 0 || strcasecmp(szFileExt, "3GA") == 0 ||
199                                                 strcasecmp(szFileExt, "m4a") == 0 || strcasecmp(szFileExt, "M4A") == 0) {
200                                                 if (avCodecType | AV_DEC_AUDIO_MPEG4)
201                                                         avCodecType = AV_DEC_AUDIO_MPEG4;
202                                         }
203
204                                         if (avCodecType != AV_CODEC_NONE) {
205                                                 strncpy(lastAccessFileInfo.szFileName, szFileName, strLen);
206                                                 lastAccessFileInfo.szFileName[strLen] = '\0';
207                                                 lastAccessFileInfo.fileSize = fileAttrib.fileSize;
208                                                 lastAccessFileInfo.dateTime = dateTime;
209                                                 lastAccessFileInfo.codecType = avCodecType;
210                                         }
211                                         return avCodecType;
212                                 }
213                         }
214                 }
215 #endif
216                 return AV_DEC_VIDEO_MPEG4;
217         } else if (strcasecmp(szFileExt, "3gp") == 0 || strcasecmp(szFileExt, "3GP") == 0 ||
218                 strcasecmp(szFileExt, "3ga") == 0 || strcasecmp(szFileExt, "3GA") == 0 ||
219                 strcasecmp(szFileExt, "3gpp") == 0 || strcasecmp(szFileExt, "3GPP") == 0) {
220                 return AV_CODEC_NONE;
221         } else if (strcasecmp(szFileExt, "sdp") == 0 || strcasecmp(szFileExt, "SDP") == 0)
222                 return AV_DEC_VIDEO_MPEG4;
223         else
224                 return AV_CODEC_NONE;
225 }