VideoFrame.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "pch.h"
  2. #include "GraphicsDevice/GraphicsDevice.h"
  3. #include "VideoFrame.h"
  4. namespace unity
  5. {
  6. namespace webrtc
  7. {
  8. VideoFrame::VideoFrame(
  9. const Size& size,
  10. rtc::scoped_refptr<GpuMemoryBufferInterface> buffer,
  11. ReturnBufferToPoolCallback returnBufferToPoolCallback,
  12. TimeDelta timestamp)
  13. : size_(size)
  14. , gpu_memory_buffer_(std::move(buffer))
  15. , returnBufferToPoolCallback_(returnBufferToPoolCallback)
  16. , timestamp_(timestamp)
  17. {
  18. }
  19. VideoFrame::~VideoFrame()
  20. {
  21. if (returnBufferToPoolCallback_)
  22. {
  23. returnBufferToPoolCallback_(std::move(gpu_memory_buffer_));
  24. }
  25. }
  26. rtc::scoped_refptr<VideoFrame> VideoFrame::WrapExternalGpuMemoryBuffer(
  27. const Size& size,
  28. rtc::scoped_refptr<GpuMemoryBufferInterface> buffer,
  29. ReturnBufferToPoolCallback returnBufferToPoolCallback,
  30. TimeDelta timestamp)
  31. {
  32. return new rtc::RefCountedObject<VideoFrame>(size, std::move(buffer), returnBufferToPoolCallback, timestamp);
  33. }
  34. bool VideoFrame::HasGpuMemoryBuffer() const { return gpu_memory_buffer_ != nullptr; }
  35. GpuMemoryBufferInterface* VideoFrame::GetGpuMemoryBuffer() const { return gpu_memory_buffer_.get(); }
  36. } // end namespace webrtc
  37. } // end namespace unity