-
Notifications
You must be signed in to change notification settings - Fork 341
/
mythvideooutgpu.cpp
725 lines (625 loc) · 22.5 KB
/
mythvideooutgpu.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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
// MythTV
#include "mythlogging.h"
#include "mythmainwindow.h"
#include "mythplayer.h"
#include "mythpaintergpu.h"
#include "mythvideogpu.h"
#include "mythvideooutgpu.h"
#define LOC QString("VidOutGPU: ")
/*! \class MythVideoOutputGPU
* \brief Common code shared between GPU accelerated sub-classes (e.g. OpenGL)
*
* MythVideoOutputGPU is a pure virtual class that contains code shared between
* the differing hardware accelerated MythVideoOutput subclasses.
*
* \note This should be considered a work-in-progress and it is likely to change.
*
* \sa MythVideoOutput
* \sa MythVideoOutputOpenGL
* \sa MythVideoOutputVulkan
*/
MythVideoOutputGPU::MythVideoOutputGPU(MythRender* Render, QString& Profile)
: MythVideoOutput(true),
m_render(Render),
m_profile(std::move(Profile))
{
if (m_render)
m_render->IncrRef();
MythMainWindow* win = MythMainWindow::getMainWindow();
if (win)
{
m_painter = dynamic_cast<MythPainterGPU*>(win->GetCurrentPainter());
if (m_painter)
m_painter->SetViewControl(MythPainterGPU::None);
}
if (!(win && m_render && m_painter))
LOG(VB_GENERAL, LOG_ERR, LOC + "Fatal error");
}
MythVideoOutputGPU::~MythVideoOutputGPU()
{
MythVideoOutputGPU::DestroyVisualisation();
for (auto & pip : m_pxpVideos)
delete pip;
MythVideoOutputGPU::DestroyBuffers();
delete m_video;
if (m_painter)
m_painter->SetViewControl(MythPainterGPU::Viewport | MythPainterGPU::Framebuffer);
if (m_render)
m_render->DecrRef();
}
MythPainter* MythVideoOutputGPU::GetOSDPainter()
{
return m_painter;
}
QRect MythVideoOutputGPU::GetDisplayVisibleRectAdj()
{
return GetDisplayVisibleRect();
}
void MythVideoOutputGPU::InitPictureAttributes()
{
m_videoColourSpace.SetSupportedAttributes(ALL_PICTURE_ATTRIBUTES);
}
void MythVideoOutputGPU::WindowResized(const QSize& Size)
{
SetWindowSize(Size);
InitDisplayMeasurements();
}
void MythVideoOutputGPU::SetVideoFrameRate(float NewRate)
{
if (!m_dbDisplayProfile)
return;
if (qFuzzyCompare(m_dbDisplayProfile->GetOutput() + 1.0F, NewRate + 1.0F))
return;
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Video frame rate changed: %1->%2")
.arg(static_cast<double>(m_dbDisplayProfile->GetOutput())).arg(static_cast<double>(NewRate)));
m_dbDisplayProfile->SetOutput(NewRate);
m_newFrameRate = true;
}
bool MythVideoOutputGPU::Init(const QSize& VideoDim, const QSize& VideoDispDim,
float Aspect, const QRect& DisplayVisibleRect, MythCodecID CodecId)
{
// if we are the main video player then free up as much video memory
// as possible at startup
PIPState pip = GetPIPState();
if ((kCodec_NONE == m_newCodecId) && ((kPIPOff == pip) || (kPBPLeft == pip)) && m_painter)
m_painter->FreeResources();
// Default initialisation - mainly MythVideoBounds
if (!MythVideoOutput::Init(VideoDim, VideoDispDim, Aspect, DisplayVisibleRect, CodecId))
return false;
// Ensure any new profile preferences are handled after a stream change
if (m_dbDisplayProfile)
m_video->SetProfile(m_dbDisplayProfile->GetVideoRenderer());
// Set default support for picture attributes
InitPictureAttributes();
// Setup display
QSize size = GetVideoDim();
// Set the display mode if required
if (m_display && m_display->UsingVideoModes() && !IsEmbedding())
ResizeForVideo(size);
InitDisplayMeasurements();
// Create buffers
if (!CreateBuffers(CodecId, GetVideoDim()))
return false;
// Adjust visible rect for embedding
QRect dvr = GetDisplayVisibleRectAdj();
if (m_videoCodecID == kCodec_NONE)
{
m_render->SetViewPort(QRect(QPoint(), dvr.size()));
return true;
}
if (GetPIPState() >= kPIPStandAlone)
{
QRect tmprect = QRect(QPoint(0,0), dvr.size());
ResizeDisplayWindow(tmprect, true);
}
// Reset OpenGLVideo
if (m_video->IsValid())
m_video->ResetFrameFormat();
return true;
}
/*! \brief Discard video frames
*
* If Flushed is true, the decoder will probably reset the hardware decoder in
* use and we need to release any hardware pause frames so the decoder is released
* before a new one is created.
*/
void MythVideoOutputGPU::DiscardFrames(bool KeyFrame, bool Flushed)
{
if (Flushed)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("(%1): %2").arg(KeyFrame).arg(m_videoBuffers.GetStatus()));
m_videoBuffers.DiscardPauseFrames();
}
MythVideoOutput::DiscardFrames(KeyFrame, Flushed);
}
/*! \brief Release a video frame back into the decoder pool.
*
* Software frames do not need a pause frame as the MythVideo subclass
* holds a copy of the last frame in its input textures. So
* just release the frame.
*
* Hardware frames hold the underlying interop class and
* hence access to the video texture. We cannot access them
* without a frame so retain the most recent frame by removing
* it from the 'used' queue and adding it to the 'pause' queue.
*/
void MythVideoOutputGPU::DoneDisplayingFrame(VideoFrame* Frame)
{
if (!Frame)
return;
bool retain = format_is_hw(Frame->codec);
QVector<VideoFrame*> release;
m_videoBuffers.BeginLock(kVideoBuffer_pause);
while (m_videoBuffers.Size(kVideoBuffer_pause))
{
VideoFrame* frame = m_videoBuffers.Dequeue(kVideoBuffer_pause);
if (!retain || (retain && (frame != Frame)))
release.append(frame);
}
if (retain)
{
m_videoBuffers.Enqueue(kVideoBuffer_pause, Frame);
if (m_videoBuffers.Contains(kVideoBuffer_used, Frame))
m_videoBuffers.Remove(kVideoBuffer_used, Frame);
}
else
{
release.append(Frame);
}
m_videoBuffers.EndLock();
for (auto * frame : release)
m_videoBuffers.DoneDisplayingFrame(frame);
}
bool MythVideoOutputGPU::CreateBuffers(MythCodecID CodecID, QSize Size)
{
if (m_buffersCreated)
return true;
if (codec_is_copyback(CodecID))
{
m_videoBuffers.Init(VideoBuffers::GetNumBuffers(FMT_NONE), false, 1, 4, 2);
return m_videoBuffers.CreateBuffers(FMT_YV12, Size.width(), Size.height());
}
if (codec_is_mediacodec(CodecID))
return m_videoBuffers.CreateBuffers(FMT_MEDIACODEC, Size, false, 1, 2, 2);
if (codec_is_vaapi(CodecID))
return m_videoBuffers.CreateBuffers(FMT_VAAPI, Size, false, 2, 1, 4, m_maxReferenceFrames);
if (codec_is_vtb(CodecID))
return m_videoBuffers.CreateBuffers(FMT_VTB, Size, false, 1, 4, 2);
if (codec_is_vdpau(CodecID))
return m_videoBuffers.CreateBuffers(FMT_VDPAU, Size, false, 2, 1, 4, m_maxReferenceFrames);
if (codec_is_nvdec(CodecID))
return m_videoBuffers.CreateBuffers(FMT_NVDEC, Size, false, 2, 1, 4);
if (codec_is_mmal(CodecID))
return m_videoBuffers.CreateBuffers(FMT_MMAL, Size, false, 2, 1, 4);
if (codec_is_v4l2(CodecID) || codec_is_drmprime(CodecID))
return m_videoBuffers.CreateBuffers(FMT_DRMPRIME, Size, false, 2, 1, 4);
return m_videoBuffers.CreateBuffers(FMT_YV12, Size, false, 1, 8, 4, m_maxReferenceFrames);
}
void MythVideoOutputGPU::DestroyBuffers()
{
MythVideoOutputGPU::DiscardFrames(true, true);
m_videoBuffers.DeleteBuffers();
m_videoBuffers.Reset();
m_buffersCreated = false;
}
bool MythVideoOutputGPU::InputChanged(const QSize& VideoDim, const QSize& VideoDispDim,
float Aspect, MythCodecID CodecId, bool& AspectOnly,
MythMultiLocker* /*Locks*/, int ReferenceFrames,
bool ForceChange)
{
QSize currentvideodim = GetVideoDim();
QSize currentvideodispdim = GetVideoDispDim();
MythCodecID currentcodec = m_videoCodecID;
float currentaspect = GetVideoAspect();
if (m_newCodecId != kCodec_NONE)
{
// InputChanged has been called twice in quick succession without a call to ProcessFrame
currentvideodim = m_newVideoDim;
currentvideodispdim = m_newVideoDispDim;
currentcodec = m_newCodecId;
currentaspect = m_newAspect;
}
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Video changed: %1x%2 (%3x%4) '%5' (Aspect %6 Refs %13)"
"-> %7x%8 (%9x%10) '%11' (Aspect %12 Refs %14)")
.arg(currentvideodispdim.width()).arg(currentvideodispdim.height())
.arg(currentvideodim.width()).arg(currentvideodim.height())
.arg(toString(currentcodec)).arg(static_cast<double>(currentaspect))
.arg(VideoDispDim.width()).arg(VideoDispDim.height())
.arg(VideoDim.width()).arg(VideoDim.height())
.arg(toString(CodecId)).arg(static_cast<double>(Aspect))
.arg(m_maxReferenceFrames).arg(ReferenceFrames));
bool cidchanged = (CodecId != currentcodec);
bool reschanged = (VideoDispDim != currentvideodispdim);
bool refschanged = m_maxReferenceFrames != ReferenceFrames;
// aspect ratio changes are a no-op as changes are handled at display time
if (!(cidchanged || reschanged || refschanged || ForceChange))
{
AspectOnly = true;
return true;
}
// N.B. We no longer check for interop support for the new codec as it is a
// poor substitute for a full check of decoder capabilities etc. Better to let
// hardware decoding fail if necessary - which should at least fallback to
// software decoding rather than bailing out here.
// delete and recreate the buffers and flag that the input has changed
m_maxReferenceFrames = ReferenceFrames;
m_buffersCreated = m_videoBuffers.DiscardAndRecreate(CodecId, VideoDim, m_maxReferenceFrames);
if (!m_buffersCreated)
return false;
m_newCodecId= CodecId;
m_newVideoDim = VideoDim;
m_newVideoDispDim = VideoDispDim;
m_newAspect = Aspect;
return true;
}
bool MythVideoOutputGPU::ProcessInputChange()
{
if (m_newCodecId != kCodec_NONE)
{
// Ensure we don't lose embedding through program changes.
bool wasembedding = IsEmbedding();
QRect oldrect;
if (wasembedding)
{
oldrect = GetEmbeddingRect();
StopEmbedding();
}
// Note - we don't call the default VideoOutput::InputChanged method as
// the OpenGL implementation is asynchronous.
// So we need to update the video display profile here. It is a little
// circular as we need to set the video dimensions first which are then
// reset in Init.
// All told needs a cleanup - not least because the use of codecName appears
// to be inconsistent.
SourceChanged(m_newVideoDim, m_newVideoDispDim, m_newAspect);
AVCodecID avCodecId = myth2av_codecid(m_newCodecId);
AVCodec* codec = avcodec_find_decoder(avCodecId);
QString codecName;
if (codec)
codecName = codec->name;
if (m_dbDisplayProfile)
m_dbDisplayProfile->SetInput(GetVideoDispDim(), 0 , codecName);
bool ok = Init(m_newVideoDim, m_newVideoDispDim, m_newAspect, GetRawWindowRect(), m_newCodecId);
m_newCodecId = kCodec_NONE;
m_newVideoDim = QSize();
m_newVideoDispDim = QSize();
m_newAspect = 0.0F;
m_newFrameRate = false;
if (wasembedding && ok)
EmbedInWidget(oldrect);
// Update deinterlacers for any input change
SetDeinterlacing(m_deinterlacing, m_deinterlacing2X, m_forcedDeinterlacer);
if (!ok)
return false;
}
else if (m_newFrameRate)
{
// If we are switching mode purely for a refresh rate change, then there
// is no need to recreate buffers etc etc
ResizeForVideo();
m_newFrameRate = false;
}
return true;
}
/*! \brief Initialise display measurement
*
* The sole intent here is to ensure that MythVideoBounds has the correct aspect
* ratio when it calculates the video display rectangle.
*/
void MythVideoOutputGPU::InitDisplayMeasurements()
{
if (!m_display)
return;
// Retrieve the display aspect ratio.
// This will be, in priority order:-
// - aspect ratio override when using resolution/mode switching (if not 'Default')
// - aspect ratio override for setups where detection does not work/is broken (multiscreen, broken EDID etc)
// - aspect ratio based on detected physical size (this should be the common/default value)
// - aspect ratio fallback using screen resolution
// - 16:9
QString source;
double displayaspect = m_display->GetAspectRatio(source);
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Display aspect ratio: %1 (%2)")
.arg(displayaspect).arg(source));
// Get the window and screen resolutions
QSize window = GetRawWindowRect().size();
QSize screen = m_display->GetResolution();
// If not running fullscreen, adjust for window size and ignore any video
// mode overrides as they do not apply when in a window
if (!window.isEmpty() && !screen.isEmpty() && window != screen)
{
displayaspect = m_display->GetAspectRatio(source, true);
double screenaspect = screen.width() / static_cast<double>(screen.height());
double windowaspect = window.width() / static_cast<double>(window.height());
displayaspect = displayaspect * (1.0 / screenaspect) * windowaspect;
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Window aspect ratio: %1").arg(displayaspect));
}
SetDisplayAspect(static_cast<float>(displayaspect));
}
void MythVideoOutputGPU::PrepareFrame(VideoFrame* Frame, const PIPMap &PiPPlayers, FrameScanType Scan)
{
// Process input changes
if (!ProcessInputChange())
return;
if (!IsEmbedding())
ShowPIPs(PiPPlayers);
if (Frame)
{
SetRotation(Frame->rotation);
if (format_is_hw(Frame->codec) || Frame->dummy)
return;
// software deinterlacing
m_deinterlacer.Filter(Frame, Scan, m_dbDisplayProfile);
// update software textures
if (m_video)
m_video->PrepareFrame(Frame, Scan);
}
}
void MythVideoOutputGPU::RenderFrame(VideoFrame *Frame, FrameScanType Scan, OSD *Osd)
{
bool dummy = false;
bool topfieldfirst = false;
if (Frame)
{
m_framesPlayed = Frame->frameNumber + 1;
topfieldfirst = Frame->interlaced_reversed ? !Frame->top_field_first : Frame->top_field_first;
dummy = Frame->dummy;
}
else
{
// see DoneDisplayingFrame
// we only retain pause frames for hardware formats
if (m_videoBuffers.Size(kVideoBuffer_pause))
Frame = m_videoBuffers.Tail(kVideoBuffer_pause);
}
// Main UI when embedded
if (m_painter && IsEmbedding())
{
// If we are using high dpi, the painter needs to set the appropriate
// viewport and enable scaling of its images
m_painter->SetViewControl(MythPainterGPU::Viewport);
MythMainWindow* win = GetMythMainWindow();
if (win && win->GetPaintWindow())
{
win->GetPaintWindow()->clearMask();
win->Draw(m_painter);
}
m_painter->SetViewControl(MythPainterGPU::None);
}
// Video
// N.B. dummy streams need the viewport updated in case we have resized the window (i.e. LiveTV)
if (m_video && !dummy)
m_video->RenderFrame(Frame, topfieldfirst, Scan, GetStereoscopicMode());
else if (dummy)
m_render->SetViewPort(GetWindowRect());
// PiPs/PBPs
if (!m_pxpVideos.empty() && !IsEmbedding())
{
for (auto it = m_pxpVideos.begin(); it != m_pxpVideos.end(); ++it)
{
if (m_pxpVideosReady[it.key()] && (*it))
{
bool active = m_pxpVideoActive == *it;
(*it)->RenderFrame(nullptr, topfieldfirst, Scan, kStereoscopicModeAuto, active);
}
}
}
const QRect osdbounds = GetTotalOSDBounds();
// Visualisation
if (m_visual && m_painter && !IsEmbeddingAndHidden())
m_visual->Draw(osdbounds, m_painter, nullptr);
// OSD
if (Osd && m_painter && !IsEmbedding())
Osd->Draw(m_painter, osdbounds.size(), true);
}
void MythVideoOutputGPU::UpdatePauseFrame(int64_t& DisplayTimecode, FrameScanType Scan)
{
VideoFrame* release = nullptr;
m_videoBuffers.BeginLock(kVideoBuffer_used);
VideoFrame* used = m_videoBuffers.Head(kVideoBuffer_used);
if (used)
{
if (format_is_hw(used->codec))
{
release = m_videoBuffers.Dequeue(kVideoBuffer_used);
}
else
{
Scan = (is_interlaced(Scan) && !used->already_deinterlaced) ? kScan_Interlaced : kScan_Progressive;
m_deinterlacer.Filter(used, Scan, m_dbDisplayProfile, true);
if (m_video)
m_video->PrepareFrame(used, Scan);
}
DisplayTimecode = used->disp_timecode;
}
else
{
LOG(VB_PLAYBACK, LOG_WARNING, LOC + "Could not update pause frame");
}
m_videoBuffers.EndLock();
if (release)
DoneDisplayingFrame(release);
}
void MythVideoOutputGPU::EndFrame()
{
m_video->EndFrame();
}
void MythVideoOutputGPU::ClearAfterSeek()
{
// Clear reference frames for GPU deinterlacing
if (m_video)
m_video->ResetTextures();
// Clear decoded frames
MythVideoOutput::ClearAfterSeek();
}
bool MythVideoOutputGPU::EnableVisualisation(AudioPlayer* Audio, bool Enable, const QString& Name)
{
if (!Enable)
{
DestroyVisualisation();
return false;
}
return SetupVisualisation(Audio, Name);
}
QString MythVideoOutputGPU::GetVisualiserName()
{
if (m_visual)
return m_visual->Name();
return MythVideoOutput::GetVisualiserName();
}
void MythVideoOutputGPU::DestroyVisualisation()
{
delete m_visual;
m_visual = nullptr;
}
bool MythVideoOutputGPU::StereoscopicModesAllowed() const
{
return true;
}
QStringList MythVideoOutputGPU::GetVisualiserList()
{
if (m_render)
return VideoVisual::GetVisualiserList(m_render->Type());
return MythVideoOutput::GetVisualiserList();
}
bool MythVideoOutputGPU::CanVisualise(AudioPlayer* Audio)
{
return VideoVisual::CanVisualise(Audio, m_render);
}
bool MythVideoOutputGPU::SetupVisualisation(AudioPlayer* Audio, const QString& Name)
{
DestroyVisualisation();
m_visual = VideoVisual::Create(Name, Audio, m_render);
return m_visual != nullptr;
}
VideoVisual* MythVideoOutputGPU::GetVisualisation()
{
return m_visual;
}
void MythVideoOutputGPU::ShowPIPs(const PIPMap& PiPPlayers)
{
m_pxpVideoActive = nullptr;
for (auto it = PiPPlayers.cbegin(); it != PiPPlayers.cend(); ++it)
ShowPIP(it.key(), *it);
}
void MythVideoOutputGPU::ShowPIP(MythPlayer* PiPPlayer, PIPLocation Location)
{
if (!PiPPlayer)
return;
int pipw = 0;
int piph = 0;
VideoFrame* pipimage = PiPPlayer->GetCurrentFrame(pipw, piph);
const QSize pipvideodim = PiPPlayer->GetVideoBufferSize();
QRect pipvideorect = QRect(QPoint(0, 0), pipvideodim);
if ((PiPPlayer->GetVideoAspect() <= 0.0F) || !pipimage || !pipimage->buf ||
(pipimage->codec != FMT_YV12) || !PiPPlayer->IsPIPVisible())
{
PiPPlayer->ReleaseCurrentFrame(pipimage);
return;
}
QRect position = GetPIPRect(Location, PiPPlayer);
QRect dvr = GetDisplayVisibleRectAdj();
m_pxpVideosReady[PiPPlayer] = false;
MythVideoGPU* video = m_pxpVideos[PiPPlayer];
if (video && video->GetVideoDim() != pipvideodim)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC + "Re-initialise PiP.");
delete video;
video = nullptr;
}
if (!video)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC + "Initialise PiP");
video = CreateSecondaryVideo(pipvideodim, pipvideodim, dvr, position, pipvideorect);
}
m_pxpVideos[PiPPlayer] = video;
if (video)
{
if (!video->IsValid())
{
PiPPlayer->ReleaseCurrentFrame(pipimage);
return;
}
video->SetMasterViewport(dvr.size());
video->SetVideoRects(position, pipvideorect);
video->PrepareFrame(pipimage);
}
m_pxpVideosReady[PiPPlayer] = true;
if (PiPPlayer->IsPIPActive())
m_pxpVideoActive = video;
PiPPlayer->ReleaseCurrentFrame(pipimage);
}
void MythVideoOutputGPU::RemovePIP(MythPlayer* PiPPlayer)
{
if (m_pxpVideos.contains(PiPPlayer))
{
delete m_pxpVideos.take(PiPPlayer);
m_pxpVideosReady.remove(PiPPlayer);
m_pxpVideos.remove(PiPPlayer);
}
}
/**
* \fn VideoOutput::ResizeForVideo(uint width, uint height)
* Sets display parameters based on video resolution.
*
* If we are using DisplayRes support we use the video size to
* determine the desired screen size and refresh rate.
* If we are also not using "GuiSizeForTV" we also resize
* the video output window.
*
* \param width,height Resolution of the video we will be playing
*/
void MythVideoOutputGPU::ResizeForVideo(QSize Size)
{
if (!m_display)
return;
if (!m_display->UsingVideoModes())
return;
if (Size.isEmpty())
{
Size = GetVideoDispDim();
if (Size.isEmpty())
return;
}
float rate = m_dbDisplayProfile ? m_dbDisplayProfile->GetOutput() : 0.0F;
bool hide = m_display->NextModeIsLarger(Size);
MythMainWindow* window = GetMythMainWindow();
if (hide)
window->hide();
if (m_display->SwitchToVideo(Size, static_cast<double>(rate)))
{
// Switching to custom display resolution succeeded
// Make a note of the new size
QString source;
double aspect = m_display->GetAspectRatio(source);
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Aspect ratio: %1 (%2)")
.arg(aspect).arg(source));
SetDisplayAspect(static_cast<float>(aspect));
SetWindowSize(m_display->GetResolution());
bool fullscreen = !UsingGuiSize();
// if width && height are zero users expect fullscreen playback
if (!fullscreen)
{
int gui_width = 0;
int gui_height = 0;
gCoreContext->GetResolutionSetting("Gui", gui_width, gui_height);
fullscreen |= (0 == gui_width && 0 == gui_height);
}
if (fullscreen)
{
QSize sz = m_display->GetResolution();
QRect display_visible_rect = QRect(GetMythMainWindow()->geometry().topLeft(), sz);
if (HasMythMainWindow())
{
if (hide)
{
window->Show();
hide = false;
}
GetMythMainWindow()->MoveResize(display_visible_rect);
}
}
}
if (hide)
window->Show();
}