mvcp protocol support embedded from melted project
[melted_gui] / src / player.c
1 /*
2 * player.h -- GTK+ 2 melted gui
3 * Copyright (C) 2012 Maksym Veremeyenko <verem@m1stereo.tv>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 #ifndef _GNU_SOURCE
20 #define _GNU_SOURCE
21 #endif
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <gtk/gtk.h>
31 #include <gdk/gdkkeysyms.h>
32 #include <pthread.h>
33
34 #include <mvcp/mvcp.h>
35 #include <mvcp/mvcp_remote.h>
36
37 #include "player.h"
38
39 static void* player_thread_proc(void* data)
40 {
41 int r;
42 int playlist_start_prev = 0;
43 // OmPlrStatus st_curr, st_prev;
44 player_t* player = (player_t*)data;
45
46 g_warning("omnplay_thread_proc\n");
47
48 // memset(&st_curr, 0, sizeof(OmPlrStatus));
49 // memset(&st_prev, 0, sizeof(OmPlrStatus));
50
51 /* connect */
52 pthread_mutex_lock(&player->app->players.lock);
53 // r = OmPlrOpen(player->host, player->name, (OmPlrHandle*)&player->handle);
54 pthread_mutex_unlock(&player->app->players.lock);
55 if(r)
56 {
57 // g_warning("ERROR: OmPlrOpen(%s, %s) failed with 0x%.8X\n",
58 // player->host, player->name, r);
59
60 return (void*)r;
61 };
62
63 /* setup to do not reconnect */
64 pthread_mutex_lock(&player->app->players.lock);
65 // OmPlrSetRetryOpen((OmPlrHandle)player->handle, 0);
66 pthread_mutex_unlock(&player->app->players.lock);
67
68 /* setup directory */
69 // if(player->app->players.path[0])
70 {
71 pthread_mutex_lock(&player->app->players.lock);
72 // r = OmPlrClipSetDirectory((OmPlrHandle)player->handle, player->app->players.path);
73 pthread_mutex_unlock(&player->app->players.lock);
74
75 if(r)
76 {
77 // g_warning("ERROR: OmPlrClipSetDirectory(%s) failed with 0x%.8X\n",
78 // player->app->players.path, r);
79
80 pthread_mutex_lock(&player->app->players.lock);
81 // OmPlrClose((OmPlrHandle)player->handle);
82 pthread_mutex_unlock(&player->app->players.lock);
83
84 return (void*)r;
85 };
86 };
87
88 /* endless loop */
89 for(r = 0 ; !player->app->f_exit && !r;)
90 {
91 /* sleep */
92 #ifdef _WIN32
93 Sleep(100);
94 #else
95 usleep(100000);
96 #endif
97
98 /* get status */
99 pthread_mutex_lock(&player->app->players.lock);
100 // st_curr.size = sizeof(OmPlrStatus);
101 // r = OmPlrGetPlayerStatus((OmPlrHandle)player->handle, &st_curr);
102 pthread_mutex_unlock(&player->app->players.lock);
103
104 if(r)
105 g_warning("ERROR: OmPlrGetPlayerStatus failed with 0x%.8X\n", r);
106 else
107 {
108 // omnplay_update_status(player, &st_prev , &st_curr, &playlist_start_prev);
109 // playlist_start_prev = player->playlist_start;
110 // memcmp(&st_curr, &st_prev, sizeof(OmPlrStatus));
111 };
112 };
113
114 pthread_mutex_lock(&player->app->players.lock);
115 // OmPlrClose((OmPlrHandle)player->handle);
116 pthread_mutex_unlock(&player->app->players.lock);
117
118 return NULL;
119 };
120
121
122 void player_run(instance_t* app, int idx)
123 {
124 mvcp_parser parser = mvcp_parser_init_remote(app->players.host, 5250);
125 mvcp command = mvcp_init(parser);
126
127 app->players.item[idx].thread = g_thread_create(
128 player_thread_proc, &app->players.item[idx], TRUE, NULL);
129 };
130
131 void player_stop(instance_t* app, int idx)
132 {
133 g_thread_join(app->players.item[idx].thread);
134 };