Skip to content

Instantly share code, notes, and snippets.

@happyj2me
Last active February 9, 2023 12:30
Show Gist options
  • Save happyj2me/a82a26f4279a1a8d51902abf2e5c8d71 to your computer and use it in GitHub Desktop.
Save happyj2me/a82a26f4279a1a8d51902abf2e5c8d71 to your computer and use it in GitHub Desktop.
1. 输入编码器的帧率,分辨率控制
PeerConnectionClient.java::createVideoTrack方法里面 加入一行 changeCaptureFormat(videoWidth,videoHeight,videoFps);
2. 编码器目标码率设置
PeerConnectionClient.java::onLocalDescription方法里面,调用setVideoMaxBitrate方法进行设置,该方法主体如下:
RtpParameters parameters = localVideoSender.getParameters();
if (parameters.encodings.size() == 0) {
Log.w(TAG, "RtpParameters are not ready.");
return;
}
for (RtpParameters.Encoding encoding : parameters.encodings) {
// Null value means no limit.
encoding.maxBitrateBps = maxBitrateKbps == null ? null : maxBitrateKbps * BPS_IN_KBPS;
}
if (!localVideoSender.setParameters(parameters)) {
Log.e(TAG, "RtpSender.setParameters failed.");
}
Log.d(TAG, "Configured max video bitrate to: " + maxBitrateKbps);
3.最低分辨率设置位置: video_encoder.h
int min_pixels_per_frame = 320 * 180;
4.帧率分辨率动态调整位置:video_stream_encoder.cc
最低帧率控制: const int kMinFramerateFps = 2;
帧率升降幅度: 2/3
分辨率升降幅度: 3/5
5.首帧丢弃原则,和编码器的启动码率有关
bool VideoStreamEncoder::DropDueToSize(uint32_t pixel_count) const {
if (initial_framedrop_ < kMaxInitialFramedrop &&
encoder_start_bitrate_bps_ > 0) {
if (encoder_start_bitrate_bps_ < 300000 /* qvga */) {
return pixel_count > 320 * 240;
} else if (encoder_start_bitrate_bps_ < 500000 /* vga */) {
return pixel_count > 640 * 480;
}
}
return false;
}
3.linux版本启动码率初始值相关配置
peer_connection_factory.cc::CreateCall_w
const int kMinBandwidthBps = 30000;
const int kStartBandwidthBps = 300000;
const int kMaxBandwidthBps = 2000000;
6.编码器启动码率设置
struct BitrateConstraints {
int min_bitrate_bps = 0;
int start_bitrate_bps = kDefaultStartBitrateBps;
int max_bitrate_bps = -1;
private:
static constexpr int kDefaultStartBitrateBps = 600000; //默认是300kbps
};
7.编码器初始最大码率设置
static int GetMaxDefaultVideoBitrateKbps(int width,
int height,
bool is_screenshare) {
int max_bitrate;
if (width * height <= 320 * 240) {
max_bitrate = 600;
} else if (width * height <= 640 * 480) {
max_bitrate = 1700;
} else if (width * height <= 960 * 540) {
max_bitrate = 2000;
} else {
max_bitrate = 2500;
}
if (is_screenshare)
max_bitrate = std::max(max_bitrate, 1200);
return max_bitrate;
}
webrtc抗丢包方法配置:NACK_ONLY 或者 FEC_ONLY 或者 NACK + FEC 或者 KNONE
配置位置: VCMLossProtectionLogic::SetMethod
3. svc vs simulticast
https://webrtchacks.com/sfu-simulcast/
https://www.meetecho.com/blog/simulcast-janus-ssrc/
4. 接收端如果没有收到关键帧,会立马请求:RtpVideoStreamReceiver::OnAssembledFrame
// Request a key frame as soon as possible.
if (!has_received_frame_) {
has_received_frame_ = true;
if (frame->FrameType() != VideoFrameType::kVideoFrameKey) {
// TODO(bugs.webrtc.org/10336): Allow the sender to ignore these messages
// if it is relying on LNTF alone.
RequestKeyFrame();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment