Commit fb154a3b authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Reuse decoder after FuchsiaVideoDecoder re-initialization.

Previously FuchsiaVideoDecoder was creating a new StreamProcessor
instance every time Initialize() is called. This was not working
correctly with decoders that do not support more than once instance.
Fixed Initialize() to reuse StreamProcessor if it was initialized for
the same codec.

Bug: 1003529
Change-Id: I268c73f7e325eeb22be5bc2ad355d5b0f54b8659
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1814328
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698746}
parent 34b25bed
......@@ -189,7 +189,7 @@ class FuchsiaVideoDecoderTest : public testing::Test {
}
~FuchsiaVideoDecoderTest() override = default;
bool Initialize(VideoDecoderConfig config) WARN_UNUSED_RESULT {
bool InitializeDecoder(VideoDecoderConfig config) WARN_UNUSED_RESULT {
base::RunLoop run_loop;
bool init_cb_result = false;
decoder_->Initialize(
......@@ -201,13 +201,20 @@ class FuchsiaVideoDecoderTest : public testing::Test {
},
&init_cb_result, &run_loop),
base::BindRepeating(&FuchsiaVideoDecoderTest::OnVideoFrame,
base::Unretained(this)),
weak_factory_.GetWeakPtr()),
base::NullCallback());
run_loop.Run();
return init_cb_result;
}
void ResetDecoder() {
base::RunLoop run_loop;
decoder_->Reset(base::BindRepeating(
[](base::RunLoop* run_loop) { run_loop->Quit(); }, &run_loop));
run_loop.Run();
}
void OnVideoFrame(scoped_refptr<VideoFrame> frame) {
num_output_frames_++;
CHECK(frame->HasTextures());
......@@ -220,9 +227,10 @@ class FuchsiaVideoDecoderTest : public testing::Test {
}
void DecodeBuffer(scoped_refptr<DecoderBuffer> buffer) {
decoder_->Decode(buffer, base::BindRepeating(
&FuchsiaVideoDecoderTest::OnFrameDecoded,
base::Unretained(this), num_input_buffers_));
decoder_->Decode(
buffer,
base::BindRepeating(&FuchsiaVideoDecoderTest::OnFrameDecoded,
weak_factory_.GetWeakPtr(), num_input_buffers_));
num_input_buffers_ += 1;
}
......@@ -273,18 +281,32 @@ class FuchsiaVideoDecoderTest : public testing::Test {
// Number of frames that OnVideoFrame() should keep in |output_frames_|.
size_t frames_to_keep_ = 2;
base::WeakPtrFactory<FuchsiaVideoDecoderTest> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(FuchsiaVideoDecoderTest);
};
scoped_refptr<DecoderBuffer> GetH264Frame(size_t frame_num) {
static scoped_refptr<DecoderBuffer> frames[] = {
ReadTestDataFile("h264-320x180-frame-0"),
ReadTestDataFile("h264-320x180-frame-1"),
ReadTestDataFile("h264-320x180-frame-2"),
ReadTestDataFile("h264-320x180-frame-3")};
CHECK_LT(frame_num, base::size(frames));
return frames[frame_num];
}
TEST_F(FuchsiaVideoDecoderTest, CreateAndDestroy) {}
TEST_F(FuchsiaVideoDecoderTest, CreateInitDestroy) {
EXPECT_TRUE(Initialize(TestVideoConfig::NormalH264()));
EXPECT_TRUE(InitializeDecoder(TestVideoConfig::NormalH264()));
}
TEST_F(FuchsiaVideoDecoderTest, DISABLED_VP9) {
ASSERT_TRUE(Initialize(TestVideoConfig::Normal(kCodecVP9)));
ASSERT_TRUE(InitializeDecoder(TestVideoConfig::Normal(kCodecVP9)));
ReadAndDecodeFrame("vp9-I-frame-320x240");
DecodeBuffer(ReadTestDataFile("vp9-I-frame-320x240"));
DecodeBuffer(DecoderBuffer::CreateEOSBuffer());
ASSERT_NO_FATAL_FAILURE(WaitDecodeDone());
......@@ -292,14 +314,59 @@ TEST_F(FuchsiaVideoDecoderTest, DISABLED_VP9) {
}
TEST_F(FuchsiaVideoDecoderTest, H264) {
ASSERT_TRUE(Initialize(TestVideoConfig::NormalH264()));
ASSERT_TRUE(InitializeDecoder(TestVideoConfig::NormalH264()));
DecodeBuffer(GetH264Frame(0));
DecodeBuffer(GetH264Frame(1));
ASSERT_NO_FATAL_FAILURE(WaitDecodeDone());
ReadAndDecodeFrame("h264-320x180-frame-0");
ReadAndDecodeFrame("h264-320x180-frame-1");
DecodeBuffer(GetH264Frame(2));
DecodeBuffer(GetH264Frame(3));
DecodeBuffer(DecoderBuffer::CreateEOSBuffer());
ASSERT_NO_FATAL_FAILURE(WaitDecodeDone());
ReadAndDecodeFrame("h264-320x180-frame-2");
ReadAndDecodeFrame("h264-320x180-frame-3");
EXPECT_EQ(num_output_frames_, 4U);
}
// Verify that the decoder can be re-initialized while there pending decode
// requests.
TEST_F(FuchsiaVideoDecoderTest, ReinitializeH264) {
ASSERT_TRUE(InitializeDecoder(TestVideoConfig::NormalH264()));
DecodeBuffer(GetH264Frame(0));
DecodeBuffer(GetH264Frame(1));
ASSERT_NO_FATAL_FAILURE(WaitDecodeDone());
num_output_frames_ = 0;
// Re-initialize decoder and send the same data again.
ASSERT_TRUE(InitializeDecoder(TestVideoConfig::NormalH264()));
DecodeBuffer(GetH264Frame(0));
DecodeBuffer(GetH264Frame(1));
DecodeBuffer(GetH264Frame(2));
DecodeBuffer(GetH264Frame(3));
DecodeBuffer(DecoderBuffer::CreateEOSBuffer());
ASSERT_NO_FATAL_FAILURE(WaitDecodeDone());
EXPECT_EQ(num_output_frames_, 4U);
}
// Verify that the decoder can be re-initialized after Reset().
TEST_F(FuchsiaVideoDecoderTest, ResetAndReinitializeH264) {
ASSERT_TRUE(InitializeDecoder(TestVideoConfig::NormalH264()));
DecodeBuffer(GetH264Frame(0));
DecodeBuffer(GetH264Frame(1));
ASSERT_NO_FATAL_FAILURE(WaitDecodeDone());
ResetDecoder();
num_output_frames_ = 0;
// Re-initialize decoder and send the same data again.
ASSERT_TRUE(InitializeDecoder(TestVideoConfig::NormalH264()));
DecodeBuffer(GetH264Frame(0));
DecodeBuffer(GetH264Frame(1));
DecodeBuffer(GetH264Frame(2));
DecodeBuffer(GetH264Frame(3));
DecodeBuffer(DecoderBuffer::CreateEOSBuffer());
ASSERT_NO_FATAL_FAILURE(WaitDecodeDone());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment