emotion/generic: Fix frame dropping.
authorantognolli <antognolli>
Mon, 5 Sep 2011 21:52:18 +0000 (21:52 +0000)
committerantognolli <antognolli@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 5 Sep 2011 21:52:18 +0000 (21:52 +0000)
Move the frame drop counter to the shared memory object, so the player
can check its value and not send new frames if we didn't "consume" the
previous one.

Also move the triple buffering pointer changing to the display function,
so it will only lock once when accessing the critical region.

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/emotion@63220 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/examples/emotion_generic_example.c
src/generic_players/vlc/emotion_generic_vlc.c
src/modules/generic/Emotion_Generic_Plugin.h
src/modules/generic/emotion_generic.c

index 33c1686..bef1501 100644 (file)
@@ -95,6 +95,11 @@ _on_key_down(void *data, Evas *e, Evas_Object *o, void *event_info)
      {
        evas_object_del(em);
      }
+   else if (!strcmp(ev->keyname, "l"))
+     {
+       // force frame dropping
+       sleep(5);
+     }
    else
      {
        fprintf(stderr, "unhandled key: %s\n", ev->keyname);
index b3e1eb1..dfa0962 100644 (file)
@@ -253,17 +253,6 @@ _lock(void *data, void **pixels)
 static void
 _unlock(void *data, void *id, void *const *pixels)
 {
-   struct _App *app = data;
-
-   if (!app->playing)
-     return;
-
-   sem_wait(&app->vs->lock);
-   app->vs->frame.last = app->vs->frame.player;
-   app->vs->frame.player = app->vs->frame.next;
-   app->vs->frame.next = app->vs->frame.last;
-
-   sem_post(&app->vs->lock);
 }
 
 static void
@@ -273,7 +262,13 @@ _display(void *data, void *id)
    if (!app->playing)
      return;
 
-   _send_cmd(app, EM_RESULT_FRAME_NEW);
+   sem_wait(&app->vs->lock);
+   app->vs->frame.last = app->vs->frame.player;
+   app->vs->frame.player = app->vs->frame.next;
+   app->vs->frame.next = app->vs->frame.last;
+   if (!app->vs->frame_drop++)
+     _send_cmd(app, EM_RESULT_FRAME_NEW);
+   sem_post(&app->vs->lock);
 }
 
 static void *
index b418ebc..cb0a399 100644 (file)
@@ -89,6 +89,7 @@ struct _Emotion_Generic_Video_Shared
        int next;
    } frame;
    sem_t lock;
+   int frame_drop;
 };
 
 inline int
index eee92bd..d8876e0 100644 (file)
@@ -173,6 +173,7 @@ _create_shm_data(Emotion_Generic_Video *ev, const char *shmname)
    vs->frame.player = 1;
    vs->frame.last = 2;
    vs->frame.next = 2;
+   vs->frame_drop = 0;
    sem_init(&vs->lock, 1, 1);
    ev->frame.frames[0] = (unsigned char *)vs + sizeof(*vs);
    ev->frame.frames[1] = (unsigned char *)vs + sizeof(*vs) + vs->height * vs->width * vs->pitch;
@@ -190,8 +191,7 @@ _player_new_frame(Emotion_Generic_Video *ev)
 {
    if (ev->opening || ev->closing)
      return;
-   if (!ev->drop++)
-     _emotion_frame_new(ev->obj);
+   _emotion_frame_new(ev->obj);
 }
 
 static void
@@ -1103,6 +1103,10 @@ em_bgra_data_get(void *data, unsigned char **bgra_data)
      }
    *bgra_data = ev->frame.frames[ev->shared->frame.emotion];
 
+   if (ev->shared->frame_drop > 1)
+     WRN("dropped frames: %d", ev->shared->frame_drop - 1);
+   ev->shared->frame_drop = 0;
+
    // unlock frame here
    sem_post(&ev->shared->lock);
    ev->drop = 0;