From 84b9f4b17fe1bc5e2269c2c4797fac85035a4f77 Mon Sep 17 00:00:00 2001 From: Jehun Lim Date: Mon, 11 May 2015 13:13:23 +0900 Subject: [PATCH] update media info in db update callback function Change-Id: If25d5d4da514ff852dd5ecf96c903ef5702eb7ff Signed-off-by: Jehun Lim --- include/data/imageinfo.h | 11 ++- include/data/mediadata.h | 8 +- include/data/mediainfo.h | 13 +++- include/data/videoinfo.h | 9 ++- src/data/imageinfo.cpp | 59 ++++++++++++-- src/data/mediadata.cpp | 194 +++++++++++++++++------------------------------ src/data/mediainfo.cpp | 110 +++++++++++++++++++++++++-- src/data/videoinfo.cpp | 47 +++++++++++- 8 files changed, 299 insertions(+), 152 deletions(-) diff --git a/include/data/imageinfo.h b/include/data/imageinfo.h index 33b4492..79274df 100644 --- a/include/data/imageinfo.h +++ b/include/data/imageinfo.h @@ -21,6 +21,11 @@ class CImageInfo : public CMediaInfo { private: struct SImageInfo *m; +private: + bool m_SetWidth(int width); + bool m_SetHeight(int height); + bool m_SetOrientation(int orientation); + public: CImageInfo() : m(0) {}; virtual ~CImageInfo() {}; @@ -28,14 +33,12 @@ public: bool Create(void); void Destroy(void); + bool Update(void); + int Width(void); int Height(void); int Orientation(void); - bool SetWidth(int width); - bool SetHeight(int height); - bool SetOrientation(int orientation); - bool Duplicate(CNameInfo *obj); }; diff --git a/include/data/mediadata.h b/include/data/mediadata.h index 557a909..1eb513f 100644 --- a/include/data/mediadata.h +++ b/include/data/mediadata.h @@ -17,7 +17,7 @@ #ifndef __MEDIADATA_H__ #define __MEDIADATA_H__ -class CMediadata { +class CMediadata : public CMediaContentListener { private: static CMediadata *instance; struct SMediadata *m; @@ -30,8 +30,8 @@ private: static bool sm_CbEachFolderInfo(media_folder_h folder, void *dt); bool m_HandleEachFolderInfo(media_folder_h folder); - bool m_HandleEachImageInfo(media_info_h media_h, CMediaInfo *minfo); - bool m_HandleEachVideoInfo(media_info_h media_h, CMediaInfo *minfo); + static bool sm_CbUpdateImageInfo(media_info_h media_h, void *dt); + bool m_UpdateImageInfo(media_info_h media_h); void m_GetEventList(void); void m_GetMediaList(void); @@ -61,6 +61,8 @@ public: Eina_List *MediaList(void); Eina_List *EventList(void); Eina_List *FolderList(void); + + virtual void OnDbUpdated(const SEntity *entity); }; #endif diff --git a/include/data/mediainfo.h b/include/data/mediainfo.h index 70a3070..08dfd11 100644 --- a/include/data/mediainfo.h +++ b/include/data/mediainfo.h @@ -21,6 +21,11 @@ class CMediaInfo : public CExtNameInfo { private: struct SMediaInfo *m; +private: + bool m_SetLocationTag(const char *location_tag); + bool m_SetCreatedTime(time_t created_time); + bool m_SetSource(int source); + public: CMediaInfo() : m(0) {}; virtual ~CMediaInfo() {}; @@ -28,15 +33,17 @@ public: bool Create(void); virtual void Destroy(void); + bool Update(void); + char *LocationTag(void); time_t CreatedTime(void); time_t Time(void); int Source(void); media_info_h MediaInfo(void); - bool SetLocationTag(const char *location_tag); - bool SetCreatedTime(time_t created_time); - bool SetSource(int source); + bool GetImageHandle(image_meta_h *image_h); + bool GetVideoHandle(video_meta_h *video_h); + bool SetMediaInfo(media_info_h media_h); bool Duplicate(CNameInfo *obj); diff --git a/include/data/videoinfo.h b/include/data/videoinfo.h index 706678e..fff71d7 100644 --- a/include/data/videoinfo.h +++ b/include/data/videoinfo.h @@ -21,6 +21,10 @@ class CVideoInfo : public CMediaInfo { private: struct SVideoInfo *m; +private: + bool m_SetDuration(int duration); + bool m_SetPlayedPosition(int played_position); + public: CVideoInfo() : m(0) {}; virtual ~CVideoInfo() {}; @@ -28,12 +32,11 @@ public: bool Create(void); virtual void Destroy(void); + bool Update(void); + int Duration(void); int PlayedPosition(void); - bool SetDuration(int duration); - bool SetPlayedPosition(int played_position); - bool Duplicate(CNameInfo *obj); }; diff --git a/src/data/imageinfo.cpp b/src/data/imageinfo.cpp index 1936bb1..e9ef6cd 100644 --- a/src/data/imageinfo.cpp +++ b/src/data/imageinfo.cpp @@ -57,6 +57,53 @@ void CImageInfo::Destroy(void) m = NULL; } +bool CImageInfo::Update(void) +{ + int val; + image_meta_h image_h; + + if (!CMediaInfo::Update()) + return false; + + if (!GetImageHandle(&image_h) || !image_h) { + _ERR("Get image handle failed"); + return false; + } + + if (image_meta_get_width(image_h, &val) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Image meta get width error"); + goto error; + } + m_SetWidth(val); + + if (image_meta_get_height(image_h, &val) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Image meta get height error"); + goto error; + } + m_SetHeight(val); + + if (image_meta_get_orientation(image_h, + (media_content_orientation_e *)&val) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Image meta get orientation error"); + goto error; + } + m_SetOrientation(val); + + if (image_meta_destroy(image_h) != MEDIA_CONTENT_ERROR_NONE) { + _ERR("Image meta destroy error"); + return false; + } + + return true; + +error: + image_meta_destroy(image_h); + return false; +} + int CImageInfo::Width(void) { if (!m) @@ -81,7 +128,7 @@ int CImageInfo::Orientation(void) return m->orientation; } -bool CImageInfo::SetWidth(int width) +bool CImageInfo::m_SetWidth(int width) { if (!m) return false; @@ -91,7 +138,7 @@ bool CImageInfo::SetWidth(int width) return true; } -bool CImageInfo::SetHeight(int height) +bool CImageInfo::m_SetHeight(int height) { if (!m) return false; @@ -101,7 +148,7 @@ bool CImageInfo::SetHeight(int height) return true; } -bool CImageInfo::SetOrientation(int orientation) +bool CImageInfo::m_SetOrientation(int orientation) { if (!m) return false; @@ -121,11 +168,11 @@ bool CImageInfo::Duplicate(CNameInfo *obj) if (!CMediaInfo::Duplicate(obj)) return false; - if (!SetWidth(dst->Width())) + if (!m_SetWidth(dst->Width())) return false; - if (!SetHeight(dst->Height())) + if (!m_SetHeight(dst->Height())) return false; - if (!SetOrientation(dst->Orientation())) + if (!m_SetOrientation(dst->Orientation())) return false; return true; diff --git a/src/data/mediadata.cpp b/src/data/mediadata.cpp index 682d7a4..5dacfd5 100644 --- a/src/data/mediadata.cpp +++ b/src/data/mediadata.cpp @@ -132,6 +132,8 @@ void CMediadata::DestroyMediaList(void) if (m->folder_medialist) m_DeleteMediaList(E_TYPE_FOLDER_MEDIA); + + CMediaContentListener::Destroy(); } bool CMediadata::m_CreateFilter(filter_h *filter, int type) @@ -305,74 +307,42 @@ error: m_DeleteEventList(); } -bool CMediadata::m_HandleEachImageInfo(media_info_h media_h, CMediaInfo *minfo) +bool CMediadata::sm_CbUpdateImageInfo(media_info_h media_h, void *dt) { - int val; - image_meta_h image_h; - - if (media_info_get_image(media_h, &image_h) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media Image Handle Fetch Error"); - return false; - } - - if (image_meta_get_width(image_h, &val) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Image meta get width error"); - return false; - } - ((CImageInfo *)minfo)->SetWidth(val); - - if (image_meta_get_height(image_h, &val) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Image meta get height error"); - return false; - } - ((CImageInfo *)minfo)->SetHeight(val); - - if (image_meta_get_orientation(image_h, - (media_content_orientation_e *)&val) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Image meta get orientation error"); - return false; - } - ((CImageInfo *)minfo)->SetOrientation(val); + CMediadata *root = (CMediadata *)dt; - if (image_meta_destroy(image_h) != MEDIA_CONTENT_ERROR_NONE) { - _ERR("Image meta destroy error"); + if (!root) return false; - } - return true; + return root->m_UpdateImageInfo(media_h); } -bool CMediadata::m_HandleEachVideoInfo(media_info_h media_h, CMediaInfo *minfo) +bool CMediadata::m_UpdateImageInfo(media_info_h media_h) { - int val; - video_meta_h video_h; + Eina_List *l; + CMediaInfo *minfo; + char *buf; + void *obj; - if (media_info_get_video(media_h, &video_h) != - MEDIA_CONTENT_ERROR_NONE || !video_h) { - _ERR("Media video handle fetch error"); + if (media_info_get_file_path(media_h, &buf) + != MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media file path Fetch error"); return false; } - if (video_meta_get_duration(video_h, &val) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("video meta get duration error"); - return false; + minfo = NULL; + EINA_LIST_FOREACH(m->medialist, l, obj) { + minfo = (CMediaInfo *)obj; + + if (!strcmp(minfo->Path(), buf)) + break; } - ((CVideoInfo *)minfo)->SetDuration(val); - if (video_meta_get_played_position(video_h, &val) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("video meta get played position error"); + if (!minfo) return false; - } - ((CVideoInfo *)minfo)->SetPlayedPosition(val); - if (video_meta_destroy(video_h) != MEDIA_CONTENT_ERROR_NONE) { - _ERR("video meta destroy error"); + if (!((CImageInfo *)minfo)->Update()) { + _ERR("Get media info failed"); return false; } @@ -392,9 +362,7 @@ bool CMediadata::sm_CbEachMediaInfo(media_info_h media_h, void *dt) bool CMediadata::m_HandleEachMediaInfo(media_info_h media_h) { CMediaInfo *minfo; - char *buf; int type; - unsigned long long val; minfo = NULL; @@ -413,7 +381,9 @@ bool CMediadata::m_HandleEachMediaInfo(media_info_h media_h) } ((CImageInfo *)minfo)->Create(); - if (!m_HandleEachImageInfo(media_h, minfo)) + minfo->SetMediaInfo(media_h); + + if (!((CImageInfo *)minfo)->Update()) goto error; } else if (type == MEDIA_CONTENT_TYPE_VIDEO) { minfo = new CVideoInfo; @@ -423,78 +393,14 @@ bool CMediadata::m_HandleEachMediaInfo(media_info_h media_h) } ((CVideoInfo *)minfo)->Create(); - if (!m_HandleEachVideoInfo(media_h, minfo)) + minfo->SetMediaInfo(media_h); + + if (!((CVideoInfo *)minfo)->Update()) goto error; } minfo->SetType(type); - if (media_info_get_media_id(media_h, &buf) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media ID Fetch error"); - goto error; - } - minfo->SetId(buf); - - if (media_info_get_display_name(media_h, &buf) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media display nam))e Fetch error"); - goto error; - } - minfo->SetName(buf); - - if (media_info_get_size(media_h, &val) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media size Fetch error"); - goto error; - } - minfo->SetSize(val); - - if (media_info_get_file_path(media_h, &buf) - != MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media file path Fetch error"); - goto error; - } - minfo->SetPath(buf); - - if (media_info_get_thumbnail_path(media_h, &buf) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media thumbnail path Fetch error"); - goto error; - } - minfo->SetThumbnailPath(buf); - - if (media_info_get_modified_time(media_h, (time_t *)&val) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media modified time Fetch error"); - goto error; - } - minfo->SetModifiedTime(val); - - if (media_info_get_modified_time(media_h, (time_t *)&val) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media created time Fetch error"); - goto error; - } - minfo->SetCreatedTime(val); - - if (media_info_get_location_tag(media_h, &buf) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media location tag Fetch error"); - goto error; - } - minfo->SetLocationTag(buf); - - if (media_info_get_storage_type(media_h, - (media_content_storage_e *)&val) != - MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media location tag Fetch error"); - goto error; - } - minfo->SetSource(val); - - minfo->SetMediaInfo(media_h); - m->folder_medialist = eina_list_append(m->folder_medialist, minfo); return true; @@ -686,6 +592,11 @@ bool CMediadata::CreateMediaList(int source_type, int media) m_DestroyFilter(m->filter); + if (!CMediaContentListener::Create()) { + _ERR("MediaContentListener create failed"); + return false; + } + return true; } @@ -752,3 +663,40 @@ Eina_List *CMediadata::FolderList(void) return m->folderlist; } + +void CMediadata::OnDbUpdated(const SEntity *entity) +{ + filter_h filter; + char buf[1024]; + int r; + + if (entity->err != MEDIA_CONTENT_ERROR_NONE) + return; + + if (entity->update_item == MEDIA_ITEM_FILE && + entity->update_type == MEDIA_CONTENT_UPDATE && + entity->media_type == MEDIA_CONTENT_TYPE_IMAGE) { + r = media_filter_create(&filter); + if (r != MEDIA_CONTENT_ERROR_NONE) { + _ERR("media filter create failed"); + return; + } + + snprintf(buf, sizeof(buf), "MEDIA_PATH = \"%s\"", entity->path); + + r = media_filter_set_condition(filter, buf, + MEDIA_CONTENT_COLLATE_DEFAULT); + if (r != MEDIA_CONTENT_ERROR_NONE) { + _ERR("filter condition set failed"); + media_filter_destroy(filter); + return; + } + + r = media_info_foreach_media_from_db(filter, + sm_CbUpdateImageInfo, this); + if (r != MEDIA_CONTENT_ERROR_NONE) + _ERR("Media content error: %d", r); + + media_filter_destroy(filter); + } +} diff --git a/src/data/mediainfo.cpp b/src/data/mediainfo.cpp index e2823c4..b68f0e3 100644 --- a/src/data/mediainfo.cpp +++ b/src/data/mediainfo.cpp @@ -63,6 +63,104 @@ void CMediaInfo::Destroy(void) m = NULL; } +bool CMediaInfo::Update(void) +{ + char *buf; + unsigned long long val; + + if (media_info_get_media_id(m->media_h, &buf) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media ID Fetch error"); + return false; + } + SetId(buf); + + if (media_info_get_display_name(m->media_h, &buf) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media display nam))e Fetch error"); + return false; + } + SetName(buf); + + if (media_info_get_size(m->media_h, &val) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media size Fetch error"); + return false; + } + SetSize(val); + + if (media_info_get_file_path(m->media_h, &buf) + != MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media file path Fetch error"); + return false; + } + SetPath(buf); + + if (media_info_get_thumbnail_path(m->media_h, &buf) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media thumbnail path Fetch error"); + return false; + } + SetThumbnailPath(buf); + + if (media_info_get_modified_time(m->media_h, (time_t *)&val) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media modified time Fetch error"); + return false; + } + SetModifiedTime(val); + + if (media_info_get_modified_time(m->media_h, (time_t *)&val) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media created time Fetch error"); + return false; + } + m_SetCreatedTime(val); + + if (media_info_get_location_tag(m->media_h, &buf) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media location tag Fetch error"); + return false; + } + m_SetLocationTag(buf); + + if (media_info_get_storage_type(m->media_h, + (media_content_storage_e *)&val) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media location tag Fetch error"); + return false; + } + m_SetSource(val); + + return true; +} + +bool CMediaInfo::GetImageHandle(image_meta_h *image_h) +{ + int r; + + r = media_info_get_image(m->media_h, image_h); + if (r != MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media Image Handle Fetch Error"); + return false; + } + + return true; +} + +bool CMediaInfo::GetVideoHandle(video_meta_h *video_h) +{ + int r; + + r = media_info_get_video(m->media_h, video_h); + if (r != MEDIA_CONTENT_ERROR_NONE) { + _ERR("Media Video Handle Fetch Error"); + return false; + } + + return true; +} + char *CMediaInfo::LocationTag(void) { if (!m) @@ -114,7 +212,7 @@ media_info_h CMediaInfo::MediaInfo(void) return m->media_h; } -bool CMediaInfo::SetLocationTag(const char *location_tag) +bool CMediaInfo::m_SetLocationTag(const char *location_tag) { if (!m) return false; @@ -131,7 +229,7 @@ bool CMediaInfo::SetLocationTag(const char *location_tag) return true; } -bool CMediaInfo::SetCreatedTime(time_t created_time) +bool CMediaInfo::m_SetCreatedTime(time_t created_time) { if (!m) return false; @@ -141,7 +239,7 @@ bool CMediaInfo::SetCreatedTime(time_t created_time) return true; } -bool CMediaInfo::SetSource(int source) +bool CMediaInfo::m_SetSource(int source) { if (!m) return false; @@ -175,11 +273,11 @@ bool CMediaInfo::Duplicate(CNameInfo *obj) if (!CExtNameInfo::Duplicate(obj)) return false; - if (!SetLocationTag(dst->LocationTag())) + if (!m_SetLocationTag(dst->LocationTag())) return false; - if (!SetCreatedTime(dst->CreatedTime())) + if (!m_SetCreatedTime(dst->CreatedTime())) return false; - if (!SetSource(dst->Source())) + if (!m_SetSource(dst->Source())) return false; if (!SetMediaInfo(dst->MediaInfo())) return false; diff --git a/src/data/videoinfo.cpp b/src/data/videoinfo.cpp index d3fafdb..fe2e427 100644 --- a/src/data/videoinfo.cpp +++ b/src/data/videoinfo.cpp @@ -56,6 +56,45 @@ void CVideoInfo::Destroy(void) m = NULL; } +bool CVideoInfo::Update(void) +{ + int val; + video_meta_h video_h; + + if (!CMediaInfo::Update()) + return false; + + if (!GetVideoHandle(&video_h) || !video_h) { + _ERR("Get video handle failed"); + return false; + } + + if (video_meta_get_duration(video_h, &val) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("video meta get duration error"); + goto error; + } + m_SetDuration(val); + + if (video_meta_get_played_position(video_h, &val) != + MEDIA_CONTENT_ERROR_NONE) { + _ERR("video meta get played position error"); + goto error; + } + m_SetPlayedPosition(val); + + if (video_meta_destroy(video_h) != MEDIA_CONTENT_ERROR_NONE) { + _ERR("video meta destroy error"); + return false; + } + + return true; + +error: + video_meta_destroy(video_h); + return false; +} + int CVideoInfo::Duration(void) { if (!m) @@ -72,7 +111,7 @@ int CVideoInfo::PlayedPosition(void) return m->played_position; } -bool CVideoInfo::SetDuration(int duration) +bool CVideoInfo::m_SetDuration(int duration) { if (!m) return false; @@ -82,7 +121,7 @@ bool CVideoInfo::SetDuration(int duration) return true; } -bool CVideoInfo::SetPlayedPosition(int played_position) +bool CVideoInfo::m_SetPlayedPosition(int played_position) { if (!m) return false; @@ -102,9 +141,9 @@ bool CVideoInfo::Duplicate(CNameInfo *obj) if (!CMediaInfo::Duplicate(obj)) return false; - if (!SetDuration(dst->Duration())) + if (!m_SetDuration(dst->Duration())) return false; - if (!SetPlayedPosition(dst->PlayedPosition())) + if (!m_SetPlayedPosition(dst->PlayedPosition())) return false; return true; -- 2.7.4