Use Mock Muxer Listener in WebVttOutput Tests
Use a mock muxer listener so that we can verify that the webvtt output handlers will write to a manifest correctly. Change-Id: I0294a998bfaf06a6d8f7d4c287fb014839b38f73
This commit is contained in:
parent
49933737cd
commit
c877af9f3b
|
@ -11,12 +11,15 @@
|
||||||
#include "packager/media/base/media_handler_test_base.h"
|
#include "packager/media/base/media_handler_test_base.h"
|
||||||
#include "packager/media/base/text_stream_info.h"
|
#include "packager/media/base/text_stream_info.h"
|
||||||
#include "packager/media/event/combined_muxer_listener.h"
|
#include "packager/media/event/combined_muxer_listener.h"
|
||||||
|
#include "packager/media/event/mock_muxer_listener.h"
|
||||||
#include "packager/media/formats/webvtt/webvtt_output_handler.h"
|
#include "packager/media/formats/webvtt/webvtt_output_handler.h"
|
||||||
#include "packager/status_test_util.h"
|
#include "packager/status_test_util.h"
|
||||||
|
|
||||||
namespace shaka {
|
namespace shaka {
|
||||||
namespace media {
|
namespace media {
|
||||||
namespace {
|
namespace {
|
||||||
|
using testing::_;
|
||||||
|
|
||||||
const size_t kInputCount = 1;
|
const size_t kInputCount = 1;
|
||||||
const size_t kOutputCount = 0;
|
const size_t kOutputCount = 0;
|
||||||
const size_t kInputIndex = 0;
|
const size_t kInputIndex = 0;
|
||||||
|
@ -28,6 +31,9 @@ const char* kNoId = "";
|
||||||
const char* kSegmentedFileTemplate = "memory://output/template-$Number$.vtt";
|
const char* kSegmentedFileTemplate = "memory://output/template-$Number$.vtt";
|
||||||
const char* kSegmentedFileOutput1 = "memory://output/template-1.vtt";
|
const char* kSegmentedFileOutput1 = "memory://output/template-1.vtt";
|
||||||
const char* kSegmentedFileOutput2 = "memory://output/template-2.vtt";
|
const char* kSegmentedFileOutput2 = "memory://output/template-2.vtt";
|
||||||
|
|
||||||
|
const uint64_t kSegmentDuration = 10000;
|
||||||
|
const float kMillisecondsPerSecond = 1000.0f;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class WebVttSegmentedOutputTest : public MediaHandlerTestBase {
|
class WebVttSegmentedOutputTest : public MediaHandlerTestBase {
|
||||||
|
@ -35,7 +41,11 @@ class WebVttSegmentedOutputTest : public MediaHandlerTestBase {
|
||||||
void SetUp() {
|
void SetUp() {
|
||||||
MuxerOptions muxer_options;
|
MuxerOptions muxer_options;
|
||||||
muxer_options.segment_template = kSegmentedFileTemplate;
|
muxer_options.segment_template = kSegmentedFileTemplate;
|
||||||
std::unique_ptr<MuxerListener> muxer_listener(new CombinedMuxerListener());
|
|
||||||
|
// Create a mock muxer listener but save a reference to the mock so that we
|
||||||
|
// can use it in the test.
|
||||||
|
std::unique_ptr<MockMuxerListener> muxer_listener(new MockMuxerListener);
|
||||||
|
muxer_listener_ = muxer_listener.get();
|
||||||
|
|
||||||
out_ = std::make_shared<WebVttSegmentedOutputHandler>(
|
out_ = std::make_shared<WebVttSegmentedOutputHandler>(
|
||||||
muxer_options, std::move(muxer_listener));
|
muxer_options, std::move(muxer_listener));
|
||||||
|
@ -43,20 +53,27 @@ class WebVttSegmentedOutputTest : public MediaHandlerTestBase {
|
||||||
ASSERT_OK(SetUpAndInitializeGraph(out_, kInputCount, kOutputCount));
|
ASSERT_OK(SetUpAndInitializeGraph(out_, kInputCount, kOutputCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MockMuxerListener* muxer_listener_ = nullptr;
|
||||||
std::shared_ptr<WebVttSegmentedOutputHandler> out_;
|
std::shared_ptr<WebVttSegmentedOutputHandler> out_;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(WebVttSegmentedOutputTest, WithNoSegmentAndWithNoSamples) {
|
TEST_F(WebVttSegmentedOutputTest, WithNoSegmentAndWithNoSamples) {
|
||||||
// Expected output - No files should be created as there were no
|
EXPECT_CALL(*muxer_listener_, OnNewSegment(_, _, _, _)).Times(0);
|
||||||
// samples.
|
|
||||||
|
{
|
||||||
|
// No segments should have be created as there were no samples.
|
||||||
|
|
||||||
|
testing::InSequence s;
|
||||||
|
EXPECT_CALL(*muxer_listener_, OnMediaStart(_, _, _, _));
|
||||||
|
|
||||||
|
const float kMediaDuration = 0 * kSegmentDuration / kMillisecondsPerSecond;
|
||||||
|
EXPECT_CALL(*muxer_listener_,
|
||||||
|
OnMediaEndMock(_, _, _, _, _, _, _, _, kMediaDuration));
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT_OK(Input(kInputIndex)
|
ASSERT_OK(Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromStreamInfo(kStreamIndex,
|
->Dispatch(StreamData::FromStreamInfo(kStreamIndex,
|
||||||
GetTextStreamInfo())));
|
GetTextStreamInfo())));
|
||||||
ASSERT_OK(
|
|
||||||
Input(kInputIndex)
|
|
||||||
->Dispatch(StreamData::FromSegmentInfo(
|
|
||||||
kStreamIndex, GetSegmentInfo(kStreamIndex, 10000, !kEncrypted))));
|
|
||||||
ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams());
|
ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +85,20 @@ TEST_F(WebVttSegmentedOutputTest, WithOneSegmentAndWithOneSample) {
|
||||||
"payload\n"
|
"payload\n"
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
|
const uint64_t kSegmentStart = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
testing::InSequence s;
|
||||||
|
EXPECT_CALL(*muxer_listener_, OnMediaStart(_, _, _, _));
|
||||||
|
EXPECT_CALL(*muxer_listener_,
|
||||||
|
OnNewSegment(kSegmentedFileOutput1, kSegmentStart,
|
||||||
|
kSegmentDuration, _));
|
||||||
|
|
||||||
|
const float kMediaDuration = 1 * kSegmentDuration / kMillisecondsPerSecond;
|
||||||
|
EXPECT_CALL(*muxer_listener_,
|
||||||
|
OnMediaEndMock(_, _, _, _, _, _, _, _, kMediaDuration));
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT_OK(Input(kInputIndex)
|
ASSERT_OK(Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromStreamInfo(kStreamIndex,
|
->Dispatch(StreamData::FromStreamInfo(kStreamIndex,
|
||||||
GetTextStreamInfo())));
|
GetTextStreamInfo())));
|
||||||
|
@ -75,9 +106,11 @@ TEST_F(WebVttSegmentedOutputTest, WithOneSegmentAndWithOneSample) {
|
||||||
Input(kInputIndex)
|
Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromTextSample(
|
->Dispatch(StreamData::FromTextSample(
|
||||||
kStreamIndex, GetTextSample(kNoId, 5000, 6000, "payload"))));
|
kStreamIndex, GetTextSample(kNoId, 5000, 6000, "payload"))));
|
||||||
ASSERT_OK(Input(kInputIndex)
|
ASSERT_OK(
|
||||||
|
Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromSegmentInfo(
|
->Dispatch(StreamData::FromSegmentInfo(
|
||||||
kStreamIndex, GetSegmentInfo(0, 10000, !kEncrypted))));
|
kStreamIndex,
|
||||||
|
GetSegmentInfo(kSegmentStart, kSegmentDuration, !kEncrypted))));
|
||||||
ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams());
|
ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams());
|
||||||
|
|
||||||
ASSERT_FILE_STREQ(kSegmentedFileOutput1, kExpectedOutput);
|
ASSERT_FILE_STREQ(kSegmentedFileOutput1, kExpectedOutput);
|
||||||
|
@ -98,6 +131,24 @@ TEST_F(WebVttSegmentedOutputTest, WithTwoSegmentAndWithOneSample) {
|
||||||
"payload 2\n"
|
"payload 2\n"
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
|
const uint64_t kSegment1Start = 0;
|
||||||
|
const uint64_t kSegment2Start = kSegmentDuration;
|
||||||
|
|
||||||
|
{
|
||||||
|
testing::InSequence s;
|
||||||
|
EXPECT_CALL(*muxer_listener_, OnMediaStart(_, _, _, _));
|
||||||
|
EXPECT_CALL(*muxer_listener_,
|
||||||
|
OnNewSegment(kSegmentedFileOutput1, kSegment1Start,
|
||||||
|
kSegmentDuration, _));
|
||||||
|
EXPECT_CALL(*muxer_listener_,
|
||||||
|
OnNewSegment(kSegmentedFileOutput2, kSegment2Start,
|
||||||
|
kSegmentDuration, _));
|
||||||
|
|
||||||
|
const float kMediaDuration = 2 * kSegmentDuration / kMillisecondsPerSecond;
|
||||||
|
EXPECT_CALL(*muxer_listener_,
|
||||||
|
OnMediaEndMock(_, _, _, _, _, _, _, _, kMediaDuration));
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT_OK(Input(kInputIndex)
|
ASSERT_OK(Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromStreamInfo(0, GetTextStreamInfo())));
|
->Dispatch(StreamData::FromStreamInfo(0, GetTextStreamInfo())));
|
||||||
|
|
||||||
|
@ -106,17 +157,21 @@ TEST_F(WebVttSegmentedOutputTest, WithTwoSegmentAndWithOneSample) {
|
||||||
Input(kInputIndex)
|
Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromTextSample(
|
->Dispatch(StreamData::FromTextSample(
|
||||||
kStreamIndex, GetTextSample(kNoId, 5000, 6000, "payload 1"))));
|
kStreamIndex, GetTextSample(kNoId, 5000, 6000, "payload 1"))));
|
||||||
ASSERT_OK(Input(kInputIndex)
|
ASSERT_OK(
|
||||||
|
Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromSegmentInfo(
|
->Dispatch(StreamData::FromSegmentInfo(
|
||||||
kStreamIndex, GetSegmentInfo(0, 10000, !kEncrypted))));
|
kStreamIndex,
|
||||||
|
GetSegmentInfo(kSegment1Start, kSegmentDuration, !kEncrypted))));
|
||||||
// Segment Two
|
// Segment Two
|
||||||
ASSERT_OK(
|
ASSERT_OK(
|
||||||
Input(kInputIndex)
|
Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromTextSample(
|
->Dispatch(StreamData::FromTextSample(
|
||||||
kStreamIndex, GetTextSample(kNoId, 15000, 16000, "payload 2"))));
|
kStreamIndex, GetTextSample(kNoId, 15000, 16000, "payload 2"))));
|
||||||
ASSERT_OK(Input(kInputIndex)
|
ASSERT_OK(
|
||||||
|
Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromSegmentInfo(
|
->Dispatch(StreamData::FromSegmentInfo(
|
||||||
kStreamIndex, GetSegmentInfo(10000, 10000, !kEncrypted))));
|
kStreamIndex,
|
||||||
|
GetSegmentInfo(kSegment2Start, kSegmentDuration, !kEncrypted))));
|
||||||
ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams());
|
ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams());
|
||||||
|
|
||||||
ASSERT_FILE_STREQ(kSegmentedFileOutput1, kExpectedOutput1);
|
ASSERT_FILE_STREQ(kSegmentedFileOutput1, kExpectedOutput1);
|
||||||
|
@ -124,32 +179,57 @@ TEST_F(WebVttSegmentedOutputTest, WithTwoSegmentAndWithOneSample) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WebVttSegmentedOutputTest, WithAnEmptySegment) {
|
TEST_F(WebVttSegmentedOutputTest, WithAnEmptySegment) {
|
||||||
const char* kExpectedOutput =
|
const char* kExpectedOutput1 =
|
||||||
|
"WEBVTT\n"
|
||||||
|
"\n";
|
||||||
|
|
||||||
|
const char* kExpectedOutput2 =
|
||||||
"WEBVTT\n"
|
"WEBVTT\n"
|
||||||
"\n"
|
"\n"
|
||||||
"00:00:15.000 --> 00:00:16.000\n"
|
"00:00:15.000 --> 00:00:16.000\n"
|
||||||
"payload 2\n"
|
"payload 2\n"
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
|
const uint64_t kSegment1Start = 0;
|
||||||
|
const uint64_t kSegment2Start = kSegmentDuration;
|
||||||
|
|
||||||
|
{
|
||||||
|
testing::InSequence s;
|
||||||
|
EXPECT_CALL(*muxer_listener_, OnMediaStart(_, _, _, _));
|
||||||
|
EXPECT_CALL(*muxer_listener_,
|
||||||
|
OnNewSegment(kSegmentedFileOutput1, kSegment1Start,
|
||||||
|
kSegmentDuration, _));
|
||||||
|
EXPECT_CALL(*muxer_listener_,
|
||||||
|
OnNewSegment(kSegmentedFileOutput2, kSegment2Start,
|
||||||
|
kSegmentDuration, _));
|
||||||
|
|
||||||
|
const float kMediaDuration = 2 * kSegmentDuration / kMillisecondsPerSecond;
|
||||||
|
EXPECT_CALL(*muxer_listener_,
|
||||||
|
OnMediaEndMock(_, _, _, _, _, _, _, _, kMediaDuration));
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT_OK(Input(kInputIndex)
|
ASSERT_OK(Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromStreamInfo(0, GetTextStreamInfo())));
|
->Dispatch(StreamData::FromStreamInfo(0, GetTextStreamInfo())));
|
||||||
// Segment One
|
// Segment One
|
||||||
ASSERT_OK(Input(kInputIndex)
|
ASSERT_OK(
|
||||||
|
Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromSegmentInfo(
|
->Dispatch(StreamData::FromSegmentInfo(
|
||||||
kStreamIndex, GetSegmentInfo(0, 10000, !kEncrypted))));
|
kStreamIndex,
|
||||||
|
GetSegmentInfo(kSegment1Start, kSegmentDuration, !kEncrypted))));
|
||||||
// Segment Two
|
// Segment Two
|
||||||
ASSERT_OK(
|
ASSERT_OK(
|
||||||
Input(kInputIndex)
|
Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromTextSample(
|
->Dispatch(StreamData::FromTextSample(
|
||||||
kStreamIndex, GetTextSample(kNoId, 15000, 16000, "payload 2"))));
|
kStreamIndex, GetTextSample(kNoId, 15000, 16000, "payload 2"))));
|
||||||
ASSERT_OK(Input(kInputIndex)
|
ASSERT_OK(
|
||||||
|
Input(kInputIndex)
|
||||||
->Dispatch(StreamData::FromSegmentInfo(
|
->Dispatch(StreamData::FromSegmentInfo(
|
||||||
kStreamIndex, GetSegmentInfo(10000, 10000, !kEncrypted))));
|
kStreamIndex,
|
||||||
|
GetSegmentInfo(kSegment2Start, kSegmentDuration, !kEncrypted))));
|
||||||
ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams());
|
ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams());
|
||||||
|
|
||||||
// The empty segment will not write to disk, but it will use segment's
|
ASSERT_FILE_STREQ(kSegmentedFileOutput1, kExpectedOutput1);
|
||||||
// filename.
|
ASSERT_FILE_STREQ(kSegmentedFileOutput2, kExpectedOutput2);
|
||||||
ASSERT_FILE_STREQ(kSegmentedFileOutput2, kExpectedOutput);
|
|
||||||
}
|
}
|
||||||
} // namespace media
|
} // namespace media
|
||||||
} // namespace shaka
|
} // namespace shaka
|
||||||
|
|
Loading…
Reference in New Issue