Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 自定义视频捕获本机webrtc_C++_Webrtc - Fatal编程技术网

C++ 自定义视频捕获本机webrtc

C++ 自定义视频捕获本机webrtc,c++,webrtc,C++,Webrtc,根据webrtc的说法,google cricket的讨论组主题::VideoCapture将很快被弃用。要定制视频源,我们应该实现VideoTrackSourceInterface。我尝试实现接口,但没有成功。当我有一个帧时,我实现了一个接口,然后称为事件OnFrame(const webrtc::VideoFrame&frame),如下所示: void StreamSource::OnFrame(const webrtc::VideoFrame& frame) { rtc::sco

根据webrtc的说法,google cricket的讨论组主题::VideoCapture将很快被弃用。要定制视频源,我们应该实现VideoTrackSourceInterface。我尝试实现接口,但没有成功。当我有一个帧时,我实现了一个接口,然后称为事件OnFrame(const webrtc::VideoFrame&frame),如下所示:

void StreamSource::OnFrame(const webrtc::VideoFrame& frame)
{
 rtc::scoped_refptr<webrtc::VideoFrameBuffer buffer(frame.video_frame_buffer());
 broadcaster_.OnFrame(frame);
void StreamSource::OnFrame(const webrtc::VideoFrame&frame)
{
rtc::scoped_refptrCreateVideoTrack(kVideoLabel,新mystream::StreamSource());

我的视频无法在浏览器中播放。我做错了什么?

我使用了基类AdaptedVideoTrackSource,并创建了一个方法FrameCapture,它是从我的线程中调用的,在这个方法中,我将该方法称为OnFrame。工作正常

 class StreamSource : public rtc::AdaptedVideoTrackSource
 {
   void OnFrameCaptured(const webrtc::VideoFrame& frame);
 }

 void StreamSource::OnFrameCaptured(const webrtc::VideoFrame& frame) 
 {
  OnFrame(frame);
 }
我得到了答案

VideoFrame具有枚举类型,如下所示:

class VideoFrameBuffer:公共rtc::RefCountInterface{
公众:
//当出现错误时,将保守地添加新的帧缓冲区类型
//优化某对视频源和视频源之间的路径的机会
//视频接收器。
枚举类类型{
无赖的,
kI420,
kI420A,
kI444,
kI010,
};
...
}
要详细说明客户的答案: 创建自定义视频源类并定义所有抽象方法。以下是一个示例:

class CustomVideoSource : public rtc::AdaptedVideoTrackSource  {

public:
    void OnFrameCaptured(const webrtc::VideoFrame& frame);
    void AddRef() const override;
    rtc::RefCountReleaseStatus Release() const override;
    SourceState state() const override;
    bool remote() const override;
    bool is_screencast() const override;
    absl::optional<bool> needs_denoising() const override;
private:
    mutable volatile int ref_count_;
};
class CustomVideoSource:公共rtc::AdaptedVideoTrackSource{
公众:
void OnFrameCaptured(const webrtc::VideoFrame和frame);
void AddRef()常量覆盖;
rtc::RefCountReleaseStatus Release()常量覆盖;
SourceState()常量覆盖;
bool remote()常量覆盖;
bool是_screencast()常量覆盖;
absl::可选需要\u去噪()常量覆盖;
私人:
可变易失性整数参考计数;
};
和实施:

void CustomVideoSource::OnFrameCaptured(const webrtc::VideoFrame& frame) {
  OnFrame(frame);
}

void CustomVideoSource::AddRef() const {
  rtc::AtomicOps::Increment(&ref_count_);
}

rtc::RefCountReleaseStatus CustomVideoSource::Release() const {
  const int count = rtc::AtomicOps::Decrement(&ref_count_);
  if (count == 0) {
    return rtc::RefCountReleaseStatus::kDroppedLastRef;
  }
  return rtc::RefCountReleaseStatus::kOtherRefsRemained;
}

webrtc::MediaSourceInterface::SourceState CustomVideoSource::state() const {
  return kLive;
}

bool CustomVideoSource::remote() const {
  return false;
}

bool CustomVideoSource::is_screencast() const {
  return false;
}

absl::optional<bool> CustomVideoSource::needs_denoising() const {
  return false;
void CustomVideoSource::OnFrameCaptured(const webrtc::VideoFrame&frame){
OnFrame(frame);
}
void CustomVideoSource::AddRef()常量{
rtc::原子操作::增量(&ref\u计数);
}
rtc::RefCountReleaseStatus CustomVideoSource::Release()常量{
常量int count=rtc::原子运算::减量(&ref\u count);
如果(计数=0){
返回rtc::RefCountReleaseStatus::kDroppedLastRef;
}
返回rtc::RefCountReleaseStatus::KotherRefsRemain;
}
webrtc::MediaSourceInterface::SourceState CustomVideoSource::state()常量{
回归克里夫;
}
bool CustomVideoSource::remote()常量{
返回false;
}
bool CustomVideoSource::是屏幕广播()常量吗{
返回false;
}
absl::可选CustomVideoSource::需要去噪()常量{
返回false;
请记住,这只是为了让它工作,而不是完整的实现。您应该正确地实现抽象方法,而不是返回硬编码的值。 要发送帧,只需调用随帧捕获的onFrameCapture

要添加流,请执行以下操作:

custom_source= new rtc::RefCountedObject<CustomVideoSource>();
// create video track from our custom source
rtc::scoped_refptr<webrtc::VideoTrackInterface> custom_video_track(
g_peer_connection_factory->CreateVideoTrack( kVideoLabel, custom_source));
//add to stream
stream->AddTrack(custom_video_track);
custom_source=new rtc::RefCountedObject();
//从自定义源创建视频曲目
rtc::作用域\u refptr自定义\u视频\u曲目(
g_peer_connection_factory->CreateVideoTrack(KVideLabel,自定义_源);
//添加到流
流->添加曲目(自定义视频曲目);

<>我不是专家,而是自己做一个项目,并在沿途实施一些事情。请随意纠正我或添加到这个代码。

你能详细说明你是如何使它工作的吗?或者你是如何到达那里的,也许是帮助你的东西?我有同样的问题,我不知道从哪里开始。我也试图在C++中实现同样的任务。我是PR。etty是新来的,为此挣扎了很长一段时间。如果你不介意的话,你能告诉我一个样品吗?
custom_source= new rtc::RefCountedObject<CustomVideoSource>();
// create video track from our custom source
rtc::scoped_refptr<webrtc::VideoTrackInterface> custom_video_track(
g_peer_connection_factory->CreateVideoTrack( kVideoLabel, custom_source));
//add to stream
stream->AddTrack(custom_video_track);