Repository navigation
Expand file tree
/
Copy pathplugindrmdevice.cpp
More file actions
617 lines (554 loc) · 17.1 KB
/
Copy pathplugindrmdevice.cpp
File metadata and controls
617 lines (554 loc) · 17.1 KB
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
// SPDX-License-Identifier: AGPL-3.0-or-later
/**
* @file plugindrmdevice.cpp
* Main Plugin Interface
*
* This file defines cPluginDrmDevice, which is the main class
* for initializing the plugin itselft.
*
* @copyright 2011, 2015 by Johns. All Rights Reserved.
* @copyright 2018 zille. All Rights Reserved.
* @copyright 2025 - 2026 by Andreas Baierl. All Rights Reserved.
*
* @license{AGPL-3.0-or-later}
*/
#include <algorithm>
#include <cstdlib>
#include <iterator>
#include <libintl.h>
#include <vdr/channels.h>
#include <vdr/player.h>
#include <vdr/plugin.h>
#include <vdr/remote.h>
#include <vdr/skins.h>
#include "logger.h"
#include "config.h"
#include "device.h"
#include "mediaplayer.h"
#include "menu.h"
#include "plugindrmdevice.h"
#include "setupmenu.h"
/**
* @addtogroup plugin
* @{
*/
/*****************************************************************************
* Static variables
****************************************************************************/
static const char *const VERSION = "2.1.1" GIT_DESCRIBE; ///< vdr-plugin version number
///< Makefile extracts the version number for generating the file name
///< for the distribution archive.
static const char *const DESCRIPTION = trNOOP("A DRM/KMS based output device");
///< vdr-plugin description.
static const char *const MAINMENUENTRY = trNOOP("DRMDevice");
///< what is displayed in the main menu entry
cDeviceMenu *cDeviceMenu::pMenu = NULL; ///< Main Menu Instance
/** @} */
/*****************************************************************************
* cPluginDrmDevice
****************************************************************************/
/**
* cPluginDrmDevice constructor
*
* Initialize any member variables here.
*
* @note DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
* VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
*
* We only create the config and the device itself, because Plugin->SetupParse
* is done next and that one needs config to be available.
* SetupParse must not access any other objects!
*/
cPluginDrmDevice::cPluginDrmDevice(void)
{
m_pConfig = new cDeviceConfig();
m_pDevice = new cOutputDevice(m_pConfig); // no need to delete m_pDevice, because VDR does it for us
}
/**
* cPluginDrmDevice destructor
*
* Clean up after yourself!
*/
cPluginDrmDevice::~cPluginDrmDevice(void)
{
delete m_pConfig;
}
/**
* Return plugin version number
*
* @return the version number as constant string
*/
const char *cPluginDrmDevice::Version(void)
{
return VERSION;
}
/**
* Return plugin short description
*
* @return a short description as constant string
*/
const char *cPluginDrmDevice::Description(void)
{
return tr(DESCRIPTION);
}
/**
* Return a string that describes all known command line options
*
* @return the command line help as constant string
*/
const char *cPluginDrmDevice::CommandLineHelp(void)
{
return " -a device\taudio device (e.g. alsa: hw:0,0)\n"
" -c channel\taudio mixer channel name (e.g. PCM)\n"
" -o device\tdrm device (e.g. /dev/dri/card0)\n"
" -x connector\tdrm connector (e.g. HDMI-A-1)\n"
" -d resolution\tdisplay resolution (e.g. 1920x1080@50)\n"
" -g resolution\tosd resolution (e.g. 1920x1080)\n"
" -D start in detached state\n"
" -w workaround\tenable/disable workarounds\n"
#ifdef USE_GLES
"\tdisable-ogl-osd disable openGL osd\n"
#endif
"\tdisable-pip disable picture-in-picture\n"
"\n";
}
/**
* Process the command line arguments.
*
* @param argc number of arguments
* @param argv arguments vector
*/
bool cPluginDrmDevice::ProcessArgs(int argc, char *argv[])
{
// LOGDEBUG("plugin: %s:", __FUNCTION__);
//
// Parse arguments.
//
for (;;) {
switch (getopt(argc, argv, "-a:c:o:x:d:g:Dw:")) {
case 'a': // audio device for pcm
m_pConfig->ConfigAudioPCMDevice = optarg;
continue;
case 'c': // channel of audio mixer
m_pConfig->ConfigAudioMixerChannel = optarg;
continue;
case 'o': // set display drm device
m_pConfig->ConfigDrmDevice = optarg;
continue;
case 'x': // set display drm connector
m_pConfig->ConfigDrmConnector = optarg;
continue;
case 'd': { // set display output
m_pConfig->ConfigDisplayResolution = optarg;
int w = 0;
int h = 0;
double rate = 0.0;
if (sscanf(m_pConfig->ConfigDisplayResolution, "%dx%d@%lf", &w, &h, &rate) != 3) {
fprintf(stderr, gettext("Wrong argument for option '%c'\n"), 'd');
return 0;
}
m_pConfig->UserSetDrmMode = { w, h, rate, false };
continue;
}
case 'g': // set osd (rendering) size
m_pConfig->ConfigOsdResolution = optarg;
continue;
case 'D': // start plugin in detached state
m_pDevice->SetStartDetached();
continue;
case 'w': // workarounds
if (!strcasecmp("disable-pip", optarg)) {
m_pDevice->SetDisablePip();
#ifdef USE_GLES
} else if (!strcasecmp("disable-ogl-osd", optarg)) {
m_pDevice->SetDisableOglOsd();
#endif
} else {
fprintf(stderr, gettext("Workaround '%s' unsupported\n"),
optarg);
return 0;
}
continue;
case EOF:
break;
case '-':
fprintf(stderr, gettext("We need no long options\n"));
return 0;
case ':':
fprintf(stderr, gettext("Missing argument for option '%c'\n"), optopt);
return 0;
default:
fprintf(stderr, gettext("Unknown option '%c'\n"), optopt);
return 0;
}
break;
}
while (optind < argc) {
fprintf(stderr, gettext("Unhandled argument '%s'\n"), argv[optind++]);
}
return 1;
}
/**
* Initializes the DVB devices
*
* Must be called before accessing any DVB functions
*/
bool cPluginDrmDevice::Initialize(void)
{
// LOGDEBUG("plugin: %s:", __FUNCTION__);
return m_pDevice->Initialize();
}
/**
* Start any background activities the plugin shall perform
*/
bool cPluginDrmDevice::Start(void)
{
// LOGDEBUG("plugin: %s:", __FUNCTION__);
return m_pDevice->Start();
}
/**
* Shutdown plugin
*
* Stop any background activities the plugin is performing
*/
void cPluginDrmDevice::Stop(void)
{
//LOGDEBUG("plugin: %s:", __FUNCTION__);
m_pDevice->Stop();
}
/**
* Create main menu entry
*/
const char *cPluginDrmDevice::MainMenuEntry(void)
{
//LOGDEBUG("plugin: %s:", __FUNCTION__);
return m_pConfig->ConfigHideMainMenuEntry ? NULL : tr(MAINMENUENTRY);
}
/**
* Perform the action when selected from the main VDR menu
*/
cOsdObject *cPluginDrmDevice::MainMenuAction(void)
{
//LOGDEBUG("plugin: %s:", __FUNCTION__);
return new cDeviceMenu("DRMDevice", m_pDevice);
}
/**
* Main thread hook
*
* Closes the menu after a detach or attach with SVDRP: the menu wasn't shown
* while detached, so VDR would only close it with the next menu key instead
* of opening the menu. The menu key is put into the queue, because only the
* main thread may access the menu.
*/
void cPluginDrmDevice::MainThreadHook(void)
{
if (m_closeMenu.exchange(false) && dynamic_cast<cSkinDisplayMenu *>(cSkinDisplay::Current())) {
LOGDEBUG("plugin: %s: close the menu", __FUNCTION__);
cRemote::Put(kMenu);
}
}
/**
* Return our setup menu
*/
cMenuSetupPage *cPluginDrmDevice::SetupMenu(void)
{
//LOGDEBUG("plugin: %s:", __FUNCTION__);
return new cDeviceSetupMenu(m_pDevice);
}
/*****************************************************************************
* cPluginDrmDevice - Setup parameters
****************************************************************************/
/**
* Parse setup parameters
*
* @param name paramter name (case sensetive)
* @param value value as string
*
* @retval true if the parameter is supported
* @retval false if the parameter is unsupported
*/
bool cPluginDrmDevice::SetupParse(const char *name, const char *value)
{
return m_pConfig->SetupParse(name, value);
}
/**
* Receive requests or messages
*
* @param id unique identification string that identifies the
* service protocol
* @param data custom data structure
*/
bool cPluginDrmDevice::Service(const char *id, void *data)
{
//LOGDEBUG("plugin: %s: id %s", __FUNCTION__, id);
(void)id;
(void)data;
return false;
}
/*****************************************************************************
* cPluginDrmDevice - SVDRP
****************************************************************************/
/**
* SVDRP commands help text
*
* @ingroup plugin
*/
static const char *SVDRPHelpText[] = {
"PLAY Url\n" " Play the media from the given url.\n",
"DETA\n" " Detach the plugin.\n",
"ATTA\n" " Attach the plugin.\n",
"STAT\n" " Get attached/detached status.\n"
" ATTACHED -> 910\n"
" DETACHED -> 911\n",
"PION [channel]\n" " Enable picture-in-picture. The channel (number, channel ID or name)\n"
" is shown, otherwise the current channel. If pip is enabled, it\n"
" switches to the given channel.\n",
"PIOF\n" " Disable picture-in-picture.\n",
"PITO\n" " Toggle picture-in-picture.\n",
"PIPU\n" " Pip channel up.\n",
"PIPD\n" " Pip channel down.\n",
"PIPC\n" " Pip swap channels.\n",
"PIPS\n" " Pip switch main stream to pip channel and close pip.\n",
"PIPP\n" " Pip swap positions.\n",
"ZOOM [next | 0-5]\n" " Select the next zoom level (next) or the given level (0 = off).\n"
" Without an argument the active zoom level is returned.\n",
"PASS [on | off | toggle]\n" " Switch the audio passthrough on or off (not stored).\n"
" Without an argument the passthrough state is returned.\n",
NULL
};
/**
* Return SVDRP commands help pages
*
* return a pointer to a list of help strings for all of the plugin's
* SVDRP commands.
*/
const char **cPluginDrmDevice::SVDRPHelpPages(void)
{
return SVDRPHelpText;
}
/**
* Find a channel like VDR's SVDRP command CHAN does
*
* @param channel channel number, channel ID (e.g. "S19.2E-1-1019-10301") or
* channel name (not case sensitive)
*
* @return channel number (0, if there is no such channel)
*
* @ingroup plugin
*/
static int FindChannelNumber(const char *channel)
{
LOCK_CHANNELS_READ;
const cChannel *found = nullptr;
char *end;
long number = strtol(channel, &end, 10);
if (!*end && number > 0)
found = Channels->GetByNumber(number);
else if (!(found = Channels->GetByChannelID(tChannelID::FromString(channel)))) {
for (const cChannel *c = Channels->First(); c && !found; c = Channels->Next(c)) {
if (!c->GroupSep() && !strcasecmp(c->Name(), channel))
found = c;
}
}
return found && !found->GroupSep() ? found->Number() : 0;
}
/**
* Handle SVDRP commands
*
* @param command SVDRP command
* @param option all command arguments
* @param reply_code reply code
*/
cString cPluginDrmDevice::SVDRPCommand(const char *command, const char *option, int &reply_code)
{
// mediaplayer
if (!strcasecmp(command, "PLAY")) {
LOGDEBUG2(L_MEDIA, "plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!option || !*option) {
reply_code = 501;
return "Missing url";
}
if (m_pDevice->IsDetached()) {
reply_code = 550;
return "DRMDevice is detached";
}
cControl::Launch(new cDrmDeviceControl(option, m_pDevice));
return "PLAY url";
}
// attach/detach
if (!strcasecmp(command, "DETA")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (m_pDevice->IsDetached()) {
reply_code = 550;
return "DRMDevice is already detached";
}
// the menu isn't shown any more, but VDR would close it with the next menu key
m_closeMenu = true;
m_pDevice->Detach();
return "Detached DRMDevice";
}
if (!strcasecmp(command, "ATTA")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!m_pDevice->IsDetached()) {
reply_code = 550;
return "DRMDevice is not detached";
}
m_pDevice->Attach();
// a menu, which was opened while detached, was never shown
m_closeMenu = true;
return "Attached DRMDevice";
}
if (!strcasecmp(command, "STAT")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!m_pDevice->IsDetached()) {
reply_code = 910;
return "DRMDevice is attached";
} else {
reply_code = 911;
return "DRMDevice is detached";
}
}
// zoom
if (!strcasecmp(command, "ZOOM")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (option && !strcasecmp(option, "next")) {
m_pDevice->NextZoomLevel();
} else if (option && *option) {
char *end;
long level = strtol(option, &end, 10);
if (*end || level < 0 || level > cDeviceConfig::ZOOM_LEVELS) {
reply_code = 501;
return cString::sprintf("Invalid zoom level '%s'", option);
}
if (!m_pDevice->SetZoomLevel(static_cast<int>(level))) {
reply_code = 550;
return cString::sprintf("Zoom level %ld is disabled in the setup", level);
}
}
int zoom = m_pDevice->GetZoom();
return zoom ? cString::sprintf("Zoom level %d (+%d.%d%%)", m_pDevice->GetZoomLevel(), zoom / 10, zoom % 10)
: cString("Zoom off");
}
// audio passthrough
if (!strcasecmp(command, "PASS")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (option && !strcasecmp(option, "on")) {
m_pDevice->SetPassthroughOn(true);
} else if (option && !strcasecmp(option, "off")) {
m_pDevice->SetPassthroughOn(false);
} else if (option && !strcasecmp(option, "toggle")) {
m_pDevice->TogglePassthrough();
} else if (option && *option) {
reply_code = 501;
return cString::sprintf("Invalid argument '%s'", option);
}
if (!m_pDevice->IsPassthroughOn())
return "Passthrough: off";
return m_pDevice->Config()->ConfigAudioPassthroughAuto ? "Passthrough: automatic" : "Passthrough: manual";
}
// pip
static const char *const pipCommands[] = { "PION", "PIOF", "PITO", "PIPU", "PIPD", "PIPC", "PIPS", "PIPP" };
bool isPipCommand = std::any_of(std::begin(pipCommands), std::end(pipCommands),
[command](const char *pipCommand) { return !strcasecmp(command, pipCommand); });
if (isPipCommand && !m_pDevice->UsePip()) {
reply_code = 550;
return m_pDevice->IsDetached() ? "DRMDevice is detached" : "Pip isn't available";
}
if (isPipCommand) {
if (!strcasecmp(command, "PION")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (option && *option) {
int channelNum = FindChannelNumber(option);
if (!channelNum) {
reply_code = 550;
return cString::sprintf("Unknown channel '%s'", option);
}
if (!m_pDevice->PipEnableChannel(channelNum)) {
reply_code = 554;
return cString::sprintf("Channel %d can't be received", channelNum);
}
return cString::sprintf("Pip shows channel %d", channelNum);
}
if (m_pDevice->PipIsEnabled()) {
reply_code = 550;
return "Pip is already enabled";
}
m_pDevice->PipEnable();
if (!m_pDevice->PipIsEnabled()) {
reply_code = 554;
return "The current channel can't be received for pip";
}
return "Pip was enabled";
}
if (!strcasecmp(command, "PIOF")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!m_pDevice->PipIsEnabled()) {
reply_code = 550;
return "Pip isn't enabled";
}
m_pDevice->PipDisable();
return "Pip was disabled";
}
if (!strcasecmp(command, "PITO")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!m_pDevice->PipIsEnabled()) {
m_pDevice->PipEnable();
if (!m_pDevice->PipIsEnabled()) {
reply_code = 554;
return "The current channel can't be received for pip";
}
return "Pip was enabled";
} else {
m_pDevice->PipDisable();
return "Pip was disabled";
}
}
if (!strcasecmp(command, "PIPU")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!m_pDevice->PipIsEnabled()) {
reply_code = 550;
return "Pip isn't enabled";
}
m_pDevice->PipChannelChange(1);
return "Pip channel up";
}
if (!strcasecmp(command, "PIPD")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!m_pDevice->PipIsEnabled()) {
reply_code = 550;
return "Pip isn't enabled";
}
m_pDevice->PipChannelChange(-1);
return "Pip channel down";
}
if (!strcasecmp(command, "PIPC")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!m_pDevice->PipIsEnabled()) {
reply_code = 550;
return "Pip isn't enabled";
}
m_pDevice->PipChannelSwap(false);
return "Pip swap channels";
}
if (!strcasecmp(command, "PIPS")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!m_pDevice->PipIsEnabled()) {
reply_code = 550;
return "Pip isn't enabled";
}
m_pDevice->PipChannelSwap(true);
return "Pip switch main stream to pip channel and close pip";
}
if (!strcasecmp(command, "PIPP")) {
LOGDEBUG("plugin: %s: SVDRPCommand: %s %s", __FUNCTION__, command, option);
if (!m_pDevice->PipIsEnabled()) {
reply_code = 550;
return "Pip isn't enabled";
}
m_pDevice->PipSwapPosition();
return "Pip swap position";
}
}
return NULL;
}
VDRPLUGINCREATOR(cPluginDrmDevice); // Don't touch this!