一、概述

  • NetEqImpl类实现的功能有:

  1. 音频冗余报文解析
  2. nack报文请求
  3. 音频jitterbuffer
  4. 音频变速算法功能
  • 该类对外的关键接口有:

  1. NetEqImpl::InsertPacket:输入音频RTP报文
  2. NetEqImpl::GetAudio:音频渲染模块定时要音频报文
  3. std::vector<uint16_t> GetNackList(int64_t round_trip_time_ms):输出需要nack重传的报文序列号

二、代码详解 

  • NetEqImpl::InsertPacket

     核心函数调用关系如下:

NetEqImpl::InsertPacket
->NetEqImpl::InsertPacketInternal
->PacketBuffer::InsertPacketList
->PacketBuffer::InsertPacket
->buffer_.insert(it, std::move(packet));  // Insert the packet at that position.

该函数的主要目的是把报文存储到PacketBuffer对象的buffer_中。

需要注意buffer_结构体的std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame参数:

struct Packet {
  struct Priority {
    Priority() : codec_level(0), red_level(0) {}
    Priority(int codec_level, int red_level)
        : codec_level(codec_level), red_level(red_level) {
      CheckInvariant();
    }
  //...
  }

  uint32_t timestamp;
  uint16_t sequence_number;
  uint8_t payload_type;
  // Datagram excluding RTP header and header extension.
  rtc::Buffer payload;
  Priority priority;
  RtpPacketInfo packet_info;
  std::unique_ptr<TickTimer::Stopwatch> waiting_time;
  std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame;

  //......
};

 std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame里面挂了解码器的句柄,就是说每个报文都指定了自己的解码器句柄。

收包入队函数里面,会调用:

std::unique_ptr<NackTracker> nack_:更新收包信息,便于确定需要nack重传的报文。

std::unique_ptr<StatisticsCalculator> stats_:更新报文之间时间间隔,用于确定jitterbuffer缓存时间。

  • NetEqImpl::GetAudio

关键函数处理说明: 

NetEqImpl::ExtractPackets:获取RTP报文,待解码

 packet_list->front().frame->Decode进行音频解码

 

封装输出音频PCM帧数据。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐