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 <cstdint>
10#include <string>
11
12#include <packager/file.h>
13#include <packager/media/base/muxer_options.h>
14#include <packager/media/base/stream_info.h>
15#include <packager/media/base/text_muxer.h>
16#include <packager/media/base/text_sample.h>
17#include <packager/media/base/text_stream_info.h>
18#include <packager/status.h>
19
20namespace shaka {
21namespace media {
22namespace ttml {
23
24TtmlMuxer::TtmlMuxer(const MuxerOptions& options) : TextMuxer(options) {}
25TtmlMuxer::~TtmlMuxer() {}
26
27Status TtmlMuxer::InitializeStream(TextStreamInfo* stream) {
28 stream->set_codec(kCodecTtml);
29 stream->set_codec_string("ttml");
30 generator_.Initialize(stream->regions(), stream->language(),
31 stream->time_scale());
32 return Status::OK;
33}
34
35Status TtmlMuxer::AddTextSampleInternal(const TextSample& sample) {
36 generator_.AddSample(sample);
37 return Status::OK;
38}
39
40Status TtmlMuxer::WriteToFile(const std::string& filename, uint64_t* size) {
41 std::string data;
42 if (!generator_.Dump(&data))
43 return Status(error::INTERNAL_ERROR, "Error generating XML");
44 generator_.Reset();
45 *size = data.size();
46
47 if (!File::WriteStringToFile(filename.c_str(), data))
48 return Status(error::FILE_FAILURE, "Failed to write " + filename);
49 return Status::OK;
50}
51
52} // namespace ttml
53} // namespace media
54} // namespace shaka
All the methods that are virtual are virtual for mocking.