From 061777db9bf575ba73976004e4f2725f735b5519 Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Fri, 6 Apr 2018 13:19:39 -0700 Subject: [PATCH] Add CueEvent Support To WebVtt Output The WebVtt Output Handler did not recognize cue events. This change allows the handler to accept the events and tell muxer listener about them. Issue #362 Change-Id: I7c3318b72e539adc19af587c8e213fdb0af8290b --- .../media/formats/webvtt/webvtt_output_handler.cc | 14 ++++++++++++++ .../media/formats/webvtt/webvtt_output_handler.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/packager/media/formats/webvtt/webvtt_output_handler.cc b/packager/media/formats/webvtt/webvtt_output_handler.cc index 1f4c90d606..7ab31d5f18 100644 --- a/packager/media/formats/webvtt/webvtt_output_handler.cc +++ b/packager/media/formats/webvtt/webvtt_output_handler.cc @@ -13,6 +13,10 @@ namespace shaka { namespace media { +namespace { +double kMillisecondsToSeconds = 1000.0; +} // namespace + void WebVttOutputHandler::WriteCue(const std::string& id, uint64_t start_ms, uint64_t end_ms, @@ -91,6 +95,8 @@ Status WebVttOutputHandler::Process(std::unique_ptr stream_data) { return OnStreamInfo(*stream_data->stream_info); case StreamDataType::kSegmentInfo: return OnSegmentInfo(*stream_data->segment_info); + case StreamDataType::kCueEvent: + return OnCueEvent(*stream_data->cue_event); case StreamDataType::kTextSample: return OnTextSample(*stream_data->text_sample); default: @@ -143,6 +149,14 @@ Status WebVttSegmentedOutputHandler::OnSegmentInfo(const SegmentInfo& info) { return Status::OK; } +Status WebVttSegmentedOutputHandler::OnCueEvent(const CueEvent& event) { + double timestamp_seconds = event.time_in_seconds; + double timestamp_ms = timestamp_seconds * kMillisecondsToSeconds; + uint64_t timestamp = static_cast(timestamp_ms); + muxer_listener_->OnCueEvent(timestamp, event.cue_data); + return Status::OK; +} + Status WebVttSegmentedOutputHandler::OnTextSample(const TextSample& sample) { const std::string& id = sample.id(); const uint64_t start_ms = sample.start_time(); diff --git a/packager/media/formats/webvtt/webvtt_output_handler.h b/packager/media/formats/webvtt/webvtt_output_handler.h index 54e3702669..e1ed2986ed 100644 --- a/packager/media/formats/webvtt/webvtt_output_handler.h +++ b/packager/media/formats/webvtt/webvtt_output_handler.h @@ -29,6 +29,7 @@ class WebVttOutputHandler : public MediaHandler { protected: virtual Status OnStreamInfo(const StreamInfo& info) = 0; virtual Status OnSegmentInfo(const SegmentInfo& info) = 0; + virtual Status OnCueEvent(const CueEvent& event) = 0; virtual Status OnTextSample(const TextSample& sample) = 0; virtual Status OnStreamEnd() = 0; @@ -65,6 +66,7 @@ class WebVttSegmentedOutputHandler : public WebVttOutputHandler { private: Status OnStreamInfo(const StreamInfo& info) override; Status OnSegmentInfo(const SegmentInfo& info) override; + Status OnCueEvent(const CueEvent& event) override; Status OnTextSample(const TextSample& sample) override; Status OnStreamEnd() override;