summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--chrome/renderer/media/audio_renderer_impl_unittest.cc19
-rw-r--r--media/base/mock_filters.h36
-rw-r--r--media/base/pipeline_impl_unittest.cc64
-rw-r--r--media/filters/audio_renderer_base_unittest.cc13
-rw-r--r--media/filters/video_renderer_base_unittest.cc16
6 files changed, 97 insertions, 52 deletions
diff --git a/AUTHORS b/AUTHORS
index 87b7df9..d027efd 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -54,3 +54,4 @@ Bruno Calvignac <brunocalvignac@gmail.com>
Jaime Soriano Pastor <jsorianopastor@gmail.com>
Bryan Donlan <bdonlan@gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com>
+Dominic Jodoin <dominic.jodoin@gmail.com> \ No newline at end of file
diff --git a/chrome/renderer/media/audio_renderer_impl_unittest.cc b/chrome/renderer/media/audio_renderer_impl_unittest.cc
index a3b3420..601fa31 100644
--- a/chrome/renderer/media/audio_renderer_impl_unittest.cc
+++ b/chrome/renderer/media/audio_renderer_impl_unittest.cc
@@ -5,10 +5,13 @@
#include "chrome/common/render_messages.h"
#include "chrome/renderer/media/audio_renderer_impl.h"
#include "media/base/data_buffer.h"
+#include "media/base/media_format.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
#include "testing/gtest/include/gtest/gtest.h"
+using ::testing::ReturnRef;
+
class AudioRendererImplTest : public ::testing::Test {
public:
static const int kRouteId = 0;
@@ -28,7 +31,16 @@ class AudioRendererImplTest : public ::testing::Test {
// Setup expectations for initialization.
EXPECT_CALL(callback_, OnFilterCallback());
EXPECT_CALL(callback_, OnCallbackDestroyed());
- decoder_ = new media::MockAudioDecoder(2, 48000, 16);
+ decoder_ = new media::MockAudioDecoder();
+
+ // Associate media format with decoder
+ decoder_media_format_.SetAsString(media::MediaFormat::kMimeType,
+ media::mime_type::kUncompressedAudio);
+ decoder_media_format_.SetAsInteger(media::MediaFormat::kChannels, 2);
+ decoder_media_format_.SetAsInteger(media::MediaFormat::kSampleRate, 48000);
+ decoder_media_format_.SetAsInteger(media::MediaFormat::kSampleBits, 16);
+ EXPECT_CALL(*decoder_, media_format())
+ .WillRepeatedly(ReturnRef(decoder_media_format_));
// Create and initialize audio renderer.
renderer_ = new AudioRendererImpl(filter_);
@@ -53,6 +65,7 @@ class AudioRendererImplTest : public ::testing::Test {
media::MockFilterCallback callback_;
scoped_refptr<media::MockAudioDecoder> decoder_;
scoped_refptr<AudioRendererImpl> renderer_;
+ media::MediaFormat decoder_media_format_;
private:
DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest);
@@ -66,15 +79,15 @@ TEST_F(AudioRendererImplTest, SetPlaybackRate) {
renderer_->SetPlaybackRate(1.0f);
renderer_->SetPlaybackRate(0.0f);
- message_loop_->RunAllPending();
renderer_->Stop();
+ message_loop_->RunAllPending();
}
TEST_F(AudioRendererImplTest, SetVolume) {
// Execute SetVolume() codepath to create an IPC message.
renderer_->SetVolume(0.5f);
- message_loop_->RunAllPending();
renderer_->Stop();
+ message_loop_->RunAllPending();
}
TEST_F(AudioRendererImplTest, Stop) {
diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h
index e140818..ca60179 100644
--- a/media/base/mock_filters.h
+++ b/media/base/mock_filters.h
@@ -101,7 +101,7 @@ class MockDataSource : public DataSource {
// DataSource implementation.
MOCK_METHOD2(Initialize, void(const std::string& url,
FilterCallback* callback));
- const MediaFormat& media_format() { return media_format_; }
+ MOCK_METHOD0(media_format, const MediaFormat&());
MOCK_METHOD4(Read, void(int64 position, size_t size, uint8* data,
DataSource::ReadCallback* callback));
MOCK_METHOD1(GetSize, bool(int64* size_out));
@@ -111,8 +111,6 @@ class MockDataSource : public DataSource {
virtual ~MockDataSource() {}
private:
- MediaFormat media_format_;
-
DISALLOW_COPY_AND_ASSIGN(MockDataSource);
};
@@ -143,14 +141,8 @@ class MockDemuxerStream : public DemuxerStream {
public:
MockDemuxerStream() {}
- // Sets the mime type of this object's media format, which is usually checked
- // to determine the type of decoder to create.
- explicit MockDemuxerStream(const std::string& mime_type) {
- media_format_.SetAsString(MediaFormat::kMimeType, mime_type);
- }
-
// DemuxerStream implementation.
- const MediaFormat& media_format() { return media_format_; }
+ MOCK_METHOD0(media_format, const MediaFormat&());
MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback));
MOCK_METHOD1(QueryInterface, void*(const char* interface_id));
@@ -167,13 +159,6 @@ class MockVideoDecoder : public VideoDecoder {
public:
MockVideoDecoder() {}
- // Sets the essential media format keys for this decoder.
- MockVideoDecoder(const std::string& mime_type, int width, int height) {
- media_format_.SetAsString(MediaFormat::kMimeType, mime_type);
- media_format_.SetAsInteger(MediaFormat::kWidth, width);
- media_format_.SetAsInteger(MediaFormat::kHeight, height);
- }
-
// MediaFilter implementation.
MOCK_METHOD0(Stop, void());
MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
@@ -183,15 +168,13 @@ class MockVideoDecoder : public VideoDecoder {
// VideoDecoder implementation.
MOCK_METHOD2(Initialize, void(DemuxerStream* stream,
FilterCallback* callback));
- const MediaFormat& media_format() { return media_format_; }
+ MOCK_METHOD0(media_format, const MediaFormat&());
MOCK_METHOD1(Read, void(Callback1<VideoFrame*>::Type* read_callback));
protected:
virtual ~MockVideoDecoder() {}
private:
- MediaFormat media_format_;
-
DISALLOW_COPY_AND_ASSIGN(MockVideoDecoder);
};
@@ -199,15 +182,6 @@ class MockAudioDecoder : public AudioDecoder {
public:
MockAudioDecoder() {}
- // Sets the essential media format keys for this decoder.
- MockAudioDecoder(int channels, int sample_rate, int sample_bits) {
- media_format_.SetAsString(MediaFormat::kMimeType,
- mime_type::kUncompressedAudio);
- media_format_.SetAsInteger(MediaFormat::kChannels, channels);
- media_format_.SetAsInteger(MediaFormat::kSampleRate, sample_rate);
- media_format_.SetAsInteger(MediaFormat::kSampleBits, sample_bits);
- }
-
// MediaFilter implementation.
MOCK_METHOD0(Stop, void());
MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
@@ -217,15 +191,13 @@ class MockAudioDecoder : public AudioDecoder {
// AudioDecoder implementation.
MOCK_METHOD2(Initialize, void(DemuxerStream* stream,
FilterCallback* callback));
- const MediaFormat& media_format() { return media_format_; }
+ MOCK_METHOD0(media_format, const MediaFormat&());
MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback));
protected:
virtual ~MockAudioDecoder() {}
private:
- MediaFormat media_format_;
-
DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder);
};
diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc
index e7681da..2a2e556 100644
--- a/media/base/pipeline_impl_unittest.cc
+++ b/media/base/pipeline_impl_unittest.cc
@@ -4,6 +4,7 @@
#include <string>
+#include "base/stl_util-inl.h"
#include "base/waitable_event.h"
#include "media/base/pipeline_impl.h"
#include "media/base/media_format.h"
@@ -19,6 +20,7 @@ using ::testing::Invoke;
using ::testing::Mock;
using ::testing::NotNull;
using ::testing::Return;
+using ::testing::ReturnRef;
using ::testing::StrictMock;
namespace {
@@ -76,6 +78,9 @@ class PipelineImplTest : public ::testing::Test {
pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_),
&CallbackHelper::OnStop));
message_loop_.RunAllPending();
+
+ // Free allocated media formats (if any).
+ STLDeleteElements(&stream_media_formats_);
}
protected:
@@ -89,6 +94,8 @@ class PipelineImplTest : public ::testing::Test {
EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
EXPECT_CALL(*mocks_->data_source(), Stop());
+ EXPECT_CALL(*mocks_->data_source(), media_format())
+ .WillOnce(ReturnRef(data_source_media_format_));
}
// Sets up expectations to allow the demuxer to initialize.
@@ -114,6 +121,22 @@ class PipelineImplTest : public ::testing::Test {
}
}
+ // Create a stream with an associated media format.
+ StrictMock<MockDemuxerStream>* CreateStream(const std::string& mime_type) {
+ StrictMock<MockDemuxerStream>* stream =
+ new StrictMock<MockDemuxerStream>();
+
+ // Sets the mime type of this stream's media format, which is usually
+ // checked to determine the type of decoder to create.
+ MediaFormat* media_format = new MediaFormat();
+ media_format->SetAsString(MediaFormat::kMimeType, mime_type);
+ EXPECT_CALL(*stream, media_format())
+ .WillRepeatedly(ReturnRef(*media_format));
+ stream_media_formats_.push_back(media_format);
+
+ return stream;
+ }
+
// Sets up expectations to allow the video decoder to initialize.
void InitializeVideoDecoder(MockDemuxerStream* stream) {
EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull()))
@@ -122,6 +145,8 @@ class PipelineImplTest : public ::testing::Test {
EXPECT_CALL(*mocks_->video_decoder(), Seek(base::TimeDelta(), NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
EXPECT_CALL(*mocks_->video_decoder(), Stop());
+ EXPECT_CALL(*mocks_->video_decoder(), media_format())
+ .WillOnce(ReturnRef(video_decoder_media_format_));
}
// Sets up expectations to allow the audio decoder to initialize.
@@ -132,6 +157,8 @@ class PipelineImplTest : public ::testing::Test {
EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
EXPECT_CALL(*mocks_->audio_decoder(), Stop());
+ EXPECT_CALL(*mocks_->audio_decoder(), media_format())
+ .WillOnce(ReturnRef(audio_decoder_media_format_));
}
// Sets up expectations to allow the video renderer to initialize.
@@ -174,6 +201,13 @@ class PipelineImplTest : public ::testing::Test {
scoped_refptr<PipelineImpl> pipeline_;
scoped_refptr<media::MockFilterFactory> mocks_;
+ MediaFormat data_source_media_format_;
+ MediaFormat audio_decoder_media_format_;
+ MediaFormat video_decoder_media_format_;
+
+ typedef std::vector<MediaFormat*> MediaFormatVector;
+ MediaFormatVector stream_media_formats_;
+
private:
DISALLOW_COPY_AND_ASSIGN(PipelineImplTest);
};
@@ -280,6 +314,8 @@ TEST_F(PipelineImplTest, NoStreams) {
EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
EXPECT_CALL(*mocks_->data_source(), Stop());
+ EXPECT_CALL(*mocks_->data_source(), media_format())
+ .WillOnce(ReturnRef(data_source_media_format_));
EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
@@ -295,7 +331,7 @@ TEST_F(PipelineImplTest, NoStreams) {
TEST_F(PipelineImplTest, AudioStream) {
scoped_refptr<StrictMock<MockDemuxerStream> > stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(stream);
@@ -313,7 +349,7 @@ TEST_F(PipelineImplTest, AudioStream) {
TEST_F(PipelineImplTest, VideoStream) {
scoped_refptr<StrictMock<MockDemuxerStream> > stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(stream);
@@ -331,9 +367,9 @@ TEST_F(PipelineImplTest, VideoStream) {
TEST_F(PipelineImplTest, AudioVideoStream) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
scoped_refptr<StrictMock<MockDemuxerStream> > video_stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
streams.push_back(video_stream);
@@ -354,9 +390,9 @@ TEST_F(PipelineImplTest, AudioVideoStream) {
TEST_F(PipelineImplTest, Seek) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
scoped_refptr<StrictMock<MockDemuxerStream> > video_stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
streams.push_back(video_stream);
@@ -400,7 +436,7 @@ TEST_F(PipelineImplTest, Seek) {
TEST_F(PipelineImplTest, SetVolume) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
@@ -418,14 +454,14 @@ TEST_F(PipelineImplTest, SetVolume) {
pipeline_->SetVolume(expected);
}
-TEST_F(PipelineImplTest, Properties) {
+TEST_F(PipelineImplTest, Properties) {
scoped_refptr<StrictMock<MockDemuxerStream> > stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(stream);
InitializeDataSource();
- base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100);
+ const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100);
InitializeDemuxer(&streams, kDuration);
InitializeVideoDecoder(stream);
InitializeVideoRenderer();
@@ -443,9 +479,9 @@ TEST_F(PipelineImplTest, Properties) {
TEST_F(PipelineImplTest, BroadcastMessage) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
scoped_refptr<StrictMock<MockDemuxerStream> > video_stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
streams.push_back(video_stream);
@@ -484,9 +520,9 @@ TEST_F(PipelineImplTest, BroadcastMessage) {
TEST_F(PipelineImplTest, EndedCallback) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
scoped_refptr<StrictMock<MockDemuxerStream> > video_stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
streams.push_back(video_stream);
diff --git a/media/filters/audio_renderer_base_unittest.cc b/media/filters/audio_renderer_base_unittest.cc
index 1827424..df4c9f0 100644
--- a/media/filters/audio_renderer_base_unittest.cc
+++ b/media/filters/audio_renderer_base_unittest.cc
@@ -15,6 +15,7 @@ using ::testing::InSequence;
using ::testing::Invoke;
using ::testing::NotNull;
using ::testing::Return;
+using ::testing::ReturnRef;
using ::testing::StrictMock;
namespace media {
@@ -47,12 +48,21 @@ class AudioRendererBaseTest : public ::testing::Test {
// Give the decoder some non-garbage media properties.
AudioRendererBaseTest()
: renderer_(new MockAudioRendererBase()),
- decoder_(new MockAudioDecoder(1, 44100, 16)) {
+ decoder_(new MockAudioDecoder()) {
renderer_->set_host(&host_);
// Queue all reads from the decoder.
EXPECT_CALL(*decoder_, Read(NotNull()))
.WillRepeatedly(Invoke(this, &AudioRendererBaseTest::EnqueueCallback));
+
+ // Sets the essential media format keys for this decoder.
+ decoder_media_format_.SetAsString(MediaFormat::kMimeType,
+ mime_type::kUncompressedAudio);
+ decoder_media_format_.SetAsInteger(MediaFormat::kChannels, 1);
+ decoder_media_format_.SetAsInteger(MediaFormat::kSampleRate, 44100);
+ decoder_media_format_.SetAsInteger(MediaFormat::kSampleBits, 16);
+ EXPECT_CALL(*decoder_, media_format())
+ .WillRepeatedly(ReturnRef(decoder_media_format_));
}
virtual ~AudioRendererBaseTest() {
@@ -71,6 +81,7 @@ class AudioRendererBaseTest : public ::testing::Test {
scoped_refptr<MockAudioDecoder> decoder_;
StrictMock<MockFilterHost> host_;
StrictMock<MockFilterCallback> callback_;
+ MediaFormat decoder_media_format_;
// Receives asynchronous read requests sent to |decoder_|.
std::deque<Callback1<Buffer*>::Type*> read_queue_;
diff --git a/media/filters/video_renderer_base_unittest.cc b/media/filters/video_renderer_base_unittest.cc
index b6a5c6b..9735b5f 100644
--- a/media/filters/video_renderer_base_unittest.cc
+++ b/media/filters/video_renderer_base_unittest.cc
@@ -16,6 +16,7 @@ using ::testing::InSequence;
using ::testing::Invoke;
using ::testing::NotNull;
using ::testing::Return;
+using ::testing::ReturnRef;
using ::testing::StrictMock;
namespace media {
@@ -42,13 +43,20 @@ class VideoRendererBaseTest : public ::testing::Test {
public:
VideoRendererBaseTest()
: renderer_(new MockVideoRendererBase()),
- decoder_(new MockVideoDecoder(mime_type::kUncompressedVideo, kWidth,
- kHeight)) {
+ decoder_(new MockVideoDecoder()) {
renderer_->set_host(&host_);
// Queue all reads from the decoder.
EXPECT_CALL(*decoder_, Read(NotNull()))
.WillRepeatedly(Invoke(this, &VideoRendererBaseTest::EnqueueCallback));
+
+ // Sets the essential media format keys for this decoder.
+ decoder_media_format_.SetAsString(MediaFormat::kMimeType,
+ mime_type::kUncompressedVideo);
+ decoder_media_format_.SetAsInteger(MediaFormat::kWidth, kWidth);
+ decoder_media_format_.SetAsInteger(MediaFormat::kHeight, kHeight);
+ EXPECT_CALL(*decoder_, media_format())
+ .WillRepeatedly(ReturnRef(decoder_media_format_));
}
virtual ~VideoRendererBaseTest() {
@@ -68,6 +76,7 @@ class VideoRendererBaseTest : public ::testing::Test {
scoped_refptr<MockVideoDecoder> decoder_;
StrictMock<MockFilterHost> host_;
StrictMock<MockFilterCallback> callback_;
+ MediaFormat decoder_media_format_;
// Receives asynchronous read requests sent to |decoder_|.
std::deque<Callback1<VideoFrame*>::Type*> read_queue_;
@@ -88,7 +97,10 @@ TEST_F(VideoRendererBaseTest, Initialize_BadMediaFormat) {
InSequence s;
// Don't set a media format.
+ MediaFormat media_format;
scoped_refptr<MockVideoDecoder> bad_decoder = new MockVideoDecoder();
+ EXPECT_CALL(*bad_decoder, media_format())
+ .WillRepeatedly(ReturnRef(media_format));
// We expect to receive an error.
EXPECT_CALL(host_, SetError(PIPELINE_ERROR_INITIALIZATION_FAILED));