gsml_capturer.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include <pc/video_track_source.h>
  3. #include <thread>
  4. #include <string>
  5. #include "media/base/video_broadcaster.h"
  6. // #include "yuyvtoi420.cuh"
  7. #define ERROR_RETURN(fmt, ...) \
  8. do { \
  9. printf("ERROR: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
  10. return false; \
  11. } while(0)
  12. #define INFO(fmt, ...) \
  13. if (p->enable_verbose) \
  14. printf("INFO: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);
  15. #define WARN(fmt, ...) \
  16. printf("WARN: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);
  17. #define V4L2_BUFFERS_NUM 4
  18. class CaptureOp;
  19. rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> OpenGSMLCapture(CaptureOp* op) ;
  20. class GSMLCapturer : public rtc::VideoSourceInterface<webrtc::VideoFrame>
  21. {
  22. public:
  23. GSMLCapturer(CaptureOp* lhs);
  24. virtual ~GSMLCapturer()=default;
  25. void Start();
  26. void Run();
  27. void Stop();
  28. void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
  29. const rtc::VideoSinkWants& wants) override;
  30. void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
  31. private:
  32. bool open_cam();
  33. void close_cam();
  34. bool prepare_buffer();
  35. bool start_streams();
  36. bool stop_streams();
  37. bool request_camera_buff(context_t * p);
  38. bool request_camera_buff_mmap(context_t * p);
  39. private:
  40. void Destroy();
  41. private:
  42. rtc::VideoBroadcaster _broadcaster;
  43. std::thread _thread;
  44. bool _run;
  45. CaptureOp* _op;
  46. };
  47. class GSMLTrackSource : public webrtc::VideoTrackSource {
  48. public:
  49. static rtc::scoped_refptr<GSMLTrackSource> Create(std::unique_ptr<GSMLCapturer> capturer) {
  50. return new rtc::RefCountedObject<GSMLTrackSource>(std::move(capturer));
  51. }
  52. protected:
  53. explicit GSMLTrackSource(std::unique_ptr<GSMLCapturer> capturer)
  54. : VideoTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {}
  55. ~GSMLTrackSource()
  56. {
  57. capturer_->Stop();
  58. }
  59. private:
  60. rtc::VideoSourceInterface<webrtc::VideoFrame>* source() override {
  61. return capturer_.get();
  62. }
  63. std::unique_ptr<GSMLCapturer> capturer_;
  64. };