Update Cue Alignment Tests To Interweave Sample Data

Problem: Sending samples to the cue alignmenet handler did
         not reflect what was more likely to happen. In our
         tests we would send all the samples for one stream
         then all the samples for another stream. This created
         some special cases that would either not happen in
         reality or miss cases that would likely happen in
         reality.

Changes: Changes all tests to dispatch samples in an interlaced
         pattern that better reflects muxed content.

Change-Id: I985092154b62eb12d95499663d195ca6c103bc19
This commit is contained in:
Aaron Vaage 2018-05-01 14:40:01 -07:00
parent 0b2e1a6b40
commit 9a9f7d58b2
1 changed files with 187 additions and 165 deletions

View File

@ -12,6 +12,7 @@
#include "packager/media/base/media_handler_test_base.h" #include "packager/media/base/media_handler_test_base.h"
#include "packager/media/chunking/cue_alignment_handler.h" #include "packager/media/chunking/cue_alignment_handler.h"
#include "packager/media/public/ad_cue_generator_params.h" #include "packager/media/public/ad_cue_generator_params.h"
#include "packager/status_macros.h"
#include "packager/status_test_util.h" #include "packager/status_test_util.h"
using ::testing::ElementsAre; using ::testing::ElementsAre;
@ -39,7 +40,34 @@ const size_t kChild = 0;
const size_t kParent = 0; const size_t kParent = 0;
} // namespace } // namespace
class CueAlignmentHandlerTest : public MediaHandlerTestBase {}; class CueAlignmentHandlerTest : public MediaHandlerTestBase {
protected:
Status DispatchStreamInfo(size_t stream,
std::shared_ptr<const StreamInfo> info) {
return Input(stream)->Dispatch(
StreamData::FromStreamInfo(kChild, std::move(info)));
}
Status DispatchMediaSample(size_t stream,
std::shared_ptr<const MediaSample> sample) {
return Input(stream)->Dispatch(
StreamData::FromMediaSample(kChild, std::move(sample)));
}
Status DispatchTextSample(size_t stream,
std::shared_ptr<const TextSample> sample) {
return Input(stream)->Dispatch(
StreamData::FromTextSample(kChild, std::move(sample)));
}
Status FlushAll(std::initializer_list<size_t> inputs) {
for (auto& input : inputs) {
RETURN_IF_ERROR(Input(input)->FlushAllDownstreams());
}
return Status::OK;
}
};
TEST_F(CueAlignmentHandlerTest, VideoInputWithNoCues) { TEST_F(CueAlignmentHandlerTest, VideoInputWithNoCues) {
const size_t kVideoStream = 0; const size_t kVideoStream = 0;
@ -72,19 +100,17 @@ TEST_F(CueAlignmentHandlerTest, VideoInputWithNoCues) {
EXPECT_CALL(*Output(kVideoStream), OnFlush(kParent)); EXPECT_CALL(*Output(kVideoStream), OnFlush(kParent));
} }
Input(kVideoStream) auto stream_info = GetVideoStreamInfo(kMsTimeScale);
->Dispatch( auto sample_0 = GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame);
StreamData::FromStreamInfo(kChild, GetVideoStreamInfo(kMsTimeScale))); auto sample_1 = GetMediaSample(kSample1Start, kSampleDuration, !kKeyFrame);
Input(kVideoStream) auto sample_2 = GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame);
->Dispatch(StreamData::FromMediaSample(
kChild, GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame))); DispatchStreamInfo(kVideoStream, std::move(stream_info));
Input(kVideoStream) DispatchMediaSample(kVideoStream, std::move(sample_0));
->Dispatch(StreamData::FromMediaSample( DispatchMediaSample(kVideoStream, std::move(sample_1));
kChild, GetMediaSample(kSample1Start, kSampleDuration, !kKeyFrame))); DispatchMediaSample(kVideoStream, std::move(sample_2));
Input(kVideoStream)
->Dispatch(StreamData::FromMediaSample( ASSERT_OK(FlushAll({kVideoStream}));
kChild, GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame)));
Input(kVideoStream)->FlushAllDownstreams();
} }
TEST_F(CueAlignmentHandlerTest, AudioInputWithNoCues) { TEST_F(CueAlignmentHandlerTest, AudioInputWithNoCues) {
@ -118,19 +144,17 @@ TEST_F(CueAlignmentHandlerTest, AudioInputWithNoCues) {
EXPECT_CALL(*Output(kAudioStream), OnFlush(kParent)); EXPECT_CALL(*Output(kAudioStream), OnFlush(kParent));
} }
Input(kAudioStream) auto stream_info = GetAudioStreamInfo(kMsTimeScale);
->Dispatch( auto sample_0 = GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame);
StreamData::FromStreamInfo(kChild, GetAudioStreamInfo(kMsTimeScale))); auto sample_1 = GetMediaSample(kSample1Start, kSampleDuration, kKeyFrame);
Input(kAudioStream) auto sample_2 = GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame);
->Dispatch(StreamData::FromMediaSample(
kChild, GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame))); ASSERT_OK(DispatchStreamInfo(kAudioStream, std::move(stream_info)));
Input(kAudioStream) ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(sample_0)));
->Dispatch(StreamData::FromMediaSample( ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(sample_1)));
kChild, GetMediaSample(kSample1Start, kSampleDuration, kKeyFrame))); ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(sample_2)));
Input(kAudioStream)
->Dispatch(StreamData::FromMediaSample( ASSERT_OK(FlushAll({kAudioStream}));
kChild, GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame)));
Input(kAudioStream)->FlushAllDownstreams();
} }
TEST_F(CueAlignmentHandlerTest, TextInputWithNoCues) { TEST_F(CueAlignmentHandlerTest, TextInputWithNoCues) {
@ -168,21 +192,17 @@ TEST_F(CueAlignmentHandlerTest, TextInputWithNoCues) {
EXPECT_CALL(*Output(kTextStream), OnFlush(kParent)); EXPECT_CALL(*Output(kTextStream), OnFlush(kParent));
} }
Input(kTextStream) auto stream_info = GetTextStreamInfo();
->Dispatch(StreamData::FromStreamInfo(kChild, GetTextStreamInfo())); auto sample_0 = GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload);
Input(kTextStream) auto sample_1 = GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload);
->Dispatch(StreamData::FromTextSample( auto sample_2 = GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload);
kChild,
GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload))); ASSERT_OK(DispatchStreamInfo(kTextStream, std::move(stream_info)));
Input(kTextStream) ASSERT_OK(DispatchTextSample(kTextStream, std::move(sample_0)));
->Dispatch(StreamData::FromTextSample( ASSERT_OK(DispatchTextSample(kTextStream, std::move(sample_1)));
kChild, ASSERT_OK(DispatchTextSample(kTextStream, std::move(sample_2)));
GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload)));
Input(kTextStream) ASSERT_OK(FlushAll({kTextStream}));
->Dispatch(StreamData::FromTextSample(
kChild,
GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload)));
Input(kTextStream)->FlushAllDownstreams();
} }
TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithNoCues) { TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithNoCues) {
@ -256,49 +276,54 @@ TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithNoCues) {
EXPECT_CALL(*Output(kVideoStream), OnFlush(kParent)); EXPECT_CALL(*Output(kVideoStream), OnFlush(kParent));
} }
Input(kTextStream) // Text samples
->Dispatch(StreamData::FromStreamInfo(kChild, GetTextStreamInfo())); auto text_stream_info = GetTextStreamInfo();
Input(kTextStream) auto text_sample_0 =
->Dispatch(StreamData::FromTextSample( GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload);
kChild, auto text_sample_1 =
GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload))); GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload);
Input(kTextStream) auto text_sample_2 =
->Dispatch(StreamData::FromTextSample( GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload);
kChild,
GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload)));
Input(kTextStream)
->Dispatch(StreamData::FromTextSample(
kChild,
GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload)));
Input(kTextStream)->FlushAllDownstreams();
Input(kAudioStream) // Audio samples
->Dispatch( auto audio_stream_info = GetAudioStreamInfo(kMsTimeScale);
StreamData::FromStreamInfo(kChild, GetAudioStreamInfo(kMsTimeScale))); auto audio_sample_0 =
Input(kAudioStream) GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame);
->Dispatch(StreamData::FromMediaSample( auto audio_sample_1 =
kChild, GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame))); GetMediaSample(kSample1Start, kSampleDuration, kKeyFrame);
Input(kAudioStream) auto audio_sample_2 =
->Dispatch(StreamData::FromMediaSample( GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame);
kChild, GetMediaSample(kSample1Start, kSampleDuration, kKeyFrame)));
Input(kAudioStream)
->Dispatch(StreamData::FromMediaSample(
kChild, GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame)));
Input(kAudioStream)->FlushAllDownstreams();
Input(kVideoStream) // Video samples
->Dispatch( auto video_stream_info = GetVideoStreamInfo(kMsTimeScale);
StreamData::FromStreamInfo(kChild, GetVideoStreamInfo(kMsTimeScale))); auto video_sample_0 =
Input(kVideoStream) GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame);
->Dispatch(StreamData::FromMediaSample( auto video_sample_1 =
kChild, GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame))); GetMediaSample(kSample1Start, kSampleDuration, !kKeyFrame);
Input(kVideoStream) auto video_sample_2 =
->Dispatch(StreamData::FromMediaSample( GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame);
kChild, GetMediaSample(kSample1Start, kSampleDuration, !kKeyFrame)));
Input(kVideoStream) // Dispatch Stream Info
->Dispatch(StreamData::FromMediaSample( ASSERT_OK(DispatchStreamInfo(kTextStream, std::move(text_stream_info)));
kChild, GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame))); ASSERT_OK(DispatchStreamInfo(kAudioStream, std::move(audio_stream_info)));
Input(kVideoStream)->FlushAllDownstreams(); ASSERT_OK(DispatchStreamInfo(kVideoStream, std::move(video_stream_info)));
// Dispatch Sample 0
ASSERT_OK(DispatchTextSample(kTextStream, std::move(text_sample_0)));
ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(audio_sample_0)));
ASSERT_OK(DispatchMediaSample(kVideoStream, std::move(video_sample_0)));
// Dispatch Sample 1
ASSERT_OK(DispatchTextSample(kTextStream, std::move(text_sample_1)));
ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(audio_sample_1)));
ASSERT_OK(DispatchMediaSample(kVideoStream, std::move(video_sample_1)));
// Dispatch Sample 2
ASSERT_OK(DispatchTextSample(kTextStream, std::move(text_sample_2)));
ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(audio_sample_2)));
ASSERT_OK(DispatchMediaSample(kVideoStream, std::move(video_sample_2)));
ASSERT_OK(FlushAll({kTextStream, kAudioStream, kVideoStream}));
} }
TEST_F(CueAlignmentHandlerTest, VideoInputWithCues) { TEST_F(CueAlignmentHandlerTest, VideoInputWithCues) {
@ -343,19 +368,17 @@ TEST_F(CueAlignmentHandlerTest, VideoInputWithCues) {
EXPECT_CALL(*Output(kVideoStream), OnFlush(kParent)); EXPECT_CALL(*Output(kVideoStream), OnFlush(kParent));
} }
Input(kVideoStream) auto stream_info = GetVideoStreamInfo(kMsTimeScale);
->Dispatch( auto sample_0 = GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame);
StreamData::FromStreamInfo(kChild, GetVideoStreamInfo(kMsTimeScale))); auto sample_1 = GetMediaSample(kSample1Start, kSampleDuration, !kKeyFrame);
Input(kVideoStream) auto sample_2 = GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame);
->Dispatch(StreamData::FromMediaSample(
kChild, GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame))); ASSERT_OK(DispatchStreamInfo(kVideoStream, std::move(stream_info)));
Input(kVideoStream) ASSERT_OK(DispatchMediaSample(kVideoStream, std::move(sample_0)));
->Dispatch(StreamData::FromMediaSample( ASSERT_OK(DispatchMediaSample(kVideoStream, std::move(sample_1)));
kChild, GetMediaSample(kSample1Start, kSampleDuration, !kKeyFrame))); ASSERT_OK(DispatchMediaSample(kVideoStream, std::move(sample_2)));
Input(kVideoStream)
->Dispatch(StreamData::FromMediaSample( ASSERT_OK(FlushAll({kVideoStream}));
kChild, GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame)));
Input(kVideoStream)->FlushAllDownstreams();
} }
TEST_F(CueAlignmentHandlerTest, AudioInputWithCues) { TEST_F(CueAlignmentHandlerTest, AudioInputWithCues) {
@ -399,19 +422,17 @@ TEST_F(CueAlignmentHandlerTest, AudioInputWithCues) {
EXPECT_CALL(*Output(kAudioStream), OnFlush(kParent)); EXPECT_CALL(*Output(kAudioStream), OnFlush(kParent));
} }
Input(kAudioStream) auto stream_info = GetAudioStreamInfo(kMsTimeScale);
->Dispatch( auto sample_0 = GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame);
StreamData::FromStreamInfo(kChild, GetAudioStreamInfo(kMsTimeScale))); auto sample_1 = GetMediaSample(kSample1Start, kSampleDuration, kKeyFrame);
Input(kAudioStream) auto sample_2 = GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame);
->Dispatch(StreamData::FromMediaSample(
kChild, GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame))); ASSERT_OK(DispatchStreamInfo(kAudioStream, std::move(stream_info)));
Input(kAudioStream) ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(sample_0)));
->Dispatch(StreamData::FromMediaSample( ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(sample_1)));
kChild, GetMediaSample(kSample1Start, kSampleDuration, kKeyFrame))); ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(sample_2)));
Input(kAudioStream)
->Dispatch(StreamData::FromMediaSample( ASSERT_OK(FlushAll({kAudioStream}));
kChild, GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame)));
Input(kAudioStream)->FlushAllDownstreams();
} }
TEST_F(CueAlignmentHandlerTest, TextInputWithCues) { TEST_F(CueAlignmentHandlerTest, TextInputWithCues) {
@ -459,21 +480,17 @@ TEST_F(CueAlignmentHandlerTest, TextInputWithCues) {
EXPECT_CALL(*Output(kTextStream), OnFlush(kParent)); EXPECT_CALL(*Output(kTextStream), OnFlush(kParent));
} }
Input(kTextStream) auto stream_info = GetTextStreamInfo();
->Dispatch(StreamData::FromStreamInfo(kChild, GetTextStreamInfo())); auto sample_0 = GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload);
Input(kTextStream) auto sample_1 = GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload);
->Dispatch(StreamData::FromTextSample( auto sample_2 = GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload);
kChild,
GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload))); ASSERT_OK(DispatchStreamInfo(kTextStream, std::move(stream_info)));
Input(kTextStream) ASSERT_OK(DispatchTextSample(kTextStream, std::move(sample_0)));
->Dispatch(StreamData::FromTextSample( ASSERT_OK(DispatchTextSample(kTextStream, std::move(sample_1)));
kChild, ASSERT_OK(DispatchTextSample(kTextStream, std::move(sample_2)));
GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload)));
Input(kTextStream) ASSERT_OK(FlushAll({kTextStream}));
->Dispatch(StreamData::FromTextSample(
kChild,
GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload)));
Input(kTextStream)->FlushAllDownstreams();
} }
TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithCues) { TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithCues) {
@ -562,49 +579,54 @@ TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithCues) {
EXPECT_CALL(*Output(kVideoStream), OnFlush(kParent)); EXPECT_CALL(*Output(kVideoStream), OnFlush(kParent));
} }
Input(kTextStream) // Text samples
->Dispatch(StreamData::FromStreamInfo(kChild, GetTextStreamInfo())); auto text_stream_info = GetTextStreamInfo();
Input(kTextStream) auto text_sample_0 =
->Dispatch(StreamData::FromTextSample( GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload);
kChild, auto text_sample_1 =
GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload))); GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload);
Input(kTextStream) auto text_sample_2 =
->Dispatch(StreamData::FromTextSample( GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload);
kChild,
GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload)));
Input(kTextStream)
->Dispatch(StreamData::FromTextSample(
kChild,
GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload)));
Input(kTextStream)->FlushAllDownstreams();
Input(kAudioStream) // Audio samples
->Dispatch( auto audio_stream_info = GetAudioStreamInfo(kMsTimeScale);
StreamData::FromStreamInfo(kChild, GetAudioStreamInfo(kMsTimeScale))); auto audio_sample_0 =
Input(kAudioStream) GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame);
->Dispatch(StreamData::FromMediaSample( auto audio_sample_1 =
kChild, GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame))); GetMediaSample(kSample1Start, kSampleDuration, kKeyFrame);
Input(kAudioStream) auto audio_sample_2 =
->Dispatch(StreamData::FromMediaSample( GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame);
kChild, GetMediaSample(kSample1Start, kSampleDuration, kKeyFrame)));
Input(kAudioStream)
->Dispatch(StreamData::FromMediaSample(
kChild, GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame)));
Input(kAudioStream)->FlushAllDownstreams();
Input(kVideoStream) // Video samples
->Dispatch( auto video_stream_info = GetVideoStreamInfo(kMsTimeScale);
StreamData::FromStreamInfo(kChild, GetVideoStreamInfo(kMsTimeScale))); auto video_sample_0 =
Input(kVideoStream) GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame);
->Dispatch(StreamData::FromMediaSample( auto video_sample_1 =
kChild, GetMediaSample(kSample0Start, kSampleDuration, kKeyFrame))); GetMediaSample(kSample1Start, kSampleDuration, !kKeyFrame);
Input(kVideoStream) auto video_sample_2 =
->Dispatch(StreamData::FromMediaSample( GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame);
kChild, GetMediaSample(kSample1Start, kSampleDuration, !kKeyFrame)));
Input(kVideoStream) // Dispatch Stream Info
->Dispatch(StreamData::FromMediaSample( ASSERT_OK(DispatchStreamInfo(kTextStream, std::move(text_stream_info)));
kChild, GetMediaSample(kSample2Start, kSampleDuration, kKeyFrame))); ASSERT_OK(DispatchStreamInfo(kAudioStream, std::move(audio_stream_info)));
Input(kVideoStream)->FlushAllDownstreams(); ASSERT_OK(DispatchStreamInfo(kVideoStream, std::move(video_stream_info)));
// Dispatch Sample 0
ASSERT_OK(DispatchTextSample(kTextStream, std::move(text_sample_0)));
ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(audio_sample_0)));
ASSERT_OK(DispatchMediaSample(kVideoStream, std::move(video_sample_0)));
// Dispatch Sample 1
ASSERT_OK(DispatchTextSample(kTextStream, std::move(text_sample_1)));
ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(audio_sample_1)));
ASSERT_OK(DispatchMediaSample(kVideoStream, std::move(video_sample_1)));
// Dispatch Sample 2
ASSERT_OK(DispatchTextSample(kTextStream, std::move(text_sample_2)));
ASSERT_OK(DispatchMediaSample(kAudioStream, std::move(audio_sample_2)));
ASSERT_OK(DispatchMediaSample(kVideoStream, std::move(video_sample_2)));
ASSERT_OK(FlushAll({kTextStream, kAudioStream, kVideoStream}));
} }
// TODO(kqyang): Add more tests, in particular, multi-thread tests. // TODO(kqyang): Add more tests, in particular, multi-thread tests.