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
|
|
|
|
//
|
2015-07-16 06:51:24 +00:00
|
|
|
/// All the methods that are virtual are virtual for mocking.
|
2015-03-23 19:55:58 +00:00
|
|
|
/// NOTE: Inclusion of this module will cause xmlInitParser and xmlCleanupParser
|
|
|
|
/// to be called at static initialization / deinitialization time.
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
#ifndef MPD_BASE_MPD_BUILDER_H_
|
|
|
|
#define MPD_BASE_MPD_BUILDER_H_
|
|
|
|
|
2017-12-13 01:26:37 +00:00
|
|
|
#include <libxml/tree.h>
|
2014-09-30 23:52:58 +00:00
|
|
|
|
2023-08-05 03:45:21 +00:00
|
|
|
#include <chrono>
|
2013-11-18 23:48:14 +00:00
|
|
|
#include <list>
|
2017-12-13 01:26:37 +00:00
|
|
|
#include <memory>
|
2023-08-05 03:45:21 +00:00
|
|
|
#include <optional>
|
2013-11-18 23:48:14 +00:00
|
|
|
#include <string>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/macros.h>
|
|
|
|
#include <packager/mpd/base/mpd_options.h>
|
|
|
|
#include <packager/mpd/base/xml/xml_node.h>
|
|
|
|
#include <packager/utils/clock.h>
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-01-31 19:02:30 +00:00
|
|
|
// TODO(rkuroiwa): For classes with |id_|, consider removing the field and let
|
|
|
|
// the MPD (XML) generation functions take care of assigning an ID to each
|
|
|
|
// element.
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-09-19 20:41:13 +00:00
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
class AdaptationSet;
|
2017-12-13 01:26:37 +00:00
|
|
|
class MediaInfo;
|
2017-12-14 01:00:11 +00:00
|
|
|
class Period;
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// This class generates DASH MPDs (Media Presentation Descriptions).
|
2013-11-18 23:48:14 +00:00
|
|
|
class MpdBuilder {
|
|
|
|
public:
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Constructs MpdBuilder.
|
2016-12-21 23:28:56 +00:00
|
|
|
/// @param mpd_options contains options on how this MPD should be built.
|
|
|
|
explicit MpdBuilder(const MpdOptions& mpd_options);
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual ~MpdBuilder();
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Add <BaseURL> entry to the MPD.
|
|
|
|
/// @param base_url URL for <BaseURL> entry.
|
2013-11-18 23:48:14 +00:00
|
|
|
void AddBaseUrl(const std::string& base_url);
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
/// Check the existing Periods, if there is one matching the provided
|
|
|
|
/// @a start_time_in_seconds, return it; otherwise a new Period is created and
|
|
|
|
/// returned.
|
|
|
|
/// @param start_time_in_seconds is the period start time.
|
|
|
|
/// @return the Period matching @a start_time_in_seconds if found; otherwise
|
|
|
|
/// return a new Period.
|
|
|
|
virtual Period* GetOrCreatePeriod(double start_time_in_seconds);
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Writes the MPD to the given string.
|
|
|
|
/// @param[out] output is an output string where the MPD gets written.
|
|
|
|
/// @return true on success, false otherwise.
|
2017-06-15 20:00:28 +00:00
|
|
|
// TODO(kqyang): Handle file IO in this class as in HLS media_playlist?
|
2023-08-05 03:45:21 +00:00
|
|
|
[[nodiscard]] virtual bool ToString(std::string* output);
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-12-16 01:32:19 +00:00
|
|
|
/// Adjusts the fields of MediaInfo so that paths are relative to the
|
|
|
|
/// specified MPD path.
|
|
|
|
/// @param mpd_path is the file path of the MPD file.
|
|
|
|
/// @param media_info is the MediaInfo object to be updated with relative
|
|
|
|
/// paths.
|
|
|
|
static void MakePathsRelativeToMpd(const std::string& mpd_path,
|
|
|
|
MediaInfo* media_info);
|
|
|
|
|
2016-01-11 23:58:02 +00:00
|
|
|
// Inject a |clock| that returns the current time.
|
|
|
|
/// This is for testing.
|
2023-08-05 03:45:21 +00:00
|
|
|
void InjectClockForTesting(std::unique_ptr<Clock> clock) {
|
2016-08-17 17:41:40 +00:00
|
|
|
clock_ = std::move(clock);
|
2016-01-11 23:58:02 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
private:
|
2017-12-13 01:26:37 +00:00
|
|
|
MpdBuilder(const MpdBuilder&) = delete;
|
|
|
|
MpdBuilder& operator=(const MpdBuilder&) = delete;
|
|
|
|
|
2016-12-21 23:28:56 +00:00
|
|
|
// LiveMpdBuilderTest needs to set availabilityStartTime so that the test
|
2014-06-26 01:33:09 +00:00
|
|
|
// doesn't need to depend on current time.
|
2016-12-21 23:28:56 +00:00
|
|
|
friend class LiveMpdBuilderTest;
|
|
|
|
template <DashProfile profile>
|
|
|
|
friend class MpdBuilderTest;
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
// Returns the document pointer to the MPD. This must be freed by the caller
|
|
|
|
// using appropriate xmlDocPtr freeing function.
|
|
|
|
// On failure, this returns NULL.
|
2023-08-05 03:45:21 +00:00
|
|
|
std::optional<xml::XmlNode> GenerateMpd();
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-06-26 01:33:09 +00:00
|
|
|
// Set MPD attributes common to all profiles. Uses non-zero |mpd_options_| to
|
|
|
|
// set attributes for the MPD.
|
2023-08-05 03:45:21 +00:00
|
|
|
[[nodiscard]] bool AddCommonMpdInfo(xml::XmlNode* mpd_node);
|
2014-06-26 01:33:09 +00:00
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
// Adds 'static' MPD attributes and elements to |mpd_node|. This assumes that
|
|
|
|
// the first child element is a Period element.
|
2023-08-05 03:45:21 +00:00
|
|
|
[[nodiscard]] bool AddStaticMpdInfo(xml::XmlNode* mpd_node);
|
2014-05-22 02:16:17 +00:00
|
|
|
|
|
|
|
// Same as AddStaticMpdInfo() but for 'dynamic' MPDs.
|
2023-08-05 03:45:21 +00:00
|
|
|
[[nodiscard]] bool AddDynamicMpdInfo(xml::XmlNode* mpd_node);
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2018-03-17 01:37:53 +00:00
|
|
|
// Add UTCTiming element if utc timing is provided.
|
2023-08-05 03:45:21 +00:00
|
|
|
[[nodiscard]] bool AddUtcTiming(xml::XmlNode* mpd_node);
|
2018-03-17 01:37:53 +00:00
|
|
|
|
2018-01-24 23:26:37 +00:00
|
|
|
float GetStaticMpdDuration();
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-06-26 01:33:09 +00:00
|
|
|
// Set MPD attributes for dynamic profile MPD. Uses non-zero |mpd_options_| as
|
|
|
|
// well as various calculations to set attributes for the MPD.
|
|
|
|
void SetDynamicMpdAttributes(xml::XmlNode* mpd_node);
|
|
|
|
|
|
|
|
// Gets the earliest, normalized segment timestamp. Returns true if
|
|
|
|
// successful, false otherwise.
|
2023-08-05 03:45:21 +00:00
|
|
|
[[nodiscard]] bool GetEarliestTimestamp(double* timestamp_seconds);
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2018-01-29 18:37:50 +00:00
|
|
|
// Update Period durations and presentation timestamps.
|
|
|
|
void UpdatePeriodDurationAndPresentationTimestamp();
|
|
|
|
|
2014-05-27 22:21:42 +00:00
|
|
|
MpdOptions mpd_options_;
|
2017-12-14 01:00:11 +00:00
|
|
|
std::list<std::unique_ptr<Period>> periods_;
|
2013-11-18 23:48:14 +00:00
|
|
|
|
|
|
|
std::list<std::string> base_urls_;
|
2014-06-26 01:33:09 +00:00
|
|
|
std::string availability_start_time_;
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2018-07-23 22:24:20 +00:00
|
|
|
uint32_t period_counter_ = 0;
|
|
|
|
uint32_t representation_counter_ = 0;
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2016-01-11 23:58:02 +00:00
|
|
|
// By default, this returns the current time. This can be injected for
|
|
|
|
// testing.
|
2023-08-05 03:45:21 +00:00
|
|
|
std::unique_ptr<Clock> clock_;
|
2013-11-18 23:48:14 +00:00
|
|
|
};
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-11-18 23:48:14 +00:00
|
|
|
|
|
|
|
#endif // MPD_BASE_MPD_BUILDER_H_
|