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  m_rawAudio = CopyAudio;
39  m_rawVideo = CopyVideo;
40  if (m_decoder)
42 }
43 
45 {
46  m_deleteMap.SetMap(CutList);
47 }
48 
49 bool MythTranscodePlayer::TranscodeGetNextFrame(int &DidFF, bool &KeyFrame, bool HonorCutList)
50 {
51  m_playerCtx->LockPlayingInfo(__FILE__, __LINE__);
54  m_playerCtx->UnlockPlayingInfo(__FILE__, __LINE__);
55 
56  int64_t lastDecodedFrameNumber = m_videoOutput->GetLastDecodedFrame()->m_frameNumber;
57 
58  if ((lastDecodedFrameNumber == 0) && HonorCutList)
60 
61  if (!m_decoderThread)
62  DecoderStart(true/*start paused*/);
63 
64  if (!m_decoder)
65  return false;
66 
67  {
68  QMutexLocker decoderlocker(&m_decoderChangeLock);
69  if (!DoGetFrame(kDecodeAV))
70  return false;
71  }
72 
73  if (GetEof() != kEofStateNone)
74  return false;
75 
76  if (HonorCutList && !m_deleteMap.IsEmpty())
77  {
78  if (m_totalFrames && lastDecodedFrameNumber >= static_cast<int64_t>(m_totalFrames))
79  return false;
80 
81  uint64_t jumpto = 0;
82  if (m_deleteMap.TrackerWantsToJump(static_cast<uint64_t>(lastDecodedFrameNumber), jumpto))
83  {
84  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Fast-Forwarding from %1 to %2")
85  .arg(lastDecodedFrameNumber).arg(jumpto));
86  if (jumpto >= m_totalFrames)
87  {
89  return false;
90  }
91 
92  // For 0.25, move this to DoJumpToFrame(jumpto)
93  WaitForSeek(jumpto, 0);
95  m_decoderChangeLock.lock();
97  m_decoderChangeLock.unlock();
98  DidFF = 1;
99  }
100  }
101  if (GetEof() != kEofStateNone)
102  return false;
103  KeyFrame = m_decoder->IsLastFrameKey();
104  return true;
105 }
MythPlayer::m_decoderChangeLock
QRecursiveMutex m_decoderChangeLock
Definition: mythplayer.h:362
PlayerContext::UnlockPlayingInfo
void UnlockPlayingInfo(const char *file, int line) const
Definition: playercontext.cpp:249
MythPlayer::SetEof
void SetEof(EofState eof)
Definition: mythplayer.cpp:1080
MythPlayer::m_decoderThread
MythDecoderThread * m_decoderThread
Definition: mythplayer.h:366
DeleteMap::TrackerReset
void TrackerReset(uint64_t frame)
Resets the internal state tracker.
Definition: deletemap.cpp:811
MythTranscodePlayer::MythTranscodePlayer
MythTranscodePlayer(PlayerContext *Context, PlayerFlags Flags=kNoFlags)
Definition: mythtranscodeplayer.cpp:6
MythTranscodePlayer::TranscodeGetNextFrame
bool TranscodeGetNextFrame(int &DidFF, bool &KeyFrame, bool HonorCutList)
Definition: mythtranscodeplayer.cpp:49
DeleteMap::SetMap
void SetMap(const frm_dir_map_t &map)
Use the given map.
Definition: deletemap.cpp:720
frm_dir_map_t
QMap< uint64_t, MarkTypes > frm_dir_map_t
Frame # -> Mark map.
Definition: programtypes.h:117
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
DeleteMap::IsEmpty
bool IsEmpty(void) const
Definition: deletemap.cpp:259
ProgramInfo::UpdateInUseMark
void UpdateInUseMark(bool force=false)
Definition: programinfo.cpp:4984
PlayerFlags
PlayerFlags
Definition: mythplayer.h:64
MythPlayer::GetEof
EofState GetEof(void) const
Definition: mythplayer.cpp:1067
MythPlayer
Definition: mythplayer.h:83
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:847
MythTranscodePlayer::InitForTranscode
void InitForTranscode(bool CopyAudio, bool CopyVideo)
Definition: mythtranscodeplayer.cpp:22
MythPlayer::m_decoder
DecoderBase * m_decoder
Definition: mythplayer.h:361
kEofStateNone
@ kEofStateNone
Definition: decoderbase.h:70
MythPlayer::m_framesPlayed
uint64_t m_framesPlayed
Definition: mythplayer.h:423
PlayerContext::m_playingInfo
ProgramInfo * m_playingInfo
Currently playing info.
Definition: playercontext.h:117
PlayerContext::LockPlayingInfo
void LockPlayingInfo(const char *file, int line) const
Definition: playercontext.cpp:239
MythTranscodePlayer::m_rawAudio
bool m_rawAudio
Definition: mythtranscodeplayer.h:24
MythPlayer::m_videoOutput
MythVideoOutput * m_videoOutput
Definition: mythplayer.h:363
DecoderBase::IsLastFrameKey
virtual bool IsLastFrameKey(void) const =0
mythtranscodeplayer.h
MythPlayer::InitVideo
virtual bool InitVideo(void)
Definition: mythplayer.cpp:273
kDecodeAV
@ kDecodeAV
Definition: decoderbase.h:53
MythVideoFrame::m_frameNumber
long long m_frameNumber
Definition: mythframe.h:128
MythPlayer::ClearAfterSeek
void ClearAfterSeek(bool clearvideobuffers=true)
This is to support seeking...
Definition: mythplayer.cpp:1678
MythPlayer::m_totalFrames
uint64_t m_totalFrames
Definition: mythplayer.h:424
MythPlayer::m_playerCtx
PlayerContext * m_playerCtx
Definition: mythplayer.h:365
MythVideoOutput::GetLastDecodedFrame
virtual MythVideoFrame * GetLastDecodedFrame()
Definition: mythvideoout.cpp:303
MythPlayer::m_keyframeDist
uint m_keyframeDist
Video (input) Number of frames between key frames (often inaccurate)
Definition: mythplayer.h:444
MythPlayer::m_deleteMap
DeleteMap m_deleteMap
Definition: mythplayer.h:477
DecoderBase::SetSeekSnap
void SetSeekSnap(uint64_t snap)
Definition: decoderbase.h:138
DecoderBase::SetTranscoding
void SetTranscoding(bool value)
Definition: decoderbase.h:215
kEofStateDelayed
@ kEofStateDelayed
Definition: decoderbase.h:71
MythPlayer::WaitForSeek
void WaitForSeek(uint64_t frame, uint64_t seeksnap_wanted)
Definition: mythplayer.cpp:1615
MythPlayer::SetPlaying
void SetPlaying(bool is_playing)
Definition: mythplayer.cpp:245
MythPlayer::m_transcoding
bool m_transcoding
Definition: mythplayer.h:404
PlayerContext
Definition: playercontext.h:49
MythTranscodePlayer::SetTranscoding
void SetTranscoding(bool Transcoding)
Definition: mythtranscodeplayer.cpp:11
MythTranscodePlayer::SetCutList
void SetCutList(const frm_dir_map_t &CutList)
Definition: mythtranscodeplayer.cpp:44
MythTranscodePlayer::m_rawVideo
bool m_rawVideo
Definition: mythtranscodeplayer.h:25
LOC
#define LOC
Definition: mythtranscodeplayer.cpp:4
MythPlayer::DoGetFrame
bool DoGetFrame(DecodeType DecodeType)
Get one frame from the decoder.
Definition: mythplayer.cpp:1286
MythPlayer::DecoderStart
virtual void DecoderStart(bool start_paused)
Definition: mythplayer.cpp:1016