VideoFrame.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <api/units/time_delta.h>
  3. #include <rtc_base/ref_counted_object.h>
  4. #include <rtc_base/timestamp_aligner.h>
  5. #include "GpuMemoryBuffer.h"
  6. #include "Size.h"
  7. namespace unity
  8. {
  9. namespace webrtc
  10. {
  11. using namespace ::webrtc;
  12. class VideoFrame : public rtc::RefCountInterface
  13. {
  14. public:
  15. using ReturnBufferToPoolCallback = std::function<void(rtc::scoped_refptr<GpuMemoryBufferInterface>)>;
  16. VideoFrame() = delete;
  17. VideoFrame(const VideoFrame&) = delete;
  18. VideoFrame& operator=(const VideoFrame&) = delete;
  19. Size size() const { return size_; }
  20. UnityRenderingExtTextureFormat format() const { return gpu_memory_buffer_->GetFormat(); }
  21. TimeDelta timestamp() const { return timestamp_; }
  22. void set_timestamp(TimeDelta timestamp) { timestamp_ = timestamp; }
  23. GpuMemoryBufferInterface* GetGpuMemoryBuffer() const;
  24. bool HasGpuMemoryBuffer() const;
  25. static rtc::scoped_refptr<VideoFrame> WrapExternalGpuMemoryBuffer(
  26. const Size& size,
  27. rtc::scoped_refptr<GpuMemoryBufferInterface> gpu_memory_buffer,
  28. ReturnBufferToPoolCallback returnBufferToPoolCallback,
  29. TimeDelta timestamp);
  30. protected:
  31. VideoFrame(
  32. const Size& size,
  33. rtc::scoped_refptr<GpuMemoryBufferInterface> buffer,
  34. ReturnBufferToPoolCallback returnBufferToPoolCallback,
  35. TimeDelta timestamp);
  36. virtual ~VideoFrame() override;
  37. private:
  38. Size size_;
  39. rtc::scoped_refptr<GpuMemoryBufferInterface> gpu_memory_buffer_;
  40. ReturnBufferToPoolCallback returnBufferToPoolCallback_;
  41. TimeDelta timestamp_;
  42. };
  43. } // end namespace webrtc
  44. } // end namespace unity