DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
mpd_writer.h
1 // Copyright 2014 Google Inc. 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/base/macros.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  const std::string& mpd_path);
60 
61  // |base_url| will be used for <BaseURL> element for the MPD. The BaseURL
62  // element will be a direct child element of the <MPD> element.
63  void AddBaseUrl(const std::string& base_url);
64 
65  // Write the MPD to |file_name|. |file_name| should not be NULL.
66  // This opens the file in write mode, IOW if the
67  // file exists this will over write whatever is in the file.
68  // AddFile() should be called before calling this function to generate an MPD.
69  // On success, the MPD gets written to |file| and returns true, otherwise
70  // returns false.
71  // This method can be called multiple times, if necessary.
72  bool WriteMpdToFile(const char* file_name);
73 
74  private:
75  friend class MpdWriterTest;
76 
77  void SetMpdNotifierFactoryForTest(
78  std::unique_ptr<MpdNotifierFactory> factory);
79 
80  std::list<MediaInfo> media_infos_;
81  std::vector<std::string> base_urls_;
82 
83  std::unique_ptr<MpdNotifierFactory> notifier_factory_;
84 
85  DISALLOW_COPY_AND_ASSIGN(MpdWriter);
86 };
87 
88 } // namespace shaka
89 
90 #endif // MPD_UTIL_MPD_WRITER_H_
Defines Mpd Options.
Definition: mpd_options.h:25