/
mythplayer.cpp
4688 lines (4067 loc) · 132 KB
/
mythplayer.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
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- Mode: c++ -*-
#undef HAVE_AV_CONFIG_H
// Std C headers
#include <stdint.h>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cerrno>
#include <ctime>
#include <cmath>
// POSIX headers
#include <unistd.h>
#include <fcntl.h>
#include <sched.h>
#include <sys/time.h>
// C++ headers
#include <algorithm>
#include <iostream>
using namespace std;
// Qt headers
#include <QCoreApplication>
#include <QThread>
#include <QKeyEvent>
#include <QDir>
// MythTV headers
#include "mythconfig.h"
#include "mythdbcon.h"
#include "dialogbox.h"
#include "mythplayer.h"
#include "DetectLetterbox.h"
#include "audioplayer.h"
#include "recordingprofile.h"
#include "teletextscreen.h"
#include "interactivescreen.h"
#include "remoteutil.h"
#include "programinfo.h"
#include "mythcorecontext.h"
#include "fifowriter.h"
#include "filtermanager.h"
#include "util.h"
#include "decodeencode.h"
#include "livetvchain.h"
#include "decoderbase.h"
#include "nuppeldecoder.h"
#include "avformatdecoder.h"
#include "dummydecoder.h"
#include "jobqueue.h"
#include "NuppelVideoRecorder.h"
#include "tv_play.h"
#include "interactivetv.h"
#include "mythverbose.h"
#include "myth_imgconvert.h"
#include "mythsystemevent.h"
#include "mythpainter.h"
#include "mythimage.h"
#include "mythuiimage.h"
extern "C" {
#include "vbitext/vbi.h"
#include "vsync.h"
#include "libavcodec/avcodec.h"
#include "libswscale/swscale.h"
}
#include "remoteencoder.h"
#include "videoout_null.h"
#if ! HAVE_ROUND
#define round(x) ((int) ((x) + 0.5))
#endif
#if CONFIG_DARWIN
extern "C" {
int isnan(double);
}
#endif
static unsigned dbg_ident(const MythPlayer*);
#define LOC QString("Player(%1): ").arg(dbg_ident(this),0,36)
#define LOC_WARN QString("Player(%1), Warning: ").arg(dbg_ident(this),0,36)
#define LOC_ERR QString("Player(%1), Error: ").arg(dbg_ident(this),0,36)
#define LOC_DEC QString("Player(%1): ").arg(dbg_ident(m_mp),0,36)
void DecoderThread::run(void)
{
if (!m_mp)
return;
VERBOSE(VB_PLAYBACK, LOC_DEC + QString("Decoder thread starting."));
m_mp->DecoderLoop(m_start_paused);
VERBOSE(VB_PLAYBACK, LOC_DEC + QString("Decoder thread exiting."));
}
static const int toCaptionType(int 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 const int toTrackType(int 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 0;
}
MythPlayer::MythPlayer(bool muted)
: decoder(NULL), decoder_change_lock(QMutex::Recursive),
videoOutput(NULL), player_ctx(NULL),
decoderThread(NULL), playerThread(NULL),
no_hardware_decoders(false),
// Window stuff
parentWidget(NULL), embedid(0),
embx(-1), emby(-1), embw(-1), embh(-1),
// State
decoderEof(false),
decoderPaused(false), pauseDecoder(false), unpauseDecoder(false),
killdecoder(false), decoderSeek(-1), decodeOneFrame(false),
needNewPauseFrame(false),
bufferPaused(false), videoPaused(false),
allpaused(false), playing(false),
m_double_framerate(false), m_double_process(false),
m_can_double(false), m_deint_possible(true),
livetv(false),
watchingrecording(false), using_null_videoout(false),
transcoding(false),
hasFullPositionMap(false), limitKeyRepeat(false),
errorMsg(QString::null), errorType(kError_None),
// Chapter stuff
jumpchapter(0),
// Bookmark stuff
bookmarkseek(0),
// Seek
fftime(0), exactseeks(false),
// Playback misc.
videobuf_retries(0), framesPlayed(0),
totalFrames(0), totalLength(0),
totalDuration(0),
rewindtime(0),
// Input Video Attributes
video_disp_dim(0,0), video_dim(0,0),
video_frame_rate(29.97f), video_aspect(4.0f / 3.0f),
forced_video_aspect(-1),
m_scan(kScan_Interlaced), m_scan_locked(false),
m_scan_tracker(0), m_scan_initialized(false),
keyframedist(30), noVideoTracks(false),
// Prebuffering
buffering(false),
// General Caption/Teletext/Subtitle support
textDisplayMode(kDisplayNone),
prevTextDisplayMode(kDisplayNone),
// Support for analog captions and teletext
vbimode(VBIMode::None),
ttPageNum(0x888),
// Support for captions, teletext, etc. decoded by libav
textDesired(false), enableCaptions(false), disableCaptions(false),
// CC608/708
db_prefer708(true), cc608(this), cc708(this),
// MHEG/MHI Interactive TV visible in OSD
itvVisible(false),
interactiveTV(NULL),
itvEnabled(false),
// OSD stuff
osd(NULL), reinit_osd(false), osdLock(QMutex::Recursive),
// Audio
audio(this, muted),
// Picture-in-Picture stuff
pip_active(false), pip_visible(true),
// Filters
videoFiltersForProgram(""), videoFiltersOverride(""),
postfilt_width(0), postfilt_height(0),
videoFilters(NULL), FiltMan(new FilterManager()),
forcePositionMapSync(false), pausedBeforeEdit(false),
speedBeforeEdit(1.0f),
// Playback (output) speed control
decoder_lock(QMutex::Recursive),
next_play_speed(1.0f), next_normal_speed(true),
play_speed(1.0f), normal_speed(true),
frame_interval((int)(1000000.0f / 30)), m_frame_interval(0),
ffrew_skip(1),ffrew_adjust(0),
// Audio and video synchronization stuff
videosync(NULL), avsync_delay(0),
avsync_adjustment(0), avsync_avg(0),
avsync_predictor(0), avsync_predictor_enabled(false),
refreshrate(0),
lastsync(false), repeat_delay(0),
disp_timecode(0),
// Time Code stuff
prevtc(0), prevrp(0),
// LiveTVChain stuff
m_tv(NULL), isDummy(false),
// Debugging variables
output_jmeter(NULL)
{
playerThread = QThread::currentThread();
// Playback (output) zoom control
detect_letter_box = new DetectLetterbox(this);
vbimode = VBIMode::Parse(gCoreContext->GetSetting("VbiFormat"));
decode_extra_audio = gCoreContext->GetNumSetting("DecodeExtraAudio", 0);
itvEnabled = gCoreContext->GetNumSetting("EnableMHEG", 0);
db_prefer708 = gCoreContext->GetNumSetting("Prefer708Captions", 1);
memset(&tc_lastval, 0, sizeof(tc_lastval));
memset(&tc_wrap, 0, sizeof(tc_wrap));
tc_wrap[TC_AUDIO] = gCoreContext->GetNumSetting("AudioSyncOffset", 0);
// Get VBI page number
QString mypage = gCoreContext->GetSetting("VBIpageNr", "888");
bool valid = false;
uint tmp = mypage.toInt(&valid, 16);
ttPageNum = (valid) ? tmp : ttPageNum;
cc608.SetTTPageNum(ttPageNum);
}
MythPlayer::~MythPlayer(void)
{
QMutexLocker lk1(&osdLock);
QMutexLocker lk2(&vidExitLock);
QMutexLocker lk3(&videofiltersLock);
if (osd)
{
delete osd;
osd = NULL;
}
SetDecoder(NULL);
if (decoderThread)
{
delete decoderThread;
decoderThread = NULL;
}
if (interactiveTV)
{
delete interactiveTV;
interactiveTV = NULL;
}
if (FiltMan)
{
delete FiltMan;
FiltMan = NULL;
}
if (videoFilters)
{
delete videoFilters;
videoFilters = NULL;
}
if (videosync)
{
delete videosync;
videosync = NULL;
}
if (videoOutput)
{
delete videoOutput;
videoOutput = NULL;
}
if (output_jmeter)
{
delete output_jmeter;
output_jmeter = NULL;
}
if (detect_letter_box)
{
delete detect_letter_box;
detect_letter_box = NULL;
}
}
void MythPlayer::SetWatchingRecording(bool mode)
{
QMutexLocker locker(&decoder_change_lock);
watchingrecording = mode;
if (decoder)
decoder->setWatchingRecording(mode);
}
void MythPlayer::PauseBuffer(void)
{
bufferPauseLock.lock();
if (player_ctx->buffer)
{
player_ctx->buffer->Pause();
player_ctx->buffer->WaitForPause();
}
bufferPaused = true;
bufferPauseLock.unlock();
}
void MythPlayer::UnpauseBuffer(void)
{
bufferPauseLock.lock();
if (player_ctx->buffer)
player_ctx->buffer->Unpause();
bufferPaused = false;
bufferPauseLock.unlock();
}
bool MythPlayer::Pause(void)
{
if (!pauseLock.tryLock(100))
{
VERBOSE(VB_PLAYBACK, LOC + "Waited 100ms to get pause lock.");
DecoderPauseCheck();
}
bool already_paused = allpaused;
if (already_paused)
{
pauseLock.unlock();
return already_paused;
}
next_play_speed = 0.0;
next_normal_speed = false;
PauseVideo();
audio.Pause(true);
PauseBuffer();
PauseDecoder();
allpaused = decoderPaused && videoPaused && bufferPaused;
{
QMutexLocker locker(&decoder_change_lock);
if (using_null_videoout && decoder)
decoder->UpdateFramesPlayed();
else if (videoOutput && !using_null_videoout)
framesPlayed = videoOutput->GetFramesPlayed();
}
pauseLock.unlock();
return already_paused;
}
bool MythPlayer::Play(float speed, bool normal, bool unpauseaudio)
{
pauseLock.lock();
VERBOSE(VB_PLAYBACK, LOC +
QString("Play(%1, normal %2, unpause audio %3)")
.arg(speed,5,'f',1).arg(normal).arg(unpauseaudio));
if (deleteMap.IsEditing())
{
VERBOSE(VB_IMPORTANT, LOC + "Ignoring Play(), in edit mode.");
pauseLock.unlock();
return false;
}
UnpauseBuffer();
UnpauseDecoder();
if (unpauseaudio)
audio.Pause(false);
UnpauseVideo();
allpaused = false;
next_play_speed = speed;
next_normal_speed = normal;
pauseLock.unlock();
return true;
}
void MythPlayer::PauseVideo(void)
{
videoPauseLock.lock();
needNewPauseFrame = true;
videoPaused = true;
videoPauseLock.unlock();
}
void MythPlayer::UnpauseVideo(void)
{
videoPauseLock.lock();
videoPaused = false;
if (videoOutput)
videoOutput->ExposeEvent();
videoPauseLock.unlock();
}
void MythPlayer::SetPlayingInfo(const ProgramInfo &pginfo)
{
assert(player_ctx);
if (!player_ctx)
return;
player_ctx->LockPlayingInfo(__FILE__, __LINE__);
player_ctx->SetPlayingInfo(&pginfo);
player_ctx->UnlockPlayingInfo(__FILE__, __LINE__);
SetVideoFilters("");
InitFilters();
}
void MythPlayer::SetPlaying(bool is_playing)
{
QMutexLocker locker(&playingLock);
playing = is_playing;
playingWaitCond.wakeAll();
}
bool MythPlayer::IsPlaying(uint wait_in_msec, bool wait_for) const
{
QMutexLocker locker(&playingLock);
if (!wait_in_msec)
return playing;
MythTimer t;
t.start();
while ((wait_for != playing) && ((uint)t.elapsed() < wait_in_msec))
{
playingWaitCond.wait(
&playingLock, max(0,(int)wait_in_msec - t.elapsed()));
}
return playing;
}
bool MythPlayer::InitVideo(void)
{
assert(player_ctx);
if (!player_ctx)
return false;
PIPState pipState = player_ctx->GetPIPState();
if (using_null_videoout && decoder)
{
MythCodecID codec = decoder->GetVideoCodecID();
videoOutput = new VideoOutputNull();
if (!videoOutput->Init(video_disp_dim.width(), video_disp_dim.height(),
video_aspect, 0, 0, 0, 0, 0, codec, 0))
{
VERBOSE(VB_IMPORTANT, LOC_ERR +
"Unable to create null video out");
SetErrored(QObject::tr("Unable to create null video out"));
return false;
}
}
else
{
QWidget *widget = parentWidget;
if (!widget)
{
MythMainWindow *window = GetMythMainWindow();
widget = window->findChild<QWidget*>("video playback window");
if (!widget)
{
VERBOSE(VB_IMPORTANT, "Couldn't find 'tv playback' widget");
widget = window->currentWidget();
}
}
if (!widget)
{
VERBOSE(VB_IMPORTANT, "Couldn't find 'tv playback' widget. "
"Current widget doesn't exist. Exiting..");
SetErrored(QObject::tr("'tv playback' widget missing."));
return false;
}
QRect display_rect;
if (pipState == kPIPStandAlone)
display_rect = QRect(embx, emby, embw, embh);
else
display_rect = QRect(0, 0, widget->width(), widget->height());
if (decoder)
{
videoOutput = VideoOutput::Create(
decoder->GetCodecDecoderName(),
decoder->GetVideoCodecID(),
decoder->GetVideoCodecPrivate(),
pipState,
video_disp_dim, video_aspect,
widget->winId(), display_rect, video_frame_rate,
0 /*embedid*/);
}
if (videoOutput)
{
videoOutput->SetVideoScalingAllowed(true);
CheckExtraAudioDecode();
}
}
if (!videoOutput)
{
VERBOSE(VB_IMPORTANT, LOC_ERR +
"Couldn't create VideoOutput instance. Exiting..");
SetErrored(QObject::tr("Failed to initialize video output"));
return false;
}
if (embedid > 0 && pipState == kPIPOff)
{
videoOutput->EmbedInWidget(embx, emby, embw, embh);
}
InitFilters();
return true;
}
void MythPlayer::CheckExtraAudioDecode(void)
{
if (using_null_videoout)
return;
bool force = false;
if (videoOutput && videoOutput->NeedExtraAudioDecode())
{
VERBOSE(VB_IMPORTANT, LOC +
"Forcing decode extra audio option on"
" (Video method requires it).");
force = true;
}
if (decoder)
decoder->SetLowBuffers(decode_extra_audio || force);
}
void MythPlayer::ReinitOSD(void)
{
if (videoOutput && !using_null_videoout)
{
osdLock.lock();
if (QThread::currentThread() != (QThread*)playerThread)
{
reinit_osd = true;
osdLock.unlock();
return;
}
QRect visible, total;
float aspect, scaling;
if (osd)
{
osd->SetPainter(videoOutput->GetOSDPainter());
videoOutput->GetOSDBounds(total, visible, aspect,
scaling, 1.0f);
if (osd->Bounds() != visible)
{
uint old = textDisplayMode;
ToggleCaptions(old);
osd->Reinit(visible, aspect);
EnableCaptions(old, false);
}
}
#ifdef USING_MHEG
if (GetInteractiveTV())
{
QMutexLocker locker(&itvLock);
total = videoOutput->GetMHEGBounds();
interactiveTV->Reinit(total);
itvVisible = false;
}
#endif // USING_MHEG
reinit_osd = false;
osdLock.unlock();
}
}
void MythPlayer::ReinitVideo(void)
{
if (!videoOutput->IsPreferredRenderer(video_disp_dim))
{
VERBOSE(VB_PLAYBACK, LOC + QString("Need to switch video renderer."));
SetErrored(QObject::tr("Need to switch video renderer."));
errorType |= kError_Switch_Renderer;
return;
}
bool aspect_only = false;
{
QMutexLocker locker1(&osdLock);
QMutexLocker locker2(&vidExitLock);
QMutexLocker locker3(&videofiltersLock);
videoOutput->SetVideoFrameRate(video_frame_rate);
float aspect = (forced_video_aspect > 0) ? forced_video_aspect :
video_aspect;
if (!videoOutput->InputChanged(video_disp_dim, aspect,
decoder->GetVideoCodecID(),
decoder->GetVideoCodecPrivate(),
aspect_only))
{
VERBOSE(VB_IMPORTANT, LOC_ERR +
"Failed to Reinitialize Video. Exiting..");
SetErrored(QObject::tr("Failed to reinitialize video output"));
return;
}
if (osd)
osd->SetPainter(videoOutput->GetOSDPainter());
ReinitOSD();
}
if (!aspect_only)
{
CheckExtraAudioDecode();
ClearAfterSeek();
InitFilters();
}
if (textDisplayMode)
{
DisableCaptions(textDisplayMode, false);
SetCaptionsEnabled(true, false);
}
}
static inline QString toQString(FrameScanType scan) {
switch (scan) {
case kScan_Ignore: return QString("Ignore Scan");
case kScan_Detect: return QString("Detect Scan");
case kScan_Interlaced: return QString("Interlaced Scan");
case kScan_Progressive: return QString("Progressive Scan");
default: return QString("Unknown Scan");
}
}
FrameScanType MythPlayer::detectInterlace(FrameScanType newScan,
FrameScanType scan,
float fps, int video_height)
{
QString dbg = QString("detectInterlace(") + toQString(newScan) +
QString(", ") + toQString(scan) + QString(", ") + QString("%1").arg(fps) +
QString(", ") + QString("%1").arg(video_height) + QString(") ->");
if (kScan_Ignore != newScan || kScan_Detect == scan)
{
// The scanning mode should be decoded from the stream, but if it
// isn't, we have to guess.
scan = kScan_Interlaced; // default to interlaced
if (720 == video_height) // ATSC 720p
scan = kScan_Progressive;
else if (fps > 45) // software deinterlacing
scan = kScan_Progressive;
if (kScan_Detect != newScan)
scan = newScan;
};
VERBOSE(VB_PLAYBACK, LOC + dbg+toQString(scan));
return scan;
}
void MythPlayer::SetKeyframeDistance(int keyframedistance)
{
keyframedist = (keyframedistance > 0) ? keyframedistance : keyframedist;
}
/** \fn MythPlayer::FallbackDeint(void)
* \brief Fallback to non-frame-rate-doubling deinterlacing method.
*/
void MythPlayer::FallbackDeint(void)
{
m_double_framerate = false;
m_double_process = false;
if (videoOutput)
videoOutput->FallbackDeint();
}
void MythPlayer::AutoDeint(VideoFrame *frame, bool allow_lock)
{
if (!frame || m_scan_locked)
return;
if (frame->interlaced_frame)
{
if (m_scan_tracker < 0)
{
VERBOSE(VB_PLAYBACK, LOC + "interlaced frame seen after "
<< abs(m_scan_tracker) << " progressive frames");
m_scan_tracker = 2;
if (allow_lock)
{
VERBOSE(VB_PLAYBACK, LOC + "Locking scan to Interlaced.");
SetScanType(kScan_Interlaced);
return;
}
}
m_scan_tracker++;
}
else
{
if (m_scan_tracker > 0)
{
VERBOSE(VB_PLAYBACK, LOC + "progressive frame seen after "
<< m_scan_tracker << " interlaced frames");
m_scan_tracker = 0;
}
m_scan_tracker--;
}
if ((m_scan_tracker % 400) == 0)
{
QString type = (m_scan_tracker < 0) ? "progressive" : "interlaced";
VERBOSE(VB_PLAYBACK, LOC + QString("%1 %2 frames seen.")
.arg(abs(m_scan_tracker)).arg(type));
}
int min_count = !allow_lock ? 0 : 2;
if (abs(m_scan_tracker) <= min_count)
return;
SetScanType((m_scan_tracker > min_count) ? kScan_Interlaced : kScan_Progressive);
m_scan_locked = false;
}
void MythPlayer::SetScanType(FrameScanType scan)
{
QMutexLocker locker(&videofiltersLock);
if (!videoOutput || !videosync)
return; // hopefully this will be called again later...
if (m_scan_initialized &&
m_scan == scan &&
m_frame_interval == frame_interval)
return;
m_scan_locked = (scan != kScan_Detect);
m_scan_initialized = true;
m_frame_interval = frame_interval;
bool interlaced = is_interlaced(scan);
if (interlaced && !m_deint_possible)
{
m_scan = scan;
return;
}
if (interlaced)
{
m_deint_possible = videoOutput->SetDeinterlacingEnabled(true);
if (!m_deint_possible)
{
VERBOSE(VB_IMPORTANT, LOC + "Failed to enable deinterlacing");
m_scan = scan;
return;
}
if (videoOutput->NeedsDoubleFramerate())
{
m_double_framerate = true;
m_can_double = (frame_interval / 2 > videosync->getRefreshInterval() * 0.995);
if (!m_can_double)
{
VERBOSE(VB_IMPORTANT, LOC + "Video sync method can't support "
"double framerate (refresh rate too low for 2x deint)");
FallbackDeint();
}
}
m_double_process = videoOutput->IsExtraProcessingRequired();
VERBOSE(VB_PLAYBACK, LOC + "Enabled deinterlacing");
}
else
{
if (kScan_Progressive == scan)
{
m_double_process = false;
m_double_framerate = false;
videoOutput->SetDeinterlacingEnabled(false);
VERBOSE(VB_PLAYBACK, LOC + "Disabled deinterlacing");
}
}
m_scan = scan;
}
void MythPlayer::SetVideoParams(int width, int height, double fps,
int keyframedistance, float aspect,
FrameScanType scan, bool video_codec_changed)
{
if (width == 0 || height == 0 || isnan(aspect) || isnan(fps))
return;
if ((video_disp_dim == QSize(width, height)) &&
(video_aspect == aspect) && (video_frame_rate == fps ) &&
((keyframedistance <= 0) ||
((uint64_t)keyframedistance == keyframedist)) &&
!video_codec_changed)
{
return;
}
if ((width > 0) && (height > 0))
{
video_dim = QSize((width + 15) & ~0xf, (height + 15) & ~0xf);
video_disp_dim = QSize(width, height);
}
video_aspect = (aspect > 0.0f) ? aspect : video_aspect;
keyframedist = (keyframedistance > 0) ? keyframedistance : keyframedist;
if (fps > 0.0f && fps < 121.0f)
{
video_frame_rate = fps;
float temp_speed = (play_speed == 0.0f) ?
audio.GetStretchFactor() : play_speed;
SetFrameInterval(kScan_Progressive, 1.0 / (video_frame_rate * temp_speed));
}
if (videoOutput)
ReinitVideo();
if (IsErrored())
return;
SetScanType(detectInterlace(scan, m_scan, video_frame_rate,
video_disp_dim.height()));
m_scan_locked = false;
m_scan_tracker = (m_scan == kScan_Interlaced) ? 2 : 0;
}
void MythPlayer::SetFileLength(int total, int frames)
{
totalLength = total;
totalFrames = frames;
}
void MythPlayer::SetDuration(int duration)
{
totalDuration = duration;
}
void MythPlayer::OpenDummy(void)
{
isDummy = true;
float displayAspect =
gCoreContext->GetFloatSettingOnHost("XineramaMonitorAspectRatio",
gCoreContext->GetHostName(), 1.3333);
if (!videoOutput)
{
SetVideoParams(720, 576, 25.00, 15, displayAspect);
}
player_ctx->LockPlayingInfo(__FILE__, __LINE__);
DummyDecoder *dec = new DummyDecoder(this, *(player_ctx->playingInfo));
player_ctx->UnlockPlayingInfo(__FILE__, __LINE__);
SetDecoder(dec);
}
void MythPlayer::CreateDecoder(char *testbuf, int testreadsize,
bool allow_libmpeg2, bool no_accel)
{
if (NuppelDecoder::CanHandle(testbuf, testreadsize))
SetDecoder(new NuppelDecoder(this, *player_ctx->playingInfo));
else if (AvFormatDecoder::CanHandle(testbuf,
player_ctx->buffer->GetFilename(),
testreadsize))
{
SetDecoder(new AvFormatDecoder(this, *player_ctx->playingInfo,
using_null_videoout,
allow_libmpeg2, no_accel,
player_ctx->GetSpecialDecode()));
}
}
int MythPlayer::OpenFile(uint retries, bool allow_libmpeg2)
{
isDummy = false;
assert(player_ctx);
if (!player_ctx || !player_ctx->buffer)
return -1;
livetv = player_ctx->tvchain;
if (player_ctx->tvchain &&
player_ctx->tvchain->GetCardType(player_ctx->tvchain->GetCurPos()) ==
"DUMMY")
{
OpenDummy();
return 0;
}
player_ctx->buffer->Start();
/// OSX has a small stack, so we put this buffer on the heap instead.
char *testbuf = new char[kDecoderProbeBufferSize];
UnpauseBuffer();
// delete any pre-existing recorder
SetDecoder(NULL);
int testreadsize = 2048;
MythTimer bigTimer; bigTimer.start();
int timeout = (retries + 1) * 500;
while (testreadsize <= kDecoderProbeBufferSize)
{
MythTimer peekTimer; peekTimer.start();
while (player_ctx->buffer->Peek(testbuf, testreadsize) != testreadsize)
{
if (peekTimer.elapsed() > 1000 || bigTimer.elapsed() > timeout)
{
VERBOSE(VB_IMPORTANT, LOC_ERR +
QString("OpenFile(): Could not read "
"first %1 bytes of '%2'")
.arg(testreadsize)
.arg(player_ctx->buffer->GetFilename()));
delete[] testbuf;
return -1;
}
VERBOSE(VB_IMPORTANT, LOC_WARN + "OpenFile() waiting on data");
usleep(50 * 1000);
}
player_ctx->LockPlayingInfo(__FILE__, __LINE__);
bool noaccel = no_hardware_decoders ||
(player_ctx->IsPBP() && !player_ctx->IsPrimaryPBP());
CreateDecoder(testbuf, testreadsize, allow_libmpeg2, noaccel);
player_ctx->UnlockPlayingInfo(__FILE__, __LINE__);
if (decoder || (bigTimer.elapsed() > timeout))
break;
testreadsize <<= 1;
}
if (!decoder)
{
VERBOSE(VB_IMPORTANT, LOC_ERR +
QString("Couldn't find an A/V decoder for: '%1'")
.arg(player_ctx->buffer->GetFilename()));
delete[] testbuf;
return -1;
}
else if (decoder->IsErrored())
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Could not initialize A/V decoder.");
SetDecoder(NULL);
delete[] testbuf;
return -1;
}
decoder->setExactSeeks(exactseeks);
decoder->setLiveTVMode(livetv);
decoder->setWatchingRecording(watchingrecording);
decoder->setTranscoding(transcoding);
CheckExtraAudioDecode();
//noVideoTracks = !decoder->GetTrackCount(kTrackTypeVideo);
decoderEof = false;
// Set 'no_video_decode' to true for audio only decodeing
bool no_video_decode = false;
// We want to locate decoder for video even if using_null_videoout
// is true, only disable if no_video_decode is true.
int ret = decoder->OpenFile(
player_ctx->buffer, no_video_decode, testbuf, testreadsize);
delete[] testbuf;
if (ret < 0)
{
VERBOSE(VB_IMPORTANT, QString("Couldn't open decoder for: %1")
.arg(player_ctx->buffer->GetFilename()));
return -1;
}
audio.CheckFormat();
if (ret > 0)
{
hasFullPositionMap = true;