#include "pch.h" #include "MockVideoRenderer.h" #include #include #include namespace Vav2PlayerUnitTests { MockVideoRenderer::MockVideoRenderer() { } HRESULT MockVideoRenderer::Initialize(uint32_t width, uint32_t height) { m_initializeCallCount++; m_lastInitializeWidth = width; m_lastInitializeHeight = height; if (FAILED(m_initializeResult)) { return m_initializeResult; } m_width = width; m_height = height; m_initialized = true; return S_OK; } void MockVideoRenderer::Shutdown() { m_initialized = false; m_width = 0; m_height = 0; m_renderedFrames.clear(); } bool MockVideoRenderer::IsInitialized() const { return m_initialized; } HRESULT MockVideoRenderer::RenderVideoFrame(const Vav2Player::VideoFrame& frame) { m_renderFrameCallCount++; if (!m_initialized) { return E_FAIL; } if (FAILED(m_renderFrameResult)) { return m_renderFrameResult; } // Store frame for test verification Vav2Player::VideoFrame frameCopy; CopyFrame(frame, frameCopy); m_renderedFrames.push_back(std::move(frameCopy)); // Simulate rendering delay if configured SimulateRenderDelay(); return S_OK; } bool MockVideoRenderer::TryRenderFrame(const Vav2Player::VideoFrame& frame) { m_tryRenderFrameCallCount++; if (!m_initialized || !m_tryRenderFrameResult) { return false; } // Store frame for test verification Vav2Player::VideoFrame frameCopy; CopyFrame(frame, frameCopy); m_renderedFrames.push_back(std::move(frameCopy)); // Simulate rendering delay if configured SimulateRenderDelay(); return true; } HRESULT MockVideoRenderer::Present() { m_presentCallCount++; if (!m_initialized) { return E_FAIL; } return m_presentResult; } HRESULT MockVideoRenderer::Resize(uint32_t width, uint32_t height) { m_resizeCallCount++; if (!m_initialized) { return E_FAIL; } if (FAILED(m_resizeResult)) { return m_resizeResult; } m_width = width; m_height = height; return S_OK; } uint32_t MockVideoRenderer::GetWidth() const { return m_width; } uint32_t MockVideoRenderer::GetHeight() const { return m_height; } void MockVideoRenderer::SetAspectFitMode(bool enabled) { m_aspectFitEnabled = enabled; } void MockVideoRenderer::UpdateContainerSize(uint32_t container_width, uint32_t container_height) { m_containerWidth = container_width; m_containerHeight = container_height; } // Mock control methods void MockVideoRenderer::SetInitializeResult(HRESULT result) { m_initializeResult = result; } void MockVideoRenderer::SetRenderFrameResult(HRESULT result) { m_renderFrameResult = result; } void MockVideoRenderer::SetTryRenderFrameResult(bool success) { m_tryRenderFrameResult = success; } void MockVideoRenderer::SetPresentResult(HRESULT result) { m_presentResult = result; } void MockVideoRenderer::SetResizeResult(HRESULT result) { m_resizeResult = result; } void MockVideoRenderer::SimulateInitializationFailure(bool fail) { m_initializeResult = fail ? E_FAIL : S_OK; } void MockVideoRenderer::SimulateRenderingFailure(bool fail) { m_renderFrameResult = fail ? E_FAIL : S_OK; m_tryRenderFrameResult = !fail; } // Private helper methods void MockVideoRenderer::CopyFrame(const Vav2Player::VideoFrame& source, Vav2Player::VideoFrame& dest) { dest.width = source.width; dest.height = source.height; dest.format = source.format; dest.color_space = source.color_space; dest.timestamp_ns = source.timestamp_ns; dest.frame_index = source.frame_index; // Copy stride information dest.y_stride = source.y_stride; dest.u_stride = source.u_stride; dest.v_stride = source.v_stride; // Copy Y plane if (source.y_plane && source.y_stride > 0 && source.height > 0) { size_t y_size = static_cast(source.y_stride) * source.height; dest.y_plane = std::make_unique(y_size); std::memcpy(dest.y_plane.get(), source.y_plane.get(), y_size); } // Copy U plane if (source.u_plane && source.u_stride > 0 && source.height > 0) { size_t u_size = static_cast(source.u_stride) * (source.height / 2); // YUV420 assumption dest.u_plane = std::make_unique(u_size); std::memcpy(dest.u_plane.get(), source.u_plane.get(), u_size); } // Copy V plane if (source.v_plane && source.v_stride > 0 && source.height > 0) { size_t v_size = static_cast(source.v_stride) * (source.height / 2); // YUV420 assumption dest.v_plane = std::make_unique(v_size); std::memcpy(dest.v_plane.get(), source.v_plane.get(), v_size); } } void MockVideoRenderer::SimulateRenderDelay() { if (m_renderDelayMs > 0) { auto start = std::chrono::high_resolution_clock::now(); std::this_thread::sleep_for(std::chrono::milliseconds(m_renderDelayMs)); auto end = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast(end - start); m_totalRenderTimeMs += static_cast(duration.count()); } } } // namespace Vav2PlayerUnitTests