-
Notifications
You must be signed in to change notification settings - Fork 341
/
mythplayercaptionsui.cpp
711 lines (624 loc) · 23.5 KB
/
mythplayercaptionsui.cpp
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
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
// MythTV
#include "livetvchain.h"
#include "tv_play.h"
#include "interactivetv.h"
#include "captions/subtitlescreen.h"
#include "mythplayercaptionsui.h"
#define LOC QString("PlayerCaptions: ")
MythPlayerCaptionsUI::MythPlayerCaptionsUI(MythMainWindow* MainWindow, TV* Tv, PlayerContext* Context, PlayerFlags Flags)
: MythPlayerAudioUI(MainWindow, Tv, Context, Flags),
m_captionsOverlay(MainWindow, Tv, nullptr, m_painter)
{
m_itvEnabled = gCoreContext->GetBoolSetting("EnableMHEG", false);
// Connect outgoing
connect(this, &MythPlayerCaptionsUI::CaptionsStateChanged, m_tv, &TV::CaptionsStateChanged);
// Inbound connections
connect(m_tv, &TV::SetTrack, this, &MythPlayerCaptionsUI::SetTrack);
connect(m_tv, &TV::ChangeAllowForcedSubtitles, this, &MythPlayerCaptionsUI::SetAllowForcedSubtitles);
connect(m_tv, &TV::ToggleCaptions, this, &MythPlayerCaptionsUI::ToggleCaptions);
connect(m_tv, &TV::ToggleCaptionsByType, this, &MythPlayerCaptionsUI::ToggleCaptionsByType);
connect(m_tv, &TV::SetCaptionsEnabled, this, &MythPlayerCaptionsUI::SetCaptionsEnabled);
connect(m_tv, &TV::DisableCaptions, this, &MythPlayerCaptionsUI::DisableCaptions);
connect(m_tv, &TV::EnableCaptions, this, &MythPlayerCaptionsUI::EnableCaptions);
connect(m_tv, &TV::ChangeCaptionTrack, this, &MythPlayerCaptionsUI::ChangeCaptionTrack);
connect(m_tv, &TV::ChangeTrack, this, &MythPlayerCaptionsUI::ChangeTrack);
connect(m_tv, &TV::ResetCaptions, this, &MythPlayerCaptionsUI::ResetCaptions);
connect(m_tv, &TV::EnableTeletext, this, &MythPlayerCaptionsUI::EnableTeletext);
connect(m_tv, &TV::ResetTeletext, this, &MythPlayerCaptionsUI::ResetTeletext);
connect(m_tv, &TV::SetTeletextPage, this, &MythPlayerCaptionsUI::SetTeletextPage);
connect(m_tv, &TV::RestartITV, this, &MythPlayerCaptionsUI::ITVRestart);
connect(m_tv, &TV::HandleTeletextAction, this, &MythPlayerCaptionsUI::HandleTeletextAction);
connect(m_tv, &TV::HandleITVAction, this, &MythPlayerCaptionsUI::ITVHandleAction);
connect(m_tv, &TV::AdjustSubtitleZoom, this, &MythPlayerCaptionsUI::AdjustSubtitleZoom);
connect(m_tv, &TV::AdjustSubtitleDelay, this, &MythPlayerCaptionsUI::AdjustSubtitleDelay);
// Signalled connections (from MHIContext)
connect(this, &MythPlayerCaptionsUI::SetInteractiveStream, this, &MythPlayerCaptionsUI::SetStream);
connect(this, &MythPlayerCaptionsUI::SetInteractiveStreamPos, this, &MythPlayerCaptionsUI::SetStreamPos);
connect(this, &MythPlayerCaptionsUI::PlayInteractiveStream, this, &MythPlayerCaptionsUI::StreamPlay);
// Signalled from the decoder
connect(this, &MythPlayerCaptionsUI::SignalTracksChanged, this, &MythPlayerCaptionsUI::TracksChanged);
// Signalled from the base class
connect(this, &MythPlayerCaptionsUI::RequestResetCaptions, this, &MythPlayerCaptionsUI::ResetCaptions);
}
MythPlayerCaptionsUI::~MythPlayerCaptionsUI()
{
delete m_interactiveTV;
}
void MythPlayerCaptionsUI::AdjustSubtitleZoom(int Delta)
{
if (!(GetCaptionsEnabled() && !(m_browsing || m_editing)))
return;
auto * subs = m_captionsOverlay.InitSubtitles();
if (subs)
{
int newval = std::clamp(subs->GetZoom() + Delta, 50, 200);
UpdateOSDStatus(tr("Adjust Subtitle Zoom"), tr("Subtitle Zoom"),
QString::number(newval), kOSDFunctionalType_SubtitleZoomAdjust,
"%", newval * 1000 / 200, kOSDTimeout_None);
ChangeOSDPositionUpdates(false);
subs->SetZoom(newval);
}
}
void MythPlayerCaptionsUI::AdjustSubtitleDelay(int Delta)
{
bool showing = (m_captionsState.m_textDisplayMode == kDisplayRawTextSubtitle) ||
(m_captionsState.m_textDisplayMode == kDisplayTextSubtitle);
if (!(showing && !(m_browsing || m_editing)))
return;
auto * subs = m_captionsOverlay.InitSubtitles();
if (subs)
{
int newval = std::clamp(subs->GetDelay() + (Delta * 10), -5000, 5000);
// range of -5000ms..+5000ms, scale to 0..1000
UpdateOSDStatus(tr("Adjust Subtitle Delay"), tr("Subtitle Delay"),
QString::number(newval), kOSDFunctionalType_SubtitleDelayAdjust,
"ms", (newval / 10) + 500, kOSDTimeout_None);
ChangeOSDPositionUpdates(false);
subs->SetDelay(newval);
}
}
void MythPlayerCaptionsUI::ResetCaptions()
{
m_captionsOverlay.ClearSubtitles();
m_captionsOverlay.TeletextClear();
}
static uint toCaptionType(uint Type)
{
if (kTrackTypeCC608 == Type) return kDisplayCC608;
if (kTrackTypeCC708 == Type) return kDisplayCC708;
if (kTrackTypeSubtitle == Type) return kDisplayAVSubtitle;
if (kTrackTypeTeletextCaptions == Type) return kDisplayTeletextCaptions;
if (kTrackTypeTextSubtitle == Type) return kDisplayTextSubtitle;
if (kTrackTypeRawText == Type) return kDisplayRawTextSubtitle;
return 0;
}
static uint toTrackType(uint Type)
{
if (kDisplayCC608 == Type) return kTrackTypeCC608;
if (kDisplayCC708 == Type) return kTrackTypeCC708;
if (kDisplayAVSubtitle == Type) return kTrackTypeSubtitle;
if (kDisplayTeletextCaptions == Type) return kTrackTypeTeletextCaptions;
if (kDisplayTextSubtitle == Type) return kTrackTypeTextSubtitle;
if (kDisplayRawTextSubtitle == Type) return kTrackTypeRawText;
return kTrackTypeUnknown;
}
void MythPlayerCaptionsUI::DisableCaptions(uint Mode, bool UpdateOSD)
{
uint oldcaptions = m_captionsState.m_textDisplayMode;
if (m_captionsState.m_textDisplayMode != kDisplayNone)
m_lastValidTextDisplayMode = m_captionsState.m_textDisplayMode;
m_captionsState.m_textDisplayMode &= ~Mode;
if (oldcaptions != m_captionsState.m_textDisplayMode)
emit CaptionsStateChanged(m_captionsState);
ResetCaptions();
QMutexLocker locker(&m_osdLock);
bool newTextDesired = (m_captionsState.m_textDisplayMode & kDisplayAllTextCaptions) != 0U;
// Only turn off textDesired if the Operator requested it.
if (UpdateOSD || newTextDesired)
m_textDesired = newTextDesired;
QString msg = "";
if (kDisplayNUVTeletextCaptions & Mode)
msg += tr("TXT CAP");
if (kDisplayTeletextCaptions & Mode)
{
if (m_decoder != nullptr)
{
int track = GetTrack(kTrackTypeTeletextCaptions);
if (track > -1)
msg += m_decoder->GetTrackDesc(kTrackTypeTeletextCaptions, static_cast<uint>(track));
}
DisableTeletext();
}
int preserve = m_captionsState.m_textDisplayMode & (kDisplayCC608 | kDisplayTextSubtitle |
kDisplayAVSubtitle | kDisplayCC708 |
kDisplayRawTextSubtitle);
if ((kDisplayCC608 & Mode) || (kDisplayCC708 & Mode) ||
(kDisplayAVSubtitle & Mode) || (kDisplayRawTextSubtitle & Mode))
{
uint type = toTrackType(Mode);
if (m_decoder != nullptr)
{
int track = GetTrack(type);
if (track > -1)
msg += m_decoder->GetTrackDesc(type, static_cast<uint>(track));
}
m_captionsOverlay.EnableSubtitles(preserve);
}
if (kDisplayTextSubtitle & Mode)
{
msg += tr("Text subtitles");
m_captionsOverlay.EnableSubtitles(preserve);
}
if (!msg.isEmpty() && UpdateOSD)
{
msg += " " + tr("Off");
UpdateOSDMessage(msg, kOSDTimeout_Med);
}
}
void MythPlayerCaptionsUI::EnableCaptions(uint Mode, bool UpdateOSD)
{
QMutexLocker locker(&m_osdLock);
bool newTextDesired = (Mode & kDisplayAllTextCaptions) != 0U;
// Only turn off textDesired if the Operator requested it.
if (UpdateOSD || newTextDesired)
m_textDesired = newTextDesired;
QString msg = "";
if ((kDisplayCC608 & Mode) || (kDisplayCC708 & Mode) ||
(kDisplayAVSubtitle & Mode) || kDisplayRawTextSubtitle & Mode)
{
uint type = toTrackType(Mode);
if (m_decoder != nullptr)
{
int track = GetTrack(type);
if (track > -1)
msg += m_decoder->GetTrackDesc(type, static_cast<uint>(track));
}
m_captionsOverlay.EnableSubtitles(static_cast<int>(Mode));
}
if (kDisplayTextSubtitle & Mode)
{
m_captionsOverlay.EnableSubtitles(kDisplayTextSubtitle);
msg += tr("Text subtitles");
}
if (kDisplayNUVTeletextCaptions & Mode)
msg += tr("TXT %1").arg(m_ttPageNum, 3, 16);
if ((kDisplayTeletextCaptions & Mode) && (m_decoder != nullptr))
{
msg += m_decoder->GetTrackDesc(kTrackTypeTeletextCaptions,
static_cast<uint>(GetTrack(kTrackTypeTeletextCaptions)));
int page = m_decoder->GetTrackLanguageIndex(kTrackTypeTeletextCaptions,
static_cast<uint>(GetTrack(kTrackTypeTeletextCaptions)));
EnableTeletext(page);
}
msg += " " + tr("On");
LOG(VB_PLAYBACK, LOG_INFO, QString("EnableCaptions(%1) msg: %2")
.arg(Mode).arg(msg));
uint oldcaptions = m_captionsState.m_textDisplayMode;
m_captionsState.m_textDisplayMode = Mode;
if (m_captionsState.m_textDisplayMode != kDisplayNone)
m_lastValidTextDisplayMode = m_captionsState.m_textDisplayMode;
if (oldcaptions != m_captionsState.m_textDisplayMode)
emit CaptionsStateChanged(m_captionsState);
if (UpdateOSD)
UpdateOSDMessage(msg, kOSDTimeout_Med);
}
/*! \brief This tries to re-enable captions/subtitles if the user
* wants them and one of the captions/subtitles tracks has changed.
*/
void MythPlayerCaptionsUI::TracksChanged(uint TrackType)
{
if (m_textDesired && (TrackType >= kTrackTypeSubtitle) &&
(TrackType <= kTrackTypeTeletextCaptions))
{
SetCaptionsEnabled(true, false);
}
}
void MythPlayerCaptionsUI::SetAllowForcedSubtitles(bool Allow)
{
m_allowForcedSubtitles = Allow;
UpdateOSDMessage(m_allowForcedSubtitles ? tr("Forced Subtitles On") : tr("Forced Subtitles Off"));
}
void MythPlayerCaptionsUI::ToggleCaptions()
{
SetCaptionsEnabled(!(static_cast<bool>(m_captionsState.m_textDisplayMode)));
}
uint MythPlayerCaptionsUI::GetCaptionMode() const
{
return m_captionsState.m_textDisplayMode;
}
bool MythPlayerCaptionsUI::HasTextSubtitles()
{
return m_subReader.HasTextSubtitles();
}
void MythPlayerCaptionsUI::ToggleCaptionsByType(uint Type)
{
QMutexLocker locker(&m_osdLock);
uint mode = toCaptionType(Type);
uint origMode = m_captionsState.m_textDisplayMode;
if (m_captionsState.m_textDisplayMode)
DisableCaptions(m_captionsState.m_textDisplayMode, (origMode & mode) != 0U);
if (origMode & mode)
return;
if (mode)
EnableCaptions(mode);
}
void MythPlayerCaptionsUI::SetCaptionsEnabled(bool Enable, bool UpdateOSD)
{
QMutexLocker locker(&m_osdLock);
m_enableCaptions = m_disableCaptions = false;
uint origMode = m_captionsState.m_textDisplayMode;
// Only turn off textDesired if the Operator requested it.
if (UpdateOSD || Enable)
m_textDesired = Enable;
if (!Enable)
{
DisableCaptions(origMode, UpdateOSD);
return;
}
uint mode = HasCaptionTrack(m_lastValidTextDisplayMode) ?
m_lastValidTextDisplayMode : NextCaptionTrack(kDisplayNone);
if (origMode != mode)
{
DisableCaptions(origMode, false);
if (kDisplayNone == mode)
{
if (UpdateOSD)
{
UpdateOSDMessage(tr("No captions", "CC/Teletext/Subtitle text not available"),
kOSDTimeout_Med);
}
LOG(VB_PLAYBACK, LOG_INFO, "No captions available yet to enable.");
}
else if (mode)
{
EnableCaptions(mode, UpdateOSD);
}
}
ResetCaptions();
}
/*! \brief Return whether any *optional* captions are enabled
*
* Which currently means anything except DVD buttons.
*/
bool MythPlayerCaptionsUI::GetCaptionsEnabled() const
{
return (kDisplayNUVTeletextCaptions == m_captionsState.m_textDisplayMode) ||
(kDisplayTeletextCaptions == m_captionsState.m_textDisplayMode) ||
(kDisplayAVSubtitle == m_captionsState.m_textDisplayMode) ||
(kDisplayCC608 == m_captionsState.m_textDisplayMode) ||
(kDisplayCC708 == m_captionsState.m_textDisplayMode) ||
(kDisplayTextSubtitle == m_captionsState.m_textDisplayMode) ||
(kDisplayRawTextSubtitle == m_captionsState.m_textDisplayMode) ||
(kDisplayTeletextMenu == m_captionsState.m_textDisplayMode);
}
QStringList MythPlayerCaptionsUI::GetTracks(uint Type)
{
if (m_decoder)
return m_decoder->GetTracks(Type);
return QStringList();
}
uint MythPlayerCaptionsUI::GetTrackCount(uint Type)
{
if (m_decoder)
return m_decoder->GetTrackCount(Type);
return 0;
}
void MythPlayerCaptionsUI::SetTrack(uint Type, uint TrackNo)
{
if (!m_decoder)
return;
m_decoder->SetTrack(Type, static_cast<int>(TrackNo));
if (kTrackTypeAudio == Type)
{
if (m_decoder)
{
UpdateOSDMessage(m_decoder->GetTrackDesc(Type,
static_cast<uint>(GetTrack(Type))), kOSDTimeout_Med);
}
return;
}
uint subtype = toCaptionType(Type);
if (subtype)
{
DisableCaptions(m_captionsState.m_textDisplayMode, false);
EnableCaptions(subtype, true);
if ((kDisplayCC708 == subtype || kDisplayCC608 == subtype) && m_decoder)
{
int sid = m_decoder->GetTrackInfo(Type, TrackNo).m_stream_id;
if (sid >= 0)
{
(kDisplayCC708 == subtype) ? m_cc708.SetCurrentService(sid) :
m_cc608.SetMode(sid);
}
}
}
}
void MythPlayerCaptionsUI::DoDisableForcedSubtitles()
{
m_disableForcedSubtitles = false;
m_osdLock.lock();
m_captionsOverlay.DisableForcedSubtitles();
m_osdLock.unlock();
}
void MythPlayerCaptionsUI::DoEnableForcedSubtitles()
{
m_enableForcedSubtitles = false;
if (!m_allowForcedSubtitles)
return;
m_osdLock.lock();
m_captionsOverlay.EnableSubtitles(kDisplayAVSubtitle, true /*forced only*/);
m_osdLock.unlock();
}
int MythPlayerCaptionsUI::GetTrack(uint Type)
{
if (m_decoder)
return m_decoder->GetTrack(Type);
return -1;
}
void MythPlayerCaptionsUI::ChangeTrack(uint Type, int Direction)
{
if (!m_decoder)
return;
int retval = m_decoder->ChangeTrack(Type, Direction);
if (retval >= 0)
{
UpdateOSDMessage(m_decoder->GetTrackDesc(Type, static_cast<uint>(GetTrack(Type))),
kOSDTimeout_Med);
}
}
void MythPlayerCaptionsUI::ChangeCaptionTrack(int Direction)
{
if (!m_decoder || (Direction < 0))
return;
if (!((m_captionsState.m_textDisplayMode == kDisplayTextSubtitle) ||
(m_captionsState.m_textDisplayMode == kDisplayNUVTeletextCaptions) ||
(m_captionsState.m_textDisplayMode == kDisplayNone)))
{
uint tracktype = toTrackType(m_captionsState.m_textDisplayMode);
if (GetTrack(tracktype) < m_decoder->NextTrack(tracktype))
{
SetTrack(tracktype, static_cast<uint>(m_decoder->NextTrack(tracktype)));
return;
}
}
uint nextmode = NextCaptionTrack(m_captionsState.m_textDisplayMode);
if ((nextmode == kDisplayTextSubtitle) ||
(nextmode == kDisplayNUVTeletextCaptions) ||
(nextmode == kDisplayNone))
{
DisableCaptions(m_captionsState.m_textDisplayMode, true);
if (nextmode != kDisplayNone)
EnableCaptions(nextmode, true);
}
else
{
uint tracktype = toTrackType(nextmode);
uint tracks = m_decoder->GetTrackCount(tracktype);
if (tracks)
{
DisableCaptions(m_captionsState.m_textDisplayMode, true);
SetTrack(tracktype, 0);
}
}
}
bool MythPlayerCaptionsUI::HasCaptionTrack(uint Mode)
{
if (Mode == kDisplayNone)
return false;
if (((Mode == kDisplayTextSubtitle) && HasTextSubtitles()) || (Mode == kDisplayNUVTeletextCaptions))
return true;
if (!(Mode == kDisplayTextSubtitle) && m_decoder->GetTrackCount(toTrackType(Mode)))
return true;
return false;
}
uint MythPlayerCaptionsUI::NextCaptionTrack(uint Mode)
{
// Text->TextStream->708->608->AVSubs->Teletext->NUV->None
// NUV only offerred if PAL
bool pal = (m_vbiMode == VBIMode::PAL_TT);
uint nextmode = kDisplayNone;
if (kDisplayTextSubtitle == Mode)
nextmode = kDisplayRawTextSubtitle;
else if (kDisplayRawTextSubtitle == Mode)
nextmode = kDisplayCC708;
else if (kDisplayCC708 == Mode)
nextmode = kDisplayCC608;
else if (kDisplayCC608 == Mode)
nextmode = kDisplayAVSubtitle;
else if (kDisplayAVSubtitle == Mode)
nextmode = kDisplayTeletextCaptions;
else if (kDisplayTeletextCaptions == Mode)
nextmode = pal ? kDisplayNUVTeletextCaptions : kDisplayNone;
else if ((kDisplayNUVTeletextCaptions == Mode) && pal)
nextmode = kDisplayNone;
else if (kDisplayNone == Mode)
nextmode = kDisplayTextSubtitle;
if (nextmode == kDisplayNone || HasCaptionTrack(nextmode))
return nextmode;
return NextCaptionTrack(nextmode);
}
void MythPlayerCaptionsUI::EnableTeletext(int Page)
{
QMutexLocker locker(&m_osdLock);
uint oldcaptions = m_captionsState.m_textDisplayMode;
m_captionsOverlay.EnableTeletext(true, Page);
m_lastTextDisplayMode = m_captionsState.m_textDisplayMode;
m_captionsState.m_textDisplayMode = kDisplayTeletextMenu;
if (oldcaptions != m_captionsState.m_textDisplayMode)
emit CaptionsStateChanged(m_captionsState);
}
void MythPlayerCaptionsUI::DisableTeletext()
{
QMutexLocker locker(&m_osdLock);
m_captionsOverlay.EnableTeletext(false, 0);
uint oldcaptions = m_captionsState.m_textDisplayMode;
m_captionsState.m_textDisplayMode = kDisplayNone;
if (oldcaptions != m_captionsState.m_textDisplayMode)
emit CaptionsStateChanged(m_captionsState);
// If subtitles were enabled before the teletext menu was displayed then re-enable them
if (m_lastTextDisplayMode & kDisplayAllCaptions)
EnableCaptions(m_lastTextDisplayMode, false);
}
void MythPlayerCaptionsUI::ResetTeletext()
{
QMutexLocker locker(&m_osdLock);
m_captionsOverlay.TeletextReset();
}
/*! \brief Set Teletext NUV Caption page
*/
void MythPlayerCaptionsUI::SetTeletextPage(uint Page)
{
m_osdLock.lock();
DisableCaptions(m_captionsState.m_textDisplayMode);
uint oldcaptions = m_captionsState.m_textDisplayMode;
m_ttPageNum = static_cast<int>(Page);
m_cc608.SetTTPageNum(m_ttPageNum);
m_captionsState.m_textDisplayMode &= static_cast<uint>(~kDisplayAllCaptions);
m_captionsState.m_textDisplayMode |= kDisplayNUVTeletextCaptions;
if (oldcaptions != m_captionsState.m_textDisplayMode)
emit CaptionsStateChanged(m_captionsState);
m_osdLock.unlock();
}
void MythPlayerCaptionsUI::HandleTeletextAction(const QString& Action, bool &Handled)
{
if (!(m_captionsState.m_textDisplayMode & kDisplayTeletextMenu))
return;
bool exit = false;
m_osdLock.lock();
Handled = m_captionsOverlay.TeletextAction(Action, exit);
m_osdLock.unlock();
if (exit)
DisableTeletext();
}
InteractiveTV* MythPlayerCaptionsUI::GetInteractiveTV()
{
#ifdef USING_MHEG
bool update = false;
{
QMutexLocker lock1(&m_osdLock);
QMutexLocker lock2(&m_itvLock);
if (!m_interactiveTV && m_itvEnabled && !FlagIsSet(kNoITV))
{
m_interactiveTV = new InteractiveTV(this);
m_captionsState.m_haveITV = true;
update = true;
}
}
if (update)
emit CaptionsStateChanged(m_captionsState);
#endif
return m_interactiveTV;
}
/*! \brief Submit Action to the interactiveTV object
*
* This is a little contrived as this method is signalled from the parent object. Rather
* than return a value (which is not possible with a signal) we update the Handled
* parameter. This is fine as long as there is only one signal/slot connection but
* I'm guessing won't work as well if signalled across threads.
*/
void MythPlayerCaptionsUI::ITVHandleAction(const QString &Action, bool& Handled)
{
#ifdef USING_MHEG
if (!GetInteractiveTV())
{
Handled = false;
return;
}
QMutexLocker locker(&m_itvLock);
Handled = m_interactiveTV->OfferKey(Action);
#else
Q_UNUSED(Action);
Q_UNUSED(Handled);
#endif
}
/// \brief Restart the MHEG/MHP engine.
void MythPlayerCaptionsUI::ITVRestart(uint Chanid, uint Cardid, bool IsLiveTV)
{
#ifdef USING_MHEG
if (!GetInteractiveTV())
return;
QMutexLocker locker(&m_itvLock);
m_interactiveTV->Restart(static_cast<int>(Chanid), static_cast<int>(Cardid), IsLiveTV);
m_itvVisible = false;
#else
Q_UNUSED(Chanid);
Q_UNUSED(Cardid);
Q_UNUSED(IsLiveTV);
#endif
}
/*! \brief Selects the audio stream using the DVB component tag.
*
* This is called from the InteractiveTV thread and really needs to be processed
* in the decoder thread. So for the time being do not convert this to a signal/slot
* (as there are no slots in the decoder classes yet) and just pass through with
* the protection of the decoder change lock.
*/
bool MythPlayerCaptionsUI::SetAudioByComponentTag(int Tag)
{
QMutexLocker locker(&m_decoderChangeLock);
if (m_decoder)
return m_decoder->SetAudioByComponentTag(Tag);
return false;
}
/*! \brief Selects the video stream using the DVB component tag.
*
* See SetAudioByComponentTag comments
*/
bool MythPlayerCaptionsUI::SetVideoByComponentTag(int Tag)
{
QMutexLocker locker(&m_decoderChangeLock);
if (m_decoder)
return m_decoder->SetVideoByComponentTag(Tag);
return false;
}
double MythPlayerCaptionsUI::SafeFPS()
{
QMutexLocker locker(&m_decoderChangeLock);
if (!m_decoder)
return 25;
double fps = m_decoder->GetFPS();
return fps > 0 ? fps : 25.0;
}
void MythPlayerCaptionsUI::SetStream(const QString& Stream)
{
// The stream name is empty if the stream is closing
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("SetStream '%1'").arg(Stream));
// Stream will be changed by JumpToStream called from EventLoop
// If successful will call m_interactiveTV->StreamStarted();
m_newStream = Stream;
if (Stream.isEmpty() && m_playerCtx->m_tvchain &&
m_playerCtx->m_buffer->GetType() == kMythBufferMHEG)
{
// Restore livetv
SetEof(kEofStateDelayed);
m_playerCtx->m_tvchain->JumpToNext(false, 0);
m_playerCtx->m_tvchain->JumpToNext(true, 0);
}
}
// Called from the interactiveTV (MHIContext) thread
long MythPlayerCaptionsUI::GetStreamPos()
{
return static_cast<long>((1000 * GetFramesPlayed()) / SafeFPS());
}
// Called from the interactiveTV (MHIContext) thread
long MythPlayerCaptionsUI::GetStreamMaxPos()
{
long maxpos = static_cast<long>(1000 * (m_totalDuration > 0 ? m_totalDuration : m_totalLength));
long pos = GetStreamPos();
return maxpos > pos ? maxpos : pos;
}
long MythPlayerCaptionsUI::SetStreamPos(long Position)
{
auto frameNum = static_cast<uint64_t>((Position * SafeFPS()) / 1000);
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("SetStreamPos %1 mS = frame %2, now=%3")
.arg(Position).arg(frameNum).arg(GetFramesPlayed()) );
JumpToFrame(frameNum);
return Position;
}
void MythPlayerCaptionsUI::StreamPlay(bool Playing)
{
if (Playing)
Play();
else
Pause();
}