-
Notifications
You must be signed in to change notification settings - Fork 32
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
enhance H264EncoderNvCodec by adding a buffer threshold property #360
Open
kushaljain-apra
wants to merge
2
commits into
main
Choose a base branch
from
ks/enhanceH264EncoderNvCodec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,14 @@ class H264EncoderNVCodec::Detail | |
public: | ||
Detail(H264EncoderNVCodecProps &_props) : mProps(_props) | ||
{ | ||
helper.reset(new H264EncoderNVCodecHelper(_props.bitRateKbps, _props.cuContext,_props.gopLength,_props.frameRate,_props.vProfile,_props.enableBFrames)); | ||
if(_props.bufferThres == 30) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add it to #define instead of hard coding |
||
{ | ||
helper.reset(new H264EncoderNVCodecHelper(_props.bitRateKbps, _props.cuContext,_props.gopLength,_props.frameRate,_props.vProfile,_props.enableBFrames)); | ||
} | ||
else | ||
{ | ||
helper.reset(new H264EncoderNVCodecHelper(_props.bitRateKbps, _props.cuContext,_props.gopLength,_props.frameRate,_props.vProfile,_props.enableBFrames,_props.bufferThres)); | ||
} | ||
} | ||
|
||
~Detail() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,7 +204,7 @@ class H264EncoderNVCodecHelper::Detail | |
} | ||
} | ||
public: | ||
Detail(uint32_t& bitRateKbps, apracucontext_sp& cuContext, uint32_t& gopLength, uint32_t& frameRate,H264EncoderNVCodecProps::H264CodecProfile profile,bool enableBFrames) : | ||
Detail(uint32_t& bitRateKbps, apracucontext_sp& cuContext, uint32_t& gopLength, uint32_t& frameRate,H264EncoderNVCodecProps::H264CodecProfile profile,bool enableBFrames, uint32_t& bufferThres) : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we Have Limit on Max Buffer Threshold, or it can be any |
||
m_nWidth(0), | ||
m_nHeight(0), | ||
m_eBufferFormat(NV_ENC_BUFFER_FORMAT_UNDEFINED), | ||
|
@@ -214,7 +214,8 @@ class H264EncoderNVCodecHelper::Detail | |
m_nGopLength(gopLength), | ||
m_nFrameRate(frameRate), | ||
m_nProfile(profile), | ||
m_bEnableBFrames(enableBFrames) | ||
m_bEnableBFrames(enableBFrames), | ||
m_nBufferThres(bufferThres) | ||
{ | ||
m_nvcodecResources.reset(new NVCodecResources(cuContext)); | ||
|
||
|
@@ -574,7 +575,15 @@ class H264EncoderNVCodecHelper::Detail | |
|
||
bool is_not_empty() const | ||
{ | ||
if (!m_nvcodecResources->m_nFreeOutputBitstreams) | ||
uint32_t busyStreams = m_nvcodecResources->m_nBusyOutputBitstreams; | ||
if (!m_nvcodecResources->m_nFreeOutputBitstreams && busyStreams < m_nBufferThres) | ||
{ | ||
uint32_t bufferLength = min(busyStreams, m_nBufferThres - busyStreams); | ||
doubleOutputBuffers(bufferLength); | ||
LOG_INFO << "Allocated <" << bufferLength << "> outputbitstreams to the encoder buffer."; | ||
m_nvcodecResources->m_nFreeOutputBitstreams += bufferLength; | ||
} | ||
else | ||
{ | ||
LOG_INFO << "waiting for free outputbitstream<> busy streams<" << m_nvcodecResources->m_nBusyOutputBitstreams << ">"; | ||
} | ||
|
@@ -587,6 +596,16 @@ class H264EncoderNVCodecHelper::Detail | |
return m_nvcodecResources->m_nBusyOutputBitstreams > 0 || !m_bRunning; | ||
} | ||
|
||
void doubleOutputBuffers(uint32_t bufferLength) const | ||
{ | ||
for (int i = 0; i < bufferLength; i++) | ||
{ | ||
NV_ENC_CREATE_BITSTREAM_BUFFER createBitstreamBuffer = { NV_ENC_CREATE_BITSTREAM_BUFFER_VER }; | ||
NVENC_API_CALL(m_nvcodecResources->m_nvenc.nvEncCreateBitstreamBuffer(m_nvcodecResources->m_hEncoder, &createBitstreamBuffer)); | ||
m_nvcodecResources->m_qBitstreamOutputBitstream.push_back(createBitstreamBuffer.bitstreamBuffer); | ||
} | ||
} | ||
|
||
std::thread m_thread; | ||
bool m_bRunning; | ||
|
||
|
@@ -600,6 +619,7 @@ class H264EncoderNVCodecHelper::Detail | |
uint32_t m_nFrameRate; | ||
H264EncoderNVCodecProps::H264CodecProfile m_nProfile; | ||
bool m_bEnableBFrames; | ||
uint32_t m_nBufferThres; | ||
|
||
NV_ENC_INITIALIZE_PARAMS m_initializeParams; | ||
NV_ENC_CONFIG m_encodeConfig; | ||
|
@@ -621,7 +641,13 @@ class H264EncoderNVCodecHelper::Detail | |
|
||
H264EncoderNVCodecHelper::H264EncoderNVCodecHelper(uint32_t _bitRateKbps, apracucontext_sp& _cuContext, uint32_t _gopLength, uint32_t _frameRate, H264EncoderNVCodecProps::H264CodecProfile _profile, bool enableBFrames) | ||
{ | ||
mDetail.reset(new Detail(_bitRateKbps, _cuContext,_gopLength,_frameRate,_profile,enableBFrames)); | ||
uint32_t _bufferThres = 30; | ||
mDetail.reset(new Detail(_bitRateKbps, _cuContext,_gopLength,_frameRate,_profile,enableBFrames,_bufferThres)); | ||
} | ||
|
||
H264EncoderNVCodecHelper::H264EncoderNVCodecHelper(uint32_t _bitRateKbps, apracucontext_sp& _cuContext, uint32_t _gopLength, uint32_t _frameRate, H264EncoderNVCodecProps::H264CodecProfile _profile, bool enableBFrames, uint32_t _bufferThres) | ||
{ | ||
mDetail.reset(new Detail(_bitRateKbps, _cuContext,_gopLength,_frameRate,_profile,enableBFrames,_bufferThres)); | ||
} | ||
|
||
H264EncoderNVCodecHelper::~H264EncoderNVCodecHelper() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some basic documentation