From 48c84a76e319e50568c23d47bca3dd3a47e410db Mon Sep 17 00:00:00 2001 From: Minkyu Kang Date: Fri, 13 Feb 2015 17:12:18 +0900 Subject: [PATCH] mediadata: convert to class Change-Id: I8528d32e3129fbb8622f34083aa1da135a817623 Signed-off-by: Minkyu Kang --- include/mediadata.h | 40 +++++++----- include/videodata.h | 31 +++++---- include/view_player.h | 1 - src/mediadata.cpp | 178 +++++++++++++++++++++----------------------------- src/videodata.cpp | 83 +++++++++-------------- src/view_player.cpp | 81 ++++++----------------- 6 files changed, 168 insertions(+), 246 deletions(-) diff --git a/include/mediadata.h b/include/mediadata.h index d5b98f1..ddfdbd3 100644 --- a/include/mediadata.h +++ b/include/mediadata.h @@ -17,21 +17,29 @@ #ifndef __MEDIADATA_H__ #define __MEDIADATA_H__ -#include -#include "videodata.h" - -struct mediadata; - -int mediadata_init(); -int mediadata_fini(); - -struct mediadata *mediadata_create(const char *path); -void mediadata_destroy(struct mediadata *md); - -const char *mediadata_get_displayname(struct mediadata *md); -const char *mediadata_get_filepath(struct mediadata *md); -time_t mediadata_get_modifiedtime(struct mediadata *md); - -const struct videodata *mediadata_get_video_info(struct mediadata *md); +struct SMediaData; + +class CMediaData { +private: + SMediaData *m; + +private: + static bool sm_GetMediaInfo(media_info_h media_h, void *dt); + +public: + CMediaData(void); + virtual ~CMediaData(void); + + bool Create(const char *path); + void Destroy(void); + + const char *GetName(void); + const char *GetPath(void); + time_t GetTime(void); + int GetDuration(void); + int GetPosition(void); + int GetWidth(void); + int GetHeight(void); +}; #endif diff --git a/include/videodata.h b/include/videodata.h index 555fc29..85abdcf 100644 --- a/include/videodata.h +++ b/include/videodata.h @@ -17,18 +17,23 @@ #ifndef __VIDEODATA_H__ #define __VIDEODATA_H__ -#include - -struct videodata; - -struct videodata *videodata_create(media_info_h media_h); - -void videodata_destroy(struct videodata *video_info); - -int videodata_get_duration(const struct videodata *video_info); -int videodata_get_played_position(const struct videodata *video_info); - -int videodata_get_width(const struct videodata *video_info); -int videodata_get_height(const struct videodata *video_info); +class CVideoData { +private: + int duration; + int position; + int width; + int height; + +public: + CVideoData(void); + virtual ~CVideoData(void) {} + + bool Update(media_info_h media_h); + + int GetDuration(void); + int GetPosition(void); + int GetWidth(void); + int GetHeight(void); +}; #endif diff --git a/include/view_player.h b/include/view_player.h index 2dc5cfb..64c4195 100644 --- a/include/view_player.h +++ b/include/view_player.h @@ -42,7 +42,6 @@ private: bool m_UiInit(void); bool m_AddControls(void); void m_UpdateInfoBar(void); - void m_UpdateInfoBar(struct mediadata *md); bool m_PlayerInit(void); void m_ShowBar(void); void m_HideBar(void); diff --git a/src/mediadata.cpp b/src/mediadata.cpp index 2b5ed30..d91a082 100644 --- a/src/mediadata.cpp +++ b/src/mediadata.cpp @@ -16,109 +16,59 @@ #include #include +#include +#include #include #include "define.h" #include "mediadata.h" +#include "videodata.h" -struct mediadata { +struct SMediaData { char *name; char *path; - time_t modified; - struct videodata *video_info; + time_t time; + CVideoData *video; }; -static int g_ref_count; - -int mediadata_init(void) -{ - int r; - - if (g_ref_count > 0) { - g_ref_count++; - return -1; - } - - r = media_content_connect(); - if (r != MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media Content Connect Failed"); - return -1; - } - g_ref_count++; - - return 0; -} - -int mediadata_fini(void) +CMediaData::CMediaData(void) { - int r; - - if (g_ref_count <= 0) - return -1; - - g_ref_count--; - - if (g_ref_count == 0) { - r = media_content_disconnect(); - if (r != MEDIA_CONTENT_ERROR_NONE) { - _ERR("Media Content Connect Failed"); - return -1; - } - } - - return 0; + m = NULL; + media_content_connect(); } -static void _free_mediadata_item(struct mediadata *md) +CMediaData::~CMediaData(void) { - free(md->name); - free(md->path); - - videodata_destroy(md->video_info); - - free(md); + media_content_disconnect(); } -static bool _get_each_media_info(media_info_h media_h, void *dt) +bool CMediaData::sm_GetMediaInfo(media_info_h media_h, void *dt) { - struct mediadata *md; - int r; + SMediaData *md; - md = *((struct mediadata **)dt); + md = (SMediaData *)dt; - r = media_info_get_display_name(media_h, &(md->name)); - if (r != MEDIA_CONTENT_ERROR_NONE) - goto error; + media_info_get_display_name(media_h, &md->name); + media_info_get_file_path(media_h, &md->path); + media_info_get_modified_time(media_h, &md->time); - r = media_info_get_file_path(media_h, &(md->path)); - if (r != MEDIA_CONTENT_ERROR_NONE) - goto error; - - r = media_info_get_modified_time(media_h, &(md->modified)); - if (r != MEDIA_CONTENT_ERROR_NONE) - goto error; - - md->video_info = videodata_create(media_h); - if (!md->video_info) - goto error; + md->video = new CVideoData; + md->video->Update(media_h); return true; - -error: - _free_mediadata_item(md); - return false; } -struct mediadata *mediadata_create(const char *path) +bool CMediaData::Create(const char *path) { + ASSERT(!m); + filter_h filter; - struct mediadata *md; char buf[1024]; int r; r = media_filter_create(&filter); if (r != MEDIA_CONTENT_ERROR_NONE) { _ERR("Media Filter Creation Failed"); - return NULL; + return false; } snprintf(buf, sizeof(buf), "MEDIA_PATH = \"%s\"", path); @@ -128,17 +78,16 @@ struct mediadata *mediadata_create(const char *path) if (r != MEDIA_CONTENT_ERROR_NONE) { _ERR("Fail to set filter condition"); media_filter_destroy(filter); - return NULL; + return false; } - md = (mediadata *)calloc(1, sizeof(*md)); - if (!md) { + m = new SMediaData; + if (!m) { _ERR("allocation failed"); - return NULL; + return false; } - r = media_info_foreach_media_from_db(filter, - _get_each_media_info, &md); + r = media_info_foreach_media_from_db(filter, sm_GetMediaInfo, m); if (r != MEDIA_CONTENT_ERROR_NONE) { if (r == MEDIA_CONTENT_ERROR_DB_FAILED) _ERR("MEDIA CONTENT ERROR DB FAILED"); @@ -147,53 +96,78 @@ struct mediadata *mediadata_create(const char *path) else _ERR("MEDIA CONTENT ERROR"); - free(md); media_filter_destroy(filter); - return NULL; + delete m; + m = NULL; + + return false; } media_filter_destroy(filter); - return md; + return true; +} + +void CMediaData::Destroy(void) +{ + ASSERT(m); + + free(m->name); + free(m->path); + + delete m->video; + m->video = NULL; + + delete m; + m = NULL; +} + +const char *CMediaData::GetName(void) +{ + ASSERT(m); + + return m->name; +} + +const char *CMediaData::GetPath(void) +{ + ASSERT(m); + + return m->path; } -void mediadata_destroy(struct mediadata *md) +time_t CMediaData::GetTime(void) { - if (!md) - return; + ASSERT(m); - _free_mediadata_item(md); + return m->time; } -const char *mediadata_get_displayname(struct mediadata *md) +int CMediaData::GetDuration(void) { - if (!md) - return NULL; + ASSERT(m); - return md->name; + return m->video->GetDuration(); } -const char *mediadata_get_filepath(struct mediadata *md) +int CMediaData::GetPosition(void) { - if (!md) - return NULL; + ASSERT(m); - return md->path; + return m->video->GetPosition(); } -time_t mediadata_get_modifiedtime(struct mediadata *md) +int CMediaData::GetWidth(void) { - if (!md) - return -1; + ASSERT(m); - return md->modified; + return m->video->GetWidth(); } -const struct videodata *mediadata_get_video_info(struct mediadata *md) +int CMediaData::GetHeight(void) { - if (!md) - return NULL; + ASSERT(m); - return md->video_info; + return m->video->GetHeight(); } diff --git a/src/videodata.cpp b/src/videodata.cpp index 40543b3..182953f 100644 --- a/src/videodata.cpp +++ b/src/videodata.cpp @@ -16,105 +16,82 @@ #include #include +#include #include #include "define.h" #include "videodata.h" -struct videodata { - int duration; - int position; - int width; - int height; -}; - -void videodata_destroy(struct videodata *video_info) +CVideoData::CVideoData(void) { - free(video_info); - video_info = NULL; + duration = 0; + position = 0; + width = 0; + height = 0; } -struct videodata *videodata_create(media_info_h media_h) +bool CVideoData::Update(media_info_h media_h) { int r; - struct videodata *video_info; video_meta_h video_h; if (!media_h) - return NULL; + return false; r = media_info_get_video(media_h, &video_h); if (r != MEDIA_CONTENT_ERROR_NONE || !video_h) { _ERR("Media video handle fetch error"); - return NULL; + return false; } - video_info = (videodata *)calloc(1, sizeof(*video_info)); - if (!video_info) - goto error; - - r = video_meta_get_duration(video_h, &video_info->duration); + r = video_meta_get_duration(video_h, &duration); if (r != MEDIA_CONTENT_ERROR_NONE) { _ERR("video meta get duration error"); - goto error; + video_meta_destroy(video_h); + return false; } - r = video_meta_get_width(video_h, &video_info->width); + r = video_meta_get_width(video_h, &width); if (r != MEDIA_CONTENT_ERROR_NONE) { _ERR("video meta get width error"); - goto error; + video_meta_destroy(video_h); + return false; } - r = video_meta_get_height(video_h, &video_info->height); + r = video_meta_get_height(video_h, &height); if (r != MEDIA_CONTENT_ERROR_NONE) { _ERR("video meta get width error"); - goto error; + video_meta_destroy(video_h); + return false; } - r = video_meta_get_played_position(video_h, &video_info->position); + r = video_meta_get_played_position(video_h, &position); if (r != MEDIA_CONTENT_ERROR_NONE) { _ERR("video meta get played position error"); - goto error; + video_meta_destroy(video_h); + return false; } video_meta_destroy(video_h); - return video_info; - -error: - video_meta_destroy(video_h); - videodata_destroy(video_info); - - return NULL; + return true; } -int videodata_get_duration(const struct videodata *video_info) +int CVideoData::GetDuration(void) { - if (!video_info) - return -1; - - return video_info->duration; + return duration; } -int videodata_get_played_position(const struct videodata *video_info) +int CVideoData::GetPosition(void) { - if (!video_info) - return -1; - - return video_info->position; + return position; } -int videodata_get_width(const struct videodata *video_info) +int CVideoData::GetWidth(void) { - if (!video_info) - return -1; - - return video_info->width; + return width; } -int videodata_get_height(const struct videodata *video_info) +int CVideoData::GetHeight(void) { - if (!video_info) - return -1; - - return video_info->height; + return width; } diff --git a/src/view_player.cpp b/src/view_player.cpp index 23fb972..0ab0460 100644 --- a/src/view_player.cpp +++ b/src/view_player.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "define.h" #include "i18n.h" @@ -59,15 +60,15 @@ struct SPlayerView { Evas_Object *base; char *id; - struct playermgr *player; + playermgr *player; CVolume *volume; CVideoController *control; CVideoSlider *slider; + CMediaData *mediadata; - struct timeout_handler *timeout_handle; + timeout_handler *timeout_handle; bool bar_hidden; - bool error; Ecore_Timer *drawanim_timer; int duration; @@ -92,38 +93,18 @@ enum _repeat_option { void CPlayerView::m_UpdateInfoBar(void) { - Evas_Object *obj; - - obj = m->base; - - /* Title */ - elm_object_part_text_set(obj, PART_TITLETEXT, _(TEXT_NOVIDEO)); - - /* Created Time */ - elm_object_part_text_set(obj, PART_DATETEXT, _(TEXT_NODATE)); - - /* Source */ - elm_object_part_text_set(obj, PART_SOURCETEXT, _(TEXT_NOSOURCE)); - - /* Resolution */ - elm_object_part_text_set(obj, PART_RESOLUTIONTEXT, _(TEXT_NORES)); -} - -void CPlayerView::m_UpdateInfoBar(struct mediadata *md) -{ const char *name; char buf[32]; time_t video_time; struct tm tm; - const struct videodata *vd; /* Title */ - name = mediadata_get_displayname(md); + name = m->mediadata->GetName(); if (name) elm_object_part_text_set(m->base, PART_TITLETEXT, name); /* Created Time */ - video_time = mediadata_get_modifiedtime(md); + video_time = m->mediadata->GetTime(); if (video_time > 0) { localtime_r(&video_time, &tm); @@ -143,24 +124,16 @@ void CPlayerView::m_UpdateInfoBar(struct mediadata *md) elm_object_part_text_set(m->base, PART_CURRENTTEXT, buf); /* Resolution */ - vd = mediadata_get_video_info(md); - if (vd) { - snprintf(buf, sizeof(buf), "%dx%d", - videodata_get_width(vd), - videodata_get_height(vd)); + snprintf(buf, sizeof(buf), "%dx%d", m->mediadata->GetWidth(), + m->mediadata->GetHeight()); - m->duration = videodata_get_duration(vd); - } else { - snprintf(buf, sizeof(buf), "%s", _(TEXT_NORES)); - m->duration = 0; - } + m->duration = m->mediadata->GetDuration(); elm_object_part_text_set(m->base, PART_RESOLUTIONTEXT, buf); } bool CPlayerView::m_PlayerInit(void) { - struct mediadata *md; const char *path; int r; @@ -170,11 +143,9 @@ bool CPlayerView::m_PlayerInit(void) path = playermgr_get_video_path(m->player); - md = mediadata_create(path); - if (md) { - m_UpdateInfoBar(md); - mediadata_destroy(md); - } + m->mediadata->Create(path); + m_UpdateInfoBar(); + m->mediadata->Destroy(); m->slider->Reset(m->duration); m->control->Signal(E_PLAYPAUSE_BTN, SIG_SET_PAUSE, ""); @@ -407,18 +378,15 @@ void CPlayerView::m_HideBar(void) void CPlayerView::sm_CbTimeoutEvent(void *dt, int type, void *ev) { SPlayerView *data; + update_action action; if (!dt) return; data = (SPlayerView *)dt; - if (!data->error) { - update_action action; - - action = ACTION_HIDE; - CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action); - } + action = ACTION_HIDE; + CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action); } void CPlayerView::sm_EvtBack(void *dt, Evas_Object *obj, void *ev) @@ -536,10 +504,8 @@ Eina_Bool CPlayerView::sm_CbDrawAnimation(void *dt) void CPlayerView::m_ControlInit(SPlayerParam *param) { - int r; - - r = mediadata_init(); - if (r < 0) + m->mediadata = new CMediaData; + if (!m->mediadata) _ERR("mediadata init failed"); if (param->id) @@ -614,7 +580,6 @@ bool CPlayerView::Create(void *data) } m->win = win; - m->error = false; m_ControlInit((SPlayerParam *)data); @@ -627,14 +592,7 @@ bool CPlayerView::Create(void *data) if (!m_PlayerInit()) { _ERR("failed to play video"); - m->error = true; - - m_UpdateInfoBar(); - m->control->Hide(); - elm_object_signal_emit(m->base, SIG_SHOW_VIEW, ""); - - CBaseView::Create(NULL); - return true; + return false; } playermgr_set_completed_cb(m->player, sm_CbPlayComplete, m); @@ -662,7 +620,8 @@ void CPlayerView::Destroy(void) if (m->drawanim_timer) ecore_timer_del(m->drawanim_timer); - mediadata_fini(); + delete m->mediadata; + m->mediadata = NULL; playermgr_fini(m->player); -- 2.7.4