From 113a7d123bacaaab3f48c2ba1c3f77e75a694278 Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Mon, 2 Apr 2018 16:20:14 -0700 Subject: [PATCH] Don't Output Empty Text Samples Only output text samples to webvtt text output when they have a payload. Change-Id: I958d2b4f087209f540fa32cef002cd2cef37c65c --- .../hls-segmented-webvtt/bear-subtitle-english-text-1.vtt | 3 --- packager/media/formats/webvtt/webvtt_output_handler.cc | 8 +++++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packager/app/test/testdata/hls-segmented-webvtt/bear-subtitle-english-text-1.vtt b/packager/app/test/testdata/hls-segmented-webvtt/bear-subtitle-english-text-1.vtt index cf4aec6ee0..81150bae25 100644 --- a/packager/app/test/testdata/hls-segmented-webvtt/bear-subtitle-english-text-1.vtt +++ b/packager/app/test/testdata/hls-segmented-webvtt/bear-subtitle-english-text-1.vtt @@ -3,6 +3,3 @@ WEBVTT 00:00:00.000 --> 00:00:00.800 Yup, that's a bear, eh. -00:00:00.800 --> 00:00:01.000 - - diff --git a/packager/media/formats/webvtt/webvtt_output_handler.cc b/packager/media/formats/webvtt/webvtt_output_handler.cc index db8893a4ce..1f4c90d606 100644 --- a/packager/media/formats/webvtt/webvtt_output_handler.cc +++ b/packager/media/formats/webvtt/webvtt_output_handler.cc @@ -18,6 +18,8 @@ void WebVttOutputHandler::WriteCue(const std::string& id, uint64_t end_ms, const std::string& settings, const std::string& payload) { + DCHECK_GT(payload.size(), 0u); + // Build a block of text that makes up the cue so that we can use a loop to // write all the lines. const std::string start = MsToWebVttTimestamp(start_ms); @@ -148,7 +150,11 @@ Status WebVttSegmentedOutputHandler::OnTextSample(const TextSample& sample) { const std::string& settings = sample.settings(); const std::string& payload = sample.payload(); - WriteCue(id, start_ms, end_ms, settings, payload); + // Only write cues that have payloads. Cue without payloads won't present + // any information to the user. + if (payload.size()) { + WriteCue(id, start_ms, end_ms, settings, payload); + } return Status::OK; }