diff --git a/packager/media/formats/webvtt/webvtt_to_mp4_handler.cc b/packager/media/formats/webvtt/webvtt_to_mp4_handler.cc index 450feaf934..0125879a4d 100644 --- a/packager/media/formats/webvtt/webvtt_to_mp4_handler.cc +++ b/packager/media/formats/webvtt/webvtt_to_mp4_handler.cc @@ -85,9 +85,7 @@ Status WebVttToMp4Handler::Process(std::unique_ptr stream_data) { actions_.push(add); actions_.push(remove); - ProcessUpToTime(add->time()); - - return Status::OK; + return ProcessUpToTime(add->time()); } return Status(error::INTERNAL_ERROR, "Invalid stream data type for this handler"); @@ -123,7 +121,7 @@ void WebVttToMp4Handler::WriteCue(const std::string& id, box.Write(out); } -void WebVttToMp4Handler::ProcessUpToTime(uint64_t cutoff_time) { +Status WebVttToMp4Handler::ProcessUpToTime(uint64_t cutoff_time) { // We can only process as far as the last add as no new events will be // added that come before that time. while (actions_.size() && actions_.top()->time() < cutoff_time) { @@ -138,9 +136,14 @@ void WebVttToMp4Handler::ProcessUpToTime(uint64_t cutoff_time) { next_change_ > previous_change); // Send out the active group. If there is nothing in the active group, then - // this segment is ignored. - if (active_.size()) { - MergeAndSendSamples(active_, previous_change, next_change_); + // an empty cue is sent. + Status status = + active_.size() + ? MergeAndSendSamples(active_, previous_change, next_change_) + : SendEmptySample(previous_change, next_change_); + + if (!status.ok()) { + return status; } // STAGE 2: Move to the next state. @@ -149,6 +152,8 @@ void WebVttToMp4Handler::ProcessUpToTime(uint64_t cutoff_time) { actions_.pop(); } } + + return Status::OK; } Status WebVttToMp4Handler::MergeAndSendSamples( @@ -173,6 +178,12 @@ Status WebVttToMp4Handler::MergeAndSendSamples( return DispatchMediaSample(kTrackId, std::move(sample)); } +Status WebVttToMp4Handler::SendEmptySample(uint64_t start_time, + uint64_t end_time) { + // TODO(vaage): Dispatch an empty vtt sample. + return Status::OK; +} + uint64_t WebVttToMp4Handler::NextActionId() { return next_id_++; } diff --git a/packager/media/formats/webvtt/webvtt_to_mp4_handler.h b/packager/media/formats/webvtt/webvtt_to_mp4_handler.h index cc335eb588..366a16a0bc 100644 --- a/packager/media/formats/webvtt/webvtt_to_mp4_handler.h +++ b/packager/media/formats/webvtt/webvtt_to_mp4_handler.h @@ -54,7 +54,7 @@ class WebVttToMp4Handler : public MediaHandler { // queue's time is less than |cutoff|. |cutoff| is needed as we can only // merge and send samples when we are sure no new samples will appear before // the next action. - void ProcessUpToTime(uint64_t cutoff_time); + Status ProcessUpToTime(uint64_t cutoff_time); // Merge together all TextSamples in |samples| into a single MP4 box and // pass the box downstream. @@ -62,11 +62,7 @@ class WebVttToMp4Handler : public MediaHandler { uint64_t start_time, uint64_t end_time); - // Take a Mp4 box as a byte buffer and send it downstream. - Status WriteSample(uint64_t start, - uint64_t end, - const uint8_t* sample, - size_t sample_length); + Status SendEmptySample(uint64_t start_time, uint64_t end_time); // Get a new id for the next action. uint64_t NextActionId();