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 const std::string& style_region_config)
23 : transport_stream_timestamp_offset_(transport_stream_timestamp_offset_ms *
25 style_region_config_(style_region_config) {
31 void WebVttFileBuffer::Reset() {
35 buffer_.append(kHeader);
36 if (transport_stream_timestamp_offset_ > 0) {
38 base::StringAppendF(&buffer_,
39 "X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:%d\n",
40 transport_stream_timestamp_offset_);
43 if (!style_region_config_.empty()) {
44 buffer_.append(style_region_config_);
45 buffer_.append(
"\n\n");
49 void WebVttFileBuffer::Append(
const TextSample& sample) {
50 DCHECK_GT(buffer_.size(), 0u) <<
"The buffer should at least have a header";
55 if (sample.id().length()) {
56 buffer_.append(sample.id());
61 buffer_.append(MsToWebVttTimestamp(sample.start_time()));
62 buffer_.append(
" --> ");
63 buffer_.append(MsToWebVttTimestamp(sample.EndTime()));
66 if (sample.settings().length()) {
68 buffer_.append(sample.settings());
72 buffer_.append(sample.payload());
77 bool WebVttFileBuffer::WriteTo(File* file) {
79 DCHECK_GT(buffer_.size(), 0u) <<
"The buffer should at least have a header";
81 const int written = file->Write(buffer_.c_str(), buffer_.size());
86 return static_cast<size_t>(written) == buffer_.size();
All the methods that are virtual are virtual for mocking.