Custom video capture

117 views
Skip to first unread message

EARob Agar

unread,
Sep 29, 2016, 4:37:18 AM9/29/16
to webrtcbuilds
Hi all!

I'm after some advice on how best to pass raw video frames to WebRTC in the current system.  We have working code built on the old Chromium codebase from webrtcbuilds-builder rev a9046d0 (see below), but it seems there have been some fairly major refactoring going on since then.  Apart from anything else, the DeviceManager we used to create the video capturer has gone completely.

The basic question now is, is it even possible to register a custom source of video frame data?  Looking at video_capture_linux.cc, it seems to me that for Linux it appears to be hard coded to get video from the /dev/videoX devices only.  It doesn't appear to allow for other sources of video. Please tell me I'm missing something! 

Here's our previous working (if kludgy) code:

void PeerConnectionImpl::initMediaStream(webrtc::MediaConstraintsInterface *connectionConstraints)
{
 
const char *mediaStreamLabel = "the_media_stream";
  scoped_refptr
<webrtc::MediaStreamInterface> ms = factory->CreateLocalMediaStream(mediaStreamLabel);

  mediaStream
= ms.get();
  mediaStream
->AddRef();

  rtc
::scoped_refptr<webrtc::VideoSourceInterface> vs;
  rtc
::scoped_refptr<webrtc::VideoTrackInterface> vt;
 
if (withVideo)
 
{
   
const char *videoTrackLabel = "the_video_track";

   
// create our custom video capture
    cricket
::VideoCapturer *vc = initVideoCapturer();

    vs
= factory->CreateVideoSource(vc, NULL);
    vt
= factory->CreateVideoTrack(videoTrackLabel, vs);

    mediaStream
->AddTrack(vt);
 
}
 
  connection
->AddStream(mediaStream);
}


cricket
::VideoCapturer* PeerConnectionImpl::initVideoCapturer()
{
  rtc
::scoped_ptr<cricket::DeviceManagerInterface> deviceManager(cricket::DeviceManagerFactory::Create());

 
// use our factory which only creates our custom capturer
 
RawVideoCapturerFactory* f =  new RawVideoCapturerFactory();
  cricket
::VideoDeviceCapturerFactory *cf = static_cast<cricket::VideoDeviceCapturerFactory*>(static_cast<void*>(f));
  deviceManager
->SetVideoDeviceCapturerFactory(cf);
 
 
// create the capturer
  std
::vector<cricket::Device> devices;
  deviceManager
->GetVideoCaptureDevices(&devices);
  cricket
::VideoCapturer* c = NULL;
 
for(auto d : devices)
 
{
    c
= deviceManager->CreateVideoCapturer(d);
   
if (c != NULL)
   
{
     
// this must be our custom one
      videoCapturer
= static_cast<RawVideoCapturer*>(c);
     
break;
   
}
 
}

 
return c;
}

EARob Agar

unread,
Oct 19, 2016, 6:31:36 AM10/19/16
to webrtcbuilds
Got an answer to a cross post over on discuss-webrtc :)
Reply all
Reply to author
Forward
0 new messages