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