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