File: xine.c

package info (click to toggle)
vdr-plugin-xine 0.9.4-16
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,756 kB
  • sloc: ansic: 14,014; makefile: 86; sh: 34
file content (342 lines) | stat: -rw-r--r-- 8,213 bytes parent folder | download | duplicates (5)
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
 * xine.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include "xineCommon.h"

#include <vdr/plugin.h>

#include "xineDevice.h"
#include "xineSettings.h"
#include "xineSetupPage.h"



static const char *VERSION        = "0.9.4";
static const char *DESCRIPTION    = tr("Software based playback using xine");
//static const char *MAINMENUENTRY  = "xine - Toggle prebuffer setting";



class cPluginXine : public cPlugin {
private:
  // Add any member variables or functions you may need here.
  PluginXine::cXineSettings m_settings;

  PluginXine::cXineRemote *m_remote;
  bool m_remoteOn;
  
public:
  PluginXine::cXineLib *m_xineLib;
  int m_instanceNo;
  in_addr_t m_bindIp;
  int m_bindPort;
  
  cPluginXine(void);
  virtual ~cPluginXine();
  virtual const char *Version(void) { return VERSION; }
  virtual const char *Description(void) { return tr(DESCRIPTION); }
  virtual const char *CommandLineHelp(void);
  virtual bool ProcessArgs(int argc, char *argv[]);
  virtual bool Initialize(void);
  virtual bool Start(void);
  virtual void Stop(void);
  virtual void Housekeeping(void);
#if APIVERSNUM >= 10347
  virtual void MainThreadHook(void);
  virtual cString Active(void);
  virtual time_t WakeupTime(void);
#endif
  virtual const char *MainMenuEntry(void);// { return tr(MAINMENUENTRY); }
  virtual cOsdObject *MainMenuAction(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);
#if APIVERSNUM >= 10330
  virtual bool Service(const char *Id, void *Data = NULL);
  virtual const char **SVDRPHelpPages(void);
  virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
#endif
  };

cPluginXine::cPluginXine(void)
  : cPlugin()
  , m_remote(0)
  , m_remoteOn(false)
  , m_xineLib(0)
  , m_instanceNo(-1)
  , m_bindIp(0)
  , m_bindPort(0)
{
  // Initialize any member variables here.
  // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
  // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
}

cPluginXine::~cPluginXine()
{
  // Clean up after yourself!
}

const char *cPluginXine::CommandLineHelp(void)
{
  //Return a string that describes all known command line options.
  //"  -         --             x                                                   \n"
  return
    "  -bIP                     ip address to bind for socket connections (see -p)\n"
    "  -iN                      instance number to append to FIFO directory\n"
    "  -p[N]                    use socket connections on port N (18701)\n" 
    "  -q                       turn off debug messages on console\n"
    "  -r                       turn on remote (pressing keys in xine controls VDR)\n"
#if APIVERSNUM >= 10320
    "  -s                       switch to curses skin, while xine is disconnected\n"
#endif 
    "  -XN                      default 'SizeX' for GRAB command (720, 1..4096)\n"
    "  -YN                      default 'SizeY' for GRAB command (576, 1..4096)\n"
    ;
}

bool cPluginXine::ProcessArgs(int argc, char *argv[])
{
  // Implement command line argument processing here if applicable.

  ::optind = 0;
  ::opterr = 0;

#define INVALID_ARG(fmt, args...) do { esyslog(fmt, ##args); fprintf(stderr, fmt "\n", ##args); } while (false)

  for (int r = -1; (r = ::getopt(argc, argv, ":b:i:p::qrsX:Y:")) >= 0; )
  {
    switch (r)
    {
    case ':':
      INVALID_ARG("vdr-xine: missing argument for option -%c", ::optopt);
      return false;

    case 'b':
      m_bindIp = ::inet_addr(::optarg);
      if (m_bindIp == INADDR_NONE)
      {
        INVALID_ARG("vdr-xine: invalid argument '%s' for option -%c", ::optarg, r);
        return false;
      }
      break;

    case 'i':
      m_instanceNo = ::atoi(::optarg);
      if (m_instanceNo < 0)
      {
        INVALID_ARG("vdr-xine: invalid argument '%s' for option -%c", ::optarg, r);
        return false;
      }
      break;
      
    case 'p':
      if (!::optarg)
        m_bindPort = 18701;
      else
      {
        m_bindPort = ::atoi(::optarg);
        if (m_bindPort <= 0)
        {
          INVALID_ARG("vdr-xine: invalid argument '%s' for option -%c", ::optarg, r);
          return false;
        }
      }
      break;

    case 'r':
      m_remoteOn = true;
      break;

#if APIVERSNUM >= 10320      
    case 's':
      m_settings.SetSwitchSkin(true);
      break;
#endif

    case 'q':
      m_settings.SetBeQuiet(true);
      break;
      
    case 'X':
      {
        const int X = ::atoi(::optarg);
        if (X < 1 || X > 4096)
        {
          INVALID_ARG("vdr-xine: invalid argument '%s' for option -%c", ::optarg, r);
          return false;
        }
        
        m_settings.SetDefaultGrabSizeX(X);
      }
      break;

    case 'Y':
      {
        const int Y = ::atoi(::optarg);
        if (Y < 1 || Y > 4096)
        {
          INVALID_ARG("vdr-xine: invalid argument '%s' for option -%c", ::optarg, r);
          return false;
        }
        
        m_settings.SetDefaultGrabSizeY(Y);
      }
      break;

    default:
      INVALID_ARG("vdr-xine: invalid option -%c", r);
      return false;
    }
  }

  if (argv[::optind])
  {
    INVALID_ARG("vdr-xine: invalid argument '%s'", argv[::optind]);
    return false;
  }
  
#undef INVALID_ARG

  return true;
}

bool cPluginXine::Initialize(void)
{
#if APIVERSNUM < 10507
  RegisterI18n(PluginXine::Phrases);
#endif
  
  // Initialize any background activities the plugin shall perform.
  m_remote = new PluginXine::cXineRemote(m_remoteOn);
  if (!m_remote)
    return false;
  
  if (!PluginXine::cXineDevice::Create(this, m_settings, m_remote))
    return false;

  return true;
}

bool cPluginXine::Start(void)
{
  // Start any background activities the plugin shall perform.
  if (!PluginXine::cXineDevice::Open())
    return false;

  return true;
}

void cPluginXine::Stop(void)
{
  PluginXine::cXineDevice::Stop();
}

void cPluginXine::Housekeeping(void)
{
  // Perform any cleanup or other regular tasks.
}

#if APIVERSNUM >= 10347

void cPluginXine::MainThreadHook(void)
{
  // Perform actions in the context of the main program thread.
  // WARNING: Use with great care - see PLUGINS.html!

  PluginXine::cXineDevice::MainMenuTrampoline();
}

cString cPluginXine::Active(void)
{
  // Return a message string if shutdown should be postponed
  return NULL;
}

time_t cPluginXine::WakeupTime(void)
{
  // Return custom wakeup time for shutdown script
  return 0;
}

#endif

cOsdObject *cPluginXine::MainMenuAction(void)
{
  // Perform the action when selected from the main VDR menu.
#if APIVERSNUM < 10347
  PluginXine::cXineDevice::MainMenuTrampoline();
#endif
  return NULL;
}

cMenuSetupPage *cPluginXine::SetupMenu(void)
{
  // Return a setup menu in case the plugin supports one.
  return new PluginXine::cXineSetupPage(m_xineLib, m_settings);
}

bool cPluginXine::SetupParse(const char *Name, const char *Value)
{
  // Parse your own setup parameters and store their values.
  return m_settings.SetupParse(Name, Value);
}

#if APIVERSNUM >= 10330

bool cPluginXine::Service(const char *Id, void *Data)
{
  // Handle custom service requests from other plugins
  return cPlugin::Service(Id, Data);
}

const char **cPluginXine::SVDRPHelpPages(void)
{
  // Return help text for SVDRP commands this plugin implements
  return cPlugin::SVDRPHelpPages();
}

cString cPluginXine::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
  // Process SVDRP commands this plugin implements
  return cPlugin::SVDRPCommand(Command, Option, ReplyCode);
}

#endif

const char *cPluginXine::MainMenuEntry(void)
{
//  return m_settings.GetMainMenuEntry();
  return 0;
}

namespace PluginXine
{
  int GetBindIp(cPlugin *const plugin)
  {
    return ((cPluginXine *)plugin)->m_bindIp;
  }

  int GetBindPort(cPlugin *const plugin)
  {
    return ((cPluginXine *)plugin)->m_bindPort;
  }

  int GetInstanceNo(cPlugin *const plugin)
  {
    return ((cPluginXine *)plugin)->m_instanceNo;
  }

  cXineLib *&GetXineLib(cPlugin *const plugin)
  {
    return ((cPluginXine *)plugin)->m_xineLib;
  }
}



VDRPLUGINCREATOR(cPluginXine); // Don't touch this!