2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <dpl/log/log.h>
18 #include <dpl/scoped_ptr.h>
20 #include "Mediacontent.h"
21 #include "MediacontentManager.h"
22 #include "MediaFilterValidator.h"
23 #include <Commons/StringUtils.h>
27 using namespace TizenApis::Api::Mediacontent;
28 using namespace WrtDeviceApis::Commons;
31 #define TAG_DELIMETER '/' //After reviewing the ID3v2.3 spec the delimiter is a "/" for multiple entries.
35 namespace Mediacontent{
37 Mediacontent::Mediacontent()
42 Mediacontent::~Mediacontent()
47 tm Mediacontent::toDateTm(time_t date)
51 localtime_r(&date, &tm_date);
56 media_content_orientation_e Mediacontent::convertToOrientation(string orientation)
58 media_content_orientation_e ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
60 if ( orientation.compare("NORMAL")==0)
62 ret = MEDIA_CONTENT_ORIENTATION_NORMAL;
64 else if (orientation.compare("FLIP_HORIZONTAL")==0)
66 ret = MEDIA_CONTENT_ORIENTATION_HFLIP;
68 else if (orientation.compare("ROTATE_180")==0)
70 ret = MEDIA_CONTENT_ORIENTATION_ROT_180;
72 else if (orientation.compare("FLIP_VERTICAL")==0)
74 ret = MEDIA_CONTENT_ORIENTATION_VFLIP;
76 else if (orientation.compare("TRANSPOSE")==0)
78 ret = MEDIA_CONTENT_ORIENTATION_TRANSPOSE;
80 else if (orientation.compare("ROTATE_90")==0)
82 ret = MEDIA_CONTENT_ORIENTATION_ROT_90;
84 else if (orientation.compare("TRANSVERSE")==0)
86 ret =MEDIA_CONTENT_ORIENTATION_TRANSVERSE;
88 else if (orientation.compare("ROTATE_270")==0)
90 ret =MEDIA_CONTENT_ORIENTATION_ROT_270;
94 LogDebug("wrong value.");
95 ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
101 void Mediacontent::convertToPlatformFolder(media_folder_h media_folder, MediacontentFolderPtr& newFolder)
105 media_content_storage_e storageType;
107 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_folder_id(media_folder, &tmpStr))
111 LogDebug("Folder UUID : " << tmpStr);
112 newFolder->setFolderUUID(tmpStr);
118 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_path(media_folder, &tmpStr))
122 LogDebug("Folder path : " << tmpStr);
123 newFolder->setFolderPath(tmpStr);
129 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_name(media_folder, &tmpStr))
133 LogDebug("Folder name : " << tmpStr);
134 newFolder->setFolderName(tmpStr);
140 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_modified_time(media_folder, &date))
142 LogDebug("get Modified Time ");
143 newFolder->setFolderModifiedDate(toDateTm(date));
146 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_storage_type(media_folder, &storageType))
148 LogDebug("storage Type=" << storageType);
150 if(storageType == MEDIA_CONTENT_STORAGE_INTERNAL )
154 else if( storageType == MEDIA_CONTENT_STORAGE_EXTERNAL)
162 newFolder->setFolderStorageType(type);
168 void Mediacontent::readCommonDataFromMediaInfo(media_info_h info, MediacontentMedia* newMedia)
174 unsigned long long tmpLongLong = 0;
177 LogDebug("enter Common Data type : " << newMedia->getMediaType());
179 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_id(info, &tmpStr) )
183 newMedia->setMediaUUID(tmpStr);
184 LogDebug("UUID : " << tmpStr);
190 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_mime_type(info, &tmpStr) )
194 newMedia->setMimeType(tmpStr);
195 LogDebug("MineType : " << tmpStr);
201 if ( newMedia->getMediaType().compare("IMAGE") == 0
202 && MEDIA_CONTENT_ERROR_NONE == media_info_get_display_name(info, &tmpStr) )
206 newMedia->setDisplayName(tmpStr);
207 LogDebug("Display Name : " << tmpStr);
213 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_file_path(info, &tmpStr) )
217 newMedia->setFilePath(tmpStr);
218 LogDebug("Path : " << tmpStr);
224 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_thumbnail_path (info, &tmpStr) )
228 newMedia->setThumbnailPath(tmpStr);
229 LogDebug("Thumnail Path : " << tmpStr);
235 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_description(info, &tmpStr) )
239 newMedia->setDescription(tmpStr);
240 LogDebug("Desc : " << tmpStr);
246 //newImage->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
247 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_modified_time (info, &tmpDate) )
249 newMedia->setModifiedDate(Mediacontent::toDateTm(tmpDate));
252 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_favorite (info, &tmpBool) )
254 newMedia->setFavorite(tmpBool);
255 LogDebug("favorite " << tmpBool);
258 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_rating (info, &tmpInt) )
260 newMedia->setRating(tmpInt);
261 LogDebug("rating " << tmpInt);
264 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
266 newMedia->setSize(tmpLongLong);
267 LogDebug("Size : " << tmpLongLong);
272 void Mediacontent::readImageFromMediaInfo( media_info_h info, MediacontentImage* newImage)
280 newImage->setMediaType("IMAGE");
282 readCommonDataFromMediaInfo(info, newImage);
286 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(info, &img))
289 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_date_taken (img, &tmpStr) )
294 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
295 LogError( "Couldn't convert supplied date.");
298 LogDebug("image_meta_get_date_taken : " << tmpStr); //time??
299 newImage->setReleasedDate(result);
305 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_width(img, &tmpInt) )
307 newImage->setImageWidth(tmpInt);
308 LogDebug("Image Width " << tmpInt);
311 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_height(img, &tmpInt) )
313 newImage->setImageHeight(tmpInt);
314 LogDebug("Image Height " << tmpInt);
317 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
319 newImage->setImageLatitude(tmpDouble);
320 LogDebug("Image Latitude " << tmpDouble);
323 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
325 newImage->setImageLongitude(tmpDouble);
326 LogDebug("Image Longitude " << tmpDouble);
329 media_content_orientation_e orientation;
331 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_orientation(img, &orientation) )
334 string orientationStr;
339 orientationStr = "NORMAL";
342 orientationStr = "FLIP_HORIZONTAL";
345 orientationStr = "ROTATE_180";
348 orientationStr = "FLIP_VERTICAL";
351 orientationStr = "TRANSPOSE";
354 orientationStr = "ROTATE_90";
357 orientationStr = "TRANSVERSE";
360 orientationStr = "ROTATE_270";
364 newImage->setImageOrientation(orientationStr);
365 LogDebug(" image Orientation. " << orientationStr);
370 if ( METADATA_EXTRACTOR_ERROR_NONE != image_meta_destroy(img))
372 LogDebug(" image_meta_destroy is fail... ");
377 LogDebug("fetch Image Info failed..");
383 LogDebug("media info is NULL");
387 void Mediacontent::readVideoFromMediaInfo( media_info_h info, MediacontentVideo* newVideo)
396 newVideo->setMediaType("VIDEO");
398 readCommonDataFromMediaInfo(info, newVideo); //set common media infomation
402 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(info, &video))
405 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_recorded_date(video, &tmpStr) )
410 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
411 LogError( "Couldn't convert supplied date.");
413 newVideo->setReleasedDate(result);
415 LogDebug("audio_meta_get_recorded_date : " << tmpStr);
421 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_album(video, &tmpStr) )
425 newVideo->setVideoAlbum(tmpStr);
426 LogDebug(" Video Album. " << tmpStr);
432 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_title(video, &tmpStr) )
436 newVideo->setDisplayName(tmpStr);
437 LogDebug(" Video Title. " << tmpStr);
443 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_artist(video, &tmpStr) )
447 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
448 for( unsigned int i=0; i < artists.size(); i++)
450 string artist = artists.at(i);
451 LogDebug("Audio artist: " << artist);
452 newVideo->appendVideoArtist(artist);
460 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_played_position(video, &tmpInt) )
462 newVideo->setVideoPlayedTime(tmpInt);
463 LogDebug(" Video PlayedTime. " << tmpInt);
466 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_played_count(video, &tmpInt) )
468 newVideo->setVideoPlayCount(tmpInt);
469 LogDebug(" Video PlayedCount. " << tmpInt);
472 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
474 newVideo->setVideoLongitude(tmpDouble);
477 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
479 newVideo->setVideoLatitude(tmpDouble);
482 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_width(video, &tmpInt) )
484 newVideo->setVideoWidth(tmpInt);
487 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_height(video, &tmpInt) )
489 newVideo->setVideoHeight(tmpInt);
492 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_duration(video, &tmpInt) )
494 newVideo->setVideoDuration(tmpInt);
497 if ( METADATA_EXTRACTOR_ERROR_NONE != video_meta_destroy(video))
499 LogDebug(" video_meta_destroy is fail... ");
505 LogDebug("fetch Video info fail...");
510 LogDebug("media info is NULL");
515 void Mediacontent::readMusicFromMediaInfo( media_info_h info, MediacontentAudio* newAudio)
519 unsigned long long tmpLongLong = 0;
523 newAudio->setMediaType("AUDIO");
525 readCommonDataFromMediaInfo(info, newAudio); //set common media infomation
529 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(info, &audio))
531 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_recorded_date(audio, &tmpStr) )
536 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
537 LogError( "Couldn't convert supplied date.");
539 newAudio->setReleasedDate(result);
541 LogDebug("audio_meta_get_recorded_date : " << tmpStr);
547 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_title(audio, &tmpStr) )
551 newAudio->setDisplayName(tmpStr);
552 LogDebug("Audio Title : " << tmpStr);
558 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_album(audio, &tmpStr) )
562 newAudio->setAudioAlbum(tmpStr);
563 LogDebug("Audio Album : " << tmpStr);
569 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_artist(audio, &tmpStr) )
573 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
574 for( unsigned int i=0; i < artists.size(); i++)
576 string artist = artists.at(i);
577 LogDebug("Audio artist: " << artist);
578 newAudio->appendAudioArtist(artist);
586 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_played_position (audio, &tmpInt) )
588 newAudio->setAudioPlayedTime(tmpInt);
589 LogDebug("Audio Played Time : " << tmpInt);
592 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_played_count(audio, &tmpInt) )
594 newAudio->setAudioPlayCount(tmpInt);
595 LogDebug("Audio Played Count : " << tmpInt);
598 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_composer(audio, &tmpStr) )
602 std::vector<std::string> composers = String::split(tmpStr, TAG_DELIMETER);
603 for( unsigned int i=0; i < composers.size(); i++)
605 string composer = composers.at(i);
606 LogDebug("Audio Composer : " << composer);
607 newAudio->appendAudioComposer(composer);
615 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_duration(audio, &tmpInt) )
617 newAudio->setAudioDuration(tmpInt);
618 LogDebug("Audio Duration : " << tmpInt);
621 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_copyright(audio, &tmpStr) )
625 newAudio->setAudioCopyright(tmpStr);
626 LogDebug("Audio CopyRight: " << tmpStr);
632 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_track_num(audio, &tmpStr) )
637 LogDebug("trackNum: " << tmpStr);
639 istringstream(tmpStr) >> trackNum;
641 LogDebug("Track Number type is wrong. (track number:" << tmpStr << ")");
645 newAudio->setAudioTrackNum(trackNum);
651 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
654 newAudio->setAudioSize(tmpLongLong);
655 LogDebug("Audio Size: " << tmpLongLong);
658 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_bit_rate(audio, &tmpInt) )
661 newAudio->setAudioBitrate(tmpInt);
662 LogDebug("Audio Bitrate: " << tmpInt);
665 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_genre(audio, &tmpStr) )
670 std::vector<std::string> genres = String::split(tmpStr, TAG_DELIMETER);
672 for( unsigned int i=0; i < genres.size(); i++)
674 string genre = genres.at(i);
675 LogDebug("Audio Genre: " << genre);
676 newAudio->appendAudioGenre(genre);
684 if ( METADATA_EXTRACTOR_ERROR_NONE != audio_meta_destroy(audio))
686 LogDebug(" audio_meta_destroy is fail... ");
693 LogDebug("fetch Music Info fail...");
700 LogDebug("media info is NULL");
707 bool Mediacontent::mediaFolderCallback(media_folder_h folder, void *user_data)
710 if (user_data != NULL){
711 IEventFindFolder* event = (IEventFindFolder*)user_data;
712 LogDebug("user data is valide");
715 LogDebug("folder is valide");
716 MediacontentFolderPtr newFolder(new MediacontentFolder());
717 convertToPlatformFolder(folder, newFolder);
718 LogDebug("folder type" << newFolder->getFolderStorageType());
720 event->addFolder(newFolder);
725 LogDebug("user data is NULL");
732 bool Mediacontent::mediaItemCallback(media_info_h info, void* user_data)
734 if (user_data != NULL){
735 IEventBrowseFolder* event = (IEventBrowseFolder*)user_data;
737 media_content_type_e type;
739 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_type( info, &type) )
741 if ( type == MEDIA_CONTENT_TYPE_IMAGE)
743 MediacontentImage *newImage(new MediacontentImage());
744 readImageFromMediaInfo(info, newImage);
745 event->addMedia(newImage);
747 else if ( type == MEDIA_CONTENT_TYPE_VIDEO)
749 MediacontentVideo *newVideo(new MediacontentVideo());
750 readVideoFromMediaInfo(info, newVideo);
751 event->addMedia(newVideo);
753 else if ( type == MEDIA_CONTENT_TYPE_MUSIC)
755 MediacontentAudio *newVAudio(new MediacontentAudio());
756 readMusicFromMediaInfo(info, newVAudio);
757 event->addMedia(newVAudio);
761 LogDebug("other type");
768 LogDebug("event is NULL");
774 void Mediacontent::OnRequestReceived(const IEventFindFolderPtr &eFolder)
778 if ( MEDIA_CONTENT_ERROR_NONE !=
779 media_folder_foreach_folder_from_db (NULL, mediaFolderCallback, eFolder.Get()))
781 LogError("error ( media_folder_foreach_folder_from_db ) : ");
782 eFolder->setResult(false);
786 eFolder->setResult(true);
793 void Mediacontent::OnRequestReceived(const IEventBrowseFolderPtr &eBrowse)
795 LogDebug("OnRequestReceived::IEventBrowseFolderPtr entered");
797 MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
798 visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
799 int ret = MEDIA_CONTENT_ERROR_NONE;
802 filter_h filter = NULL;
804 if(eBrowse->getFilterIsSet() || eBrowse->getFolderIdIsSet() || eBrowse->getSortModesIsSet()
805 || eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
808 if ( MEDIA_CONTENT_ERROR_NONE == media_filter_create(&filter))
810 if (eBrowse->getFilterIsSet())
813 FilterPtr jsFilter = eBrowse->getFilter();
815 FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
816 bool success = jsFilter->validate(validator);
819 ThrowMsg(PlatformException, "Invalid attirbutes.");
821 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
823 jsFilter->travel(IVisitor);
824 condition = visitor->getResult();
826 LogDebug("execute condition [" << condition << "]");
827 media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT ); //set condition
830 if(eBrowse->getSortModesIsSet())
832 media_content_order_e order;
834 SortModePtr attr = eBrowse->getSortMode();
838 string attriName = attr->getAttributeName();
839 attriName = visitor->getPlatformAttr(attriName);
840 LogDebug("Attribute Name [" << attriName << "]");
842 if (attriName.compare("") != 0)
844 if (attr->getOrder() == Api::Tizen::ASCENDING_SORT_ORDER)
846 order = MEDIA_CONTENT_ORDER_ASC;
850 order = MEDIA_CONTENT_ORDER_DESC;
853 if ( attriName.compare( "MEDIA_TITLE") == 0 )
855 attriName.append(", MEDIA_DISPLAY_NAME");
857 if ( MEDIA_CONTENT_ERROR_NONE !=
858 media_filter_set_order(filter, order, attriName.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT )) //set order
860 LogDebug("media_filter_set_order fail...");
867 if (eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
869 LogDebug("limit or offset");
874 if ( eBrowse->getLimitIsSet() )
876 count = eBrowse->getLimit();
877 LogDebug("limit is " << count);
880 if ( eBrowse->getOffsetIsSet() )
882 offset = eBrowse->getOffset();
883 LogDebug("offset is " << offset);
886 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_set_offset(filter, offset, count))
888 LogDebug("set limit or offset fail...");
896 LogError("error ( media filter create ) : ");
897 eBrowse->setResult(false);
901 if ( eBrowse->getFolderIdIsSet())
903 string folderID = eBrowse->getFolderID();
904 LogDebug("FolderID :" << folderID);
906 if ( MEDIA_CONTENT_ERROR_NONE !=
907 media_folder_foreach_media_from_db (folderID.c_str(), filter, mediaItemCallback, eBrowse.Get()))
909 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
910 eBrowse->setResult(false);
914 eBrowse->setResult(true);
919 if ( MEDIA_CONTENT_ERROR_NONE !=
920 media_info_foreach_media_from_db (filter, mediaItemCallback, eBrowse.Get()))
922 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
923 eBrowse->setResult(false);
927 eBrowse->setResult(true);
934 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_destroy(filter))
936 LogError("media_filter_create Error: " << ret);
941 catch(const Exception &ex){
942 LogError("Exception: " << ex.DumpToString());
943 eBrowse->setResult(false);
951 bool Mediacontent::updateMediaToDB(MediacontentMediaPtr mediaPtr)
953 string type = mediaPtr->getMediaType(); //media type.
954 string mediaId = mediaPtr->getMediaUUID();
956 LogDebug("MediaId : " << mediaId);
957 media_info_h media = NULL;
961 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_from_db(mediaId.c_str(), &media))
963 if ( mediaPtr->isChangedRating()
964 || mediaPtr->isChangedDisplayName()
965 || mediaPtr->isChangedDescription() )
968 if ( mediaPtr->isChangedRating())
970 if ( MEDIA_CONTENT_ERROR_NONE
971 != media_info_set_rating(media, mediaPtr->getRating()))
973 LogDebug("Error: set rating");
976 else if ( mediaPtr->isChangedDisplayName() )
978 if ( MEDIA_CONTENT_ERROR_NONE
979 != media_info_set_description (media, mediaPtr->getDescription().c_str()))
981 LogDebug("Error: set description");
986 if ( MEDIA_CONTENT_ERROR_NONE
987 != media_info_set_display_name (media, mediaPtr->getDisplayName().c_str()))
989 LogDebug("Error: set displayname");
996 if(type.compare("IMAGE") ==0 )
998 MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
1000 if(imagePtr && (imagePtr->isChangedOrientaion()
1001 || imagePtr->isChangedLatitude() || imagePtr->isChangedLongitude()))
1003 image_meta_h img=NULL;
1004 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img))
1006 if(imagePtr->isChangedOrientaion())
1008 if ( MEDIA_CONTENT_ERROR_NONE !=
1009 image_meta_set_orientation (img, convertToOrientation(imagePtr->getImageOrientation())))
1011 LogDebug("Error: set orientation");
1016 if ( imagePtr->isChangedLatitude() )
1018 if ( MEDIA_CONTENT_ERROR_NONE !=
1019 media_info_set_latitude(media, imagePtr->getImageLatitude())
1022 LogDebug("Error: set Latitude");
1026 if ( imagePtr->isChangedLongitude() )
1028 if ( MEDIA_CONTENT_ERROR_NONE !=
1029 media_info_set_longitude(media, imagePtr->getImageLongitude())
1032 LogDebug("Error: set Latitude");
1037 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_update_to_db (img) )
1039 LogDebug("Error: update db");
1043 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_destroy(img))
1045 LogDebug("Error: destroy media info");
1054 LogDebug("Error: get Image from DB");
1061 if(type.compare("VIDEO") ==0 )
1063 MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
1064 if (videoPtr && ( videoPtr->isChangedPlayCount () || videoPtr->isChangedPlayedTime ()
1065 ||videoPtr->isChangedArtists () || videoPtr->isChangedAlbum()
1066 || videoPtr->isChangedLatitude() ||videoPtr->isChangedLongitude()) )
1069 video_meta_h video = NULL;
1070 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(media, &video))
1072 if ( videoPtr->isChangedPlayCount() )
1074 if ( MEDIA_CONTENT_ERROR_NONE !=
1075 video_meta_set_played_count (video, videoPtr->getVideoPlayCount()))
1077 LogDebug("Error: set play count");
1083 if (videoPtr->isChangedPlayedTime())
1085 if ( MEDIA_CONTENT_ERROR_NONE !=
1086 video_meta_set_played_position (video, videoPtr->getVideoPlayedTime()))
1088 LogDebug("Error: set played time");
1093 if (videoPtr->isChangedAlbum())
1095 LogDebug("Not support - Album API");
1099 if (videoPtr->isChangedArtists())
1101 LogDebug("Not support - Artist API");
1105 if ( videoPtr->isChangedLatitude() )
1107 if ( MEDIA_CONTENT_ERROR_NONE !=
1108 media_info_set_latitude(media, videoPtr->getVideoLatitude())
1111 LogDebug("Error: set Latitude");
1115 if ( videoPtr->isChangedLongitude() )
1117 if ( MEDIA_CONTENT_ERROR_NONE !=
1118 media_info_set_longitude(media, videoPtr->getVideoLongitude())
1121 LogDebug("Error: set Latitude");
1126 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_update_to_db (video) )
1128 LogDebug("Error: update db");
1132 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_destroy(video))
1134 LogDebug("Error: destroy video meta");
1147 if(type.compare("AUDIO") ==0 )
1150 MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
1151 if (audioPtr && ( audioPtr->isChangedPlayCount () || audioPtr->isChangedPlayedTime ()
1152 ||audioPtr->isChangedAudioArtist () || audioPtr->isChangedAudioAlbum()
1153 || audioPtr->isChangedAudioGenre() ||audioPtr->isChangedAudioComposer()
1154 || audioPtr->isChangedAudioTrackNumber()) )
1157 audio_meta_h audio=NULL;
1158 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(media, &audio))
1160 if ( audioPtr->isChangedPlayCount() )
1162 if ( MEDIA_CONTENT_ERROR_NONE !=
1163 audio_meta_set_played_count (audio, audioPtr->getAudioPlayCount()))
1165 LogDebug("Error: set play count");
1170 if (audioPtr->isChangedPlayedTime())
1172 if ( MEDIA_CONTENT_ERROR_NONE !=
1173 audio_meta_set_played_position (audio, audioPtr->getAudioPlayedTime()))
1175 LogDebug("Error: set played time");
1180 if (audioPtr->isChangedAudioArtist())
1182 LogDebug("Not Support API");
1186 if (audioPtr->isChangedAudioAlbum())
1188 LogDebug("Not Support API");
1192 if (audioPtr->isChangedAudioGenre())
1194 LogDebug("Not Support API");
1198 if (audioPtr->isChangedAudioComposer())
1200 LogDebug("Not Support API");
1204 if (audioPtr->isChangedAudioTrackNumber())
1206 LogDebug("Not Support API");
1210 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_update_to_db (audio) )
1212 LogDebug("Error: update db");
1216 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_destroy(audio))
1218 LogDebug("Error: destroy audio meta");
1230 if ( MEDIA_CONTENT_ERROR_NONE != media_info_update_to_db(media))
1232 LogDebug("Error: update to DB");
1236 if ( MEDIA_CONTENT_ERROR_NONE !=media_info_destroy(media))
1238 LogDebug("Error: destroy media info");
1248 void Mediacontent::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
1250 LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered");
1253 MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
1255 if(updateMediaToDB(mediaPtr))
1257 eMedia->setResult(true);
1258 LogDebug("update success");
1262 eMedia->setResult(false);
1263 ThrowMsg(PlatformException, "DB operation is failed");
1266 catch (const Exception &ex)
1268 LogError("Exception: " << ex.DumpToString());
1269 eMedia->setResult(false);
1274 void Mediacontent::OnRequestReceived(const IEventUpdateMediaItemsPtr &eItems)
1276 LogDebug("OnRequestReceived::IEventUpdateMediaItemsPtr entered");
1280 MediacontentMediaListPtr mediaListPtr = eItems->getMediaItems();
1281 if (mediaListPtr->empty())
1283 LogDebug("Item vector is empty");
1287 for(unsigned int i=0; i<mediaListPtr->size(); i++)
1290 MediacontentMediaPtr mediaPtr = mediaListPtr->at(i);
1291 if(updateMediaToDB(mediaPtr))
1293 eItems->setResult(true);
1294 LogDebug("update success");
1298 eItems->setResult(false);
1299 ThrowMsg(PlatformException, "DB operation is failed");
1305 catch (const Exception &ex)
1307 LogError("Exception: " << ex.DumpToString());
1308 eItems->setResult(false);
1310 //eItems->setCancelAllowed(false);