Read enough bytes before detecting the container type

The input source may produce inputs with very small sizes. Demuxer
needs to accumulate enough bytes before trying to detect the container
type.

Issue: https://github.com/google/edash-packager/issues/11
Change-Id: Ie25339832a826e78f39b3b25abb98c1ad89e3021
This commit is contained in:
KongQun Yang 2015-03-20 11:45:49 -07:00
parent f494f1f760
commit 299bb97490
1 changed files with 11 additions and 4 deletions

View File

@ -57,10 +57,17 @@ Status Demuxer::Initialize() {
"Cannot open file for reading " + file_name_);
}
// Determine media container.
int64_t bytes_read = media_file_->Read(buffer_.get(), kInitBufSize);
if (bytes_read <= 0)
// Read enough bytes before detecting the container.
size_t bytes_read = 0;
while (bytes_read < kInitBufSize) {
int64_t read_result =
media_file_->Read(buffer_.get() + bytes_read, kInitBufSize);
if (read_result < 0)
return Status(error::FILE_FAILURE, "Cannot read file " + file_name_);
if (read_result == 0)
break;
bytes_read += read_result;
}
MediaContainerName container = DetermineContainer(buffer_.get(), bytes_read);
// Initialize media parser.