summaryrefslogtreecommitdiff
path: root/legacy/emotion/src/generic_players/vlc/emotion_generic_vlc.c
diff options
context:
space:
mode:
authorRafael Antognolli <antognolli@gmail.com>2011-09-05 13:12:17 +0000
committerRafael Antognolli <antognolli@gmail.com>2011-09-05 13:12:17 +0000
commitd04377d4d2426cb9f7ec5bf85cda4d03deca99a9 (patch)
tree3c8e50c1de7a6402ff32a75c360b53096663c297 /legacy/emotion/src/generic_players/vlc/emotion_generic_vlc.c
parent733fe1d4449544377e31d47e6211144c92877d85 (diff)
emotion/generic - Use pipes instead of stdin/stdout for communication.
Now the player will have the stdin and stdout available for anything else, and there's no need to make line-buffering with ecore_exe anymore. SVN revision: 63198
Diffstat (limited to '')
-rw-r--r--legacy/emotion/src/generic_players/vlc/emotion_generic_vlc.c164
1 files changed, 88 insertions, 76 deletions
diff --git a/legacy/emotion/src/generic_players/vlc/emotion_generic_vlc.c b/legacy/emotion/src/generic_players/vlc/emotion_generic_vlc.c
index 0df7c00f9d..425aeb4d60 100644
--- a/legacy/emotion/src/generic_players/vlc/emotion_generic_vlc.c
+++ b/legacy/emotion/src/generic_players/vlc/emotion_generic_vlc.c
@@ -36,8 +36,10 @@ struct _App {
36 char *filename; 36 char *filename;
37 char *shmname; 37 char *shmname;
38 int w, h; 38 int w, h;
39 int fd_read; 39 int fd_read; // read commands from theads here
40 int fd_write; 40 int fd_write; // write commands from threads here
41 int em_read; // read commands from emotion here
42 int em_write; // write commands to emotion here
41 int size_sent; 43 int size_sent;
42 int opening; 44 int opening;
43 int closing; 45 int closing;
@@ -121,13 +123,13 @@ _em_write_safe(int fd, const void *buf, ssize_t size)
121} 123}
122 124
123static int 125static int
124_em_str_read(char **str) 126_em_str_read(int fd, char **str)
125{ 127{
126 int size; 128 int size;
127 int r; 129 int r;
128 char buf[PATH_MAX]; 130 char buf[PATH_MAX];
129 131
130 r = _em_read_safe(STDIN_FILENO, &size, sizeof(size)); 132 r = _em_read_safe(fd, &size, sizeof(size));
131 if (!r) 133 if (!r)
132 { 134 {
133 *str = NULL; 135 *str = NULL;
@@ -140,7 +142,7 @@ _em_str_read(char **str)
140 return 1; 142 return 1;
141 } 143 }
142 144
143 r = _em_read_safe(STDIN_FILENO, buf, size); 145 r = _em_read_safe(fd, buf, size);
144 if (!r) 146 if (!r)
145 { 147 {
146 *str = NULL; 148 *str = NULL;
@@ -152,86 +154,84 @@ _em_str_read(char **str)
152} 154}
153 155
154static int 156static int
155_em_cmd_read(void) 157_em_cmd_read(struct _App *app)
156{ 158{
157 int cmd; 159 int cmd;
158 _em_read_safe(STDIN_FILENO, &cmd, sizeof(cmd)); 160 _em_read_safe(app->em_read, &cmd, sizeof(cmd));
159 161
160 return cmd; 162 return cmd;
161} 163}
162 164
163static void 165static void
164_send_cmd_start(int cmd) 166_send_cmd_start(struct _App *app, int cmd)
165{ 167{
166 pthread_mutex_lock(&_mutex_fd); 168 pthread_mutex_lock(&_mutex_fd);
167 _em_write_safe(STDOUT_FILENO, &cmd, sizeof(cmd)); 169 _em_write_safe(app->em_write, &cmd, sizeof(cmd));
168} 170}
169 171
170static void 172static void
171_send_cmd_finish(void) 173_send_cmd_finish(struct _App *app)
172{ 174{
173 static const char c = '\n';
174 _em_write_safe(STDOUT_FILENO, &c, sizeof(c));
175 pthread_mutex_unlock(&_mutex_fd); 175 pthread_mutex_unlock(&_mutex_fd);
176} 176}
177 177
178static void 178static void
179_send_cmd(int cmd) 179_send_cmd(struct _App *app, int cmd)
180{ 180{
181 _send_cmd_start(cmd); 181 _send_cmd_start(app, cmd);
182 _send_cmd_finish(); 182 _send_cmd_finish(app);
183} 183}
184 184
185static void 185static void
186_send_cmd_str(const char *str) 186_send_cmd_str(struct _App *app, const char *str)
187{ 187{
188 int len; 188 int len;
189 len = strlen(str) + 1; 189 len = strlen(str) + 1;
190 _em_write_safe(STDOUT_FILENO, &len, sizeof(len)); 190 _em_write_safe(app->em_write, &len, sizeof(len));
191 _em_write_safe(STDOUT_FILENO, str, len); 191 _em_write_safe(app->em_write, str, len);
192} 192}
193 193
194#define SEND_CMD_PARAM(i) \ 194#define SEND_CMD_PARAM(app, i) \
195 _em_write_safe(STDOUT_FILENO, &(i), sizeof((i))); 195 _em_write_safe((app)->em_write, &(i), sizeof((i)));
196 196
197static void 197static void
198_send_resize(int width, int height) 198_send_resize(struct _App *app, int width, int height)
199{ 199{
200 _send_cmd_start(EM_RESULT_FRAME_SIZE); 200 _send_cmd_start(app, EM_RESULT_FRAME_SIZE);
201 SEND_CMD_PARAM(width); 201 SEND_CMD_PARAM(app, width);
202 SEND_CMD_PARAM(height); 202 SEND_CMD_PARAM(app, height);
203 _send_cmd_finish(); 203 _send_cmd_finish(app);
204} 204}
205 205
206static void 206static void
207_send_length_changed(const struct libvlc_event_t *ev) 207_send_length_changed(struct _App *app, const struct libvlc_event_t *ev)
208{ 208{
209 float length = ev->u.media_player_length_changed.new_length; 209 float length = ev->u.media_player_length_changed.new_length;
210 length /= 1000; 210 length /= 1000;
211 211
212 fprintf(stderr, "length changed: %0.3f\n", length); 212 fprintf(stderr, "length changed: %0.3f\n", length);
213 _send_cmd_start(EM_RESULT_LENGTH_CHANGED); 213 _send_cmd_start(app, EM_RESULT_LENGTH_CHANGED);
214 SEND_CMD_PARAM(length); 214 SEND_CMD_PARAM(app, length);
215 _send_cmd_finish(); 215 _send_cmd_finish(app);
216} 216}
217 217
218static void 218static void
219_send_time_changed(const struct libvlc_event_t *ev) 219_send_time_changed(struct _App *app, const struct libvlc_event_t *ev)
220{ 220{
221 float new_time = ev->u.media_player_time_changed.new_time; 221 float new_time = ev->u.media_player_time_changed.new_time;
222 new_time /= 1000; 222 new_time /= 1000;
223 _send_cmd_start(EM_RESULT_POSITION_CHANGED); 223 _send_cmd_start(app, EM_RESULT_POSITION_CHANGED);
224 SEND_CMD_PARAM(new_time); 224 SEND_CMD_PARAM(app, new_time);
225 _send_cmd_finish(); 225 _send_cmd_finish(app);
226} 226}
227 227
228static void 228static void
229_send_seekable_changed(const struct libvlc_event_t *ev) 229_send_seekable_changed(struct _App *app, const struct libvlc_event_t *ev)
230{ 230{
231 int seekable = ev->u.media_player_seekable_changed.new_seekable; 231 int seekable = ev->u.media_player_seekable_changed.new_seekable;
232 _send_cmd_start(EM_RESULT_SEEKABLE_CHANGED); 232 _send_cmd_start(app, EM_RESULT_SEEKABLE_CHANGED);
233 SEND_CMD_PARAM(seekable); 233 SEND_CMD_PARAM(app, seekable);
234 _send_cmd_finish(); 234 _send_cmd_finish(app);
235} 235}
236 236
237static void * 237static void *
@@ -270,7 +270,7 @@ _display(void *data, void *id)
270 if (!app->playing) 270 if (!app->playing)
271 return; 271 return;
272 272
273 _send_cmd(EM_RESULT_FRAME_NEW); 273 _send_cmd(app, EM_RESULT_FRAME_NEW);
274} 274}
275 275
276static void * 276static void *
@@ -298,7 +298,7 @@ _play(struct _App *app)
298 if (!app->mp) 298 if (!app->mp)
299 return; 299 return;
300 300
301 _em_read_safe(STDIN_FILENO, &pos, sizeof(pos)); 301 _em_read_safe(app->em_read, &pos, sizeof(pos));
302 302
303 if (app->playing) 303 if (app->playing)
304 { 304 {
@@ -325,14 +325,14 @@ _send_file_closed(struct _App *app)
325{ 325{
326 app->closing = 0; 326 app->closing = 0;
327 emotion_generic_shm_free(app->vs); 327 emotion_generic_shm_free(app->vs);
328 _send_cmd(EM_RESULT_FILE_CLOSE); 328 _send_cmd(app, EM_RESULT_FILE_CLOSE);
329} 329}
330 330
331static void 331static void
332_send_file_set(struct _App *app) 332_send_file_set(struct _App *app)
333{ 333{
334 if (app->opening) 334 if (app->opening)
335 _send_cmd(EM_RESULT_FILE_SET); 335 _send_cmd(app, EM_RESULT_FILE_SET);
336 336
337 if (app->closing) 337 if (app->closing)
338 _send_file_closed(app); 338 _send_file_closed(app);
@@ -346,26 +346,26 @@ _event_cb(const struct libvlc_event_t *ev, void *data)
346 346
347 switch (ev->type) { 347 switch (ev->type) {
348 case libvlc_MediaPlayerTimeChanged: 348 case libvlc_MediaPlayerTimeChanged:
349 _send_time_changed(ev); 349 _send_time_changed(app, ev);
350 break; 350 break;
351 case libvlc_MediaPlayerPositionChanged: 351 case libvlc_MediaPlayerPositionChanged:
352 thread_event = EM_THREAD_POSITION_CHANGED; 352 thread_event = EM_THREAD_POSITION_CHANGED;
353 write(app->fd_write, &thread_event, sizeof(thread_event)); 353 write(app->fd_write, &thread_event, sizeof(thread_event));
354 break; 354 break;
355 case libvlc_MediaPlayerLengthChanged: 355 case libvlc_MediaPlayerLengthChanged:
356 _send_length_changed(ev); 356 _send_length_changed(app, ev);
357 break; 357 break;
358 case libvlc_MediaPlayerSeekableChanged: 358 case libvlc_MediaPlayerSeekableChanged:
359 _send_seekable_changed(ev); 359 _send_seekable_changed(app, ev);
360 break; 360 break;
361 case libvlc_MediaPlayerPlaying: 361 case libvlc_MediaPlayerPlaying:
362 _send_resize(app->w, app->h); 362 _send_resize(app, app->w, app->h);
363 break; 363 break;
364 case libvlc_MediaPlayerStopped: 364 case libvlc_MediaPlayerStopped:
365 _send_file_set(app); 365 _send_file_set(app);
366 break; 366 break;
367 case libvlc_MediaPlayerEndReached: 367 case libvlc_MediaPlayerEndReached:
368 _send_cmd(EM_RESULT_PLAYBACK_STOPPED); 368 _send_cmd(app, EM_RESULT_PLAYBACK_STOPPED);
369 break; 369 break;
370 } 370 }
371} 371}
@@ -373,7 +373,7 @@ _event_cb(const struct libvlc_event_t *ev, void *data)
373static void 373static void
374_file_set(struct _App *app) 374_file_set(struct _App *app)
375{ 375{
376 _em_str_read(&app->filename); 376 _em_str_read(app->em_read, &app->filename);
377 377
378 app->m = libvlc_media_new_path(app->libvlc, app->filename); 378 app->m = libvlc_media_new_path(app->libvlc, app->filename);
379 if (!app->m) 379 if (!app->m)
@@ -411,7 +411,7 @@ _position_set(struct _App *app)
411 return; 411 return;
412 412
413 float position; 413 float position;
414 _em_read_safe(STDIN_FILENO, &position, sizeof(position)); 414 _em_read_safe(app->em_read, &position, sizeof(position));
415 415
416 libvlc_time_t new_time = position * 1000; 416 libvlc_time_t new_time = position * 1000;
417 libvlc_media_player_set_time(app->mp, new_time); 417 libvlc_media_player_set_time(app->mp, new_time);
@@ -425,7 +425,7 @@ _speed_set(struct _App *app)
425 if (!app->mp) 425 if (!app->mp)
426 return; 426 return;
427 427
428 _em_read_safe(STDIN_FILENO, &rate, sizeof(rate)); 428 _em_read_safe(app->em_read, &rate, sizeof(rate));
429 429
430 libvlc_media_player_set_rate(app->mp, rate); 430 libvlc_media_player_set_rate(app->mp, rate);
431} 431}
@@ -438,7 +438,7 @@ _mute_set(struct _App *app)
438 if (!app->mp) 438 if (!app->mp)
439 return; 439 return;
440 440
441 _em_read_safe(STDIN_FILENO, &mute, sizeof(mute)); 441 _em_read_safe(app->em_read, &mute, sizeof(mute));
442 442
443 libvlc_audio_set_mute(app->mp, mute); 443 libvlc_audio_set_mute(app->mp, mute);
444} 444}
@@ -452,7 +452,7 @@ _volume_set(struct _App *app)
452 if (!app->mp) 452 if (!app->mp)
453 return; 453 return;
454 454
455 _em_read_safe(STDIN_FILENO, &volume, sizeof(volume)); 455 _em_read_safe(app->em_read, &volume, sizeof(volume));
456 vol = volume * 100; 456 vol = volume * 100;
457 457
458 libvlc_audio_set_volume(app->mp, vol); 458 libvlc_audio_set_volume(app->mp, vol);
@@ -463,7 +463,7 @@ _audio_track_set(struct _App *app)
463{ 463{
464 int track; 464 int track;
465 465
466 _em_read_safe(STDIN_FILENO, &track, sizeof(track)); 466 _em_read_safe(app->em_read, &track, sizeof(track));
467 467
468 libvlc_audio_set_track(app->mp, track); 468 libvlc_audio_set_track(app->mp, track);
469} 469}
@@ -484,9 +484,9 @@ _file_set_done(struct _App *app)
484 app->filename = NULL; 484 app->filename = NULL;
485 app->m = NULL; 485 app->m = NULL;
486 app->mp = NULL; 486 app->mp = NULL;
487 _send_cmd_start(EM_RESULT_FILE_SET_DONE); 487 _send_cmd_start(app, EM_RESULT_FILE_SET_DONE);
488 SEND_CMD_PARAM(r); 488 SEND_CMD_PARAM(app, r);
489 _send_cmd_finish(); 489 _send_cmd_finish(app);
490 } 490 }
491 app->w = app->vs->width; 491 app->w = app->vs->width;
492 app->h = app->vs->height; 492 app->h = app->vs->height;
@@ -505,9 +505,9 @@ _file_set_done(struct _App *app)
505 505
506 libvlc_audio_set_mute(app->mp, 0); 506 libvlc_audio_set_mute(app->mp, 0);
507 507
508 _send_cmd_start(EM_RESULT_FILE_SET_DONE); 508 _send_cmd_start(app, EM_RESULT_FILE_SET_DONE);
509 SEND_CMD_PARAM(r); 509 SEND_CMD_PARAM(app, r);
510 _send_cmd_finish(); 510 _send_cmd_finish(app);
511} 511}
512 512
513static void 513static void
@@ -534,7 +534,7 @@ _file_close(struct _App *app)
534static void 534static void
535_process_emotion_commands(struct _App *app) 535_process_emotion_commands(struct _App *app)
536{ 536{
537 int cmd = _em_cmd_read(); 537 int cmd = _em_cmd_read(app);
538 switch (cmd) { 538 switch (cmd) {
539 case EM_CMD_FILE_SET: 539 case EM_CMD_FILE_SET:
540 _file_set(app); 540 _file_set(app);
@@ -570,27 +570,27 @@ _process_emotion_commands(struct _App *app)
570} 570}
571 571
572static void 572static void
573_send_track_info(libvlc_media_player_t *mp) 573_send_track_info(struct _App *app)
574{ 574{
575 int track_count, current; 575 int track_count, current;
576 libvlc_track_description_t *desc; 576 libvlc_track_description_t *desc;
577 577
578 current = libvlc_audio_get_track(mp); 578 current = libvlc_audio_get_track(app->mp);
579 track_count = libvlc_audio_get_track_count(mp); 579 track_count = libvlc_audio_get_track_count(app->mp);
580 desc = libvlc_audio_get_track_description(mp); 580 desc = libvlc_audio_get_track_description(app->mp);
581 581
582 _send_cmd_start(EM_RESULT_AUDIO_TRACK_INFO); 582 _send_cmd_start(app, EM_RESULT_AUDIO_TRACK_INFO);
583 SEND_CMD_PARAM(current); 583 SEND_CMD_PARAM(app, current);
584 SEND_CMD_PARAM(track_count); 584 SEND_CMD_PARAM(app, track_count);
585 while (desc) 585 while (desc)
586 { 586 {
587 int tid = desc->i_id; 587 int tid = desc->i_id;
588 const char *name = desc->psz_name; 588 const char *name = desc->psz_name;
589 SEND_CMD_PARAM(tid); 589 SEND_CMD_PARAM(app, tid);
590 _send_cmd_str(name); 590 _send_cmd_str(app, name);
591 desc = desc->p_next; 591 desc = desc->p_next;
592 } 592 }
593 _send_cmd_finish(); 593 _send_cmd_finish(app);
594} 594}
595 595
596static void 596static void
@@ -604,10 +604,10 @@ _position_changed(struct _App *app)
604 r = libvlc_video_get_size(app->mp, 0, &w, &h); 604 r = libvlc_video_get_size(app->mp, 0, &w, &h);
605 if (r < 0) 605 if (r < 0)
606 return; 606 return;
607 _send_resize(w, h); 607 _send_resize(app, w, h);
608 608
609 /* sending audio track info */ 609 /* sending audio track info */
610 // _send_track_info(app->mp); 610 // _send_track_info(app);
611 611
612 libvlc_media_player_stop(app->mp); 612 libvlc_media_player_stop(app->mp);
613} 613}
@@ -657,6 +657,18 @@ main(int argc, const char *argv[])
657 chroma 657 chroma
658 }; 658 };
659 659
660 if (argc < 3)
661 {
662 fprintf(stderr, "player: missing paramters.\n");
663 fprintf(stderr, "syntax:\n\t%s <fd read> <fd write>\n", argv[0]);
664 return -1;
665 }
666
667 app.em_read = atoi(argv[1]);
668 app.em_write = atoi(argv[2]);
669
670 fprintf(stderr, "reading commands from fd: %d, writing on fd: %d\n", app.em_read, app.em_write);
671
660 int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv); 672 int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
661 snprintf(cwidth, sizeof(cwidth), "%d", DEFAULTWIDTH); 673 snprintf(cwidth, sizeof(cwidth), "%d", DEFAULTWIDTH);
662 snprintf(cheight, sizeof(cheight), "%d", DEFAULTHEIGHT); 674 snprintf(cheight, sizeof(cheight), "%d", DEFAULTHEIGHT);
@@ -684,23 +696,23 @@ main(int argc, const char *argv[])
684 app.playing = 0; 696 app.playing = 0;
685 app.closing = 0; 697 app.closing = 0;
686 698
687 if (_em_cmd_read() != EM_CMD_INIT) 699 if (_em_cmd_read(&app) != EM_CMD_INIT)
688 { 700 {
689 fprintf(stderr, "player: wrong init command!\n"); 701 fprintf(stderr, "player: wrong init command!\n");
690 return -1; 702 return -1;
691 } 703 }
692 704
693 int size; 705 int size;
694 _em_read_safe(STDIN_FILENO, &size, sizeof(size)); 706 _em_read_safe(app.em_read, &size, sizeof(size));
695 _em_read_safe(STDIN_FILENO, buf, size); 707 _em_read_safe(app.em_read, buf, size);
696 app.shmname = strdup(buf); 708 app.shmname = strdup(buf);
697 709
698 _send_cmd(EM_RESULT_INIT); 710 _send_cmd(&app, EM_RESULT_INIT);
699 711
700 pipe(tpipe); 712 pipe(tpipe);
701 app.fd_read = tpipe[0]; 713 app.fd_read = tpipe[0];
702 app.fd_write = tpipe[1]; 714 app.fd_write = tpipe[1];
703 fds[0].fd = STDIN_FILENO; 715 fds[0].fd = app.em_read;
704 fds[0].events = POLLIN; 716 fds[0].events = POLLIN;
705 fds[1].fd = app.fd_read; 717 fds[1].fd = app.fd_read;
706 fds[1].events = POLLIN; 718 fds[1].events = POLLIN;