capture_factory.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <regex>
  3. #include "VcmCapturer.h"
  4. #include "rtspvideocapturer.h"
  5. #include "rtspaudiocapturer.h"
  6. #include "pc/video_track_source.h"
  7. template<class T>
  8. class TrackSource : public webrtc::VideoTrackSource {
  9. public:
  10. static rtc::scoped_refptr<TrackSource> Create(const std::string & videourl, std::unique_ptr<webrtc::VideoDecoderFactory>& videoDecoderFactory) {
  11. std::unique_ptr<T> capturer = absl::WrapUnique(T::Create(videourl, videoDecoderFactory));
  12. if (!capturer) {
  13. return nullptr;
  14. }
  15. return new rtc::RefCountedObject<TrackSource>(std::move(capturer));
  16. }
  17. protected:
  18. explicit TrackSource(std::unique_ptr<T> capturer)
  19. : webrtc::VideoTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {}
  20. private:
  21. rtc::VideoSourceInterface<webrtc::VideoFrame>* source() override {
  22. return capturer_.get();
  23. }
  24. std::unique_ptr<T> capturer_;
  25. };
  26. class CapturerFactory {
  27. public:
  28. static rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> CreateVideoSource(const std::string & videourl, std::unique_ptr<webrtc::VideoDecoderFactory>& videoDecoderFactory) {
  29. rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> videoSource;
  30. videoSource = TrackSource<RTSPVideoCapturer>::Create(videourl, videoDecoderFactory);
  31. return videoSource;
  32. }
  33. static rtc::scoped_refptr<webrtc::AudioSourceInterface> CreateAudioSource(const std::string & audiourl,
  34. const std::map<std::string,std::string> & opts,
  35. rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory,
  36. rtc::scoped_refptr<webrtc::AudioDecoderFactory> audioDecoderfactory,
  37. rtc::scoped_refptr<webrtc::> audioDeviceModule) {
  38. rtc::scoped_refptr<webrtc::AudioSourceInterface> audioSource;
  39. audioDeviceModule->Terminate();
  40. audioSource = RTSPAudioSource::Create(audioDecoderfactory, audiourl);
  41. return audioSource;
  42. }
  43. };