[WebRTC导读] VideoSendStream 视频流发送类

相关的类 VideoSendStream, VideoSendStream::Config,VideoEncoderConfig,I420FrameCallback,EncodedFrameObserver, VideoEncoderConfig, newapi::Transport

VideoSendStream 视频流发送类,用于将yuv数据转换成h264等编码格式,并且将编码转换成rtp格式,通过传入的通讯通道来发送,本类也提供了编码前,编码后的回调。可以使用这些回调来做预处理或者文件保存等动作。

  • 创建
    本类通过CreateVideoSendStream 函数来创建实体,创建过程中需要两个结构体VideoSendStream::Config和webrtc::VideoEncoderConfig
virtual VideoSendStream* CreateVideoSendStream(
      const VideoSendStream::Config& config,
      const VideoEncoderConfig& encoder_config) = 0;
  • 流输入
    VideoCaptureInput* VideoSendStream::Input() 获取视频VideoSendStream的输入口,通过VideoCaptureInput::IncomingCapturedFrame(const VideoFrame& video_frame) 把yuv的数据输入到编码器
send_stream_ = sender_call_->CreateVideoSendStream(send_config_, encoder_config_);
video_capture_input_ = send_stream_->Input();
//将VideoFrame 送入到编码器中进行编码
video_capture_input_->IncomingCapturedFrame(videoFrame);
  • 输出
    通过EncodedFrameObserver将编码后的数据导出,该设置通过VideoSendStream::Config::post_encode_callback来注入
void VideoEngineImpl::RegistPostEncodeCallback(EncodedFrameObserver*  encode_frame_callback)
{
    send_config_.post_encode_callback = encode_frame_callback;
}

I420FrameCallback 预处理回调,在回调方法中可以修改I420的数据,用来预处理中添加效果,比如美颜等等

class I420FrameCallback {
public:
  // This function is called with a I420 frame allowing the user to modify the
  // frame content.
  virtual void FrameCallback(VideoFrame* video_frame) = 0;
protected:
  virtual ~I420FrameCallback() {}
};

EncodedFrameObserver 后处理回调,用来返回编码好的数据,可用来录制文件等

class EncodedFrameObserver {
public:
  virtual void EncodedFrameCallback(const EncodedFrame& encoded_frame) = 0;
  virtual int32_t Encoded(const EncodedImage& encodedImage,
      const CodecSpecificInfo* codecSpecificInfo,
      const RTPFragmentationHeader* fragmentation) {
      return 0;
  }
protected:
  virtual ~EncodedFrameObserver() {}
};

VideoSendStream::Config 提供发送流的输入配置
重要的几个成员

 // Transport for outgoing packets.
    newapi::Transport* send_transport = nullptr;    用来表示rtp协议的输出通道

    // Called for each I420 frame before encoding the frame. Can be used for
    // effects, snapshots etc. 'nullptr' disables the callback.
    I420FrameCallback* pre_encode_callback = nullptr; 预处理编码之前调用,用来添加效果,截屏等

    // Called for each encoded frame, e.g. used for file storage. 'nullptr'
    // disables the callback.
    EncodedFrameObserver* post_encode_callback = nullptr; 后处理,编码后返回已经编码好的数据,用来保存文件等

    // Renderer for local preview. The local renderer will be called even if
    // sending hasn't started. 'nullptr' disables local rendering.
    VideoRenderer* local_renderer = nullptr; 设置渲染器,用来渲染传入的数据

VideoEncoderConfig 用来配置每一路流的编码配置

struct VideoEncoderConfig {
  enum class ContentType {
    kRealtimeVideo,
    kScreen,
  };
  VideoEncoderConfig();
  ~VideoEncoderConfig();
  std::string ToString() const;
  std::vector<VideoStream> streams;
  ContentType content_type;
  void* encoder_specific_settings;
  // Padding will be used up to this bitrate regardless of the bitrate produced
  // by the encoder. Padding above what's actually produced by the encoder helps
  // maintaining a higher bitrate estimate. Padding will however not be sent
  // unless the estimated bandwidth indicates that the link can handle it.
  int min_transmit_bitrate_bps;
};

newapi::Transport 用来导出rtp和rtcp包用来发送

class Transport {
 public:
  virtual bool SendRtp(const uint8_t* packet, size_t length) = 0;
  virtual bool SendRtcp(const uint8_t* packet, size_t length) = 0;

 protected:
  virtual ~Transport() {}
};

欢迎访问本人的小站 xsnip.cn

你可能感兴趣的:(webrtc导读,webrtc,rtc)