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