summaryrefslogtreecommitdiff
path: root/xine_fbfe_frontend.c
blob: 06ab56b9fb95c0d01fa2725809c2c5b4afbd69be (plain)
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
 * xine_fbfe_frontend.c: Simple front-end, framebuffer functions
 *
 * See the main source file 'xineliboutput.c' for copyright information and
 * how to reach the author.
 *
 * $Id: xine_fbfe_frontend.c,v 1.12 2007-03-14 10:26:39 phintuka Exp $
 *
 */

#include <errno.h>
#include <inttypes.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <pthread.h>
#include <sched.h>

#ifdef boolean
# define HAVE_BOOLEAN
#endif
#include <jpeglib.h>
#undef boolean

#include <xine.h>
#ifndef XINE_ENGINE_INTERNAL
#  define XINE_ENGINE_INTERNAL
#  include <xine/xine_internal.h>
#  undef XINE_ENGINE_INTERNAL
#else
#  include <xine/xine_internal.h>
#endif
#include <xine/xineutils.h>
#include <xine/input_plugin.h>
#include <xine/plugin_catalog.h>

#include "xine_input_vdr.h"

#include "xine_frontend.h"
#include "xine/post.h"


/*
 * data
 */

typedef struct fbfe_t {

  /* function pointers */
  frontend_t         fe;
  void (*update_display_size)(frontend_t*);

  /* xine stuff */
  xine_t             *xine;
  xine_stream_t      *stream;
  input_plugin_t     *input;
  xine_video_port_t  *video_port;
  xine_video_port_t  *video_port_none;
  xine_audio_port_t  *audio_port;
  xine_audio_port_t  *audio_port_none;
  xine_event_queue_t *event_queue;

  post_plugins_t     *postplugins;

  char                configfile[256];

  int                 xine_visual_type;
  fb_visual_t         vis;

  double              display_ratio;
  int                 overscan;

  int                 pes_buffers;
  int                 aspect;
  int                 cropping;
  int                 scale_video;
  int                 priority;

  /* frontend */
  int                 playback_finished;
  int                 slave_playback_finished;

  /* vdr */
  fe_keypress_f       keypress;

  /* display */
  int                 display;
  int                 fullscreen;
  int                 vmode_switch;
  int                 field_order;
  char                modeline[256];

  int                 xpos, ypos;
  int                 width, height;

  int                 video_width, video_height;

} fe_t;

#define IS_FBFE
static char *fbdev = NULL;

/* Common (non-X11/FB) frontend functions */
#include "xine_frontend.c"

static void fbfe_update_display_size(frontend_t *this_gen)
{
  fe_t *this = (fe_t*)this_gen;
  if(this->fullscreen) {
    this->width  = this->video_port->get_property(this->video_port, 
						  VO_PROP_WINDOW_WIDTH);
    this->height = this->video_port->get_property(this->video_port, 
						  VO_PROP_WINDOW_HEIGHT);
    LOGDBG("Framebuffer size after initialization: %dx%d",
	   this->width, this->height);
  }
}

/*
 * fbfe_display_open
 */
static int fbfe_display_open(frontend_t *this_gen, int width, int height, int fullscreen,
			     int modeswitch, const char *modeline, int aspect,
			     fe_keypress_f keyfunc, const char *video_port,
			     int scale_video, int field_order) 
{
  fe_t *this = (fe_t*)this_gen;

  if(!this)
    return 0;

  if(this->display)
    this->fe.fe_display_close(this_gen);

  this->display = 1;
  if(keyfunc) {
    this->keypress = keyfunc;
    this->keypress("KBD", "");
  }

  LOGDBG("fbfe_display_open(width=%d, height=%d, fullscreen=%d, display=%s)",
	 width, height, fullscreen, video_port);

  this->xpos            = 0;
  this->ypos            = 0;
  this->width           = width;
  this->height          = height;
  this->fullscreen      = fullscreen;
  this->vmode_switch    = 0/*modeswitch*/;
  this->aspect          = aspect;
  this->cropping        = 0;
  this->field_order     = 0/*field_order ? 1 : 0*/;
  this->scale_video     = scale_video;
  this->overscan        = 0;
  strn0cpy(this->modeline, modeline, sizeof(this->modeline));
  this->display_ratio   = 1.0;

  this->xine_visual_type = XINE_VISUAL_TYPE_FB;
  this->vis.frame_output_cb = fe_frame_output_cb;
  this->vis.user_data = this;

  this->update_display_size = fbfe_update_display_size;

  if(video_port && *video_port && !strncmp(video_port, "/dev/", 5)) {
    fbdev = strdup(video_port);
  }

  return 1;
}

/*
 * fbfe_display_config
 *
 * configure windows
 */
static int fbfe_display_config(frontend_t *this_gen, int width, int height, int fullscreen, 
			       int modeswitch, const char *modeline, int aspect, 
			       int scale_video, int field_order) 
{
  fe_t *this = (fe_t*)this_gen;

  if(!this)
    return 0;

  if(this->width != width || this->height != height) {
    this->width           = width;
    this->height          = height;
  }

  if(fullscreen != this->fullscreen) {
    this->fullscreen = fullscreen;
  }

  if(!modeswitch && strcmp(modeline, this->modeline)) {
    strn0cpy(this->modeline, modeline, sizeof(this->modeline));
    /* XXX TODO - switch vmode */
#ifdef LOG
    LOGDBG("fbfe_display_config: TODO: switch vmode\n");fflush(stdout);
#endif
  }

  this->vmode_switch = modeswitch;
  this->aspect = aspect;
  this->scale_video = scale_video;
  this->field_order = field_order ? 1 : 0;
  return 1;
}

static void fbfe_interrupt(frontend_t *this_gen) 
{
  /* stop fbfe_run() */
}

static int fbfe_run(frontend_t *this_gen) 
{
  struct timeval tv;
  fe_t *this = (fe_t*)this_gen;

  if(this && this->playback_finished)
    return !this->playback_finished;

  tv.tv_sec = 0;
  tv.tv_usec = 500*1000;
  select(0, NULL, NULL, NULL, &tv); /* just sleep 500ms */

  return !(!this || this->playback_finished);
}

static void fbfe_display_close(frontend_t *this_gen) 
{
  fe_t *this = (fe_t*)this_gen;

  if(this) {
    this->display = 0;

    if(this->xine)
      this->fe.xine_exit(this_gen);
  }
}

static frontend_t *fbfe_get_frontend(void)
{
  fe_t *this = malloc(sizeof(fe_t));
  memset(this, 0, sizeof(fe_t));

  this->fe.fe_display_open   = fbfe_display_open;
  this->fe.fe_display_config = fbfe_display_config;
  this->fe.fe_display_close  = fbfe_display_close;

  this->fe.xine_init  = fe_xine_init;
  this->fe.xine_open  = fe_xine_open;
  this->fe.xine_play  = fe_xine_play;
  this->fe.xine_stop  = fe_xine_stop;
  this->fe.xine_close = fe_xine_close;
  this->fe.xine_exit  = fe_xine_exit;
  this->fe.xine_is_finished = fe_is_finished;

  this->fe.fe_run       = fbfe_run;
  this->fe.fe_interrupt = fbfe_interrupt;

  this->fe.fe_free      = fe_free;

  this->fe.grab                  = fe_grab;
#ifndef FE_STANDALONE
  this->fe.xine_osd_command      = xine_osd_command;
  this->fe.xine_control          = xine_control;

  this->fe.xine_queue_pes_packet = xine_queue_pes_packet;
#endif /*#ifndef FE_STANDALONE */

  return (frontend_t*)this;
}

/* ENTRY POINT */
const fe_creator_f fe_creator __attribute__((visibility("default"))) = fbfe_get_frontend;