MythTV  master
videodecodebuffer.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "videodecodebuffer.h"
3 #include "mythtranscodeplayer.h"
4 
5 // Std
6 #include <chrono>
7 #include <thread>
8 
10  bool Cutlist, int Size)
11  : m_player(Player), m_videoOutput(Videoout),
12  m_honorCutlist(Cutlist), m_maxFrames(Size)
13 {
14 }
15 
17 {
18  m_runThread = false;
19  m_frameWaitCond.wakeAll();
20  while (m_isRunning)
21  std::this_thread::sleep_for(50ms);
22 }
23 
25 {
26  m_runThread = false;
27  m_frameWaitCond.wakeAll();
28  while (m_isRunning)
29  std::this_thread::sleep_for(50ms);
30 }
31 
33 {
34  m_isRunning = true;
35  while (m_runThread)
36  {
37  QMutexLocker locker(&m_queueLock);
38 
39  if (m_frameList.size() < m_maxFrames && !m_eof)
40  {
41  locker.unlock();
42 
43  DecodedFrameInfo frameinfo {};
44  frameinfo.frame = nullptr;
45  frameinfo.didFF = 0;
46  frameinfo.isKey = false;
47 
48  if (m_player->TranscodeGetNextFrame(frameinfo.didFF, frameinfo.isKey, m_honorCutlist))
49  {
50  frameinfo.frame = m_videoOutput->GetLastDecodedFrame();
51  locker.relock();
52  m_frameList.append(frameinfo);
53  }
54  else if (m_player->GetEof() != kEofStateNone)
55  {
56  locker.relock();
57  m_eof = true;
58  }
59  else
60  {
61  continue;
62  }
63  m_frameWaitCond.wakeAll();
64  }
65  else
66  {
67  m_frameWaitCond.wait(locker.mutex());
68  }
69  }
70  m_isRunning = false;
71 }
72 
74 {
75  QMutexLocker locker(&m_queueLock);
76 
77  if (m_frameList.isEmpty())
78  {
79  if (m_eof)
80  return nullptr;
81 
82  m_frameWaitCond.wait(locker.mutex());
83  if (m_frameList.isEmpty())
84  return nullptr;
85  }
86 
87  DecodedFrameInfo tfInfo = m_frameList.takeFirst();
88  locker.unlock();
89  m_frameWaitCond.wakeAll();
90  DidFF = tfInfo.didFF;
91  Key = tfInfo.isKey;
92  return tfInfo.frame;
93 }
94 
95 /* vim: set expandtab tabstop=4 shiftwidth=4: */
96 
VideoDecodeBuffer::GetFrame
MythVideoFrame * GetFrame(int &DidFF, bool &Key)
Definition: videodecodebuffer.cpp:73
MythVideoOutput
Definition: mythvideoout.h:35
VideoDecodeBuffer::m_runThread
bool volatile m_runThread
Definition: videodecodebuffer.h:39
VideoDecodeBuffer::stop
void stop()
Definition: videodecodebuffer.cpp:24
kEofStateNone
@ kEofStateNone
Definition: decoderbase.h:69
MythTranscodePlayer::TranscodeGetNextFrame
bool TranscodeGetNextFrame(int &DidFF, bool &KeyFrame, bool HonorCutList)
Definition: mythtranscodeplayer.cpp:51
VideoDecodeBuffer::m_videoOutput
MythVideoOutput *const m_videoOutput
Definition: videodecodebuffer.h:36
VideoDecodeBuffer::DecodedFrameInfo::didFF
int didFF
Definition: videodecodebuffer.h:31
VideoDecodeBuffer::~VideoDecodeBuffer
~VideoDecodeBuffer() override
Definition: videodecodebuffer.cpp:16
MythPlayer::GetEof
EofState GetEof(void) const
Definition: mythplayer.cpp:1052
VideoDecodeBuffer::m_frameList
QList< DecodedFrameInfo > m_frameList
Definition: videodecodebuffer.h:43
VideoDecodeBuffer::m_player
MythTranscodePlayer *const m_player
Definition: videodecodebuffer.h:35
VideoDecodeBuffer::m_queueLock
QMutex m_queueLock
Definition: videodecodebuffer.h:41
VideoDecodeBuffer::m_isRunning
bool volatile m_isRunning
Definition: videodecodebuffer.h:40
mythtranscodeplayer.h
VideoDecodeBuffer::DecodedFrameInfo
Definition: videodecodebuffer.h:28
MythVideoOutput::GetLastDecodedFrame
virtual MythVideoFrame * GetLastDecodedFrame()
Definition: mythvideoout.cpp:302
VideoDecodeBuffer::m_honorCutlist
const bool m_honorCutlist
Definition: videodecodebuffer.h:37
VideoDecodeBuffer::DecodedFrameInfo::frame
MythVideoFrame * frame
Definition: videodecodebuffer.h:30
VideoDecodeBuffer::m_frameWaitCond
QWaitCondition m_frameWaitCond
Definition: videodecodebuffer.h:44
VideoDecodeBuffer::DecodedFrameInfo::isKey
bool isKey
Definition: videodecodebuffer.h:32
VideoDecodeBuffer::m_maxFrames
const int m_maxFrames
Definition: videodecodebuffer.h:38
videodecodebuffer.h
VideoDecodeBuffer::VideoDecodeBuffer
VideoDecodeBuffer(MythTranscodePlayer *Player, MythVideoOutput *Videoout, bool Cutlist, int Size=5)
Definition: videodecodebuffer.cpp:9
Player
Definition: zmliveplayer.h:34
MythVideoFrame
Definition: mythframe.h:88
VideoDecodeBuffer::run
void run() override
Definition: videodecodebuffer.cpp:32
VideoDecodeBuffer::m_eof
bool m_eof
Definition: videodecodebuffer.h:42
MythTranscodePlayer
Definition: mythtranscodeplayer.h:7