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,
39  const std::vector<std::string>& base_urls,
40  const std::string& output_path) = 0;
41 };
42 
43 // An instance of this class takes a set of MediaInfo files and generates an
44 // MPD when one of WriteMpd* methods are called. This generates an MPD with one
45 // <Period> element and at most three <AdaptationSet> elements, each for video,
46 // audio, and text. Information in MediaInfo will be put into one of the
47 // AdaptationSets by checking the video_info, audio_info, and text_info fields.
48 // Therefore, this cannot handle an instance of MediaInfo with video, audio, and
49 // text combination.
50 class MpdWriter {
51  public:
52  MpdWriter();
53  ~MpdWriter();
54 
55  // Add |media_info_path| for MPD generation.
56  // The content of |media_info_path| should be a string representation of
57  // MediaInfo, i.e. the content should be a result of using
58  // google::protobuf::TestFormat::Print*() methods.
59  // If necessary, this method can be called after WriteMpd*() methods.
60  bool AddFile(const std::string& media_info_path,
61  const std::string& mpd_path);
62 
63  // |base_url| will be used for <BaseURL> element for the MPD. The BaseURL
64  // element will be a direct child element of the <MPD> element.
65  void AddBaseUrl(const std::string& base_url);
66 
67  // Write the MPD to |file_name|. |file_name| should not be NULL.
68  // This opens the file in write mode, IOW if the
69  // file exists this will over write whatever is in the file.
70  // AddFile() should be called before calling this function to generate an MPD.
71  // On success, the MPD gets written to |file| and returns true, otherwise
72  // returns false.
73  // This method can be called multiple times, if necessary.
74  bool WriteMpdToFile(const char* file_name);
75 
76  private:
77  friend class MpdWriterTest;
78 
79  void SetMpdNotifierFactoryForTest(
80  std::unique_ptr<MpdNotifierFactory> factory);
81 
82  std::list<MediaInfo> media_infos_;
83  std::vector<std::string> base_urls_;
84 
85  std::unique_ptr<MpdNotifierFactory> notifier_factory_;
86 
87  DISALLOW_COPY_AND_ASSIGN(MpdWriter);
88 };
89 
90 } // namespace shaka
91 
92 #endif // MPD_UTIL_MPD_WRITER_H_
Defines Mpd Options.
Definition: mpd_options.h:23