forked from zillevdr/vdr-plugin-softhddevice-drm
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsofthdmenu.cpp
More file actions
522 lines (471 loc) · 12.7 KB
/
Copy pathsofthdmenu.cpp
File metadata and controls
522 lines (471 loc) · 12.7 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
// SPDX-License-Identifier: AGPL-3.0-or-later
/**
* @file softhdmenu.cpp
* Plugin Main Menu
*
* @copyright 2020 zille. All Rights Reserved.
* @copyright 2025 - 2026 by Andreas Baierl. All Rights Reserved.
*
* @license{AGPL-3.0-or-later}
*/
#include <string>
#include <vdr/interface.h>
#include <vdr/osdbase.h>
#include <vdr/plugin.h>
#include <vdr/videodir.h>
#include "logger.h"
#include "mediaplayer.h"
#include "softhddevice.h"
#include "softhdmenu.h"
/**
* Build main or playlist menu
*/
cSoftHdMenu::cSoftHdMenu(const char *title, cSoftHdDevice *device,
int c0, int c1, int c2, int c3, int c4)
: cOsdMenu(title, c0, c1, c2, c3, c4),
m_pDevice(device)
{
pSoftHdMenu = this;
m_playlist.clear();
if (cSoftHdControl::Control() && cSoftHdControl::Control()->Player()->GetFirstPlaylistEntry()) {
LOGDEBUG2(L_MEDIA, "mediaplayer: %s: pointer to cSoftHdControl exist.", __FUNCTION__);
PlayListMenu(); // Test if PL!!!
} else {
MainMenu();
}
}
cSoftHdMenu::~cSoftHdMenu()
{
pSoftHdMenu = NULL;
}
/**
* Create a seperator item
*
* @param label text inside separator
*
* @ingroup menu
*/
static inline cOsdItem *SeparatorName(const char *label)
{
return new cOsdItem(cString::sprintf("%s:", label), osUnknown, false);
}
/**
* Create a seperator item
*
* @param label text inside separator
*
* @ingroup menu
*/
static inline cOsdItem *SeparatorSpace(void)
{
return new cOsdItem(" ", osUnknown, false);
}
/**
* Create main menu
*/
void cSoftHdMenu::MainMenu(void)
{
int current;
current = Current(); // get current menu item index
Clear(); // clear the menu
// pip
if (m_pDevice->UsePip()) {
Add(SeparatorName("PIP"));
Add(new cOsdItem(hk(tr(" Toggle")), osUser1));
Add(new cOsdItem(hk(tr(" Channel +")), osUser2));
Add(new cOsdItem(hk(tr(" Channel -")), osUser3));
Add(new cOsdItem(hk(tr(" Swap channels")), osUser4));
Add(new cOsdItem(hk(tr(" Swap position")), osUser5));
Add(new cOsdItem(hk(tr(" Switch to pip channel")), osUser6));
}
Add(SeparatorSpace());
// detach
Add(SeparatorName("Detach"));
Add(new cOsdItem(hk(tr(" Detach device")), osUser7));
Add(SeparatorSpace());
// mediaplayer
Add(SeparatorName("Mediaplayer"));
Add(new cOsdItem(hk(tr(" play file / make play list")), osUser8));
Add(new cOsdItem(hk(tr(" select play list")), osUser9));
SetCurrent(Get(current)); // restore selected menu entry
Display();
}
/**
* Hotkeys
*
* @ingroup menu
*/
enum Hotkeys {
PIPKEYBASE = 100,
PIPTOGGLEONOFF,
PIPCHANNELUP,
PIPCHANNELDOWN,
PIPCHANNELSWAP,
PIPPOSITIONSWAP,
PIPCHANNELSWITCHBACK,
DETACHKEYBASE = 110,
DETACHDEVICE,
ATTACHDEVICE
};
/**
* Handle a key code which was compose by hotkey handling in ProcessKey()
*
* @param code hotkey code to handle (see enum Hotkeys)
*/
void cSoftHdMenu::HandleHotKey(int code) {
switch (code) {
// pip
case PIPTOGGLEONOFF:
m_pDevice->PipToggle();
break;
case PIPCHANNELUP:
m_pDevice->PipChannelChange(1);
break;
case PIPCHANNELDOWN:
m_pDevice->PipChannelChange(-1);
break;
case PIPCHANNELSWAP:
m_pDevice->PipChannelSwap(false);
break;
case PIPPOSITIONSWAP:
m_pDevice->PipSwapPosition();
break;
case PIPCHANNELSWITCHBACK:
m_pDevice->PipChannelSwap(true);
break;
// detach/ attach
case DETACHDEVICE:
m_pDevice->Detach();
break;
case ATTACHDEVICE:
m_pDevice->Attach();
break;
default:
break;
}
}
/**
* Handle key event
*
* @param key key event
*/
eOSState cSoftHdMenu::ProcessKey(eKeys key)
{
eOSState state;
cOsdItem *item;
switch (m_hotkeyState) {
case HotkeyState::Initial:
if (key == kBlue) {
if (!m_pDevice->UsePip())
return osEnd;
m_hotkeyState = HotkeyState::Blue;
return osContinue;
}
if (key == kRed) {
m_hotkeyState = HotkeyState::Red;
return osContinue;
}
break;
case HotkeyState::Blue: // pip
if (k0 <= key && key <= k9) {
int hotkeyCode = static_cast<int>(PIPKEYBASE) + static_cast<int>(key) - static_cast<int>(k0);
m_hotkeyState = HotkeyState::Initial;
HandleHotKey(hotkeyCode);
return osEnd;
}
m_hotkeyState = HotkeyState::Initial;
break;
case HotkeyState::Red: // detach/ attach
if (k0 <= key && key <= k9) {
int hotkeyCode = static_cast<int>(DETACHKEYBASE) + static_cast<int>(key) - static_cast<int>(k0);
m_hotkeyState = HotkeyState::Initial;
HandleHotKey(hotkeyCode);
return osEnd;
}
m_hotkeyState = HotkeyState::Initial;
break;
}
item = (cOsdItem *) Get(Current());
state = cOsdMenu::ProcessKey(key);
switch (state) {
// pip
case osUser1: // toggle pip
m_pDevice->PipToggle();
return osEnd;
case osUser2: // pip channel +
m_pDevice->PipChannelChange(1);
return osEnd;
case osUser3: // pip channel -
m_pDevice->PipChannelChange(-1);
return osEnd;
case osUser4: // pip channel swap
m_pDevice->PipChannelSwap(false);
return osEnd;
case osUser5: // pip position swap
m_pDevice->PipSwapPosition();
return osEnd;
case osUser6: // pip switch main stream back to pip stream and close pip
m_pDevice->PipChannelSwap(true);
return osEnd;
// detach
case osUser7: // detach device
m_pDevice->Detach();
return osEnd;
// mediaplayer
case osUser8: // play file / make play list
m_path = cVideoDirectory::Name();
FindFileMenu(m_path, NULL);
return osContinue;
case osUser9: // select play list
m_path = cPlugin::ConfigDirectory("softhddevice-drm-gles");
SelectPlaylistMenu();
return osContinue;
default:
break;
}
switch (key) {
case kOk:
if (strcasestr(item->Text(), "[..]")) {
std::string newPath = m_path.substr(0 ,m_path.find_last_of("/"));
if (!m_lastItem.empty())
m_lastItem.clear();
m_lastItem = m_path.substr(m_path.find_last_of("/") + 1);
m_path = newPath;
FindFileMenu(m_path.c_str(), NULL);
break;
}
if (cSoftHdControl::Control() && cSoftHdControl::Control()->Player()->GetCurrentPlaylistEntry()) {
cSoftHdControl::Control()->Player()->SetEntry(Current());
// PlayListMenu();
break;
}
if (IsValidMediaFile(item->Text())) {
PlayMedia(item->Text());
return osEnd;
} else {
std::string newPath = m_path + "/" + item->Text();
struct stat sb;
if (stat(newPath.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
m_path = newPath;
FindFileMenu(newPath.c_str(), NULL);
}
}
break;
case kRed:
if (cSoftHdControl::Control() && cSoftHdControl::Control()->Player()->GetCurrentPlaylistEntry()) {
cSoftHdControl::Control()->Player()->ToggleRandomPlay();
PlayListMenu();
break;
}
if (m_playlist.empty()) {
if (IsValidMediaFile(item->Text())) {
PlayMedia(item->Text());
return osEnd;
}
} else {
m_path = cPlugin::ConfigDirectory("softhddevice-drm-gles");
PlayMedia(m_playlist.c_str());
return osEnd;
}
break;
case kGreen:
if (cSoftHdControl::Control()) {
cSoftHdControl::Control()->Player()->JumpSec(-60);
} else {
MakePlayList(item->Text(), "w");
Interface->Confirm(tr("New Playlist"), 1, true);
if (!m_lastItem.empty())
m_lastItem.clear();
m_lastItem = item->Text();
FindFileMenu(m_path.c_str(), NULL);
}
break;
case kYellow:
if (cSoftHdControl::Control()) {
cSoftHdControl::Control()->Player()->JumpSec(60);
} else {
MakePlayList(item->Text(), "a");
Interface->Confirm(tr("Added to Playlist"), 1, true);
}
break;
case kBlue:
state = osStopReplay;
break;
case kPlay:
if (IsValidMediaFile(item->Text())) {
PlayMedia(item->Text());
return osEnd;
}
break;
case kNext:
if (cSoftHdControl::Control())
cSoftHdControl::Control()->Player()->Stop();
break;
default:
break;
}
return state;
}
/*****************************************************************************
* Mediaplayer sub menus
****************************************************************************/
/**
* Create mediaplayer playlist menu
*/
void cSoftHdMenu::PlayListMenu(void)
{
cPlaylistEntry *entry = cSoftHdControl::Control()->Player()->GetFirstPlaylistEntry();
Clear();
while (1) {
std::string p_string = entry->OsdItemString();
Add(new cOsdItem(p_string.c_str()), (entry == cSoftHdControl::Control()->Player()->GetCurrentPlaylistEntry()));
if (!entry->GetNextEntry())
break;
entry = entry->GetNextEntry();
}
SetHelp(cSoftHdControl::Control()->Player()->IsRandomPlayActive() ? "Random Play" : " No Random Play",
"Jump -1 min", "Jump +1 min", "End player");
Display();
}
/**
* Create mediaplayer select playlist menu
*/
void cSoftHdMenu::SelectPlaylistMenu(void)
{
struct dirent **dirList;
int n, i;
if ((n = scandir(cPlugin::ConfigDirectory("softhddevice-drm-gles"), &dirList, NULL, alphasort)) == -1) {
LOGERROR("mediaplayer: %s: searching PL in %s failed (%d): %m", __FUNCTION__,
cPlugin::ConfigDirectory("softhddevice-drm-gles"), errno);
return;
}
Clear();
for (i = 0; i < n; i++) {
if (dirList[i]->d_name[0] != '.' && (strcasestr(dirList[i]->d_name, ".M3U"))) {
Add(new cOsdItem(dirList[i]->d_name));
}
}
SetHelp("Play PL", NULL, NULL, NULL);
Display();
}
/**
* Create mediaplayer sub menu find file or make a play list
*
* @param searchPath path to start search mediafile
* @param playlist if there is a play list write to play list else make a new menu
*/
void cSoftHdMenu::FindFileMenu(std::string searchPath, FILE *playlist)
{
struct dirent **dirList;
int n, i;
const char * sp;
if (!searchPath.size())
sp = "/";
else
sp = searchPath.c_str();
if (!playlist) {
Clear();
if (searchPath.size())
Add(new cOsdItem("[..]"));
}
if ((n = scandir(sp, &dirList, NULL, alphasort)) == -1) {
LOGERROR("mediaplayer: %s: scanning directory %s failed (%d): %m", __FUNCTION__, sp, errno);
} else {
struct stat fileAttributs;
for (i = 0; i < n; i++) {
std::string str = searchPath + "/" + dirList[i]->d_name;
if (stat(str.c_str(), &fileAttributs) == -1) {
LOGERROR("mediaplayer: %s: stat on %s failed (%d): %m", __FUNCTION__, str.c_str(), errno);
} else {
if (S_ISDIR(fileAttributs.st_mode) && dirList[i]->d_name[0] != '.') {
if (playlist) {
FindFileMenu(str.c_str(), playlist);
} else {
Add(new cOsdItem(dirList[i]->d_name),
!m_lastItem.compare(0, m_lastItem.length(), dirList[i]->d_name));
}
}
}
}
for (i = 0; i < n; i++) {
std::string str = searchPath + "/" + dirList[i]->d_name;
if (stat(str.c_str(), &fileAttributs) == -1) {
LOGERROR("mediaplayer: %s: stat on %s failed (%d): %m", __FUNCTION__, str.c_str(), errno);
} else {
if (S_ISREG(fileAttributs.st_mode) && dirList[i]->d_name[0] != '.') {
if (playlist) {
if (IsValidMediaFile(dirList[i]->d_name))
fprintf(playlist, "%s/%s\n", searchPath.c_str(),
dirList[i]->d_name);
} else {
Add(new cOsdItem(dirList[i]->d_name));
}
}
}
}
}
if (!playlist) {
SetHelp( m_playlist.empty() ? "Play File" : "Play PL", "New PL", "Add to PL", NULL);
// SetHelp(Control->Player->Running ? NULL : "Set new PL",
// Control->Player->Running ? "Play Menu" : "Select PL");
Display();
}
}
/**
* Make a play list
*
* @param target path to start search mediafiles
* @param mode open file mode
*/
void cSoftHdMenu::MakePlayList(const char * target, const char * mode)
{
if (m_playlist.empty())
m_playlist = "/default.m3u";
std::string plPath = cPlugin::ConfigDirectory("softhddevice-drm-gles");
plPath.append(m_playlist.c_str());
FILE *playlist = fopen(plPath.c_str(), mode);
if (!playlist)
return;
if (IsValidMediaFile(target)) {
fprintf(playlist, "%s/%s\n", m_path.c_str(), target);
} else {
std::string str = m_path + "/" + target;
FindFileMenu(str.c_str(), playlist);
}
fclose (playlist);
}
/**
* Play media file
*
* @param name file name
*/
void cSoftHdMenu::PlayMedia(const char *name)
{
std::string aim = m_path + "/" + name;
if (!cSoftHdControl::Control()) {
cControl::Launch(new cSoftHdControl(aim.c_str(), m_pDevice));
} else {
LOGERROR("mediaplayer: %s: can't start %s", __FUNCTION__, aim.c_str());
}
}
/**
* Test if it's a media file - at least if it has the right file extension...
*
* @param name file name
* @return true if it's a media file
*/
bool cSoftHdMenu::IsValidMediaFile(const char *name)
{
if (strcasestr(name, ".MP3") ||
strcasestr(name, ".MP4") ||
strcasestr(name, ".MKV") ||
strcasestr(name, ".MPG") ||
strcasestr(name, ".AVI") ||
strcasestr(name, ".M2TS") ||
strcasestr(name, ".MPEG") ||
strcasestr(name, ".M3U") ||
strcasestr(name, ".TS")) {
return true;
}
return false;
}