#include <limits>
#include <memory>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/cpu.h"
#include "base/files/file_util.h"
#include "base/functional/callback_helpers.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/test/bind.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "build/build_config.h"
#include "media/base/decoder_buffer.h"
#include "media/base/encryption_scheme.h"
#include "media/base/media_switches.h"
#include "media/base/media_util.h"
#include "media/base/test_data_util.h"
#include "media/base/video_decoder_config.h"
#include "media/base/video_transformation.h"
#include "media/filters/dav1d_video_decoder.h"
#include "media/gpu/test/video_bitstream.h"
#include "media/gpu/test/video_decode_accelerator_test_suite.h"
#include "media/gpu/test/video_frame_file_writer.h"
#include "media/gpu/test/video_frame_validator.h"
#include "media/gpu/test/video_player/decoder_listener.h"
#include "media/gpu/test/video_player/decoder_wrapper.h"
#include "media/gpu/test/video_player/frame_renderer_dummy.h"
#include "media/gpu/test/video_player/video_player_test_environment.h"
#include "media/gpu/test/video_test_helpers.h"
#include "media/media_buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
#include "media/gpu/chromeos/video_decoder_pipeline.h"
#endif
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
#include "media/gpu/chromeos/platform_video_frame_pool.h"
#endif
namespace media {
namespace test {
namespace {
media::test::VideoDecodeAcceleratorTestSuite* g_env;
class VideoDecoderTest : public ::testing::Test { … };
}
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
TEST_F(VideoDecoderTest, GetSupportedConfigs) { … }
#endif
TEST_F(VideoDecoderTest, Initialize) { … }
TEST_F(VideoDecoderTest, Reinitialize) { … }
TEST_F(VideoDecoderTest, ReinitializeThenPlayThenInitialize) { … }
TEST_F(VideoDecoderTest, DestroyBeforeInitialize) { … }
#if BUILDFLAG(USE_V4L2_CODEC)
TEST_F(VideoDecoderTest, Decode) {
auto tvp = CreateDecoderListener(g_env->Video());
tvp->Play();
const size_t kNumDecodeBuffers = 8;
EXPECT_TRUE(tvp->WaitForEvent(DecoderListener::Event::kDecoderBufferAccepted,
kNumDecodeBuffers));
}
TEST_F(VideoDecoderTest, AllDecoderBuffersAcceptedForDecoding) {
auto tvp = CreateDecoderListener(g_env->Video());
tvp->Play();
EXPECT_TRUE(tvp->WaitForEvent(DecoderListener::Event::kDecoderBufferAccepted,
g_env->Video()->NumFrames()));
base::PlatformThread::Sleep(base::Milliseconds(100));
}
#endif
TEST_F(VideoDecoderTest, FlushAtEndOfStream) { … }
#if BUILDFLAG(USE_V4L2_CODEC)
TEST_F(VideoDecoderTest, DISABLED_FlushMidStream) {
if (!base::FeatureList::IsEnabled(kV4L2FlatStatefulVideoDecoder)) {
GTEST_SKIP();
}
auto tvp = CreateDecoderListener(g_env->Video());
tvp->Play();
const size_t flush_location_in_frames =
std::min(static_cast<size_t>(10), g_env->Video()->NumFrames() / 2);
EXPECT_TRUE(tvp->WaitForFrameDecoded(flush_location_in_frames));
tvp->Flush();
EXPECT_TRUE(tvp->WaitForFlushDone());
EXPECT_GE(tvp->GetFrameDecodedCount(), flush_location_in_frames);
tvp->Play();
EXPECT_TRUE(tvp->WaitForFlushDone());
EXPECT_EQ(tvp->GetFlushDoneCount(), 2u);
const bool has_b_frames = g_env->Video()->Codec() == VideoCodec::kH264;
if (!has_b_frames)
EXPECT_EQ(tvp->GetFrameDecodedCount(), g_env->Video()->NumFrames());
else
EXPECT_LE(tvp->GetFrameDecodedCount(), g_env->Video()->NumFrames());
EXPECT_TRUE(tvp->WaitForFrameProcessors());
}
#endif
TEST_F(VideoDecoderTest, FlushAfterInitialize) { … }
TEST_F(VideoDecoderTest, ResetAfterInitialize) { … }
TEST_F(VideoDecoderTest, ResetMidStream) { … }
TEST_F(VideoDecoderTest, ResetEndOfStream) { … }
TEST_F(VideoDecoderTest, ResetBeforeFlushDone) { … }
TEST_F(VideoDecoderTest, ResetAfterFirstConfigInfo) { … }
TEST_F(VideoDecoderTest, ResolutionChangeAbortedByReset) { … }
TEST_F(VideoDecoderTest, FlushAtEndOfStream_MultipleOutstandingDecodes) { … }
TEST_F(VideoDecoderTest, FlushAtEndOfStream_MultipleConcurrentDecodes) { … }
TEST_F(VideoDecoderTest, InitializeWithNonSupportedConfig) { … }
}
}
int main(int argc, char** argv) { … }