Commit de4f5859 authored by Jose Lopes's avatar Jose Lopes Committed by Commit Bot

Migrate callbacks in media unittests.

Remove base::Callback in some media unittests.

The following callbacks are called every time a texture is created:
* https://cs.chromium.org/chromium/src/media/renderers/paint_canvas_video_renderer_unittest.cc?rcl=f511dfda653e4f840e520384df599885ae827039&l=934
* https://cs.chromium.org/chromium/src/media/renderers/paint_canvas_video_renderer_unittest.cc?rcl=f511dfda653e4f840e520384df599885ae827039&l=949

The following callback is used in a factory:
* https://cs.chromium.org/chromium/src/media/mojo/test/mojo_video_decoder_integration_test.cc?rcl=99887411e48037a3d41ab6862b460d1f501fea34&l=193

The following base::Callback definition can be omitted by rewriting the gmock code:
* https://cs.chromium.org/chromium/src/media/filters/source_buffer_state_unittest.cc?rcl=f5dd4b5e849703668bd1e606eb6b6dc43027a1ac&l=55

The following callback is called on a stream until false is returned:
* https://cs.chromium.org/chromium/src/media/gpu/video_encode_accelerator_unittest.cc?rcl=f5dd4b5e849703668bd1e606eb6b6dc43027a1ac&l=849

The following callback is called on every frame:
* https://cs.chromium.org/chromium/src/media/remoting/end2end_test_renderer.cc?rcl=f5dd4b5e849703668bd1e606eb6b6dc43027a1ac&l=61

This is part of the base::Callback migration.

Context: https://cs.chromium.org/chromium/src/docs/callback.md?rcl=9fcc3764aea8f97e9f6de4a9ee61d554e67edcda&l=40

Bug: 714018
Change-Id: I568b22ff281c0217f1cb49f6fe9a040cefd24d72
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2058953
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Auto-Submit: Jose Lopes <jabolopes@google.com>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742224}
parent aceb0f9f
......@@ -22,6 +22,7 @@ namespace media {
using base::test::RunClosure;
using testing::_;
using testing::InvokeWithoutArgs;
using testing::SaveArg;
namespace {
......@@ -52,11 +53,7 @@ void AddVideoTrack(std::unique_ptr<MediaTracks>& t, VideoCodec codec, int id) {
MediaTrack::Label(), MediaTrack::Language());
}
void InvokeCbAndSaveResult(const base::Callback<bool()>& cb, bool* result) {
DCHECK(result);
*result = cb.Run();
}
}
} // namespace
class SourceBufferStateTest : public ::testing::Test {
public:
......@@ -117,14 +114,12 @@ class SourceBufferStateTest : public ::testing::Test {
StreamParser::TextTrackConfigMap text_track_config_map;
bool new_configs_result = false;
base::Closure new_configs_closure =
base::Bind(InvokeCbAndSaveResult,
base::Bind(new_config_cb_, base::Passed(std::move(tracks)),
text_track_config_map),
&new_configs_result);
EXPECT_CALL(*mock_stream_parser_, Parse(stream_data, data_size))
.WillOnce(testing::DoAll(RunClosure(new_configs_closure),
testing::Return(true)));
.WillOnce(InvokeWithoutArgs([&] {
new_configs_result =
new_config_cb_.Run(std::move(tracks), text_track_config_map);
return true;
}));
sbs->Append(stream_data, data_size, t, t, &t);
return new_configs_result;
}
......
......@@ -846,23 +846,23 @@ class StreamValidator {
// buffer, passing true if the frame is a keyframe and the visible size.
// Returns false if we are not interested in more frames and further
// processing should be aborted.
typedef base::Callback<bool(bool, const gfx::Size&)> FrameFoundCallback;
typedef base::RepeatingCallback<bool(bool, const gfx::Size&)>
FrameFoundCallback;
virtual ~StreamValidator() {}
// Provide a StreamValidator instance for the given |profile| and |level|.
// |level| is optional and should specified only if codec is h264.
static std::unique_ptr<StreamValidator> Create(
VideoCodecProfile profile,
base::Optional<uint8_t> level,
const FrameFoundCallback& frame_cb);
static std::unique_ptr<StreamValidator> Create(VideoCodecProfile profile,
base::Optional<uint8_t> level,
FrameFoundCallback frame_cb);
// Process and verify contents of a bitstream buffer.
virtual void ProcessStreamBuffer(const uint8_t* stream, size_t size) = 0;
protected:
explicit StreamValidator(const FrameFoundCallback& frame_cb)
: frame_cb_(frame_cb) {}
explicit StreamValidator(FrameFoundCallback frame_cb)
: frame_cb_(std::move(frame_cb)) {}
FrameFoundCallback frame_cb_;
gfx::Size visible_size_;
......@@ -870,9 +870,8 @@ class StreamValidator {
class H264Validator : public StreamValidator {
public:
H264Validator(base::Optional<uint8_t> level,
const FrameFoundCallback& frame_cb)
: StreamValidator(frame_cb),
H264Validator(base::Optional<uint8_t> level, FrameFoundCallback frame_cb)
: StreamValidator(std::move(frame_cb)),
target_level_(level),
seen_sps_(false),
seen_pps_(false),
......@@ -1005,8 +1004,8 @@ bool H264Validator::UpdateCurrentPicture(const H264SliceHeader& slice_hdr) {
class VP8Validator : public StreamValidator {
public:
explicit VP8Validator(const FrameFoundCallback& frame_cb)
: StreamValidator(frame_cb), seen_keyframe_(false) {}
explicit VP8Validator(FrameFoundCallback frame_cb)
: StreamValidator(std::move(frame_cb)), seen_keyframe_(false) {}
void ProcessStreamBuffer(const uint8_t* stream, size_t size) override;
......@@ -1034,8 +1033,10 @@ void VP8Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) {
class VP9Validator : public StreamValidator {
public:
explicit VP9Validator(const FrameFoundCallback& frame_cb)
: StreamValidator(frame_cb), parser_(false), seen_keyframe_(false) {}
explicit VP9Validator(FrameFoundCallback frame_cb)
: StreamValidator(std::move(frame_cb)),
parser_(false),
seen_keyframe_(false) {}
void ProcessStreamBuffer(const uint8_t* stream, size_t size) override;
......@@ -1067,15 +1068,15 @@ void VP9Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) {
std::unique_ptr<StreamValidator> StreamValidator::Create(
VideoCodecProfile profile,
base::Optional<uint8_t> level,
const FrameFoundCallback& frame_cb) {
FrameFoundCallback frame_cb) {
std::unique_ptr<StreamValidator> validator;
if (IsH264(profile)) {
validator.reset(new H264Validator(level, frame_cb));
validator.reset(new H264Validator(level, std::move(frame_cb)));
} else if (IsVP8(profile)) {
validator.reset(new VP8Validator(frame_cb));
validator.reset(new VP8Validator(std::move(frame_cb)));
} else if (IsVP9(profile)) {
validator.reset(new VP9Validator(frame_cb));
validator.reset(new VP9Validator(std::move(frame_cb)));
} else {
LOG(FATAL) << "Unsupported profile: " << GetProfileName(profile);
}
......
......@@ -178,9 +178,9 @@ class MockVideoDecoder : public VideoDecoder {
class FakeMojoMediaClient : public MojoMediaClient {
public:
using CreateVideoDecoderCB =
base::Callback<std::unique_ptr<VideoDecoder>(MediaLog*)>;
base::RepeatingCallback<std::unique_ptr<VideoDecoder>(MediaLog*)>;
FakeMojoMediaClient(CreateVideoDecoderCB create_video_decoder_cb)
explicit FakeMojoMediaClient(CreateVideoDecoderCB create_video_decoder_cb)
: create_video_decoder_cb_(std::move(create_video_decoder_cb)) {}
std::unique_ptr<VideoDecoder> CreateVideoDecoder(
......@@ -204,9 +204,9 @@ class FakeMojoMediaClient : public MojoMediaClient {
class MojoVideoDecoderIntegrationTest : public ::testing::Test {
public:
MojoVideoDecoderIntegrationTest()
: mojo_media_client_(
base::Bind(&MojoVideoDecoderIntegrationTest::CreateVideoDecoder,
base::Unretained(this))) {}
: mojo_media_client_(base::BindRepeating(
&MojoVideoDecoderIntegrationTest::CreateVideoDecoder,
base::Unretained(this))) {}
void TearDown() override {
if (client_) {
......
......@@ -30,17 +30,17 @@ namespace {
class TestStreamSender final : public mojom::RemotingDataStreamSender {
public:
using SendFrameToSinkCallback =
base::Callback<void(const std::vector<uint8_t>& data,
DemuxerStream::Type type)>;
base::RepeatingCallback<void(const std::vector<uint8_t>& data,
DemuxerStream::Type type)>;
TestStreamSender(
mojo::PendingReceiver<mojom::RemotingDataStreamSender> receiver,
mojo::ScopedDataPipeConsumerHandle handle,
DemuxerStream::Type type,
const SendFrameToSinkCallback& callback)
SendFrameToSinkCallback callback)
: receiver_(this, std::move(receiver)),
data_pipe_reader_(std::move(handle)),
type_(type),
send_frame_to_sink_cb_(callback) {}
send_frame_to_sink_cb_(std::move(callback)) {}
~TestStreamSender() override = default;
......@@ -75,13 +75,12 @@ class TestRemoter final : public mojom::Remoter {
public:
using SendMessageToSinkCallback =
base::RepeatingCallback<void(const std::vector<uint8_t>& message)>;
TestRemoter(
mojo::PendingRemote<mojom::RemotingSource> source,
const SendMessageToSinkCallback& send_message_to_sink_cb,
const TestStreamSender::SendFrameToSinkCallback& send_frame_to_sink_cb)
TestRemoter(mojo::PendingRemote<mojom::RemotingSource> source,
SendMessageToSinkCallback send_message_to_sink_cb,
TestStreamSender::SendFrameToSinkCallback send_frame_to_sink_cb)
: source_(std::move(source)),
send_message_to_sink_cb_(send_message_to_sink_cb),
send_frame_to_sink_cb_(send_frame_to_sink_cb) {}
send_message_to_sink_cb_(std::move(send_message_to_sink_cb)),
send_frame_to_sink_cb_(std::move(send_frame_to_sink_cb)) {}
~TestRemoter() override = default;
......@@ -137,15 +136,15 @@ class TestRemoter final : public mojom::Remoter {
};
std::unique_ptr<RendererController> CreateController(
const TestRemoter::SendMessageToSinkCallback& send_message_to_sink_cb,
const TestStreamSender::SendFrameToSinkCallback& send_frame_to_sink_cb) {
TestRemoter::SendMessageToSinkCallback send_message_to_sink_cb,
TestStreamSender::SendFrameToSinkCallback send_frame_to_sink_cb) {
mojo::PendingRemote<mojom::RemotingSource> remoting_source;
auto remoting_source_receiver =
remoting_source.InitWithNewPipeAndPassReceiver();
mojo::PendingRemote<mojom::Remoter> remoter;
std::unique_ptr<TestRemoter> test_remoter = std::make_unique<TestRemoter>(
std::move(remoting_source), send_message_to_sink_cb,
send_frame_to_sink_cb);
std::move(remoting_source), std::move(send_message_to_sink_cb),
std::move(send_frame_to_sink_cb));
mojo::MakeSelfOwnedReceiver(std::move(test_remoter),
remoter.InitWithNewPipeAndPassReceiver());
return std::make_unique<RendererController>(
......
......@@ -951,26 +951,26 @@ class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
}
}
base::Callback<void(GLenum target,
GLint level,
GLint internalformat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const void* pixels)>
base::RepeatingCallback<void(GLenum target,
GLint level,
GLint internalformat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const void* pixels)>
teximage2d_callback_;
base::Callback<void(GLenum target,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const void* pixels)>
base::RepeatingCallback<void(GLenum target,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const void* pixels)>
texsubimage2d_callback_;
};
......
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