2015-07-22 06:57:21 +00:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#ifndef MPD_BASE_DASH_IOP_MPD_NOTIFIER_H_
|
|
|
|
#define MPD_BASE_DASH_IOP_MPD_NOTIFIER_H_
|
|
|
|
|
|
|
|
#include "packager/mpd/base/mpd_notifier.h"
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-11-12 21:40:52 +00:00
|
|
|
#include "packager/base/synchronization/lock.h"
|
2015-07-22 06:57:21 +00:00
|
|
|
#include "packager/mpd/base/mpd_builder.h"
|
|
|
|
#include "packager/mpd/base/mpd_notifier_util.h"
|
|
|
|
#include "packager/mpd/base/mpd_options.h"
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-07-22 06:57:21 +00:00
|
|
|
|
|
|
|
/// This class is an MpdNotifier which will try its best to generate a
|
|
|
|
/// DASH IF IOPv3 compliant MPD.
|
2015-08-05 23:00:02 +00:00
|
|
|
/// e.g.
|
|
|
|
/// All <ContentProtection> elements must be right under
|
2015-07-22 06:57:21 +00:00
|
|
|
/// <AdaptationSet> and cannot be under <Representation>.
|
2015-08-05 23:00:02 +00:00
|
|
|
/// All video Adaptation Sets have Role set to "main".
|
2015-07-22 06:57:21 +00:00
|
|
|
class DashIopMpdNotifier : public MpdNotifier {
|
|
|
|
public:
|
|
|
|
DashIopMpdNotifier(DashProfile dash_profile,
|
|
|
|
const MpdOptions& mpd_options,
|
|
|
|
const std::vector<std::string>& base_urls,
|
|
|
|
const std::string& output_path);
|
2015-07-22 23:40:45 +00:00
|
|
|
~DashIopMpdNotifier() override;
|
2015-07-22 06:57:21 +00:00
|
|
|
|
2015-09-10 23:01:00 +00:00
|
|
|
/// None of the methods write out the MPD file until Flush() is called.
|
2015-07-22 06:57:21 +00:00
|
|
|
/// @name MpdNotifier implemetation overrides.
|
|
|
|
/// @{
|
2015-07-22 23:40:45 +00:00
|
|
|
bool Init() override;
|
|
|
|
bool NotifyNewContainer(const MediaInfo& media_info, uint32_t* id) override;
|
|
|
|
bool NotifySampleDuration(uint32_t container_id,
|
|
|
|
uint32_t sample_duration) override;
|
|
|
|
bool NotifyNewSegment(uint32_t id,
|
|
|
|
uint64_t start_time,
|
|
|
|
uint64_t duration,
|
|
|
|
uint64_t size) override;
|
|
|
|
bool NotifyEncryptionUpdate(uint32_t container_id,
|
|
|
|
const std::string& drm_uuid,
|
|
|
|
const std::vector<uint8_t>& new_key_id,
|
|
|
|
const std::vector<uint8_t>& new_pssh) override;
|
|
|
|
bool AddContentProtectionElement(
|
2015-07-22 06:57:21 +00:00
|
|
|
uint32_t id,
|
2015-07-22 23:40:45 +00:00
|
|
|
const ContentProtectionElement& content_protection_element) override;
|
|
|
|
bool Flush() override;
|
2015-07-22 06:57:21 +00:00
|
|
|
/// @}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class DashIopMpdNotifierTest;
|
|
|
|
|
|
|
|
// Maps representation ID to Representation.
|
|
|
|
typedef std::map<uint32_t, Representation*> RepresentationMap;
|
|
|
|
|
|
|
|
// Maps AdaptationSet ID to ProtectedContent.
|
|
|
|
typedef std::map<uint32_t, MediaInfo::ProtectedContent> ProtectedContentMap;
|
|
|
|
|
|
|
|
// Checks the protected_content field of media_info and returns a non-null
|
|
|
|
// AdaptationSet* for a new Representation.
|
|
|
|
// This does not necessarily return a new AdaptationSet. If
|
|
|
|
// media_info.protected_content completely matches with an existing
|
|
|
|
// AdaptationSet, then it will return the pointer.
|
2016-03-08 19:19:12 +00:00
|
|
|
AdaptationSet* GetAdaptationSetForMediaInfo(const std::string& key,
|
|
|
|
const MediaInfo& media_info);
|
2015-07-22 06:57:21 +00:00
|
|
|
|
|
|
|
// Sets a group id for |adaptation_set| if applicable.
|
|
|
|
// If a group ID is already assigned, then this returns immediately.
|
2016-03-08 19:19:12 +00:00
|
|
|
void SetGroupId(const std::string& key, AdaptationSet* adaptation_set);
|
2015-07-22 06:57:21 +00:00
|
|
|
|
|
|
|
// Helper function to get a new AdaptationSet; registers the values
|
|
|
|
// to the fields (maps) of the instance.
|
|
|
|
// If the media is encrypted, registers data to protected_content_map_.
|
|
|
|
AdaptationSet* NewAdaptationSet(const MediaInfo& media_info,
|
|
|
|
std::list<AdaptationSet*>* adaptation_sets);
|
|
|
|
|
|
|
|
// Testing only method. Returns a pointer to MpdBuilder.
|
|
|
|
MpdBuilder* MpdBuilderForTesting() const {
|
|
|
|
return mpd_builder_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Testing only method. Sets mpd_builder_.
|
2016-08-17 17:41:40 +00:00
|
|
|
void SetMpdBuilderForTesting(std::unique_ptr<MpdBuilder> mpd_builder) {
|
|
|
|
mpd_builder_ = std::move(mpd_builder);
|
2015-07-22 06:57:21 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 19:19:12 +00:00
|
|
|
std::map<std::string, std::list<AdaptationSet*>> adaptation_set_list_map_;
|
2015-07-22 06:57:21 +00:00
|
|
|
RepresentationMap representation_map_;
|
|
|
|
|
|
|
|
// Used to check whether a Representation should be added to an AdaptationSet.
|
|
|
|
ProtectedContentMap protected_content_map_;
|
|
|
|
|
|
|
|
// MPD output path.
|
|
|
|
std::string output_path_;
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MpdBuilder> mpd_builder_;
|
2015-07-22 06:57:21 +00:00
|
|
|
base::Lock lock_;
|
|
|
|
|
|
|
|
// Next group ID to use for AdapationSets that can be grouped.
|
|
|
|
int next_group_id_;
|
2015-08-26 20:25:29 +00:00
|
|
|
|
|
|
|
// Maps Representation ID to AdaptationSet. This is for updating the PSSH.
|
|
|
|
std::map<uint32_t, AdaptationSet*> representation_id_to_adaptation_set_;
|
2015-07-22 06:57:21 +00:00
|
|
|
};
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2015-07-22 06:57:21 +00:00
|
|
|
|
|
|
|
#endif // MPD_BASE_DASH_IOP_MPD_NOTIFIER_H_
|