VideoRendererTest.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "pch.h"
  2. #include "Context.h"
  3. #include "GraphicsDevice/IGraphicsDevice.h"
  4. #include "GraphicsDevice/ITexture2D.h"
  5. #include "GraphicsDeviceTestBase.h"
  6. #include "UnityVideoRenderer.h"
  7. #include "UnityVideoTrackSource.h"
  8. #include <api/task_queue/default_task_queue_factory.h>
  9. using testing::_;
  10. using testing::Invoke;
  11. using testing::Mock;
  12. namespace unity
  13. {
  14. namespace webrtc
  15. {
  16. const int kWidth = 256;
  17. const int kHeight = 256;
  18. class VideoRendererTest : public GraphicsDeviceTestBase
  19. {
  20. public:
  21. VideoRendererTest()
  22. : m_taskQueueFactory(CreateDefaultTaskQueueFactory())
  23. {
  24. m_callback = &OnFrameSizeChange;
  25. m_renderer = std::make_unique<UnityVideoRenderer>(1, m_callback, true);
  26. }
  27. ~VideoRendererTest() override = default;
  28. protected:
  29. void SetUp() override
  30. {
  31. if (!device())
  32. GTEST_SKIP() << "The graphics driver is not installed on the device.";
  33. m_texture.reset(device()->CreateDefaultTextureV(kWidth, kHeight, format()));
  34. EXPECT_TRUE(device()->WaitIdleForTest());
  35. ContextDependencies dependencies;
  36. dependencies.device = device();
  37. context = std::make_unique<Context>(dependencies);
  38. }
  39. std::unique_ptr<Context> context;
  40. std::unique_ptr<ITexture2D> m_texture;
  41. std::unique_ptr<TaskQueueFactory> m_taskQueueFactory;
  42. std::unique_ptr<UnityVideoRenderer> m_renderer;
  43. DelegateVideoFrameResize m_callback;
  44. ::webrtc::VideoFrame::Builder CreateBlackFrameBuilder(int width, int height)
  45. {
  46. rtc::scoped_refptr<webrtc::I420Buffer> buffer = webrtc::I420Buffer::Create(width, height);
  47. webrtc::I420Buffer::SetBlack(buffer);
  48. return ::webrtc::VideoFrame::Builder().set_video_frame_buffer(buffer).set_timestamp_us(
  49. Clock::GetRealTimeClock()->TimeInMicroseconds());
  50. }
  51. static void OnFrameSizeChange(UnityVideoRenderer* renderer, int width, int height) { }
  52. };
  53. TEST_P(VideoRendererTest, SetAndGetFrameBuffer)
  54. {
  55. EXPECT_EQ(nullptr, m_renderer->GetFrameBuffer());
  56. auto builder = CreateBlackFrameBuilder(kWidth, kHeight);
  57. m_renderer->OnFrame(builder.build());
  58. EXPECT_NE(nullptr, m_renderer->GetFrameBuffer());
  59. }
  60. TEST_P(VideoRendererTest, ConvertVideoFrameToTexture)
  61. {
  62. auto builder = CreateBlackFrameBuilder(kWidth, kHeight);
  63. m_renderer->OnFrame(builder.build());
  64. void* data = m_renderer->ConvertVideoFrameToTextureAndWriteToBuffer(kWidth, kHeight, libyuv::FOURCC_ARGB);
  65. EXPECT_NE(nullptr, data);
  66. }
  67. INSTANTIATE_TEST_SUITE_P(GfxDeviceAndColorSpece, VideoRendererTest, testing::ValuesIn(VALUES_TEST_ENV));
  68. } // end namespace webrtc
  69. } // end namespace unity