Shaka Packager SDK
Loading...
Searching...
No Matches
ttml_muxer.cc
1// Copyright 2020 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#include <packager/media/formats/ttml/ttml_muxer.h>
8
9#include <packager/file.h>
10#include <packager/macros/status.h>
11
12namespace shaka {
13namespace media {
14namespace ttml {
15
16TtmlMuxer::TtmlMuxer(const MuxerOptions& options) : TextMuxer(options) {}
17TtmlMuxer::~TtmlMuxer() {}
18
19Status TtmlMuxer::InitializeStream(TextStreamInfo* stream) {
20 stream->set_codec(kCodecTtml);
21 stream->set_codec_string("ttml");
22 generator_.Initialize(stream->regions(), stream->language(),
23 stream->time_scale());
24 return Status::OK;
25}
26
27Status TtmlMuxer::AddTextSampleInternal(const TextSample& sample) {
28 generator_.AddSample(sample);
29 return Status::OK;
30}
31
32Status TtmlMuxer::WriteToFile(const std::string& filename, uint64_t* size) {
33 std::string data;
34 if (!generator_.Dump(&data))
35 return Status(error::INTERNAL_ERROR, "Error generating XML");
36 generator_.Reset();
37 *size = data.size();
38
39 if (!File::WriteStringToFile(filename.c_str(), data))
40 return Status(error::FILE_FAILURE, "Failed to write " + filename);
41 return Status::OK;
42}
43
44} // namespace ttml
45} // namespace media
46} // namespace shaka
All the methods that are virtual are virtual for mocking.