gsml_capturer.h 2.0 KB

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