Commit 4921ae20 authored by Chih-Yu Huang's avatar Chih-Yu Huang Committed by Commit Bot

media: Add SimpleSyncTokenClient class.

In MojoVDService and some unittest we duplicate a simple
implementation of VideoFrame::SyncTokenClient. This CL moved it to a
separate file.

BUG=522298
TEST=media_unittests

Change-Id: I18009712977a12b31cc8136ef79a230b34667384
Reviewed-on: https://chromium-review.googlesource.com/c/1460741
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Auto-Submit: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630692}
parent 01c835bf
......@@ -235,6 +235,8 @@ jumbo_source_set("base") {
"serial_runner.h",
"silent_sink_suspender.cc",
"silent_sink_suspender.h",
"simple_sync_token_client.cc",
"simple_sync_token_client.h",
"sinc_resampler.cc",
"sinc_resampler.h",
"stream_parser.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/base/simple_sync_token_client.h"
namespace media {
SimpleSyncTokenClient::SimpleSyncTokenClient(const gpu::SyncToken& sync_token)
: sync_token_(sync_token) {}
void SimpleSyncTokenClient::GenerateSyncToken(gpu::SyncToken* sync_token) {
*sync_token = sync_token_;
}
void SimpleSyncTokenClient::WaitSyncToken(const gpu::SyncToken& sync_token) {}
} // namespace media
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_BASE_SIMPLE_SYNC_TOKEN_CLIENT_H_
#define MEDIA_BASE_SIMPLE_SYNC_TOKEN_CLIENT_H_
#include "base/macros.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "media/base/media_export.h"
#include "media/base/video_frame.h"
namespace media {
class MEDIA_EXPORT SimpleSyncTokenClient : public VideoFrame::SyncTokenClient {
public:
explicit SimpleSyncTokenClient(const gpu::SyncToken& sync_token);
void GenerateSyncToken(gpu::SyncToken* sync_token) final;
void WaitSyncToken(const gpu::SyncToken& sync_token) final;
private:
gpu::SyncToken sync_token_;
DISALLOW_COPY_AND_ASSIGN(SimpleSyncTokenClient);
};
} // namespace media
#endif // MEDIA_BASE_SIMPLE_SYNC_TOKEN_CLIENT_H_
......@@ -19,6 +19,7 @@
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/mailbox_holder.h"
#include "media/base/simple_sync_token_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libyuv/include/libyuv.h"
......@@ -467,24 +468,6 @@ TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) {
EXPECT_FALSE(called_sync_token.HasData());
}
namespace {
class SyncTokenClientImpl : public VideoFrame::SyncTokenClient {
public:
explicit SyncTokenClientImpl(const gpu::SyncToken& sync_token)
: sync_token_(sync_token) {}
~SyncTokenClientImpl() override = default;
void GenerateSyncToken(gpu::SyncToken* sync_token) override {
*sync_token = sync_token_;
}
void WaitSyncToken(const gpu::SyncToken& sync_token) override {}
private:
gpu::SyncToken sync_token_;
};
} // namespace
// Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is
// destroyed with the release sync point, which was updated by clients.
// (i.e. the compositor, webgl).
......@@ -532,7 +515,7 @@ TEST(VideoFrame,
EXPECT_EQ(sync_token, mailbox_holder.sync_token);
}
SyncTokenClientImpl client(release_sync_token);
SimpleSyncTokenClient client(release_sync_token);
frame->UpdateReleaseSyncToken(&client);
EXPECT_EQ(sync_token,
frame->mailbox_holder(VideoFrame::kYPlane).sync_token);
......
......@@ -10,34 +10,12 @@
#include "base/memory/scoped_refptr.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_task_environment.h"
#include "media/base/simple_sync_token_client.h"
#include "media/gpu/fake_command_buffer_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace {
// TODO(sandersd): Should be part of //media, as it is used by
// MojoVideoDecoderService (production code) as well.
class StaticSyncTokenClient : public VideoFrame::SyncTokenClient {
public:
explicit StaticSyncTokenClient(const gpu::SyncToken& sync_token)
: sync_token_(sync_token) {}
void GenerateSyncToken(gpu::SyncToken* sync_token) final {
*sync_token = sync_token_;
}
void WaitSyncToken(const gpu::SyncToken& sync_token) final {}
private:
gpu::SyncToken sync_token_;
DISALLOW_COPY_AND_ASSIGN(StaticSyncTokenClient);
};
} // namespace
class PictureBufferManagerImplTest : public testing::Test {
public:
explicit PictureBufferManagerImplTest() {
......@@ -88,7 +66,7 @@ class PictureBufferManagerImplTest : public testing::Test {
gpu::SyncToken sync_token(gpu::GPU_IO,
gpu::CommandBufferId::FromUnsafeValue(1),
next_release_count_++);
StaticSyncTokenClient sync_token_client(sync_token);
SimpleSyncTokenClient sync_token_client(sync_token);
video_frame->UpdateReleaseSyncToken(&sync_token_client);
return sync_token;
}
......
......@@ -20,6 +20,7 @@
#include "media/base/decoder_buffer.h"
#include "media/base/media_util.h"
#include "media/base/mock_media_log.h"
#include "media/base/simple_sync_token_client.h"
#include "media/base/video_codecs.h"
#include "media/base/video_frame.h"
#include "media/base/video_rotation.h"
......@@ -53,25 +54,6 @@ scoped_refptr<DecoderBuffer> CreateDecoderBuffer(base::TimeDelta timestamp) {
return buffer;
}
// TODO(sandersd): Should be part of //media, as it is used by
// MojoVideoDecoderService (production code) as well.
class StaticSyncTokenClient : public VideoFrame::SyncTokenClient {
public:
explicit StaticSyncTokenClient(const gpu::SyncToken& sync_token)
: sync_token_(sync_token) {}
void GenerateSyncToken(gpu::SyncToken* sync_token) final {
*sync_token = sync_token_;
}
void WaitSyncToken(const gpu::SyncToken& sync_token) final {}
private:
gpu::SyncToken sync_token_;
DISALLOW_COPY_AND_ASSIGN(StaticSyncTokenClient);
};
VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles() {
VideoDecodeAccelerator::SupportedProfiles profiles;
{
......@@ -279,7 +261,7 @@ class VdaVideoDecoderTest : public testing::TestWithParam<bool> {
gpu::SyncToken sync_token(gpu::GPU_IO,
gpu::CommandBufferId::FromUnsafeValue(1),
next_release_count_++);
StaticSyncTokenClient sync_token_client(sync_token);
SimpleSyncTokenClient sync_token_client(sync_token);
video_frame->UpdateReleaseSyncToken(&sync_token_client);
return sync_token;
}
......
......@@ -13,6 +13,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "media/base/cdm_context.h"
#include "media/base/decoder_buffer.h"
#include "media/base/simple_sync_token_client.h"
#include "media/base/video_decoder.h"
#include "media/base/video_decoder_config.h"
#include "media/base/video_frame.h"
......@@ -41,26 +42,6 @@ const char kInitializeTraceName[] = "MojoVideoDecoderService::Initialize";
const char kDecodeTraceName[] = "MojoVideoDecoderService::Decode";
const char kResetTraceName[] = "MojoVideoDecoderService::Reset";
class StaticSyncTokenClient : public VideoFrame::SyncTokenClient {
public:
explicit StaticSyncTokenClient(const gpu::SyncToken& sync_token)
: sync_token_(sync_token) {}
// VideoFrame::SyncTokenClient implementation
void GenerateSyncToken(gpu::SyncToken* sync_token) final {
*sync_token = sync_token_;
}
void WaitSyncToken(const gpu::SyncToken& sync_token) final {
// NOP; we don't care what the old sync token was.
}
private:
gpu::SyncToken sync_token_;
DISALLOW_COPY_AND_ASSIGN(StaticSyncTokenClient);
};
} // namespace
class VideoFrameHandleReleaserImpl final
......@@ -92,7 +73,7 @@ class VideoFrameHandleReleaserImpl final
mojo::ReportBadMessage("Unknown |release_token|.");
return;
}
StaticSyncTokenClient client(release_sync_token);
SimpleSyncTokenClient client(release_sync_token);
it->second->UpdateReleaseSyncToken(&client);
video_frames_.erase(it);
}
......
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