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