7 #include "packager/media/formats/webvtt/webvtt_muxer.h"
9 #include "packager/file/file.h"
10 #include "packager/file/file_closer.h"
11 #include "packager/media/formats/webvtt/webvtt_utils.h"
12 #include "packager/status_macros.h"
19 WebVttMuxer::~WebVttMuxer() {}
22 stream->set_codec(kCodecWebVtt);
23 stream->set_codec_string(
"wvtt");
25 const std::string preamble = WebVttGetPreamble(*stream);
27 options().transport_stream_timestamp_offset_ms, preamble));
31 Status WebVttMuxer::AddTextSampleInternal(
const TextSample& sample) {
32 if (sample.id().find(
'\n') != std::string::npos) {
33 return Status(error::MUXER_FAILURE,
"Text id cannot contain newlines");
36 buffer_->Append(sample);
40 Status WebVttMuxer::WriteToFile(
const std::string& filename, uint64_t* size) {
43 std::unique_ptr<File, FileCloser> file(
File::Open(filename.c_str(),
"w"));
45 return Status(error::FILE_FAILURE,
"Failed to open " + filename);
48 buffer_->WriteTo(file.get(), size);
50 if (!file.release()->Close()) {
51 return Status(error::FILE_FAILURE,
"Failed to close " + filename);