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