2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 <Elementary.h>
26 #include <provider_buffer.h>
30 #include <mm_message.h>
31 #include <mm_player.h>
38 Eina_List *CVideo::s_pList = NULL;
41 CVideo *CVideo::Find(enum target_type type, const char *id)
47 EINA_LIST_FOREACH(s_pList, l, item) {
48 video = (CVideo *)item;
50 if (video->Type() == type && !strcmp(video->Id(), id))
57 CVideo *CVideo::Create(enum target_type type, const char *id, int w, int h)
60 struct livebox_buffer *pBuffer;
62 if (!ecore_x_damage_query()) {
63 ErrPrint("Damage event is not supported\n");
68 video = new CVideo(type, w, h);
70 ErrPrint("Failed to create a video instance\n");
74 video->m_sId = strdup(id);
76 ErrPrint("Heap: %s\n", strerror(errno));
81 pBuffer = provider_buffer_acquire(video->Type(), PKGNAME, video->Id(),
82 video->Width(), video->Height(), sizeof(int),
83 CVideo::s_BufferEventHandler, video);
85 ErrPrint("Failed to acquire buffer handle\n");
92 * this function must has to be called before add an item to the s_pList
94 video->SetBuffer(pBuffer);
96 s_pList = eina_list_append(s_pList, video);
100 Eina_Bool CVideo::s_DamageEventHandler(void *data, int type, void *event)
102 CVideo *video = (CVideo *)data;
103 Ecore_X_Event_Damage *e = (Ecore_X_Event_Damage *)event;
105 if (e->drawable == video->PixmapId()) {
106 switch (video->Type()) {
108 provider_send_updated(PKGNAME, video->Id(), video->Width(), video->Height(), 1.0f, NULL, NULL);
111 provider_send_desc_updated(PKGNAME, video->Id(), NULL);
114 ErrPrint("Unknown video type\n");
121 return ECORE_CALLBACK_PASS_ON;
124 int CVideo::Update(void)
126 ecore_x_damage_subtract(m_vDamage, None, None);
130 void CVideo::SetBuffer(struct livebox_buffer *pBuffer)
133 if (m_pDamageHandler)
134 ecore_event_handler_del(m_pDamageHandler);
136 m_pDamageHandler = NULL;
139 ecore_x_damage_free(m_vDamage);
147 m_nId = provider_buffer_pixmap_id(m_pBuffer);
149 ErrPrint("Failed to get pixmap\n");
153 m_pDamageHandler = ecore_event_handler_add(ECORE_X_EVENT_DAMAGE_NOTIFY, CVideo::s_DamageEventHandler, this);
154 if (!m_pDamageHandler) {
155 ErrPrint("Failed to add a event handler\n");
159 m_vDamage = ecore_x_damage_new(m_nId, ECORE_X_DAMAGE_REPORT_RAW_RECTANGLES);
161 ErrPrint("Failed to create a new damage object\n");
165 DbgPrint("Prepare callback\n");
169 int CVideo::s_BufferEventHandler(struct livebox_buffer *buffer, enum buffer_event event, double timestamp, double x, double y, void *data)
171 CVideo *video = (CVideo *)data;
175 ix = video->Width() * x;
176 iy = video->Height() * y;
179 case BUFFER_EVENT_ENTER:
181 case BUFFER_EVENT_LEAVE:
183 case BUFFER_EVENT_DOWN:
184 DbgPrint("Down: %dx%d\n", ix, iy);
186 case BUFFER_EVENT_MOVE:
188 case BUFFER_EVENT_UP:
189 DbgPrint("Up: %dx%d\n", ix, iy);
198 int CVideo::Destroy(void)
201 DbgPrint("Destroy a video object\n");
203 s_pList = eina_list_remove(s_pList, this);
205 Stop(); /*!< Just try to stop playing */
208 ecore_x_damage_free(m_vDamage);
210 if (m_pDamageHandler)
211 ecore_event_handler_del(m_pDamageHandler);
215 ret = provider_buffer_release(m_pBuffer);
216 DbgPrint("release: %d\n", ret);
221 int CVideo::Resize(int w, int h)
223 struct livebox_buffer *pBuffer;
225 if (m_nWidth == w && m_nHeight == h) {
226 DbgPrint("Size has no changes\n");
234 ErrPrint("Buffer is not available\n");
240 provider_buffer_release(m_pBuffer);
243 pBuffer = provider_buffer_acquire(m_vType, PKGNAME,
244 m_sId, m_nWidth, m_nHeight, sizeof(int),
245 CVideo::s_BufferEventHandler, this);
249 if (m_vState == PLAYING) {
253 uri = CModel::GetInstance()->VideoFilename();
254 DbgPrint("Update PIXMAP: 0x%X (file: %s)\n", m_nId, uri);
255 mm_player_set_attribute(m_vPlayer, &m_sError,
256 "display_surface_type", MM_DISPLAY_SURFACE_X,
257 "display_width", m_nWidth,
258 "display_height", m_nHeight,
259 "display_overlay", &m_nId, sizeof(m_nId),
260 "profile_uri", uri, strlen(uri),
261 "display_rotation", MM_DISPLAY_ROTATION_NONE,
262 "profile_play_count", 1,
265 ErrPrint("SetAttribute: %s\n", m_sError);
271 int CVideo::s_MMMessageHandler(int message, void *_param, void *user_param)
273 CVideo *video = (CVideo *)user_param;
274 // MMMessageParamType *param = (MMMessageParamType *)_param;
277 case MM_MESSAGE_END_OF_STREAM:
279 DbgPrint("End of stream\n");
288 void CVideo::Clear(void)
290 static unsigned int s_color = 0x00FF0000;
293 gc = XCreateGC((Display *)ecore_x_display_get(), PixmapId(), 0, 0);
295 XSetForeground((Display *)ecore_x_display_get(), gc, 0xFF000000 | s_color);
296 XFillRectangle((Display *)ecore_x_display_get(), PixmapId(), gc, 0, 0, Width(), Height());
298 XSync((Display *)ecore_x_display_get(), FALSE);
299 XFreeGC((Display *)ecore_x_display_get(), gc);
303 s_color = 0xFF000000;
306 int CVideo::Play(const char *uri)
308 if (m_vState == PLAYING)
311 if (mm_player_create(&m_vPlayer) != MM_ERROR_NONE) {
312 ErrPrint("Failed to create a player\n");
317 mm_player_set_attribute(m_vPlayer, &m_sError,
318 "display_surface_type", MM_DISPLAY_SURFACE_X,
319 "display_width", m_nWidth,
320 "display_height", m_nHeight,
321 "display_overlay", &m_nId, sizeof(m_nId),
322 "profile_uri", uri, strlen(uri),
323 "display_rotation", MM_DISPLAY_ROTATION_NONE,
324 "profile_play_count", 1,
327 ErrPrint("SetAttribute: %s\n", m_sError);
329 if (mm_player_realize(m_vPlayer) != MM_ERROR_NONE) {
330 ErrPrint("Failed to realize a player\n");
331 mm_player_destroy(m_vPlayer);
336 mm_player_set_message_callback(m_vPlayer, CVideo::s_MMMessageHandler, this);
337 mm_player_start(m_vPlayer);
340 DbgPrint("Play file %s on %d\n", uri, m_nId);
344 int CVideo::Stop(void)
346 if (m_vState == STOPPED)
352 mm_player_unrealize(m_vPlayer);
353 mm_player_destroy(m_vPlayer);
357 DbgPrint("Stop playing\n");
361 CVideo::CVideo(enum target_type type, int width, int height)
374 CVideo::~CVideo(void)
378 CVideo::TVideoState CVideo::State(void)