emotion/generic - Don't start opening new file when another one is being open.
authorantognolli <antognolli@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 5 Sep 2011 16:07:00 +0000 (16:07 +0000)
committerantognolli <antognolli@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 5 Sep 2011 16:07:00 +0000 (16:07 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/emotion@63203 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/generic_players/vlc/emotion_generic_vlc.c
src/modules/generic/emotion_generic.c
src/modules/generic/emotion_generic.h

index 425aeb4..a297931 100644 (file)
@@ -373,6 +373,13 @@ _event_cb(const struct libvlc_event_t *ev, void *data)
 static void
 _file_set(struct _App *app)
 {
+   if (app->opening)
+     {
+       libvlc_media_release(app->m);
+       libvlc_media_player_release(app->mp);
+       free(app->filename);
+     }
+
    _em_str_read(app->em_read, &app->filename);
 
    app->m = libvlc_media_new_path(app->libvlc, app->filename);
@@ -514,6 +521,9 @@ static void
 _file_close(struct _App *app)
 {
    app->playing = 0;
+   if (app->opening)
+     goto release_resources;
+
    if (libvlc_media_player_get_state(app->mp) != libvlc_Playing)
      {
        _send_file_closed(app);
@@ -521,6 +531,8 @@ _file_close(struct _App *app)
      }
 
    app->closing = 1;
+
+release_resources:
    libvlc_media_player_stop(app->mp);
    if (app->filename)
      free(app->filename);
index 3d8f1f0..c0dfe89 100644 (file)
@@ -193,17 +193,6 @@ _player_new_frame(Emotion_Generic_Video *ev)
 }
 
 static void
-_player_file_set_done(Emotion_Generic_Video *ev)
-{
-   if (!_create_shm_data(ev, ev->shmname))
-     {
-       ERR("could not create shared memory.");
-       return;
-     }
-   _player_send_cmd(ev, EM_CMD_FILE_SET_DONE);
-}
-
-static void
 _file_open(Emotion_Generic_Video *ev)
 {
    INF("Opening file: %s", ev->filename);
@@ -221,6 +210,24 @@ _file_open(Emotion_Generic_Video *ev)
 }
 
 static void
+_player_file_set_done(Emotion_Generic_Video *ev)
+{
+   if (ev->file_changed)
+     {
+       _file_open(ev);
+       ev->file_changed = EINA_FALSE;
+       return;
+     }
+
+   if (!_create_shm_data(ev, ev->shmname))
+     {
+       ERR("could not create shared memory.");
+       return;
+     }
+   _player_send_cmd(ev, EM_CMD_FILE_SET_DONE);
+}
+
+static void
 _player_ready(Emotion_Generic_Video *ev)
 {
    INF("received: player ready.");
@@ -460,10 +467,17 @@ _player_open_done(Emotion_Generic_Video *ev)
 {
    int success;
 
-   ev->opening = EINA_FALSE;
    _player_int_read(ev, &success);
-
    shm_unlink(ev->shmname);
+
+   if (ev->file_changed)
+     {
+       _file_open(ev);
+       ev->file_changed = EINA_FALSE;
+       return;
+     }
+
+   ev->opening = EINA_FALSE;
    if (!success)
      {
        ERR("Could not open file.");
@@ -761,10 +775,18 @@ em_file_open(const char *file, Evas_Object *obj __UNUSED__, void *data)
    INF("file set: %s", file);
    if (!ev) return 0;
 
+   eina_stringshare_replace(&ev->filename, file);
+
    ev->pos = 0;
-   ev->opening = EINA_TRUE;
 
-   eina_stringshare_replace(&ev->filename, file);
+   if (ev->ready && ev->opening)
+     {
+       INF("file changed while opening.");
+       ev->file_changed = EINA_TRUE;
+       return 1;
+     }
+
+   ev->opening = EINA_TRUE;
 
    if (!ev->closing)
      _file_open(ev);
@@ -783,6 +805,9 @@ em_file_close(void *data)
    if (!ev->filename)
      return;
 
+   if (ev->opening)
+     return;
+
    _player_send_cmd(ev, EM_CMD_FILE_CLOSE);
    ev->closing = EINA_TRUE;
 }
index 08084a5..30af7de 100644 (file)
@@ -56,6 +56,7 @@ struct _Emotion_Generic_Video
    Eina_Bool                seekable : 1;
    volatile Eina_Bool        opening : 1;
    volatile Eina_Bool        closing : 1;
+   Eina_Bool                file_changed : 1;
    int                      audio_channels_count;
    int                      audio_channel_current;
    struct _Emotion_Generic_Audio_Channel *audio_channels;