Skip to content

Commit

Permalink
H264 reverse play working - all test cases passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammedzakikochargi committed Sep 12, 2023
1 parent aaab868 commit 050db87
Show file tree
Hide file tree
Showing 11 changed files with 994 additions and 211 deletions.
54 changes: 40 additions & 14 deletions base/include/H264Decoder.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#pragma once

#include "Module.h"
#include <vector>

class H264DecoderProps : public ModuleProps
{
public:
H264DecoderProps() {}
H264DecoderProps(uint _lowerWaterMark = 300, uint _upperWaterMark = 350)
{
lowerWaterMark = _lowerWaterMark;
upperWaterMark = _upperWaterMark;
}
uint lowerWaterMark;
uint upperWaterMark;
};

class H264Decoder : public Module
Expand All @@ -26,23 +33,42 @@ class H264Decoder : public Module
bool shouldTriggerSOS();

private:
void bufferDecodedFrames(frame_sp& frame);
void bufferBackwardEncodedFrames(frame_sp& frame, short naluType);
void bufferAndDecodeForwardEncodedFrames(frame_sp& frame, short naluType);

class Detail;
boost::shared_ptr<Detail> mDetail;
bool mShouldTriggerSOS;
framemetadata_sp mOutputMetadata;
std::string mOutputPinId;
H264DecoderProps mProps;
void bufferDecodedFrames(frame_sp& frame);
void bufferEncodedFrames(frame_sp& frame);
std::deque<std::pair<std::deque<frame_sp>, bool>> gop;
std::deque<frame_sp> tempGop ;
std::deque<std::deque<frame_sp>> bufferedDecodedFrames;
std::deque<frame_sp> tempDecodedFrames;
std::queue<std::pair<uint, bool>> framesInGopAndDirectionTracker;

/* Used to buffer multiple complete GOPs
note that we decode frames from this queue in reverse play*/
std::deque<std::deque<frame_sp>> backwardGopBuffer;
/* buffers the incomplete GOP */
std::deque<frame_sp> latestBackwardGop;
/* It buffers only one latest GOP
used in cases where partial GOP maybe in cache and rest of the GOP needs to be decoded
note that since there is no buffering in forward play, we directly decode frames from module queue*/
std::deque<frame_sp> latestForwardGop;
std::map<uint64, frame_sp> decodedFramesCache;
void sendDecodedFrame();
uint framesCounterOfCurrentGop = 0;
bool hasDirectionChangedToForward = false;
bool hasDirectionChangedToBackward = false;
bool foundGopIFrame = false;
void sendFramesToDecoder();
};
bool mDirection;
bool dirChangedToFwd = false;
bool dirChangedToBwd = false;
bool foundIFrameOfReverseGop = false;
bool flushDecoderFlag = false;
bool decodePreviousFramesOfTheForwardGop = false;
bool prevFrameInCache = false;
void decodeFrameFromBwdGOP();
std::deque<uint64_t> incomingFramesTSQ;
void clearIncompleteBwdGopTsFromIncomingTSQ(std::deque<frame_sp>& latestGop);
void saveSpsPps(frame_sp frame);
frame_sp prependSpsPps(frame_sp& iFrame);
void dropFarthestFromCurrentTs(uint64_t ts);
frame_sp mHeaderFrame;
boost::asio::const_buffer spsBuffer;
boost::asio::const_buffer ppsBuffer;
};
2 changes: 2 additions & 0 deletions base/include/H264Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class H264Metadata : public FrameMetadata
width = metadata.width;
height = metadata.height;
direction = metadata.direction;
mp4Seek = metadata.mp4Seek;
//setDataSize();
}
bool direction = true;
bool mp4Seek = false;
protected:
void initData(int _width, int _height, MemType _memType = MemType::HOST)
{
Expand Down
Loading

0 comments on commit 050db87

Please sign in to comment.