Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
H264Decoder.h
1#pragma once
2
3#include "Module.h"
4#include <vector>
5
7{
8public:
9 H264DecoderProps(uint _lowerWaterMark = 300, uint _upperWaterMark = 350)
10 {
11 lowerWaterMark = _lowerWaterMark;
12 upperWaterMark = _upperWaterMark;
13 }
16};
17
18class H264Decoder : public Module
19{
20public:
22 virtual ~H264Decoder();
23 bool init();
24 bool term();
25 bool processEOS(string& pinId);
26
27protected:
28 bool process(frame_container& frames);
29 bool processSOS(frame_sp& frame);
30 void addInputPin(framemetadata_sp& metadata, string& pinId);
31 bool validateInputPins();
32 bool validateOutputPins();
33 bool shouldTriggerSOS();
34 void flushQue();
35 bool handleCommand(Command::CommandType type, frame_sp& frame);
36
37private:
38 void bufferDecodedFrames(frame_sp& frame);
39 void bufferBackwardEncodedFrames(frame_sp& frame, short naluType);
40 void bufferAndDecodeForwardEncodedFrames(frame_sp& frame, short naluType);
41
42 class Detail;
43 boost::shared_ptr<Detail> mDetail;
45 framemetadata_sp mOutputMetadata;
46 std::string mOutputPinId;
48
49
50 /* Used to buffer multiple complete GOPs
51 note that we decode frames from this queue in reverse play*/
52 std::deque<std::deque<frame_sp>> backwardGopBuffer;
53 /* buffers the incomplete GOP */
54 std::deque<frame_sp> latestBackwardGop;
55 /* It buffers only one latest GOP
56 used in cases where partial GOP maybe in cache and rest of the GOP needs to be decoded
57 note that since there is no buffering in forward play, we directly decode frames from module queue*/
58 std::deque<frame_sp> latestForwardGop;
59 std::map<uint64, frame_sp> decodedFramesCache;
60 void sendDecodedFrame();
62 bool dirChangedToFwd = false;
63 bool dirChangedToBwd = false;
66 bool prevFrameInCache = false;
68 std::deque<uint64_t> incomingFramesTSQ;
69 void clearIncompleteBwdGopTsFromIncomingTSQ(std::deque<frame_sp>& latestGop);
70 void saveSpsPps(frame_sp frame);
71 void* prependSpsPps(frame_sp& iFrame, size_t& spsPpsFrameSize);
72 void dropFarthestFromCurrentTs(uint64_t ts);
73 frame_sp mHeaderFrame;
74 boost::asio::const_buffer spsBuffer;
75 boost::asio::const_buffer ppsBuffer;
76 std::mutex m;
77 int framesToSkip = 0;
79 int currentFps = 24;
80 int previousFps = 24;
81 float playbackSpeed = 1;
82 int gop;
83 uint64_t lastFrameSent;
84 bool resumeFwdPlayback = true;
85 bool resumeBwdPlayback = true;
86 bool resumePlayback = true;
88};
CommandType
Definition Command.h:9
Definition H264Decoder.h:7
uint upperWaterMark
Definition H264Decoder.h:15
H264DecoderProps(uint _lowerWaterMark=300, uint _upperWaterMark=350)
Definition H264Decoder.h:9
uint lowerWaterMark
Definition H264Decoder.h:14
Definition H264Decoder.cpp:18
Definition H264Decoder.h:19
void sendDecodedFrame()
Definition H264Decoder.cpp:512
bool resumeBwdPlayback
Definition H264Decoder.h:85
std::deque< frame_sp > latestBackwardGop
Definition H264Decoder.h:54
void flushQue()
Definition H264Decoder.cpp:745
void bufferBackwardEncodedFrames(frame_sp &frame, short naluType)
Definition H264Decoder.cpp:198
void decodeFrameFromBwdGOP()
Definition H264Decoder.cpp:321
float playbackSpeed
Definition H264Decoder.h:81
virtual ~H264Decoder()
Definition H264Decoder.cpp:101
void bufferAndDecodeForwardEncodedFrames(frame_sp &frame, short naluType)
Definition H264Decoder.cpp:220
bool shouldTriggerSOS()
Definition H264Decoder.cpp:729
void saveSpsPps(frame_sp frame)
Definition H264Decoder.cpp:353
bool dirChangedToFwd
Definition H264Decoder.h:62
boost::shared_ptr< Detail > mDetail
Definition H264Decoder.h:43
bool mShouldTriggerSOS
Definition H264Decoder.h:44
int previousFps
Definition H264Decoder.h:80
std::string mOutputPinId
Definition H264Decoder.h:46
bool term()
Definition H264Decoder.cpp:156
void dropFarthestFromCurrentTs(uint64_t ts)
Definition H264Decoder.cpp:587
framemetadata_sp mOutputMetadata
Definition H264Decoder.h:45
bool resumePlayback
Definition H264Decoder.h:86
bool processSOS(frame_sp &frame)
Definition H264Decoder.cpp:651
std::deque< std::deque< frame_sp > > backwardGopBuffer
Definition H264Decoder.h:52
std::map< uint64, frame_sp > decodedFramesCache
Definition H264Decoder.h:59
bool prevFrameInCache
Definition H264Decoder.h:66
bool processEOS(string &pinId)
Definition H264Decoder.cpp:734
int incomingFramesTSQSize
Definition H264Decoder.h:87
bool foundIFrameOfReverseGop
Definition H264Decoder.h:64
bool handleCommand(Command::CommandType type, frame_sp &frame)
Definition H264Decoder.cpp:678
int currentFps
Definition H264Decoder.h:79
bool dirChangedToBwd
Definition H264Decoder.h:63
std::deque< uint64_t > incomingFramesTSQ
Definition H264Decoder.h:68
bool decodePreviousFramesOfTheForwardGop
Definition H264Decoder.h:65
std::deque< frame_sp > latestForwardGop
Definition H264Decoder.h:58
bool validateInputPins()
Definition H264Decoder.cpp:103
boost::asio::const_buffer spsBuffer
Definition H264Decoder.h:74
bool process(frame_container &frames)
Definition H264Decoder.cpp:370
int gop
Definition H264Decoder.h:82
H264Decoder(H264DecoderProps _props)
Definition H264Decoder.cpp:90
void clearIncompleteBwdGopTsFromIncomingTSQ(std::deque< frame_sp > &latestGop)
Definition H264Decoder.cpp:185
std::mutex m
Definition H264Decoder.h:76
void bufferDecodedFrames(frame_sp &frame)
Definition H264Decoder.cpp:582
int iFramesToSkip
Definition H264Decoder.h:78
void addInputPin(framemetadata_sp &metadata, string &pinId)
Definition H264Decoder.cpp:142
uint64_t lastFrameSent
Definition H264Decoder.h:83
bool mDirection
Definition H264Decoder.h:61
boost::asio::const_buffer ppsBuffer
Definition H264Decoder.h:75
void * prependSpsPps(frame_sp &iFrame, size_t &spsPpsFrameSize)
Definition H264Decoder.cpp:166
bool validateOutputPins()
Definition H264Decoder.cpp:123
int framesToSkip
Definition H264Decoder.h:77
frame_sp mHeaderFrame
Definition H264Decoder.h:73
H264DecoderProps mProps
Definition H264Decoder.h:47
bool init()
Definition H264Decoder.cpp:147
bool resumeFwdPlayback
Definition H264Decoder.h:84
Definition Module.h:33
Definition Module.h:151