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