diff --git a/packager/media/base/media_handler_test_base.h b/packager/media/base/media_handler_test_base.h index 986df5cf6d..0c9755e928 100644 --- a/packager/media/base/media_handler_test_base.h +++ b/packager/media/base/media_handler_test_base.h @@ -39,6 +39,23 @@ MATCHER_P3(IsStreamInfo, stream_index, time_scale, encrypted, "") { arg->stream_info->is_encrypted() == encrypted; } +MATCHER_P4(IsStreamInfo, stream_index, time_scale, encrypted, language, "") { + if (arg->stream_data_type != StreamDataType::kStreamInfo) { + *result_listener << "which is " + << StreamDataTypeToString(arg->stream_data_type); + return false; + } + + *result_listener << "which is (" << arg->stream_index << "," + << arg->stream_info->time_scale() << "," + << BoolToString(arg->stream_info->is_encrypted()) << "," + << arg->stream_info->language() << ")"; + return arg->stream_index == stream_index && + arg->stream_info->time_scale() == time_scale && + arg->stream_info->is_encrypted() == encrypted && + arg->stream_info->language() == language; +} + MATCHER_P5(IsSegmentInfo, stream_index, start_timestamp, diff --git a/packager/media/formats/webvtt/webvtt_parser.cc b/packager/media/formats/webvtt/webvtt_parser.cc index ff5771dbf4..e0315f0b56 100644 --- a/packager/media/formats/webvtt/webvtt_parser.cc +++ b/packager/media/formats/webvtt/webvtt_parser.cc @@ -46,8 +46,9 @@ bool MaybeCueId(const std::string& line) { } } // namespace -WebVttParser::WebVttParser(std::unique_ptr source) - : reader_(std::move(source)) {} +WebVttParser::WebVttParser(std::unique_ptr source, + const std::string& language) + : reader_(std::move(source)), language_(language) {} Status WebVttParser::InitializeInternal() { return Status::OK; @@ -186,17 +187,13 @@ Status WebVttParser::DispatchTextStreamInfo() { // work nicely with the current demuxer. const int kDuration = 0; - // There is no one metadata to determine what the language is. Parts - // of the text may be annotated as some specific language. - const char kLanguage[] = ""; - const char kWebVttCodecString[] = "wvtt"; StreamInfo* info = new TextStreamInfo(0, kTimescale, kDuration, kCodecWebVtt, kWebVttCodecString, "", 0, // width 0, // height - kLanguage); + language_); return DispatchStreamInfo(0, std::shared_ptr(info)); } diff --git a/packager/media/formats/webvtt/webvtt_parser.h b/packager/media/formats/webvtt/webvtt_parser.h index 2359c54e75..16351fcee2 100644 --- a/packager/media/formats/webvtt/webvtt_parser.h +++ b/packager/media/formats/webvtt/webvtt_parser.h @@ -20,7 +20,7 @@ namespace media { // Used to parse a WebVTT source into Cues that will be sent downstream. class WebVttParser : public OriginHandler { public: - explicit WebVttParser(std::unique_ptr source); + WebVttParser(std::unique_ptr source, const std::string& language); Status Run() override; void Cancel() override; @@ -42,6 +42,7 @@ class WebVttParser : public OriginHandler { Status DispatchTextStreamInfo(); BlockReader reader_; + std::string language_; bool keep_reading_ = true; }; diff --git a/packager/media/formats/webvtt/webvtt_parser_unittest.cc b/packager/media/formats/webvtt/webvtt_parser_unittest.cc index 786fdc05bc..64aa5029cb 100644 --- a/packager/media/formats/webvtt/webvtt_parser_unittest.cc +++ b/packager/media/formats/webvtt/webvtt_parser_unittest.cc @@ -16,6 +16,7 @@ namespace shaka { namespace media { namespace { +const char kLanguage[] = "en"; const size_t kInputCount = 0; const size_t kOutputCount = 1; const size_t kOutputIndex = 0; @@ -40,7 +41,7 @@ class WebVttParserTest : public MediaHandlerTestBase { std::unique_ptr reader; ASSERT_OK(FileReader::Open(kFilename, &reader)); - parser_ = std::make_shared(std::move(reader)); + parser_ = std::make_shared(std::move(reader), kLanguage); ASSERT_OK(MediaHandlerTestBase::SetUpAndInitializeGraph( parser_, kInputCount, kOutputCount)); @@ -70,7 +71,8 @@ TEST_F(WebVttParserTest, ParseOnlyHeader) { { testing::InSequence s; EXPECT_CALL(*Output(kOutputIndex), - OnProcess(IsStreamInfo(kStreamIndex, kTimeScale, !kEncrypted))); + OnProcess(IsStreamInfo(kStreamIndex, kTimeScale, !kEncrypted, + kLanguage))); EXPECT_CALL(*Output(kOutputIndex), OnFlush(kStreamIndex)); } diff --git a/packager/media/formats/webvtt/webvtt_pipeline_unittest.cc b/packager/media/formats/webvtt/webvtt_pipeline_unittest.cc index 565858891c..77ac09e6da 100644 --- a/packager/media/formats/webvtt/webvtt_pipeline_unittest.cc +++ b/packager/media/formats/webvtt/webvtt_pipeline_unittest.cc @@ -109,7 +109,9 @@ TEST(WebVttTextPipelineTest, SegmentedOutput) { 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))); + const char kLanguage[] = "en"; + std::shared_ptr parser( + new WebVttParser(std::move(reader), kLanguage)); std::shared_ptr segmenter( new WebVttSegmenter(kSegmentDuration)); diff --git a/packager/packager.cc b/packager/packager.cc index f53e6cc910..6afad69d72 100644 --- a/packager/packager.cc +++ b/packager/packager.cc @@ -431,7 +431,8 @@ Status CreateHlsTextJob(const StreamDescriptor& stream, return open_status; } - std::shared_ptr parser(new WebVttParser(std::move(reader))); + std::shared_ptr parser( + new WebVttParser(std::move(reader), stream.language)); std::shared_ptr segmenter( new WebVttSegmenter(segment_length_in_ms)); @@ -460,7 +461,8 @@ Status CreateWebVttToMp4TextJob(const StreamDescriptor& stream, return status; } - std::shared_ptr parser(new WebVttParser(std::move(reader))); + std::shared_ptr parser( + new WebVttParser(std::move(reader), stream.language)); std::shared_ptr text_to_mp4(new WebVttToMp4Handler); std::shared_ptr chunker( new ChunkingHandler(packaging_params.chunking_params));