[content] Fix compat TC fails
[platform/framework/native/content.git] / src / FCnt_ContentManagerUtilImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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  * @file                FCnt_ContentManagerUtilImpl.cpp
18  * @brief               This is the implementation file for the %_ContentManagerUtilImpl class.
19  *
20  * This file contains implementation of the %_ContentManagerUtilImpl class.
21  */
22
23 #include <new>
24 #include <stdlib.h>
25 #include <aul/aul.h>
26 #include <mime_type.h>
27 #include <FAppApp.h>
28 #include <FBaseByteBuffer.h>
29 #include <FBaseSysLog.h>
30 #include <FBaseUtilStringTokenizer.h>
31 #include <FCntImageMetadata.h>
32 #include <FCntAudioMetadata.h>
33 #include <FCntVideoMetadata.h>
34 #include <FMediaImage.h>
35 #include <FMediaImageBuffer.h>
36 #include <FMediaImageUtil.h>
37 #include <FIoDirectory.h>
38 #include <FSysEnvironment.h>
39 #include <FApp_AppInfo.h>
40 #include <FBase_LocalizedNumParser.h>
41 #include <FBase_StringConverter.h>
42 #include <FGrp_BitmapImpl.h>
43 #include <FIo_FileImpl.h>
44 #include <FMedia_ImageDecoder.h>
45 #include <FMedia_ImageImpl.h>
46 #include "FCnt_AudioMetadataImpl.h"
47 #include "FCnt_ContentManagerUtilImpl.h"
48 #include "FCnt_ImageMetadataImpl.h"
49 #include "FCnt_VideoMetadataImpl.h"
50
51 using namespace std;
52 using namespace Tizen::App;
53 using namespace Tizen::Base;
54 using namespace Tizen::Base::Utility;
55 using namespace Tizen::Graphics;
56 using namespace Tizen::Io;
57 using namespace Tizen::Media;
58 using namespace Tizen::System;
59
60 namespace Tizen { namespace Content
61 {
62
63 // Types of content, format supported and default values
64 static const int _IMAGE_BUFF_LENGTH = 100;
65 static const int _THUMBNAIL_IMAGE_WIDTH = 80;
66 static const int _THUMBNAIL_IMAGE_HEIGHT = 60;
67 static const int _MINUTES = 60;
68 static const int _SECONDS = 3600;
69
70 ImageMetadata*
71 _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
72 {
73         ClearLastResult();
74
75         if (!internal)
76         {
77                 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
78                                 "[E_INVALID_ARG] The path is not compatible.");
79         }
80         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
81                         "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
82
83         // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
84         unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
85         SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
86                         "[E_OUT_OF_MEMORY] pImageMetadata is null.");
87
88         _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
89         SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
90                         "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
91
92         ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
93         SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
94                         "[E_INVALID_ARG] pMetadata is null.");
95
96         //assign by default here and overwrite below if width and height presents in EXIF data.
97         ImageFormat imgType = IMG_FORMAT_NONE;
98         Dimension dim(0,0);
99
100         result r = _ImageImpl::GetImageInfo(contentPath, imgType, dim);
101         SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
102                         "[E_INVALID_ARG] GetImageInfo failed.");
103
104         pMetadata->width = dim.width;
105         pMetadata->height = dim.height;
106         pMetadata->contentPath = contentPath;
107
108         String tizenPath(L"");
109         String changedPath(L"");
110         r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
111         SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
112
113         if (imgType == IMG_FORMAT_JPG)
114         {
115                 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
116                 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
117                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
118
119                 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_file(pFileName.get()));
120                 if (pExifdata != null)
121                 {
122                         ExifTag tag;
123                         ExifByteOrder byteOrder;
124                         ExifEntry** pEntries = null;
125                         const char* pData = null;
126                         char buf[_IMAGE_BUFF_LENGTH] = {0, };
127                         ExifContent* pExifcont[EXIF_IFD_COUNT];
128                         char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
129                         char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
130                         unsigned int entryCount = 0;
131                         bool isOrientation = false;
132                         bool isLatitude = false;
133                         bool isLongitude = false;
134
135                         for (int i = 0; i < EXIF_IFD_COUNT; i++)
136                         {
137                                 pExifcont[i] = pExifdata->ifd[i];
138                                 entryCount = pExifcont[i]->count;
139                                 pEntries = pExifcont[i]->entries;
140                                 for (unsigned int j = 0; j < entryCount; j++)
141                                 {
142                                         tag = pEntries[j]->tag;
143                                         pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
144                                         SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
145                                                         "[E_INVALID_ARG] exif_entry_get_value failed.");
146
147                                         if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
148                                         {
149                                                 pMetadata->width = atoi(buf);
150                                         }
151                                         else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
152                                         {
153                                                 pMetadata->height = atoi(buf);
154                                         }
155                                         else if (tag == EXIF_TAG_MAKE)
156                                         {
157                                                 pMetadata->pManufacturer = new (nothrow) String(buf);
158                                                 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
159                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
160                                         }
161                                         else if (tag == EXIF_TAG_MODEL)
162                                         {
163                                                 pMetadata->pModel = new (nothrow) String(buf);
164                                                 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
165                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
166                                         }
167                                         else if (tag == EXIF_TAG_DATE_TIME)
168                                         {
169                                                 pMetadata->pDateTime = new (nothrow) String(buf);
170                                                 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
171                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
172                                         }
173                                         else if (tag == EXIF_TAG_ORIENTATION && !isOrientation)
174                                         {
175                                                 //get the byte order(little endian or big endian) before extracting orientation type
176                                                 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
177                                                 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
178
179                                                 isOrientation = true;
180                                         }
181                                         else if (tag == EXIF_TAG_SOFTWARE)
182                                         {
183                                                 pMetadata->pSoftware = new (nothrow) String(buf);
184                                                 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
185                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
186                                         }
187                                         else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
188                                         {
189                                                 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
190                                         }
191                                         else if (tag == EXIF_TAG_GPS_LATITUDE && !isLatitude)
192                                         {
193                                                 String tempLatitude(buf);
194                                                 String delim(L",");
195
196                                                 StringTokenizer strTok(tempLatitude, delim);
197                                                 String token[3] = {L"", };
198
199                                                 int count = 0;
200                                                 while (strTok.HasMoreTokens() && count < 3)
201                                                 {
202                                                         strTok.GetNextToken(token[count++]);
203                                                 }
204
205                                                 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
206                                                 r = GetLastResult();
207                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
208
209                                                 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
210                                                 r = GetLastResult();
211                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
212
213                                                 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
214                                                 r = GetLastResult();
215                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
216
217                                                 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
218
219                                                 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
220                                                 if (latitudeRef == 'S')
221                                                 {
222                                                         pMetadata->latitude = (pMetadata->latitude * (double)(-1));
223                                                 }
224                                                 isLatitude = true;
225                                         }
226                                         else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
227                                         {
228                                                 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
229                                         }
230                                         else if (tag == EXIF_TAG_GPS_LONGITUDE && !isLongitude)
231                                         {
232                                                 String tempLongitude(buf);
233                                                 String delim(L",");
234
235                                                 StringTokenizer strTok(tempLongitude, delim);
236                                                 String token[3] = {L"", };
237
238                                                 int count = 0;
239                                                 while (strTok.HasMoreTokens() && count < 3)
240                                                 {
241                                                         strTok.GetNextToken(token[count++]);
242                                                 }
243
244                                                 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
245                                                 r = GetLastResult();
246                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
247
248                                                 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
249                                                 r = GetLastResult();
250                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
251
252                                                 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
253                                                 r = GetLastResult();
254                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
255
256                                                 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
257
258                                                 // if longitude designation is Western (WEST) then longitude degree will be negative DD
259                                                 if (longitudeRef == 'W')
260                                                 {
261                                                         pMetadata->longitude = (pMetadata->longitude * (double)(-1));
262                                                 }
263                                                 isLongitude = true;
264                                         }
265                                         else if (tag == EXIF_TAG_WHITE_BALANCE)
266                                         {
267                                                 pMetadata->pWhiteBalance = new (nothrow) String(buf);
268                                                 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
269                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
270                                         }
271                                 }
272                         }
273                 }
274         }
275
276         return pImageMetadata.release();
277 }
278
279 AudioMetadata*
280 _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
281 {
282         ClearLastResult();
283
284         SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
285                         "[E_INVALID_ARG] The path is not compatible.");
286         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
287                         "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
288
289         // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
290         unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
291         SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
292                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
293
294         _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
295         SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
296                         "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
297
298         AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
299         SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
300                         "[E_INVALID_ARG] pMetadata is null.");
301
302         pMetadata->contentPath = contentPath;
303
304         String tizenPath(L"");
305         String changedPath(L"");
306         result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
307         SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
308
309         // Create the metadata extractor handle
310         metadata_extractor_h tempExtractor = NULL;
311
312         int retVal = metadata_extractor_create(&tempExtractor);
313         r = ErrorMapToRetVal(retVal);
314         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
315                         "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
316
317         unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
318         SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
319                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
320
321         // Set file path of content to extract the metadata
322         unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
323         SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
324                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
325
326         retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
327         r = ErrorMapToRetVal(retVal);
328         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
329                         "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
330
331         // Get all relavent audio metadata by passing relavent attirbutes
332         char* pTempAudioMeta = null;
333         unique_ptr<char, CharDeleter> pAudioMeta(null);
334
335         // bitrate
336         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
337         if (pTempAudioMeta != null)
338         {
339                 pAudioMeta.reset(pTempAudioMeta);
340                 pMetadata->bitrate = atoi(pAudioMeta.get());
341         }
342         else
343         {
344                 r = ErrorMapToRetVal(retVal);
345                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
346                                 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
347         }
348
349         // channelcount
350         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
351         if (pTempAudioMeta != null)
352         {
353                 pAudioMeta.reset(pTempAudioMeta);
354                 pMetadata->channelCount = atoi(pAudioMeta.get());
355         }
356         else
357         {
358                 r = ErrorMapToRetVal(retVal);
359                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
360                                 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
361         }
362
363         // duration
364         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
365         if (pTempAudioMeta != null)
366         {
367                 pAudioMeta.reset(pTempAudioMeta);
368                 pMetadata->duration = atoi(pAudioMeta.get());
369         }
370         else
371         {
372                 r = ErrorMapToRetVal(retVal);
373                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
374                                 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
375         }
376
377         // frequency
378         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
379         if (pTempAudioMeta != null)
380         {
381                 pAudioMeta.reset(pTempAudioMeta);
382                 pMetadata->frequency = atoi(pAudioMeta.get());
383         }
384         else
385         {
386                 r = ErrorMapToRetVal(retVal);
387                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
388                                 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
389         }
390
391         // albumname
392         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
393         if (pTempAudioMeta != null)
394         {
395                 pAudioMeta.reset(pTempAudioMeta);
396                 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
397                 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
398                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
399         }
400         else
401         {
402                 r = ErrorMapToRetVal(retVal);
403                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
404                                 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
405         }
406
407         // artist
408         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
409         if (pAudioMeta.get() != null)
410         {
411                 pAudioMeta.reset(pTempAudioMeta);
412                 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
413                 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
414                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
415         }
416         else
417         {
418                 r = ErrorMapToRetVal(retVal);
419                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
420                                 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
421         }
422
423         // copyright
424         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
425         if (pTempAudioMeta != null)
426         {
427                 pAudioMeta.reset(pTempAudioMeta);
428                 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
429                 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
430                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
431         }
432         else
433         {
434                 r = ErrorMapToRetVal(retVal);
435                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
436                                 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
437         }
438
439         // genre
440         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
441         if (pTempAudioMeta != null)
442         {
443                 pAudioMeta.reset(pTempAudioMeta);
444                 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
445                 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
446                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
447         }
448         else
449         {
450                 r = ErrorMapToRetVal(retVal);
451                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
452                                 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
453         }
454
455         // title
456         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
457         if (pTempAudioMeta != null)
458         {
459                 pAudioMeta.reset(pTempAudioMeta);
460                 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
461                 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
462                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
463         }
464         else
465         {
466                 r = ErrorMapToRetVal(retVal);
467                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
468                                 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
469         }
470
471         // comment
472         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
473         if (pTempAudioMeta != null)
474         {
475                 pAudioMeta.reset(pTempAudioMeta);
476                 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
477                 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
478                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
479         }
480         else
481         {
482                 r = ErrorMapToRetVal(retVal);
483                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
484                                 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
485         }
486
487         // description
488         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
489         if (pTempAudioMeta != null)
490         {
491                 pAudioMeta.reset(pTempAudioMeta);
492                 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
493                 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
494                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
495         }
496         else
497         {
498                 r = ErrorMapToRetVal(retVal);
499                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
500                                 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
501         }
502
503         // recording date
504         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
505         if (pTempAudioMeta != null)
506         {
507                 pAudioMeta.reset(pTempAudioMeta);
508                 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
509                 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
510                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
511         }
512         else
513         {
514                 r = ErrorMapToRetVal(retVal);
515                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
516                                 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
517         }
518
519         // author
520         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
521         if (pTempAudioMeta != null)
522         {
523                 pAudioMeta.reset(pTempAudioMeta);
524                 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
525                 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
526                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
527         }
528         else
529         {
530                 r = ErrorMapToRetVal(retVal);
531                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
532                                 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
533         }
534
535         // track info
536         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
537         if (pTempAudioMeta != null)
538         {
539                 pAudioMeta.reset(pTempAudioMeta);
540                 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
541                 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
542                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
543
544                 // if the string contains the track info like track num/track position,
545                 // then track position will be ignored and only track num is returned
546                 // no need to parse this string, since only track number is required
547                 pMetadata->trackNum = atoi(pAudioMeta.get());
548         }
549         else
550         {
551                 r = ErrorMapToRetVal(retVal);
552                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
553                                 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
554         }
555
556         // date
557         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
558         if (pTempAudioMeta != null)
559         {
560                 pAudioMeta.reset(pTempAudioMeta);
561                 pMetadata->year = atoi(pAudioMeta.get());
562         }
563         else
564         {
565                 r = ErrorMapToRetVal(retVal);
566                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
567                                 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
568         }
569
570         // artwork
571         int size = 0;
572         void* pTempArtwork = null;
573         unique_ptr<void, VoidDeleter> pArtwork(null);
574
575         // Get the artwork image in media file
576         retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
577         pAudioMeta.reset(pTempAudioMeta);
578
579         //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
580         //while processing albumart. This is to pass the other metadata tags to application.
581         if (pTempArtwork != null)
582         {
583                 pArtwork.reset(pTempArtwork);
584
585                 Image img;
586                 ImageFormat format = IMG_FORMAT_NONE;
587                 ByteBuffer buffer;
588
589                 r = buffer.Construct(size);
590                 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
591                 {
592                         r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
593                         if (!IsFailed(r))
594                         {
595                                 r = img.Construct();
596                                 if (!IsFailed(r))
597                                 {
598                                         format = img.GetImageFormat(buffer);
599                                         pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
600                                                                          _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
601                                         if (pMetadata->pThumbnail == null)
602                                         {
603                                                 // Because Thumbnail is one of the metadata, it is not exception in this function.
604                                                 SysLog(NID_CNT, "DecodeN failed.");
605                                         }
606                                         pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
607                                         if (pMetadata->pAlbumArt == null)
608                                         {
609                                                 // Because Album Art is one of the metadata, it is not exception in this function.
610                                                 SysLog(NID_CNT, "DecodeN failed.");
611                                         }
612                                 }
613                         }
614                 }
615         }
616         else
617         {
618                 r = ErrorMapToRetVal(retVal);
619                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
620                                 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
621         }
622
623         return pAudioMetadata.release();
624 }
625
626 VideoMetadata*
627 _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
628 {
629         ClearLastResult();
630
631         SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
632                         "[E_INVALID_ARG] The path is not compatible.");
633         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
634                         "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
635
636         // need to create here to make sure that all get APIs will not crash in case of corrupted file
637         unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
638         SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
639                         "[E_OUT_OF_MEMORY] The memory insufficient.");
640
641         _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
642         SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
643                         "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
644
645         VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
646         SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
647                         "[E_INVALID_ARG] pMetadata is null.");
648
649         pMetadata->contentPath = contentPath;
650
651         String tizenPath(L"");
652         String changedPath(L"");
653         result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
654         SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
655
656         // Create the metadata extractor handle
657         metadata_extractor_h tempExtractor = NULL;
658
659         int retVal = metadata_extractor_create(&tempExtractor);
660         r = ErrorMapToRetVal(retVal);
661         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
662                         "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
663
664         unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
665         SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
666                                 "[E_OUT_OF_MEMORY] The memory insufficient.");
667
668         // Set file path of content to extract the metadata
669         unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
670         SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
671                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
672
673         retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
674         r = ErrorMapToRetVal(retVal);
675         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
676                         "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
677
678         // Get all relavent video metadata by passing relavent attirbutes
679         char* pTempVideoMeta = null;
680         unique_ptr<char, CharDeleter> pVideoMeta(null);
681
682         // width
683         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
684         if (pTempVideoMeta != null)
685         {
686                 pVideoMeta.reset(pTempVideoMeta);
687                 pMetadata->width = atoi(pVideoMeta.get());
688         }
689         else
690         {
691                 r = ErrorMapToRetVal(retVal);
692                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
693                                 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
694         }
695
696         // height
697         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
698         if (pTempVideoMeta != null)
699         {
700                 pVideoMeta.reset(pTempVideoMeta);
701                 pMetadata->height = atoi(pVideoMeta.get());
702         }
703         else
704         {
705                 r = ErrorMapToRetVal(retVal);
706                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
707                                 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
708         }
709
710         // video bitrate
711         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
712         if (pTempVideoMeta != null)
713         {
714                 pVideoMeta.reset(pTempVideoMeta);
715                 pMetadata->videoBitrate = atoi(pVideoMeta.get());
716         }
717         else
718         {
719                 r = ErrorMapToRetVal(retVal);
720                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
721                                 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
722         }
723
724         // audio bitrate
725         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
726         if (pTempVideoMeta != null)
727         {
728                 pVideoMeta.reset(pTempVideoMeta);
729                 pMetadata->audioBitrate = atoi(pVideoMeta.get());
730         }
731         else
732         {
733                 r = ErrorMapToRetVal(retVal);
734                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
735                                 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
736         }
737
738         // framerate
739         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
740         if (pTempVideoMeta != null)
741         {
742                 pVideoMeta.reset(pTempVideoMeta);
743                 pMetadata->framerate = atoi(pVideoMeta.get());
744         }
745         else
746         {
747                 r = ErrorMapToRetVal(retVal);
748                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
749                                 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
750         }
751
752         // duration
753         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
754         if (pTempVideoMeta != null)
755         {
756                 pVideoMeta.reset(pTempVideoMeta);
757                 pMetadata->duration = atoi(pVideoMeta.get());
758         }
759         else
760         {
761                 r = ErrorMapToRetVal(retVal);
762                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
763                                 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
764         }
765
766         // genre
767         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
768         if (pTempVideoMeta != null)
769         {
770                 pVideoMeta.reset(pTempVideoMeta);
771                 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
772                 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
773                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
774         }
775         else
776         {
777                 r = ErrorMapToRetVal(retVal);
778                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
779                                 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
780         }
781
782         // comment
783         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
784         if (pTempVideoMeta != null)
785         {
786                 pVideoMeta.reset(pTempVideoMeta);
787                 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
788                 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
789                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
790         }
791         else
792         {
793                 r = ErrorMapToRetVal(retVal);
794                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
795                                 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
796         }
797
798         // description
799         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
800         if (pTempVideoMeta != null)
801         {
802                 pVideoMeta.reset(pTempVideoMeta);
803                 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
804                 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
805                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
806         }
807         else
808         {
809                 r = ErrorMapToRetVal(retVal);
810                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
811                                 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
812         }
813
814         // artwork
815         int size = 0;
816         void* pTempArtwork = null;
817         unique_ptr<void, VoidDeleter> pArtwork(null);
818
819         // Get the artwork image in media file
820         retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
821         pVideoMeta.reset(pTempVideoMeta);
822         if (pTempArtwork != null)
823         {
824                 pArtwork.reset(pTempArtwork);
825
826                 Image img;
827                 ImageFormat format = IMG_FORMAT_NONE;
828                 ByteBuffer buffer;
829
830                 r = buffer.Construct(size);
831                 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
832                 {
833                         r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
834                         if (!IsFailed(r))
835                         {
836                                 r = img.Construct();
837                                 if (!IsFailed(r))
838                                 {
839                                         format = img.GetImageFormat(buffer);
840
841                                         pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
842                                         if (pMetadata->pAlbumArt == null)
843                                         {
844                                                 // Because Album Art is one of the metadata, it is not exception in this function.
845                                                 SysLog(NID_CNT, "DecodeN failed.");
846                                         }
847                                 }
848                         }
849                 }
850         }
851         else
852         {
853                 r = ErrorMapToRetVal(retVal);
854                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
855                                 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
856         }
857
858         return pVideoMetadata.release();
859 }
860
861 ImageMetadata*
862 _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
863 {
864         ClearLastResult();
865
866         int bufferLen = byteBuffer.GetRemaining();
867         SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
868
869         // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
870         unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
871         SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
872                         "[E_OUT_OF_MEMORY] pImageMetadata is null.");
873
874         _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
875         SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
876                         "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
877
878         ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
879         SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
880                         "[E_INVALID_ARG] pMetadata is null.");
881
882         //assign by default here and overwrite below if width and height presents in EXIF data.
883         ImageFormat imgType = IMG_FORMAT_NONE;
884         int imageWidth = 0;
885         int imageHeight = 0;
886         bool isOrientation = false;
887         bool isLatitude = false;
888         bool isLongitude = false;
889
890         result r = ImageBuffer::GetImageInfo(byteBuffer, imgType, imageWidth, imageHeight);
891         SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
892                         "[E_INVALID_ARG] GetImageInfo failed.");
893
894         pMetadata->width = imageWidth;
895         pMetadata->height = imageHeight;
896
897         if (imgType == IMG_FORMAT_JPG)
898         {
899                 const byte* pByte = byteBuffer.GetPointer();
900
901                 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_data(pByte, bufferLen));
902                 if (pExifdata != null)
903                 {
904                         ExifTag tag;
905                         ExifByteOrder byteOrder;
906                         ExifEntry** pEntries = null;
907                         const char* pData = null;
908                         char buf[_IMAGE_BUFF_LENGTH] = {0, };
909                         ExifContent* pExifcont[EXIF_IFD_COUNT];
910                         char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
911                         char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
912                         unsigned int entryCount = 0;
913
914                         for (int i = 0; i < EXIF_IFD_COUNT; i++)
915                         {
916                                 pExifcont[i] = pExifdata->ifd[i];
917                                 entryCount = pExifcont[i]->count;
918                                 pEntries = pExifcont[i]->entries;
919                                 for (unsigned int j = 0; j < entryCount; j++)
920                                 {
921                                         tag = pEntries[j]->tag;
922                                         pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
923                                         SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
924                                                         "[E_INVALID_ARG] exif_entry_get_value failed.");
925
926                                         if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
927                                         {
928                                                 pMetadata->width = atoi(buf);
929                                         }
930                                         else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
931                                         {
932                                                 pMetadata->height = atoi(buf);
933                                         }
934                                         else if (tag == EXIF_TAG_MAKE)
935                                         {
936                                                 pMetadata->pManufacturer = new (nothrow) String(buf);
937                                                 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
938                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
939                                         }
940                                         else if (tag == EXIF_TAG_MODEL)
941                                         {
942                                                 pMetadata->pModel = new (nothrow) String(buf);
943                                                 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
944                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
945                                         }
946                                         else if (tag == EXIF_TAG_DATE_TIME)
947                                         {
948                                                 pMetadata->pDateTime = new (nothrow) String(buf);
949                                                 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
950                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
951                                         }
952                                         else if (tag == EXIF_TAG_ORIENTATION && !isOrientation)
953                                         {
954                                                 //get the byte order(little endian or big endian) before extracting orientation type
955                                                 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
956                                                 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
957
958                                                 isOrientation = true;
959                                         }
960                                         else if (tag == EXIF_TAG_SOFTWARE)
961                                         {
962                                                 pMetadata->pSoftware = new (nothrow) String(buf);
963                                                 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
964                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
965                                         }
966                                         else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
967                                         {
968                                                 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
969                                         }
970                                         else if (tag == EXIF_TAG_GPS_LATITUDE && !isLatitude)
971                                         {
972                                                 String tempLatitude(buf);
973                                                 String delim(L",");
974
975                                                 StringTokenizer strTok(tempLatitude, delim);
976                                                 String token[3] = {L"", };
977
978                                                 int count = 0;
979                                                 while (strTok.HasMoreTokens() && count < 3)
980                                                 {
981                                                         strTok.GetNextToken(token[count++]);
982                                                 }
983
984                                                 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
985                                                 r = GetLastResult();
986                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
987
988                                                 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
989                                                 r = GetLastResult();
990                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
991
992                                                 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
993                                                 r = GetLastResult();
994                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
995
996                                                 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
997
998                                                 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
999                                                 if (latitudeRef == 'S')
1000                                                 {
1001                                                         pMetadata->latitude = (pMetadata->latitude * (double)(-1));
1002                                                 }
1003                                                 isLatitude = true;
1004                                         }
1005                                         else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
1006                                         {
1007                                                 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
1008                                         }
1009                                         else if (tag == EXIF_TAG_GPS_LONGITUDE && !isLongitude)
1010                                         {
1011                                                 String tempLongitude(buf);
1012                                                 String delim(L",");
1013
1014                                                 StringTokenizer strTok(tempLongitude, delim);
1015                                                 String token[3] = {L"", };
1016
1017                                                 int count = 0;
1018                                                 while (strTok.HasMoreTokens() && count < 3)
1019                                                 {
1020                                                         strTok.GetNextToken(token[count++]);
1021                                                 }
1022
1023                                                 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
1024                                                 r = GetLastResult();
1025                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1026
1027                                                 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
1028                                                 r = GetLastResult();
1029                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1030
1031                                                 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
1032                                                 r = GetLastResult();
1033                                                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1034
1035                                                 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
1036
1037                                                 // if longitude designation is Western (WEST) then longitude degree will be negative DD
1038                                                 if (longitudeRef == 'W')
1039                                                 {
1040                                                         pMetadata->longitude = (pMetadata->longitude * (double)(-1));
1041                                                 }
1042                                                 isLongitude = true;
1043                                         }
1044                                         else if (tag == EXIF_TAG_WHITE_BALANCE)
1045                                         {
1046                                                 pMetadata->pWhiteBalance = new (nothrow) String(buf);
1047                                                 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
1048                                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1049                                         }
1050                                 }
1051                         }
1052                 }
1053         }
1054
1055         return pImageMetadata.release();
1056 }
1057
1058 AudioMetadata*
1059 _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
1060 {
1061         ClearLastResult();
1062
1063         int bufferLen = byteBuffer.GetRemaining();
1064         SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1065
1066         // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
1067         unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
1068         SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
1069                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1070
1071         _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
1072         SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
1073                         "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
1074
1075         AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
1076         SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1077                         "[E_INVALID_ARG] pMetadata is null.");
1078
1079         // Create the metadata extractor handle
1080         metadata_extractor_h tempExtractor = NULL;
1081
1082         int retVal = metadata_extractor_create(&tempExtractor);
1083         result r = ErrorMapToRetVal(retVal);
1084         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1085                         "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1086
1087         unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1088         SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1089                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1090
1091         const byte* pByte = byteBuffer.GetPointer();
1092
1093         retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1094         r = ErrorMapToRetVal(retVal);
1095         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1096                         "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1097
1098         // Get all relavent audio metadata by passing relavent attirbutes
1099         char* pTempAudioMeta = null;
1100         unique_ptr<char, CharDeleter> pAudioMeta(null);
1101
1102         // bitrate
1103         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
1104         if (pTempAudioMeta != null)
1105         {
1106                 pAudioMeta.reset(pTempAudioMeta);
1107                 pMetadata->bitrate = atoi(pAudioMeta.get());
1108         }
1109         else
1110         {
1111                 r = ErrorMapToRetVal(retVal);
1112                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1113                                 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
1114         }
1115
1116         // channelcount
1117         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
1118         if (pTempAudioMeta != null)
1119         {
1120                 pAudioMeta.reset(pTempAudioMeta);
1121                 pMetadata->channelCount = atoi(pAudioMeta.get());
1122         }
1123         else
1124         {
1125                 r = ErrorMapToRetVal(retVal);
1126                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1127                                 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
1128         }
1129
1130         // duration
1131         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
1132         if (pTempAudioMeta != null)
1133         {
1134                 pAudioMeta.reset(pTempAudioMeta);
1135                 pMetadata->duration = atoi(pAudioMeta.get());
1136         }
1137         else
1138         {
1139                 r = ErrorMapToRetVal(retVal);
1140                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1141                                 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1142         }
1143
1144         // frequency
1145         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
1146         if (pTempAudioMeta != null)
1147         {
1148                 pAudioMeta.reset(pTempAudioMeta);
1149                 pMetadata->frequency = atoi(pAudioMeta.get());
1150         }
1151         else
1152         {
1153                 r = ErrorMapToRetVal(retVal);
1154                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1155                                 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
1156         }
1157
1158         // albumname
1159         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
1160         if (pTempAudioMeta != null)
1161         {
1162                 pAudioMeta.reset(pTempAudioMeta);
1163                 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
1164                 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
1165                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1166         }
1167         else
1168         {
1169                 r = ErrorMapToRetVal(retVal);
1170                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1171                                 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
1172         }
1173
1174         // artist
1175         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
1176         if (pAudioMeta.get() != null)
1177         {
1178                 pAudioMeta.reset(pTempAudioMeta);
1179                 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
1180                 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
1181                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1182         }
1183         else
1184         {
1185                 r = ErrorMapToRetVal(retVal);
1186                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1187                                 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
1188         }
1189
1190         // copyright
1191         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
1192         if (pTempAudioMeta != null)
1193         {
1194                 pAudioMeta.reset(pTempAudioMeta);
1195                 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
1196                 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
1197                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1198         }
1199         else
1200         {
1201                 r = ErrorMapToRetVal(retVal);
1202                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1203                                 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
1204         }
1205
1206         // genre
1207         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
1208         if (pTempAudioMeta != null)
1209         {
1210                 pAudioMeta.reset(pTempAudioMeta);
1211                 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
1212                 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1213                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1214         }
1215         else
1216         {
1217                 r = ErrorMapToRetVal(retVal);
1218                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1219                                 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1220         }
1221
1222         // title
1223         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
1224         if (pTempAudioMeta != null)
1225         {
1226                 pAudioMeta.reset(pTempAudioMeta);
1227                 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
1228                 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
1229                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1230         }
1231         else
1232         {
1233                 r = ErrorMapToRetVal(retVal);
1234                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1235                                 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
1236         }
1237
1238         // comment
1239         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
1240         if (pTempAudioMeta != null)
1241         {
1242                 pAudioMeta.reset(pTempAudioMeta);
1243                 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
1244                 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1245                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1246         }
1247         else
1248         {
1249                 r = ErrorMapToRetVal(retVal);
1250                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1251                                 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1252         }
1253
1254         // description
1255         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
1256         if (pTempAudioMeta != null)
1257         {
1258                 pAudioMeta.reset(pTempAudioMeta);
1259                 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
1260                 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1261                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1262         }
1263         else
1264         {
1265                 r = ErrorMapToRetVal(retVal);
1266                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1267                                 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1268         }
1269
1270         // recording date
1271         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
1272         if (pTempAudioMeta != null)
1273         {
1274                 pAudioMeta.reset(pTempAudioMeta);
1275                 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
1276                 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
1277                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1278         }
1279         else
1280         {
1281                 r = ErrorMapToRetVal(retVal);
1282                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1283                                 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
1284         }
1285
1286         // author
1287         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
1288         if (pTempAudioMeta != null)
1289         {
1290                 pAudioMeta.reset(pTempAudioMeta);
1291                 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
1292                 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
1293                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1294         }
1295         else
1296         {
1297                 r = ErrorMapToRetVal(retVal);
1298                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1299                                 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
1300         }
1301
1302         // track info
1303         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
1304         if (pTempAudioMeta != null)
1305         {
1306                 pAudioMeta.reset(pTempAudioMeta);
1307                 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
1308                 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
1309                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1310
1311                 // if the string contains the track info like track num/track position,
1312                 // then track position will be ignored and only track num is returned
1313                 // no need to parse this string, since only track number is required
1314                 pMetadata->trackNum = atoi(pAudioMeta.get());
1315         }
1316         else
1317         {
1318                 r = ErrorMapToRetVal(retVal);
1319                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1320                                 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
1321         }
1322
1323         // date
1324         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
1325         if (pTempAudioMeta != null)
1326         {
1327                 pAudioMeta.reset(pTempAudioMeta);
1328                 pMetadata->year = atoi(pAudioMeta.get());
1329         }
1330         else
1331         {
1332                 r = ErrorMapToRetVal(retVal);
1333                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1334                                 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
1335         }
1336
1337         // artwork
1338         int size = 0;
1339         void* pTempArtwork = null;
1340         unique_ptr<void, VoidDeleter> pArtwork(null);
1341
1342         // Get the artwork image in media file
1343         retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
1344         pAudioMeta.reset(pTempAudioMeta);
1345
1346         //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
1347         //while processing albumart. This is to pass the other metadata tags to application.
1348         if (pTempArtwork != null)
1349         {
1350                 pArtwork.reset(pTempArtwork);
1351
1352                 Image img;
1353                 ImageFormat format = IMG_FORMAT_NONE;
1354                 ByteBuffer buffer;
1355
1356                 r = buffer.Construct(size);
1357                 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1358                 {
1359                         r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1360                         if (!IsFailed(r))
1361                         {
1362                                 r = img.Construct();
1363                                 if (!IsFailed(r))
1364                                 {
1365                                         format = img.GetImageFormat(buffer);
1366                                         pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
1367                                                                          _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
1368                                         if (pMetadata->pThumbnail == null)
1369                                         {
1370                                                 // Because Thumbnail is one of the metadata, it is not exception in this function.
1371                                                 SysLog(NID_CNT, "DecodeN failed.");
1372                                         }
1373                                         pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1374                                         if (pMetadata->pAlbumArt == null)
1375                                         {
1376                                                 // Because Album Art is one of the metadata, it is not exception in this function.
1377                                                 SysLog(NID_CNT, "DecodeN failed.");
1378                                         }
1379                                 }
1380                         }
1381                 }
1382         }
1383         else
1384         {
1385                 r = ErrorMapToRetVal(retVal);
1386                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1387                                 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1388         }
1389
1390         return pAudioMetadata.release();
1391 }
1392
1393 VideoMetadata*
1394 _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer)
1395 {
1396         ClearLastResult();
1397
1398         int bufferLen = byteBuffer.GetRemaining();
1399         SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1400
1401         // need to create here to make sure that all get APIs will not crash in case of corrupted file
1402         unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
1403         SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
1404                         "[E_OUT_OF_MEMORY] The memory insufficient.");
1405
1406         _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
1407         SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
1408                         "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
1409
1410         VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
1411         SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1412                         "[E_INVALID_ARG] pMetadata is null.");
1413
1414         // Create the metadata extractor handle
1415         metadata_extractor_h tempExtractor = NULL;
1416
1417         int retVal = metadata_extractor_create(&tempExtractor);
1418         result r = ErrorMapToRetVal(retVal);
1419         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1420                         "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1421
1422         unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1423         SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1424                                 "[E_OUT_OF_MEMORY] The memory insufficient.");
1425
1426         const byte* pByte = byteBuffer.GetPointer();
1427
1428         retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1429         r = ErrorMapToRetVal(retVal);
1430         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1431                         "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1432
1433         // Get all relavent video metadata by passing relavent attirbutes
1434         char* pTempVideoMeta = null;
1435         unique_ptr<char, CharDeleter> pVideoMeta(null);
1436
1437         // width
1438         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
1439         if (pTempVideoMeta != null)
1440         {
1441                 pVideoMeta.reset(pTempVideoMeta);
1442                 pMetadata->width = atoi(pVideoMeta.get());
1443         }
1444         else
1445         {
1446                 r = ErrorMapToRetVal(retVal);
1447                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1448                                 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
1449         }
1450
1451         // height
1452         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
1453         if (pTempVideoMeta != null)
1454         {
1455                 pVideoMeta.reset(pTempVideoMeta);
1456                 pMetadata->height = atoi(pVideoMeta.get());
1457         }
1458         else
1459         {
1460                 r = ErrorMapToRetVal(retVal);
1461                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1462                                 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
1463         }
1464
1465         // video bitrate
1466         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
1467         if (pTempVideoMeta != null)
1468         {
1469                 pVideoMeta.reset(pTempVideoMeta);
1470                 pMetadata->videoBitrate = atoi(pVideoMeta.get());
1471         }
1472         else
1473         {
1474                 r = ErrorMapToRetVal(retVal);
1475                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1476                                 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
1477         }
1478
1479         // audio bitrate
1480         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
1481         if (pTempVideoMeta != null)
1482         {
1483                 pVideoMeta.reset(pTempVideoMeta);
1484                 pMetadata->audioBitrate = atoi(pVideoMeta.get());
1485         }
1486         else
1487         {
1488                 r = ErrorMapToRetVal(retVal);
1489                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1490                                 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
1491         }
1492
1493         // framerate
1494         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
1495         if (pTempVideoMeta != null)
1496         {
1497                 pVideoMeta.reset(pTempVideoMeta);
1498                 pMetadata->framerate = atoi(pVideoMeta.get());
1499         }
1500         else
1501         {
1502                 r = ErrorMapToRetVal(retVal);
1503                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1504                                 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
1505         }
1506
1507         // duration
1508         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
1509         if (pTempVideoMeta != null)
1510         {
1511                 pVideoMeta.reset(pTempVideoMeta);
1512                 pMetadata->duration = atoi(pVideoMeta.get());
1513         }
1514         else
1515         {
1516                 r = ErrorMapToRetVal(retVal);
1517                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1518                                 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1519         }
1520
1521         // genre
1522         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
1523         if (pTempVideoMeta != null)
1524         {
1525                 pVideoMeta.reset(pTempVideoMeta);
1526                 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
1527                 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1528                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1529         }
1530         else
1531         {
1532                 r = ErrorMapToRetVal(retVal);
1533                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1534                                 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1535         }
1536
1537         // comment
1538         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
1539         if (pTempVideoMeta != null)
1540         {
1541                 pVideoMeta.reset(pTempVideoMeta);
1542                 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
1543                 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1544                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1545         }
1546         else
1547         {
1548                 r = ErrorMapToRetVal(retVal);
1549                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1550                                 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1551         }
1552
1553         // description
1554         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
1555         if (pTempVideoMeta != null)
1556         {
1557                 pVideoMeta.reset(pTempVideoMeta);
1558                 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
1559                 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1560                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1561         }
1562         else
1563         {
1564                 r = ErrorMapToRetVal(retVal);
1565                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1566                                 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1567         }
1568
1569         // artwork
1570         int size = 0;
1571         void* pTempArtwork = null;
1572         unique_ptr<void, VoidDeleter> pArtwork(null);
1573
1574         // Get the artwork image in media file
1575         retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
1576         pVideoMeta.reset(pTempVideoMeta);
1577         if (pTempArtwork != null)
1578         {
1579                 pArtwork.reset(pTempArtwork);
1580
1581                 Image img;
1582                 ImageFormat format = IMG_FORMAT_NONE;
1583                 ByteBuffer buffer;
1584
1585                 r = buffer.Construct(size);
1586                 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1587                 {
1588                         r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1589                         if (!IsFailed(r))
1590                         {
1591                                 r = img.Construct();
1592                                 if (!IsFailed(r))
1593                                 {
1594                                         format = img.GetImageFormat(buffer);
1595
1596                                         pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1597                                         if (pMetadata->pAlbumArt == null)
1598                                         {
1599                                                 // Because Album Art is one of the metadata, it is not exception in this function.
1600                                                 SysLog(NID_CNT, "DecodeN failed.");
1601                                         }
1602                                 }
1603                         }
1604                 }
1605         }
1606         else
1607         {
1608                 r = ErrorMapToRetVal(retVal);
1609                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1610                                 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1611         }
1612
1613         return pVideoMetadata.release();
1614 }
1615
1616 ContentType
1617 _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool internal)
1618 {
1619         ClearLastResult();
1620
1621         ContentType contentType = CONTENT_TYPE_UNKNOWN;
1622         String mimeType(L"");
1623
1624         if (!internal)
1625         {
1626                 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), contentType, E_INVALID_ARG,
1627                                 "[E_INVALID_ARG] The path is not compatible.");
1628         }
1629
1630         String tizenPath(L"");
1631         String changedPath(L"");
1632         result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
1633         SysTryReturn(NID_CNT, !IsFailed(r), contentType, r, "[%s] Failed to perform ChangeMediaFilePathCompat.", GetErrorMessage(r));
1634
1635         SysTryReturn(NID_CNT, changedPath.GetLength() != 0, contentType, E_INVALID_ARG,
1636                         "[E_INVALID_ARG] The length of contentPath is 0.");
1637         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), contentType, E_FILE_NOT_FOUND,
1638                         "[E_FILE_NOT_FOUND] The file corresponding to contentPath could not be found.");
1639
1640         String fileExt = _FileImpl::GetFileExtension(changedPath);
1641         r = GetLastResult();
1642
1643         if (!IsFailed(r))
1644         {
1645                 unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
1646                 SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
1647                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1648
1649                 char* pTempMimeType = null;
1650                 int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
1651                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
1652                                 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1653                 SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
1654                                 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1655
1656                 unique_ptr<char, CharDeleter> pMimeType;
1657                 pMimeType.reset(pTempMimeType);
1658
1659                 SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
1660
1661                 r = mimeType.Append(pMimeType.get());
1662                 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1663                                 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1664         }
1665         else
1666         {
1667                 ClearLastResult();
1668
1669                 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1670
1671                 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(tizenPath));
1672                 SysTryReturn(NID_CNT, pTempPath != null, contentType, E_OUT_OF_MEMORY,
1673                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1674
1675                 char tempType[255] = {0, };
1676                 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1677                 SysTryReturn(NID_CNT, ret == AUL_R_OK, contentType, E_INVALID_ARG,
1678                                 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1679
1680                 r = mimeType.Append(tempType);
1681                 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1682                                 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1683         }
1684
1685         if (mimeType.Contains(L"image"))
1686         {
1687                 return CONTENT_TYPE_IMAGE;
1688         }
1689         else if (mimeType.Contains(L"audio"))
1690         {
1691                 if (mimeType.Contains(L"x-mpegurl"))
1692                 {
1693                         SysLog(NID_CNT, "The type of x-mpegurl is other.");
1694                         return CONTENT_TYPE_OTHER;
1695                 }
1696                 return CONTENT_TYPE_AUDIO;
1697         }
1698         else if (mimeType.Contains(L"video"))
1699         {
1700                 if (mimeType == L"video/3gpp" || mimeType == L"video/mp4")
1701                 {
1702                         return CheckStream(tizenPath);
1703                 }
1704                 return CONTENT_TYPE_VIDEO;
1705         }
1706         else if (mimeType.Contains(L"application"))
1707         {
1708                 if (mimeType.Contains(L"x-smaf"))
1709                 {
1710                         SysLog(NID_CNT, "The type of x-smaf is audio.");
1711                         return CONTENT_TYPE_AUDIO;
1712                 }
1713                 return CONTENT_TYPE_OTHER;
1714         }
1715
1716         return CONTENT_TYPE_OTHER;
1717 }
1718
1719 ContentType
1720 _ContentManagerUtilImpl::CheckStream(const String& contentPath)
1721 {
1722         ClearLastResult();
1723
1724         ContentType contentType = CONTENT_TYPE_UNKNOWN;
1725         metadata_extractor_h tempExtractor = NULL;
1726
1727         int retVal = metadata_extractor_create(&tempExtractor);
1728         result r = ErrorMapToRetVal(retVal);
1729         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1730                         "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1731
1732         unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1733         SysTryReturn(NID_CNT, pExtractor != null, contentType, E_OUT_OF_MEMORY,
1734                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1735
1736         //Set the file path to extract metadata.
1737         unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
1738         SysTryReturn(NID_CNT, pContentPath != null, contentType, E_INVALID_ARG,
1739                         "[E_INVALID_ARG] The memory is insufficient.");
1740
1741         retVal = metadata_extractor_set_path(pExtractor.get(), pContentPath.get());
1742         r = ErrorMapToRetVal(retVal);
1743         SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE && pExtractor, contentType, r,
1744                         "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1745
1746         //Check whether it is an audio or video file.
1747         char* pTempAudio = null;
1748         unique_ptr<char, CharDeleter> pAudio(null);
1749
1750         char* pTempVideo = null;
1751         unique_ptr<char, CharDeleter> pVideo(null);
1752
1753         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_AUDIO, &pTempAudio);
1754         if (pTempAudio != null)
1755         {
1756                 pAudio.reset(pTempAudio);
1757         }
1758         else
1759         {
1760                 r = ErrorMapToRetVal(retVal);
1761                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1762                                 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1763         }
1764
1765         retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_VIDEO, &pTempVideo);
1766         if (pTempVideo != null)
1767         {
1768                 pVideo.reset(pTempVideo);
1769         }
1770         else
1771         {
1772                 r = ErrorMapToRetVal(retVal);
1773                 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1774                                 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1775         }
1776
1777         if (*(pAudio.get()) > '0' && *(pVideo.get()) == '0')
1778         {
1779                 SysLog(NID_CNT, "The result of CheckStream() is audio");
1780                 return CONTENT_TYPE_AUDIO;
1781         }
1782         else if (*(pAudio.get()) == '0' && *(pVideo.get()) > '0')
1783         {
1784                 SysLog(NID_CNT, "The result of CheckStream() is video");
1785                 return CONTENT_TYPE_VIDEO;
1786         }
1787         else if (*(pAudio.get()) > '0' && *(pVideo.get()) > '0')
1788         {
1789                 SysLog(NID_CNT, "The result of CheckStream() is video");
1790                 return CONTENT_TYPE_VIDEO;
1791         }
1792         else
1793         {
1794                 SysLogException(NID_CNT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The stream is empty.");
1795         }
1796
1797         return contentType;
1798 }
1799
1800 bool
1801 _ContentManagerUtilImpl::VerifyFilePathCompatibility(const String& contentPath)
1802 {
1803         if (!_AppInfo::IsOspCompat())
1804         {
1805                 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1806                         || contentPath.StartsWith(OSP_HOME, 0))
1807                 {
1808                         SysLogException(NID_CNT, E_INVALID_ARG,
1809                                         "/Home, /Media/, or /Storagecard/Media/ is not supported from Tizen 2.0.");
1810                         return false;
1811                 }
1812         }
1813         else
1814         {
1815                 // prior to 2.0
1816                 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1817                         || contentPath.StartsWith(OSP_HOME, 0)))
1818                 {
1819                         SysLogException(NID_CNT, E_INVALID_ARG,
1820                                         "The contentPath should start with /Home, /Media, or /Storagecard/Media.");
1821                         return false;
1822                 }
1823         }
1824
1825         return true;
1826 }
1827
1828 result
1829 _ContentManagerUtilImpl::ErrorMapToRetVal(int retVal)
1830 {
1831         result r = E_SUCCESS;
1832
1833         switch (retVal)
1834         {
1835         case METADATA_EXTRACTOR_ERROR_NONE:
1836                 r = E_SUCCESS;
1837                 break;
1838         case METADATA_EXTRACTOR_ERROR_INVALID_PARAMETER:
1839                 r = E_INVALID_ARG;
1840                 break;
1841         case METADATA_EXTRACTOR_ERROR_OUT_OF_MEMORY:
1842                 r = E_OUT_OF_MEMORY;
1843                 break;
1844         case METADATA_EXTRACTOR_ERROR_FILE_EXISTS:
1845                 r = E_INVALID_ARG;
1846                 break;
1847         case METADATA_EXTRACTOR_ERROR_OPERATION_FAILED:
1848                 r = E_INVALID_ARG;
1849                 break;
1850         }
1851
1852         return r;
1853 }
1854
1855 result
1856 _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1857 {
1858         ClearLastResult();
1859
1860         // For srcContentPath
1861         SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1862                 "[E_INVALID_ARG] Can not copy the file in the system region.");
1863         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1864                 "[E_INVALID_ARG] Can not find the file.");
1865
1866         // For destContentPath
1867         SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1868                 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1869
1870         // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1871         result r = E_SUCCESS;
1872         r = _FileImpl::Copy(srcContentPath, destContentPath, true);
1873         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CopyToMediaDirectory failed.", GetErrorMessage(r));
1874
1875         return r;
1876 }
1877
1878 result
1879 _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1880 {
1881         ClearLastResult();
1882
1883         // For srcContentPath
1884         SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1885                 "[E_INVALID_ARG] Can not copy the file in the system region.");
1886         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1887                 "[E_INVALID_ARG] Can not find the file.");
1888
1889         // For destContentPath
1890         SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1891                 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1892
1893         // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1894         result r = E_SUCCESS;
1895         r = _FileImpl::Move(srcContentPath, destContentPath);
1896         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] MoveToMediaDirectory failed.", GetErrorMessage(r));
1897
1898         return r;
1899 }
1900
1901 result
1902 _ContentManagerUtilImpl::ChangeMediaFilePath(const String& contentPath, String& tizenPath, String& changedPath)
1903 {
1904         result r = E_SUCCESS;
1905
1906         tizenPath = contentPath;
1907         changedPath = contentPath;
1908
1909         // If the api version is 2.0, the content path has to be changed.
1910         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1911         {
1912                 if ((contentPath.StartsWith(Environment::GetMediaPath(), 0)) || (contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1913                 {
1914                         tizenPath = contentPath;
1915
1916                         r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
1917                         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
1918                                         "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
1919                 }
1920                 else if ((contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) || (contentPath.StartsWith(OSP_MEDIA_MMC, 0)) || (contentPath.StartsWith(OSP_HOME, 0)))
1921                 {
1922                         changedPath = contentPath;
1923
1924                         r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, tizenPath);
1925                         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
1926                                         "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
1927                 }
1928                 else
1929                 {
1930                         SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path is not supported.", GetErrorMessage(E_INVALID_ARG));
1931                         return E_INVALID_ARG;
1932                 }
1933         }
1934
1935         return r;
1936 }
1937
1938 }}