fix: Fix failure on very short WebVTT files (#1216)
Fix a bug that if the webvtt file is very short, e.g. only contains one block WEBVTT 00:00:00.500 --> 00:00:02.000 The Web is always changing shaka packager will report error: "Packaging Error: 6 (END_OF_STREAM)". Fixes #1217
This commit is contained in:
parent
d9d3c7f8be
commit
dab165d3e5
|
@ -162,13 +162,16 @@ Status Demuxer::InitializeParser() {
|
||||||
|
|
||||||
// Read enough bytes before detecting the container.
|
// Read enough bytes before detecting the container.
|
||||||
int64_t bytes_read = 0;
|
int64_t bytes_read = 0;
|
||||||
|
bool eof = false;
|
||||||
while (static_cast<size_t>(bytes_read) < kInitBufSize) {
|
while (static_cast<size_t>(bytes_read) < kInitBufSize) {
|
||||||
int64_t read_result =
|
int64_t read_result =
|
||||||
media_file_->Read(buffer_.get() + bytes_read, kInitBufSize);
|
media_file_->Read(buffer_.get() + bytes_read, kInitBufSize);
|
||||||
if (read_result < 0)
|
if (read_result < 0)
|
||||||
return Status(error::FILE_FAILURE, "Cannot read file " + file_name_);
|
return Status(error::FILE_FAILURE, "Cannot read file " + file_name_);
|
||||||
if (read_result == 0)
|
if (read_result == 0) {
|
||||||
|
eof = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
bytes_read += read_result;
|
bytes_read += read_result;
|
||||||
}
|
}
|
||||||
container_name_ = DetermineContainer(buffer_.get(), bytes_read);
|
container_name_ = DetermineContainer(buffer_.get(), bytes_read);
|
||||||
|
@ -224,7 +227,7 @@ Status Demuxer::InitializeParser() {
|
||||||
// descriptor |media_file_| instead of opening the same file again.
|
// descriptor |media_file_| instead of opening the same file again.
|
||||||
static_cast<mp4::MP4MediaParser*>(parser_.get())->LoadMoov(file_name_);
|
static_cast<mp4::MP4MediaParser*>(parser_.get())->LoadMoov(file_name_);
|
||||||
}
|
}
|
||||||
if (!parser_->Parse(buffer_.get(), bytes_read)) {
|
if (!parser_->Parse(buffer_.get(), bytes_read) || (eof && !parser_->Flush())) {
|
||||||
return Status(error::PARSER_FAILURE,
|
return Status(error::PARSER_FAILURE,
|
||||||
"Cannot parse media file " + file_name_);
|
"Cannot parse media file " + file_name_);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue