unit passing fixed, status update fixes
authorMaksym Veremeyenko <verem@m1stereo.tv>
Wed, 27 Jun 2012 14:00:36 +0000 (17:00 +0300)
committerMaksym Veremeyenko <verem@m1stereo.tv>
Wed, 27 Jun 2012 14:00:36 +0000 (17:00 +0300)
src/opts.c
src/player.c

index e993080..109ba1f 100644 (file)
@@ -34,7 +34,7 @@ static const char short_options [] = "h";
 static const struct option long_options [] =
 {
     { "host",                   required_argument,    NULL,   '0'},
-    { "player",                 required_argument,    NULL,   '1'},
+    { "unit",                   required_argument,    NULL,   '1'},
     { "help",                   no_argument,          NULL,   'h'},
     { 0,                        0,                    0,      0}
 };
@@ -68,7 +68,7 @@ int instance_opt(int argc, char** argv, instance_t* app)
                 strncpy(app->players.host, optarg, PATH_MAX);
                 break;
 
-            /** --player */
+            /** --unit */
             case '1':
                 app->players.item[app->players.count].unit = atol(optarg);
                 app->players.item[app->players.count].idx = app->players.count;
@@ -93,6 +93,6 @@ void instance_usage(void)
         stderr,
         "Usage:\n"
         "\t--host=<STRING>    Host name of melted server\n"
-        "\t--player=<INT>     Player to use (e.g. unit number)\n"
+        "\t--unit=<INT>       Player to use (e.g. unit number)\n"
     );
 };
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);
 };