2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2017-12-14 01:00:11 +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
|
|
|
|
//
|
|
|
|
/// All the methods that are virtual are virtual for mocking.
|
|
|
|
|
|
|
|
#ifndef PACKAGER_MPD_BASE_PERIOD_H_
|
|
|
|
#define PACKAGER_MPD_BASE_PERIOD_H_
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <optional>
|
2017-12-14 01:00:11 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/mpd/base/adaptation_set.h>
|
|
|
|
#include <packager/mpd/base/media_info.pb.h>
|
|
|
|
#include <packager/mpd/base/xml/xml_node.h>
|
2017-12-14 01:00:11 +00:00
|
|
|
|
|
|
|
namespace shaka {
|
|
|
|
|
|
|
|
struct MpdOptions;
|
|
|
|
|
|
|
|
/// Period class maps to <Period> element and provides methods to add
|
|
|
|
/// AdaptationSets.
|
|
|
|
class Period {
|
|
|
|
public:
|
2020-03-24 19:15:30 +00:00
|
|
|
virtual ~Period();
|
2018-01-04 06:02:19 +00:00
|
|
|
|
2017-12-14 01:00:11 +00:00
|
|
|
/// Check the existing AdaptationSets, if there is one matching the provided
|
|
|
|
/// @a media_info, return it; otherwise a new AdaptationSet is created and
|
|
|
|
/// returned.
|
|
|
|
/// @param media_info contains media information, which is used to match
|
|
|
|
/// AdaptationSets.
|
|
|
|
/// @param content_protection_in_adaptation_set determines if the
|
|
|
|
/// ContentProtection is placed in AdaptationSet or Representation
|
|
|
|
/// element. This affects how MediaInfo in AdaptationSets are matched.
|
|
|
|
/// @return the AdaptationSet matching @a media_info if found; otherwise
|
|
|
|
/// return a new AdaptationSet.
|
2018-01-25 23:04:59 +00:00
|
|
|
// TODO(kqyang): Move |content_protection_in_adaptation_set| to Period
|
|
|
|
// constructor.
|
2017-12-14 01:00:11 +00:00
|
|
|
virtual AdaptationSet* GetOrCreateAdaptationSet(
|
|
|
|
const MediaInfo& media_info,
|
|
|
|
bool content_protection_in_adaptation_set);
|
|
|
|
|
|
|
|
/// Generates <Period> xml element with its child AdaptationSet elements.
|
|
|
|
/// @return On success returns a non-NULL scoped_xml_ptr. Otherwise returns a
|
|
|
|
/// NULL scoped_xml_ptr.
|
2023-12-01 17:32:19 +00:00
|
|
|
std::optional<xml::XmlNode> GetXml(bool output_period_duration);
|
2017-12-14 01:00:11 +00:00
|
|
|
|
2018-01-05 02:31:27 +00:00
|
|
|
/// @return The list of AdaptationSets in this Period.
|
|
|
|
const std::list<AdaptationSet*> GetAdaptationSets() const;
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
/// @return The start time of this Period.
|
|
|
|
double start_time_in_seconds() const { return start_time_in_seconds_; }
|
|
|
|
|
2018-01-29 18:37:50 +00:00
|
|
|
/// @return period duration in seconds.
|
|
|
|
double duration_seconds() const { return duration_seconds_; }
|
|
|
|
|
2018-01-24 23:26:37 +00:00
|
|
|
/// Set period duration.
|
|
|
|
void set_duration_seconds(double duration_seconds) {
|
|
|
|
duration_seconds_ = duration_seconds;
|
|
|
|
}
|
|
|
|
|
2020-03-24 19:15:30 +00:00
|
|
|
/// @return trickplay_cache.
|
|
|
|
const std::map<std::string, std::list<AdaptationSet*>>& trickplay_cache()
|
|
|
|
const {
|
|
|
|
return trickplay_cache_;
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:00:11 +00:00
|
|
|
protected:
|
2018-01-03 00:10:54 +00:00
|
|
|
/// @param period_id is an ID number for this Period.
|
|
|
|
/// @param start_time_in_seconds is the start time for this Period.
|
2017-12-14 01:00:11 +00:00
|
|
|
/// @param mpd_options is the options for this MPD.
|
|
|
|
/// @param representation_counter is a counter for assigning ID numbers to
|
|
|
|
/// Representation. It can not be NULL.
|
2018-01-03 00:10:54 +00:00
|
|
|
Period(uint32_t period_id,
|
|
|
|
double start_time_in_seconds,
|
|
|
|
const MpdOptions& mpd_options,
|
2018-07-23 22:24:20 +00:00
|
|
|
uint32_t* representation_counter);
|
2017-12-14 01:00:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Period(const Period&) = delete;
|
|
|
|
Period& operator=(const Period&) = delete;
|
|
|
|
|
|
|
|
friend class MpdBuilder;
|
|
|
|
friend class PeriodTest;
|
|
|
|
|
|
|
|
// Calls AdaptationSet constructor. For mock injection.
|
|
|
|
virtual std::unique_ptr<AdaptationSet> NewAdaptationSet(
|
|
|
|
const std::string& lang,
|
|
|
|
const MpdOptions& options,
|
2018-07-23 22:24:20 +00:00
|
|
|
uint32_t* representation_counter);
|
2017-12-14 01:00:11 +00:00
|
|
|
|
|
|
|
// Helper function to set new AdaptationSet attributes.
|
|
|
|
bool SetNewAdaptationSetAttributes(
|
|
|
|
const std::string& language,
|
|
|
|
const MediaInfo& media_info,
|
|
|
|
const std::list<AdaptationSet*>& adaptation_sets,
|
2020-03-18 02:33:44 +00:00
|
|
|
bool content_protection_in_adaptation_set,
|
2017-12-14 01:00:11 +00:00
|
|
|
AdaptationSet* new_adaptation_set);
|
|
|
|
|
2020-03-24 19:15:30 +00:00
|
|
|
// If processing a trick play AdaptationSet, gets the original AdaptationSet
|
|
|
|
// which the trick play video belongs to.It is assumed that the corresponding
|
|
|
|
// AdaptationSet has been created before the trick play AdaptationSet.
|
|
|
|
// Returns the matching AdaptationSet if found, otherwise returns nullptr;
|
|
|
|
// If processing non-trick play AdaptationSet, gets the trick play
|
|
|
|
// AdaptationSet that belongs to current AdaptationSet from trick play cache.
|
|
|
|
// Returns nullptr if matching trick play AdaptationSet is not found.
|
|
|
|
AdaptationSet* FindMatchingAdaptationSetForTrickPlay(
|
|
|
|
const MediaInfo& media_info,
|
|
|
|
bool content_protection_in_adaptation_set,
|
|
|
|
std::string* adaptation_set_key);
|
|
|
|
|
|
|
|
// Returns AdaptationSet key without ':trickplay' in it for trickplay
|
|
|
|
// AdaptationSet.
|
|
|
|
std::string GetAdaptationSetKeyForTrickPlay(const MediaInfo& media_info);
|
2017-12-14 01:00:11 +00:00
|
|
|
|
2020-03-24 19:15:30 +00:00
|
|
|
// FindMatchingAdaptationSetForTrickPlay
|
2018-01-03 00:10:54 +00:00
|
|
|
const uint32_t id_;
|
|
|
|
const double start_time_in_seconds_;
|
2018-01-24 23:26:37 +00:00
|
|
|
double duration_seconds_ = 0;
|
2017-12-14 01:00:11 +00:00
|
|
|
const MpdOptions& mpd_options_;
|
2018-07-23 22:24:20 +00:00
|
|
|
uint32_t* const representation_counter_;
|
2018-01-25 23:04:59 +00:00
|
|
|
std::list<std::unique_ptr<AdaptationSet>> adaptation_sets_;
|
2017-12-14 01:00:11 +00:00
|
|
|
// AdaptationSets grouped by a specific adaptation set grouping key.
|
|
|
|
// AdaptationSets with the same key contain identical parameters except
|
|
|
|
// ContentProtection parameters. A single AdaptationSet would be created
|
|
|
|
// if they contain identical ContentProtection elements. This map is only
|
|
|
|
// useful when ContentProtection element is placed in AdaptationSet.
|
|
|
|
std::map<std::string, std::list<AdaptationSet*>> adaptation_set_list_map_;
|
2020-03-24 19:15:30 +00:00
|
|
|
// Contains Trickplay AdaptationSets grouped by specific adaptation set
|
|
|
|
// grouping key. These AdaptationSets still have not found reference
|
|
|
|
// AdaptationSet.
|
|
|
|
std::map<std::string, std::list<AdaptationSet*>> trickplay_cache_;
|
2017-12-14 01:00:11 +00:00
|
|
|
|
|
|
|
// Tracks ProtectedContent in AdaptationSet.
|
|
|
|
class ProtectedAdaptationSetMap {
|
|
|
|
public:
|
|
|
|
ProtectedAdaptationSetMap() = default;
|
|
|
|
// Register the |adaptation_set| with associated |media_info| in the map.
|
|
|
|
void Register(const AdaptationSet& adaptation_set,
|
|
|
|
const MediaInfo& media_info);
|
|
|
|
// Check if the protected content associated with |adaptation_set| matches
|
|
|
|
// with the one in |media_info|.
|
|
|
|
bool Match(const AdaptationSet& adaptation_set,
|
2020-03-18 02:33:44 +00:00
|
|
|
const MediaInfo& media_info,
|
|
|
|
bool content_protection_in_adaptation_set);
|
2017-12-14 01:00:11 +00:00
|
|
|
// Check if the two adaptation sets are switchable.
|
|
|
|
bool Switchable(const AdaptationSet& adaptation_set_a,
|
|
|
|
const AdaptationSet& adaptation_set_b);
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProtectedAdaptationSetMap(const ProtectedAdaptationSetMap&) = delete;
|
|
|
|
ProtectedAdaptationSetMap& operator=(const ProtectedAdaptationSetMap&) =
|
|
|
|
delete;
|
|
|
|
|
2018-01-25 23:04:59 +00:00
|
|
|
// AdaptationSet => ProtectedContent map.
|
|
|
|
std::map<const AdaptationSet*, MediaInfo::ProtectedContent>
|
|
|
|
protected_content_map_;
|
2017-12-14 01:00:11 +00:00
|
|
|
};
|
|
|
|
ProtectedAdaptationSetMap protected_adaptation_set_map_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace shaka
|
|
|
|
|
|
|
|
#endif // PACKAGER_MPD_BASE_PERIOD_H_
|