WebVTT Text to Mp4 - Verify Media Sample Contents

In our text to mp4 tests, we were only checking if the times on
the samples lined-up with what we were expecting.

We want to check that text sample contents (ids, settings, and
payloads) were correctly merged into a single media sample. To
verify this, we now check if the sample ids appear in the
media sample.

Change-Id: Ica1a85a14e7b116275e3571332b2e90d7bc44c45
This commit is contained in:
Aaron Vaage 2018-05-31 14:04:11 -07:00
parent 668bae314f
commit 2c1faa71a0
1 changed files with 144 additions and 49 deletions

View File

@ -11,6 +11,9 @@
#include "packager/media/formats/webvtt/webvtt_to_mp4_handler.h" #include "packager/media/formats/webvtt/webvtt_to_mp4_handler.h"
#include "packager/status_test_util.h" #include "packager/status_test_util.h"
using testing::AllOf;
using testing::Not;
namespace shaka { namespace shaka {
namespace media { namespace media {
namespace { namespace {
@ -23,6 +26,26 @@ const char* kId2 = "sample-id-2";
const char* kId3 = "sample-id-3"; const char* kId3 = "sample-id-3";
} // namespace } // namespace
MATCHER_P(MediaSampleContainsId, id, "") {
auto& sample = arg->media_sample;
if (!sample) {
return false;
}
// Convert the sample to a string so that we can look for the id but also
// so we can print the data if we need to look at it. Replace the
// non-displayable characters with "." as they can cause problems.
std::string s;
for (size_t i = 0; i < sample->data_size(); i++) {
char c = static_cast<char>(sample->data()[i]);
s.push_back(isprint(c) ? c : '.');
}
*result_listener << s << " does not contain " << id;
return s.find(id) != std::string::npos;
}
class WebVttToMp4HandlerTest : public MediaHandlerTestBase { class WebVttToMp4HandlerTest : public MediaHandlerTestBase {
protected: protected:
Status SetUpTestGraph() { Status SetUpTestGraph() {
@ -101,11 +124,17 @@ TEST_F(WebVttToMp4HandlerTest, NonZeroStartTime) {
EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex))); EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex)));
// Gap // Gap
EXPECT_CALL(*Out(), OnProcess(IsMediaSample(kStreamIndex, kGapStart, EXPECT_CALL(*Out(),
kGapDuration, !kEncrypted))); OnProcess(AllOf(IsMediaSample(kStreamIndex, kGapStart,
kGapDuration, !kEncrypted),
Not(MediaSampleContainsId(kId1)))));
// Sample // Sample
EXPECT_CALL(*Out(), OnProcess(IsMediaSample(kStreamIndex, kSampleStart, EXPECT_CALL(*Out(),
kSampleDuration, !kEncrypted))); OnProcess(AllOf(IsMediaSample(kStreamIndex, kSampleStart,
kSampleDuration, !kEncrypted),
MediaSampleContainsId(kId1))));
// Segment // Segment
EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart, EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart,
kSegmentDuration, !kSubSegment, kSegmentDuration, !kSubSegment,
@ -153,15 +182,25 @@ TEST_F(WebVttToMp4HandlerTest, NoOverlap) {
// Sample 1 // Sample 1
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kSample1Start, OnProcess(AllOf(IsMediaSample(kStreamIndex, kSample1Start,
kSample1Duration, !kEncrypted))); kSample1Duration, !kEncrypted),
MediaSampleContainsId(kId1),
Not(MediaSampleContainsId(kId2)))));
// Gap // Gap
EXPECT_CALL(*Out(), OnProcess(IsMediaSample(kStreamIndex, kGapStart, EXPECT_CALL(*Out(),
kGapDuration, !kEncrypted))); OnProcess(AllOf(IsMediaSample(kStreamIndex, kGapStart,
kGapDuration, !kEncrypted),
Not(MediaSampleContainsId(kId1)),
Not(MediaSampleContainsId(kId2)))));
// Sample 2 // Sample 2
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kSample2Start, OnProcess(AllOf(IsMediaSample(kStreamIndex, kSample2Start,
kSample2Duration, !kEncrypted))); kSample2Duration, !kEncrypted),
Not(MediaSampleContainsId(kId1)),
MediaSampleContainsId(kId2))));
// Segment // Segment
EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart, EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart,
kSegmentDuration, !kSubSegment, kSegmentDuration, !kSubSegment,
@ -215,17 +254,26 @@ TEST_F(WebVttToMp4HandlerTest, Overlap) {
EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex))); EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex)));
// Sample 1 // Sample 1
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(), OnProcess(AllOf(
OnProcess(IsMediaSample(kStreamIndex, kOnlySample1Start, IsMediaSample(kStreamIndex, kOnlySample1Start,
kOnlySample1Duration, !kEncrypted))); kOnlySample1Duration, !kEncrypted),
MediaSampleContainsId(kId1),
Not(MediaSampleContainsId(kId2)))));
// Sample 1 and Sample 2 // Sample 1 and Sample 2
EXPECT_CALL(*Out(), OnProcess(IsMediaSample(
kStreamIndex, kSample1AndSample2Start,
kSample1AndSample2Duration, !kEncrypted)));
// Sample 2
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kOnlySample2Start, OnProcess(AllOf(
kOnlySample2Duration, !kEncrypted))); IsMediaSample(kStreamIndex, kSample1AndSample2Start,
kSample1AndSample2Duration, !kEncrypted),
MediaSampleContainsId(kId1), MediaSampleContainsId(kId2))));
// Sample 2
EXPECT_CALL(*Out(), OnProcess(AllOf(
IsMediaSample(kStreamIndex, kOnlySample2Start,
kOnlySample2Duration, !kEncrypted),
Not(MediaSampleContainsId(kId1)),
MediaSampleContainsId(kId2))));
// Segment // Segment
EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart, EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart,
kSegmentDuration, !kSubSegment, kSegmentDuration, !kSubSegment,
@ -281,17 +329,26 @@ TEST_F(WebVttToMp4HandlerTest, Contains) {
EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex))); EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex)));
// Sample 1 // Sample 1
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(), OnProcess(AllOf(
OnProcess(IsMediaSample(kStreamIndex, kBeforeSample2Start, IsMediaSample(kStreamIndex, kBeforeSample2Start,
kBeforeSample2Duration, !kEncrypted))); kBeforeSample2Duration, !kEncrypted),
MediaSampleContainsId(kId1),
Not(MediaSampleContainsId(kId2)))));
// Sample 1 and Sample 2 // Sample 1 and Sample 2
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kDuringSample2Start, OnProcess(AllOf(
kDuringSample2Duration, !kEncrypted))); IsMediaSample(kStreamIndex, kDuringSample2Start,
kDuringSample2Duration, !kEncrypted),
MediaSampleContainsId(kId1), MediaSampleContainsId(kId2))));
// Sample 1 Again // Sample 1 Again
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(), OnProcess(AllOf(
OnProcess(IsMediaSample(kStreamIndex, kAfterSample2Start, IsMediaSample(kStreamIndex, kAfterSample2Start,
kAfterSample2Duration, !kEncrypted))); kAfterSample2Duration, !kEncrypted),
MediaSampleContainsId(kId1),
Not(MediaSampleContainsId(kId2)))));
// Segment // Segment
EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart, EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart,
kSegmentDuration, !kSubSegment, kSegmentDuration, !kSubSegment,
@ -331,8 +388,12 @@ TEST_F(WebVttToMp4HandlerTest, ExactOverlap) {
EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex))); EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex)));
// Both Samples // Both Samples
EXPECT_CALL(*Out(), OnProcess(IsMediaSample(kStreamIndex, kSampleStart, EXPECT_CALL(*Out(),
kSampleDuration, !kEncrypted))); OnProcess(AllOf(IsMediaSample(kStreamIndex, kSampleStart,
kSampleDuration, !kEncrypted),
MediaSampleContainsId(kId1),
MediaSampleContainsId(kId2))));
// Segment // Segment
EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart, EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart,
kSegmentDuration, !kSubSegment, kSegmentDuration, !kSubSegment,
@ -390,16 +451,28 @@ TEST_F(WebVttToMp4HandlerTest, OverlapStartWithStaggerEnd) {
// Three Samples // Three Samples
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kThreeSamplesStart, OnProcess(AllOf(
kThreeSamplesDuration, !kEncrypted))); IsMediaSample(kStreamIndex, kThreeSamplesStart,
kThreeSamplesDuration, !kEncrypted),
MediaSampleContainsId(kId1), MediaSampleContainsId(kId2),
MediaSampleContainsId(kId3))));
// Two Samples // Two Samples
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kTwoSamplesStart, OnProcess(AllOf(IsMediaSample(kStreamIndex, kTwoSamplesStart,
kTwoSamplesDuration, !kEncrypted))); kTwoSamplesDuration, !kEncrypted),
MediaSampleContainsId(kId1),
MediaSampleContainsId(kId2),
Not(MediaSampleContainsId(kId3)))));
// One Sample // One Sample
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kOneSampleStart, OnProcess(AllOf(IsMediaSample(kStreamIndex, kOneSampleStart,
kOneSampleDuration, !kEncrypted))); kOneSampleDuration, !kEncrypted),
MediaSampleContainsId(kId1),
Not(MediaSampleContainsId(kId2)),
Not(MediaSampleContainsId(kId3)))));
// Segment // Segment
EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart, EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart,
kSegmentDuration, !kSubSegment, kSegmentDuration, !kSubSegment,
@ -458,16 +531,28 @@ TEST_F(WebVttToMp4HandlerTest, StaggerStartWithOverlapEnd) {
// One Sample // One Sample
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kOneSampleStart, OnProcess(AllOf(IsMediaSample(kStreamIndex, kOneSampleStart,
kOneSampleDuration, !kEncrypted))); kOneSampleDuration, !kEncrypted),
MediaSampleContainsId(kId1),
Not(MediaSampleContainsId(kId2)),
Not(MediaSampleContainsId(kId3)))));
// Two Samples // Two Samples
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kTwoSamplesStart, OnProcess(AllOf(IsMediaSample(kStreamIndex, kTwoSamplesStart,
kTwoSamplesDuration, !kEncrypted))); kTwoSamplesDuration, !kEncrypted),
MediaSampleContainsId(kId1),
MediaSampleContainsId(kId2),
Not(MediaSampleContainsId(kId3)))));
// Three Samples // Three Samples
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kThreeSamplesStart, OnProcess(AllOf(
kThreeSamplesDuration, !kEncrypted))); IsMediaSample(kStreamIndex, kThreeSamplesStart,
kThreeSamplesDuration, !kEncrypted),
MediaSampleContainsId(kId1), MediaSampleContainsId(kId2),
MediaSampleContainsId(kId3))));
// Segment // Segment
EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart, EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart,
kSegmentDuration, !kSubSegment, kSegmentDuration, !kSubSegment,
@ -521,21 +606,31 @@ TEST_F(WebVttToMp4HandlerTest, CrossSegmentSamples) {
EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex))); EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex)));
// Gap, Sample, Segment // Gap, Sample, Segment
EXPECT_CALL(*Out(), OnProcess(IsMediaSample(kStreamIndex, kGap1Start,
kGapDuration, !kEncrypted)));
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kSamplePart1Start, OnProcess(AllOf(IsMediaSample(kStreamIndex, kGap1Start,
kSamplePart1Duration, !kEncrypted))); kGapDuration, !kEncrypted),
Not(MediaSampleContainsId(kId1)))));
EXPECT_CALL(*Out(), OnProcess(AllOf(
IsMediaSample(kStreamIndex, kSamplePart1Start,
kSamplePart1Duration, !kEncrypted),
MediaSampleContainsId(kId1))));
EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegment1Start, EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegment1Start,
kSegmentDuration, !kSubSegment, kSegmentDuration, !kSubSegment,
!kEncrypted))); !kEncrypted)));
// Sample, Gap, Segment // Sample, Gap, Segment
EXPECT_CALL(*Out(), OnProcess(AllOf(
IsMediaSample(kStreamIndex, kSamplePart2Start,
kSamplePart2Duration, !kEncrypted),
MediaSampleContainsId(kId1))));
EXPECT_CALL(*Out(), EXPECT_CALL(*Out(),
OnProcess(IsMediaSample(kStreamIndex, kSamplePart2Start, OnProcess(AllOf(IsMediaSample(kStreamIndex, kGap2Start,
kSamplePart2Duration, !kEncrypted))); kGapDuration, !kEncrypted),
EXPECT_CALL(*Out(), OnProcess(IsMediaSample(kStreamIndex, kGap2Start, Not(MediaSampleContainsId(kId1)))));
kGapDuration, !kEncrypted)));
EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegment2Start, EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegment2Start,
kSegmentDuration, !kSubSegment, kSegmentDuration, !kSubSegment,
!kEncrypted))); !kEncrypted)));