unit passing fixed, status update fixes
[melted_gui] / src / player.c
index 03746fa..b07723b 100644 (file)
@@ -38,6 +38,7 @@
 #include "player.h"
 #include "ui.h"
 #include "timecode.h"
+#include "playlist.h"
 
 static char* status_to_text(mvcp_status status)
 {
@@ -58,7 +59,8 @@ static char* status_to_text(mvcp_status status)
 typedef struct player_handle_desc
 {
     mvcp_parser parser;
-    mvcp conn;
+    mvcp command;
+    mvcp status;
 } player_handle_t;
 
 static void player_update_status(player_t* player, mvcp_status_t *status_prev , mvcp_status_t *status_curr,
@@ -81,7 +83,11 @@ static void player_update_status(player_t* player, mvcp_status_t *status_prev ,
 
         frames2tc(p, 25.0, tc_cur);
         frames2tc(status_curr->dur - p, 25.0, tc_rem);
-        clip = status_curr->clip;
+        clip = strrchr(status_curr->clip, '/');
+        if(clip)
+            clip++;
+        else
+            clip = status_curr->clip;
         state = status_to_text(status_curr);
         strcpy(status, "ONLINE");
     };
@@ -129,9 +135,9 @@ static void* player_thread_proc(void* data)
     mvcp_status_t status_curr, status_prev;
     player_t* player = (player_t*)data;
     player_handle_t* handle = player->handle;
-    mvcp_notifier notifier = mvcp_get_notifier(handle->conn);
+    mvcp_notifier notifier = mvcp_get_notifier(handle->status);
 
-    g_warning("player_thread_proc: started\n");
+    g_warning("player_thread_proc: started (player=%d, unit=%d)\n", player->idx, player->unit);
 
 //    memset(&st_curr, 0, sizeof(OmPlrStatus));
 //    memset(&st_prev, 0, sizeof(OmPlrStatus));
@@ -140,17 +146,22 @@ static void* player_thread_proc(void* data)
     for(; !player->app->f_exit;)
     {
         /* connect */
-        pthread_mutex_lock(&player->app->players.lock);
-        if(mvcp_connect(handle->conn) == mvcp_ok)
+        if(mvcp_connect(handle->command) == mvcp_ok)
         {
-            g_warning("player_thread_proc: failed to connect to server\n");
+            g_warning("player_thread_proc: failed to connect to server %s (player=%d, unit=%d)\n",
+                player->app->players.host, player->idx, player->unit);
             sleep(1);
             continue;
         };
 
+        g_warning("player_thread_proc: connected to server %s (player=%d, unit=%d)\n",
+            player->app->players.host, player->idx, player->unit);
+
         /* status request loop */
         for(r = 0, f = 0; !player->app->f_exit && !r;)
         {
+            int c;
+
             /* wait for any event from notifier */
             mvcp_notifier_wait(notifier, &status_curr);
 
@@ -160,17 +171,21 @@ static void* player_thread_proc(void* data)
 
             /* notify about exit from loop and reconnect */
             if(status_curr.status == unit_disconnected)
+            {
                 r = 1;
+                continue;
+            };
 
             /* do we need to update status */
-            if(!memcmp(&status_curr, &status_prev, sizeof(mvcp_status_t)) || !f)
-            {
-            };
+            c = memcmp(&status_curr, &status_prev, sizeof(mvcp_status_t));
+            if(!c && f)
+                continue;
 
-            f = 1;
+            /* call update func */
             player_update_status(player, &status_prev , &status_curr, &playlist_start_prev);
             playlist_start_prev = player->playlist_start;
             status_prev = status_curr;
+            f = 1;
         };
     };
 
@@ -186,7 +201,8 @@ void player_run(instance_t* app, int idx)
 {
     player_handle_t* handle = malloc(sizeof(player_handle_t));
     handle->parser = mvcp_parser_init_remote(app->players.host, 5250);
-    handle->conn = mvcp_init(handle->parser);
+    handle->status = mvcp_init(handle->parser);
+    handle->command = mvcp_init(handle->parser);
     app->players.item[idx].handle = handle;
     app->players.item[idx].thread = g_thread_create(
         player_thread_proc, &app->players.item[idx], TRUE, NULL);
@@ -196,7 +212,8 @@ void player_stop(instance_t* app, int idx)
 {
     player_handle_t* handle = app->players.item[idx].handle;
     g_thread_join(app->players.item[idx].thread);
-    mvcp_close(handle->conn);
+    mvcp_close(handle->status);
+    mvcp_close(handle->command);
     mvcp_parser_close(handle->parser);
     free(handle);
 };