#pragma once #include #include #include #include "media/base/video_broadcaster.h" // #include "yuyvtoi420.cuh" #include "nvbufsurface.h" #include "NvBufSurface.h" #include "nvbufsurftransform.h" // #define ERROR_RETURN(fmt, ...) \ // do { \ // printf("ERROR: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \ // return false; \ // } while(0) // #define INFO(fmt, ...) \ // if (p->enable_verbose) \ // printf("INFO: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); // #define WARN(fmt, ...) \ // printf("WARN: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); #define V4L2_BUFFERS_NUM 4 class CaptureOp; rtc::scoped_refptr OpenGSMLCapture(CaptureOp* op) ; class GSMLCapturer : public rtc::VideoSourceInterface { public: GSMLCapturer(CaptureOp* lhs); virtual ~GSMLCapturer()=default; void Start(); void Run(); void Stop(); void AddOrUpdateSink(rtc::VideoSinkInterface* sink, const rtc::VideoSinkWants& wants) override; void RemoveSink(rtc::VideoSinkInterface* sink) override; bool EncodeI420ToVP8(const webrtc::I420Buffer* i420_buffer, webrtc::VideoFrame* output_frame); // private: bool open_cam(); void close_cam(); bool prepare_buffer(); bool start_streams(); bool stop_streams(); bool request_camera_buff(context_t * p); bool request_camera_buff_mmap(context_t * p); private: void Destroy(); private: rtc::VideoBroadcaster _broadcaster; std::thread _thread; bool _run; CaptureOp* _op; }; class GSMLTrackSource : public webrtc::VideoTrackSource { public: static rtc::scoped_refptr Create(std::unique_ptr capturer) { return new rtc::RefCountedObject(std::move(capturer)); } protected: explicit GSMLTrackSource(std::unique_ptr capturer) : VideoTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {} ~GSMLTrackSource() { capturer_->Stop(); } private: rtc::VideoSourceInterface* source() override { return capturer_.get(); } std::unique_ptr capturer_; };