Shaka Packager SDK
mpd_writer.h
1 // Copyright 2014 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 // Class for reading in MediaInfo from files and writing out an MPD.
8 
9 #ifndef MPD_UTIL_MPD_WRITER_H_
10 #define MPD_UTIL_MPD_WRITER_H_
11 
12 #include <list>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include <packager/macros/classes.h>
18 #include <packager/mpd/base/mpd_notifier.h>
19 #include <packager/mpd/base/mpd_options.h>
20 
21 namespace shaka {
22 
23 namespace media {
24 class File;
25 } // namespace media
26 
27 class MediaInfo;
28 
33  public:
35  virtual ~MpdNotifierFactory() {}
36 
37  virtual std::unique_ptr<MpdNotifier> Create(
38  const MpdOptions& mpd_options) = 0;
39 };
40 
41 // An instance of this class takes a set of MediaInfo files and generates an
42 // MPD when one of WriteMpd* methods are called. This generates an MPD with one
43 // <Period> element and at most three <AdaptationSet> elements, each for video,
44 // audio, and text. Information in MediaInfo will be put into one of the
45 // AdaptationSets by checking the video_info, audio_info, and text_info fields.
46 // Therefore, this cannot handle an instance of MediaInfo with video, audio, and
47 // text combination.
48 class MpdWriter {
49  public:
50  MpdWriter();
51  ~MpdWriter();
52 
53  // Add |media_info_path| for MPD generation.
54  // The content of |media_info_path| should be a string representation of
55  // MediaInfo, i.e. the content should be a result of using
56  // google::protobuf::TestFormat::Print*() methods.
57  // If necessary, this method can be called after WriteMpd*() methods.
58  bool AddFile(const std::string& media_info_path);
59 
60  // |base_url| will be used for <BaseURL> element for the MPD. The BaseURL
61  // element will be a direct child element of the <MPD> element.
62  void AddBaseUrl(const std::string& base_url);
63 
64  // Write the MPD to |file_name|. |file_name| should not be NULL.
65  // This opens the file in write mode, IOW if the
66  // file exists this will over write whatever is in the file.
67  // AddFile() should be called before calling this function to generate an MPD.
68  // On success, the MPD gets written to |file| and returns true, otherwise
69  // returns false.
70  // This method can be called multiple times, if necessary.
71  bool WriteMpdToFile(const char* file_name);
72 
73  private:
74  friend class MpdWriterTest;
75 
76  void SetMpdNotifierFactoryForTest(
77  std::unique_ptr<MpdNotifierFactory> factory);
78 
79  std::list<MediaInfo> media_infos_;
80  std::vector<std::string> base_urls_;
81 
82  std::unique_ptr<MpdNotifierFactory> notifier_factory_;
83 
84  DISALLOW_COPY_AND_ASSIGN(MpdWriter);
85 };
86 
87 } // namespace shaka
88 
89 #endif // MPD_UTIL_MPD_WRITER_H_
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66
Defines Mpd Options.
Definition: mpd_options.h:25