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