2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
//
|
2014-01-15 18:50:47 +00:00
|
|
|
// Class for reading in MediaInfo from files and writing out an MPD.
|
2014-02-14 23:21:05 +00:00
|
|
|
|
2014-01-15 18:50:47 +00:00
|
|
|
#ifndef MPD_UTIL_MPD_WRITER_H_
|
|
|
|
#define MPD_UTIL_MPD_WRITER_H_
|
|
|
|
|
|
|
|
#include <list>
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2014-01-15 18:50:47 +00:00
|
|
|
#include <string>
|
2015-09-14 19:53:32 +00:00
|
|
|
#include <vector>
|
2014-01-15 18:50:47 +00:00
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/macros.h>
|
|
|
|
#include <packager/mpd/base/mpd_notifier.h>
|
|
|
|
#include <packager/mpd/base/mpd_options.h>
|
2014-01-15 18:50:47 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-05-19 21:38:15 +00:00
|
|
|
|
2014-01-15 18:50:47 +00:00
|
|
|
namespace media {
|
|
|
|
class File;
|
|
|
|
} // namespace media
|
|
|
|
|
|
|
|
class MediaInfo;
|
|
|
|
|
2015-09-14 19:53:32 +00:00
|
|
|
/// This is mainly for testing, and is implementation detail. No need to worry
|
|
|
|
/// about this class if you are just using the API.
|
|
|
|
/// Inject a factory and mock MpdNotifier to test the MpdWriter implementation.
|
|
|
|
class MpdNotifierFactory {
|
|
|
|
public:
|
|
|
|
MpdNotifierFactory() {}
|
|
|
|
virtual ~MpdNotifierFactory() {}
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
virtual std::unique_ptr<MpdNotifier> Create(
|
2017-07-27 18:49:50 +00:00
|
|
|
const MpdOptions& mpd_options) = 0;
|
2015-09-14 19:53:32 +00:00
|
|
|
};
|
|
|
|
|
2014-01-15 18:50:47 +00:00
|
|
|
// An instance of this class takes a set of MediaInfo files and generates an
|
|
|
|
// MPD when one of WriteMpd* methods are called. This generates an MPD with one
|
|
|
|
// <Period> element and at most three <AdaptationSet> elements, each for video,
|
|
|
|
// audio, and text. Information in MediaInfo will be put into one of the
|
|
|
|
// AdaptationSets by checking the video_info, audio_info, and text_info fields.
|
|
|
|
// Therefore, this cannot handle an instance of MediaInfo with video, audio, and
|
|
|
|
// text combination.
|
|
|
|
class MpdWriter {
|
|
|
|
public:
|
|
|
|
MpdWriter();
|
|
|
|
~MpdWriter();
|
|
|
|
|
2014-12-16 01:32:19 +00:00
|
|
|
// Add |media_info_path| for MPD generation.
|
|
|
|
// The content of |media_info_path| should be a string representation of
|
2014-01-15 18:50:47 +00:00
|
|
|
// MediaInfo, i.e. the content should be a result of using
|
|
|
|
// google::protobuf::TestFormat::Print*() methods.
|
|
|
|
// If necessary, this method can be called after WriteMpd*() methods.
|
2018-04-17 17:42:45 +00:00
|
|
|
bool AddFile(const std::string& media_info_path);
|
2014-01-15 18:50:47 +00:00
|
|
|
|
|
|
|
// |base_url| will be used for <BaseURL> element for the MPD. The BaseURL
|
|
|
|
// element will be a direct child element of the <MPD> element.
|
|
|
|
void AddBaseUrl(const std::string& base_url);
|
|
|
|
|
|
|
|
// Write the MPD to |file_name|. |file_name| should not be NULL.
|
|
|
|
// This opens the file in write mode, IOW if the
|
|
|
|
// file exists this will over write whatever is in the file.
|
|
|
|
// AddFile() should be called before calling this function to generate an MPD.
|
|
|
|
// On success, the MPD gets written to |file| and returns true, otherwise
|
|
|
|
// returns false.
|
|
|
|
// This method can be called multiple times, if necessary.
|
|
|
|
bool WriteMpdToFile(const char* file_name);
|
|
|
|
|
|
|
|
private:
|
2015-09-14 19:53:32 +00:00
|
|
|
friend class MpdWriterTest;
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
void SetMpdNotifierFactoryForTest(
|
|
|
|
std::unique_ptr<MpdNotifierFactory> factory);
|
2015-09-14 19:53:32 +00:00
|
|
|
|
2014-01-15 18:50:47 +00:00
|
|
|
std::list<MediaInfo> media_infos_;
|
2015-09-14 19:53:32 +00:00
|
|
|
std::vector<std::string> base_urls_;
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MpdNotifierFactory> notifier_factory_;
|
2014-01-15 18:50:47 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MpdWriter);
|
|
|
|
};
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2014-01-15 18:50:47 +00:00
|
|
|
|
|
|
|
#endif // MPD_UTIL_MPD_WRITER_H_
|