1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
/*****************************************************************
* gmerlin - a general purpose multimedia framework and applications
*
* Copyright (c) 2001 - 2024 Members of the Gmerlin project
* http://github.com/bplaum
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* *****************************************************************/
#include <string.h>
#include <config.h>
#include <gmerlin/parameter.h>
#include <gmerlin/bgmsg.h>
#include <gmerlin/player.h>
#include <gmerlin/playermsg.h>
#include <gmerlin/frontend.h>
#include <gmerlin/bggavl.h>
#include <gmerlin/translation.h>
#include <gmerlin/log.h>
#define LOG_DOMAIN "consoleplayer"
typedef struct
{
int display_time;
int time_active;
gavl_time_t total_time;
bg_control_t ctrl;
} bg_player_frontend_console_t;
#if 1
static void print_time(bg_player_frontend_console_t * priv, gavl_time_t time)
{
if(!priv->display_time)
return;
bg_print_time(stderr, time, priv->total_time);
}
#endif
static int handle_player_message_console(void * data,
gavl_msg_t * msg)
{
bg_player_frontend_console_t * priv = data;
switch(msg->NS)
{
case BG_MSG_NS_STATE:
switch(msg->ID)
{
case BG_MSG_STATE_CHANGED:
{
gavl_value_t val;
const char * ctx;
const char * var;
gavl_value_init(&val);
gavl_msg_get_state(msg,
NULL,
&ctx,
&var,
&val, NULL);
if(!strcmp(ctx, BG_PLAYER_STATE_CTX))
{
if(!strcmp(var, BG_PLAYER_STATE_TIME)) // long
{
gavl_time_t t = GAVL_TIME_UNDEFINED;
if(!gavl_value_get_long(&val, &t))
return 1;
print_time(priv, t);
}
else if(!strcmp(var, BG_PLAYER_STATE_VOLUME)) // float
{
}
else if(!strcmp(var, BG_PLAYER_STATE_STATUS)) // int
{
int status;
if(!gavl_value_get_int(&val, &status))
return 1;
switch(status)
{
case BG_PLAYER_STATUS_STOPPED:
break;
case BG_PLAYER_STATUS_PLAYING:
gavl_log(GAVL_LOG_DEBUG, LOG_DOMAIN, "Player now playing");
break;
case BG_PLAYER_STATUS_SEEKING:
if(priv->time_active) { putc('\n', stderr); priv->time_active = 0; }
gavl_log(GAVL_LOG_DEBUG, LOG_DOMAIN, "Player now seeking");
break;
case BG_PLAYER_STATUS_CHANGING:
gavl_log(GAVL_LOG_DEBUG, LOG_DOMAIN, "Player now changing");
if(priv->time_active) { putc('\n', stderr); priv->time_active = 0; }
break;
case BG_PLAYER_STATUS_PAUSED:
break;
}
break;
}
else if(!strcmp(var, BG_PLAYER_STATE_CURRENT_TRACK)) // dictionary
{
const gavl_dictionary_t * m;
const gavl_dictionary_t * track;
if(!(track = gavl_value_get_dictionary(&val)) ||
!(m = gavl_track_get_metadata(track)))
return 1;
priv->total_time = GAVL_TIME_UNDEFINED;
gavl_dictionary_get_long(m, GAVL_META_APPROX_DURATION, &priv->total_time);
fprintf(stderr, "Track changed:\n");
gavl_dictionary_dump(m, 2);
fprintf(stderr, "\n");
}
else if(!strcmp(var, BG_PLAYER_STATE_MODE)) // int
{
}
else if(!strcmp(var, BG_PLAYER_STATE_AUDIO_STREAM_CURRENT)) // int
{
int val_i;
if(!gavl_value_get_int(&val, &val_i))
return 1;
fprintf(stderr, "Playing audio stream %d\n", val_i);
}
else if(!strcmp(var, BG_PLAYER_STATE_VIDEO_STREAM_CURRENT)) // int
{
int val_i;
if(!gavl_value_get_int(&val, &val_i))
return 1;
fprintf(stderr, "Playing video stream %d\n", val_i);
}
else if(!strcmp(var, BG_PLAYER_STATE_SUBTITLE_STREAM_CURRENT)) // int
{
int val_i;
if(!gavl_value_get_int(&val, &val_i))
return 1;
fprintf(stderr, "Playing subtitle stream %d\n", val_i);
}
}
}
break;
}
break;
case GAVL_MSG_NS_SRC:
switch(msg->ID)
{
}
break;
case BG_MSG_NS_PLAYER:
switch(msg->ID)
{
case BG_PLAYER_MSG_CLEANUP:
gavl_log(GAVL_LOG_DEBUG, LOG_DOMAIN, "Player cleaned up");
break;
}
break;
}
return 1;
}
static int ping_renderer_console(void * data)
{
int ret = 0;
bg_player_frontend_console_t * p = data;
/* Handle player message */
bg_msg_sink_iteration(p->ctrl.evt_sink);
ret += bg_msg_sink_get_num(p->ctrl.evt_sink);
return ret;
}
static void destroy_renderer_console(void * priv)
{
bg_player_frontend_console_t * p = priv;
bg_control_cleanup(&p->ctrl);
free(p);
}
static int open_renderer_console(void * data,
bg_controllable_t * ctrl)
{
bg_player_frontend_console_t * priv = data;
bg_control_init(&priv->ctrl, bg_msg_sink_create(handle_player_message_console, priv, 0));
bg_controllable_connect(ctrl, &priv->ctrl);
return 1;
}
static void * create_renderer_console()
{
bg_player_frontend_console_t * priv;
priv = calloc(1, sizeof(*priv));
priv->display_time = 1;
return priv;
}
bg_frontend_plugin_t the_plugin =
{
.common =
{
BG_LOCALE,
.name = "fe_renderer_console",
.long_name = TRS("Console frontend"),
.description = TRS("Console frontend for commandline applications"),
.type = BG_PLUGIN_FRONTEND_RENDERER,
.flags = BG_PLUGIN_NEEDS_TERMINAL,
.create = create_renderer_console,
.destroy = destroy_renderer_console,
.priority = 1,
},
.update = ping_renderer_console,
.open = open_renderer_console,
};
/* Include this into all plugin modules exactly once
to let the plugin loader obtain the API version */
BG_GET_PLUGIN_API_VERSION;
|