vdr-plugin-drmdevice 2.0.0-46418f1
plugindrmdevice.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
17#include <libintl.h>
18
19#include <vdr/player.h>
20#include <vdr/plugin.h>
21
22#include "logger.h"
23
24#include "config.h"
25#include "device.h"
26#include "mediaplayer.h"
27#include "menu.h"
28#include "plugindrmdevice.h"
29#include "setupmenu.h"
30
36/*****************************************************************************
37 * Static variables
38 ****************************************************************************/
39static const char *const VERSION = "2.0.0" GIT_DESCRIBE;
42
43static const char *const DESCRIPTION = trNOOP("A DRM/KMS based output device");
45
46static const char *const MAINMENUENTRY = trNOOP("DRMDevice");
48
50
53/*****************************************************************************
54 * cPluginDrmDevice
55 ****************************************************************************/
56
70{
72 m_pDevice = new cOutputDevice(m_pConfig); // no need to delete m_pDevice, because VDR does it for us
73}
74
84
91{
92 return VERSION;
93}
94
101{
102 return tr(DESCRIPTION);
103}
104
111{
112 return " -a device\taudio device (e.g. alsa: hw:0,0)\n"
113 " -c channel\taudio mixer channel name (e.g. PCM)\n"
114 " -o device\tdrm device (e.g. /dev/dri/card0)\n"
115 " -d resolution\tdisplay resolution (e.g. 1920x1080@50)\n"
116 " -g resolution\tosd resolution (e.g. 1920x1080)\n"
117 " -D start in detached state\n"
118 " -w workaround\tenable/disable workarounds\n"
119#ifdef USE_GLES
120 "\tdisable-ogl-osd disable openGL osd\n"
121#endif
122 "\tdisable-pip disable picture-in-picture\n"
123 "\n";
124}
125
133{
134// LOGDEBUG("plugin: %s:", __FUNCTION__);
135
136 //
137 // Parse arguments.
138 //
139
140 for (;;) {
141#ifdef USE_GLES
142 switch (getopt(argc, argv, "-a:c:o:x:d:g:Dw:")) {
143#else
144 switch (getopt(argc, argv, "-a:c:o:x:d:g:D")) {
145#endif
146 case 'a': // audio device for pcm
148 continue;
149 case 'c': // channel of audio mixer
151 continue;
152 case 'o': // set display drm device
154 continue;
155 case 'x': // set display drm connector
157 continue;
158 case 'd': { // set display output
160 int w = 0;
161 int h = 0;
162 double rate = 0.0;
163 if (sscanf(m_pConfig->ConfigDisplayResolution, "%dx%d@%lf", &w, &h, &rate) != 3) {
164 fprintf(stderr, gettext("Wring argument for option '%c'\n"), optopt);
165 return 0;
166 }
167 m_pConfig->UserSetDrmMode = { w, h, rate, false };
168 continue;
169 }
170 case 'g': // set osd (rendering) size
172 continue;
173 case 'D': // start plugin in detached state
175 continue;
176 case 'w': // workarounds
177 if (!strcasecmp("disable-pip", optarg)) {
179#ifdef USE_GLES
180 } else if (!strcasecmp("disable-ogl-osd", optarg)) {
182#endif
183 } else {
184 fprintf(stderr, gettext("Workaround '%s' unsupported\n"),
185 optarg);
186 return 0;
187 }
188 continue;
189 case EOF:
190 break;
191 case '-':
192 fprintf(stderr, gettext("We need no long options\n"));
193 return 0;
194 case ':':
195 fprintf(stderr, gettext("Missing argument for option '%c'\n"), optopt);
196 return 0;
197 default:
198 fprintf(stderr, gettext("Unknown option '%c'\n"), optopt);
199 return 0;
200 }
201 break;
202 }
203
204 while (optind < argc) {
205 fprintf(stderr, gettext("Unhandled argument '%s'\n"), argv[optind++]);
206 }
207
208 return 1;
209}
210
217{
218// LOGDEBUG("plugin: %s:", __FUNCTION__);
219
220 return m_pDevice->Initialize();
221}
222
227{
228// LOGDEBUG("plugin: %s:", __FUNCTION__);
229
230 return m_pDevice->Start();
231}
232
239{
240 //LOGDEBUG("plugin: %s:", __FUNCTION__);
241
242 m_pDevice->Stop();
243}
244
249{
250 //LOGDEBUG("plugin: %s:", __FUNCTION__);
251
253}
254
259{
260 //LOGDEBUG("plugin: %s:", __FUNCTION__);
261
262 return new cDeviceMenu("DRMDevice", m_pDevice);
263}
264
268cMenuSetupPage *cPluginDrmDevice::SetupMenu(void)
269{
270 //LOGDEBUG("plugin: %s:", __FUNCTION__);
271
272 return new cDeviceSetupMenu(m_pDevice);
273}
274
275/*****************************************************************************
276 * cPluginDrmDevice - Setup parameters
277 ****************************************************************************/
278
288bool cPluginDrmDevice::SetupParse(const char *name, const char *value)
289{
290 return m_pConfig->SetupParse(name, value);
291}
292
300bool cPluginDrmDevice::Service(const char *id, void *data)
301{
302 //LOGDEBUG("plugin: %s: id %s", __FUNCTION__, id);
303 (void)id;
304 (void)data;
305
306 return false;
307}
308
309/*****************************************************************************
310 * cPluginDrmDevice - SVDRP
311 ****************************************************************************/
312
318static const char *SVDRPHelpText[] = {
319 "PLAY Url\n" " Play the media from the given url.\n",
320 "DETA\n" " Detach the plugin.\n",
321 "ATTA\n" " Attach the plugin.\n",
322 "STAT\n" " Get attached/detached status.\n"
323 " ATTACHED -> 910\n"
324 " DETACHED -> 911\n",
325 "PION\n" " Enable picture-in-picture.\n",
326 "PIOF\n" " Disable picture-in-picture.\n",
327 "PITO\n" " Toggle picture-in-picture.\n",
328 "PIPU\n" " Pip channel up.\n",
329 "PIPD\n" " Pip channel down.\n",
330 "PIPC\n" " Pip swap channels.\n",
331 "PIPS\n" " Pip switch main stream to pip channel and close pip.\n",
332 "PIIP\n" " Pip swap positions.\n",
333 NULL
334};
335
343{
344 return SVDRPHelpText;
345}
346
355{
356 // mediaplayer
357 if (!strcasecmp(command, "PLAY")) {
358 LOGDEBUG2(L_MEDIA, "plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
359 cControl::Launch(new cDrmDeviceControl(option, m_pDevice));
360 return "PLAY url";
361 }
362
363 // attach/detach
364 if (!strcasecmp(command, "DETA")) {
365 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
366 if (m_pDevice->IsDetached())
367 return "DRMDevice is already detached";
368
369 m_pDevice->Detach();
370 return "Detached DRMDevice";
371 }
372 if (!strcasecmp(command, "ATTA")) {
373 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
374 if (!m_pDevice->IsDetached())
375 return "DRMDevice is not detached";
376
377 m_pDevice->Attach();
378 return "Attached DRMDevice";
379 }
380 if (!strcasecmp(command, "STAT")) {
381 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
382 if (!m_pDevice->IsDetached()) {
383 reply_code = 910;
384 return "DRMDevice is attached";
385 } else {
386 reply_code = 911;
387 return "DRMDevice is detached";
388 }
389 }
390
391 // pip
392 if (m_pDevice->UsePip()) {
393 if (!strcasecmp(command, "PION")) {
394 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
395 if (m_pDevice->PipIsEnabled())
396 return "Pip is already enabled";
397
399 return "Pip was enabled";
400 }
401 if (!strcasecmp(command, "PIOF")) {
402 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
403 if (!m_pDevice->PipIsEnabled())
404 return "Pip isn't enabled";
405
407 return "Pip was disabled";
408 }
409 if (!strcasecmp(command, "PITO")) {
410 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
411 if (!m_pDevice->PipIsEnabled()) {
413 return "Pip was enabled";
414 } else {
416 return "Pip was disabled";
417 }
418 }
419 if (!strcasecmp(command, "PIPU")) {
420 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
421 if (!m_pDevice->PipIsEnabled())
422 return "Pip isn't enabled";
423
425 return "Pip channel up";
426 }
427 if (!strcasecmp(command, "PIPD")) {
428 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
429 if (!m_pDevice->PipIsEnabled())
430 return "Pip isn't enabled";
431
433 return "Pip channel down";
434 }
435 if (!strcasecmp(command, "PIPC")) {
436 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
437 if (!m_pDevice->PipIsEnabled())
438 return "Pip isn't enabled";
439
441 return "Pip swap channels";
442 }
443 if (!strcasecmp(command, "PIPS")) {
444 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
445 if (!m_pDevice->PipIsEnabled())
446 return "Pip isn't enabled";
447
449 return "Pip switch main stream to pip channel and close pip";
450 }
451 if (!strcasecmp(command, "PIPP")) {
452 LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
453 if (!m_pDevice->PipIsEnabled())
454 return "Pip isn't enabled";
455
457 return "Pip swap position";
458 }
459 }
460
461 return NULL;
462}
463
464VDRPLUGINCREATOR(cPluginDrmDevice); // Don't touch this!
Plugin Configuration.
Definition config.h:65
const char * ConfigOsdResolution
osd resolution (syntax: "1920x1080")
Definition config.h:133
sDrmMode UserSetDrmMode
user requested drm mode on the current connector
Definition config.h:149
const char * ConfigDrmDevice
user requested drm device (e.g. "/dev/dri/card0")
Definition config.h:131
const char * ConfigDisplayResolution
display resolution (syntax: "1920x1080@50")
Definition config.h:132
bool ConfigHideMainMenuEntry
config hide main menu entry
Definition config.h:72
const char * ConfigAudioMixerChannel
audio mixer channel name
Definition config.h:129
const char * ConfigAudioPCMDevice
audio PCM device
Definition config.h:128
const char * ConfigDrmConnector
user requested drm connector (e.g. "HDMI-A-1")
Definition config.h:130
bool SetupParse(const char *, const char *)
Parse setup parameters.
Definition config.cpp:33
Plugin Main Menu.
Definition menu.h:43
Plugin Setup Menu.
Definition setupmenu.h:28
Media Player Control.
Output Device Implementation.
Definition device.h:72
void PipChannelChange(int)
Definition device.cpp:1452
void Detach(void)
Detach the device.
Definition device.cpp:1343
bool UsePip(void)
Definition device.h:197
void Stop(void)
Called by VDR when the plugin is stopped.
Definition device.cpp:119
void PipDisable(void)
Definition device.cpp:1450
void Attach(void)
Attach the device again.
Definition device.cpp:1365
bool Initialize(void)
Initialize the device.
Definition device.cpp:84
void PipChannelSwap(bool)
Definition device.cpp:1453
void PipEnable(void)
Definition device.cpp:1449
bool PipIsEnabled(void)
Returns true, if pip is currently enabled.
Definition device.cpp:1442
bool IsDetached(void) const
Returns true, if the device is detached.
Definition device.cpp:1380
void SetDisablePip(void)
Definition device.h:201
void SetDisableOglOsd(void)
Disables OpenGL/ES Osd (called from setup menu or conf)
Definition device.cpp:1141
void SetStartDetached(void)
Definition device.h:191
void PipSwapPosition(void)
Definition device.cpp:1454
int Start(void)
Called by VDR when the plugin is started.
Definition device.cpp:108
Main Plugin Class.
virtual bool Start(void)
Start any background activities the plugin shall perform.
virtual const char * Version(void)
Return plugin version number.
cPluginDrmDevice(void)
cPluginDrmDevice constructor
virtual cString SVDRPCommand(const char *, const char *, int &)
Handle SVDRP commands.
virtual bool SetupParse(const char *, const char *)
Parse setup parameters.
virtual const char * Description(void)
Return plugin short description.
cDeviceConfig * m_pConfig
pointer to cDeviceConfig object
virtual const char * CommandLineHelp(void)
Return a string that describes all known command line options.
virtual cMenuSetupPage * SetupMenu(void)
Return our setup menu.
virtual bool Initialize(void)
Initializes the DVB devices.
virtual ~cPluginDrmDevice(void)
cPluginDrmDevice destructor
virtual bool Service(const char *, void *=nullptr)
Receive requests or messages.
cOutputDevice * m_pDevice
pointer to cOutputDevice object
virtual const char ** SVDRPHelpPages(void)
Return SVDRP commands help pages.
virtual const char * MainMenuEntry(void)
Create main menu entry.
virtual bool ProcessArgs(int, char *[])
Process the command line arguments.
virtual void Stop(void)
Shutdown plugin.
virtual cOsdObject * MainMenuAction(void)
Perform the action when selected from the main VDR menu.
Plugin Configuration Header File.
Output Device Header File.
#define LOGDEBUG2
log to LOG_DEBUG and add a prefix
Definition logger.h:48
#define LOGDEBUG
log to LOG_DEBUG
Definition logger.h:46
@ L_MEDIA
mediaplayer logs
Definition logger.h:68
static const char *const DESCRIPTION
vdr-plugin description.
static const char * SVDRPHelpText[]
SVDRP commands help text.
static cDeviceMenu * pMenu
Main Menu Instance.
Definition menu.h:47
static const char *const MAINMENUENTRY
what is displayed in the main menu entry
static const char *const VERSION
vdr-plugin version number Makefile extracts the version number for generating the file name for the d...
Logger Header File.
Mediaplayer Header File.
Plugin Main Menu Header File.
VDRPLUGINCREATOR(cPluginDrmDevice)
Main Plugin Interface Header File.
#define GIT_DESCRIBE
Plugin Setup Menu Header File.