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