gsml_capturer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> OpenGSMLCapture(CaptureOp* op,int32_t GSML) ;
  20. class GSMLCapturer : public rtc::VideoSourceInterface<webrtc::VideoFrame>
  21. {
  22. public:
  23. GSMLCapturer(CaptureOp* lhs);
  24. virtual ~GSMLCapturer()=default;
  25. void Start(int32_t GSML);
  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. int64_t count;
  47. int32_t CameraRecord;
  48. int File_fd;
  49. long long _curStopTick;
  50. };
  51. class GSMLTrackSource : public webrtc::VideoTrackSource {
  52. public:
  53. static rtc::scoped_refptr<GSMLTrackSource> Create(std::unique_ptr<GSMLCapturer> capturer) {
  54. return new rtc::RefCountedObject<GSMLTrackSource>(std::move(capturer));
  55. }
  56. protected:
  57. explicit GSMLTrackSource(std::unique_ptr<GSMLCapturer> capturer)
  58. : VideoTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {}
  59. ~GSMLTrackSource()
  60. {
  61. capturer_->Stop();
  62. }
  63. private:
  64. rtc::VideoSourceInterface<webrtc::VideoFrame>* source() override {
  65. return capturer_.get();
  66. }
  67. std::unique_ptr<GSMLCapturer> capturer_;
  68. };