Make first frame for each connection into I frame

This commit is contained in:
dijunkun
2023-10-07 15:32:06 +08:00
parent bf4f5ca87d
commit e2e2fb53ae
3 changed files with 10 additions and 1 deletions

View File

@@ -139,4 +139,4 @@ int FFmpegVideoEncoder::OnEncodedImage(char *encoded_packets, size_t size) {
return 0;
}
void FFmpegVideoEncoder::ForceIdr() {}
void FFmpegVideoEncoder::ForceIdr() { frame_->pict_type = AV_PICTURE_TYPE_I; }

View File

@@ -94,6 +94,7 @@ int PeerConnection::Init(PeerConnectionParams params,
on_ice_status_change_ = [this](std::string ice_status) {
if ("JUICE_STATE_COMPLETED" == ice_status) {
ice_ready_ = true;
b_force_i_frame_ = true;
LOG_INFO("Ice finish");
} else {
ice_ready_ = false;
@@ -368,6 +369,12 @@ int PeerConnection::SendVideoData(const char *data, size_t size) {
return -1;
}
if (b_force_i_frame_) {
video_encoder_->ForceIdr();
LOG_INFO("Force I frame");
b_force_i_frame_ = false;
}
int ret = video_encoder_->Encode(
(uint8_t *)data, size, [this](char *encoded_frame, size_t size) -> int {
for (auto &ice_trans : ice_transmission_list_) {
@@ -377,6 +384,7 @@ int PeerConnection::SendVideoData(const char *data, size_t size) {
}
return 0;
});
if (0 != ret) {
LOG_ERROR("Encode failed");
return -1;

View File

@@ -104,6 +104,7 @@ class PeerConnection {
std::unique_ptr<VideoDecoder> video_decoder_ = nullptr;
bool hardware_accelerated_encode_ = false;
bool hardware_accelerated_decode_ = false;
bool b_force_i_frame_ = false;
};
#endif