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 ( MEDIA_CONTENT_ERROR_NONE == media_info_get_display_name(info, &tmpStr) )
205 newMedia->setDisplayName(tmpStr);
206 LogDebug("Display Name : " << tmpStr);
212 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_file_path(info, &tmpStr) )
216 newMedia->setFilePath(tmpStr);
217 LogDebug("Path : " << tmpStr);
223 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_thumbnail_path (info, &tmpStr) )
227 newMedia->setThumbnailPath(tmpStr);
228 LogDebug("Thumnail Path : " << tmpStr);
234 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_description(info, &tmpStr) )
238 newMedia->setDescription(tmpStr);
239 LogDebug("Desc : " << tmpStr);
245 //newImage->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
246 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_modified_time (info, &tmpDate) )
248 newMedia->setModifiedDate(Mediacontent::toDateTm(tmpDate));
251 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_favorite (info, &tmpBool) )
253 newMedia->setFavorite(tmpBool);
254 LogDebug("favorite " << tmpBool);
257 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_rating (info, &tmpInt) )
259 newMedia->setRating(tmpInt);
260 LogDebug("rating " << tmpInt);
263 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
265 newMedia->setSize(tmpLongLong);
266 LogDebug("Size : " << tmpLongLong);
271 void Mediacontent::readImageFromMediaInfo( media_info_h info, MediacontentImage* newImage)
279 newImage->setMediaType("IMAGE");
281 readCommonDataFromMediaInfo(info, newImage);
285 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(info, &img))
288 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_date_taken (img, &tmpStr) )
293 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
294 LogError( "Couldn't convert supplied date.");
297 LogDebug("image_meta_get_date_taken : " << tmpStr); //time??
298 newImage->setReleasedDate(result);
304 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_width(img, &tmpInt) )
306 newImage->setImageWidth(tmpInt);
307 LogDebug("Image Width " << tmpInt);
310 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_height(img, &tmpInt) )
312 newImage->setImageHeight(tmpInt);
313 LogDebug("Image Height " << tmpInt);
316 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
318 newImage->setImageLatitude(tmpDouble);
319 LogDebug("Image Latitude " << tmpDouble);
322 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
324 newImage->setImageLongitude(tmpDouble);
325 LogDebug("Image Longitude " << tmpDouble);
328 media_content_orientation_e orientation;
330 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_orientation(img, &orientation) )
333 string orientationStr;
338 orientationStr = "NORMAL";
341 orientationStr = "FLIP_HORIZONTAL";
344 orientationStr = "ROTATE_180";
347 orientationStr = "FLIP_VERTICAL";
350 orientationStr = "TRANSPOSE";
353 orientationStr = "ROTATE_90";
356 orientationStr = "TRANSVERSE";
359 orientationStr = "ROTATE_270";
363 newImage->setImageOrientation(orientationStr);
364 LogDebug(" image Orientation. " << orientationStr);
369 if ( METADATA_EXTRACTOR_ERROR_NONE != image_meta_destroy(img))
371 LogDebug(" image_meta_destroy is fail... ");
376 LogDebug("fetch Image Info failed..");
382 LogDebug("media info is NULL");
386 void Mediacontent::readVideoFromMediaInfo( media_info_h info, MediacontentVideo* newVideo)
395 newVideo->setMediaType("VIDEO");
397 readCommonDataFromMediaInfo(info, newVideo); //set common media infomation
401 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(info, &video))
404 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_recorded_date(video, &tmpStr) )
409 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
410 LogError( "Couldn't convert supplied date.");
412 newVideo->setReleasedDate(result);
414 LogDebug("audio_meta_get_recorded_date : " << tmpStr);
420 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_album(video, &tmpStr) )
424 newVideo->setVideoAlbum(tmpStr);
425 LogDebug(" Video Album. " << tmpStr);
431 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_artist(video, &tmpStr) )
435 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
436 for( unsigned int i=0; i < artists.size(); i++)
438 string artist = artists.at(i);
439 LogDebug("Audio artist: " << artist);
440 newVideo->appendVideoArtist(artist);
448 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_played_position(video, &tmpInt) )
450 newVideo->setVideoPlayedTime(tmpInt);
451 LogDebug(" Video PlayedTime. " << tmpInt);
454 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_played_count(video, &tmpInt) )
456 newVideo->setVideoPlayCount(tmpInt);
457 LogDebug(" Video PlayedCount. " << tmpInt);
460 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
462 newVideo->setVideoLongitude(tmpDouble);
465 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
467 newVideo->setVideoLatitude(tmpDouble);
470 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_width(video, &tmpInt) )
472 newVideo->setVideoWidth(tmpInt);
475 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_height(video, &tmpInt) )
477 newVideo->setVideoHeight(tmpInt);
480 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_duration(video, &tmpInt) )
482 newVideo->setVideoDuration(tmpInt);
485 if ( METADATA_EXTRACTOR_ERROR_NONE != video_meta_destroy(video))
487 LogDebug(" video_meta_destroy is fail... ");
493 LogDebug("fetch Video info fail...");
498 LogDebug("media info is NULL");
503 void Mediacontent::readMusicFromMediaInfo( media_info_h info, MediacontentAudio* newAudio)
507 unsigned long long tmpLongLong = 0;
511 newAudio->setMediaType("AUDIO");
513 readCommonDataFromMediaInfo(info, newAudio); //set common media infomation
517 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(info, &audio))
519 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_recorded_date(audio, &tmpStr) )
524 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
525 LogError( "Couldn't convert supplied date.");
527 newAudio->setReleasedDate(result);
529 LogDebug("audio_meta_get_recorded_date : " << tmpStr);
535 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_album(audio, &tmpStr) )
539 newAudio->setAudioAlbum(tmpStr);
540 LogDebug("Audio Album : " << tmpStr);
546 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_artist(audio, &tmpStr) )
550 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
551 for( unsigned int i=0; i < artists.size(); i++)
553 string artist = artists.at(i);
554 LogDebug("Audio artist: " << artist);
555 newAudio->appendAudioArtist(artist);
563 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_played_position (audio, &tmpInt) )
565 newAudio->setAudioPlayedTime(tmpInt);
566 LogDebug("Audio Played Time : " << tmpInt);
569 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_played_count(audio, &tmpInt) )
571 newAudio->setAudioPlayCount(tmpInt);
572 LogDebug("Audio Played Count : " << tmpInt);
575 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_composer(audio, &tmpStr) )
579 std::vector<std::string> composers = String::split(tmpStr, TAG_DELIMETER);
580 for( unsigned int i=0; i < composers.size(); i++)
582 string composer = composers.at(i);
583 LogDebug("Audio Composer : " << composer);
584 newAudio->appendAudioComposer(composer);
592 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_duration(audio, &tmpInt) )
594 newAudio->setAudioDuration(tmpInt);
595 LogDebug("Audio Duration : " << tmpInt);
598 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_copyright(audio, &tmpStr) )
602 newAudio->setAudioCopyright(tmpStr);
603 LogDebug("Audio CopyRight: " << tmpStr);
609 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_track_num(audio, &tmpStr) )
614 LogDebug("trackNum: " << tmpStr);
616 istringstream(tmpStr) >> trackNum;
618 LogDebug("Track Number type is wrong. (track number:" << tmpStr << ")");
622 newAudio->setAudioTrackNum(trackNum);
628 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
631 newAudio->setAudioSize(tmpLongLong);
632 LogDebug("Audio Size: " << tmpLongLong);
635 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_bit_rate(audio, &tmpInt) )
638 newAudio->setAudioBitrate(tmpInt);
639 LogDebug("Audio Bitrate: " << tmpInt);
642 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_genre(audio, &tmpStr) )
647 std::vector<std::string> genres = String::split(tmpStr, TAG_DELIMETER);
649 for( unsigned int i=0; i < genres.size(); i++)
651 string genre = genres.at(i);
652 LogDebug("Audio Genre: " << genre);
653 newAudio->appendAudioGenre(genre);
661 if ( METADATA_EXTRACTOR_ERROR_NONE != audio_meta_destroy(audio))
663 LogDebug(" audio_meta_destroy is fail... ");
670 LogDebug("fetch Music Info fail...");
677 LogDebug("media info is NULL");
684 bool Mediacontent::mediaFolderCallback(media_folder_h folder, void *user_data)
687 if (user_data != NULL){
688 IEventFindFolder* event = (IEventFindFolder*)user_data;
689 LogDebug("user data is valide");
692 LogDebug("folder is valide");
693 MediacontentFolderPtr newFolder(new MediacontentFolder());
694 convertToPlatformFolder(folder, newFolder);
695 LogDebug("folder type" << newFolder->getFolderStorageType());
697 event->addFolder(newFolder);
702 LogDebug("user data is NULL");
709 bool Mediacontent::mediaItemCallback(media_info_h info, void* user_data)
711 if (user_data != NULL){
712 IEventBrowseFolder* event = (IEventBrowseFolder*)user_data;
714 media_content_type_e type;
716 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_type( info, &type) )
718 if ( type == MEDIA_CONTENT_TYPE_IMAGE)
720 MediacontentImage *newImage(new MediacontentImage());
721 readImageFromMediaInfo(info, newImage);
722 event->addMedia(newImage);
724 else if ( type == MEDIA_CONTENT_TYPE_VIDEO)
726 MediacontentVideo *newVideo(new MediacontentVideo());
727 readVideoFromMediaInfo(info, newVideo);
728 event->addMedia(newVideo);
730 else if ( type == MEDIA_CONTENT_TYPE_MUSIC)
732 MediacontentAudio *newVAudio(new MediacontentAudio());
733 readMusicFromMediaInfo(info, newVAudio);
734 event->addMedia(newVAudio);
738 LogDebug("other type");
745 LogDebug("event is NULL");
751 void Mediacontent::OnRequestReceived(const IEventFindFolderPtr &eFolder)
755 if ( MEDIA_CONTENT_ERROR_NONE !=
756 media_folder_foreach_folder_from_db (NULL, mediaFolderCallback, eFolder.Get()))
758 LogError("error ( media_folder_foreach_folder_from_db ) : ");
759 eFolder->setResult(false);
763 eFolder->setResult(true);
770 void Mediacontent::OnRequestReceived(const IEventBrowseFolderPtr &eBrowse)
772 LogDebug("OnRequestReceived::IEventBrowseFolderPtr entered");
774 MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
775 visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
776 int ret = MEDIA_CONTENT_ERROR_NONE;
779 filter_h filter = NULL;
781 if(eBrowse->getFilterIsSet() || eBrowse->getFolderIdIsSet() || eBrowse->getSortModesIsSet()
782 || eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
785 if ( MEDIA_CONTENT_ERROR_NONE == media_filter_create(&filter))
787 if (eBrowse->getFilterIsSet())
790 FilterPtr jsFilter = eBrowse->getFilter();
792 FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
793 bool success = jsFilter->validate(validator);
796 ThrowMsg(PlatformException, "Invalid attirbutes.");
798 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
800 jsFilter->travel(IVisitor);
801 condition = visitor->getResult();
803 LogDebug("execute condition [" << condition << "]");
804 media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT ); //set condition
807 if(eBrowse->getSortModesIsSet())
809 media_content_order_e order;
811 SortModePtr attr = eBrowse->getSortMode();
815 string attriName = attr->getAttributeName();
816 attriName = visitor->getPlatformAttr(attriName);
817 LogDebug("Attribute Name [" << attriName << "]");
819 if (attriName.compare("") != 0)
821 if (attr->getOrder() == Api::Tizen::ASCENDING_SORT_ORDER)
823 order = MEDIA_CONTENT_ORDER_ASC;
827 order = MEDIA_CONTENT_ORDER_DESC;
830 if ( attriName.compare( "MEDIA_TITLE") == 0 )
832 attriName.append(", MEDIA_DISPLAY_NAME");
834 if ( MEDIA_CONTENT_ERROR_NONE !=
835 media_filter_set_order(filter, order, attriName.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT )) //set order
837 LogDebug("media_filter_set_order fail...");
844 if (eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
846 LogDebug("limit or offset");
851 if ( eBrowse->getLimitIsSet() )
853 count = eBrowse->getLimit();
854 LogDebug("limit is " << count);
857 if ( eBrowse->getOffsetIsSet() )
859 offset = eBrowse->getOffset();
860 LogDebug("offset is " << offset);
863 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_set_offset(filter, offset, count))
865 LogDebug("set limit or offset fail...");
873 LogError("error ( media filter create ) : ");
874 eBrowse->setResult(false);
878 if ( eBrowse->getFolderIdIsSet())
880 string folderID = eBrowse->getFolderID();
881 LogDebug("FolderID :" << folderID);
883 if ( MEDIA_CONTENT_ERROR_NONE !=
884 media_folder_foreach_media_from_db (folderID.c_str(), filter, mediaItemCallback, eBrowse.Get()))
886 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
887 eBrowse->setResult(false);
891 eBrowse->setResult(true);
896 if ( MEDIA_CONTENT_ERROR_NONE !=
897 media_info_foreach_media_from_db (filter, mediaItemCallback, eBrowse.Get()))
899 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
900 eBrowse->setResult(false);
904 eBrowse->setResult(true);
911 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_destroy(filter))
913 LogError("media_filter_create Error: " << ret);
918 catch(const Exception &ex){
919 LogError("Exception: " << ex.DumpToString());
920 eBrowse->setResult(false);
928 bool Mediacontent::updateMediaToDB(MediacontentMediaPtr mediaPtr)
930 string type = mediaPtr->getMediaType(); //media type.
931 string mediaId = mediaPtr->getMediaUUID();
933 LogDebug("MediaId : " << mediaId);
934 media_info_h media = NULL;
938 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_from_db(mediaId.c_str(), &media))
940 if ( mediaPtr->isChangedRating()
941 || mediaPtr->isChangedDisplayName()
942 || mediaPtr->isChangedDescription() )
945 if ( mediaPtr->isChangedRating())
947 if ( MEDIA_CONTENT_ERROR_NONE
948 != media_info_set_rating(media, mediaPtr->getRating()))
950 LogDebug("Error: set rating");
953 else if ( mediaPtr->isChangedDisplayName() )
955 if ( MEDIA_CONTENT_ERROR_NONE
956 != media_info_set_description (media, mediaPtr->getDescription().c_str()))
958 LogDebug("Error: set description");
963 if ( MEDIA_CONTENT_ERROR_NONE
964 != media_info_set_display_name (media, mediaPtr->getDisplayName().c_str()))
966 LogDebug("Error: set displayname");
973 if(type.compare("IMAGE") ==0 )
975 MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
977 if(imagePtr && (imagePtr->isChangedOrientaion()
978 || imagePtr->isChangedLatitude() || imagePtr->isChangedLongitude()))
980 image_meta_h img=NULL;
981 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img))
983 if(imagePtr->isChangedOrientaion())
985 if ( MEDIA_CONTENT_ERROR_NONE !=
986 image_meta_set_orientation (img, convertToOrientation(imagePtr->getImageOrientation())))
988 LogDebug("Error: set orientation");
993 if ( imagePtr->isChangedLatitude() )
995 if ( MEDIA_CONTENT_ERROR_NONE !=
996 media_info_set_latitude(media, imagePtr->getImageLatitude())
999 LogDebug("Error: set Latitude");
1003 if ( imagePtr->isChangedLongitude() )
1005 if ( MEDIA_CONTENT_ERROR_NONE !=
1006 media_info_set_longitude(media, imagePtr->getImageLongitude())
1009 LogDebug("Error: set Latitude");
1014 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_update_to_db (img) )
1016 LogDebug("Error: update db");
1020 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_destroy(img))
1022 LogDebug("Error: destroy media info");
1031 LogDebug("Error: get Image from DB");
1038 if(type.compare("VIDEO") ==0 )
1040 MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
1041 if (videoPtr && ( videoPtr->isChangedPlayCount () || videoPtr->isChangedPlayedTime ()
1042 ||videoPtr->isChangedArtists () || videoPtr->isChangedAlbum()
1043 || videoPtr->isChangedLatitude() ||videoPtr->isChangedLongitude()) )
1046 video_meta_h video = NULL;
1047 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(media, &video))
1049 if ( videoPtr->isChangedPlayCount() )
1051 if ( MEDIA_CONTENT_ERROR_NONE !=
1052 video_meta_set_played_count (video, videoPtr->getVideoPlayCount()))
1054 LogDebug("Error: set play count");
1060 if (videoPtr->isChangedPlayedTime())
1062 if ( MEDIA_CONTENT_ERROR_NONE !=
1063 video_meta_set_played_position (video, videoPtr->getVideoPlayedTime()))
1065 LogDebug("Error: set played time");
1070 if (videoPtr->isChangedAlbum())
1072 LogDebug("Not support - Album API");
1076 if (videoPtr->isChangedArtists())
1078 LogDebug("Not support - Artist API");
1082 if ( videoPtr->isChangedLatitude() )
1084 if ( MEDIA_CONTENT_ERROR_NONE !=
1085 media_info_set_latitude(media, videoPtr->getVideoLatitude())
1088 LogDebug("Error: set Latitude");
1092 if ( videoPtr->isChangedLongitude() )
1094 if ( MEDIA_CONTENT_ERROR_NONE !=
1095 media_info_set_longitude(media, videoPtr->getVideoLongitude())
1098 LogDebug("Error: set Latitude");
1103 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_update_to_db (video) )
1105 LogDebug("Error: update db");
1109 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_destroy(video))
1111 LogDebug("Error: destroy video meta");
1124 if(type.compare("AUDIO") ==0 )
1127 MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
1128 if (audioPtr && ( audioPtr->isChangedPlayCount () || audioPtr->isChangedPlayedTime ()
1129 ||audioPtr->isChangedAudioArtist () || audioPtr->isChangedAudioAlbum()
1130 || audioPtr->isChangedAudioGenre() ||audioPtr->isChangedAudioComposer()
1131 || audioPtr->isChangedAudioTrackNumber()) )
1134 audio_meta_h audio=NULL;
1135 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(media, &audio))
1137 if ( audioPtr->isChangedPlayCount() )
1139 if ( MEDIA_CONTENT_ERROR_NONE !=
1140 audio_meta_set_played_count (audio, audioPtr->getAudioPlayCount()))
1142 LogDebug("Error: set play count");
1147 if (audioPtr->isChangedPlayedTime())
1149 if ( MEDIA_CONTENT_ERROR_NONE !=
1150 audio_meta_set_played_position (audio, audioPtr->getAudioPlayedTime()))
1152 LogDebug("Error: set played time");
1157 if (audioPtr->isChangedAudioArtist())
1159 LogDebug("Not Support API");
1163 if (audioPtr->isChangedAudioAlbum())
1165 LogDebug("Not Support API");
1169 if (audioPtr->isChangedAudioGenre())
1171 LogDebug("Not Support API");
1175 if (audioPtr->isChangedAudioComposer())
1177 LogDebug("Not Support API");
1181 if (audioPtr->isChangedAudioTrackNumber())
1183 LogDebug("Not Support API");
1187 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_update_to_db (audio) )
1189 LogDebug("Error: update db");
1193 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_destroy(audio))
1195 LogDebug("Error: destroy audio meta");
1207 if ( MEDIA_CONTENT_ERROR_NONE != media_info_update_to_db(media))
1209 LogDebug("Error: update to DB");
1213 if ( MEDIA_CONTENT_ERROR_NONE !=media_info_destroy(media))
1215 LogDebug("Error: destroy media info");
1225 void Mediacontent::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
1227 LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered");
1230 MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
1232 if(updateMediaToDB(mediaPtr))
1234 eMedia->setResult(true);
1235 LogDebug("update success");
1239 eMedia->setResult(false);
1240 ThrowMsg(PlatformException, "DB operation is failed");
1243 catch (const Exception &ex)
1245 LogError("Exception: " << ex.DumpToString());
1246 eMedia->setResult(false);
1251 void Mediacontent::OnRequestReceived(const IEventUpdateMediaItemsPtr &eItems)
1253 LogDebug("OnRequestReceived::IEventUpdateMediaItemsPtr entered");
1257 MediacontentMediaListPtr mediaListPtr = eItems->getMediaItems();
1258 if (mediaListPtr->empty())
1260 LogDebug("Item vector is empty");
1264 for(unsigned int i=0; i<mediaListPtr->size(); i++)
1267 MediacontentMediaPtr mediaPtr = mediaListPtr->at(i);
1268 if(updateMediaToDB(mediaPtr))
1270 eItems->setResult(true);
1271 LogDebug("update success");
1275 eItems->setResult(false);
1276 ThrowMsg(PlatformException, "DB operation is failed");
1282 catch (const Exception &ex)
1284 LogError("Exception: " << ex.DumpToString());
1285 eItems->setResult(false);
1287 //eItems->setCancelAllowed(false);