jetson_buffer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef SORA_HWENC_JETSON_JETSON_BUFFER_H_
  2. #define SORA_HWENC_JETSON_JETSON_BUFFER_H_
  3. #include <linux/videodev2.h>
  4. #include <memory>
  5. // WebRTC
  6. #include <api/video/video_frame.h>
  7. #include <common_video/include/video_frame_buffer.h>
  8. #include <common_video/libyuv/include/webrtc_libyuv.h>
  9. #include <rtc_base/memory/aligned_malloc.h>
  10. #include "jetson_jpeg_decoder.h"
  11. namespace sora {
  12. class JetsonBuffer : public webrtc::VideoFrameBuffer {
  13. public:
  14. static rtc::scoped_refptr<JetsonBuffer> Create(
  15. webrtc::VideoType video_type,
  16. int raw_width,
  17. int raw_height,
  18. int scaled_width,
  19. int scaled_height,
  20. int fd,
  21. uint32_t pixfmt,
  22. std::shared_ptr<JetsonJpegDecoder> decoder);
  23. static rtc::scoped_refptr<JetsonBuffer> Create(webrtc::VideoType video_type,
  24. int raw_width,
  25. int raw_height,
  26. int scaled_width,
  27. int scaled_height);
  28. Type type() const override;
  29. webrtc::VideoType VideoType() const;
  30. int width() const override;
  31. int height() const override;
  32. rtc::scoped_refptr<webrtc::I420BufferInterface> ToI420() override;
  33. int RawWidth() const;
  34. int RawHeight() const;
  35. int DecodedFd() const;
  36. uint32_t V4L2PixelFormat() const;
  37. std::shared_ptr<JetsonJpegDecoder> JpegDecoder() const;
  38. uint8_t* Data() const;
  39. void SetLength(size_t size);
  40. size_t Length() const;
  41. protected:
  42. JetsonBuffer(webrtc::VideoType video_type,
  43. int raw_width,
  44. int raw_height,
  45. int scaled_width,
  46. int scaled_height,
  47. int fd,
  48. uint32_t pixfmt,
  49. std::shared_ptr<JetsonJpegDecoder> decoder);
  50. JetsonBuffer(webrtc::VideoType video_type,
  51. int raw_width,
  52. int raw_height,
  53. int scaled_width,
  54. int scaled_height);
  55. private:
  56. webrtc::VideoType video_type_;
  57. const int raw_width_;
  58. const int raw_height_;
  59. const int scaled_width_;
  60. const int scaled_height_;
  61. const int fd_;
  62. const uint32_t pixfmt_;
  63. const std::shared_ptr<JetsonJpegDecoder> decoder_;
  64. const std::unique_ptr<uint8_t, webrtc::AlignedFreeDeleter> data_;
  65. size_t length_;
  66. };
  67. } // namespace sora
  68. #endif