To elaborate on user1658843's answer:
create a custom video source class and define all the abstract methods. here is an example:
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_;
};
And implementations:
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;
Keep in mind this is just to get it to work and not full implementations. You should implement the abstract methods properly instead of returning the hard coded values.
To send a frame simply call OnFrameCaptured with the frame.
To add stream:
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);
I'm not an expert but doing a project on my own and implementing stuff along the way.Feel free to correct me or add to this code.