Fix language option not honored on text streams

Change-Id: I9034b779e9b193c39201a5f2d142ec390927e5f7
This commit is contained in:
KongQun Yang 2018-02-07 18:28:51 -08:00
parent 0401d62a3f
commit aa4bb49b2f
6 changed files with 34 additions and 13 deletions

View File

@ -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,

View File

@ -46,8 +46,9 @@ bool MaybeCueId(const std::string& line) {
}
} // namespace
WebVttParser::WebVttParser(std::unique_ptr<FileReader> source)
: reader_(std::move(source)) {}
WebVttParser::WebVttParser(std::unique_ptr<FileReader> 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<StreamInfo>(info));
}

View File

@ -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<FileReader> source);
WebVttParser(std::unique_ptr<FileReader> 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;
};

View File

@ -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<FileReader> reader;
ASSERT_OK(FileReader::Open(kFilename, &reader));
parser_ = std::make_shared<WebVttParser>(std::move(reader));
parser_ = std::make_shared<WebVttParser>(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));
}

View File

@ -109,7 +109,9 @@ TEST(WebVttTextPipelineTest, SegmentedOutput) {
ASSERT_TRUE(File::WriteStringToFile(kInputFile, kInput));
std::unique_ptr<FileReader> reader;
ASSERT_OK(FileReader::Open(kInputFile, &reader));
std::shared_ptr<OriginHandler> parser(new WebVttParser(std::move(reader)));
const char kLanguage[] = "en";
std::shared_ptr<OriginHandler> parser(
new WebVttParser(std::move(reader), kLanguage));
std::shared_ptr<MediaHandler> segmenter(
new WebVttSegmenter(kSegmentDuration));

View File

@ -431,7 +431,8 @@ Status CreateHlsTextJob(const StreamDescriptor& stream,
return open_status;
}
std::shared_ptr<OriginHandler> parser(new WebVttParser(std::move(reader)));
std::shared_ptr<OriginHandler> parser(
new WebVttParser(std::move(reader), stream.language));
std::shared_ptr<MediaHandler> segmenter(
new WebVttSegmenter(segment_length_in_ms));
@ -460,7 +461,8 @@ Status CreateWebVttToMp4TextJob(const StreamDescriptor& stream,
return status;
}
std::shared_ptr<OriginHandler> parser(new WebVttParser(std::move(reader)));
std::shared_ptr<OriginHandler> parser(
new WebVttParser(std::move(reader), stream.language));
std::shared_ptr<MediaHandler> text_to_mp4(new WebVttToMp4Handler);
std::shared_ptr<MediaHandler> chunker(
new ChunkingHandler(packaging_params.chunking_params));