@@ -90,7 +90,8 @@ namespace webrtc
90
90
nvEncConfig.profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
91
91
nvEncConfig.gopLength = nvEncInitializeParams.frameRateNum ;
92
92
nvEncConfig.rcParams .rateControlMode = NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ;
93
- nvEncConfig.rcParams .averageBitRate = (static_cast <unsigned int >(5 .0f *
93
+ nvEncConfig.rcParams .averageBitRate =
94
+ (static_cast <unsigned int >(5 .0f *
94
95
nvEncInitializeParams.encodeWidth *
95
96
nvEncInitializeParams.encodeHeight ) / (m_width * m_height)) * 100000 ;
96
97
nvEncConfig.encodeCodecConfig .h264Config .idrPeriod = nvEncConfig.gopLength ;
@@ -107,19 +108,18 @@ namespace webrtc
107
108
capsParam.capsToQuery = NV_ENC_CAPS_ASYNC_ENCODE_SUPPORT;
108
109
int32 asyncMode = 0 ;
109
110
errorCode = pNvEncodeAPI->nvEncGetEncodeCaps (pEncoderInterface, nvEncInitializeParams.encodeGUID , &capsParam, &asyncMode);
110
- checkf (NV_RESULT (errorCode), StringFormat (" Failded to get NVEncoder capability params %d" , errorCode).c_str ());
111
+ checkf (NV_RESULT (errorCode), StringFormat (" Failed to get NVEncoder capability params %d" , errorCode).c_str ());
111
112
nvEncInitializeParams.enableEncodeAsync = 0 ;
112
113
#pragma endregion
113
114
#pragma region initialize hardware encoder session
114
115
errorCode = pNvEncodeAPI->nvEncInitializeEncoder (pEncoderInterface, &nvEncInitializeParams);
115
116
result = NV_RESULT (errorCode);
116
117
checkf (result, StringFormat (" Failed to initialize NVEncoder %d" , errorCode).c_str ());
117
118
#pragma endregion
118
-
119
119
InitEncoderResources ();
120
120
m_isNvEncoderSupported = true ;
121
-
122
121
}
122
+
123
123
NvEncoder::~NvEncoder ()
124
124
{
125
125
ReleaseEncoderResources ();
@@ -205,7 +205,7 @@ namespace webrtc
205
205
{
206
206
if (s_hModule)
207
207
{
208
- #if _WIN32
208
+ #if defined( _WIN32)
209
209
FreeLibrary ((HMODULE)s_hModule);
210
210
#else
211
211
dlclose (s_hModule);
@@ -242,10 +242,6 @@ namespace webrtc
242
242
}
243
243
}
244
244
245
- constexpr double kLowRateFactor = 1.0 ;
246
- constexpr double kHighRateFactor = 2.0 ;
247
-
248
-
249
245
void NvEncoder::SetRates (uint32_t bitRate, int64_t frameRate)
250
246
{
251
247
m_frameRate = frameRate;
@@ -269,14 +265,6 @@ namespace webrtc
269
265
UpdateSettings ();
270
266
uint32 bufferIndexToWrite = frameCount % bufferedFrameNum;
271
267
Frame& frame = bufferedFrames[bufferIndexToWrite];
272
- #pragma region set frame params
273
- // no free buffer, skip this frame
274
- if (frame.isEncoding )
275
- {
276
- return false ;
277
- }
278
- frame.isEncoding = true ;
279
- #pragma endregion
280
268
#pragma region configure per-frame encode parameters
281
269
NV_ENC_PIC_PARAMS picParams = { 0 };
282
270
picParams.version = NV_ENC_PIC_PARAMS_VER;
@@ -305,12 +293,6 @@ namespace webrtc
305
293
// get encoded frame
306
294
void NvEncoder::ProcessEncodedFrame (Frame& frame)
307
295
{
308
- // The frame hasn't been encoded, something wrong
309
- if (!frame.isEncoding )
310
- {
311
- return ;
312
- }
313
- frame.isEncoding = false ;
314
296
#pragma region retrieve encoded frame from output buffer
315
297
NV_ENC_LOCK_BITSTREAM lockBitStream = { 0 };
316
298
lockBitStream.version = NV_ENC_LOCK_BITSTREAM_VER;
@@ -325,14 +307,15 @@ namespace webrtc
325
307
}
326
308
errorCode = pNvEncodeAPI->nvEncUnlockBitstream (pEncoderInterface, frame.outputFrame );
327
309
checkf (NV_RESULT (errorCode), StringFormat (" Failed to unlock bit stream, error is %d" , errorCode).c_str ());
328
- frame.isIdrFrame = lockBitStream.pictureType == NV_ENC_PIC_TYPE_IDR;
329
310
#pragma endregion
330
- rtc::scoped_refptr<FrameBuffer> buffer = new rtc::RefCountedObject<FrameBuffer>(m_width, m_height, frame.encodedFrame , m_encoderId);
331
-
311
+ const rtc::scoped_refptr<FrameBuffer> buffer =
312
+ new rtc::RefCountedObject<FrameBuffer>(
313
+ m_width, m_height, frame.encodedFrame , m_encoderId);
332
314
const int64_t timestamp_us = m_clock->TimeInMicroseconds ();
333
315
const int64_t now_us = rtc::TimeMicros ();
334
316
const int64_t translated_camera_time_us =
335
- timestamp_aligner_.TranslateTimestamp (timestamp_us,
317
+ timestamp_aligner_.TranslateTimestamp (
318
+ timestamp_us,
336
319
now_us);
337
320
338
321
webrtc::VideoFrame::Builder builder =
0 commit comments