MythTV  master
decoderbase.cpp
Go to the documentation of this file.
1 
2 #include <algorithm>
3 
4 #include "mythconfig.h"
5 
6 #include "mythplayer.h"
7 #include "mythlogging.h"
8 #include "decoderbase.h"
9 #include "programinfo.h"
10 #include "iso639.h"
11 #include "DVD/mythdvdbuffer.h"
12 #include "Bluray/mythbdbuffer.h"
13 #include "mythcodeccontext.h"
14 
15 #define LOC QString("Dec: ")
16 
18  : m_parent(parent), m_playbackInfo(new ProgramInfo(pginfo)),
19  m_audio(m_parent->GetAudio()),
20  m_totalDuration(AVRationalInit(0)),
21 
22  // language preference
23  m_languagePreference(iso639_get_language_key_list())
24 {
25  ResetTracks();
26  m_tracks[kTrackTypeAudio].emplace_back(0, 0, 0, 0, 0);
27  m_tracks[kTrackTypeCC608].emplace_back(0, 0, 0, 1, 0);
28  m_tracks[kTrackTypeCC608].emplace_back(0, 0, 2, 3, 0);
29 }
30 
32 {
33  delete m_playbackInfo;
34 }
35 
37 {
38  if (RenderFormats != nullptr)
39  m_renderFormats = RenderFormats;
40 }
41 
43 {
44  delete m_playbackInfo;
45  m_playbackInfo = new ProgramInfo(pginfo);
46 }
47 
48 void DecoderBase::Reset(bool reset_video_data, bool seek_reset, bool reset_file)
49 {
50  LOG(VB_PLAYBACK, LOG_INFO, LOC +
51  QString("Reset: Video %1, Seek %2, File %3")
52  .arg(reset_video_data).arg(seek_reset).arg(reset_file));
53 
54  if (seek_reset)
55  SeekReset(0, 0, true, true);
56 
57  if (reset_video_data)
58  {
59  ResetPosMap();
60  m_framesPlayed = 0;
61  m_frameCounter += 100;
62  m_fpsSkip = 0;
63  m_framesRead = 0;
65  m_dontSyncPositionMap = false;
66  }
67 
68  if (reset_file)
69  {
70  m_waitingForChange = false;
72  }
73 }
74 
75 void DecoderBase::SeekReset(long long /*newkey*/, uint /*skipFrames*/,
76  bool /*doFlush*/, bool /*discardFrames*/)
77 {
78  m_readAdjust = 0;
79  m_frameCounter += 100; // NB don't just set to 0
80 }
81 
83 {
84  bool wereWatchingRecording = m_watchingRecording;
85 
86  // When we switch from WatchingRecording to WatchingPreRecorded,
87  // re-get the positionmap
88  m_posmapStarted = false;
89  m_watchingRecording = mode;
90 
91  if (wereWatchingRecording && !m_watchingRecording)
93 }
94 
96 {
97  if (!m_playbackInfo)
98  return false;
99 
100  // Overwrites current positionmap with entire contents of database
101  frm_pos_map_t posMap;
102  frm_pos_map_t durMap;
103 
104  if (m_ringBuffer && m_ringBuffer->IsDVD())
105  {
106  m_keyframeDist = 15;
108  if (m_fps < 26 && m_fps > 24)
109  m_keyframeDist = 12;
110  auto totframes =
112  posMap[totframes] = m_ringBuffer->DVD()->GetTotalReadPosition();
113  }
114  else if (m_ringBuffer && m_ringBuffer->IsBD())
115  {
116  m_keyframeDist = 15;
118  if (m_fps < 26 && m_fps > 24)
119  m_keyframeDist = 12;
120  auto totframes =
121  (long long)(m_ringBuffer->BD()->GetTotalTimeOfTitle() * m_fps);
122  posMap[totframes] = m_ringBuffer->BD()->GetTotalReadPosition();
123 #if 0
124  LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
125  QString("%1 TotalTimeOfTitle() in ticks, %2 TotalReadPosition() "
126  "in bytes, %3 is fps")
128  .arg(m_ringBuffer->BD()->GetTotalReadPosition()).arg(m_fps));
129 #endif
130  }
131  else if ((m_positionMapType == MARK_UNSET) ||
132  (m_keyframeDist == -1))
133  {
135  if (!posMap.empty())
136  {
138  if (m_keyframeDist == -1)
139  m_keyframeDist = 1;
140  }
141  else
142  {
144  if (!posMap.empty())
145  {
147  if (m_keyframeDist == -1)
148  {
149  m_keyframeDist = 15;
150  if (m_fps < 26 && m_fps > 24)
151  m_keyframeDist = 12;
152  }
153  }
154  else
155  {
157  if (!posMap.empty())
158  {
159  // keyframedist should be set in the fileheader so no
160  // need to try to determine it in this case
162  }
163  }
164  }
165  }
166  else
167  {
169  }
170 
171  if (posMap.empty())
172  return false; // no position map in recording
173 
175 
176  QMutexLocker locker(&m_positionMapLock);
177  m_positionMap.clear();
178  m_positionMap.reserve(posMap.size());
179  m_frameToDurMap.clear();
180  m_durToFrameMap.clear();
181 
182  for (auto it = posMap.cbegin(); it != posMap.cend(); ++it)
183  {
184  PosMapEntry e = {it.key(), it.key() * m_keyframeDist, *it};
185  m_positionMap.push_back(e);
186  }
187 
188  if (!m_positionMap.empty() && !(m_ringBuffer && m_ringBuffer->IsDisc()))
189  m_indexOffset = m_positionMap[0].index;
190 
191  if (!m_positionMap.empty())
192  {
193  LOG(VB_PLAYBACK, LOG_INFO, LOC +
194  QString("Position map filled from DB to: %1")
195  .arg(m_positionMap.back().index));
196  }
197 
198  uint64_t last = 0;
199  for (auto it = durMap.cbegin(); it != durMap.cend(); ++it)
200  {
201  m_frameToDurMap[it.key()] = it.value();
202  m_durToFrameMap[it.value()] = it.key();
203  last = it.key();
204  }
205 
206  if (!m_durToFrameMap.empty())
207  {
208  LOG(VB_PLAYBACK, LOG_INFO, LOC +
209  QString("Duration map filled from DB to: %1").arg(last));
210  }
211 
212  return true;
213 }
214 
224 {
225  if (!m_parent || m_keyframeDist < 1)
226  return false;
227 
228  unsigned long long start = 0;
229  {
230  QMutexLocker locker(&m_positionMapLock);
231  if (!m_positionMap.empty())
232  start = m_positionMap.back().index + 1;
233  }
234 
235  frm_pos_map_t posMap;
236  frm_pos_map_t durMap;
237  if (!m_parent->PosMapFromEnc(start, posMap, durMap))
238  return false;
239 
240  QMutexLocker locker(&m_positionMapLock);
241 
242  // append this new position map to class's
243  m_positionMap.reserve(m_positionMap.size() + posMap.size());
244 
245  long long last_index = 0;
246  if (!m_positionMap.empty())
247  last_index = m_positionMap.back().index;
248  for (auto it = posMap.cbegin(); it != posMap.cend(); ++it)
249  {
250  if (it.key() <= last_index)
251  continue;
252 
253  PosMapEntry e = {it.key(), it.key() * m_keyframeDist, *it};
254  m_positionMap.push_back(e);
255  }
256 
257  if (!m_positionMap.empty() && !(m_ringBuffer && m_ringBuffer->IsDisc()))
258  m_indexOffset = m_positionMap[0].index;
259 
260  if (!m_positionMap.empty())
261  {
262  LOG(VB_PLAYBACK, LOG_INFO, LOC +
263  QString("Position map filled from Encoder to: %1")
264  .arg(m_positionMap.back().index));
265  }
266 
267  bool isEmpty = m_frameToDurMap.empty();
268  if (!isEmpty)
269  {
270  frm_pos_map_t::const_iterator it = m_frameToDurMap.cend();
271  --it;
272  last_index = it.key();
273  }
274  for (frm_pos_map_t::const_iterator it = durMap.cbegin();
275  it != durMap.cend(); ++it)
276  {
277  if (!isEmpty && it.key() <= last_index)
278  continue; // we released the m_positionMapLock for a few ms...
279  m_frameToDurMap[it.key()] = it.value();
280  m_durToFrameMap[it.value()] = it.key();
281  }
282 
283  if (!m_frameToDurMap.empty())
284  {
285  frm_pos_map_t::const_iterator it = m_frameToDurMap.cend();
286  --it;
287  LOG(VB_PLAYBACK, LOG_INFO, LOC +
288  QString("Duration map filled from Encoder to: %1").arg(it.key()));
289  }
290 
291  return true;
292 }
293 
294 unsigned long DecoderBase::GetPositionMapSize(void) const
295 {
296  QMutexLocker locker(&m_positionMapLock);
297  return m_positionMap.size();
298 }
299 
323 {
324  LOG(VB_PLAYBACK, LOG_INFO, LOC +
325  QString("Resyncing position map. posmapStarted = %1"
326  " livetv(%2) watchingRec(%3)")
328 
330  return false;
331 
332  unsigned long old_posmap_size = GetPositionMapSize();
333  unsigned long new_posmap_size = old_posmap_size;
334 
336  {
337  if (!m_posmapStarted)
338  {
339  // starting up -- try first from database
340  PosMapFromDb();
341  new_posmap_size = GetPositionMapSize();
342  LOG(VB_PLAYBACK, LOG_INFO, LOC +
343  QString("SyncPositionMap watchingrecording, from DB: "
344  "%1 entries") .arg(new_posmap_size));
345  }
346  // always try to get more from encoder
347  if (!PosMapFromEnc())
348  {
349  LOG(VB_PLAYBACK, LOG_INFO, LOC +
350  QString("SyncPositionMap watchingrecording no entries "
351  "from encoder, try DB"));
352  PosMapFromDb(); // try again from db
353  }
354 
355  new_posmap_size = GetPositionMapSize();
356  LOG(VB_PLAYBACK, LOG_INFO, LOC +
357  QString("SyncPositionMap watchingrecording total: %1 entries")
358  .arg(new_posmap_size));
359  }
360  else
361  {
362  // watching prerecorded ... just get from db
363  if (!m_posmapStarted)
364  {
365  PosMapFromDb();
366 
367  new_posmap_size = GetPositionMapSize();
368  LOG(VB_PLAYBACK, LOG_INFO, LOC +
369  QString("SyncPositionMap prerecorded, from DB: %1 entries")
370  .arg(new_posmap_size));
371  }
372  }
373 
374  bool ret_val = new_posmap_size > old_posmap_size;
375 
376  if (ret_val && m_keyframeDist > 0)
377  {
378  long long totframes = 0;
379  int length = 0;
380 
381  if (m_ringBuffer && m_ringBuffer->IsDVD())
382  {
383  length = m_ringBuffer->DVD()->GetTotalTimeOfTitle();
384  QMutexLocker locker(&m_positionMapLock);
385  totframes = m_positionMap.back().index;
386  }
387  else if (m_ringBuffer && m_ringBuffer->IsBD())
388  {
389  length = m_ringBuffer->BD()->GetTotalTimeOfTitle();
390  QMutexLocker locker(&m_positionMapLock);
391  totframes = m_positionMap.back().index;
392  }
393  else
394  {
395  QMutexLocker locker(&m_positionMapLock);
396  totframes = m_positionMap.back().index * m_keyframeDist;
397  if (m_fps != 0.0)
398  length = (int)((totframes * 1.0) / m_fps);
399  }
400 
401  m_parent->SetFileLength(length, totframes);
403  m_posmapStarted = true;
404 
405  LOG(VB_PLAYBACK, LOG_INFO, LOC +
406  QString("SyncPositionMap, new totframes: %1, new length: %2, "
407  "posMap size: %3")
408  .arg(totframes).arg(length).arg(new_posmap_size));
409  }
410  m_recordingHasPositionMap |= (0 != new_posmap_size);
411  {
412  QMutexLocker locker(&m_positionMapLock);
413  m_lastPositionMapUpdate = QDateTime::currentDateTime();
414  }
415  return ret_val;
416 }
417 
418 // returns true iff found exactly
419 // searches position if search_pos, index otherwise
420 bool DecoderBase::FindPosition(long long desired_value, bool search_adjusted,
421  int &lower_bound, int &upper_bound)
422 {
423  QMutexLocker locker(&m_positionMapLock);
424  // Binary search
425  auto size = (long long) m_positionMap.size();
426  long long lower = -1;
427  long long upper = size;
428 
429  if (!search_adjusted && m_keyframeDist > 0)
430  desired_value /= m_keyframeDist;
431 
432  while (upper - 1 > lower)
433  {
434  long long i = (upper + lower) / 2;
435  long long value = 0;
436  if (search_adjusted)
437  value = m_positionMap[i].adjFrame;
438  else
439  value = m_positionMap[i].index - m_indexOffset;
440  if (value == desired_value)
441  {
442  // found it
443  upper_bound = i;
444  lower_bound = i;
445 
446  LOG(VB_PLAYBACK, LOG_INFO, LOC +
447  QString("FindPosition(%1, search%2 adjusted)")
448  .arg(desired_value).arg((search_adjusted) ? "" : " not") +
449  QString(" --> [%1:%2(%3)]")
450  .arg(i).arg(GetKey(m_positionMap[i]))
451  .arg(m_positionMap[i].pos));
452 
453  return true;
454  }
455  if (value > desired_value)
456  upper = i;
457  else
458  lower = i;
459  }
460  // Did not find it exactly -- return bounds
461 
462  if (search_adjusted)
463  {
464  while (lower >= 0 && m_positionMap[lower].adjFrame > desired_value)
465  lower--;
466  while (upper < size && m_positionMap[upper].adjFrame < desired_value)
467  upper++;
468  }
469  else
470  {
471  while (lower >= 0 &&
472  (m_positionMap[lower].index - m_indexOffset) > desired_value)
473  lower--;
474  while (upper < size &&
475  (m_positionMap[upper].index - m_indexOffset) < desired_value)
476  upper++;
477  }
478  // keep in bounds
479  lower = std::max(lower, 0LL);
480  upper = std::min(upper, size - 1LL);
481 
482  upper_bound = upper;
483  lower_bound = lower;
484  bool empty = m_positionMap.empty();
485 
486  LOG(VB_PLAYBACK, LOG_INFO, LOC +
487  QString("FindPosition(%1, search%3 adjusted)")
488  .arg(desired_value).arg((search_adjusted) ? "" : " not") +
489  QString(" --> \n\t\t\t[%1:%2(%3),%4:%5(%6)]")
490  .arg(lower_bound)
491  .arg(empty ? -1 : GetKey(m_positionMap[lower_bound]))
492  .arg(empty ? -1 : m_positionMap[lower_bound].pos)
493  .arg(upper_bound)
494  .arg(empty ? -1 : GetKey(m_positionMap[upper_bound]))
495  .arg(empty ? -1 : m_positionMap[upper_bound].pos));
496 
497  return false;
498 }
499 
500 uint64_t DecoderBase::SavePositionMapDelta(long long first, long long last)
501 {
502  MythTimer ttm;
503  MythTimer ctm;
504  MythTimer stm;
505  ttm.start();
506 
507  QMutexLocker locker(&m_positionMapLock);
509  uint64_t saved = 0;
510 
512  return saved;
513 
514  ctm.start();
515  frm_pos_map_t posMap;
516  for (auto & entry : m_positionMap)
517  {
518  if (entry.index < first)
519  continue;
520  if (entry.index > last)
521  break;
522 
523  posMap[entry.index] = entry.pos;
524  saved++;
525  }
526 
527  frm_pos_map_t durMap;
528  for (auto it = m_frameToDurMap.cbegin(); it != m_frameToDurMap.cend(); ++it)
529  {
530  if (it.key() < first)
531  continue;
532  if (it.key() > last)
533  break;
534  durMap[it.key()] = it.value();
535  }
536 
537  locker.unlock();
538 
539  stm.start();
542 
543 #if 0
544  LOG(VB_GENERAL, LOG_DEBUG, LOC +
545  QString("Saving position map [%1,%2] w/%3 keyframes, "
546  "took (%4,%5,%6) ms")
547  .arg(first).arg(last).arg(saved)
548  .arg(ttm.elapsed())
549  .arg(ctm.elapsed()-stm.elapsed()).arg(stm.elapsed()));
550 #endif
551 
552  return saved;
553 }
554 
555 bool DecoderBase::DoRewind(long long desiredFrame, bool discardFrames)
556 {
557  LOG(VB_PLAYBACK, LOG_INFO, LOC +
558  QString("DoRewind(%1 (%2), %3 discard frames)")
559  .arg(desiredFrame).arg(m_framesPlayed)
560  .arg((discardFrames) ? "do" : "don't"));
561 
562  if (!DoRewindSeek(desiredFrame))
563  return false;
564 
566  m_fpsSkip = 0;
568 
569  // Do any Extra frame-by-frame seeking for exactseeks mode
570  // And flush pre-seek frame if we are allowed to and need to..
571  int normalframes = (uint64_t)(desiredFrame - (m_framesPlayed - 1)) > m_seekSnap
572  ? desiredFrame - m_framesPlayed : 0;
573  normalframes = std::max(normalframes, 0);
574  SeekReset(m_lastKey, normalframes, true, discardFrames);
575 
576  if (discardFrames || (m_ringBuffer && m_ringBuffer->IsDisc()))
578 
579  return true;
580 }
581 
582 long long DecoderBase::GetKey(const PosMapEntry &e) const
583 {
584  long long kf = (m_ringBuffer && m_ringBuffer->IsDisc()) ?
585  1LL : m_keyframeDist;
586  return (m_hasKeyFrameAdjustTable) ? e.adjFrame :(e.index - m_indexOffset) * kf;
587 }
588 
589 bool DecoderBase::DoRewindSeek(long long desiredFrame)
590 {
591  ConditionallyUpdatePosMap(desiredFrame);
592 
593  if (!GetPositionMapSize())
594  {
595  LOG(VB_GENERAL, LOG_ERR, LOC + "PosMap is empty, can't seek");
596  return false;
597  }
598 
599  if (!m_ringBuffer)
600  {
601  LOG(VB_GENERAL, LOG_ERR, LOC + "No ringBuffer yet, can't seek");
602  return false;
603  }
604 
605  // Find keyframe <= desiredFrame, store in lastKey (frames)
606  int pre_idx = 0;
607  int post_idx = 0;
608  FindPosition(desiredFrame, m_hasKeyFrameAdjustTable, pre_idx, post_idx);
609 
610  PosMapEntry e {};
611  {
612  QMutexLocker locker(&m_positionMapLock);
613  PosMapEntry e_pre = m_positionMap[pre_idx];
614  PosMapEntry e_post = m_positionMap[post_idx];
615  int pos_idx = pre_idx;
616  e = e_pre;
617  if (((uint64_t) (GetKey(e_post) - desiredFrame)) <= m_seekSnap &&
618  m_framesPlayed - 1 > GetKey(e_post) &&
619  GetKey(e_post) - desiredFrame <= desiredFrame - GetKey(e_pre))
620  {
621  // Snap to the right if e_post is within snap distance and
622  // is at least as close a snap as e_pre. Take into
623  // account that if framesPlayed has already reached
624  // e_post, we should only snap to the left.
625  pos_idx = post_idx;
626  e = e_post;
627  }
628  m_lastKey = GetKey(e);
629 
630  // ??? Don't rewind past the beginning of the file
631  while (e.pos < 0)
632  {
633  pos_idx++;
634  if (pos_idx >= (int)m_positionMap.size())
635  return false;
636 
637  e = m_positionMap[pos_idx];
638  m_lastKey = GetKey(e);
639  }
640  }
641 
642  m_ringBuffer->Seek(e.pos, SEEK_SET);
643 
644  return true;
645 }
646 
648 {
649  QMutexLocker locker(&m_positionMapLock);
650  m_posmapStarted = false;
651  m_positionMap.clear();
652  m_frameToDurMap.clear();
653  m_durToFrameMap.clear();
654 }
655 
657 {
658  long long last_frame = 0;
659 
660  QMutexLocker locker(&m_positionMapLock);
661  if (!m_positionMap.empty())
662  last_frame = GetKey(m_positionMap.back());
663 
664  return last_frame;
665 }
666 
667 long long DecoderBase::ConditionallyUpdatePosMap(long long desiredFrame)
668 {
669  long long last_frame = GetLastFrameInPosMap();
670 
671  if (desiredFrame < 0)
672  return last_frame;
673 
674  // Resync keyframe map if we are trying to seek to a frame
675  // not yet equalled or exceeded in the seek map.
676  if (desiredFrame < last_frame)
677  return last_frame;
678 
679  LOG(VB_PLAYBACK, LOG_INFO, LOC +
680  "ConditionallyUpdatePosMap: Not enough info in positionMap," +
681  QString("\n\t\t\twe need frame %1 but highest we have is %2.")
682  .arg(desiredFrame).arg(last_frame));
683 
684  SyncPositionMap();
685 
686  last_frame = GetLastFrameInPosMap();
687 
688  if (desiredFrame > last_frame)
689  {
690  LOG(VB_PLAYBACK, LOG_INFO, LOC +
691  "ConditionallyUpdatePosMap: Still not "
692  "enough info in positionMap after sync, " +
693  QString("\n\t\t\twe need frame %1 but highest we have "
694  "is %2. Will attempt to seek frame-by-frame")
695  .arg(desiredFrame).arg(last_frame));
696  }
697 
698  return last_frame;
699 }
700 
710 bool DecoderBase::DoFastForward(long long desiredFrame, bool discardFrames)
711 {
712  LOG(VB_PLAYBACK, LOG_INFO, LOC +
713  QString("DoFastForward(%1 (%2), %3 discard frames)")
714  .arg(desiredFrame).arg(m_framesPlayed)
715  .arg((discardFrames) ? "do" : "don't"));
716 
717  if (!m_ringBuffer)
718  {
719  LOG(VB_GENERAL, LOG_ERR, LOC + "No ringBuffer yet, can't fast forward");
720  return false;
721  }
722 
723  if (m_ringBuffer->IsDVD() &&
725  m_ringBuffer->DVD()->TitleTimeLeft() < 5)
726  {
727  return false;
728  }
729  // Rewind if we have already played the desiredFrame. The +1 is for
730  // MPEG4 NUV files, which need to decode an extra frame sometimes.
731  // This shouldn't effect how this works in general because this is
732  // only triggered on the first keyframe/frame skip when paused. At
733  // that point the decoding is more than one frame ahead of display.
734  if (desiredFrame+1 < m_framesPlayed)
735  return DoRewind(desiredFrame, discardFrames);
736  desiredFrame = std::max(desiredFrame, m_framesPlayed);
737 
738  // Save rawframe state, for later restoration...
739  bool oldrawstate = m_getRawFrames;
740  m_getRawFrames = false;
741 
742  ConditionallyUpdatePosMap(desiredFrame);
743 
744  // Fetch last keyframe in position map
745  long long last_frame = GetLastFrameInPosMap();
746 
747  // If the desiredFrame is past the end of the position map,
748  // do some frame-by-frame seeking until we get to it.
749  bool needflush = false;
750  if (desiredFrame > last_frame)
751  {
752  LOG(VB_GENERAL, LOG_NOTICE, LOC +
753  QString("DoFastForward(): desiredFrame(%1) > last_frame(%2)")
754  .arg(desiredFrame).arg(last_frame));
755 
756  if (desiredFrame - last_frame > 32)
757  {
758  LOG(VB_GENERAL, LOG_ERR, LOC + "DoFastForward(): "
759  "Desired frame is way past the end of the keyframe map!"
760  "\n\t\t\tSeeking to last keyframe instead.");
761  desiredFrame = last_frame;
762  }
763 
764  needflush = true;
765 
766  // Handle non-frame-by-frame seeking
767  DoFastForwardSeek(last_frame, needflush);
768 
769  m_exitAfterDecoded = true; // don't actualy get a frame
770  while ((desiredFrame > last_frame) && !m_atEof)
771  {
772  bool retry = false;
773  GetFrame(kDecodeNothing, retry); // don't need to return frame...
774  SyncPositionMap();
775  last_frame = GetLastFrameInPosMap();
776  }
777  m_exitAfterDecoded = false; // allow frames to be returned again
778 
779  if (m_atEof)
780  {
781  // Re-enable rawframe state if it was enabled before FF
782  m_getRawFrames = oldrawstate;
783  return false;
784  }
785  }
786 
787  {
788  QMutexLocker locker(&m_positionMapLock);
789  if (m_positionMap.empty())
790  {
791  // Re-enable rawframe state if it was enabled before FF
792  m_getRawFrames = oldrawstate;
793  return false;
794  }
795  }
796 
797  // Handle non-frame-by-frame seeking
798  DoFastForwardSeek(desiredFrame, needflush);
799 
800  // Do any Extra frame-by-frame seeking for exactseeks mode
801  // And flush pre-seek frame if we are allowed to and need to..
802  int normalframes = (uint64_t)(desiredFrame - (m_framesPlayed - 1)) > m_seekSnap
803  ? desiredFrame - m_framesPlayed : 0;
804  normalframes = std::max(normalframes, 0);
805  SeekReset(m_lastKey, normalframes, needflush, discardFrames);
806 
807  if (discardFrames || m_transcoding)
809 
810  // Re-enable rawframe state if it was enabled before FF
811  m_getRawFrames = oldrawstate;
812 
813  return true;
814 }
815 
830 void DecoderBase::DoFastForwardSeek(long long desiredFrame, bool &needflush)
831 {
832  if (!m_ringBuffer)
833  {
834  LOG(VB_GENERAL, LOG_ERR, LOC +
835  "No ringBuffer yet, can't fast forward seek");
836  return;
837  }
838 
839  int pre_idx = 0;
840  int post_idx = 0;
841  FindPosition(desiredFrame, m_hasKeyFrameAdjustTable, pre_idx, post_idx);
842 
843  // if exactseeks, use keyframe <= desiredFrame
844 
845  PosMapEntry e {};
846  PosMapEntry e_pre {};
847  PosMapEntry e_post {};
848  {
849  QMutexLocker locker(&m_positionMapLock);
850  e_pre = m_positionMap[pre_idx];
851  e_post = m_positionMap[post_idx];
852  }
853  e = e_pre;
854  if (((uint64_t) (GetKey(e_post) - desiredFrame)) <= m_seekSnap &&
855  (m_framesPlayed - 1 >= GetKey(e_pre) ||
856  GetKey(e_post) - desiredFrame < desiredFrame - GetKey(e_pre)))
857  {
858  // Snap to the right if e_post is within snap distance and is
859  // a closer snap than e_pre. Take into account that if
860  // framesPlayed has already reached e_pre, we should only snap
861  // to the right.
862  e = e_post;
863  }
864  m_lastKey = GetKey(e);
865 
867  {
868  m_ringBuffer->Seek(e.pos, SEEK_SET);
869  needflush = true;
871  m_fpsSkip = 0;
873  }
874 }
875 
877 {
879 }
880 
882 {
883  ResetPosMap();
884  m_framesPlayed = 0;
885  m_framesRead = 0;
887 
888  m_waitingForChange = false;
889  m_justAfterChange = true;
890 
892 }
893 
894 void DecoderBase::SetReadAdjust(long long adjust)
895 {
896  m_readAdjust = adjust;
897 }
898 
900 {
901  m_waitingForChange = true;
902 }
903 
905 {
906  return m_waitingForChange;
907 }
908 
910 {
911  QMutexLocker locker(&m_trackLock);
912  return static_cast<uint>(m_tracks[Type].size());
913 }
914 
916 {
917  m_trackLock.lock();
918  m_decodeAllSubtitles = DecodeAll;
919  m_trackLock.unlock();
920 }
921 
922 QStringList DecoderBase::GetTracks(uint Type)
923 {
924  QMutexLocker locker(&m_trackLock);
925  QStringList list;
926  for (size_t i = 0; i < m_tracks[Type].size(); i++)
927  list += GetTrackDesc(Type, static_cast<uint>(i));
928  return list;
929 }
930 
932 {
933  QMutexLocker locker(&m_trackLock);
934  if (TrackNo >= m_tracks[Type].size())
935  return 0;
936  return static_cast<int>(m_tracks[Type][TrackNo].m_language_index);
937 }
938 
939 QString DecoderBase::GetTrackDesc(uint Type, uint TrackNo)
940 {
941  QMutexLocker locker(&m_trackLock);
942  if (TrackNo >= m_tracks[Type].size())
943  return "";
944 
945  QString type_msg = toString(static_cast<TrackType>(Type));
946  int lang = m_tracks[Type][TrackNo].m_language;
947  int hnum = static_cast<int>(TrackNo + 1);
948  if (kTrackTypeCC608 == Type)
949  hnum = m_tracks[Type][TrackNo].m_stream_id;
950 
951  if (!lang)
952  return type_msg + QString(" %1").arg(hnum);
953  QString lang_msg = iso639_key_toName(lang);
954  return type_msg + QString(" %1: %2").arg(hnum).arg(lang_msg);
955 }
956 
958 {
959  QMutexLocker locker(&m_trackLock);
960  return m_currentTrack[Type];
961 }
962 
963 int DecoderBase::SetTrack(uint Type, int TrackNo)
964 {
965  QMutexLocker locker(&m_trackLock);
966  if (TrackNo >= static_cast<int>(m_tracks[Type].size()))
967  return -1;
968 
969  m_currentTrack[Type] = std::max(-1, TrackNo);
970  if (m_currentTrack[Type] < 0)
971  {
972  m_selectedTrack[Type].m_av_stream_index = -1;
973  }
974  else
975  {
976  m_wantedTrack[Type] = m_tracks[Type][static_cast<size_t>(m_currentTrack[Type])];
977  m_selectedTrack[Type] = m_tracks[Type][static_cast<size_t>(m_currentTrack[Type])];
978  }
979 
980  return m_currentTrack[Type];
981 }
982 
984 {
985  QMutexLocker locker(&m_trackLock);
986  if (TrackNo >= m_tracks[Type].size())
987  {
988  StreamInfo si;
989  return si;
990  }
991  return m_tracks[Type][TrackNo];
992 }
993 
994 int DecoderBase::ChangeTrack(uint Type, int Dir)
995 {
996  QMutexLocker locker(&m_trackLock);
997 
998  int next_track = -1;
999  int size = static_cast<int>(m_tracks[Type].size());
1000  if (size)
1001  {
1002  if (Dir > 0)
1003  next_track = (std::max(-1, m_currentTrack[Type]) + 1) % size;
1004  else
1005  next_track = (std::max(+0, m_currentTrack[Type]) + size - 1) % size;
1006  }
1007  return SetTrack(Type, next_track);
1008 }
1009 
1011 {
1012  QMutexLocker locker(&m_trackLock);
1013 
1014  int next_track = -1;
1015  int size = static_cast<int>(m_tracks[Type].size());
1016  if (size)
1017  next_track = (std::max(0, m_currentTrack[Type]) + 1) % size;
1018  return next_track;
1019 }
1020 
1022 {
1023  QMutexLocker locker(&m_trackLock);
1024 
1025  if (std::any_of(m_tracks[Type].cbegin(), m_tracks[Type].cend(),
1026  [&](const StreamInfo& Si) { return Si.m_stream_id == Info.m_stream_id; } ))
1027  {
1028  return false;
1029  }
1030 
1031  m_tracks[Type].push_back(Info);
1032 
1033  if (m_parent)
1034  emit m_parent->SignalTracksChanged(Type);
1035 
1036  return true;
1037 }
1038 
1055 {
1056  QMutexLocker locker(&m_trackLock);
1057 
1058  uint numStreams = static_cast<uint>(m_tracks[Type].size());
1059 
1060  if ((m_currentTrack[Type] >= 0) && (m_currentTrack[Type] < static_cast<int>(numStreams)))
1061  return m_currentTrack[Type]; // track already selected
1062 
1063  if (!numStreams)
1064  {
1065  m_currentTrack[Type] = -1;
1066  m_selectedTrack[Type].m_av_stream_index = -1;
1067  return -1;
1068  }
1069 
1070  int selTrack = (1 == numStreams) ? 0 : -1;
1071 
1072  if ((selTrack < 0) && m_wantedTrack[Type].m_language>=-1)
1073  {
1074  LOG(VB_PLAYBACK, LOG_INFO, LOC + "Trying to reselect track");
1075  // Try to reselect user selected track stream.
1076  // This should find the stream after a commercial
1077  // break and in some cases after a channel change.
1078  int wlang = m_wantedTrack[Type].m_language;
1079  uint windx = m_wantedTrack[Type].m_language_index;
1080  for (uint i = 0; i < numStreams; i++)
1081  {
1082  if (wlang == m_tracks[Type][i].m_language)
1083  {
1084  selTrack = static_cast<int>(i);
1085  if (windx == m_tracks[Type][i].m_language_index)
1086  break;
1087  }
1088  }
1089  }
1090 
1091  if (selTrack < 0)
1092  {
1093  // Select the best track. Primary attribute is to favor a
1094  // forced track. Secondary attribute is language preference,
1095  // in order of most preferred to least preferred language.
1096  // Third attribute is track order, preferring the earliest
1097  // track.
1098  LOG(VB_PLAYBACK, LOG_INFO, LOC + "Trying to select track (w/lang & forced)");
1099  const int kForcedWeight = (1 << 20);
1100  const int kLanguageWeight = (1 << 10);
1101  const int kPositionWeight = (1 << 0);
1102  int bestScore = -1;
1103  selTrack = 0;
1104  for (uint i = 0; i < numStreams; i++)
1105  {
1106  bool forced = (Type == kTrackTypeSubtitle &&
1107  m_tracks[Type][i].m_forced &&
1109  int position = static_cast<int>(numStreams) - static_cast<int>(i);
1110  int language = 0;
1111  for (uint j = 0; (language == 0) && (j < m_languagePreference.size()); ++j)
1112  {
1113  if (m_tracks[Type][i].m_language == m_languagePreference[j])
1114  language = static_cast<int>(m_languagePreference.size()) - static_cast<int>(j);
1115  }
1116  int score = (kForcedWeight * static_cast<int>(forced)) +
1117  (kLanguageWeight * language) +
1118  (kPositionWeight * position);
1119  if (score > bestScore)
1120  {
1121  bestScore = score;
1122  selTrack = static_cast<int>(i);
1123  }
1124  }
1125  }
1126 
1127  int oldTrack = m_currentTrack[Type];
1128  m_currentTrack[Type] = selTrack;
1129  StreamInfo tmp = m_tracks[Type][static_cast<size_t>(m_currentTrack[Type])];
1130  m_selectedTrack[Type] = tmp;
1131 
1132  if (m_wantedTrack[Type].m_av_stream_index < 0)
1133  m_wantedTrack[Type] = tmp;
1134 
1135  int lang = m_tracks[Type][static_cast<size_t>(m_currentTrack[Type])].m_language;
1136  LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Selected track #%1 (type %2) in the %3 language(%4)")
1137  .arg(m_currentTrack[Type]+1).arg(Type).arg(iso639_key_toName(lang)).arg(lang));
1138 
1139  if (m_parent && (oldTrack != m_currentTrack[Type]))
1140  emit m_parent->SignalTracksChanged(Type);
1141 
1142  return selTrack;
1143 }
1144 
1146 {
1147  for (uint i = 0; i < kTrackTypeCount; i++)
1148  AutoSelectTrack(i);
1149 }
1150 
1152 {
1153  QMutexLocker locker(&m_trackLock);
1154  std::fill(m_currentTrack.begin(), m_currentTrack.end(), -1);
1155 }
1156 
1158 {
1159  QString str = QObject::tr("Track");
1160 
1161  if (kTrackTypeAudio == type)
1162  str = QObject::tr("Audio track");
1163  else if (kTrackTypeVideo == type)
1164  str = QObject::tr("Video track");
1165  else if (kTrackTypeSubtitle == type)
1166  str = QObject::tr("Subtitle track");
1167  else if (kTrackTypeCC608 == type)
1168  str = QObject::tr("CC", "EIA-608 closed captions");
1169  else if (kTrackTypeCC708 == type)
1170  str = QObject::tr("ATSC CC", "EIA-708 closed captions");
1171  else if (kTrackTypeTeletextCaptions == type)
1172  str = QObject::tr("TT CC", "Teletext closed captions");
1173  else if (kTrackTypeTeletextMenu == type)
1174  str = QObject::tr("TT Menu", "Teletext Menu");
1175  else if (kTrackTypeRawText == type)
1176  str = QObject::tr("Text", "Text stream");
1177  else if (kTrackTypeTextSubtitle == type)
1178  str = QObject::tr("TXT File", "Text File");
1179  return str;
1180 }
1181 
1182 int to_track_type(const QString &str)
1183 {
1184  int ret = -1;
1185 
1186  if (str.startsWith("AUDIO"))
1187  ret = kTrackTypeAudio;
1188  else if (str.startsWith("VIDEO"))
1189  ret = kTrackTypeVideo;
1190  else if (str.startsWith("SUBTITLE"))
1191  ret = kTrackTypeSubtitle;
1192  else if (str.startsWith("CC608"))
1193  ret = kTrackTypeCC608;
1194  else if (str.startsWith("CC708"))
1195  ret = kTrackTypeCC708;
1196  else if (str.startsWith("TTC"))
1198  else if (str.startsWith("TTM"))
1199  ret = kTrackTypeTeletextMenu;
1200  else if (str.startsWith("TFL"))
1201  ret = kTrackTypeTextSubtitle;
1202  else if (str.startsWith("RAWTEXT"))
1203  ret = kTrackTypeRawText;
1204  return ret;
1205 }
1206 
1208 {
1209  QString str;
1210 
1211  switch (type)
1212  {
1214  str = QObject::tr("Audio Description",
1215  "On-screen events described for the visually impaired");
1216  break;
1217  case kAudioTypeCleanEffects :
1218  str = QObject::tr("Clean Effects",
1219  "No dialog, background audio only");
1220  break;
1222  str = QObject::tr("Hearing Impaired",
1223  "Clear dialog for the hearing impaired");
1224  break;
1225  case kAudioTypeSpokenSubs :
1226  str = QObject::tr("Spoken Subtitles",
1227  "Subtitles are read out for the visually impaired");
1228  break;
1229  case kAudioTypeCommentary :
1230  str = QObject::tr("Commentary", "Director/Cast commentary track");
1231  break;
1232  case kAudioTypeNormal :
1233  default:
1234  str = QObject::tr("Normal", "Ordinary audio track");
1235  break;
1236  }
1237 
1238  return str;
1239 }
1240 
1242 {
1243  if (!m_playbackInfo || av_q2d(m_totalDuration) == 0)
1244  return;
1245 
1246  m_playbackInfo->SaveTotalDuration(1000000 * av_q2d(m_totalDuration));
1247 }
1248 
1250 {
1251  if (!m_playbackInfo || !m_framesRead)
1252  return;
1253 
1255 }
1256 
1257 // Linearly interpolate the value for a given key in the map. If the
1258 // key is outside the range of keys in the map, linearly extrapolate
1259 // using the fallback ratio.
1261  long long key,
1262  float fallback_ratio)
1263 {
1264  uint64_t key1 = 0;
1265  uint64_t key2 = 0;
1266  uint64_t val1 = 0;
1267  uint64_t val2 = 0;
1268 
1269  frm_pos_map_t::const_iterator lower = map.lowerBound(key);
1270  // QMap::lowerBound() finds a key >= the given key. We want one
1271  // <= the given key, so back up one element upon > condition.
1272  if (lower != map.begin() && (lower == map.end() || lower.key() > key))
1273  --lower;
1274  if (lower == map.end() || lower.key() > key)
1275  {
1276  key1 = 0;
1277  val1 = 0;
1278  LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
1279  QString("TranslatePosition(key=%1): extrapolating to (0,0)")
1280  .arg(key));
1281  }
1282  else
1283  {
1284  key1 = lower.key();
1285  val1 = lower.value();
1286  }
1287  // Find the next key >= the given key. QMap::lowerBound() is
1288  // precisely correct in this case.
1289  frm_pos_map_t::const_iterator upper = map.lowerBound(key);
1290  if (upper == map.end())
1291  {
1292  // Extrapolate from (key1,val1) based on fallback_ratio
1293  key2 = key;
1294  val2 = llroundf(val1 + fallback_ratio * (key2 - key1));
1295  LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
1296  QString("TranslatePosition(key=%1, ratio=%2): "
1297  "extrapolating to (%3,%4)")
1298  .arg(key).arg(fallback_ratio).arg(key2).arg(val2));
1299  return val2;
1300  }
1301  key2 = upper.key();
1302  val2 = upper.value();
1303  if (key1 == key2) // this happens for an exact keyframe match
1304  return val2; // can also set key2 = key1 + 1 avoid dividing by zero
1305 
1306  return llround(val1 + (double) (key - key1) * (val2 - val1) / (key2 - key1));
1307 }
1308 
1309 // Convert from an absolute frame number (not cutlist adjusted) to its
1310 // cutlist-adjusted position in milliseconds.
1311 uint64_t DecoderBase::TranslatePositionFrameToMs(long long position,
1312  float fallback_framerate,
1313  const frm_dir_map_t &cutlist)
1314 {
1315  QMutexLocker locker(&m_positionMapLock);
1316  // Accurate calculation of duration requires an up-to-date
1317  // duration map. However, the last frame (total duration) will
1318  // almost always appear to be past the end of the duration map, so
1319  // we limit duration map syncing to once every 3 seconds (a
1320  // somewhat arbitrary value).
1321  if (!m_frameToDurMap.empty())
1322  {
1323  frm_pos_map_t::const_iterator it = m_frameToDurMap.cend();
1324  --it;
1325  if (position > it.key())
1326  {
1327  if (!m_lastPositionMapUpdate.isValid() ||
1328  (QDateTime::currentDateTime() >
1329  m_lastPositionMapUpdate.addSecs(3)))
1330  SyncPositionMap();
1331  }
1332  }
1333  return TranslatePositionAbsToRel(cutlist, position, m_frameToDurMap,
1334  1000 / fallback_framerate);
1335 }
1336 
1337 // Convert from a cutlist-adjusted position in milliseconds to its
1338 // absolute frame number (not cutlist-adjusted).
1340  float fallback_framerate,
1341  const frm_dir_map_t &cutlist)
1342 {
1343  QMutexLocker locker(&m_positionMapLock);
1344  // Convert relative position in milliseconds (cutlist-adjusted) to
1345  // its absolute position in milliseconds (not cutlist-adjusted).
1346  uint64_t ms = TranslatePositionRelToAbs(cutlist, dur_ms, m_frameToDurMap,
1347  1000 / fallback_framerate);
1348  // Convert absolute position in milliseconds to its absolute frame
1349  // number.
1350  return TranslatePosition(m_durToFrameMap, ms, fallback_framerate / 1000);
1351 }
1352 
1353 // Convert from an "absolute" (not cutlist-adjusted) value to its
1354 // "relative" (cutlist-adjusted) mapped value. Usually the position
1355 // argument is a frame number, the map argument maps frames to
1356 // milliseconds, the fallback_ratio is 1000/framerate_fps, and the
1357 // return value is in milliseconds.
1358 //
1359 // If the map and fallback_ratio arguments are omitted, it simply
1360 // converts from an absolute frame number to a relative
1361 // (cutlist-adjusted) frame number.
1362 uint64_t
1364  uint64_t absPosition, // frames
1365  const frm_pos_map_t &map, // frame->ms
1366  float fallback_ratio)
1367 {
1368  uint64_t subtraction = 0;
1369  uint64_t startOfCutRegion = 0;
1370  bool withinCut = false;
1371  bool first = true;
1372  for (frm_dir_map_t::const_iterator i = deleteMap.begin();
1373  i != deleteMap.end(); ++i)
1374  {
1375  if (first)
1376  withinCut = (i.value() == MARK_CUT_END);
1377  first = false;
1378  if (i.key() > absPosition)
1379  break;
1380  uint64_t mappedKey = TranslatePosition(map, i.key(), fallback_ratio);
1381  if (i.value() == MARK_CUT_START && !withinCut)
1382  {
1383  withinCut = true;
1384  startOfCutRegion = mappedKey;
1385  }
1386  else if (i.value() == MARK_CUT_END && withinCut)
1387  {
1388  withinCut = false;
1389  subtraction += (mappedKey - startOfCutRegion);
1390  }
1391  }
1392  uint64_t mappedPos = TranslatePosition(map, absPosition, fallback_ratio);
1393  if (withinCut)
1394  subtraction += (mappedPos - startOfCutRegion);
1395  return mappedPos - subtraction;
1396 }
1397 
1398 // Convert from a "relative" (cutlist-adjusted) value to its
1399 // "absolute" (not cutlist-adjusted) mapped value. Usually the
1400 // position argument is in milliseconds, the map argument maps frames
1401 // to milliseconds, the fallback_ratio is 1000/framerate_fps, and the
1402 // return value is also in milliseconds. Upon return, if necessary,
1403 // the result may need a separate, non-cutlist adjusted conversion
1404 // from milliseconds to frame number, using the inverse
1405 // millisecond-to-frame map and the inverse fallback_ratio; see for
1406 // example TranslatePositionMsToFrame().
1407 //
1408 // If the map and fallback_ratio arguments are omitted, it simply
1409 // converts from a relatve (cutlist-adjusted) frame number to an
1410 // absolute frame number.
1411 uint64_t
1413  uint64_t relPosition, // ms
1414  const frm_pos_map_t &map, // frame->ms
1415  float fallback_ratio)
1416 {
1417  uint64_t addition = 0;
1418  uint64_t startOfCutRegion = 0;
1419  bool withinCut = false;
1420  bool first = true;
1421  for (frm_dir_map_t::const_iterator i = deleteMap.begin();
1422  i != deleteMap.end(); ++i)
1423  {
1424  if (first)
1425  withinCut = (i.value() == MARK_CUT_END);
1426  first = false;
1427  uint64_t mappedKey = TranslatePosition(map, i.key(), fallback_ratio);
1428  if (i.value() == MARK_CUT_START && !withinCut)
1429  {
1430  withinCut = true;
1431  startOfCutRegion = mappedKey;
1432  if (relPosition + addition <= startOfCutRegion)
1433  break;
1434  }
1435  else if (i.value() == MARK_CUT_END && withinCut)
1436  {
1437  withinCut = false;
1438  addition += (mappedKey - startOfCutRegion);
1439  }
1440  }
1441  return relPosition + addition;
1442 }
1443 
1448 AVPixelFormat DecoderBase::GetBestVideoFormat(AVPixelFormat* Formats, const VideoFrameTypes* RenderFormats)
1449 {
1450  for (AVPixelFormat *format = Formats; *format != AV_PIX_FMT_NONE; format++)
1451  {
1452  for (auto fmt : *RenderFormats)
1453  if (MythAVUtil::FrameTypeToPixelFormat(fmt) == *format)
1454  return *format;
1455  }
1456  return AV_PIX_FMT_NONE;
1457 }
1458 
1459 /* vim: set expandtab tabstop=4 shiftwidth=4: */
AVRationalInit
AVRational AVRationalInit(int num, int den=1)
Definition: decoderbase.h:113
MythMediaBuffer::BD
const MythBDBuffer * BD(void) const
Definition: mythmediabuffer.cpp:1838
DecoderBase::DoFastForward
virtual bool DoFastForward(long long desiredFrame, bool discardFrames=true)
Skips ahead or rewinds to desiredFrame.
Definition: decoderbase.cpp:710
kAudioTypeHearingImpaired
@ kAudioTypeHearingImpaired
Definition: decoderbase.h:60
MythBDBuffer::GetFrameRate
double GetFrameRate(void)
Definition: mythbdbuffer.cpp:868
e
QDomElement e
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1420
MARK_KEYFRAME
@ MARK_KEYFRAME
Definition: programtypes.h:62
DecoderBase::SetTrack
virtual int SetTrack(uint Type, int TrackNo)
Definition: decoderbase.cpp:963
DecoderBase::m_readAdjust
long long m_readAdjust
Definition: decoderbase.h:343
DecoderBase::m_trackLock
QMutex m_trackLock
Definition: decoderbase.h:348
DecoderBase::GetTrack
int GetTrack(uint Type)
Definition: decoderbase.cpp:957
DecoderBase::NextTrack
int NextTrack(uint Type)
Definition: decoderbase.cpp:1010
DecoderBase::m_seekSnap
uint64_t m_seekSnap
Definition: decoderbase.h:329
AudioTrackType
AudioTrackType
Definition: decoderbase.h:55
kTrackTypeTextSubtitle
@ kTrackTypeTextSubtitle
Definition: decoderbase.h:42
DecoderBase::m_selectedTrack
std::array< StreamInfo, kTrackTypeCount > m_selectedTrack
Definition: decoderbase.h:353
DecoderBase::m_ringBuffer
MythMediaBuffer * m_ringBuffer
Definition: decoderbase.h:288
DecoderBase::m_renderFormats
const VideoFrameTypes * m_renderFormats
Definition: decoderbase.h:359
DecoderBase::PosMapEntry
Definition: decoderbase.h:277
ProgramInfo::QueryPositionMap
void QueryPositionMap(frm_pos_map_t &posMap, MarkTypes type) const
Definition: programinfo.cpp:3593
kEofStateNone
@ kEofStateNone
Definition: decoderbase.h:69
kTrackTypeCount
@ kTrackTypeCount
Definition: decoderbase.h:38
DecoderBase::m_fps
double m_fps
Definition: decoderbase.h:290
MythTimer
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:13
DecoderBase::m_indexOffset
long long m_indexOffset
Definition: decoderbase.h:304
DecoderBase::m_lastPositionMapUpdate
QDateTime m_lastPositionMapUpdate
Definition: decoderbase.h:327
to_track_type
int to_track_type(const QString &str)
Definition: decoderbase.cpp:1182
MythBDBuffer::GetTotalReadPosition
uint64_t GetTotalReadPosition(void)
Definition: mythbdbuffer.cpp:798
MythMediaBuffer::Seek
long long Seek(long long Position, int Whence, bool HasLock=false)
Definition: mythmediabuffer.cpp:475
ProgramInfo::SavePositionMapDelta
void SavePositionMapDelta(frm_pos_map_t &posMap, MarkTypes type) const
Definition: programinfo.cpp:3821
DecoderBase::m_hasKeyFrameAdjustTable
bool m_hasKeyFrameAdjustTable
Definition: decoderbase.h:334
ProgramInfo::SaveTotalFrames
void SaveTotalFrames(int64_t frames)
Store the Total Frames at frame 0 in the recordedmarkup table.
Definition: programinfo.cpp:4170
DecoderBase::ConditionallyUpdatePosMap
long long ConditionallyUpdatePosMap(long long desiredFrame)
Definition: decoderbase.cpp:667
DecoderBase::AutoSelectTrack
virtual int AutoSelectTrack(uint Type)
Select best track.
Definition: decoderbase.cpp:1054
DecoderBase::m_atEof
EofState m_atEof
Definition: decoderbase.h:308
DecoderBase::m_parent
MythPlayer * m_parent
Definition: decoderbase.h:285
DecoderBase::SavePositionMapDelta
uint64_t SavePositionMapDelta(long long first_frame, long long last_frame)
Definition: decoderbase.cpp:500
MARK_CUT_END
@ MARK_CUT_END
Definition: programtypes.h:55
StreamInfo::m_stream_id
int m_stream_id
Definition: decoderbase.h:99
kTrackTypeTeletextMenu
@ kTrackTypeTeletextMenu
Definition: decoderbase.h:35
DecoderBase::DecoderBase
DecoderBase(MythPlayer *parent, const ProgramInfo &pginfo)
Definition: decoderbase.cpp:17
mythdvdbuffer.h
DecoderBase::m_livetv
bool m_livetv
Definition: decoderbase.h:331
arg
arg(title).arg(filename).arg(doDelete))
frm_dir_map_t
QMap< uint64_t, MarkTypes > frm_dir_map_t
Frame # -> Mark map.
Definition: programtypes.h:82
DecoderBase::ResetTracks
void ResetTracks(void)
Definition: decoderbase.cpp:1151
MythMediaBuffer::IsDVD
bool IsDVD(void) const
Definition: mythmediabuffer.cpp:1823
MythTimer::start
void start(void)
starts measuring elapsed time.
Definition: mythtimer.cpp:47
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
DecoderBase::ChangeTrack
int ChangeTrack(uint Type, int Dir)
Definition: decoderbase.cpp:994
TrackType
TrackType
Track types.
Definition: decoderbase.h:26
kAudioTypeCleanEffects
@ kAudioTypeCleanEffects
Definition: decoderbase.h:59
mythplayer.h
DecoderBase::m_positionMapType
MarkTypes m_positionMapType
Definition: decoderbase.h:321
MythDVDBuffer::TitleTimeLeft
uint TitleTimeLeft(void) const
returns seconds left in the title
Definition: mythdvdbuffer.cpp:1974
MythPlayer
Definition: mythplayer.h:83
MythMediaBuffer::IsBD
bool IsBD(void) const
Definition: mythmediabuffer.cpp:1828
MythPlayer::ForcedSubtitlesFavored
bool ForcedSubtitlesFavored(void) const
Definition: mythplayer.h:202
DecoderBase::m_posmapStarted
bool m_posmapStarted
Definition: decoderbase.h:320
MythDVDBuffer::GetFrameRate
double GetFrameRate(void)
used by DecoderBase for the total frame number calculation for position map support and ffw/rew.
Definition: mythdvdbuffer.cpp:1936
DecoderBase::m_exitAfterDecoded
bool m_exitAfterDecoded
Definition: decoderbase.h:315
iso639_key_toName
QString iso639_key_toName(int iso639_2)
Converts a canonical key to language name in English.
Definition: iso639.cpp:109
iso639_get_language_key_list
std::vector< int > iso639_get_language_key_list(void)
Definition: iso639.cpp:56
DecoderBase::m_frameToDurMap
frm_pos_map_t m_frameToDurMap
Definition: decoderbase.h:325
DecoderBase::GetWaitForChange
bool GetWaitForChange(void) const
Definition: decoderbase.cpp:904
DecoderBase::SetWaitForChange
void SetWaitForChange(void)
Definition: decoderbase.cpp:899
DecoderBase::m_currentTrack
std::array< int, kTrackTypeCount > m_currentTrack
Definition: decoderbase.h:350
tmp
static guint32 * tmp
Definition: goom_core.cpp:31
DecoderBase::m_dontSyncPositionMap
bool m_dontSyncPositionMap
Definition: decoderbase.h:330
DecoderBase::m_tracks
std::array< sinfo_vec_t, kTrackTypeCount > m_tracks
Definition: decoderbase.h:351
kAudioTypeAudioDescription
@ kAudioTypeAudioDescription
Definition: decoderbase.h:58
kAudioTypeNormal
@ kAudioTypeNormal
Definition: decoderbase.h:57
toString
QString toString(TrackType type)
Definition: decoderbase.cpp:1157
DecoderBase::GetTrackDesc
virtual QString GetTrackDesc(uint Type, uint TrackNo)
Definition: decoderbase.cpp:939
DecoderBase::SaveTotalDuration
void SaveTotalDuration(void)
Definition: decoderbase.cpp:1241
DecoderBase::GetTrackCount
virtual uint GetTrackCount(uint Type)
Definition: decoderbase.cpp:909
DecoderBase::FindPosition
virtual bool FindPosition(long long desired_value, bool search_adjusted, int &lower_bound, int &upper_bound)
Definition: decoderbase.cpp:420
DecoderBase::TranslatePositionAbsToRel
static uint64_t TranslatePositionAbsToRel(const frm_dir_map_t &deleteMap, uint64_t absPosition, const frm_pos_map_t &map=frm_pos_map_t(), float fallback_ratio=1.0)
Definition: decoderbase.cpp:1363
programinfo.h
DecoderBase::m_keyframeDist
int m_keyframeDist
Definition: decoderbase.h:302
DecoderBase::m_getRawFrames
bool m_getRawFrames
Definition: decoderbase.h:336
mythlogging.h
DecoderBase::GetTrackInfo
StreamInfo GetTrackInfo(uint Type, uint TrackNo)
Definition: decoderbase.cpp:983
StreamInfo
Definition: decoderbase.h:74
DecoderBase::m_languagePreference
std::vector< int > m_languagePreference
language preferences for auto-selection of streams
Definition: decoderbase.h:356
DecoderBase::DoRewindSeek
virtual bool DoRewindSeek(long long desiredFrame)
Definition: decoderbase.cpp:589
MythMediaBuffer::IsInDiscMenuOrStillFrame
virtual bool IsInDiscMenuOrStillFrame(void) const
Definition: mythmediabuffer.h:132
MARK_DURATION_MS
@ MARK_DURATION_MS
Definition: programtypes.h:74
MARK_GOP_START
@ MARK_GOP_START
Definition: programtypes.h:61
DecoderBase::~DecoderBase
virtual ~DecoderBase()
Definition: decoderbase.cpp:31
VideoFrameTypes
std::vector< VideoFrameType > VideoFrameTypes
Definition: mythframe.h:81
DecoderBase::TranslatePositionRelToAbs
static uint64_t TranslatePositionRelToAbs(const frm_dir_map_t &deleteMap, uint64_t relPosition, const frm_pos_map_t &map=frm_pos_map_t(), float fallback_ratio=1.0)
Definition: decoderbase.cpp:1412
DecoderBase::m_positionMap
std::vector< PosMapEntry > m_positionMap
Definition: decoderbase.h:324
LOC
#define LOC
Definition: decoderbase.cpp:15
DecoderBase::m_positionMapLock
QMutex m_positionMapLock
Definition: decoderbase.h:323
kTrackTypeTeletextCaptions
@ kTrackTypeTeletextCaptions
Definition: decoderbase.h:34
hardwareprofile.smolt.long
long
Definition: smolt.py:76
DecoderBase::m_durToFrameMap
frm_pos_map_t m_durToFrameMap
Definition: decoderbase.h:326
DecoderBase::ResetPosMap
virtual void ResetPosMap(void)
Definition: decoderbase.cpp:647
DecoderBase::SetReadAdjust
void SetReadAdjust(long long adjust)
Definition: decoderbase.cpp:894
DecoderBase::m_playbackInfo
ProgramInfo * m_playbackInfo
Definition: decoderbase.h:286
DecoderBase::m_totalDuration
AVRational m_totalDuration
Definition: decoderbase.h:301
MythPlayer::PosMapFromEnc
bool PosMapFromEnc(uint64_t start, frm_pos_map_t &posMap, frm_pos_map_t &durMap)
Definition: mythplayer.cpp:1902
kTrackTypeAudio
@ kTrackTypeAudio
Definition: decoderbase.h:29
kTrackTypeCC708
@ kTrackTypeCC708
Definition: decoderbase.h:33
DecoderBase::GetPositionMapSize
unsigned long GetPositionMapSize(void) const
Definition: decoderbase.cpp:294
uint
unsigned int uint
Definition: compat.h:141
DecoderBase::AutoSelectTracks
void AutoSelectTracks(void)
Definition: decoderbase.cpp:1145
DecoderBase::FileChanged
void FileChanged(void)
Definition: decoderbase.cpp:881
DecoderBase::m_wantedTrack
std::array< StreamInfo, kTrackTypeCount > m_wantedTrack
Definition: decoderbase.h:352
DecoderBase::m_transcoding
bool m_transcoding
Definition: decoderbase.h:316
DecoderBase::m_waitingForChange
bool m_waitingForChange
Definition: decoderbase.h:341
kTrackTypeSubtitle
@ kTrackTypeSubtitle
Definition: decoderbase.h:31
DecoderBase::m_justAfterChange
bool m_justAfterChange
Definition: decoderbase.h:342
DecoderBase::SyncPositionMap
virtual bool SyncPositionMap(void)
Updates the position map used for skipping frames.
Definition: decoderbase.cpp:322
frm_pos_map_t
QMap< long long, long long > frm_pos_map_t
Frame # -> File offset map.
Definition: programtypes.h:46
kDecodeNothing
@ kDecodeNothing
Definition: decoderbase.h:49
DecoderBase::SetProgramInfo
void SetProgramInfo(const ProgramInfo &pginfo)
Definition: decoderbase.cpp:42
DecoderBase::GetKey
long long GetKey(const PosMapEntry &entry) const
Definition: decoderbase.cpp:582
DecoderBase::PosMapFromEnc
virtual bool PosMapFromEnc(void)
Queries encoder for position map data that has not been committed to the DB yet.
Definition: decoderbase.cpp:223
DecoderBase::SetWatchingRecording
virtual void SetWatchingRecording(bool mode)
Definition: decoderbase.cpp:82
MythPlayer::SetFileLength
void SetFileLength(int total, int frames)
Definition: mythplayer.cpp:387
DecoderBase::GetFrame
virtual bool GetFrame(DecodeType Type, bool &Retry)=0
Demux, preprocess and possibly decode a frame of video/audio.
DecoderBase::DoFastForwardSeek
virtual void DoFastForwardSeek(long long desiredFrame, bool &needflush)
Seeks to the keyframe just before the desiredFrame if exact seeks is enabled, or the frame just after...
Definition: decoderbase.cpp:830
MythTimer::elapsed
int elapsed(void)
Returns milliseconds elapsed since last start() or restart()
Definition: mythtimer.cpp:90
MARK_CUT_START
@ MARK_CUT_START
Definition: programtypes.h:56
mythbdbuffer.h
kTrackTypeCC608
@ kTrackTypeCC608
Definition: decoderbase.h:32
MythPlayer::SetKeyframeDistance
void SetKeyframeDistance(int keyframedistance)
Definition: mythplayer.cpp:322
DecoderBase::UpdateFramesPlayed
virtual void UpdateFramesPlayed(void)
Definition: decoderbase.cpp:876
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
DecoderBase::SetDecodeAllSubtitles
void SetDecodeAllSubtitles(bool DecodeAll)
Definition: decoderbase.cpp:915
ProgramInfo::SaveTotalDuration
void SaveTotalDuration(int64_t duration)
Store the Total Duration at frame 0 in the recordedmarkup table.
Definition: programinfo.cpp:4138
DecoderBase::m_framesPlayed
long long m_framesPlayed
Definition: decoderbase.h:298
DecoderBase::TranslatePositionMsToFrame
uint64_t TranslatePositionMsToFrame(uint64_t dur_ms, float fallback_framerate, const frm_dir_map_t &cutlist)
Definition: decoderbase.cpp:1339
MythPlayer::SetFramesPlayed
void SetFramesPlayed(uint64_t played)
Definition: mythplayer.cpp:561
MythPlayer::FileChangedCallback
void FileChangedCallback()
Definition: mythplayer.cpp:924
MARK_GOP_BYFRAME
@ MARK_GOP_BYFRAME
Definition: programtypes.h:64
DecoderBase::SetRenderFormats
void SetRenderFormats(const VideoFrameTypes *RenderFormats)
Definition: decoderbase.cpp:36
DecoderBase::TranslatePositionFrameToMs
uint64_t TranslatePositionFrameToMs(long long position, float fallback_framerate, const frm_dir_map_t &cutlist)
Definition: decoderbase.cpp:1311
DecoderBase::m_decodeAllSubtitles
bool m_decodeAllSubtitles
Definition: decoderbase.h:349
MarkTypes
MarkTypes
Definition: programtypes.h:48
DecoderBase::m_watchingRecording
bool m_watchingRecording
Definition: decoderbase.h:332
MythAVUtil::FrameTypeToPixelFormat
static AVPixelFormat FrameTypeToPixelFormat(VideoFrameType Type)
Definition: mythavutil.cpp:26
MythDVDBuffer::GetTotalTimeOfTitle
uint GetTotalTimeOfTitle(void) const
get the total time of the title in seconds 90000 ticks = 1 sec
Definition: mythdvdbuffer.cpp:1141
MythMediaBuffer::IsDisc
bool IsDisc(void) const
Definition: mythmediabuffer.cpp:1818
DecoderBase::TranslatePosition
static uint64_t TranslatePosition(const frm_pos_map_t &map, long long key, float fallback_ratio)
Definition: decoderbase.cpp:1260
decoderbase.h
DecoderBase::PosMapFromDb
virtual bool PosMapFromDb(void)
Definition: decoderbase.cpp:95
kTrackTypeRawText
@ kTrackTypeRawText
Definition: decoderbase.h:36
DecoderBase::GetBestVideoFormat
static AVPixelFormat GetBestVideoFormat(AVPixelFormat *Formats, const VideoFrameTypes *RenderFormats)
Find a suitable frame format that is mutually acceptable to the decoder and render device.
Definition: decoderbase.cpp:1448
iso639.h
ISO 639-1 and ISO 639-2 support functions.
MARK_UNSET
@ MARK_UNSET
Definition: programtypes.h:50
mythcodeccontext.h
DecoderBase::m_lastKey
long long m_lastKey
Definition: decoderbase.h:303
MythDVDBuffer::GetTotalReadPosition
long long GetTotalReadPosition(void) const
Definition: mythdvdbuffer.cpp:451
MythMediaBuffer::DVD
const MythDVDBuffer * DVD(void) const
Definition: mythmediabuffer.cpp:1833
kTrackTypeVideo
@ kTrackTypeVideo
Definition: decoderbase.h:30
MythPlayer::SignalTracksChanged
void SignalTracksChanged(uint Type)
DecoderBase::m_framesRead
long long m_framesRead
Definition: decoderbase.h:299
MythBDBuffer::GetTotalTimeOfTitle
uint64_t GetTotalTimeOfTitle(void) const
Definition: mythbdbuffer.cpp:623
DecoderBase::Reset
virtual void Reset(bool reset_video_data, bool seek_reset, bool reset_file)
Definition: decoderbase.cpp:48
DecoderBase::GetTracks
virtual QStringList GetTracks(uint Type)
Definition: decoderbase.cpp:922
DecoderBase::m_fpsSkip
int m_fpsSkip
Definition: decoderbase.h:292
kAudioTypeSpokenSubs
@ kAudioTypeSpokenSubs
Definition: decoderbase.h:61
DecoderBase::GetLastFrameInPosMap
long long GetLastFrameInPosMap(void) const
Definition: decoderbase.cpp:656
DecoderBase::SetEofState
virtual void SetEofState(EofState eof)
Definition: decoderbase.h:131
DecoderBase::InsertTrack
virtual bool InsertTrack(uint Type, const StreamInfo &Info)
Definition: decoderbase.cpp:1021
DecoderBase::SeekReset
virtual void SeekReset(long long newkey, uint skipFrames, bool doFlush, bool discardFrames)
Definition: decoderbase.cpp:75
DecoderBase::DoRewind
virtual bool DoRewind(long long desiredFrame, bool discardFrames=true)
Definition: decoderbase.cpp:555
DecoderBase::m_recordingHasPositionMap
bool m_recordingHasPositionMap
Definition: decoderbase.h:319
DecoderBase::GetTrackLanguageIndex
virtual int GetTrackLanguageIndex(uint Type, uint TrackNo)
Definition: decoderbase.cpp:931
DecoderBase::SaveTotalFrames
void SaveTotalFrames(void)
Definition: decoderbase.cpp:1249
kAudioTypeCommentary
@ kAudioTypeCommentary
Definition: decoderbase.h:62
DecoderBase::m_frameCounter
uint64_t m_frameCounter
Definition: decoderbase.h:300