gsml_capturer.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include "nvbufsurface.h"
  8. #include "NvBufSurface.h"
  9. #include "nvbufsurftransform.h"
  10. // #define ERROR_RETURN(fmt, ...) \
  11. // do { \
  12. // printf("ERROR: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
  13. // return false; \
  14. // } while(0)
  15. // #define INFO(fmt, ...) \
  16. // if (p->enable_verbose) \
  17. // printf("INFO: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);
  18. // #define WARN(fmt, ...) \
  19. // printf("WARN: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);
  20. #define V4L2_BUFFERS_NUM 4
  21. class CaptureOp;
  22. rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> OpenGSMLCapture(CaptureOp* op) ;
  23. class GSMLCapturer : public rtc::VideoSourceInterface<webrtc::VideoFrame>
  24. {
  25. public:
  26. GSMLCapturer(CaptureOp* lhs);
  27. virtual ~GSMLCapturer()=default;
  28. void Start();
  29. void Run();
  30. void Stop();
  31. void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
  32. const rtc::VideoSinkWants& wants) override;
  33. void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
  34. bool EncodeI420ToVP8(const webrtc::I420Buffer* i420_buffer, webrtc::VideoFrame* output_frame); //
  35. private:
  36. bool open_cam();
  37. void close_cam();
  38. bool prepare_buffer();
  39. bool start_streams();
  40. bool stop_streams();
  41. bool request_camera_buff(context_t * p);
  42. bool request_camera_buff_mmap(context_t * p);
  43. private:
  44. void Destroy();
  45. private:
  46. rtc::VideoBroadcaster _broadcaster;
  47. std::thread _thread;
  48. bool _run;
  49. CaptureOp* _op;
  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. };