summaryrefslogtreecommitdiff
path: root/legacy/emotion/src/modules
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2005-04-15 07:27:02 +0000
committerCarsten Haitzler <raster@rasterman.com>2005-04-15 07:27:02 +0000
commit4c2a9d32f9f515bac025e7ec9770970369777679 (patch)
tree8aa36e793da544de73acc6b1c71d313cdbb11c5c /legacy/emotion/src/modules
parent67ce5e1c1f3aca6d06531459dce03b552fc7f4b3 (diff)
simon treney's emotion patches - THANKs :o)
SVN revision: 14208
Diffstat (limited to '')
-rw-r--r--legacy/emotion/src/modules/emotion_xine.c347
-rw-r--r--legacy/emotion/src/modules/emotion_xine.h5
2 files changed, 148 insertions, 204 deletions
diff --git a/legacy/emotion/src/modules/emotion_xine.c b/legacy/emotion/src/modules/emotion_xine.c
index 100aa2b546..bc94cba25d 100644
--- a/legacy/emotion/src/modules/emotion_xine.c
+++ b/legacy/emotion/src/modules/emotion_xine.c
@@ -2,11 +2,9 @@
2#include "emotion_private.h" 2#include "emotion_private.h"
3#include "emotion_xine.h" 3#include "emotion_xine.h"
4 4
5static int init_count = 0; 5static unsigned char em_init(Evas_Object *obj, void **emotion_video);
6 6static int em_shutdown(void *video);
7static int em_init(void); 7static unsigned char em_file_open(const char *file, Evas_Object *obj, void *video);
8static int em_shutdown(void);
9static void *em_file_open(const char *file, Evas_Object *obj);
10static void em_file_close(void *ef); 8static void em_file_close(void *ef);
11static void em_play(void *ef, double pos); 9static void em_play(void *ef, double pos);
12static void em_stop(void *ef); 10static void em_stop(void *ef);
@@ -60,42 +58,27 @@ static int _em_timer (void *data);
60static void *_em_get_pos_len_th(void *par); 58static void *_em_get_pos_len_th(void *par);
61static void _em_get_pos_len (Emotion_Xine_Video *ev); 59static void _em_get_pos_len (Emotion_Xine_Video *ev);
62 60
63static int 61static unsigned char
64em_init(void) 62em_init(Evas_Object *obj, void **emotion_video)
65{
66 init_count++;
67 if (init_count > 1) return init_count;
68 return init_count;
69}
70
71static int
72em_shutdown(void)
73{
74 init_count--;
75 if (init_count > 0) return init_count;
76 return 0;
77}
78
79static void *
80em_file_open(const char *file, Evas_Object *obj)
81{ 63{
82 Emotion_Xine_Video *ev; 64 Emotion_Xine_Video *ev;
83 int pos_stream = 0; 65 int fds[2];
84 int pos_time = 0; 66
85 int length_time = 0; 67 if (!emotion_video)
86 uint32_t v; 68 return;
87 69
88 ev = calloc(1, sizeof(Emotion_Xine_Video)); 70 ev = calloc(1, sizeof(Emotion_Xine_Video));
89 if (!ev) return NULL; 71 if (!ev) return 0;
90 ev->obj = obj; 72 ev->obj = obj;
91 73
92 ev->decoder = xine_new(); 74 ev->decoder = xine_new();
93 if (!ev->decoder) 75 if (!ev->decoder)
94 { 76 {
95 free(ev); 77 free(ev);
96 return NULL; 78 return 0;
97 } 79 }
98 xine_init(ev->decoder); 80 xine_init(ev->decoder);
81 xine_init(ev->decoder);
99 if (1) 82 if (1)
100 { 83 {
101 xine_cfg_entry_t cf; 84 xine_cfg_entry_t cf;
@@ -222,39 +205,25 @@ em_file_open(const char *file, Evas_Object *obj)
222 printf("MRL: %s\n", auto_play_mrls[i]); 205 printf("MRL: %s\n", auto_play_mrls[i]);
223 } 206 }
224 } 207 }
208
209 if (pipe(fds) == 0)
225 { 210 {
226 int fds[2]; 211 ev->fd_read = fds[0];
227 212 ev->fd_write = fds[1];
228 if (pipe(fds) == 0) 213 fcntl(ev->fd_read, F_SETFL, O_NONBLOCK);
229 { 214 ev->fd_handler = ecore_main_fd_handler_add(ev->fd_read,
230 ev->fd_read = fds[0]; 215 ECORE_FD_READ, _em_fd_active, ev, NULL, NULL);
231 ev->fd_write = fds[1]; 216 ecore_main_fd_handler_active_set(ev->fd_handler, ECORE_FD_READ);
232 fcntl(ev->fd_read, F_SETFL, O_NONBLOCK);
233 ev->fd_handler = ecore_main_fd_handler_add(ev->fd_read,
234 ECORE_FD_READ,
235 _em_fd_active,
236 ev,
237 NULL,
238 NULL);
239 ecore_main_fd_handler_active_set(ev->fd_handler, ECORE_FD_READ);
240 }
241 } 217 }
218
219 if (pipe(fds) == 0)
242 { 220 {
243 int fds[2]; 221 ev->fd_ev_read = fds[0];
244 222 ev->fd_ev_write = fds[1];
245 if (pipe(fds) == 0) 223 fcntl(ev->fd_ev_read, F_SETFL, O_NONBLOCK);
246 { 224 ev->fd_ev_handler = ecore_main_fd_handler_add(ev->fd_ev_read,
247 ev->fd_ev_read = fds[0]; 225 ECORE_FD_READ, _em_fd_ev_active, ev, NULL, NULL);
248 ev->fd_ev_write = fds[1]; 226 ecore_main_fd_handler_active_set(ev->fd_ev_handler, ECORE_FD_READ);
249 fcntl(ev->fd_ev_read, F_SETFL, O_NONBLOCK);
250 ev->fd_ev_handler = ecore_main_fd_handler_add(ev->fd_ev_read,
251 ECORE_FD_READ,
252 _em_fd_ev_active,
253 ev,
254 NULL,
255 NULL);
256 ecore_main_fd_handler_active_set(ev->fd_ev_handler, ECORE_FD_READ);
257 }
258 } 227 }
259 ev->fd = ev->fd_write; 228 ev->fd = ev->fd_write;
260 229
@@ -266,21 +235,51 @@ em_file_open(const char *file, Evas_Object *obj)
266 ev->stream = xine_stream_new(ev->decoder, ev->audio, ev->video); 235 ev->stream = xine_stream_new(ev->decoder, ev->audio, ev->video);
267 ev->queue = xine_event_new_queue(ev->stream); 236 ev->queue = xine_event_new_queue(ev->stream);
268 xine_event_create_listener_thread(ev->queue, _em_event, ev); 237 xine_event_create_listener_thread(ev->queue, _em_event, ev);
238 *emotion_video = ev;
239
240 return 1;
241}
242
243static int
244em_shutdown(void *video)
245{
246 Emotion_Xine_Video *ev;
247
248 ev = (Emotion_Xine_Video *)video;
249
250 printf("EX dispose\n");
251 xine_dispose(ev->stream);
252 printf("EX dispose evq\n");
253 xine_event_dispose_queue(ev->queue);
254 printf("EX close video drv\n");
255 if (ev->video) xine_close_video_driver(ev->decoder, ev->video);
256 printf("EX close audio drv\n");
257 if (ev->audio) xine_close_audio_driver(ev->decoder, ev->audio);
258 printf("EX del fds\n");
259 ecore_main_fd_handler_del(ev->fd_handler);
260 close(ev->fd_write);
261 close(ev->fd_read);
262 ecore_main_fd_handler_del(ev->fd_ev_handler);
263 close(ev->fd_ev_write);
264 close(ev->fd_ev_read);
265 xine_exit(ev->decoder);
266 free(ev);
267}
268
269static unsigned char
270em_file_open(const char *file, Evas_Object *obj, void *video)
271{
272 Emotion_Xine_Video *ev = (Emotion_Xine_Video *)video;
273 int pos_stream = 0;
274 int pos_time = 0;
275 int length_time = 0;
276 uint32_t v;
277
278 if (!ev)
279 return 0;
280
269 if (!xine_open(ev->stream, file)) 281 if (!xine_open(ev->stream, file))
270 { 282 return 0;
271 ecore_main_fd_handler_del(ev->fd_handler);
272 close(ev->fd_write);
273 close(ev->fd_read);
274 ecore_main_fd_handler_del(ev->fd_ev_handler);
275 close(ev->fd_ev_write);
276 close(ev->fd_ev_read);
277 xine_dispose(ev->stream);
278 if (ev->video) xine_close_video_driver(ev->decoder, ev->video);
279 if (ev->audio) xine_close_audio_driver(ev->decoder, ev->audio);
280 xine_event_dispose_queue(ev->queue);
281 free(ev);
282 return NULL;
283 }
284 if (xine_get_pos_length(ev->stream, &pos_stream, &pos_time, &length_time)) 283 if (xine_get_pos_length(ev->stream, &pos_stream, &pos_time, &length_time))
285 { 284 {
286 if (length_time == 0) 285 if (length_time == 0)
@@ -295,6 +294,11 @@ em_file_open(const char *file, Evas_Object *obj)
295 ev->len = (double)length_time / 1000.0; 294 ev->len = (double)length_time / 1000.0;
296 } 295 }
297 } 296 }
297 else
298 {
299 ev->pos = 0.0;
300 ev->len = 1.0;
301 }
298 v = xine_get_stream_info(ev->stream, XINE_STREAM_INFO_FRAME_DURATION); 302 v = xine_get_stream_info(ev->stream, XINE_STREAM_INFO_FRAME_DURATION);
299 if (v > 0) ev->fps = 90000.0 / (double)v; 303 if (v > 0) ev->fps = 90000.0 / (double)v;
300 v = xine_get_stream_info(ev->stream, XINE_STREAM_INFO_VIDEO_WIDTH); 304 v = xine_get_stream_info(ev->stream, XINE_STREAM_INFO_VIDEO_WIDTH);
@@ -305,27 +309,20 @@ em_file_open(const char *file, Evas_Object *obj)
305 ev->ratio = (double)v / 10000.0; 309 ev->ratio = (double)v / 10000.0;
306 ev->just_loaded = 1; 310 ev->just_loaded = 1;
307 ev->get_poslen = 0; 311 ev->get_poslen = 0;
312 ev->seek_to = 0;
308 313
309 { 314 ev->delete_me = 0;
310 pthread_attr_t thattr;
311
312 pthread_cond_init(&(ev->seek_cond), NULL);
313 pthread_cond_init(&(ev->get_pos_len_cond), NULL);
314 pthread_mutex_init(&(ev->seek_mutex), NULL);
315 pthread_mutex_init(&(ev->get_pos_len_mutex), NULL);
316
317 pthread_attr_init(&thattr);
318 pthread_create(&ev->seek_th, NULL, _em_seek, ev);
319 pthread_attr_destroy(&thattr);
320
321 pthread_attr_init(&thattr);
322 pthread_create(&ev->get_pos_len_th, NULL, _em_get_pos_len_th, ev);
323 pthread_attr_destroy(&thattr);
324
325 ev->get_pos_thread_deleted = 0; 315 ev->get_pos_thread_deleted = 0;
326 } 316 ev->seek_thread_deleted = 0;
317 pthread_cond_init(&(ev->seek_cond), NULL);
318 pthread_cond_init(&(ev->get_pos_len_cond), NULL);
319 pthread_mutex_init(&(ev->seek_mutex), NULL);
320 pthread_mutex_init(&(ev->get_pos_len_mutex), NULL);
321 pthread_create(&ev->seek_th, NULL, _em_seek, ev);
322 pthread_create(&ev->get_pos_len_th, NULL, _em_get_pos_len_th, ev);
323
327// em_debug(ev); 324// em_debug(ev);
328 return ev; 325 return 1;
329} 326}
330 327
331static void 328static void
@@ -336,52 +333,38 @@ em_file_close(void *ef)
336 ev = (Emotion_Xine_Video *)ef; 333 ev = (Emotion_Xine_Video *)ef;
337 ev->delete_me = 1; 334 ev->delete_me = 1;
338// pthread_mutex_lock(&(ev->seek_mutex)); 335// pthread_mutex_lock(&(ev->seek_mutex));
339 pthread_cond_broadcast(&(ev->seek_cond)); 336 if (!ev->seek_thread_deleted)
340 while (ev->seek_to); 337 {
338 printf("closing seek thread\n");
339 pthread_cond_broadcast(&(ev->seek_cond));
340 while (ev->seek_to);
341 }
341 342
342// pthread_mutex_lock(&(ev->get_pos_len_mutex)); 343// pthread_mutex_lock(&(ev->get_pos_len_mutex));
343 if (!ev->get_pos_thread_deleted) 344 if (!ev->get_pos_thread_deleted)
344 { 345 {
345 pthread_cond_broadcast(&(ev->get_pos_len_cond)); 346 printf("closing get_pos thread\n");
346 while (ev->get_poslen); 347 pthread_cond_broadcast(&(ev->get_pos_len_cond));
347 } 348 while (ev->get_poslen);
349 }
348 350
349 printf("EX pause end...\n"); 351 printf("EX pause end...\n");
350 if (!emotion_object_play_get(ev->obj)) 352 if (!emotion_object_play_get(ev->obj))
351// if (xine_get_param(ev->stream, XINE_PARAM_SPEED) == XINE_SPEED_PAUSE) 353// if (xine_get_param(ev->stream, XINE_PARAM_SPEED) == XINE_SPEED_PAUSE)
352 { 354 {
353 printf("sync...\n"); 355 printf(" ... unpause\n");
354 while (xine_get_param(ev->stream, XINE_PARAM_SPEED) == XINE_SPEED_NORMAL); 356 xine_set_param(ev->stream, XINE_PARAM_SPEED, XINE_SPEED_NORMAL);
355 printf("sync...\n");
356 while (xine_get_param(ev->stream, XINE_PARAM_SPEED) == XINE_SPEED_PAUSE)
357 {
358 printf(" ... unpause\n");
359 xine_set_param(ev->stream, XINE_PARAM_SPEED, XINE_SPEED_NORMAL);
360 }
361 } 357 }
362 printf("EX stop\n"); 358 printf("EX stop\n");
363 xine_stop(ev->stream); 359 xine_stop(ev->stream);
364 printf("EX close\n"); 360 printf("EX close\n");
365 xine_close(ev->stream); 361 xine_close(ev->stream);
366 printf("EX dispose\n");
367 xine_dispose(ev->stream);
368 printf("EX dispose evq\n");
369 xine_event_dispose_queue(ev->queue);
370 printf("EX close video drv\n");
371 if (ev->video) xine_close_video_driver(ev->decoder, ev->video);
372 printf("EX close audio drv\n");
373 if (ev->audio) xine_close_audio_driver(ev->decoder, ev->audio);
374 printf("EX del timer\n"); 362 printf("EX del timer\n");
375 if (ev->timer) ecore_timer_del(ev->timer); 363 if (ev->timer)
376 printf("EX del fds\n"); 364 {
377 ecore_main_fd_handler_del(ev->fd_handler); 365 ecore_timer_del(ev->timer);
378 close(ev->fd_write); 366 ev->timer = NULL;
379 close(ev->fd_read); 367 }
380 ecore_main_fd_handler_del(ev->fd_ev_handler);
381 close(ev->fd_ev_write);
382 close(ev->fd_ev_read);
383 xine_exit(ev->decoder);
384 free(ev);
385} 368}
386 369
387static void 370static void
@@ -473,7 +456,7 @@ em_pos_set(void *ef, double pos)
473// if (xine_get_stream_info(ev->stream, XINE_STREAM_INFO_SEEKABLE)) 456// if (xine_get_stream_info(ev->stream, XINE_STREAM_INFO_SEEKABLE))
474 { 457 {
475 ev->seek_to_pos = pos; 458 ev->seek_to_pos = pos;
476 ev->seek_to++; 459 ev->seek_to = 1;
477 pthread_cond_broadcast(&(ev->seek_cond)); 460 pthread_cond_broadcast(&(ev->seek_cond));
478 } 461 }
479} 462}
@@ -1010,13 +993,6 @@ em_meta_get(Emotion_Xine_Video *ev, int meta)
1010 return NULL; 993 return NULL;
1011} 994}
1012 995
1013
1014
1015
1016
1017
1018
1019
1020static void * 996static void *
1021_em_seek(void *par) 997_em_seek(void *par)
1022{ 998{
@@ -1026,30 +1002,29 @@ _em_seek(void *par)
1026 pthread_mutex_lock(&(ev->seek_mutex)); 1002 pthread_mutex_lock(&(ev->seek_mutex));
1027 for (;;) 1003 for (;;)
1028 { 1004 {
1029 double ppos = -1.0; 1005 double ppos;
1030 1006
1031 pthread_cond_wait(&(ev->seek_cond), &(ev->seek_mutex)); 1007 pthread_cond_wait(&(ev->seek_cond), &(ev->seek_mutex));
1032 while (ev->seek_to > 0) 1008 if (ev->seek_to)
1033 { 1009 {
1034 again:
1035 ppos = ev->seek_to_pos; 1010 ppos = ev->seek_to_pos;
1036 if (ppos > ev->len) ppos = ev->len; 1011 if (ppos > ev->len)
1012 ppos = ev->len;
1037 if (ev->no_time) 1013 if (ev->no_time)
1038 xine_play(ev->stream, ppos * 65535, 0); 1014 xine_play(ev->stream, ppos * 65535, 0);
1039 else 1015 else
1040 xine_play(ev->stream, 0, ppos * 1000); 1016 xine_play(ev->stream, 0, ppos * 1000);
1041 ev->seek_to = 0; 1017 ev->seek_to = 0;
1042 if (ev->delete_me) return NULL; 1018
1019 if (!ev->play)
1020 xine_set_param(ev->stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE);
1043 } 1021 }
1044 if (!ev->play) 1022 if (ev->delete_me)
1045 { 1023 {
1046 xine_set_param(ev->stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE); 1024 ev->seek_thread_deleted = 1;
1025 return NULL;
1047 } 1026 }
1048 if (ev->delete_me) return NULL; 1027 }
1049 usleep(1000000 / 10);
1050 if (ppos != ev->seek_to_pos)
1051 goto again;
1052 }
1053 return NULL; 1028 return NULL;
1054} 1029}
1055 1030
@@ -1146,6 +1121,8 @@ _em_fd_ev_active(void *data, Ecore_Fd_Handler *fdh)
1146 { 1121 {
1147 case XINE_EVENT_UI_PLAYBACK_FINISHED: 1122 case XINE_EVENT_UI_PLAYBACK_FINISHED:
1148 { 1123 {
1124 if ((ev->pos / ev->len) < 0.999)
1125 break;
1149 if (ev->timer) 1126 if (ev->timer)
1150 { 1127 {
1151 ecore_timer_del(ev->timer); 1128 ecore_timer_del(ev->timer);
@@ -1153,6 +1130,7 @@ _em_fd_ev_active(void *data, Ecore_Fd_Handler *fdh)
1153 } 1130 }
1154 ev->play = 0; 1131 ev->play = 0;
1155 _emotion_decode_stop(ev->obj); 1132 _emotion_decode_stop(ev->obj);
1133 _emotion_playback_finished(ev->obj);
1156 } 1134 }
1157 break; 1135 break;
1158 case XINE_EVENT_UI_CHANNELS_CHANGED: 1136 case XINE_EVENT_UI_CHANNELS_CHANGED:
@@ -1277,16 +1255,13 @@ _em_get_pos_len_th(void *par)
1277 for (;;) 1255 for (;;)
1278 { 1256 {
1279 pthread_cond_wait(&(ev->get_pos_len_cond), &(ev->get_pos_len_mutex)); 1257 pthread_cond_wait(&(ev->get_pos_len_cond), &(ev->get_pos_len_mutex));
1280 while (ev->get_poslen > 0 || ev->delete_me) 1258 if (ev->get_poslen)
1281 { 1259 {
1282 int pos_stream = 0; 1260 int pos_stream = 0;
1283 int pos_time = 0; 1261 int pos_time = 0;
1284 int length_time = 0; 1262 int length_time = 0;
1285 1263
1286 if (xine_get_pos_length(ev->stream, 1264 if (xine_get_pos_length(ev->stream, &pos_stream, &pos_time, &length_time))
1287 &pos_stream,
1288 &pos_time,
1289 &length_time))
1290 { 1265 {
1291 if (length_time == 0) 1266 if (length_time == 0)
1292 { 1267 {
@@ -1301,15 +1276,13 @@ _em_get_pos_len_th(void *par)
1301 ev->no_time = 0; 1276 ev->no_time = 0;
1302 } 1277 }
1303 } 1278 }
1304 if (ev->delete_me)
1305 {
1306 ev->get_poslen = 0;
1307 ev->get_pos_thread_deleted = 1;
1308 return NULL;
1309 }
1310 ev->get_poslen = 0; 1279 ev->get_poslen = 0;
1311// printf("get pos %3.3f\n", ev->pos); 1280 //printf("get pos %3.3f\n", ev->pos);
1312 usleep(1000000 / 15); 1281 }
1282 if (ev->delete_me)
1283 {
1284 ev->get_pos_thread_deleted = 1;
1285 return NULL;
1313 } 1286 }
1314 } 1287 }
1315 return NULL; 1288 return NULL;
@@ -1319,30 +1292,10 @@ static void
1319_em_get_pos_len(Emotion_Xine_Video *ev) 1292_em_get_pos_len(Emotion_Xine_Video *ev)
1320{ 1293{
1321 if (ev->get_poslen) return; 1294 if (ev->get_poslen) return;
1322 ev->get_poslen++; 1295 ev->get_poslen = 1;
1323 pthread_cond_broadcast(&(ev->get_pos_len_cond)); 1296 pthread_cond_broadcast(&(ev->get_pos_len_cond));
1324} 1297}
1325 1298
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346static Emotion_Video_Module em_module = 1299static Emotion_Video_Module em_module =
1347{ 1300{
1348 em_init, /* init */ 1301 em_init, /* init */
@@ -1394,35 +1347,25 @@ static Emotion_Video_Module em_module =
1394 em_meta_get /* meta_get */ 1347 em_meta_get /* meta_get */
1395}; 1348};
1396 1349
1397Emotion_Video_Module * 1350unsigned char
1398module_open(void) 1351module_open(Evas_Object *obj, Emotion_Video_Module **module, void **video)
1399{ 1352{
1400 em_module.init(); 1353 if (!module)
1401 return &em_module; 1354 return 0;
1355
1356 if (!em_module.init(obj, video))
1357 return 0;
1358
1359 *module = &em_module;
1360 return 1;
1402} 1361}
1403 1362
1404void 1363void
1405module_close(Emotion_Video_Module *module) 1364module_close(Emotion_Video_Module *module, void *video)
1406{ 1365{
1407 em_module.shutdown(); 1366 em_module.shutdown(video);
1408} 1367}
1409 1368
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426#if 0 1369#if 0
1427void 1370void
1428em_debug(Emotion_Xine_Video *ev) 1371em_debug(Emotion_Xine_Video *ev)
diff --git a/legacy/emotion/src/modules/emotion_xine.h b/legacy/emotion/src/modules/emotion_xine.h
index 8025cad9da..f796bc9369 100644
--- a/legacy/emotion/src/modules/emotion_xine.h
+++ b/legacy/emotion/src/modules/emotion_xine.h
@@ -49,6 +49,7 @@ struct _Emotion_Xine_Video
49 pthread_cond_t get_pos_len_cond; 49 pthread_cond_t get_pos_len_cond;
50 pthread_mutex_t seek_mutex; 50 pthread_mutex_t seek_mutex;
51 pthread_mutex_t get_pos_len_mutex; 51 pthread_mutex_t get_pos_len_mutex;
52 unsigned char seek_thread_deleted : 1;
52 unsigned char get_pos_thread_deleted : 1; 53 unsigned char get_pos_thread_deleted : 1;
53}; 54};
54 55
@@ -71,7 +72,7 @@ struct _Emotion_Xine_Event
71 char *xine_event; 72 char *xine_event;
72}; 73};
73 74
74Emotion_Video_Module *module_open (void); 75unsigned char module_open(Evas_Object *obj, Emotion_Video_Module **module, void **video);
75void module_close(Emotion_Video_Module *module); 76void module_close(Emotion_Video_Module *module, void *video);
76 77
77#endif 78#endif