MythTV  master
mythtranscodeplayer.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "mythtranscodeplayer.h"
3 
4 #define LOC QString("TranscodePlayer: ")
5 
7  : MythPlayer(Context, Flags)
8 {
9 }
10 
12 {
13  // TODO this is called too early to work but the second call to DecoderBase::SetTranscoding
14  // is embedded in the middle of MythPlayer::OpenFile
15  m_transcoding = Transcoding;
16  if (m_decoder)
17  m_decoder->SetTranscoding(Transcoding);
18  else
19  LOG(VB_GENERAL, LOG_WARNING, LOC + "No decoder yet - cannot set transcoding");
20 }
21 
22 void MythTranscodePlayer::InitForTranscode(bool CopyAudio, bool CopyVideo)
23 {
24  // Are these really needed?
25  SetPlaying(true);
26  m_keyframeDist = 30;
27 
28  if (!InitVideo())
29  {
30  LOG(VB_GENERAL, LOG_ERR, LOC + "Unable to initialize video for transcode.");
31  SetPlaying(false);
32  return;
33  }
34 
35  m_framesPlayed = 0;
37 
38  if (CopyVideo && m_decoder)
40  if (CopyAudio && m_decoder)
42  if (m_decoder)
44 }
45 
47 {
48  m_deleteMap.SetMap(CutList);
49 }
50 
51 bool MythTranscodePlayer::TranscodeGetNextFrame(int &DidFF, bool &KeyFrame, bool HonorCutList)
52 {
53  m_playerCtx->LockPlayingInfo(__FILE__, __LINE__);
56  m_playerCtx->UnlockPlayingInfo(__FILE__, __LINE__);
57 
58  int64_t lastDecodedFrameNumber = m_videoOutput->GetLastDecodedFrame()->m_frameNumber;
59 
60  if ((lastDecodedFrameNumber == 0) && HonorCutList)
62 
63  if (!m_decoderThread)
64  DecoderStart(true/*start paused*/);
65 
66  if (!m_decoder)
67  return false;
68 
69  {
70  QMutexLocker decoderlocker(&m_decoderChangeLock);
71  if (!DoGetFrame(kDecodeAV))
72  return false;
73  }
74 
75  if (GetEof() != kEofStateNone)
76  return false;
77 
78  if (HonorCutList && !m_deleteMap.IsEmpty())
79  {
80  if (m_totalFrames && lastDecodedFrameNumber >= static_cast<int64_t>(m_totalFrames))
81  return false;
82 
83  uint64_t jumpto = 0;
84  if (m_deleteMap.TrackerWantsToJump(static_cast<uint64_t>(lastDecodedFrameNumber), jumpto))
85  {
86  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Fast-Forwarding from %1 to %2")
87  .arg(lastDecodedFrameNumber).arg(jumpto));
88  if (jumpto >= m_totalFrames)
89  {
91  return false;
92  }
93 
94  // For 0.25, move this to DoJumpToFrame(jumpto)
95  WaitForSeek(jumpto, 0);
98  m_decoderChangeLock.lock();
100  m_decoderChangeLock.unlock();
101  DidFF = 1;
102  }
103  }
104  if (GetEof() != kEofStateNone)
105  return false;
106  KeyFrame = m_decoder->IsLastFrameKey();
107  return true;
108 }
109 
111 {
112  if (m_decoder)
113  return m_decoder->UpdateStoredFrameNum(CurrentFrameNum);
114  return 0;
115 }
116 
118  bool Writevideo,
119  std::chrono::milliseconds TimecodeOffset)
120 {
121  if (!m_decoder)
122  return false;
123  if (Writevideo && !m_decoder->GetRawVideoState())
124  Writevideo = false;
125  m_decoder->WriteStoredData(OutBuffer, Writevideo, TimecodeOffset);
126  return Writevideo;
127 }
DecoderBase::UpdateStoredFrameNum
virtual long UpdateStoredFrameNum(long frame)=0
kDecodeAV
@ kDecodeAV
Definition: decoderbase.h:52
MythPlayer::m_decoderChangeLock
QRecursiveMutex m_decoderChangeLock
Definition: mythplayer.h:370
DecoderBase::ClearStoredData
virtual void ClearStoredData(void)
Definition: decoderbase.h:190
PlayerContext::UnlockPlayingInfo
void UnlockPlayingInfo(const char *file, int line) const
Definition: playercontext.cpp:245
MythPlayer::SetEof
void SetEof(EofState eof)
Definition: mythplayer.cpp:1065
MythPlayer::m_decoderThread
MythDecoderThread * m_decoderThread
Definition: mythplayer.h:375
DeleteMap::TrackerReset
void TrackerReset(uint64_t frame)
Resets the internal state tracker.
Definition: deletemap.cpp:806
MythTranscodePlayer::MythTranscodePlayer
MythTranscodePlayer(PlayerContext *Context, PlayerFlags Flags=kNoFlags)
Definition: mythtranscodeplayer.cpp:6
kEofStateNone
@ kEofStateNone
Definition: decoderbase.h:69
MythTranscodePlayer::TranscodeGetNextFrame
bool TranscodeGetNextFrame(int &DidFF, bool &KeyFrame, bool HonorCutList)
Definition: mythtranscodeplayer.cpp:51
DeleteMap::SetMap
void SetMap(const frm_dir_map_t &map)
Use the given map.
Definition: deletemap.cpp:715
frm_dir_map_t
QMap< uint64_t, MarkTypes > frm_dir_map_t
Frame # -> Mark map.
Definition: programtypes.h:119
MythMediaBuffer
Definition: mythmediabuffer.h:50
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
DeleteMap::IsEmpty
bool IsEmpty(void) const
Definition: deletemap.cpp:259
ProgramInfo::UpdateInUseMark
void UpdateInUseMark(bool force=false)
Definition: programinfo.cpp:4809
PlayerFlags
PlayerFlags
Definition: mythplayer.h:65
MythPlayer::GetEof
EofState GetEof(void) const
Definition: mythplayer.cpp:1052
MythPlayer
Definition: mythplayer.h:86
DeleteMap::TrackerWantsToJump
bool TrackerWantsToJump(uint64_t frame, uint64_t &to) const
Returns true if the given frame has passed the last cut point start and provides the frame number of ...
Definition: deletemap.cpp:840
DecoderBase::WriteStoredData
virtual void WriteStoredData(MythMediaBuffer *Buffer, bool storevid, std::chrono::milliseconds timecodeOffset)=0
MythTranscodePlayer::InitForTranscode
void InitForTranscode(bool CopyAudio, bool CopyVideo)
Definition: mythtranscodeplayer.cpp:22
MythPlayer::m_decoder
DecoderBase * m_decoder
Definition: mythplayer.h:366
MythPlayer::m_framesPlayed
uint64_t m_framesPlayed
Definition: mythplayer.h:432
DecoderBase::GetRawVideoState
virtual bool GetRawVideoState(void) const
Definition: decoderbase.h:194
PlayerContext::m_playingInfo
ProgramInfo * m_playingInfo
Currently playing info.
Definition: playercontext.h:120
PlayerContext::LockPlayingInfo
void LockPlayingInfo(const char *file, int line) const
Definition: playercontext.cpp:233
MythPlayer::m_videoOutput
MythVideoOutput * m_videoOutput
Definition: mythplayer.h:372
DecoderBase::IsLastFrameKey
virtual bool IsLastFrameKey(void) const =0
mythtranscodeplayer.h
MythPlayer::InitVideo
virtual bool InitVideo(void)
Definition: mythplayer.cpp:276
MythVideoFrame::m_frameNumber
long long m_frameNumber
Definition: mythframe.h:129
MythPlayer::ClearAfterSeek
void ClearAfterSeek(bool clearvideobuffers=true)
This is to support seeking...
Definition: mythplayer.cpp:1684
MythPlayer::m_totalFrames
uint64_t m_totalFrames
Definition: mythplayer.h:433
MythPlayer::m_playerCtx
PlayerContext * m_playerCtx
Definition: mythplayer.h:374
MythVideoOutput::GetLastDecodedFrame
virtual MythVideoFrame * GetLastDecodedFrame()
Definition: mythvideoout.cpp:302
MythPlayer::m_keyframeDist
uint m_keyframeDist
Video (input) Number of frames between key frames (often inaccurate)
Definition: mythplayer.h:453
MythPlayer::m_deleteMap
DeleteMap m_deleteMap
Definition: mythplayer.h:486
DecoderBase::SetSeekSnap
void SetSeekSnap(uint64_t snap)
Definition: decoderbase.h:137
DecoderBase::SetTranscoding
void SetTranscoding(bool value)
Definition: decoderbase.h:223
kEofStateDelayed
@ kEofStateDelayed
Definition: decoderbase.h:70
MythPlayer::WaitForSeek
void WaitForSeek(uint64_t frame, uint64_t seeksnap_wanted)
Definition: mythplayer.cpp:1623
MythPlayer::SetPlaying
void SetPlaying(bool is_playing)
Definition: mythplayer.cpp:248
MythPlayer::m_transcoding
bool m_transcoding
Definition: mythplayer.h:412
PlayerContext
Definition: playercontext.h:52
MythTranscodePlayer::WriteStoredData
bool WriteStoredData(MythMediaBuffer *OutBuffer, bool WriteVideo, std::chrono::milliseconds TimecodeOffset)
Definition: mythtranscodeplayer.cpp:117
DecoderBase::SetRawAudioState
virtual void SetRawAudioState(bool state)
Definition: decoderbase.h:191
MythTranscodePlayer::SetTranscoding
void SetTranscoding(bool Transcoding)
Definition: mythtranscodeplayer.cpp:11
MythTranscodePlayer::SetCutList
void SetCutList(const frm_dir_map_t &CutList)
Definition: mythtranscodeplayer.cpp:46
DecoderBase::SetRawVideoState
virtual void SetRawVideoState(bool state)
Definition: decoderbase.h:193
LOC
#define LOC
Definition: mythtranscodeplayer.cpp:4
MythTranscodePlayer::UpdateStoredFrameNum
long UpdateStoredFrameNum(long CurrentFrameNum)
Definition: mythtranscodeplayer.cpp:110
MythPlayer::DoGetFrame
bool DoGetFrame(DecodeType DecodeType)
Get one frame from the decoder.
Definition: mythplayer.cpp:1273
MythPlayer::DecoderStart
virtual void DecoderStart(bool start_paused)
Definition: mythplayer.cpp:1001