Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H.264 Reverse play #295

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 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,10 +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;
};

/* 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();
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);
void* prependSpsPps(frame_sp& iFrame, size_t& spsPpsFrameSize);
void dropFarthestFromCurrentTs(uint64_t ts);
frame_sp mHeaderFrame;
boost::asio::const_buffer spsBuffer;
boost::asio::const_buffer ppsBuffer;
};
5 changes: 4 additions & 1 deletion base/include/H264Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ 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
Loading