#include "Mediacontent.h"
#include "MediacontentManager.h"
#include "MediaFilterValidator.h"
-#include "MediaSearchVisitor.h"
-
-#include <mm_file.h>
-#include <mm_error.h>
-
+#include <Commons/StringUtils.h>
+#include <time.h>
using namespace TizenApis::Api::Mediacontent;
using namespace WrtDeviceApis::Commons;
#define MEDIA_DEBUG 0
-
-const string SELECT_FOLDER_QUERY =
- "select uuid, path, title, storage_type,modified_date from (select uuid, path, folder_name as title, storage_type,modified_date from visual_folder where valid=1 union select _id, path, folder_name as title, storage_type,modified_date from audio_folder) where 1 ";
-
-const string VIEW_MEDIA_QUERY_WITH_FOLDER =
- "select media_uuid, folder_uuid, content_type, display_name, path, thumbnail_path,created_date, released_date, modified_date, description,rating, album, artist, last_played_time, played_count,longitude, latitude, width, height, orientation, genre, author, duration, folder_name, folder_path from \
-(select media_uuid,folder_uuid, content_type, display_name, path, thumbnail_path,null as created_date, released_date, modified_date, description,rating, album, artist, last_played_time, null as played_count,longitude, latitude, width, height, orientation,null as genre, null as author, duration from visual_media join \
- (select * from \
- (select media_uuid, longitude, latitude, description, width, height, datetaken as released_date, orientation,null as album, null as artist, null as last_played_time,null as duration from image_meta \
- union all \
- select media_uuid, longitude, latitude, description, width, height, datetaken as released_date, null as orientation, album, artist, last_played_time,duration from video_meta)) \
-on uuid=media_uuid \
-union all \
- select audio_id, folder_id as folder_uuid, content_type, title as display_name, path, thumbnail_path, added_time, year, modified_date, description, favourite, album, artist, last_played_time, played_count, null as longitude, null as latitude, null as width, null as height, null as orientation, genre, author, duration from audio_media) \
-join ( select uuid as folder_id, path as folder_path, folder_name, modified_date as folder_modified_date, storage_type from visual_folder \
-union all \
- select _id as folder_id, path, folder_name, modified_date, storage_type from audio_folder) \
-on folder_uuid=folder_id where 1 ";
-
-const string SELECT_MEDIA_ID_WITH_FOLDER =
- "select item_id from item_view where folder_uuid=";
-const string SELECT_EXTRA_AUDIO =
- "select copyright,bitrate,track_num,size from audio_media where audio_id=";
-
+#define TAG_DELIMETER '/' //After reviewing the ID3v2.3 spec the delimiter is a "/" for multiple entries.
namespace TizenApis {
namespace Platform {
Mediacontent::Mediacontent()
{
- LogDebug("entered");
-
-// int ret;
-
- db_connnect_count++;
-
- db_util_open(MEDIA_DB_PATH, &hDBCt, 0);
- LogDebug("hDBCt:" << hDBCt);
+ LogDebug("entered");
}
Mediacontent::~Mediacontent()
{
- LogDebug("entered");
- int ret;
- db_connnect_count--;
- if(db_connnect_count == 0)
- {
- ret = db_util_close(hDBCt);
- if(ret != SQLITE_OK)
- ret = -1;
- else
- hDBCt = NULL;
- }
+ LogDebug("entered");
}
tm Mediacontent::toDateTm(time_t date)
{
tm tm_date;
-
- tm_date.tm_year = (date / 10000) - 1900;
- tm_date.tm_mon = ((date - ((tm_date.tm_year + 1900) * 10000)) / 100) - 1;
- tm_date.tm_mday = (date - ((tm_date.tm_year + 1900) * 10000) - tm_date.tm_mon * 100);
- return tm_date;
-}
+ localtime_r(&date, &tm_date);
+ return tm_date;
+}
-void Mediacontent::convertToPlatformFolder(folder_s &media_folder, MediacontentFolderPtr& newFolder)
+media_content_orientation_e Mediacontent::convertToOrientation(string orientation)
{
- if(media_folder.folder_uuid != NULL)
+ media_content_orientation_e ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
+
+ if ( orientation.compare("NORMAL")==0)
{
- newFolder->setFolderUUID(media_folder.folder_uuid);
+ ret = MEDIA_CONTENT_ORIENTATION_NORMAL;
}
- if(media_folder.folder_path != NULL)
+ else if (orientation.compare("FLIP_HORIZONTAL")==0)
{
- newFolder->setFolderName(media_folder.folder_name);
+ ret = MEDIA_CONTENT_ORIENTATION_HFLIP;
}
- if(media_folder.folder_name != NULL)
+ else if (orientation.compare("ROTATE_180")==0)
{
- newFolder->setFolderPath(media_folder.folder_path);
+ ret = MEDIA_CONTENT_ORIENTATION_ROT_180;
}
-
- newFolder->setFolderModifiedDate(toDateTm(media_folder.modified_date));
-
- string storageType;
-
- if(media_folder.storage_type == 0)
+ else if (orientation.compare("FLIP_VERTICAL")==0)
{
- storageType = "INTERNAL";
+ ret = MEDIA_CONTENT_ORIENTATION_VFLIP;
}
- else if( media_folder.storage_type == 1)
+ else if (orientation.compare("TRANSPOSE")==0)
{
- storageType = "EXTERNAL";
+ ret = MEDIA_CONTENT_ORIENTATION_TRANSPOSE;
}
+ else if (orientation.compare("ROTATE_90")==0)
+ {
+ ret = MEDIA_CONTENT_ORIENTATION_ROT_90;
+ }
+ else if (orientation.compare("TRANSVERSE")==0)
+ {
+ ret =MEDIA_CONTENT_ORIENTATION_TRANSVERSE;
+ }
+ else if (orientation.compare("ROTATE_270")==0)
+ {
+ ret =MEDIA_CONTENT_ORIENTATION_ROT_270;
+ }
else
{
- storageType = "UNKNOWN";
+ LogDebug("wrong value.");
+ ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
}
- newFolder->setFolderStorageType(storageType);
-}
-
+ return ret;
+}
-string Mediacontent::makeQuerySortMode(SortModeArrayPtr attr)
+void Mediacontent::convertToPlatformFolder(media_folder_h media_folder, MediacontentFolderPtr& newFolder)
{
- string query("");
- string attriName;
- int cnt = 0;
- SortModeArray::iterator it = attr->begin();
-
- for (;it!=attr->end(); ++it)
+ char* tmpStr = NULL;
+ time_t date;
+ media_content_storage_e storageType;
+
+ if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_folder_id(media_folder, &tmpStr))
{
- attriName = (*it)->getAttributeName();
- //convert to attribue's name
- MediaSearchVisitor visitor;
- attriName = visitor.getPlatformAttr(attriName);
- if (attriName.compare("") != 0)
- {
- if (cnt == 0)
- {
- query.append(" ORDER BY ");
- } else
- {
- query.append(", ");
- }
- query.append(attriName);
+ if ( tmpStr )
+ {
+ LogDebug("Folder UUID : " << tmpStr);
+ newFolder->setFolderUUID(tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
- if ((*it)->getOrder() == Api::Tizen::ASCENDING_SORT_ORDER)
- {
- query.append(" ASC");
- }
- else
- {
- query.append(" DESC");
- }
- cnt++;
+ if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_path(media_folder, &tmpStr))
+ {
+ if ( tmpStr )
+ {
+ LogDebug("Folder path : " << tmpStr);
+ newFolder->setFolderPath(tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
}
}
- return query;
+ if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_name(media_folder, &tmpStr))
+ {
+ if ( tmpStr )
+ {
+ LogDebug("Folder name : " << tmpStr);
+ newFolder->setFolderName(tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
+
+ if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_modified_time(media_folder, &date))
+ {
+ LogDebug("get Modified Time ");
+ newFolder->setFolderModifiedDate(toDateTm(date));
+ }
+
+ if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_storage_type(media_folder, &storageType))
+ {
+ LogDebug("storage Type=" << storageType);
+ string type;
+ if(storageType == MEDIA_CONTENT_STORAGE_INTERNAL )
+ {
+ type = "INTERNAL";
+ }
+ else if( storageType == MEDIA_CONTENT_STORAGE_EXTERNAL)
+ {
+ type = "EXTERNAL";
+ }
+ else
+ {
+ type = "UNKNOWN";
+ }
+ newFolder->setFolderStorageType(type);
+ }
+
+
}
+void Mediacontent::readCommonDataFromMediaInfo(media_info_h info, MediacontentMedia* newMedia)
+{
+ char* tmpStr = NULL;
+ time_t tmpDate;
+ int tmpInt = 0;
+ unsigned long long tmpLongLong = 0;
+ bool tmpBool= false;
-void Mediacontent::OnRequestReceived(const IEventFindFolderPtr &eFolder)
-{
- LogDebug("entered");
-
- string projection;
- string sortMode;
- string limitOffset;
- string condition;
- string query(SELECT_FOLDER_QUERY);
-
- //set condition
- MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
+ LogDebug("enter Common Data type : " << newMedia->getMediaType());
- if(eFolder->getFilterIsSet())
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_id(info, &tmpStr) )
{
- FilterPtr filter = eFolder->getFilter();
-
- FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_FOLDER);
- bool success = filter->validate(validator);
-
- if(!success)
- ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
-
- IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
-
- visitor->setQueryType(MediaSearchVisitor::QUERY_FOLDER);
- filter->travel(IVisitor);
- condition = visitor->getResult();
-
- query.append(" and ");
- query.append(condition);
+ if (tmpStr)
+ {
+ newMedia->setMediaUUID(tmpStr);
+ LogDebug("UUID : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
}
- if(eFolder->getSortModesIsSet())
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_mime_type(info, &tmpStr) )
{
- sortMode = makeQuerySortMode(eFolder->getSortModes());
-
- query.append(sortMode);
- }
-
- //set limit/offset
- if (eFolder->getLimitIsSet())
- {
- limitOffset.append(" LIMIT ");
- std::stringstream limitStream;
- limitStream << eFolder->getLimit();
- limitOffset.append(limitStream.str());
- if(eFolder->getOffsetIsSet())
+ if (tmpStr)
{
- limitOffset.append(" OFFSET ");
- std::stringstream offsetStream;
- offsetStream << eFolder->getOffset();
- limitOffset.append(offsetStream.str());
+ newMedia->setMimeType(tmpStr);
+ LogDebug("MineType : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
}
-
- query.append(limitOffset);
}
- LogDebug("execute condition [" << condition << "]");
- LogDebug("execute projection [" << projection << "]");
- LogDebug("execute sortMode [" << sortMode << "]");
- LogDebug("execute limitOffset [" << limitOffset << "]");
- LogDebug("execute query [" << query << "]");
- try
+ if ( newMedia->getMediaType().compare("IMAGE") == 0
+ && MEDIA_CONTENT_ERROR_NONE == media_info_get_display_name(info, &tmpStr) )
{
- sqlite3_stmt* pStmt = NULL;
- folder_s media_folder;
- sqlite3_prepare_v2(hDBCt, (char *)(query.c_str()), strlen((char *)(query.c_str())), &pStmt, NULL);
- while( sqlite3_step(pStmt) == SQLITE_ROW)
+ if (tmpStr)
{
- media_folder.folder_uuid = (char *)sqlite3_column_text(pStmt, 0);
- media_folder.folder_path = (char *)sqlite3_column_text(pStmt, 1);
- media_folder.folder_name = (char *)sqlite3_column_text(pStmt, 2);
- media_folder.storage_type = sqlite3_column_int(pStmt, 3);
- media_folder.modified_date = sqlite3_column_int(pStmt, 4);
-
- MediacontentFolderPtr newFolder(new MediacontentFolder());
- convertToPlatformFolder(media_folder, newFolder);
-
- string queryMediaId(SELECT_MEDIA_ID_WITH_FOLDER);
- queryMediaId.append("'");
- queryMediaId.append(media_folder.folder_uuid);
- queryMediaId.append("'");
- sqlite3_stmt* pStmt1 = NULL;
- if(sqlite3_prepare_v2(hDBCt, (char *)(queryMediaId.c_str()), strlen((char *)(queryMediaId.c_str())), &pStmt1, NULL) == SQLITE_OK)
- {
- MediaIdListPtr newMediaIdList(new MediaIdList());
- //sqlite3_bind_text(pStmt1, 1, media_folder.folder_uuid,strlen(media_folder.folder_uuid), SQLITE_TRANSIENT);
- LogDebug("execute 111111 [" << queryMediaId << "]");
- while( sqlite3_step(pStmt1) == SQLITE_ROW)
- {
- string mediaId = (char *)sqlite3_column_text(pStmt1, 0);
- LogDebug("execute mediaId [" << mediaId << "]");
- newMediaIdList->push_back(mediaId);
- }
- newFolder->setMediaIdList(newMediaIdList);
- sqlite3_finalize(pStmt1);
- }
+ newMedia->setDisplayName(tmpStr);
+ LogDebug("Display Name : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
- eFolder->addFolder(newFolder);
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_file_path(info, &tmpStr) )
+ {
+ if (tmpStr)
+ {
+ newMedia->setFilePath(tmpStr);
+ LogDebug("Path : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
}
- sqlite3_finalize(pStmt);
- eFolder->setResult(true);
+ }
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_thumbnail_path (info, &tmpStr) )
+ {
+ if (tmpStr)
+ {
+ newMedia->setThumbnailPath(tmpStr);
+ LogDebug("Thumnail Path : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
}
- catch (const Exception &ex)
+
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_description(info, &tmpStr) )
{
- LogError("Exception: " << ex.DumpToString());
- eFolder->setResult(false);
+ if (tmpStr)
+ {
+ newMedia->setDescription(tmpStr);
+ LogDebug("Desc : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
}
- eFolder->setCancelAllowed(true);
-}
+ //newImage->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_modified_time (info, &tmpDate) )
+ {
+ newMedia->setModifiedDate(Mediacontent::toDateTm(tmpDate));
+ }
-void Mediacontent::OnRequestReceived(const IEventFindMediaPtr &eMedia)
-{
- LogDebug("OnRequestReceived::IEventFindMediaPtr entered");
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_favorite (info, &tmpBool) )
+ {
+ newMedia->setFavorite(tmpBool);
+ LogDebug("favorite " << tmpBool);
+ }
- string projection;
- string sortMode;
- string limitOffset;
- string condition;
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_rating (info, &tmpInt) )
+ {
+ newMedia->setRating(tmpInt);
+ LogDebug("rating " << tmpInt);
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
+ {
+ newMedia->setSize(tmpLongLong);
+ LogDebug("Size : " << tmpLongLong);
+ }
- string query(VIEW_MEDIA_QUERY_WITH_FOLDER);
+}
- MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
+void Mediacontent::readImageFromMediaInfo( media_info_h info, MediacontentImage* newImage)
+{
+ char* tmpStr = NULL;
+ double tmpDouble;
+ int tmpInt = 0;
- if(eMedia->getFilterIsSet())
+ if ( info)
{
- FilterPtr filter = eMedia->getFilter();
+ newImage->setMediaType("IMAGE");
- // FIXME validator have to be placed at JS binding.
- FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
- bool success = filter->validate(validator);
+ readCommonDataFromMediaInfo(info, newImage);
- if(!success)
- ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
+ image_meta_h img;
+
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(info, &img))
+ {
+ //created time
+ if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_date_taken (img, &tmpStr) )
+ {
+ if ( tmpStr )
+ {
+ struct tm result;
+ if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
+ LogError( "Couldn't convert supplied date.");
+ }
+
+ LogDebug("image_meta_get_date_taken : " << tmpStr); //time??
+ newImage->setReleasedDate(result);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
- IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
+ if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_width(img, &tmpInt) )
+ {
+ newImage->setImageWidth(tmpInt);
+ LogDebug("Image Width " << tmpInt);
+ }
- visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
- filter->travel(IVisitor);
- condition = visitor->getResult();
- query.append(" and ");
- query.append(condition);
- }
+ if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_height(img, &tmpInt) )
+ {
+ newImage->setImageHeight(tmpInt);
+ LogDebug("Image Height " << tmpInt);
+ }
- if(eMedia->getSortModesIsSet())
- {
- sortMode = makeQuerySortMode(eMedia->getSortModes());
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
+ {
+ newImage->setImageLatitude(tmpDouble);
+ LogDebug("Image Latitude " << tmpDouble);
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
+ {
+ newImage->setImageLongitude(tmpDouble);
+ LogDebug("Image Longitude " << tmpDouble);
+ }
+
+ media_content_orientation_e orientation;
+
+ if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_orientation(img, &orientation) )
+ {
+
+ string orientationStr;
+ switch(orientation)
+ {
+ case 0:
+ case 1:
+ orientationStr = "NORMAL";
+ break;
+ case 2:
+ orientationStr = "FLIP_HORIZONTAL";
+ break;
+ case 3:
+ orientationStr = "ROTATE_180";
+ break;
+ case 4:
+ orientationStr = "FLIP_VERTICAL";
+ break;
+ case 5:
+ orientationStr = "TRANSPOSE";
+ break;
+ case 6:
+ orientationStr = "ROTATE_90";
+ break;
+ case 7:
+ orientationStr = "TRANSVERSE";
+ break;
+ case 8:
+ orientationStr = "ROTATE_270";
+ break;
+ }
+
+ newImage->setImageOrientation(orientationStr);
+ LogDebug(" image Orientation. " << orientationStr);
+
+ }
- query.append(sortMode);
+
+ if ( METADATA_EXTRACTOR_ERROR_NONE != image_meta_destroy(img))
+ {
+ LogDebug(" image_meta_destroy is fail... ");
+ }
+
+ }
+ else {
+ LogDebug("fetch Image Info failed..");
+ }
+
}
- if (eMedia->getLimitIsSet())
+ else
{
- limitOffset.append(" LIMIT ");
- std::stringstream limitStream;
- limitStream << eMedia->getLimit();
- limitOffset.append(limitStream.str());
- if(eMedia->getOffsetIsSet())
- {
- limitOffset.append(" OFFSET ");
- std::stringstream offsetStream;
- offsetStream << eMedia->getOffset();
- limitOffset.append(offsetStream.str());
- }
-
- query.append(limitOffset);
+ LogDebug("media info is NULL");
}
-
- LogDebug("execute condition [" << condition << "]");
- LogDebug("execute projection [" << projection << "]");
- LogDebug("execute sortMode [" << sortMode << "]");
- LogDebug("execute limitOffset [" << limitOffset << "]");
- LogDebug("execute query [" << query << "]");
-
+}
- int ret;
+void Mediacontent::readVideoFromMediaInfo( media_info_h info, MediacontentVideo* newVideo)
+{
+ char* tmpStr;
+ int tmpInt = 0;
+ double tmpDouble;
+ time_t tmpDate;
- try
+ if ( info)
{
- sqlite3_stmt* pStmt = NULL;
- int content_type;
- ret = sqlite3_prepare_v2(hDBCt, (char *)(query.c_str()), query.length(), &pStmt, NULL);
+ newVideo->setMediaType("VIDEO");
+
+ readCommonDataFromMediaInfo(info, newVideo); //set common media infomation
- while( sqlite3_step(pStmt) == SQLITE_ROW)
+ video_meta_h video;
+
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(info, &video))
{
- content_type = sqlite3_column_int(pStmt, 2);
+ if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_recorded_date(video, &tmpStr) )
+ {
+ if ( tmpStr )
+ {
+ struct tm result;
+ if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
+ LogError( "Couldn't convert supplied date.");
+ }
+ newVideo->setReleasedDate(result);
+
+ LogDebug("audio_meta_get_recorded_date : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_album(video, &tmpStr) )
+ {
+ if( tmpStr )
+ {
+ newVideo->setVideoAlbum(tmpStr);
+ LogDebug(" Video Album. " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
- if(content_type == MEDIA_TYPE_IMAGE)
+ if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_title(video, &tmpStr) )
{
+ if( tmpStr )
+ {
+ newVideo->setDisplayName(tmpStr);
+ LogDebug(" Video Title. " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
- MediacontentImage *newImage(new MediacontentImage());
- readImageFromDB(pStmt,newImage);
- eMedia->addMedia(newImage);
+ if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_artist(video, &tmpStr) )
+ {
+ if ( tmpStr)
+ {
+ std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
+ for( unsigned int i=0; i < artists.size(); i++)
+ {
+ string artist = artists.at(i);
+ LogDebug("Audio artist: " << artist);
+ newVideo->appendVideoArtist(artist);
+ }
+
+ free(tmpStr);
+ tmpStr = NULL;
+ }
}
- else if(content_type == MEDIA_TYPE_VIDEO)
+
+ if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_played_position(video, &tmpInt) )
+ {
+ newVideo->setVideoPlayedTime(tmpInt);
+ LogDebug(" Video PlayedTime. " << tmpInt);
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_played_count(video, &tmpInt) )
{
- MediacontentVideo *newVideo(new MediacontentVideo());
- readVideoFromDB(pStmt,newVideo);
- eMedia->addMedia(newVideo);
+ newVideo->setVideoPlayCount(tmpInt);
+ LogDebug(" Video PlayedCount. " << tmpInt);
}
- else if(content_type == MEDIA_TYPE_AUDIO)
+
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
{
- MediacontentAudio *newVAudio(new MediacontentAudio());
- readAudioFromDB(pStmt,newVAudio);
- eMedia->addMedia(newVAudio);
-
+ newVideo->setVideoLongitude(tmpDouble);
}
- }
- sqlite3_finalize(pStmt);
- eMedia->setResult(true);
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
+ {
+ newVideo->setVideoLatitude(tmpDouble);
+ }
- }
- catch (const Exception &ex)
- {
- LogError("Exception: " << ex.DumpToString());
- eMedia->setResult(false);
- }
+ if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_width(video, &tmpInt) )
+ {
+ newVideo->setVideoWidth(tmpInt);
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_height(video, &tmpInt) )
+ {
+ newVideo->setVideoHeight(tmpInt);
+ }
- eMedia->setCancelAllowed(true);
+ if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_duration(video, &tmpInt) )
+ {
+ newVideo->setVideoDuration(tmpInt);
+ }
+ if ( METADATA_EXTRACTOR_ERROR_NONE != video_meta_destroy(video))
+ {
+ LogDebug(" video_meta_destroy is fail... ");
+ }
+
+ }
+ else
+ {
+ LogDebug("fetch Video info fail...");
+ }
+ }
+ else
+ {
+ LogDebug("media info is NULL");
+ }
}
-void Mediacontent::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
-{
- LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered");
-
- try
+void Mediacontent::readMusicFromMediaInfo( media_info_h info, MediacontentAudio* newAudio)
+{
+ char* tmpStr;
+ int tmpInt = 0;
+ unsigned long long tmpLongLong = 0;
+
+ if ( info)
{
- MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
- string type = mediaPtr->getMediaType();
+ newAudio->setMediaType("AUDIO");
- if(type.compare("IMAGE")==0)
- {
- LogDebug("Image11");
- MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
- if(imagePtr != NULL)
+ readCommonDataFromMediaInfo(info, newAudio); //set common media infomation
+
+ audio_meta_h audio;
+
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(info, &audio))
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_recorded_date(audio, &tmpStr) )
{
- LogDebug("Image22");
+ if ( tmpStr )
+ {
+ struct tm result;
+ if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
+ LogError( "Couldn't convert supplied date.");
+ }
+ newAudio->setReleasedDate(result);
+
+ LogDebug("audio_meta_get_recorded_date : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
}
- }
- if(type.compare("VIDEO")==0)
- {
- LogDebug("Video11");
- MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
- if(videoPtr != NULL)
+
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_title(audio, &tmpStr) )
{
- LogDebug("video22");
- }
- }
- if(type.compare("AUDIO")==0)
- {
- LogDebug("Audio11");
- MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
- if(audioPtr != NULL)
+ if (tmpStr)
+ {
+ newAudio->setDisplayName(tmpStr);
+ LogDebug("Audio Title : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_album(audio, &tmpStr) )
{
- LogDebug("audio22");
- }
- }
+ if (tmpStr)
+ {
+ newAudio->setAudioAlbum(tmpStr);
+ LogDebug("Audio Album : " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
- eMedia->setResult(true);
- }
- catch (const Exception &ex)
- {
- LogError("Exception: " << ex.DumpToString());
- eMedia->setResult(false);
- }
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_artist(audio, &tmpStr) )
+ {
+ if (tmpStr)
+ {
+ std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
+ for( unsigned int i=0; i < artists.size(); i++)
+ {
+ string artist = artists.at(i);
+ LogDebug("Audio artist: " << artist);
+ newAudio->appendAudioArtist(artist);
+ }
+
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_played_position (audio, &tmpInt) )
+ {
+ newAudio->setAudioPlayedTime(tmpInt);
+ LogDebug("Audio Played Time : " << tmpInt);
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_played_count(audio, &tmpInt) )
+ {
+ newAudio->setAudioPlayCount(tmpInt);
+ LogDebug("Audio Played Count : " << tmpInt);
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_composer(audio, &tmpStr) )
+ {
+ if (tmpStr)
+ {
+ std::vector<std::string> composers = String::split(tmpStr, TAG_DELIMETER);
+ for( unsigned int i=0; i < composers.size(); i++)
+ {
+ string composer = composers.at(i);
+ LogDebug("Audio Composer : " << composer);
+ newAudio->appendAudioComposer(composer);
+ }
+
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_duration(audio, &tmpInt) )
+ {
+ newAudio->setAudioDuration(tmpInt);
+ LogDebug("Audio Duration : " << tmpInt);
+ }
- eMedia->setCancelAllowed(true);
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_copyright(audio, &tmpStr) )
+ {
+ if (tmpStr)
+ {
+ newAudio->setAudioCopyright(tmpStr);
+ LogDebug("Audio CopyRight: " << tmpStr);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_track_num(audio, &tmpStr) )
+ {
+ int trackNum = 0;
+ if (tmpStr)
+ {
+ LogDebug("trackNum: " << tmpStr);
+ try {
+ istringstream(tmpStr) >> trackNum;
+ } catch (...) {
+ LogDebug("Track Number type is wrong. (track number:" << tmpStr << ")");
+ trackNum = 0;
+ }
+
+ newAudio->setAudioTrackNum(trackNum);
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
-}
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
+ {
+ LogDebug("size");
+ newAudio->setAudioSize(tmpLongLong);
+ LogDebug("Audio Size: " << tmpLongLong);
+ }
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_bit_rate(audio, &tmpInt) )
+ {
+ LogDebug("bitrate");
+ newAudio->setAudioBitrate(tmpInt);
+ LogDebug("Audio Bitrate: " << tmpInt);
+ }
+ if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_genre(audio, &tmpStr) )
+ {
+ LogDebug("gener");
+ if (tmpStr)
+ {
+ std::vector<std::string> genres = String::split(tmpStr, TAG_DELIMETER);
+
+ for( unsigned int i=0; i < genres.size(); i++)
+ {
+ string genre = genres.at(i);
+ LogDebug("Audio Genre: " << genre);
+ newAudio->appendAudioGenre(genre);
+ }
+
+ free(tmpStr);
+ tmpStr = NULL;
+ }
+ }
+
+ if ( METADATA_EXTRACTOR_ERROR_NONE != audio_meta_destroy(audio))
+ {
+ LogDebug(" audio_meta_destroy is fail... ");
+ }
+
-void Mediacontent::readImageFromDB(sqlite3_stmt* pStmt, MediacontentImage* newImage)
-{
- char* tmp;
- if(pStmt != NULL)
+ }
+ else
+ {
+ LogDebug("fetch Music Info fail...");
+ }
+
+
+ }
+ else
{
+ LogDebug("media info is NULL");
+ }
+}
- tmp = (char*)sqlite3_column_text(pStmt,0);
- if( tmp != NULL)
- newImage->setMediaUUID(tmp);
- newImage->setMediaType("IMAGE");
-
- //setMimeType //2
- tmp = (char*)sqlite3_column_text(pStmt,3);
- if( tmp != NULL)
- newImage->setDisplayName(tmp);
-
- tmp = (char*)sqlite3_column_text(pStmt,4);
- if( tmp != NULL)
- newImage->setFilePath(tmp);
-
- tmp = (char*)sqlite3_column_text(pStmt,5);
- if( tmp != NULL)
- newImage->setThumbnailPath(tmp);
-
- newImage->setCreatedDate(toDateTm(sqlite3_column_int(pStmt,6)));
- newImage->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
- newImage->setModifiedDate(toDateTm(sqlite3_column_int(pStmt,8)));
-
- tmp = (char*)sqlite3_column_text(pStmt,9);
- if( tmp != NULL)
- newImage->setDescription(tmp);
-
- newImage->setFavorite(sqlite3_column_int(pStmt,10));
- newImage->setImageLatitude(sqlite3_column_double(pStmt,15));
- newImage->setImageLongitude(sqlite3_column_double(pStmt,16));
- newImage->setImageWidth(sqlite3_column_int(pStmt,17));
- newImage->setImageHeight(sqlite3_column_int(pStmt,18));
- int orientation = (sqlite3_column_int(pStmt,19));
- string orientationStr;
- switch(orientation)
+
+//Callback.
+bool Mediacontent::mediaFolderCallback(media_folder_h folder, void *user_data)
+{
+ LogDebug("enter");
+ if (user_data != NULL){
+ IEventFindFolder* event = (IEventFindFolder*)user_data;
+ LogDebug("user data is valide");
+ if ( folder )
{
- case 1:
- orientationStr = "NORMAL";
- break;
- case 2:
- orientationStr = "FLIP_HORIZONTAL";
- break;
- case 3:
- orientationStr = "ROTATE_180";
- break;
- case 4:
- orientationStr = "FLIP_VERTICAL";
- break;
- case 5:
- orientationStr = "TRANSPOSE";
- break;
- case 6:
- orientationStr = "ROTATE_90";
- break;
- case 7:
- orientationStr = "TRANSVERSE";
- break;
- case 8:
- orientationStr = "ROTATE_270";
- break;
- }
- newImage->setImageOrientation(orientationStr);
+ LogDebug("folder is valide");
+ MediacontentFolderPtr newFolder(new MediacontentFolder());
+ convertToPlatformFolder(folder, newFolder);
+ LogDebug("folder type" << newFolder->getFolderStorageType());
+
+ event->addFolder(newFolder);
+ }
+ }
+ else
+ {
+ LogDebug("user data is NULL");
}
+ return true;
+
}
+bool Mediacontent::mediaItemCallback(media_info_h info, void* user_data)
+{
+ if (user_data != NULL){
+ IEventBrowseFolder* event = (IEventBrowseFolder*)user_data;
+
+ media_content_type_e type;
+
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_type( info, &type) )
+ {
+ if ( type == MEDIA_CONTENT_TYPE_IMAGE)
+ {
+ MediacontentImage *newImage(new MediacontentImage());
+ readImageFromMediaInfo(info, newImage);
+ event->addMedia(newImage);
+ }
+ else if ( type == MEDIA_CONTENT_TYPE_VIDEO)
+ {
+ MediacontentVideo *newVideo(new MediacontentVideo());
+ readVideoFromMediaInfo(info, newVideo);
+ event->addMedia(newVideo);
+ }
+ else if ( type == MEDIA_CONTENT_TYPE_MUSIC)
+ {
+ MediacontentAudio *newVAudio(new MediacontentAudio());
+ readMusicFromMediaInfo(info, newVAudio);
+ event->addMedia(newVAudio);
+ }
+ else
+ {
+ LogDebug("other type");
+ }
+
+ }
+ }
+ else
+ {
+ LogDebug("event is NULL");
+ }
+ return true;
+}
-void Mediacontent::readVideoFromDB(sqlite3_stmt* pStmt, MediacontentVideo* newVideo)
+void Mediacontent::OnRequestReceived(const IEventFindFolderPtr &eFolder)
{
- char* tmp;
- if(pStmt != NULL)
+ LogDebug("entered");
+
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ media_folder_foreach_folder_from_db (NULL, mediaFolderCallback, eFolder.Get()))
+ {
+ LogError("error ( media_folder_foreach_folder_from_db ) : ");
+ eFolder->setResult(false);
+ }
+ else
{
+ eFolder->setResult(true);
+ }
- tmp = (char*)sqlite3_column_text(pStmt,0);
- if( tmp != NULL)
- newVideo->setMediaUUID(tmp);
- newVideo->setMediaType("VIDEO");
+ LogDebug("end");
+}
- //setMimeType
- tmp = (char*)sqlite3_column_text(pStmt,3);
- if( tmp != NULL)
- newVideo->setDisplayName(tmp);
+void Mediacontent::OnRequestReceived(const IEventBrowseFolderPtr &eBrowse)
+{
+ LogDebug("OnRequestReceived::IEventBrowseFolderPtr entered");
- tmp = (char*)sqlite3_column_text(pStmt,4);
- if( tmp != NULL)
- newVideo->setFilePath(tmp);
+ MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
+ visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
+ int ret = MEDIA_CONTENT_ERROR_NONE;
- tmp = (char*)sqlite3_column_text(pStmt,5);
- if( tmp != NULL)
- newVideo->setThumbnailPath(tmp);
+ try{
+ filter_h filter = NULL;
- newVideo->setCreatedDate(toDateTm(sqlite3_column_int(pStmt,6)));
- newVideo->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
- newVideo->setModifiedDate(toDateTm(sqlite3_column_int(pStmt,8)));
+ if(eBrowse->getFilterIsSet() || eBrowse->getFolderIdIsSet() || eBrowse->getSortModesIsSet()
+ || eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
+ {
+ //set filter
+ if ( MEDIA_CONTENT_ERROR_NONE == media_filter_create(&filter))
+ {
+ if (eBrowse->getFilterIsSet())
+ {
+ string condition;
+ FilterPtr jsFilter = eBrowse->getFilter();
- tmp = (char*)sqlite3_column_text(pStmt,9);
- if( tmp != NULL)
- newVideo->setDescription(tmp);
+ FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
+ bool success = jsFilter->validate(validator);
- newVideo->setFavorite(sqlite3_column_int(pStmt,10));
+ if(!success)
+ ThrowMsg(PlatformException, "Invalid attirbutes.");
+
+ IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
- tmp = (char*)sqlite3_column_text(pStmt,11);
- if( tmp != NULL)
- newVideo->setVideoAlbum(tmp);
+ jsFilter->travel(IVisitor);
+ condition = visitor->getResult();
- tmp = (char*)sqlite3_column_text(pStmt,12);
- if( tmp != NULL)
- newVideo->setVideoArtist(tmp);
+ LogDebug("execute condition [" << condition << "]");
+ media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT ); //set condition
+ }
- newVideo->setVideoPlayedTime(sqlite3_column_int(pStmt,13));
- newVideo->setVideoPlayCount(sqlite3_column_int(pStmt,14));
+ if(eBrowse->getSortModesIsSet())
+ {
+ media_content_order_e order;
+
+ SortModePtr attr = eBrowse->getSortMode();
+
+ if ( attr )
+ {
+ string attriName = attr->getAttributeName();
+ attriName = visitor->getPlatformAttr(attriName);
+ LogDebug("Attribute Name [" << attriName << "]");
+
+ if (attriName.compare("") != 0)
+ {
+ if (attr->getOrder() == Api::Tizen::ASCENDING_SORT_ORDER)
+ {
+ order = MEDIA_CONTENT_ORDER_ASC;
+ }
+ else
+ {
+ order = MEDIA_CONTENT_ORDER_DESC;
+ }
+
+ if ( attriName.compare( "MEDIA_TITLE") == 0 )
+ {
+ attriName.append(", MEDIA_DISPLAY_NAME");
+ }
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ media_filter_set_order(filter, order, attriName.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT )) //set order
+ {
+ LogDebug("media_filter_set_order fail...");
+ }
+ }
+ }
+
+ }
+
+ if (eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
+ {
+ LogDebug("limit or offset");
+
+ long count = -1;
+ long offset = 0;
+
+ if ( eBrowse->getLimitIsSet() )
+ {
+ count = eBrowse->getLimit();
+ LogDebug("limit is " << count);
+ }
+
+ if ( eBrowse->getOffsetIsSet() )
+ {
+ offset = eBrowse->getOffset();
+ LogDebug("offset is " << offset);
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE != media_filter_set_offset(filter, offset, count))
+ {
+ LogDebug("set limit or offset fail...");
+ }
+ }
+
+ }
+ else
+ {
+
+ LogError("error ( media filter create ) : ");
+ eBrowse->setResult(false);
+ }
+ }
- newVideo->setVideoLongitude(sqlite3_column_double(pStmt,15));
- newVideo->setVideoLatitude(sqlite3_column_double(pStmt,16));
+ if ( eBrowse->getFolderIdIsSet())
+ {
+ string folderID = eBrowse->getFolderID();
+ LogDebug("FolderID :" << folderID);
+
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ media_folder_foreach_media_from_db (folderID.c_str(), filter, mediaItemCallback, eBrowse.Get()))
+ {
+ LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
+ eBrowse->setResult(false);
+ }
+ else
+ {
+ eBrowse->setResult(true);
+ }
+ }
+ else
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ media_info_foreach_media_from_db (filter, mediaItemCallback, eBrowse.Get()))
+ {
+ LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
+ eBrowse->setResult(false);
+ }
+ else
+ {
+ eBrowse->setResult(true);
+ }
+ }
+
+ //destory Filter
+ if(filter)
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE != media_filter_destroy(filter))
+ {
+ LogError("media_filter_create Error: " << ret);
+ }
+ }
- newVideo->setVideoWidth(sqlite3_column_int(pStmt,17));
- newVideo->setVideoHeight(sqlite3_column_int(pStmt,18));
-
- newVideo->setVideoDuration(sqlite3_column_int(pStmt,22));
+ }
+ catch(const Exception &ex){
+ LogError("Exception: " << ex.DumpToString());
+ eBrowse->setResult(false);
+ return;
+ }
- }
+
}
-void Mediacontent::readAudioFromDB(sqlite3_stmt* pStmt, MediacontentAudio* newAudio)
-{
- char* tmp;
- if(pStmt != NULL)
- {
-
- tmp = (char*)sqlite3_column_text(pStmt,0);
- if( tmp != NULL)
- newAudio->setMediaUUID(tmp);
+bool Mediacontent::updateMediaToDB(MediacontentMediaPtr mediaPtr)
+{
+ string type = mediaPtr->getMediaType(); //media type.
+ string mediaId = mediaPtr->getMediaUUID();
- newAudio->setMediaType("AUDIO");
+ LogDebug("MediaId : " << mediaId);
+ media_info_h media = NULL;
+
+ bool ret = true;
+
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_from_db(mediaId.c_str(), &media))
+ {
+ if ( mediaPtr->isChangedRating()
+ || mediaPtr->isChangedDisplayName()
+ || mediaPtr->isChangedDescription() )
+ {
+
+ if ( mediaPtr->isChangedRating())
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE
+ != media_info_set_rating(media, mediaPtr->getRating()))
+ {
+ LogDebug("Error: set rating");
+ }
+ }
+ else if ( mediaPtr->isChangedDisplayName() )
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE
+ != media_info_set_description (media, mediaPtr->getDescription().c_str()))
+ {
+ LogDebug("Error: set description");
+ }
+ }
+ else
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE
+ != media_info_set_display_name (media, mediaPtr->getDisplayName().c_str()))
+ {
+ LogDebug("Error: set displayname");
+ }
+ }
+
- //setMimeType
- tmp = (char*)sqlite3_column_text(pStmt,3);
- if( tmp != NULL)
- newAudio->setDisplayName(tmp);
+ }
- tmp = (char*)sqlite3_column_text(pStmt,4);
- if( tmp != NULL)
- newAudio->setFilePath(tmp);
+ if(type.compare("IMAGE") ==0 )
+ {
+ MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
+
+ if(imagePtr && (imagePtr->isChangedOrientaion()
+ || imagePtr->isChangedLatitude() || imagePtr->isChangedLongitude()))
+ {
+ image_meta_h img=NULL;
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img))
+ {
+ if(imagePtr->isChangedOrientaion())
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ image_meta_set_orientation (img, convertToOrientation(imagePtr->getImageOrientation())))
+ {
+ LogDebug("Error: set orientation");
+ ret = false;
+ }
+ }
+
+ if ( imagePtr->isChangedLatitude() )
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ media_info_set_latitude(media, imagePtr->getImageLatitude())
+ )
+ {
+ LogDebug("Error: set Latitude");
+ ret = false;
+ }
+ }
+ if ( imagePtr->isChangedLongitude() )
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ media_info_set_longitude(media, imagePtr->getImageLongitude())
+ )
+ {
+ LogDebug("Error: set Latitude");
+ ret = false;
+ }
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE != image_meta_update_to_db (img) )
+ {
+ LogDebug("Error: update db");
+ ret = false;
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE != image_meta_destroy(img))
+ {
+ LogDebug("Error: destroy media info");
+ ret = false;
+ }
+
+ img = NULL;
+
+ }
+ else
+ {
+ LogDebug("Error: get Image from DB");
+ ret = false;
+ }
+ }
+
+ }
- tmp = (char*)sqlite3_column_text(pStmt,5);
- if( tmp != NULL)
- newAudio->setThumbnailPath(tmp);
+ if(type.compare("VIDEO") ==0 )
+ {
+ MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
+ if (videoPtr && ( videoPtr->isChangedPlayCount () || videoPtr->isChangedPlayedTime ()
+ ||videoPtr->isChangedArtists () || videoPtr->isChangedAlbum()
+ || videoPtr->isChangedLatitude() ||videoPtr->isChangedLongitude()) )
+ {
- newAudio->setCreatedDate(toDateTm(sqlite3_column_int(pStmt,6)));
- newAudio->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
- newAudio->setModifiedDate(toDateTm(sqlite3_column_int(pStmt,8)));
+ video_meta_h video = NULL;
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(media, &video))
+ {
+ if ( videoPtr->isChangedPlayCount() )
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ video_meta_set_played_count (video, videoPtr->getVideoPlayCount()))
+ {
+ LogDebug("Error: set play count");
+ ret = false;
+
+ }
+ }
+
+ if (videoPtr->isChangedPlayedTime())
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ video_meta_set_played_position (video, videoPtr->getVideoPlayedTime()))
+ {
+ LogDebug("Error: set played time");
+ ret = false;
+ }
+ }
+#if 0 //NOT support
+ if (videoPtr->isChangedAlbum())
+ {
+ LogDebug("Not support - Album API");
+ ret = false;
+ }
+
+ if (videoPtr->isChangedArtists())
+ {
+ LogDebug("Not support - Artist API");
+ ret = false;
+ }
+#endif
+ if ( videoPtr->isChangedLatitude() )
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ media_info_set_latitude(media, videoPtr->getVideoLatitude())
+ )
+ {
+ LogDebug("Error: set Latitude");
+ ret = false;
+ }
+ }
+ if ( videoPtr->isChangedLongitude() )
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ media_info_set_longitude(media, videoPtr->getVideoLongitude())
+ )
+ {
+ LogDebug("Error: set Latitude");
+ ret = false;
+ }
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE != video_meta_update_to_db (video) )
+ {
+ LogDebug("Error: update db");
+ ret = false;
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE != video_meta_destroy(video))
+ {
+ LogDebug("Error: destroy video meta");
+ ret = false;
+ }
+
+ video = NULL;
+
+ }
+ }
+
+ } //video
- tmp = (char*)sqlite3_column_text(pStmt,9);
- if( tmp != NULL)
- newAudio->setDescription(tmp);
+
- newAudio->setFavorite(sqlite3_column_int(pStmt,10));
+ if(type.compare("AUDIO") ==0 )
+ {
+
+ MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
+ if (audioPtr && ( audioPtr->isChangedPlayCount () || audioPtr->isChangedPlayedTime ()
+ ||audioPtr->isChangedAudioArtist () || audioPtr->isChangedAudioAlbum()
+ || audioPtr->isChangedAudioGenre() ||audioPtr->isChangedAudioComposer()
+ || audioPtr->isChangedAudioTrackNumber()) )
+ {
- tmp = (char*)sqlite3_column_text(pStmt,11);
- if( tmp != NULL)
- newAudio->setAudioAlbum(tmp);
+ audio_meta_h audio=NULL;
+ if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(media, &audio))
+ {
+ if ( audioPtr->isChangedPlayCount() )
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ audio_meta_set_played_count (audio, audioPtr->getAudioPlayCount()))
+ {
+ LogDebug("Error: set play count");
+ ret = false;
+ }
+ }
+
+ if (audioPtr->isChangedPlayedTime())
+ {
+ if ( MEDIA_CONTENT_ERROR_NONE !=
+ audio_meta_set_played_position (audio, audioPtr->getAudioPlayedTime()))
+ {
+ LogDebug("Error: set played time");
+ ret = false;
+ }
+ }
+#if 0 //NOT support
+ if (audioPtr->isChangedAudioArtist())
+ {
+ LogDebug("Not Support API");
+ ret = false;
+ }
+
+ if (audioPtr->isChangedAudioAlbum())
+ {
+ LogDebug("Not Support API");
+ ret = false;
+ }
+
+ if (audioPtr->isChangedAudioGenre())
+ {
+ LogDebug("Not Support API");
+ ret = false;
+ }
+
+ if (audioPtr->isChangedAudioComposer())
+ {
+ LogDebug("Not Support API");
+ ret = false;
+ }
+
+ if (audioPtr->isChangedAudioTrackNumber())
+ {
+ LogDebug("Not Support API");
+ ret = false;
+ }
+#endif
+ if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_update_to_db (audio) )
+ {
+ LogDebug("Error: update db");
+ ret = false;
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_destroy(audio))
+ {
+ LogDebug("Error: destroy audio meta");
+ ret = false;
+ }
+ audio = NULL;
+ }
- tmp = (char*)sqlite3_column_text(pStmt,12);
- if( tmp != NULL)
- newAudio->setAudioArtist(tmp);
+ }
- newAudio->setAudioPlayedTime(sqlite3_column_int(pStmt,13));
- newAudio->setAudioPlayCount(sqlite3_column_int(pStmt,14));
+ }
+
+
+ //update media info
+ if ( MEDIA_CONTENT_ERROR_NONE != media_info_update_to_db(media))
+ {
+ LogDebug("Error: update to DB");
+ ret = false;
+ }
+
+ if ( MEDIA_CONTENT_ERROR_NONE !=media_info_destroy(media))
+ {
+ LogDebug("Error: destroy media info");
+ ret = false;
+ }
+
+ }
- tmp = (char*)sqlite3_column_text(pStmt,20);
- if( tmp != NULL)
- newAudio->setAudioGenre(tmp);
+ return ret;
- tmp = (char*)sqlite3_column_text(pStmt,21);
- if( tmp != NULL)
- newAudio->setAudioComposer(tmp);
+}
- newAudio->setAudioDuration(sqlite3_column_int(pStmt,22));
+void Mediacontent::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
+{
+ LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered");
+ try
+ {
+ MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
- string queryExtraAudio(SELECT_EXTRA_AUDIO);
- queryExtraAudio.append("'");
- queryExtraAudio.append(newAudio->getMediaUUID());
- queryExtraAudio.append("'");
- sqlite3_stmt* pStmt1 = NULL;
- //"select copyright,bitrate,track_num,size from audio_media where audio_id=";
- if(sqlite3_prepare_v2(hDBCt, (char *)(queryExtraAudio.c_str()), strlen((char *)(queryExtraAudio.c_str())), &pStmt1, NULL) == SQLITE_OK)
+ if(updateMediaToDB(mediaPtr))
{
- while( sqlite3_step(pStmt1) == SQLITE_ROW)
- {
- tmp = (char*)sqlite3_column_text(pStmt,0);
- if( tmp != NULL)
- newAudio->setAudioCopyright(tmp);
- newAudio->setAudioBitrate(sqlite3_column_int(pStmt,1));
- newAudio->setAudioTrackNum(sqlite3_column_int(pStmt,2));
- newAudio->setAudioSize(sqlite3_column_int(pStmt,3));
- }
- sqlite3_finalize(pStmt1);
+ eMedia->setResult(true);
+ LogDebug("update success");
}
-
- MMHandleType tag_attrs = 0;
- LogDebug("AUDIO PATH: " << newAudio->getFilePath());
- int ret = mm_file_create_tag_attrs(&tag_attrs, newAudio->getFilePath().c_str());
-
- char *err_attr_name = NULL;
- char* unSyncText;
- int unSyncLen;
- int syncTextNum;
- if (ret == MM_ERROR_NONE && tag_attrs)
+ else
{
- ret = mm_file_get_attrs( tag_attrs,
- &err_attr_name,
- MM_FILE_TAG_UNSYNCLYRICS, &unSyncText, &unSyncLen,
- MM_FILE_TAG_SYNCLYRICS_NUM, &syncTextNum,
- NULL);
+ eMedia->setResult(false);
+ ThrowMsg(PlatformException, "DB operation is failed");
}
- if (ret != MM_ERROR_NONE && err_attr_name)
+ }
+ catch (const Exception &ex)
+ {
+ LogError("Exception: " << ex.DumpToString());
+ eMedia->setResult(false);
+ }
+}
+
+
+void Mediacontent::OnRequestReceived(const IEventUpdateMediaItemsPtr &eItems)
+{
+ LogDebug("OnRequestReceived::IEventUpdateMediaItemsPtr entered");
+
+ try
+ {
+ MediacontentMediaListPtr mediaListPtr = eItems->getMediaItems();
+ if (mediaListPtr->empty())
+ {
+ LogDebug("Item vector is empty");
+ }
+ else
{
- MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
- if(syncTextNum > 0)
- {
- lyricsPtr->setMediaLyricsType("SYNCHRONIZED");
- for(int i=0; i < syncTextNum; i++)
- {
- unsigned long time_info = 0;
- char * lyrics_info = NULL;
- mm_file_get_synclyrics_info(tag_attrs,i,&time_info,&lyrics_info);
- lyricsPtr->addMediaLyricsTimeStamp(time_info);
- lyricsPtr->addMediaLyricsText(lyrics_info);
- LogDebug("SYNCHRONIZED: " << lyrics_info);
+ for(unsigned int i=0; i<mediaListPtr->size(); i++)
+ {
+
+ MediacontentMediaPtr mediaPtr = mediaListPtr->at(i);
+ if(updateMediaToDB(mediaPtr))
+ {
+ eItems->setResult(true);
+ LogDebug("update success");
}
+ else
+ {
+ eItems->setResult(false);
+ ThrowMsg(PlatformException, "DB operation is failed");
+ }
+
}
- else
- {
- LogDebug("UNSYNCHRONIZED: " << unSyncText);
- lyricsPtr->setMediaLyricsType("UNSYNCHRONIZED");
- lyricsPtr->addMediaLyricsTimeStamp(0);
- lyricsPtr->addMediaLyricsText(unSyncText);
-
- }
- newAudio->setAudioLyrics(lyricsPtr);
}
-
}
-
+ catch (const Exception &ex)
+ {
+ LogError("Exception: " << ex.DumpToString());
+ eItems->setResult(false);
+ }
+ //eItems->setCancelAllowed(false);
+
}