Don't re-open WebVTT file to determine size.
Change-Id: Id92226adce813b7d0c4c741e47e36dbf8f208797
This commit is contained in:
parent
36ef7ec945
commit
95089593fc
|
@ -73,10 +73,12 @@ void WebVttFileBuffer::Append(const TextSample& sample) {
|
||||||
buffer_.append("\n"); // end of sample
|
buffer_.append("\n"); // end of sample
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebVttFileBuffer::WriteTo(File* file) {
|
bool WebVttFileBuffer::WriteTo(File* file, uint64_t* size) {
|
||||||
DCHECK(file);
|
DCHECK(file);
|
||||||
DCHECK_GT(buffer_.size(), 0u) << "The buffer should at least have a header";
|
DCHECK_GT(buffer_.size(), 0u) << "The buffer should at least have a header";
|
||||||
|
|
||||||
|
if (size)
|
||||||
|
*size = buffer_.size();
|
||||||
const int written = file->Write(buffer_.c_str(), buffer_.size());
|
const int written = file->Write(buffer_.c_str(), buffer_.size());
|
||||||
if (written < 0) {
|
if (written < 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -27,7 +27,7 @@ class WebVttFileBuffer {
|
||||||
void Reset();
|
void Reset();
|
||||||
void Append(const TextSample& sample);
|
void Append(const TextSample& sample);
|
||||||
|
|
||||||
bool WriteTo(File* file);
|
bool WriteTo(File* file, uint64_t* size);
|
||||||
|
|
||||||
// Get the number of samples that have been appended to this file.
|
// Get the number of samples that have been appended to this file.
|
||||||
size_t sample_count() const { return sample_count_; }
|
size_t sample_count() const { return sample_count_; }
|
||||||
|
|
|
@ -45,15 +45,12 @@ Status WebVttMuxer::WriteToFile(const std::string& filename, uint64_t* size) {
|
||||||
return Status(error::FILE_FAILURE, "Failed to open " + filename);
|
return Status(error::FILE_FAILURE, "Failed to open " + filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_->WriteTo(file.get());
|
buffer_->WriteTo(file.get(), size);
|
||||||
buffer_->Reset();
|
buffer_->Reset();
|
||||||
if (!file.release()->Close()) {
|
if (!file.release()->Close()) {
|
||||||
return Status(error::FILE_FAILURE, "Failed to close " + filename);
|
return Status(error::FILE_FAILURE, "Failed to close " + filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size) {
|
|
||||||
*size = File::GetFileSize(filename.c_str());
|
|
||||||
}
|
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue