diff --git a/packager/media/base/media_handler_test_base.cc b/packager/media/base/media_handler_test_base.cc index 8ff42c4c90..80c98f57f4 100644 --- a/packager/media/base/media_handler_test_base.cc +++ b/packager/media/base/media_handler_test_base.cc @@ -68,7 +68,8 @@ Status FakeInputMediaHandler::InitializeInternal() { } Status FakeInputMediaHandler::Process(std::unique_ptr stream_data) { - return Status::OK; + return Status(error::INTERNAL_ERROR, + "FakeInputMediaHandler should never be a downstream handler."); } Status MockOutputMediaHandler::InitializeInternal() { @@ -103,10 +104,6 @@ bool FakeMediaHandler::ValidateOutputStreamIndex(size_t stream_index) const { return true; } -MediaHandlerTestBase::MediaHandlerTestBase() - : next_handler_(new FakeMediaHandler), - some_handler_(new FakeMediaHandler) {} - bool MediaHandlerTestBase::IsVideoCodec(Codec codec) const { return codec >= kCodecVideo && codec < kCodecVideoMaxPlusOne; } @@ -189,7 +186,11 @@ std::unique_ptr MediaHandlerTestBase::GetSegmentInfo( return info; } -void MediaHandlerTestBase::SetUpGraph(size_t num_inputs, +MediaHandlerGraphTestBase::MediaHandlerGraphTestBase() + : next_handler_(new FakeMediaHandler), + some_handler_(new FakeMediaHandler) {} + +void MediaHandlerGraphTestBase::SetUpGraph(size_t num_inputs, size_t num_outputs, std::shared_ptr handler) { // Input handler is not really used anywhere but just to satisfy one input @@ -203,11 +204,11 @@ void MediaHandlerTestBase::SetUpGraph(size_t num_inputs, } const std::vector>& -MediaHandlerTestBase::GetOutputStreamDataVector() const { +MediaHandlerGraphTestBase::GetOutputStreamDataVector() const { return next_handler_->stream_data_vector(); } -void MediaHandlerTestBase::ClearOutputStreamDataVector() { +void MediaHandlerGraphTestBase::ClearOutputStreamDataVector() { next_handler_->clear_stream_data_vector(); } diff --git a/packager/media/base/media_handler_test_base.h b/packager/media/base/media_handler_test_base.h index c7d432cd9e..63c99a529a 100644 --- a/packager/media/base/media_handler_test_base.h +++ b/packager/media/base/media_handler_test_base.h @@ -97,7 +97,8 @@ class MockOutputMediaHandler : public MediaHandler { Status OnFlushRequest(size_t index) override; }; -// A fake media handler definition used for testing. +// TODO(vaage) : Remove this test handler and convert other tests to use +// FakeInputMediaHandler and MockOutputMediaHandler. class FakeMediaHandler : public MediaHandler { public: const std::vector>& stream_data_vector() const { @@ -116,49 +117,54 @@ class FakeMediaHandler : public MediaHandler { class MediaHandlerTestBase : public ::testing::Test { public: - MediaHandlerTestBase(); + MediaHandlerTestBase() = default; + protected: bool IsVideoCodec(Codec codec) const; - std::unique_ptr GetVideoStreamInfo( - uint32_t time_scale) const; + std::unique_ptr GetVideoStreamInfo(uint32_t time_scale) const; - std::unique_ptr GetVideoStreamInfo( - uint32_t time_scale, uint32_t width, uint64_t height) const; + std::unique_ptr GetVideoStreamInfo(uint32_t time_scale, + uint32_t width, + uint64_t height) const; - std::unique_ptr GetVideoStreamInfo( - uint32_t time_scale, Codec codec) const; + std::unique_ptr GetVideoStreamInfo(uint32_t time_scale, + Codec codec) const; - std::unique_ptr GetVideoStreamInfo( - uint32_t time_scale, - Codec codec, - uint32_t width, - uint64_t height) const; + std::unique_ptr GetVideoStreamInfo(uint32_t time_scale, + Codec codec, + uint32_t width, + uint64_t height) const; - std::unique_ptr GetAudioStreamInfo( - uint32_t time_scale) const; + std::unique_ptr GetAudioStreamInfo(uint32_t time_scale) const; - std::unique_ptr GetAudioStreamInfo( - uint32_t time_scale, - Codec codec) const; + std::unique_ptr GetAudioStreamInfo(uint32_t time_scale, + Codec codec) const; - std::unique_ptr GetMediaSample( - int64_t timestamp, - int64_t duration, - bool is_keyframe) const; + std::unique_ptr GetMediaSample(int64_t timestamp, + int64_t duration, + bool is_keyframe) const; - std::unique_ptr GetMediaSample( - int64_t timestamp, - int64_t duration, - bool is_keyframe, - const uint8_t* data, - size_t data_length) const; + std::unique_ptr GetMediaSample(int64_t timestamp, + int64_t duration, + bool is_keyframe, + const uint8_t* data, + size_t data_length) const; - std::unique_ptr GetSegmentInfo( - int64_t start_timestamp, - int64_t duration, - bool is_subsegment) const; + std::unique_ptr GetSegmentInfo(int64_t start_timestamp, + int64_t duration, + bool is_subsegment) const; + private: + MediaHandlerTestBase(const MediaHandlerTestBase&) = delete; + MediaHandlerTestBase& operator=(const MediaHandlerTestBase&) = delete; +}; + +class MediaHandlerGraphTestBase : public MediaHandlerTestBase { + public: + MediaHandlerGraphTestBase(); + + protected: /// Setup a graph using |handler| with |num_inputs| and |num_outputs|. void SetUpGraph(size_t num_inputs, size_t num_outputs, @@ -178,8 +184,8 @@ class MediaHandlerTestBase : public ::testing::Test { std::shared_ptr next_handler() { return next_handler_; } private: - MediaHandlerTestBase(const MediaHandlerTestBase&) = delete; - MediaHandlerTestBase& operator=(const MediaHandlerTestBase&) = delete; + MediaHandlerGraphTestBase(const MediaHandlerTestBase&) = delete; + MediaHandlerGraphTestBase& operator=(const MediaHandlerTestBase&) = delete; // Downstream handler used in testing graph. std::shared_ptr next_handler_; diff --git a/packager/media/chunking/chunking_handler_unittest.cc b/packager/media/chunking/chunking_handler_unittest.cc index de28c1278b..bae09b199d 100644 --- a/packager/media/chunking/chunking_handler_unittest.cc +++ b/packager/media/chunking/chunking_handler_unittest.cc @@ -30,7 +30,7 @@ const bool kEncrypted = true; } // namespace -class ChunkingHandlerTest : public MediaHandlerTestBase { +class ChunkingHandlerTest : public MediaHandlerGraphTestBase { public: void SetUpChunkingHandler(int num_inputs, const ChunkingParams& chunking_params) { diff --git a/packager/media/crypto/encryption_handler_unittest.cc b/packager/media/crypto/encryption_handler_unittest.cc index 16dc3e1d38..5874c8f9e7 100644 --- a/packager/media/crypto/encryption_handler_unittest.cc +++ b/packager/media/crypto/encryption_handler_unittest.cc @@ -81,7 +81,7 @@ class MockVideoSliceHeaderParser : public VideoSliceHeaderParser { } // namespace -class EncryptionHandlerTest : public MediaHandlerTestBase { +class EncryptionHandlerTest : public MediaHandlerGraphTestBase { public: void SetUp() override { SetUpEncryptionHandler(EncryptionParams()); } diff --git a/packager/media/demuxer/demuxer_unittest.cc b/packager/media/demuxer/demuxer_unittest.cc index 6335f5c5de..4c948f5d16 100644 --- a/packager/media/demuxer/demuxer_unittest.cc +++ b/packager/media/demuxer/demuxer_unittest.cc @@ -29,7 +29,7 @@ class MockKeySource : public FixedKeySource { }; } // namespace -class DemuxerTest : public MediaHandlerTestBase { +class DemuxerTest : public MediaHandlerGraphTestBase { protected: EncryptionKey GetMockEncryptionKey() { const uint8_t kKeyId[]{ diff --git a/packager/media/trick_play/trick_play_handler_unittest.cc b/packager/media/trick_play/trick_play_handler_unittest.cc index f237b4a19e..bd3b2409ae 100644 --- a/packager/media/trick_play/trick_play_handler_unittest.cc +++ b/packager/media/trick_play/trick_play_handler_unittest.cc @@ -55,7 +55,7 @@ MATCHER_P3(IsKeyFrameMediaSample, stream_index, timestamp, duration, "") { arg->media_sample->is_key_frame() == true; } -class TrickPlayHandlerTest : public MediaHandlerTestBase { +class TrickPlayHandlerTest : public MediaHandlerGraphTestBase { public: void SetUpTrickPlayHandler(const std::vector& trick_play_factors) { trick_play_handler_.reset(new TrickPlayHandler());