From 299bb97490b10d915af2c6557776c375a3647f9e Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Fri, 20 Mar 2015 11:45:49 -0700 Subject: [PATCH] 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 --- packager/media/base/demuxer.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packager/media/base/demuxer.cc b/packager/media/base/demuxer.cc index d30c33c501..e509816f0c 100644 --- a/packager/media/base/demuxer.cc +++ b/packager/media/base/demuxer.cc @@ -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) - return Status(error::FILE_FAILURE, "Cannot read file " + file_name_); + // 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.