diff --git a/packager/media/formats/webvtt/webvtt_file_buffer.cc b/packager/media/formats/webvtt/webvtt_file_buffer.cc index d73a4657d6..02507c1858 100644 --- a/packager/media/formats/webvtt/webvtt_file_buffer.cc +++ b/packager/media/formats/webvtt/webvtt_file_buffer.cc @@ -73,10 +73,12 @@ void WebVttFileBuffer::Append(const TextSample& sample) { buffer_.append("\n"); // end of sample } -bool WebVttFileBuffer::WriteTo(File* file) { +bool WebVttFileBuffer::WriteTo(File* file, uint64_t* size) { DCHECK(file); 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()); if (written < 0) { return false; diff --git a/packager/media/formats/webvtt/webvtt_file_buffer.h b/packager/media/formats/webvtt/webvtt_file_buffer.h index 04f8cede61..5656ba93d5 100644 --- a/packager/media/formats/webvtt/webvtt_file_buffer.h +++ b/packager/media/formats/webvtt/webvtt_file_buffer.h @@ -27,7 +27,7 @@ class WebVttFileBuffer { void Reset(); 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. size_t sample_count() const { return sample_count_; } diff --git a/packager/media/formats/webvtt/webvtt_muxer.cc b/packager/media/formats/webvtt/webvtt_muxer.cc index b3cb7865b6..b4c031ff51 100644 --- a/packager/media/formats/webvtt/webvtt_muxer.cc +++ b/packager/media/formats/webvtt/webvtt_muxer.cc @@ -45,15 +45,12 @@ Status WebVttMuxer::WriteToFile(const std::string& filename, uint64_t* size) { return Status(error::FILE_FAILURE, "Failed to open " + filename); } - buffer_->WriteTo(file.get()); + buffer_->WriteTo(file.get(), size); buffer_->Reset(); if (!file.release()->Close()) { return Status(error::FILE_FAILURE, "Failed to close " + filename); } - if (size) { - *size = File::GetFileSize(filename.c_str()); - } return Status::OK; }