From a191c25f5748c46047da42dffc8e3b8a33f242e3 Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Fri, 23 Mar 2018 10:13:44 -0700 Subject: [PATCH] Clean Up WebVtt Parser There were a couple of bad practices in WebVtt that needed to be cleaned-up. Change-Id: I0fe21e26f11141709d8d855077805fc625e6dad5 --- .../media/formats/webvtt/webvtt_parser.cc | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packager/media/formats/webvtt/webvtt_parser.cc b/packager/media/formats/webvtt/webvtt_parser.cc index b4a8df88eb..02d03ef37e 100644 --- a/packager/media/formats/webvtt/webvtt_parser.cc +++ b/packager/media/formats/webvtt/webvtt_parser.cc @@ -18,6 +18,7 @@ namespace shaka { namespace media { namespace { +const uint64_t kStreamIndex = 0; std::string BlockToString(const std::string* block, size_t size) { std::string out = " --- BLOCK START ---\n"; @@ -70,12 +71,12 @@ Status WebVttParser::InitializeInternal() { bool WebVttParser::ValidateOutputStreamIndex(size_t stream_index) const { // Only support one output - return stream_index == 0; + return stream_index == kStreamIndex; } Status WebVttParser::Run() { return Parse() - ? FlushDownstream(0) + ? FlushDownstream(kStreamIndex) : Status(error::INTERNAL_ERROR, "Failed to parse WebVTT source. See log for details."); } @@ -209,27 +210,27 @@ Status WebVttParser::ParseCue(const std::string& id, sample->AppendPayload(block[i]); } - return DispatchTextSample(0, sample); + return DispatchTextSample(kStreamIndex, sample); } Status WebVttParser::DispatchTextStreamInfo() { + const int kTrackId = 0; // The resolution of timings are in milliseconds. const int kTimescale = 1000; - // The duration passed here is not very important. Also the whole file // must be read before determining the real duration which doesn't // work nicely with the current demuxer. const int kDuration = 0; - const char kWebVttCodecString[] = "wvtt"; + const char kCodecConfig[] = ""; + const int64_t kNoWidth = 0; + const int64_t kNoHeight = 0; - StreamInfo* info = new TextStreamInfo(0, kTimescale, kDuration, kCodecWebVtt, - kWebVttCodecString, "", - 0, // width - 0, // height - language_); + std::shared_ptr info = std::make_shared( + kTrackId, kTimescale, kDuration, kCodecWebVtt, kWebVttCodecString, + kCodecConfig, kNoWidth, kNoHeight, language_); - return DispatchStreamInfo(0, std::shared_ptr(info)); + return DispatchStreamInfo(kStreamIndex, std::move(info)); } } // namespace media } // namespace shaka