Fix : Extract the gps information according to a locale
[platform/framework/native/content.git] / src / FCnt_ContentManagerUtilImpl.cpp
index de68e10..3393c15 100755 (executable)
  * This file contains implementation of the %_ContentManagerUtilImpl class.
  */
 
+#include <new>
 #include <stdlib.h>
+#include <aul/aul.h>
 #include <mime_type.h>
-#include <FBaseSysLog.h>
-#include <FBaseByteBuffer.h>
-#include <FIoDirectory.h>
 #include <FAppApp.h>
-#include <FSysEnvironment.h>
-#include <FMediaImage.h>
-#include <FMediaImageBuffer.h>
-#include <FMediaImageUtil.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseSysLog.h>
+#include <FBaseUtilStringTokenizer.h>
 #include <FCntImageMetadata.h>
 #include <FCntAudioMetadata.h>
 #include <FCntVideoMetadata.h>
-#include <FCnt_ContentManagerUtilImpl.h>
-#include <FCnt_AudioMetadataImpl.h>
-#include <FCnt_VideoMetadataImpl.h>
-#include <FCnt_ImageMetadataImpl.h>
+#include <FMediaImage.h>
+#include <FMediaImageBuffer.h>
+#include <FMediaImageUtil.h>
+#include <FIoDirectory.h>
+#include <FSysEnvironment.h>
+#include <FApp_AppInfo.h>
+#include <FBase_LocalizedNumParser.h>
 #include <FBase_StringConverter.h>
-#include <FIo_FileImpl.h>
 #include <FGrp_BitmapImpl.h>
+#include <FIo_FileImpl.h>
 #include <FMedia_ImageDecoder.h>
 #include <FMedia_ImageImpl.h>
-#include <FApp_AppInfo.h>
+#include "FCnt_AudioMetadataImpl.h"
+#include "FCnt_ContentManagerUtilImpl.h"
+#include "FCnt_ImageMetadataImpl.h"
+#include "FCnt_VideoMetadataImpl.h"
 
+using namespace std;
+using namespace Tizen::App;
 using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Graphics;
 using namespace Tizen::Io;
 using namespace Tizen::Media;
-using namespace Tizen::Graphics;
-using namespace Tizen::App;
 using namespace Tizen::System;
-using namespace std;
 
 namespace Tizen { namespace Content
 {
+
 // Types of content, format supported and default values
-static const int IMAGE_BUFF_LENGTH = 100;
-static const int THUMBNAIL_IMAGE_WIDTH = 80;
-static const int THUMBNAIL_IMAGE_HEIGHT = 60;
-static const int MINUTES = 60;
-static const int SECONDS = 3600;
+static const int _IMAGE_BUFF_LENGTH = 100;
+static const int _THUMBNAIL_IMAGE_WIDTH = 80;
+static const int _THUMBNAIL_IMAGE_HEIGHT = 60;
+static const int _MINUTES = 60;
+static const int _SECONDS = 3600;
 
-//
-// E_SUCCESS
-// E_INVALID_ARG
-// E_OUT_OF_MEMORY
-//
 ImageMetadata*
 _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
 {
@@ -104,9 +105,14 @@ _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
        pMetadata->height = dim.height;
        pMetadata->contentPath = contentPath;
 
+       String tizenPath(L"");
+       String changedPath(L"");
+       r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
+       SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
+
        if (imgType == IMG_FORMAT_JPG)
        {
-               unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
+               unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
                SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
                                "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
@@ -117,14 +123,14 @@ _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
                        ExifByteOrder byteOrder;
                        ExifEntry** pEntries = null;
                        const char* pData = null;
-                       char buf[IMAGE_BUFF_LENGTH] = {0, };
-                       char mmBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data
-                       char ssBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data
+                       char buf[_IMAGE_BUFF_LENGTH] = {0, };
                        ExifContent* pExifcont[EXIF_IFD_COUNT];
-                       int index = 0;
                        char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
                        char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
                        unsigned int entryCount = 0;
+                       bool isOrientation = false;
+                       bool isLatitude = false;
+                       bool isLongitude = false;
 
                        for (int i = 0; i < EXIF_IFD_COUNT; i++)
                        {
@@ -164,11 +170,13 @@ _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
                                                SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
                                                                "[E_OUT_OF_MEMORY] The memory is insufficient.");
                                        }
-                                       else if (tag == EXIF_TAG_ORIENTATION)
+                                       else if (tag == EXIF_TAG_ORIENTATION && !isOrientation)
                                        {
                                                //get the byte order(little endian or big endian) before extracting orientation type
                                                byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
                                                pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
+
+                                               isOrientation = true;
                                        }
                                        else if (tag == EXIF_TAG_SOFTWARE)
                                        {
@@ -180,110 +188,107 @@ _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
                                        {
                                                latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
                                        }
-                                       else if (tag == EXIF_TAG_GPS_LATITUDE)
+                                       else if (tag == EXIF_TAG_GPS_LATITUDE && !isLatitude)
                                        {
-                                               ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present
-                                               for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
-                                               {
-                                                       mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ','
-                                               }
-                                               index = 0; //re-assign index value as this is new buffer
-                                               ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present
-                                               for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
-                                               {
-                                                       ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ','
-                                               }
+                                               String tempLatitude(buf);
+                                               int firstComma = 0;
+                                               int lastComma = 0;
 
-                                               char *pLocal;
-                                               std::unique_ptr<char> pCurrentLocal(null);
-                                               pLocal = setlocale (LC_ALL, 0); // Get the name of the current locale.
-                                               if( pLocal == null )
-                                               {
-                                                       SysLog(NID_CNT, "setlocale failed. (get current locale)");
-                                                       continue;
-                                               }
-                                               pCurrentLocal.reset(strdup (pLocal));
+                                               r = tempLatitude.IndexOf(',', 0, firstComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
 
-                                               pLocal = setlocale(LC_ALL, "C");
-                                               if( pLocal == null )
-                                               {
-                                                       SysLog(NID_CNT, "setlocale failed. (set POSIX C locale)");
-                                                       continue;
-                                               }
+                                               r = tempLatitude.SetCharAt('/', firstComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
+
+                                               r = tempLatitude.LastIndexOf(',', tempLatitude.GetLength() - 1, lastComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
 
-                                               double ddVal = atof(buf); // degree value
-                                               double mmVal = atof(mmBuff); // minutesvalue
-                                               double ssVal = atof(ssBuff); // seconds value
+                                               r = tempLatitude.SetCharAt('/', lastComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
 
-                                               pLocal = setlocale (LC_ALL, pCurrentLocal.get()); // restore the locale.
-                                               if( pLocal == null )
+                                               String delim(L"/");
+                                               StringTokenizer strTok(tempLatitude, delim);
+                                               String token[3] = {L"", };
+
+                                               int count = 0;
+                                               while (strTok.HasMoreTokens() && count < 3)
                                                {
-                                                       SysLog(NID_CNT, "setlocale failed. (set current locale)");
-                                                       continue;
+                                                       strTok.GetNextToken(token[count++]);
                                                }
 
-                                               pMetadata->latitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS);
+                                               double ddVal = _LocalizedNumParser::ToDouble(token[0], ""); // degree value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               double mmVal = _LocalizedNumParser::ToDouble(token[1], ""); // minutes value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               double ssVal = _LocalizedNumParser::ToDouble(token[2], ""); // seconds value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
 
                                                // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
                                                if (latitudeRef == 'S')
                                                {
                                                        pMetadata->latitude = (pMetadata->latitude * (double)(-1));
                                                }
+                                               isLatitude = true;
                                        }
                                        else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
                                        {
                                                longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
                                        }
-                                       else if (tag == EXIF_TAG_GPS_LONGITUDE)
+                                       else if (tag == EXIF_TAG_GPS_LONGITUDE && !isLongitude)
                                        {
-                                               index = 0; //re-assign index value as this is new buffer
-                                               ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present
-                                               for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
-                                               {
-                                                       mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ','
-                                               }
-                                               index = 0; //re-assign index value as this is new buffer
-                                               ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present
-                                               for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
-                                               {
-                                                       ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ','
-                                               }
+                                               String tempLongitude(buf);
+                                               int firstComma = 0;
+                                               int lastComma = 0;
 
-                                               char *pLocal;
-                                               std::unique_ptr<char> pCurrentLocal(null);
-                                               pLocal = setlocale (LC_ALL, 0); // Get the name of the current locale.
-                                               if( pLocal == null )
-                                               {
-                                                       SysLog(NID_CNT, "setlocale failed. (get current locale)");
-                                                       continue;
-                                               }
-                                               pCurrentLocal.reset(strdup (pLocal));
+                                               r = tempLongitude.IndexOf(',', 0, firstComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
 
-                                               pLocal = setlocale(LC_ALL, "C");
-                                               if( pLocal == null )
-                                               {
-                                                       SysLog(NID_CNT, "setlocale failed. (set POSIX C locale)");
-                                                       continue;
-                                               }
+                                               r = tempLongitude.SetCharAt('/', firstComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
+
+                                               r = tempLongitude.LastIndexOf(',', tempLongitude.GetLength() - 1, lastComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
 
-                                               double ddVal = atof(buf); // degree value
-                                               double mmVal = atof(mmBuff); // minutesvalue
-                                               double ssVal = atof(ssBuff); // seconds value
+                                               r = tempLongitude.SetCharAt('/', lastComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
 
-                                               pLocal = setlocale (LC_ALL, pCurrentLocal.get()); // restore the locale.
-                                               if( pLocal == null )
+                                               String delim(L"/");
+                                               StringTokenizer strTok(tempLongitude, delim);
+                                               String token[3] = {L"", };
+
+                                               int count = 0;
+                                               while (strTok.HasMoreTokens() && count < 3)
                                                {
-                                                       SysLog(NID_CNT, "setlocale failed. (set current locale)");
-                                                       continue;
+                                                       strTok.GetNextToken(token[count++]);
                                                }
 
-                                               pMetadata->longitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS);
+                                               double ddVal = _LocalizedNumParser::ToDouble(token[0], ""); // degree value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               double mmVal = _LocalizedNumParser::ToDouble(token[1], ""); // minutes value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               double ssVal = _LocalizedNumParser::ToDouble(token[2], ""); // seconds value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
 
                                                // if longitude designation is Western (WEST) then longitude degree will be negative DD
                                                if (longitudeRef == 'W')
                                                {
                                                        pMetadata->longitude = (pMetadata->longitude * (double)(-1));
                                                }
+                                               isLongitude = true;
                                        }
                                        else if (tag == EXIF_TAG_WHITE_BALANCE)
                                        {
@@ -299,20 +304,6 @@ _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
        return pImageMetadata.release();
 }
 
-void
-_ContentManagerUtilImpl::ParseBuffer(char* pBuffer, int& count)
-{
-       if ((*pBuffer != ',') && (*pBuffer != '\0')) // parse the buffer till ',' or '\0' and return the index
-       {
-               ParseBuffer(++pBuffer, ++count);
-       }
-}
-
-//
-// E_SUCCESS
-// E_INVALID_ARG
-// E_OUT_OF_MEMORY
-//
 AudioMetadata*
 _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
 {
@@ -338,11 +329,16 @@ _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
 
        pMetadata->contentPath = contentPath;
 
+       String tizenPath(L"");
+       String changedPath(L"");
+       result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
+       SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
+
        // Create the metadata extractor handle
        metadata_extractor_h tempExtractor = NULL;
 
        int retVal = metadata_extractor_create(&tempExtractor);
-       result r = ErrorMapToRetVal(retVal);
+       r = ErrorMapToRetVal(retVal);
        SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
                        "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
 
@@ -351,7 +347,7 @@ _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
                        "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
        // Set file path of content to extract the metadata
-       unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
+       unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
        SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
                        "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
@@ -629,7 +625,7 @@ _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
                                {
                                        format = img.GetImageFormat(buffer);
                                        pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
-                                                                        THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
+                                                                        _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
                                        if (pMetadata->pThumbnail == null)
                                        {
                                                // Because Thumbnail is one of the metadata, it is not exception in this function.
@@ -655,11 +651,6 @@ _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
        return pAudioMetadata.release();
 }
 
-//
-// E_SUCCESS
-// E_INVALID_ARG
-// E_OUT_OF_MEMORY
-//
 VideoMetadata*
 _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
 {
@@ -685,11 +676,16 @@ _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
 
        pMetadata->contentPath = contentPath;
 
+       String tizenPath(L"");
+       String changedPath(L"");
+       result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
+       SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
+
        // Create the metadata extractor handle
        metadata_extractor_h tempExtractor = NULL;
 
        int retVal = metadata_extractor_create(&tempExtractor);
-       result r = ErrorMapToRetVal(retVal);
+       r = ErrorMapToRetVal(retVal);
        SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
                        "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
 
@@ -698,7 +694,7 @@ _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
                                "[E_OUT_OF_MEMORY] The memory insufficient.");
 
        // Set file path of content to extract the metadata
-       unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
+       unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
        SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
                        "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
@@ -915,6 +911,9 @@ _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
        ImageFormat imgType = IMG_FORMAT_NONE;
        int imageWidth = 0;
        int imageHeight = 0;
+       bool isOrientation = false;
+       bool isLatitude = false;
+       bool isLongitude = false;
 
        result r = ImageBuffer::GetImageInfo(byteBuffer, imgType, imageWidth, imageHeight);
        SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
@@ -934,11 +933,8 @@ _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
                        ExifByteOrder byteOrder;
                        ExifEntry** pEntries = null;
                        const char* pData = null;
-                       char buf[IMAGE_BUFF_LENGTH] = {0, };
-                       char mmBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data
-                       char ssBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data
+                       char buf[_IMAGE_BUFF_LENGTH] = {0, };
                        ExifContent* pExifcont[EXIF_IFD_COUNT];
-                       int index = 0;
                        char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
                        char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
                        unsigned int entryCount = 0;
@@ -981,11 +977,13 @@ _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
                                                SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
                                                                "[E_OUT_OF_MEMORY] The memory is insufficient.");
                                        }
-                                       else if (tag == EXIF_TAG_ORIENTATION)
+                                       else if (tag == EXIF_TAG_ORIENTATION && !isOrientation)
                                        {
                                                //get the byte order(little endian or big endian) before extracting orientation type
                                                byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
                                                pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
+
+                                               isOrientation = true;
                                        }
                                        else if (tag == EXIF_TAG_SOFTWARE)
                                        {
@@ -997,58 +995,107 @@ _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
                                        {
                                                latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
                                        }
-                                       else if (tag == EXIF_TAG_GPS_LATITUDE)
+                                       else if (tag == EXIF_TAG_GPS_LATITUDE && !isLatitude)
                                        {
-                                               ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present
-                                               for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
-                                               {
-                                                       mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ','
-                                               }
-                                               index = 0; //re-assign index value as this is new buffer
-                                               ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present
-                                               for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
+                                               String tempLatitude(buf);
+                                               int firstComma = 0;
+                                               int lastComma = 0;
+
+                                               r = tempLatitude.IndexOf(',', 0, firstComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
+
+                                               r = tempLatitude.SetCharAt('/', firstComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
+
+                                               r = tempLatitude.LastIndexOf(',', tempLatitude.GetLength() - 1, lastComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
+
+                                               r = tempLatitude.SetCharAt('/', lastComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
+
+                                               String delim(L"/");
+                                               StringTokenizer strTok(tempLatitude, delim);
+                                               String token[3] = {L"", };
+
+                                               int count = 0;
+                                               while (strTok.HasMoreTokens() && count < 3)
                                                {
-                                                       ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ','
+                                                       strTok.GetNextToken(token[count++]);
                                                }
-                                               double ddVal = atof(buf); // degree value
-                                               double mmVal = atof(mmBuff); // minutesvalue
-                                               double ssVal = atof(ssBuff); // seconds value
-                                               pMetadata->latitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS);
+
+                                               double ddVal = _LocalizedNumParser::ToDouble(token[0], ""); // degree value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               double mmVal = _LocalizedNumParser::ToDouble(token[1], ""); // minutes value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               double ssVal = _LocalizedNumParser::ToDouble(token[2], ""); // seconds value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
 
                                                // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
                                                if (latitudeRef == 'S')
                                                {
                                                        pMetadata->latitude = (pMetadata->latitude * (double)(-1));
                                                }
+                                               isLatitude = true;
                                        }
                                        else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
                                        {
                                                longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
                                        }
-                                       else if (tag == EXIF_TAG_GPS_LONGITUDE)
+                                       else if (tag == EXIF_TAG_GPS_LONGITUDE && !isLongitude)
                                        {
-                                               index = 0; //re-assign index value as this is new buffer
-                                               ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present
-                                               for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
-                                               {
-                                                       mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ','
-                                               }
-                                               index = 0; //re-assign index value as this is new buffer
-                                               ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present
-                                               for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
+                                               String tempLongitude(buf);
+                                               int firstComma = 0;
+                                               int lastComma = 0;
+
+                                               r = tempLongitude.IndexOf(',', 0, firstComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
+
+                                               r = tempLongitude.SetCharAt('/', firstComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
+
+                                               r = tempLongitude.LastIndexOf(',', tempLongitude.GetLength() - 1, lastComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
+
+                                               r = tempLongitude.SetCharAt('/', lastComma);
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
+
+                                               String delim(L"/");
+                                               StringTokenizer strTok(tempLongitude, delim);
+                                               String token[3] = {L"", };
+
+                                               int count = 0;
+                                               while (strTok.HasMoreTokens() && count < 3)
                                                {
-                                                       ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ','
+                                                       strTok.GetNextToken(token[count++]);
                                                }
-                                               double ddVal = atof(buf); // degree value
-                                               double mmVal = atof(mmBuff); // minutesvalue
-                                               double ssVal = atof(ssBuff); // seconds value
-                                               pMetadata->longitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS);
+
+                                               double ddVal = _LocalizedNumParser::ToDouble(token[0], ""); // degree value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               double mmVal = _LocalizedNumParser::ToDouble(token[1], ""); // minutes value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               double ssVal = _LocalizedNumParser::ToDouble(token[2], ""); // seconds value
+                                               r = GetLastResult();
+                                               SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
+
+                                               pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
 
                                                // if longitude designation is Western (WEST) then longitude degree will be negative DD
                                                if (longitudeRef == 'W')
                                                {
                                                        pMetadata->longitude = (pMetadata->longitude * (double)(-1));
                                                }
+                                               isLongitude = true;
                                        }
                                        else if (tag == EXIF_TAG_WHITE_BALANCE)
                                        {
@@ -1064,11 +1111,6 @@ _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
        return pImageMetadata.release();
 }
 
-//
-// E_SUCCESS
-// E_INVALID_ARG
-// E_OUT_OF_MEMORY
-//
 AudioMetadata*
 _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
 {
@@ -1378,7 +1420,7 @@ _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
                                {
                                        format = img.GetImageFormat(buffer);
                                        pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
-                                                                        THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
+                                                                        _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
                                        if (pMetadata->pThumbnail == null)
                                        {
                                                // Because Thumbnail is one of the metadata, it is not exception in this function.
@@ -1404,11 +1446,6 @@ _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
        return pAudioMetadata.release();
 }
 
-//
-// E_SUCCESS
-// E_INVALID_ARG
-// E_OUT_OF_MEMORY
-//
 VideoMetadata*
 _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer)
 {
@@ -1632,51 +1669,74 @@ _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer)
        return pVideoMetadata.release();
 }
 
-//
-// E_SUCCESS
-// E_INVALID_ARG
-// E_OUT_OF_MEMORY
-// E_FILE_NOT_FOUND
-// E_UNSUPPORTED_FORMAT
-//
 ContentType
 _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool internal)
 {
        ClearLastResult();
 
        ContentType contentType = CONTENT_TYPE_UNKNOWN;
+       String mimeType(L"");
 
        if (!internal)
        {
                SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), contentType, E_INVALID_ARG,
                                "[E_INVALID_ARG] The path is not compatible.");
        }
-       SysTryReturn(NID_CNT, contentPath.GetLength() != 0, contentType, E_INVALID_ARG,
+
+       String tizenPath(L"");
+       String changedPath(L"");
+       result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
+       SysTryReturn(NID_CNT, !IsFailed(r), contentType, r, "[%s] Failed to perform ChangeMediaFilePathCompat.", GetErrorMessage(r));
+
+       SysTryReturn(NID_CNT, changedPath.GetLength() != 0, contentType, E_INVALID_ARG,
                        "[E_INVALID_ARG] The length of contentPath is 0.");
-       SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), contentType, E_FILE_NOT_FOUND,
+       SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), contentType, E_FILE_NOT_FOUND,
                        "[E_FILE_NOT_FOUND] The file corresponding to contentPath could not be found.");
 
-       String fileExt = _FileImpl::GetFileExtension(contentPath);
-       result r = GetLastResult();
-       SysTryReturn(NID_CNT, !IsFailed(r), contentType, r, "[%s] GetFileExtension failed.", GetErrorMessage(r));
+       String fileExt = _FileImpl::GetFileExtension(changedPath);
+       r = GetLastResult();
 
-       unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
-       SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
-                       "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       if (!IsFailed(r))
+       {
+               unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
+               SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+               char* pTempMimeType = null;
+               int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
+               SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
+                               "[E_INVALID_ARG] mime_type_get_mime_type failed.");
+               SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
+                               "[E_INVALID_ARG] mime_type_get_mime_type failed.");
+
+               unique_ptr<char, CharDeleter> pMimeType;
+               pMimeType.reset(pTempMimeType);
 
-       char* pTempMimeType = null;
-       int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
-       SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
-                       "[E_INVALID_ARG] mime_type_get_mime_type failed.");
-       SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
-                       "[E_INVALID_ARG] mime_type_get_mime_type failed.");
+               SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
 
-       unique_ptr<char, CharDeleter> pMimeType;
-       pMimeType.reset(pTempMimeType);
+               r = mimeType.Append(pMimeType.get());
+               SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
+       }
+       else
+       {
+               ClearLastResult();
+
+               SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
+
+               unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(tizenPath));
+               SysTryReturn(NID_CNT, pTempPath != null, contentType, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-       SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
+               char tempType[255] = {0, };
+               int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
+               SysTryReturn(NID_CNT, ret == AUL_R_OK, contentType, E_INVALID_ARG,
+                               "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
 
-       String mimeType(pMimeType.get());
+               r = mimeType.Append(tempType);
+               SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
+       }
 
        if (mimeType.Contains(L"image"))
        {
@@ -1693,12 +1753,9 @@ _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool intern
        }
        else if (mimeType.Contains(L"video"))
        {
-               String format;
-               fileExt.ToLowerCase(format);
-
-               if (format == L"3gp" || format == L"mp4")
+               if (mimeType == L"video/3gpp" || mimeType == L"video/mp4")
                {
-                       return CheckStream(contentPath);
+                       return CheckStream(tizenPath);
                }
                return CONTENT_TYPE_VIDEO;
        }
@@ -1756,8 +1813,9 @@ _ContentManagerUtilImpl::CheckStream(const String& contentPath)
        }
        else
        {
+               // The return value is CONTENT_TYPE_VIDEO because CreaetContent have to success, even if the content is invalid.
                r = ErrorMapToRetVal(retVal);
-               SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
+               SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, CONTENT_TYPE_VIDEO, r,
                                "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
        }
 
@@ -1768,22 +1826,23 @@ _ContentManagerUtilImpl::CheckStream(const String& contentPath)
        }
        else
        {
+               // The return value is CONTENT_TYPE_VIDEO because CreaetContent have to success, even if the content is invalid.
                r = ErrorMapToRetVal(retVal);
-               SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
+               SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, CONTENT_TYPE_VIDEO, r,
                                "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
        }
 
-       if (*(pAudio.get()) > 0 && *(pVideo.get()) == 0)
+       if (*(pAudio.get()) > '0' && *(pVideo.get()) == '0')
        {
                SysLog(NID_CNT, "The result of CheckStream() is audio");
                return CONTENT_TYPE_AUDIO;
        }
-       else if (*(pAudio.get()) == 0 && *(pVideo.get()) > 0)
+       else if (*(pAudio.get()) == '0' && *(pVideo.get()) > '0')
        {
                SysLog(NID_CNT, "The result of CheckStream() is video");
                return CONTENT_TYPE_VIDEO;
        }
-       else if (*(pAudio.get()) > 0 && *(pVideo.get()) > 0)
+       else if (*(pAudio.get()) > '0' && *(pVideo.get()) > '0')
        {
                SysLog(NID_CNT, "The result of CheckStream() is video");
                return CONTENT_TYPE_VIDEO;
@@ -1851,9 +1910,6 @@ _ContentManagerUtilImpl::ErrorMapToRetVal(int retVal)
        return r;
 }
 
-/**
- * deprecation
- */
 result
 _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, const String& destContentPath)
 {
@@ -1877,9 +1933,6 @@ _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, cons
        return r;
 }
 
-/**
- * deprecation
- */
 result
 _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, const String& destContentPath)
 {
@@ -1902,4 +1955,42 @@ _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, cons
 
        return r;
 }
+
+result
+_ContentManagerUtilImpl::ChangeMediaFilePath(const String& contentPath, String& tizenPath, String& changedPath)
+{
+       result r = E_SUCCESS;
+
+       tizenPath = contentPath;
+       changedPath = contentPath;
+
+       // If the api version is 2.0, the content path has to be changed.
+       if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+       {
+               if ((contentPath.StartsWith(Environment::GetMediaPath(), 0)) || (contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
+               {
+                       tizenPath = contentPath;
+
+                       r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
+                       SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
+                                       "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
+               }
+               else if ((contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) || (contentPath.StartsWith(OSP_MEDIA_MMC, 0)) || (contentPath.StartsWith(OSP_HOME, 0)))
+               {
+                       changedPath = contentPath;
+
+                       r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, tizenPath);
+                       SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
+                                       "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
+               }
+               else
+               {
+                       SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path is not supported.", GetErrorMessage(E_INVALID_ARG));
+                       return E_INVALID_ARG;
+               }
+       }
+
+       return r;
+}
+
 }}