From 23a2893a3562563a69fa13dba45eee9cfc6fec6d Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Mon, 18 Sep 2017 08:47:00 -0700 Subject: [PATCH] Define Text Sample Matchers and Test Functions This change create some matchers and text functions that will be used by the upcoming webvtt work. Change-Id: I2d7931d1bdabd761f74e8aee7524d5ecfb7cfdc4 --- .../media/base/media_handler_test_base.cc | 27 ++++++++++++++++--- packager/media/base/media_handler_test_base.h | 16 +++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/packager/media/base/media_handler_test_base.cc b/packager/media/base/media_handler_test_base.cc index 80c98f57f4..6cdac9b491 100644 --- a/packager/media/base/media_handler_test_base.cc +++ b/packager/media/base/media_handler_test_base.cc @@ -7,6 +7,7 @@ #include "packager/media/base/media_handler_test_base.h" #include "packager/media/base/audio_stream_info.h" +#include "packager/media/base/text_stream_info.h" #include "packager/media/base/video_stream_info.h" #include "packager/status_test_util.h" @@ -186,13 +187,33 @@ std::unique_ptr MediaHandlerTestBase::GetSegmentInfo( return info; } +std::unique_ptr MediaHandlerTestBase::GetTextStreamInfo() const { + // None of this information is actually used by the text out handler. + // The stream info is just needed to signal the start of the stream. + return std::unique_ptr( + new TextStreamInfo(0, 0, 0, kUnknownCodec, "", "", 0, 0, "")); +} + +std::unique_ptr MediaHandlerTestBase::GetTextSample( + const std::string& id, + uint64_t start, + uint64_t end, + const std::string& payload) const { + std::unique_ptr sample(new TextSample); + sample->set_id(id); + sample->SetTime(start, end); + sample->AppendPayload(payload); + + return sample; +} 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) { +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 // one output restriction for the encryption handler. auto input_handler = std::make_shared(); diff --git a/packager/media/base/media_handler_test_base.h b/packager/media/base/media_handler_test_base.h index 63c99a529a..db1ae07b17 100644 --- a/packager/media/base/media_handler_test_base.h +++ b/packager/media/base/media_handler_test_base.h @@ -74,6 +74,15 @@ MATCHER_P4(IsMediaSample, stream_index, timestamp, duration, encrypted, "") { arg->media_sample->is_encrypted() == encrypted; } +MATCHER_P5(IsTextSample, id, start_time, end_time, settings, payload, "") { + return arg->stream_data_type == StreamDataType::kTextSample && + arg->text_sample->id() == id && + arg->text_sample->start_time() == start_time && + arg->text_sample->EndTime() == end_time && + arg->text_sample->settings() == settings && + arg->text_sample->payload() == payload; +} + class FakeInputMediaHandler : public MediaHandler { public: using MediaHandler::Dispatch; @@ -155,6 +164,13 @@ class MediaHandlerTestBase : public ::testing::Test { int64_t duration, bool is_subsegment) const; + std::unique_ptr GetTextStreamInfo() const; + + std::unique_ptr GetTextSample(const std::string& id, + uint64_t start, + uint64_t end, + const std::string& payload) const; + private: MediaHandlerTestBase(const MediaHandlerTestBase&) = delete; MediaHandlerTestBase& operator=(const MediaHandlerTestBase&) = delete;