-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontrol.c
643 lines (595 loc) · 16.1 KB
/
control.c
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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
//////////////////////////////////////////////////////////////////////////////
/// ///
/// This file is part of the VDR mpv plugin and licensed under AGPLv3 ///
/// ///
/// See the README file for copyright information ///
/// ///
//////////////////////////////////////////////////////////////////////////////
#include "control.h"
#include "config.h"
#include <vdr/interface.h>
#include <vdr/videodir.h>
cMpvControl::cMpvControl(string Filename, bool Shuffle)
:cControl(Player = new cMpvPlayer(Filename.c_str(), Shuffle))
{
int w, h, x, y;
xcb_window_t window = 0;
xcb_connection_t *connect = NULL;
#ifdef DEBUG
dsyslog("[mpv] %s\n", __FUNCTION__);
#endif
DisplayReplay = NULL;
VolumeStatus = NULL;
if (!MpvPluginConfig->UsePassthrough)
VolumeStatus = new cMpvStatus(Player);
infoVisible = false;
timeSearchActive = false;
//for x11 get geometry from output plugin
if (strcmp(MpvPluginConfig->GpuCtx.c_str(),"drm") && strcmp(MpvPluginConfig->VideoOut.c_str(),"drm"))
{
Player->PlayerGetWindow("softhd", &connect, window, w, h, x, y);
if (connect && window)
{
Player->SetWindowSize(w, h, x, y);
xcb_flush(connect);
connect = NULL;
} else Player->SetWindowSize(0, 0, 0, 0);
}
cStatus::MsgReplaying(this, Filename.c_str(), Filename.c_str(), true);
}
cMpvControl::~cMpvControl()
{
#ifdef DEBUG
dsyslog("[mpv]%s\n", __FUNCTION__);
#endif
if (VolumeStatus)
delete VolumeStatus;
Hide();
Player->OsdClose();
// Osd Workaround
// osd is open, first send menu key, this will close the menu, if any other
// osd was open this opens the menu, so send kBack afterwards, to close it again
if (cOsd::IsOpen())
{
eKeys key = kMenu;
#ifdef DEBUG
dsyslog ("[mpv] osd is open sending menu key followed by back key\n");
#endif
cRemote::Put(key);
key = kBack;
cRemote::Put(key);
}
cStatus::MsgReplaying(this, NULL, NULL, false); // This has to be done before delete the player
Player->Shutdown();
delete Player;
Player = NULL;
player = NULL;
if (remove ("/tmp/mpv.playlist")) dsyslog ("[mpv] Playlist was not used\n");
cDevice::SetPrimaryDevice(cDevice::PrimaryDevice()->DeviceNumber() + 1);
}
void cMpvControl::ShowProgress(int playlist)
{
if (!Player->IsPaused() && LastPlayerCurrent == Player->CurrentPlayTime() && Player->TotalPlayTime() > 0 && !Player->NetworkPlay())
return;
LastPlayerCurrent = Player->CurrentPlayTime();
if (!DisplayReplay)
DisplayReplay = Skins.Current()->DisplayReplay(false);
if (!infoVisible)
{
if (!Player->NetworkPlay())
UpdateMarks();
infoVisible = true;
timeoutShow = Setup.ProgressDisplayTime ? (time(0) + Setup.ProgressDisplayTime) : 0;
}
string TitleDisplay = Player->CurrentFile();
if (MpvPluginConfig->TitleOverride != "")
TitleDisplay = MpvPluginConfig->TitleOverride;
else if (MpvPluginConfig->ShowMediaTitle && Player->MediaTitle() != "")
TitleDisplay = Player->MediaTitle();
if (Player->TotalListPos() > 1 && !playlist)
TitleDisplay = std::string(itoa(Player->CurrentListPos())) + " " + TitleDisplay;
if (Player->NumChapters() > 0)
{
if (Player->ChapterTitle(Player->CurrentChapter()) != "")
TitleDisplay += " - " + Player->ChapterTitle(Player->CurrentChapter());
char buffer[10];
int err = snprintf (buffer, sizeof(buffer), " (%d/%d)", Player->CurrentChapter(), Player->NumChapters());
if (err < 0)
{
esyslog ("[mpv] ShowProgress TitleDisplay error!\n");
return;
}
TitleDisplay += buffer;
DisplayReplay->SetMarks(Marks());
}
if (Player->IsRecord()) TitleDisplay = "REC " + TitleDisplay;
DisplayReplay->SetTitle(TitleDisplay.c_str());
if (playlist)
DisplayReplay->SetProgress(Player->CurrentListPos(), Player->TotalListPos());
else
DisplayReplay->SetProgress(Player->CurrentPlayTime(), Player->TotalPlayTime() != 0 ? Player->TotalPlayTime() : 1);
int Speed = Player->CurrentPlaybackSpeed();
if (Speed == 1)
Speed = -1;
DisplayReplay->SetMode(!Player->IsPaused(), true, Speed);
if (playlist)
{
DisplayReplay->SetCurrent(itoa(Player->CurrentListPos()));
DisplayReplay->SetTotal(itoa(Player->TotalListPos()));
}
else
{
DisplayReplay->SetCurrent(IndexToHMSF(Player->CurrentPlayTime(), false, 1));
DisplayReplay->SetTotal(IndexToHMSF(Player->TotalPlayTime(), false, 1));
}
SetNeedsFastResponse(true);
Skins.Flush();
}
void cMpvControl::Hide()
{
if (DisplayReplay)
{
delete DisplayReplay;
DisplayReplay = NULL;
SetNeedsFastResponse(false);
}
}
eOSState cMpvControl::ProcessKey(eKeys key)
{
eOSState state;
static int count;
#ifdef DEBUG
if (key != kNone)
{
dsyslog("[mpv]%s: key=%d\n", __FUNCTION__, key);
}
#endif
if (!Player->PlayerIsRunning()) // check if player is still alive
{
cControl::Shutdown();
return osEnd;
}
//once detect the end of file playback
if (Player->IsIdle() > 0 && !Player->IsRecord() && !MpvPluginConfig->ExitAtEnd)
{
Hide();
Player->ResetIdle();
if (MpvPluginConfig->ShowAfterStop == 1)
{
MpvPluginConfig->ShowOptions = 0;
cRemote::CallPlugin("mpv");
}
return osContinue;
}
if (timeSearchActive && key != kNone)
{
TimeSearchProcess(key);
return osContinue;
}
if (timeoutShow && time(0) > timeoutShow)
{
timeoutShow = 0;
infoVisible = false;
Hide();
}
else if (infoVisible) // if RecordingInfo visible then update
ShowProgress(count % 2);
state = osContinue;
switch ((int)key) // cast to shutup g++ warnings
{
case kUp:
if (Player->DiscNavActive())
{
Player->DiscNavUp();
break;
}
case kPlay:
if (Player->CurrentPlaybackSpeed() != 1)
{
Player->SetSpeed(1);
}
if (Player->IsPaused())
{
Player->TogglePause();
}
break;
case kDown:
if (Player->DiscNavActive())
{
Player->DiscNavDown();
break;
}
case kPause:
Player->TogglePause();
break;
case kLeft:
if (Player->DiscNavActive())
{
Player->DiscNavLeft();
break;
}
case kFastRew:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't rewind"));
break;
}
if (Player->TotalPlayTime())
{
// reset to normal playback speed (if fastfwd is active currently) and then just go back 5 seconds since there is no fastrew in mpv
Player->SetSpeed(1);
Player->Seek(-5);
}
else //image have TotalPlayTime = 0
{
Player->PreviousPlaylistItem();
}
break;
case kRight:
if (Player->DiscNavActive())
{
Player->DiscNavRight();
break;
}
case kFastFwd:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't forwarding"));
break;
}
if (Player->TotalPlayTime())
{
if (Player->CurrentPlaybackSpeed() < 32)
{
Player->SetSpeed(Player->CurrentPlaybackSpeed() * 2);
}
}
else //image have TotalPlayTime = 0
{
Player->NextPlaylistItem();
}
break;
case kRed:
TimeSearch();
break;
case kGreen | k_Repeat:
case kGreen:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't seek"));
break;
}
Player->Seek(-60);
break;
case kYellow | k_Repeat:
case kYellow:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't seek"));
break;
}
Player->Seek(+60);
break;
case kBlue:
infoVisible = false;
MpvPluginConfig->ShowOptions = 1;
cRemote::CallPlugin("mpv");
break;
case kBack:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - stop record first!"));
break;
}
if (Player->DiscNavActive())
{
Player->DiscNavPrev();
break;
}
MpvPluginConfig->ShowOptions = 0;
cRemote::CallPlugin("mpv");
break;
case kStop:
if (Player->IsRecord())
{
Skins.Message(mtInfo, tr("Recording Stoped"));
Player->Record("");
cRecordings::Update(true);
}
else
{
if (!MpvPluginConfig->ExitAtEnd)
{
Hide();
if (MpvPluginConfig->SavePos && !Player->NetworkPlay())
Player->SavePosPlayer();
//hack to disable idle when stopping manually
Player->ResetIdle();
Player->StopPlayer();
if (MpvPluginConfig->ShowAfterStop == 1)
{
MpvPluginConfig->ShowOptions = 0;
cRemote::CallPlugin("mpv");
}
}
else
{
Hide();
Player->QuitPlayer();
}
}
break;
case kOk:
if (Player->DiscNavActive())
{
Player->DiscNavSelect();
break;
}
if (infoVisible && (count > 1))
{
count = 0;
Hide();
infoVisible = false;
}
else
{
if (Player->TotalListPos() <= 1) count++;
if (!Player->TotalPlayTime()) count += 2;
count++;
ShowProgress(count % 2);
}
break;
case k5:
Player->DiscNavMenu();
break;
case kNext:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't next"));
break;
}
if (MpvPluginConfig->PlaylistOnNextKey || (MpvPluginConfig->PlaylistIfNoChapters && !Player->NumChapters()))
Player->NextPlaylistItem();
else
Player->NextChapter();
break;
case kPrev:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't prev"));
break;
}
if (MpvPluginConfig->PlaylistOnNextKey || (MpvPluginConfig->PlaylistIfNoChapters && !Player->NumChapters()))
Player->PreviousPlaylistItem();
else
Player->PreviousChapter();
break;
case k1 | k_Repeat:
case k1:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't seek"));
break;
}
Player->Seek(-15);
break;
case k3 | k_Repeat:
case k3:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't seek"));
break;
}
Player->Seek(+15);
break;
case k7:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't prev"));
break;
}
if (MpvPluginConfig->PlaylistOnNextKey)
Player->PreviousChapter();
else
Player->PreviousPlaylistItem();
break;
case k9:
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't next"));
break;
}
if (MpvPluginConfig->PlaylistOnNextKey)
Player->NextChapter();
else
Player->NextPlaylistItem();
break;
case kRecord:
if (!Player->NetworkPlay())
{
Skins.Message(mtError, tr("Not network stream, can't recording!"));
}
else
{
if (!Player->IsRecord())
{
time_t timeNow;
char buffer [20];
struct tm * timeinfo;
time (&timeNow);
timeinfo = localtime(&timeNow);
strftime (buffer,20,"%Y-%m-%d.%H.%M.%S",timeinfo);
string dir = cVideoDirectory::Name();
dir += "/" + Player->ListTitle(Player->CurrentListPos());
mkdir(dir.c_str(),0777);
dir += "/";
dir += buffer;
dir += "-0.rec";
mkdir(dir.c_str(),0777);
string rec = dir+"/"+"00001.ts";
#ifdef DEBUG
esyslog("[mpv] recording %s\n",rec.c_str());
#endif
Player->Record(rec.c_str());
Skins.Message(mtInfo, tr("Recording Started"));
}
}
break;
case kChanUp:
if (Player->NetworkPlay())
{
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't next"));
break;
}
Player->NextPlaylistItem();
ShowProgress(0);
count = 2;
}
break;
case kChanDn:
if (Player->NetworkPlay())
{
if (Player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't prev"));
break;
}
Player->PreviousPlaylistItem();
ShowProgress(0);
count = 2;
}
break;
default:
break;
}
return state;
}
void cMpvControl::UpdateMarks()
{
((cList<cMark> *)&ChapterMarks)->Clear();
if (Player->NumChapters() > 1)
{
ChapterMarks.Add(0);
for (int i=1; i <= Player->NumChapters(); i++)
{
ChapterMarks.Add(Player->ChapterStartTime(i) - 1);
ChapterMarks.Add(Player->ChapterStartTime(i));
}
}
}
// TimeSearch code is copied from vdr menu.c and slightly adjusted to fit with our class
void cMpvControl::TimeSearch()
{
timeSearchTime = timeSearchPos = 0;
timeSearchHide = false;
if (!infoVisible) {
ShowProgress();
if (infoVisible)
timeSearchHide = true;
else
return;
}
timeoutShow = 0;
TimeSearchDisplay();
timeSearchActive = true;
}
void cMpvControl::TimeSearchDisplay()
{
char buf[64];
// TRANSLATORS: note the trailing blank!
strcpy(buf, tr("Jump: "));
int len = strlen(buf);
char h10 = '0' + (timeSearchTime >> 24);
char h1 = '0' + ((timeSearchTime & 0x00FF0000) >> 16);
char m10 = '0' + ((timeSearchTime & 0x0000FF00) >> 8);
char m1 = '0' + (timeSearchTime & 0x000000FF);
char ch10 = timeSearchPos > 3 ? h10 : '-';
char ch1 = timeSearchPos > 2 ? h1 : '-';
char cm10 = timeSearchPos > 1 ? m10 : '-';
char cm1 = timeSearchPos > 0 ? m1 : '-';
sprintf(buf + len, "%c%c:%c%c", ch10, ch1, cm10, cm1);
DisplayReplay->SetJump(buf);
}
void cMpvControl::TimeSearchProcess(eKeys Key)
{
#define STAY_SECONDS_OFF_END 10
int Seconds = (timeSearchTime >> 24) * 36000 + ((timeSearchTime & 0x00FF0000) >> 16) * 3600 + ((timeSearchTime & 0x0000FF00) >> 8) * 600 + (timeSearchTime & 0x000000FF) * 60;
int Current = Player->CurrentPlayTime();
int Total = Player->TotalPlayTime();
switch (Key) {
case k0 ... k9:
if (timeSearchPos < 4) {
timeSearchTime <<= 8;
timeSearchTime |= Key - k0;
timeSearchPos++;
TimeSearchDisplay();
}
break;
case kFastRew:
case kLeft:
case kFastFwd:
case kRight: {
int dir = ((Key == kRight || Key == kFastFwd) ? 1 : -1);
if (dir > 0)
#if VDRVERSNUM < 20305
Seconds = min(Total - Current - STAY_SECONDS_OFF_END, Seconds);
#else
Seconds = std::min(Total - Current - STAY_SECONDS_OFF_END, Seconds);
#endif
else
Seconds = 0-Seconds;
Player->Seek(Seconds);
timeSearchActive = false;
}
break;
case kPlayPause:
case kPlay:
case kUp:
case kPause:
case kDown:
case kOk:
if (timeSearchPos > 0) {
#if VDRVERSNUM < 20305
Seconds = min(Total - STAY_SECONDS_OFF_END, Seconds);
#else
Seconds = std::min(Total - STAY_SECONDS_OFF_END, Seconds);
#endif
Player->SetTimePos(Seconds);
}
timeSearchActive = false;
break;
default:
if (!(Key & k_Flags)) // ignore repeat/release keys
timeSearchActive = false;
break;
}
if (!timeSearchActive) {
if (timeSearchHide)
Hide();
else
DisplayReplay->SetJump(NULL);
// ShowProgress();
}
}
void cMpvControl::PlayNew(string Filename)
{
Player->PlayNew(Filename);
}
void cMpvControl::SeekTo(int seconds)
{
Player->SetTimePos(seconds);
}
void cMpvControl::SeekRelative(int seconds)
{
Player->Seek(seconds);
}
void cMpvControl::ScaleVideo(int x, int y, int width, int height)
{
Player->ScaleVideo(x, y, width, height);
}
uint8_t *cMpvControl::GrabImage(int *size, int *width, int *height)
{
return Player->GrabImage(size, width, height);
}