From 1e9e5d1f582edfa51c2ebde188c70b7ff5ead950 Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Mon, 2 Oct 2017 14:35:55 -0700 Subject: [PATCH] Integration Test for WebVtt Pipelines Connected the WebVtt Pipeline together to test that the parser, segmenter, and output all work together as expected. Change-Id: I07138f7b5b1318f84c27c5b607d8df207c57ddb3 --- packager/media/formats/webvtt/webvtt.gyp | 3 +- .../webvtt/webvtt_pipeline_unittest.cc | 133 ++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 packager/media/formats/webvtt/webvtt_pipeline_unittest.cc diff --git a/packager/media/formats/webvtt/webvtt.gyp b/packager/media/formats/webvtt/webvtt.gyp index fab0bc77c4..687720bc1f 100644 --- a/packager/media/formats/webvtt/webvtt.gyp +++ b/packager/media/formats/webvtt/webvtt.gyp @@ -49,7 +49,7 @@ 'webvtt_parser_unittest.cc', 'webvtt_sample_converter_unittest.cc', 'webvtt_segmenter_unittest.cc', - 'webvtt_timestamp_unittest.cc', + 'webvtt_pipeline_unittest.cc', 'webvtt_timestamp_unittest.cc', 'webvtt_to_mp4_handler_unittest.cc', ], @@ -57,6 +57,7 @@ '../../../testing/gmock.gyp:gmock', '../../../testing/gtest.gyp:gtest', '../../base/media_base.gyp:media_handler_test_base', + '../../event/media_event.gyp:mock_muxer_listener', '../../test/media_test.gyp:media_test_support', 'webvtt', ] diff --git a/packager/media/formats/webvtt/webvtt_pipeline_unittest.cc b/packager/media/formats/webvtt/webvtt_pipeline_unittest.cc new file mode 100644 index 0000000000..3423e7ae43 --- /dev/null +++ b/packager/media/formats/webvtt/webvtt_pipeline_unittest.cc @@ -0,0 +1,133 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#include +#include + +#include "packager/file/file_test_util.h" +#include "packager/media/base/media_handler_test_base.h" +#include "packager/media/event/mock_muxer_listener.h" +#include "packager/media/formats/webvtt/text_readers.h" +#include "packager/media/formats/webvtt/webvtt_output_handler.h" +#include "packager/media/formats/webvtt/webvtt_parser.h" +#include "packager/media/formats/webvtt/webvtt_segmenter.h" +#include "packager/status_test_util.h" + +namespace shaka { +namespace media { + +TEST(WebVttTextPipelineTest, SegmentedOutput) { + const uint64_t kSegmentDuration = 10000; // 10 seconds + + const char* kTemplate = "memory://output/template-$Number$.vtt"; + const char* kOutput1 = "memory://output/template-1.vtt"; + const char* kOutput2 = "memory://output/template-2.vtt"; + const char* kOutput3 = "memory://output/template-3.vtt"; + + const char* kInputFile = "memory://input.vtt"; + const char* kInput = + "WEBVTT\n" + "\n" + "1\n" + "00:00:18.700 --> 00:00:21.500\n" + "This blade has a dark past.\n" + "\n" + "2\n" + "00:00:22.800 --> 00:00:26.800\n" + "It has shed much innocent blood.\n" + "\n" + "3\n" + "00:00:29.000 --> 00:00:32.450\n" + "You're a fool for traveling alone,\n" + "so completely unprepared.\n" + "\n" + "4\n" + "00:00:32.750 --> 00:00:35.800\n" + "You're lucky your blood's still flowing.\n" + "\n" + "5\n" + "00:00:36.250 --> 00:00:37.300\n" + "Thank you.\n"; + + // Segment One + // 00:00:10.000 to 00:00:20.000 + const char* kExpectedOutput1 = + "WEBVTT\n" + "\n" + "1\n" + "00:00:18.700 --> 00:00:21.500\n" + "This blade has a dark past.\n" + "\n"; + + // Segment Two + // 00:00:20.000 to 00:00:30.000 + const char* kExpectedOutput2 = + "WEBVTT\n" + "\n" + "1\n" + "00:00:18.700 --> 00:00:21.500\n" + "This blade has a dark past.\n" + "\n" + "2\n" + "00:00:22.800 --> 00:00:26.800\n" + "It has shed much innocent blood.\n" + "\n" + "3\n" + "00:00:29.000 --> 00:00:32.450\n" + "You're a fool for traveling alone,\nso completely unprepared.\n" + "\n"; + + // Segment Three + // 00:00:30.000 to 00:00:40.000 + const char* kExpectedOutput3 = + "WEBVTT\n" + "\n" + "3\n" + "00:00:29.000 --> 00:00:32.450\n" + "You're a fool for traveling alone,\nso completely unprepared.\n" + "\n" + "4\n" + "00:00:32.750 --> 00:00:35.800\n" + "You're lucky your blood's still flowing.\n" + "\n" + "5\n" + "00:00:36.250 --> 00:00:37.300\n" + "Thank you.\n" + "\n"; + + // Create the input file and the file reader. + ASSERT_TRUE(File::WriteStringToFile(kInputFile, kInput)); + std::unique_ptr reader; + ASSERT_OK(FileReader::Open(kInputFile, &reader)); + std::shared_ptr parser(new WebVttParser(std::move(reader))); + + std::shared_ptr segmenter( + new WebVttSegmenter(kSegmentDuration)); + + // Create the output handler. Because we are not verifying the manifest, we + // are using the combined muxer listener as a noop. + MuxerOptions options; + options.segment_template = kTemplate; + std::unique_ptr listener( + new testing::NiceMock()); + std::shared_ptr output( + new WebVttSegmentedOutputHandler(options, std::move(listener))); + + // Set up the graph + ASSERT_OK(segmenter->AddHandler(std::move(output))); + ASSERT_OK(parser->AddHandler(std::move(segmenter))); + + // Initialize and start the pipeline + ASSERT_OK(parser->Initialize()); + ASSERT_OK(parser->Run()); + + // Make sure all the files appear as expected. + ASSERT_FILE_STREQ(kOutput1, kExpectedOutput1); + ASSERT_FILE_STREQ(kOutput2, kExpectedOutput2); + ASSERT_FILE_STREQ(kOutput3, kExpectedOutput3); +} +} // namespace media +} // namespace shaka