chromium/media/mojo/clients/mojo_stable_video_decoder_unittest.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "media/mojo/clients/mojo_stable_video_decoder.h"

#include <sys/mman.h>

#include "base/posix/eintr_wrapper.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "media/base/decoder.h"
#include "media/base/media_util.h"
#include "media/base/supported_video_decoder_config.h"
#include "media/base/video_decoder_config.h"
#include "media/base/video_frame.h"
#include "media/gpu/chromeos/oop_video_decoder.h"
#include "media/mojo/common/media_type_converters.h"
#include "media/mojo/common/mojo_decoder_buffer_converter.h"
#include "media/mojo/mojom/stable/stable_video_decoder.mojom.h"
#include "media/video/mock_gpu_video_accelerator_factories.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gpu_fence.h"

_;
InSequence;
Matcher;
Mock;
Return;
StrictMock;
WithArgs;

namespace media {

namespace {

std::vector<SupportedVideoDecoderConfig> CreateListOfSupportedConfigs() {}

VideoDecoderConfig CreateValidSupportedVideoDecoderConfig() {}

VideoDecoderConfig CreateValidUnsupportedVideoDecoderConfig() {}

// Creates a NV12 stable::mojom::VideoFrame with the given dimensions. The
// VideoFrame is backed by FDs that look like dma-bufs (they actually just point
// to memfd shared memory).
stable::mojom::VideoFramePtr CreateTestNV12DecodedFrame(
    const gfx::Size& coded_size,
    const gfx::Rect& visible_rect,
    const gfx::Size& natural_size,
    base::TimeDelta timestamp) {}

// IsValidSharedImageInfoForNV12Frame() is a custom matcher to help write
// expectations for CreateSharedImage() calls.
// AssertSharedImageInfoIsValidForNV12Frame() is a helper for the matcher.
void AssertSharedImageInfoIsValidForNV12Frame(
    const gpu::SharedImageInfo& actual,
    const gfx::Rect& expected_visible_rect,
    const gfx::ColorSpace& expected_color_space,
    bool* result) {}
MATCHER_P2(IsValidSharedImageInfoForNV12Frame,
           expected_visible_rect,
           expected_color_space,
           "") {}

// IsValidNV12NativeGpuMemoryBufferHandle() is a custom matcher to help write
// expectations for CreateSharedImage() calls.
// AssertNV12NativeGpuMemoryBufferHandleIsValid() is a helper for the matcher.
void AssertNV12NativeGpuMemoryBufferHandleIsValid(
    const gfx::GpuMemoryBufferHandle& actual,
    const gfx::Size& coded_size,
    bool* result) {}
MATCHER_P(IsValidNV12NativeGpuMemoryBufferHandle, coded_size, "") {}

class MockVideoFrameHandleReleaser
    : public stable::mojom::VideoFrameHandleReleaser {};

class MockStableVideoDecoderService : public stable::mojom::StableVideoDecoder {};

}  // namespace

// NOTE: This needs to be outside of an anonymous namespace to allow it to be
// friended by SharedImageInterface.
class MockSharedImageInterface : public gpu::SharedImageInterface {};

namespace {

// TestEndpoints groups a few members that result from creating and initializing
// a MojoStableVideoDecoder so that tests can use them to set expectations
// and/or to poke at them to trigger specific paths.
class TestEndpoints {};

}  // namespace

class MojoStableVideoDecoderTest : public testing::Test {};

TEST_F(MojoStableVideoDecoderTest,
       InitializeWithSupportedConfigConstructsStableVideoDecoder) {}

TEST_F(MojoStableVideoDecoderTest,
       InitializeWithUnsupportedConfigDoesNotConstructStableVideoDecoder) {}

TEST_F(MojoStableVideoDecoderTest,
       TwoInitializationsWithSupportedConfigsConstructStableVideoDecoderOnce) {}

// This test sends four frames to the service for decoding and expects to
// receive four decoded frames. The order and properties of these decoded frames
// plus the timing for releasing them ensures we exercise some of the difficult
// lifetime corner cases (more details inside the test).
TEST_F(MojoStableVideoDecoderTest, Decode) {}

TEST_F(MojoStableVideoDecoderTest, Reset) {}

}  // namespace media