Prepare WebVTT To MP4 to handle gaps

Adding all the code needed to allow the webvtt to mp4 converter to
send empty vtt cues. This change does everything except writing the
mp4 box.

Bug: #324
Change-Id: I16188e6357632b2ed06f7e9bab7844f093266696
This commit is contained in:
Aaron Vaage 2018-02-05 11:27:06 -08:00
parent 9452a1bb1a
commit c991490e82
2 changed files with 20 additions and 13 deletions

View File

@ -85,9 +85,7 @@ Status WebVttToMp4Handler::Process(std::unique_ptr<StreamData> 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_++;
}

View File

@ -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();