马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
目次
- 1.视频流发送(VideoSendStream)
- 1.1 质量限定(QualityLimitationReason)
- 1.2 RTP设置项(RtpConfig)
- 1.3 视频流编码器设置项(VideoStreamEncoderSettings)
- 1.4 传输(Transport)
- 2.视频流发送实现(VideoSendStreamImpl)
- 2.1 码率分配监测器(BitrateAllocatorObserver)
- 2.2 编码罗致器(VideoStreamEncoderInterface::EncoderSink)
- 3.RTP视频发送器(RtpVideoSender)
- 4.RTP发送视频(RTPSenderVideo)
- 4.1 RTPSenderVideo::SendEncodedImage()
- 4.2 RTPSenderVideo::SendVideo
- 4.3 RTPSenderVideo:
ogAndSendToNetwork
- 5.RTP发送器(RTPSender)
视频流在收罗编码之后,必要通过RTP协议举行发送,下面纪录与视频流发送干系的一些类的声明,梳理视频流发送过程中,差异类的继续关系
1.视频流发送(VideoSendStream)
WebRTC中将已编码视频帧传送出去的类为VideoSendStream,其声明位于call/video_send_stream.h中,这个类声明的初志为一个基类,此中声明白一系列视频流发送的纯虚函数,以及视频流发送状态和设置干系的变量。大抵的内容包罗:
(1)视频流的状态(范例,长宽,延时,帧率,帧数,码率等)
(2)发送器状态(编码实例名称,输入帧率,编码帧率,帧数,丢帧数,质量限定等)
(3)发送器设置项(RTP设置项,数据包传输,带宽测试等)
(4)发送器函数(发送,克制,添加资源,天生关键帧)
视频流的范例分为3类,kMedia是利用RTP协议传输的正常流,kRtx(Retransmission)是重传流,kFlexfec专门用于Flexfec。视频流状态当中的帧干系信息,与发送器状态当中的帧干系不完全划一,由于发送器还要思量带宽,拥塞控制等标题,大概会举行丢包或质量限定,二者应该是在动态厘革中形成划一。
视频发送的流程大抵为:设置发送器,获取已编码帧信息,开启发送器,发送帧,关闭发送器
- class VideoSendStream {
- public:
- // Multiple StreamStats objects are present if simulcast is used (multiple
- // kMedia streams) or if RTX or FlexFEC is negotiated. Multiple SVC layers, on
- // the other hand, does not cause additional StreamStats.
- /*
- 如果使用了Simulcast(多个kMedia流),或者协商了RTX或FlexFEC,
- 就会出现多个StreamStats对象。另一方面,多个SVC层并不会导致额外的StreamStats
- PS:
- Simulcast表示可以对外传输多个视频流,每个视频流的分辨率和码率不同,以适应不同的用户群体或网络条件
- 其实现方式为,使用多个编码实例对同一个视频源,按照不同编码策略进行编码,每条流都有独特的SSRC
- */
- struct StreamStats {
- enum class StreamType {
- // A media stream is an RTP stream for audio or video. Retransmissions and
- // FEC is either sent over the same SSRC or negotiated to be sent over
- // separate SSRCs, in which case separate StreamStats objects exist with
- // references to this media stream's SSRC.
- /*
- 一个媒体流是用于音频或视频的RTP流。重传和FEC(前向纠错)可以通过相同的SSRC发送,
- 或者协商后通过不同的SSRC发送,在后一种情况下,会存在引用这个媒体流SSRC的独立StreamStats对象
- */
- kMedia,
- // RTX streams are streams dedicated to retransmissions. They have a
- // dependency on a single kMedia stream: `referenced_media_ssrc`.
- /*
- RTX流是专门用于重传的流。它们依赖于单个kMedia流:`referenced_media_ssrc`
- */
- kRtx,
- // FlexFEC streams are streams dedicated to FlexFEC. They have a
- // dependency on a single kMedia stream: `referenced_media_ssrc`.
- /*
- FlexFEC流是专门用于FlexFEC的流。它们依赖于单个kMedia流:`referenced_media_ssrc`
- */
- kFlexfec,
- };
- StreamStats();
- ~StreamStats();
- std::string ToString() const;
- StreamType type = StreamType::kMedia;
- // If `type` is kRtx or kFlexfec this value is present. The referenced SSRC
- // is the kMedia stream that this stream is performing retransmissions or
- // FEC for. If `type` is kMedia, this value is null.
- /*
- 如果`type`是kRtx或kFlexfec,这个值是存在的。被引用的SSRC是这个流正在执行重传
- 或FEC的kMedia流。如果`type`是kMedia,这个值是空的
- */
- std::optional<uint32_t> referenced_media_ssrc;
- // 帧数量
- FrameCounts frame_counts;
- // 宽度
- int width = 0;
- // 高度
- int height = 0;
- // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer.
- // 整体码率
- int total_bitrate_bps = 0;
- // 重传比特率
- int retransmit_bitrate_bps = 0;
- // `avg_delay_ms` and `max_delay_ms` are only used in tests. Consider
- // deleting.
- // 平均延时
- int avg_delay_ms = 0;
- // 最大延时
- int max_delay_ms = 0;
- // 用于RTP数据统计
- StreamDataCounters rtp_stats;
- // 用于RTCP包类型的数据统计
- RtcpPacketTypeCounter rtcp_packet_type_counts;
- // A snapshot of the most recent Report Block with additional data of
- // interest to statistics. Used to implement RTCRemoteInboundRtpStreamStats.
- // 一个包含对统计数据感兴趣的额外信息的最新报告块的快照。用于实现`RTCRemoteInboundRtpStreamStats`
- std::optional<ReportBlockData> report_block_data;
- // 编码帧率
- double encode_frame_rate = 0.0;
- // 已编码帧
- int frames_encoded = 0;
- std::optional<uint64_t> qp_sum;
- // 整体编码耗时,以ms为单位
- uint64_t total_encode_time_ms = 0;
- // 总体已编码比特目标
- uint64_t total_encoded_bytes_target = 0;
- uint32_t huge_frames_sent = 0;
- std::optional<ScalabilityMode> scalability_mode;
- };
- // 下面是一些发送视频流的状态信息
- struct Stats {
- Stats();
- ~Stats();
- std::string ToString(int64_t time_ms) const;
- // 编码实例名称
- std::optional<std::string> encoder_implementation_name;
- // 输入帧率
- double input_frame_rate = 0;
- // 编码帧率
- int encode_frame_rate = 0;
- // 平均编码耗时,以ms为单位
- int avg_encode_time_ms = 0;
- // 编码器使用率百分比
- int encode_usage_percent = 0;
- // 已编码帧数量
- uint32_t frames_encoded = 0;
- // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime
- // 总体编码耗时,以ms为单位
- uint64_t total_encode_time_ms = 0;
- // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
- // 编码器目标总比特数
- uint64_t total_encoded_bytes_target = 0;
- // 帧数
- uint32_t frames = 0;
- // 由于采集问题而丢帧的数量
- uint32_t frames_dropped_by_capturer = 0;
- // 由于时间戳问题而丢帧的数量
- uint32_t frames_dropped_by_bad_timestamp = 0;
- // 由于编码队列太长而丢帧的数量
- uint32_t frames_dropped_by_encoder_queue = 0;
- // 由于码率限制而丢帧的数量
- uint32_t frames_dropped_by_rate_limiter = 0;
- // 由于拥塞窗口而丢帧的数量
- uint32_t frames_dropped_by_congestion_window = 0;
- // 由于编码器问题而丢帧的数量
- uint32_t frames_dropped_by_encoder = 0;
- // Bitrate the encoder is currently configured to use due to bandwidth
- // limitations.
- // 由于带宽限制,编码器当前配置使用的比特率
- int target_media_bitrate_bps = 0;
- // Bitrate the encoder is actually producing.
- // 由编码器实际产生的码率
- int media_bitrate_bps = 0;
- // 流是否暂停
- bool suspended = false;
- // 是否由于bandwidth而降低分辨率
- bool bw_limited_resolution = false;
- // 是否由于CPU而降低分辨率
- bool cpu_limited_resolution = false;
- // 是否由于bandwidth而降低帧率
- bool bw_limited_framerate = false;
- // 是否由于CPU而减低帧率
- bool cpu_limited_framerate = false;
- // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
- // 质量限制原因
- QualityLimitationReason quality_limitation_reason =
- QualityLimitationReason::kNone;
- // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
- // 记录由于不同原因导致质量下降的持续时间
- std::map<QualityLimitationReason, int64_t> quality_limitation_durations_ms;
- // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges
- // 记录由于质量限制而导致分辨率变化的次数
- uint32_t quality_limitation_resolution_changes = 0;
- // Total number of times resolution as been requested to be changed due to
- // CPU/quality adaptation.
- // 由于CPU/质量适应,请求改变分辨率的总次数
- int number_of_cpu_adapt_changes = 0;
- int number_of_quality_adapt_changes = 0;
- // 是否进入了低分辨率状态
- bool has_entered_low_resolution = false;
- // 子流
- std::map<uint32_t, StreamStats> substreams;
- // 内容的类型
- webrtc::VideoContentType content_type =
- webrtc::VideoContentType::UNSPECIFIED;
- // 发送出去的视频帧总数
- uint32_t frames_sent = 0;
- // 发送出去的“巨大”视频帧的数量
- uint32_t huge_frames_sent = 0;
- // 是否处于节能模式
- std::optional<bool> power_efficient_encoder;
- };
- // 下面是一些配置项
- struct Config {
- public:
- Config() = delete;
- Config(Config&&);
- explicit Config(Transport* send_transport);
- Config& operator=(Config&&);
- Config& operator=(const Config&) = delete;
- ~Config();
- // Mostly used by tests. Avoid creating copies if you can.
- Config Copy() const { return Config(*this); }
- std::string ToString() const;
- // RTP配置项
- RtpConfig rtp;
- // 编码器设置
- VideoStreamEncoderSettings encoder_settings;
- // Time interval between RTCP report for video
- // 视频RTCP报告的时间间隔
- int rtcp_report_interval_ms = 1000;
- // Transport for outgoing packets.
- // 出站数据包的传输
- Transport* send_transport = nullptr;
- // Expected delay needed by the renderer, i.e. the frame will be delivered
- // this many milliseconds, if possible, earlier than expected render time.
- // Only valid if `local_renderer` is set.
- /*
- 渲染器所需的预期延迟,即如果可能的话,帧将比预期渲染时间提前这么多毫秒交付。
- 只有当设置了`local_renderer`时,此值才有效。
- */
- int render_delay_ms = 0;
- // Target delay in milliseconds. A positive value indicates this stream is
- // used for streaming instead of a real-time call.
- // 目标延迟时间,以毫秒为单位。正值表示此流用于流媒体传输,而不是实时通话
- int target_delay_ms = 0;
- // True if the stream should be suspended when the available bitrate fall
- // below the minimum configured bitrate. If this variable is false, the
- // stream may send at a rate higher than the estimated available bitrate.
- // 如果可用比特率下降到最低配置的比特率以下时应该暂停流,则为真
- // 如果这个变量为假,流可能会以高于估计的可用比特率的速度发送
- bool suspend_below_min_bitrate = false;
- // Enables periodic bandwidth probing in application-limited region.
- // 启用在应用受限区域的周期性带宽探测
- bool periodic_alr_bandwidth_probing = false;
- // An optional custom frame encryptor that allows the entire frame to be
- // encrypted in whatever way the caller chooses. This is not required by
- // default.
- // 一个可选的自定义帧加密器,允许整个帧按照调用者选择的任何方式进行加密。这不是默认必需的
- rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
- // An optional encoder selector provided by the user.
- // Overrides VideoEncoderFactory::GetEncoderSelector().
- // Owned by RtpSenderBase.
- /*
- 用户提供的一个可选编码器选择器。
- 覆盖了 VideoEncoderFactory::GetEncoderSelector()。
- 由 RtpSenderBase 拥有。
- */
- VideoEncoderFactory::EncoderSelectorInterface* encoder_selector = nullptr;
- // Per PeerConnection cryptography options.
- // 每个PeerConnection的加密选项
- CryptoOptions crypto_options;
- // 帧转换器
- rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
- private:
- // Access to the copy constructor is private to force use of the Copy()
- // method for those exceptional cases where we do use it.
- Config(const Config&);
- };
- // Starts stream activity.
- // When a stream is active, it can receive, process and deliver packets.
- // 开启一个流,此时流可以进行接收,处理和传输数据包
- virtual void Start() = 0;
- // Stops stream activity.
- // When a stream is stopped, it can't receive, process or deliver packets.
- // 停止一个流,此时流不能接收,处理和传输数据包
- virtual void Stop() = 0;
- // Accessor for determining if the stream is active. This is an inexpensive
- // call that must be made on the same thread as `Start()` and `Stop()` methods
- // are called on and will return `true` iff activity has been started
- // via `Start()`.
- // 用于确定流是否处于活动状态的访问器。这是一个低成本的调用,必须在与`Start()`和
- // `Stop()`方法调用相同的线程上进行,并且仅当通过`Start()`启动了活动时才会返回`true`
- virtual bool started() = 0;
- // If the resource is overusing, the VideoSendStream will try to reduce
- // resolution or frame rate until no resource is overusing.
- // TODO(https://crbug.com/webrtc/11565): When the ResourceAdaptationProcessor
- // is moved to Call this method could be deleted altogether in favor of
- // Call-level APIs only.
- // 如果资源使用过量,VideoSendStream将尝试降低分辨率或帧率,直到没有资源使用过量
- virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
- virtual std::vector<rtc::scoped_refptr<Resource>>
- GetAdaptationResources() = 0;
- virtual void SetSource(
- rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
- const DegradationPreference& degradation_preference) = 0;
- // Set which streams to send. Must have at least as many SSRCs as configured
- // in the config. Encoder settings are passed on to the encoder instance along
- // with the VideoStream settings.
- // 设置要发送的流。必须至少有与配置中配置的一样多的SSRCs。编码器设置会与VideoStream设置一起传递给编码器实例
- virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0;
- virtual void ReconfigureVideoEncoder(VideoEncoderConfig config,
-
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |