用webrtc直播拉流比传统的rtmp方式延迟要低,能控制延迟在1s之内,基于M76版本的webrtc在拉h264的流时,如果码率和分辨率比较大,加上网络不好的话,会出现花屏问题。
webrtc的组帧写的很有意思,每来一个包检测是否满足组帧条件具体代码如下
bool PacketBuffer::PotentialNewFrame(uint16_t seq_num) const {
size_t index = seq_num % size_;
int prev_index = index > 0 ? index - 1 : size_ - 1;
if (!sequence_buffer_[index].used)
return false;
if (sequence_buffer_[index].seq_num != seq_num)
return false;
if (sequence_buffer_[index].frame_created)
return false;
if (sequence_buffer_[index].frame_begin)
return true;
if (!sequence_buffer_[prev_index].used)
return false;
if (sequence_buffer_[prev_index].frame_created)
return false;
if (sequence_buffer_[prev_index].seq_num !=
static_cast<uint16_t>(sequence_buffer_[index].seq_num - 1)) {
return false;
}
if (data_buffer_[prev_index].timestamp != data_buffer_[index].timestamp)
return false;
if (sequence_buffer_[pr