Shaka Packager SDK
Loading...
Searching...
No Matches
ttml_generator.h
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#ifndef PACKAGER_MEDIA_FORMATS_TTML_TTML_GENERATOR_H_
8#define PACKAGER_MEDIA_FORMATS_TTML_TTML_GENERATOR_H_
9
10#include <list>
11#include <map>
12#include <string>
13#include <unordered_set>
14
15#include <packager/media/base/text_sample.h>
16#include <packager/media/base/text_stream_info.h>
17#include <packager/mpd/base/xml/xml_node.h>
18
19namespace shaka {
20namespace media {
21namespace ttml {
22
24 public:
25 explicit TtmlGenerator();
27
28 static const char* kTtNamespace;
29
30 void Initialize(const std::map<std::string, TextRegion>& regions,
31 const std::string& language,
32 int32_t time_scale);
33 void AddSample(const TextSample& sample);
34 void Reset();
35
36 bool Dump(std::string* result) const;
37
38 private:
39 bool AddSampleToXml(const TextSample& sample,
40 xml::XmlNode* body,
41 xml::XmlNode* metadata,
42 std::unordered_set<std::string>& fragmentStyles,
43 size_t* image_count) const;
44 bool ConvertFragmentToXml(const TextFragment& fragment,
45 xml::XmlNode* parent,
46 xml::XmlNode* metadata,
47 std::unordered_set<std::string>& fragmentStyles,
48 size_t* image_count) const;
49
50 bool addStyling(xml::XmlNode& styling,
51 const std::unordered_set<std::string>& fragmentStyles) const;
52 bool addRegions(xml::XmlNode& layout) const;
53 std::vector<std::string> usedRegions() const;
54 bool isEbuTTTD() const;
55
56 std::list<TextSample> samples_;
57 std::map<std::string, TextRegion> regions_;
58 std::string language_;
59 int32_t time_scale_;
60 // This is modified in "const" methods to create unique IDs.
61 mutable uint32_t region_id_ = 0;
62};
63
64} // namespace ttml
65} // namespace media
66} // namespace shaka
67
68#endif // PACKAGER_MEDIA_FORMATS_TTML_TTML_GENERATOR_H_
All the methods that are virtual are virtual for mocking.