7 #include "packager/media/formats/webvtt/webvtt_file_buffer.h" 9 #include "packager/media/base/text_sample.h" 10 #include "packager/media/formats/webvtt/webvtt_timestamp.h" 15 const char* kHeader =
"WEBVTT\n\n";
18 WebVttFileBuffer::WebVttFileBuffer() {
24 void WebVttFileBuffer::Reset() {
28 buffer_.append(kHeader);
31 void WebVttFileBuffer::Append(
const TextSample& sample) {
32 DCHECK_GT(buffer_.size(), 0u) <<
"The buffer should at least have a header";
37 if (sample.id().length()) {
38 buffer_.append(sample.id());
43 buffer_.append(MsToWebVttTimestamp(sample.start_time()));
44 buffer_.append(
" --> ");
45 buffer_.append(MsToWebVttTimestamp(sample.EndTime()));
48 if (sample.settings().length()) {
50 buffer_.append(sample.settings());
54 buffer_.append(sample.payload());
59 bool WebVttFileBuffer::WriteTo(File* file) {
61 DCHECK_GT(buffer_.size(), 0u) <<
"The buffer should at least have a header";
63 const int written = file->Write(buffer_.c_str(), buffer_.size());
68 return static_cast<size_t>(written) == buffer_.size();
All the methods that are virtual are virtual for mocking.