X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fplayer.c;h=018661f95140c95da05bfb410d8b53bdfa3ab4c8;hb=cb12ad94e4a4f01eb2b76b045dfdfa38db311883;hp=bd456b66684b34e8e98984033707e9e47854d32f;hpb=3022037d61a5e41f1e89f53b53708fec33c9bac7;p=melted_gui diff --git a/src/player.c b/src/player.c index bd456b6..018661f 100644 --- a/src/player.c +++ b/src/player.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -34,80 +35,166 @@ #include #include +#if defined(__MINGW32__) +#include +#endif + #include "player.h" +#include "ui.h" +#include "timecode.h" +#include "playlist.h" -static void* player_thread_proc(void* data) +static char* status_to_text(mvcp_status status) { - int r; - int playlist_start_prev = 0; -// OmPlrStatus st_curr, st_prev; - player_t* player = (player_t*)data; - - g_warning("omnplay_thread_proc\n"); + switch(status->status) + { + case unit_offline: return "offline"; break; + case unit_undefined: return "undefined"; break; + case unit_not_loaded: return "unloaded"; break; + case unit_stopped: return "stopped"; break; + case unit_playing: return "playing"; break; + case unit_paused: return "paused"; break; + case unit_disconnected: return "disconnect"; break; + case unit_unknown: return "unknown"; break; + } + return "unknown"; +} + +typedef struct player_handle_desc +{ + mvcp_parser parser; + mvcp command; + mvcp status; +} player_handle_t; -// memset(&st_curr, 0, sizeof(OmPlrStatus)); -// memset(&st_prev, 0, sizeof(OmPlrStatus)); +static void player_update_status(player_t* player, mvcp_status_t *status_prev , mvcp_status_t *status_curr, + int *playlist_start_prev) +{ + int idx; + char tc_cur[32], tc_rem[32], *state, status[32], *clip; - /* connect */ - pthread_mutex_lock(&player->app->players.lock); -// r = OmPlrOpen(player->host, player->name, (OmPlrHandle*)&player->handle); - pthread_mutex_unlock(&player->app->players.lock); - if(r) + if(status_curr->status == unit_disconnected) + { + tc_cur[0] = 0; + tc_rem[0] = 0; + clip = ""; + state = ""; + strcpy(status, "OFFLINE"); + } + else { -// g_warning("ERROR: OmPlrOpen(%s, %s) failed with 0x%.8X\n", -// player->host, player->name, r); + int p = status_curr->start + (status_curr->position - status_curr->in); - return (void*)r; + frames2tc(p, 25.0, tc_cur); + frames2tc(status_curr->dur - p, 25.0, tc_rem); + clip = strrchr(status_curr->clip, '/'); + if(clip) + clip++; + else + clip = status_curr->clip; + state = status_to_text(status_curr); + strcpy(status, "ONLINE"); }; - /* setup to do not reconnect */ - pthread_mutex_lock(&player->app->players.lock); -// OmPlrSetRetryOpen((OmPlrHandle)player->handle, 0); - pthread_mutex_unlock(&player->app->players.lock); + ui_update_player(player, tc_cur, tc_rem, state, status, clip); - /* setup directory */ -// if(player->app->players.path[0]) + /* update remaining time of playlist's item */ + pthread_mutex_lock(&player->app->playlist.lock); + pthread_mutex_lock(&player->app->players.lock); + if(player->playlist_length) { - pthread_mutex_lock(&player->app->players.lock); -// r = OmPlrClipSetDirectory((OmPlrHandle)player->handle, player->app->players.path); - pthread_mutex_unlock(&player->app->players.lock); + /* clear remain on "previous" item */ + if((status_curr->clip_index != status_prev->clip_index && 1 != player->playlist_length) || + (*playlist_start_prev != player->playlist_start)) + { + tc_rem[0] = 0; + idx = playlist_item_index /* find_index_of_playlist_item */(player->app, *playlist_start_prev, status_prev->clip_index); + if(idx >= 0) + ui_playlist_draw_item_rem(player->app, idx, tc_rem); + }; - if(r) + /* update current item */ + idx = playlist_item_index /* find_index_of_playlist_item */(player->app, player->playlist_start, status_curr->clip_index); + if(idx >= 0) { -// g_warning("ERROR: OmPlrClipSetDirectory(%s) failed with 0x%.8X\n", -// player->app->players.path, r); + /* reset value */ + tc_rem[0] = 0; - pthread_mutex_lock(&player->app->players.lock); -// OmPlrClose((OmPlrHandle)player->handle); - pthread_mutex_unlock(&player->app->players.lock); + /* for play and cue calc new value */ + if(/*status_curr->status == unit_stopped || */ status_curr->status == unit_playing || status_curr->status == unit_paused) + frames2tc(status_curr->out - status_curr->position, 25.0, tc_rem); - return (void*)r; + /* setup that value */ + ui_playlist_draw_item_rem(player->app, idx, tc_rem); }; }; + pthread_mutex_unlock(&player->app->players.lock); + pthread_mutex_unlock(&player->app->playlist.lock); +}; + +static void* player_thread_proc(void* data) +{ + int r, f; + int playlist_start_prev = 0; + 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->status); - /* endless loop */ - for(r = 0 ; !player->app->f_exit && !r;) + 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)); + + /* endless reconnect loop */ + for(; !player->app->f_exit;) { - /* sleep */ -#ifdef _WIN32 - Sleep(100); + r = mvcp_connect(handle->command); + /* connect */ + if(mvcp_ok != r) + { + g_warning("player_thread_proc: failed to connect to server %s:%d (player=%d, unit=%d), r=%d\n", + player->app->players.host, player->app->players.port, player->idx, player->unit, r); +#if defined(__MINGW32__) + Sleep(1000); #else - usleep(100000); + sleep(1); #endif + continue; + }; - /* get status */ - pthread_mutex_lock(&player->app->players.lock); -// st_curr.size = sizeof(OmPlrStatus); -// r = OmPlrGetPlayerStatus((OmPlrHandle)player->handle, &st_curr); - pthread_mutex_unlock(&player->app->players.lock); + g_warning("player_thread_proc: connected to server %s (player=%d, unit=%d)\n", + player->app->players.host, player->idx, player->unit); - if(r) - g_warning("ERROR: OmPlrGetPlayerStatus failed with 0x%.8X\n", r); - else + /* status request loop */ + for(r = 0, f = 0; !player->app->f_exit && !r;) { -// omnplay_update_status(player, &st_prev , &st_curr, &playlist_start_prev); -// playlist_start_prev = player->playlist_start; -// memcmp(&st_curr, &st_prev, sizeof(OmPlrStatus)); + int c; + + /* wait for any event from notifier */ + mvcp_notifier_wait(notifier, &status_curr); + + /* get status for our unit */ + if(player->unit != status_curr.unit) + mvcp_notifier_get(notifier, &status_curr, player->unit); + + /* notify about exit from loop and reconnect */ + if(status_curr.status == unit_disconnected) + { + r = 1; + continue; + }; + + /* do we need to update status */ + c = memcmp(&status_curr, &status_prev, sizeof(mvcp_status_t)); + if(!c && f) + continue; + + /* 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; }; }; @@ -121,14 +208,21 @@ static void* player_thread_proc(void* data) void player_run(instance_t* app, int idx) { - mvcp_parser parser = mvcp_parser_init_remote(app->players.host, 5250); - mvcp command = mvcp_init(parser); - + player_handle_t* handle = malloc(sizeof(player_handle_t)); + handle->parser = mvcp_parser_init_remote(app->players.host, app->players.port); + 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); }; 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->status); + mvcp_close(handle->command); + mvcp_parser_close(handle->parser); + free(handle); };