MCPcopy Create free account
hub / github.com/Aleksoid1978/VideoRenderer / ShouldDrawSampleNow

Method ShouldDrawSampleNow

Source/renbase2.cpp:489–753  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487// to make the decision
488
489HRESULT CBaseVideoRenderer2::ShouldDrawSampleNow(IMediaSample *pMediaSample,
490 __inout REFERENCE_TIME *ptrStart,
491 __inout REFERENCE_TIME *ptrEnd)
492{
493
494 // Don't call us unless there's a clock interface to synchronise with
495 ASSERT(m_pClock);
496
497 // We lose a bit of time depending on the monitor type waiting for the next
498 // screen refresh. On average this might be about 8mSec - so it will be
499 // later than we think when the picture appears. To compensate a bit
500 // we bias the media samples by -8mSec i.e. 80000 UNITs.
501 // We don't ever make a stream time negative (call it paranoia)
502 if (*ptrStart>=80000) {
503 *ptrStart -= 80000;
504 *ptrEnd -= 80000; // bias stop to to retain valid frame duration
505 }
506
507 // Cache the time stamp now. We will want to compare what we did with what
508 // we started with (after making the monitor allowance).
509 m_trRememberStampForPerf = *ptrStart;
510
511 // Get reference times (current and late)
512 REFERENCE_TIME trRealStream; // the real time now expressed as stream time.
513 m_pClock->GetTime(&trRealStream);
514
515 trRealStream -= m_tStart; // convert to stream time (this is a reftime)
516
517 // We have to wory about two versions of "lateness". The truth, which we
518 // try to work out here and the one measured against m_trTarget which
519 // includes long term feedback. We report statistics against the truth
520 // but for operational decisions we work to the target.
521 // We use TimeDiff to make sure we get an integer because we
522 // may actually be late (or more likely early if there is a big time
523 // gap) by a very long time.
524 const int trTrueLate = TimeDiff(trRealStream - *ptrStart);
525 const int trLate = trTrueLate;
526
527 // Send quality control messages upstream, measured against target
528 HRESULT hr = SendQuality(trLate, trRealStream);
529 // Note: the filter upstream is allowed to this FAIL meaning "you do it".
530 m_bSupplierHandlingQuality = (hr==S_OK);
531
532 // Decision time! Do we drop, draw when ready or draw immediately?
533
534 const int trDuration = (int)(*ptrEnd - *ptrStart);
535 {
536 // We need to see if the frame rate of the file has just changed.
537 // This would make comparing our previous frame rate with the current
538 // frame rate inefficient. Hang on a moment though. I've seen files
539 // where the frames vary between 33 and 34 mSec so as to average
540 // 30fps. A minor variation like that won't hurt us.
541 int t = m_trDuration/32;
542 if ( trDuration > m_trDuration+t
543 || trDuration < m_trDuration-t
544 ) {
545 // There's a major variation. Reset the average frame rate to
546 // exactly the current rate to disable decision 9002 for this frame,

Callers

nothing calls this directly

Calls 1

TimeDiffFunction · 0.85

Tested by

no test coverage detected