VideoFrameUtil.cpp 975 B

123456789101112131415161718192021222324252627282930
  1. #include "pch.h"
  2. #include <system_wrappers/include/clock.h>
  3. #include "GpuMemoryBuffer.h"
  4. #include "GraphicsDevice/ITexture2D.h"
  5. #include "VideoFrameUtil.h"
  6. namespace unity
  7. {
  8. namespace webrtc
  9. {
  10. rtc::scoped_refptr<VideoFrame>
  11. CreateTestFrame(IGraphicsDevice* device, const ITexture2D* texture, UnityRenderingExtTextureFormat format)
  12. {
  13. NativeTexPtr ptr = NativeTexPtr(texture->GetNativeTexturePtrV());
  14. Size size = Size(static_cast<int>(texture->GetWidth()), static_cast<int>(texture->GetHeight()));
  15. rtc::scoped_refptr<GpuMemoryBufferInterface> gmb =
  16. new rtc::RefCountedObject<GpuMemoryBufferFromUnity>(device, ptr, size, format);
  17. const int64_t timestamp_us = webrtc::Clock::GetRealTimeClock()->TimeInMicroseconds();
  18. return VideoFrame::WrapExternalGpuMemoryBuffer(
  19. size, std::move(gmb), nullptr, webrtc::TimeDelta::Micros(timestamp_us));
  20. }
  21. } // end namespace webrtc
  22. } // end namespace unity