Modify flora license version.
[platform/core/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginAvCodec.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *    http://floralicense.org/license/
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <string.h>
18 #include "MmsPluginAvCodec.h"
19
20 AvCodecType     AvGetFileCodecType(const char *szFileName)
21 {
22         char szFileExt[FILEEXT_MAX] = {0, };
23         int iPos = 0;
24         int iStrLen = 0;
25         bool bMIME = false;
26
27         iStrLen = strlen(szFileName);
28
29         iPos = iStrLen;
30
31         while (iPos > 0) {
32                 iPos--;
33
34                 if (szFileName[iPos] == '.')
35                         break;
36                 if (szFileName[iPos] == '/') {
37                         bMIME = true;
38                         break;
39                 }
40         }
41
42         if (iPos == 0) {
43                 return AV_CODEC_NONE;
44         }
45
46         if (FILEEXT_MAX > (iStrLen - iPos - 1)) {
47                 strncpy(szFileExt, szFileName + iPos + 1, (iStrLen - iPos - 1));
48                 szFileExt[iStrLen - iPos - 1] = '\0';
49         } else
50                 return AV_CODEC_NONE;
51
52         if (strcasecmp(szFileExt, "mp3") == 0 || strcasecmp(szFileExt, "MP3") == 0)
53                 return AV_DEC_AUDIO_MP3;
54
55         if (strcasecmp(szFileExt, "pvx") == 0 || strcasecmp(szFileExt, "PVX") == 0)
56                 return AV_DEC_VIDEO_PVX;
57         else if (strcasecmp(szFileExt, "wav") == 0 || strcasecmp(szFileExt, "WAV") == 0) {
58 #ifdef AV_DEBUG_MODE
59                 if (!bMIME) {
60                         if (__AvValidWAVE(szFileName) == true)
61                                 return AV_DEC_AUDIO_WAVE;
62                         else
63                                 return AV_CODEC_NONE;
64                 } else
65 #endif
66                         return AV_DEC_AUDIO_WAVE;
67         } else if (strcasecmp(szFileExt, "aac") == 0 || strcasecmp(szFileExt, "AAC") == 0)
68                 return AV_DEC_AUDIO_AAC;
69 #ifdef AV_DEBUG_MODE
70         else if (strcasecmp(szFileExt, "wma") == 0 || strcasecmp(szFileExt, "WMA") == 0)
71                 return AvWMFFGetFileType(szFileName);
72         else if (strcasecmp(szFileExt, "wmv") == 0 || strcasecmp(szFileExt, "WMV") == 0)
73                 return AvWMFFGetFileType(szFileName);
74         else if (strcasecmp(szFileExt, "asf") == 0 || strcasecmp(szFileExt, "ASF") == 0)
75                 return AvWMFFGetFileType(szFileName);
76 #endif
77         else if (strcasecmp(szFileExt, "amr") == 0 || strcasecmp(szFileExt, "AMR") == 0 ||
78                         strcasecmp(szFileExt, "x-amr") == 0 || strcasecmp(szFileExt, "X-AMR") == 0) {
79 #ifdef AV_DEBUG_MODE
80                 if (!bMIME) {
81                         if (__AvValidAMR(szFileName) == true)
82                                 return AV_DEC_AUDIO_AMR;
83                         else
84                                 return AV_CODEC_NONE;
85                 } else
86 #endif
87                         return AV_DEC_AUDIO_AMR;
88         } else if (strcasecmp(szFileExt, "g7231") == 0 || strcasecmp(szFileExt, "G7231") == 0)
89                 return AV_DEC_AUDIO_G723_1;
90         else if ((strcasecmp(szFileExt, "mid") == 0 || strcasecmp(szFileExt, "MID") == 0) ||
91                         (strcasecmp(szFileExt, "midi") == 0 || strcasecmp(szFileExt, "MIDI") == 0)) {
92 #ifdef AV_DEBUG_MODE
93                 if (!bMIME) {
94                         if (__AvValidMIDI(szFileName) == true)
95                                 return AV_DEC_AUDIO_MIDI;
96                         else
97                                 return AV_CODEC_NONE;
98                 } else
99 #endif
100                         return AV_DEC_AUDIO_MIDI;
101         } else if (strcasecmp(szFileExt, "mmf") == 0 || strcasecmp(szFileExt, "MMF") == 0 || strcasecmp(szFileExt, "x-mmf") == 0) {
102 #ifdef AV_DEBUG_MODE
103                 if (!bMIME) {
104                         if (__AvValidMMF(szFileName) == true)
105                                 return AV_DEC_AUDIO_MMF;
106                         else
107                                 return AV_CODEC_NONE;
108                 } else
109 #endif
110                         return AV_DEC_AUDIO_MMF;
111         } else if (strcasecmp(szFileExt, "pmd") == 0 || strcasecmp(szFileExt, "PMD") == 0) {
112                         return AV_DEC_AUDIO_MIDI;
113         } else if (strcasecmp(szFileExt, "xmf") == 0 || strcasecmp(szFileExt, "XMF") == 0 ||
114                                 strcasecmp(szFileExt,  "mxmf") == 0 || strcasecmp(szFileExt,  "MXMF") == 0) {
115                 return AV_DEC_AUDIO_XMF;
116         } else if (strcasecmp(szFileExt, "smp") == 0 || strcasecmp(szFileExt, "SMP") == 0) {
117 #ifdef AV_DEBUG_MODE
118                 if (!bMIME) {
119                         if (__AvValidSMP(szFileName) == true)
120                                 return AV_DEC_AUDIO_ADPCM;
121                         else
122                                 return AV_CODEC_NONE;
123                 } else
124 #endif
125                         return AV_DEC_AUDIO_ADPCM;
126         } else if (strcasecmp(szFileExt, "spm") == 0 || strcasecmp(szFileExt, "SPM") == 0) {
127 #ifdef AV_DEBUG_MODE
128                 if (!bMIME) {
129                         if (__AvValidMIDI(szFileName) == true)
130                                 return AV_DEC_AUDIO_SPM;
131                         else
132                                 return AV_CODEC_NONE;
133                 } else
134 #endif
135                         return AV_DEC_AUDIO_SPM;
136         } else if (strcasecmp(szFileExt, "spf") == 0 || strcasecmp(szFileExt, "SPF") == 0) {
137 #ifdef AV_DEBUG_MODE
138                 if (!bMIME) {
139                         if (__AvValidMMF(szFileName) == true)
140                                 return AV_DEC_AUDIO_MMF_PHRASE_L1;
141                         else
142                                 return AV_CODEC_NONE;
143                 } else
144 #endif
145                         return AV_DEC_AUDIO_MMF_PHRASE_L1;
146         } else if (strcasecmp(szFileExt, "imy") == 0 || strcasecmp(szFileExt, "IMY") == 0 ||
147                 strcasecmp(szFileExt, "iMelody") == 0 || strcasecmp(szFileExt, "x-iMelody") == 0 ||
148                 strcasecmp(szFileExt, "Melody") == 0) {
149 #ifdef AV_DEBUG_MODE
150                 if (!bMIME) {
151                         if (__AvValidIMELODY(szFileName) == true)
152                                 return AV_DEC_AUDIO_IMELODY;
153                         else
154                                 return AV_CODEC_NONE;
155                 } else
156 #endif
157                         return AV_DEC_AUDIO_IMELODY;
158         } else if (strcasecmp(szFileExt, "dtmf") == 0)
159                 return AV_DEC_AUDIO_DTMF_TONE;
160         else if (strcasecmp(szFileExt, "h263") == 0 || strcasecmp(szFileExt, "H263") == 0)
161                 return AV_DEC_VIDEO_H263;
162         else if (strcasecmp(szFileExt, "mp4") == 0 || strcasecmp(szFileExt, "MP4") == 0 ||
163                         strcasecmp(szFileExt, "mpeg4") == 0 || strcasecmp(szFileExt, "MPEG4") == 0 ||
164                         strcasecmp(szFileExt, "m4a") == 0 || strcasecmp(szFileExt, "M4A") == 0) {
165 #ifdef AV_DEBUG_MODE
166                 if (!bMIME) {
167                         AvCodecType avCodecType = AV_CODEC_NONE;
168                         FmFileAttribute fileAttrib;
169                         size_t strLen;
170                         UINT32  dateTime = 0;
171
172                         if (!DrmGetFileAttributes(szFileName, &fileAttrib)) {
173                                 return AV_CODEC_NONE;
174                         } else {
175                                 dateTime =  TmDateTimeToSeconds(&fileAttrib.dt);
176                                 strLen = strlen(szFileName);
177                                 if ((strnicmp(lastAccessFileInfo.szFileName, szFileName, strLen) == 0) &&
178                                         (lastAccessFileInfo.fileSize == fileAttrib.fileSize) &&
179                                         (lastAccessFileInfo.dateTime == dateTime)) {
180                                         return lastAccessFileInfo.codecType;
181                                 } else {
182                                         avCodecType = AvMP4FFGetFileType(szFileName);
183
184                                         if (strcasecmp(szFileExt, "3ga") == 0 || strcasecmp(szFileExt, "3GA") == 0 ||
185                                                 strcasecmp(szFileExt, "m4a") == 0 || strcasecmp(szFileExt, "M4A") == 0) {
186                                                 if (avCodecType | AV_DEC_AUDIO_MPEG4)
187                                                         avCodecType = AV_DEC_AUDIO_MPEG4;
188                                         }
189
190                                         if (avCodecType != AV_CODEC_NONE) {
191                                                 strncpy(lastAccessFileInfo.szFileName, szFileName, strLen);
192                                                 lastAccessFileInfo.szFileName[strLen] = '\0';
193                                                 lastAccessFileInfo.fileSize = fileAttrib.fileSize;
194                                                 lastAccessFileInfo.dateTime = dateTime;
195                                                 lastAccessFileInfo.codecType = avCodecType;
196                                         }
197                                         return avCodecType;
198                                 }
199                         }
200                 }
201 #endif
202                 return AV_DEC_VIDEO_MPEG4;
203         } else if (strcasecmp(szFileExt, "3gp") == 0 || strcasecmp(szFileExt, "3GP") == 0 ||
204                 strcasecmp(szFileExt, "3ga") == 0 || strcasecmp(szFileExt, "3GA") == 0 ||
205                 strcasecmp(szFileExt, "3gpp") == 0 || strcasecmp(szFileExt, "3GPP") == 0) {
206                 return AV_CODEC_NONE;
207         } else if (strcasecmp(szFileExt, "sdp") == 0 || strcasecmp(szFileExt, "SDP") == 0)
208                 return AV_DEC_VIDEO_MPEG4;
209         else
210                 return AV_CODEC_NONE;
211 }