7 #include "packager/media/formats/webvtt/webvtt_file_buffer.h" 9 #include "packager/base/strings/stringprintf.h" 10 #include "packager/media/base/text_sample.h" 11 #include "packager/media/formats/webvtt/webvtt_timestamp.h" 16 const char* kHeader =
"WEBVTT\n";
17 const int kTsTimescale = 90000;
20 WebVttFileBuffer::WebVttFileBuffer(
21 uint32_t transport_stream_timestamp_offset_ms)
22 : transport_stream_timestamp_offset_(transport_stream_timestamp_offset_ms *
23 kTsTimescale / 1000) {
29 void WebVttFileBuffer::Reset() {
33 buffer_.append(kHeader);
34 if (transport_stream_timestamp_offset_ > 0) {
36 base::StringAppendF(&buffer_,
37 "X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:%d\n",
38 transport_stream_timestamp_offset_);
43 void WebVttFileBuffer::Append(
const TextSample& sample) {
44 DCHECK_GT(buffer_.size(), 0u) <<
"The buffer should at least have a header";
49 if (sample.id().length()) {
50 buffer_.append(sample.id());
55 buffer_.append(MsToWebVttTimestamp(sample.start_time()));
56 buffer_.append(
" --> ");
57 buffer_.append(MsToWebVttTimestamp(sample.EndTime()));
60 if (sample.settings().length()) {
62 buffer_.append(sample.settings());
66 buffer_.append(sample.payload());
71 bool WebVttFileBuffer::WriteTo(File* file) {
73 DCHECK_GT(buffer_.size(), 0u) <<
"The buffer should at least have a header";
75 const int written = file->Write(buffer_.c_str(), buffer_.size());
80 return static_cast<size_t>(written) == buffer_.size();
All the methods that are virtual are virtual for mocking.