美文网首页
jitter_buffer之PacketBuffer

jitter_buffer之PacketBuffer

作者: lssaint | 来源:发表于2020-04-28 09:30 被阅读0次

PacketBuffer (位于webrtc\modules\video_coding)
新版的webrtc已经弃用了以前的VCMJitterBuffer类
主要函数:
virtual bool InsertPacket(VCMPacket* packet);
void ClearTo(uint16_t seq_num);
void Clear();
void PaddingReceived(uint16_t seq_num);

 VCMPacket :应该是video coding model packet 的缩写,用于视频包。
 InsertPacket函数:
 bool PacketBuffer::InsertPacket(VCMPacket* packet);
//packet 里的数据是rtp数据

//源码实现

{
    //完整的数据帧,例如:h264 
   std::vector<std::unique_ptr<CRtpFrameObject>> found_frames;
  {
       MiniBase::CGurd lock(&crit_);
       uint16_t seq_num = packet->seqNum;
      size_t index = seq_num % nTotalSize_;
      //如果是第一个包
     if (!first_packet_received_) 
     {
            first_seq_num_ = seq_num;
            first_packet_received_ = true;
      }
      ////判断first_seq_num_是否在seq_num之前,如果是返回false;
      else if (AheadOf(first_seq_num_, seq_num)) 
     {
                  uint16_t old_seq_num = first_seq_num_ - kMaxPaddingAge;
                // If we have explicitly cleared past this packet then it's old,
               // don't insert it.
              if (is_cleared_to_first_seq_num_) 
              {
                    delete[] packet->dataPtr;
                    packet->dataPtr = nullptr;
                     return false;
             }
             first_seq_num_ = seq_num;
     }
    if (sequence_buffer_[index].used)
    {
                  // Duplicate packet, just delete the payload.
                 if (data_buffer_[index].seqNum == packet->seqNum) 
                 {
                          delete[] packet->dataPtr;
                           packet->dataPtr = nullptr;
                          return true;
                 }

                 // The packet buffer is full, try to expand the buffer.
                 // 在队列中寻找缓冲,如果缓冲已经满了,则扩充
                while (ExpandBufferSize() && sequence_buffer_[seq_num % nTotalSize_].used)
                {

                }
              // 删除旧的数据
               if (sequence_buffer_[index].used)
               {
                       delete[] packet->dataPtr;
                       packet->dataPtr = nullptr;
                      return false;
                }
     }
   sequence_buffer_[index].frame_begin = packet->is_first_packet_in_frame;
   sequence_buffer_[index].frame_end = packet->markerBit;
  sequence_buffer_[index].seq_num = packet->seqNum;
  sequence_buffer_[index].continuous = false;
  sequence_buffer_[index].frame_created = false;
  sequence_buffer_[index].used = true;
  data_buffer_[index] = *packet;
  packet->dataPtr = nullptr;
  //更新丢包列表,注意nack请求再NackModule里
  UpdateMissingPackets(packet->seqNum);
  int64_t now_ms = m_pClock_->TimeInMilliseconds();
  last_received_packet_ms_ = MiniBase::Optional<int64_t>(now_ms);
  //更新最后接收关键帧的时间
  if (packet->frameType == kVFrameKey)
    last_received_keyframe_packet_ms_ = MiniBase::Optional<int64_t>(now_ms);
  //查找收到的帧
   found_frames = FindFrames(seq_num);
 }
 //完整的数据,通知回调
  for (std::unique_ptr<CRtpFrameObject>& frame : found_frames)
     received_frame_callback_->OnReceivedFrame(std::move(frame));
  return true;
}

相关文章

  • jitter_buffer之PacketBuffer

    见这里

  • jitter_buffer之PacketBuffer

    PacketBuffer (位于webrtc\modules\video_coding)新版的webrtc已经弃用...

  • 十之

    博学之,审问之,慎思之,明辨之,笃行之。 励志之,健身之,涅槃之,弘毅之,自强之!

  • 读记|唐诗人:诗心煎红尘(二)

    愈之挫之 险之退之 借之济之 忠之犯之 勇之夺之 衰之立之 坚之韧之 载之言之 一代宗师 成之传之 字曰子厚 道解...

  • 《寄君归》

    思之念之 见之不忘 吾亦求之 求之不得 吾亦念之 兮之盼之 来之归之 欲予离之 得之兮之 心思念之 盼来归之 归之...

  • 飘零

    艾雪儿 难耐心中怦然之 抑之,控之,思之,忘之 能否任之,弃之,拥之,念之 山河为鉴 赴之,游之,悦之,相守之…

  • 《美》

    刚之美,软之美,善之美,心之美。 水之美,声之美,爱之美,景之美,笑之美,物之美,月之美。 仁之美,慈之美,德之美...

  • 众说纷云

    众说纷云 文‖曾之一 20200220 古人说 真之假之善之恶之美之丑之 今人说 真之假之善之恶之美之丑之 后人说...

  • 安沨

    博学之,审问之,慎思之,明辨之,笃行之。

  • 2019-01-13

    博学之、明辨之、慎思之、审问之、笃行之

网友评论

      本文标题:jitter_buffer之PacketBuffer

      本文链接:https://www.haomeiwen.com/subject/fklkyhtx.html