Use bytes_read == 0 instead of EoF()
Due to various libraries' inconsistencies with using EoF, this change will instead continue to read a file until the number of bytes read is 0. It considers bytes_read == 0 to mean end of file. Change-Id: I90a592d6ae2b9879fe21bd0c4f9e1c9cbc680afe
This commit is contained in:
parent
269aced6f0
commit
6a7c6a3f7a
|
@ -159,11 +159,10 @@ Status Demuxer::Parse() {
|
||||||
return init_parsing_status_;
|
return init_parsing_status_;
|
||||||
|
|
||||||
int64_t bytes_read = media_file_->Read(buffer_.get(), kBufSize);
|
int64_t bytes_read = media_file_->Read(buffer_.get(), kBufSize);
|
||||||
if (bytes_read <= 0) {
|
if (bytes_read == 0) {
|
||||||
if (media_file_->Eof()) {
|
|
||||||
parser_->Flush();
|
parser_->Flush();
|
||||||
return Status(error::END_OF_STREAM, "");
|
return Status(error::END_OF_STREAM, "");
|
||||||
}
|
} else if (bytes_read < 0) {
|
||||||
return Status(error::FILE_FAILURE, "Cannot read file " + file_name_);
|
return Status(error::FILE_FAILURE, "Cannot read file " + file_name_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,9 +117,11 @@ Status SingleSegmentSegmenter::DoFinalize() {
|
||||||
|
|
||||||
const int kBufSize = 0x200000; // 2MB.
|
const int kBufSize = 0x200000; // 2MB.
|
||||||
scoped_ptr<uint8_t[]> buf(new uint8_t[kBufSize]);
|
scoped_ptr<uint8_t[]> buf(new uint8_t[kBufSize]);
|
||||||
while (!temp_file->Eof()) {
|
while (true) {
|
||||||
int64_t size = temp_file->Read(buf.get(), kBufSize);
|
int64_t size = temp_file->Read(buf.get(), kBufSize);
|
||||||
if (size <= 0) {
|
if (size == 0) {
|
||||||
|
break;
|
||||||
|
} else if (size < 0) {
|
||||||
return Status(error::FILE_FAILURE,
|
return Status(error::FILE_FAILURE,
|
||||||
"Failed to read file " + temp_file_name_);
|
"Failed to read file " + temp_file_name_);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue