2014-05-19 21:30:58 +00:00
|
|
|
// Copyright 2014 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
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/simple_mpd_notifier.h"
|
2014-05-19 21:30:58 +00:00
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/logging.h"
|
|
|
|
#include "packager/mpd/base/mpd_builder.h"
|
2015-07-22 06:57:21 +00:00
|
|
|
#include "packager/mpd/base/mpd_notifier_util.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/mpd_utils.h"
|
2014-05-19 21:30:58 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2014-05-19 21:30:58 +00:00
|
|
|
|
2014-05-16 23:32:10 +00:00
|
|
|
SimpleMpdNotifier::SimpleMpdNotifier(DashProfile dash_profile,
|
2014-05-30 05:01:09 +00:00
|
|
|
const MpdOptions& mpd_options,
|
2014-05-16 23:32:10 +00:00
|
|
|
const std::vector<std::string>& base_urls,
|
2014-05-19 21:30:58 +00:00
|
|
|
const std::string& output_path)
|
2014-05-16 23:32:10 +00:00
|
|
|
: MpdNotifier(dash_profile),
|
|
|
|
output_path_(output_path),
|
|
|
|
mpd_builder_(new MpdBuilder(dash_profile == kLiveProfile
|
|
|
|
? MpdBuilder::kDynamic
|
2014-05-22 02:16:17 +00:00
|
|
|
: MpdBuilder::kStatic,
|
2014-05-30 05:01:09 +00:00
|
|
|
mpd_options)) {
|
2014-05-16 23:32:10 +00:00
|
|
|
DCHECK(dash_profile == kLiveProfile || dash_profile == kOnDemandProfile);
|
|
|
|
for (size_t i = 0; i < base_urls.size(); ++i)
|
|
|
|
mpd_builder_->AddBaseUrl(base_urls[i]);
|
2014-05-19 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleMpdNotifier::~SimpleMpdNotifier() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleMpdNotifier::Init() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleMpdNotifier::NotifyNewContainer(const MediaInfo& media_info,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t* container_id) {
|
2014-05-19 21:30:58 +00:00
|
|
|
DCHECK(container_id);
|
|
|
|
|
|
|
|
ContentType content_type = GetContentType(media_info);
|
2015-07-22 06:57:21 +00:00
|
|
|
if (content_type == kContentTypeUnknown)
|
2014-05-19 21:30:58 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
base::AutoLock auto_lock(lock_);
|
|
|
|
// TODO(kqyang): Consider adding a new method MpdBuilder::AddRepresentation.
|
|
|
|
// Most of the codes here can be moved inside.
|
2015-02-02 17:26:09 +00:00
|
|
|
std::string lang;
|
2015-06-09 23:58:32 +00:00
|
|
|
if (media_info.has_audio_info()) {
|
|
|
|
lang = media_info.audio_info().language();
|
2015-02-02 17:26:09 +00:00
|
|
|
}
|
|
|
|
AdaptationSet** adaptation_set = &adaptation_set_map_[content_type][lang];
|
2014-05-19 21:30:58 +00:00
|
|
|
if (*adaptation_set == NULL)
|
2015-02-02 17:26:09 +00:00
|
|
|
*adaptation_set = mpd_builder_->AddAdaptationSet(lang);
|
2014-05-19 21:30:58 +00:00
|
|
|
|
|
|
|
DCHECK(*adaptation_set);
|
2014-12-16 01:32:19 +00:00
|
|
|
MediaInfo adjusted_media_info(media_info);
|
|
|
|
MpdBuilder::MakePathsRelativeToMpd(output_path_, &adjusted_media_info);
|
2014-05-19 21:30:58 +00:00
|
|
|
Representation* representation =
|
2014-12-16 01:32:19 +00:00
|
|
|
(*adaptation_set)->AddRepresentation(adjusted_media_info);
|
2014-05-19 21:30:58 +00:00
|
|
|
if (representation == NULL)
|
|
|
|
return false;
|
|
|
|
|
2015-07-22 06:57:21 +00:00
|
|
|
// For SimpleMpdNotifier, just put it in Representation. It should still
|
|
|
|
// generate a valid MPD.
|
2015-07-15 21:57:47 +00:00
|
|
|
AddContentProtectionElements(media_info, representation);
|
2014-05-19 21:30:58 +00:00
|
|
|
*container_id = representation->id();
|
2015-07-21 21:52:20 +00:00
|
|
|
DCHECK(!ContainsKey(representation_map_, representation->id()));
|
|
|
|
representation_map_[representation->id()] = representation;
|
2014-05-19 21:30:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-15 21:12:42 +00:00
|
|
|
bool SimpleMpdNotifier::NotifySampleDuration(uint32_t container_id,
|
|
|
|
uint32_t sample_duration) {
|
|
|
|
base::AutoLock auto_lock(lock_);
|
|
|
|
RepresentationMap::iterator it = representation_map_.find(container_id);
|
|
|
|
if (it == representation_map_.end()) {
|
|
|
|
LOG(ERROR) << "Unexpected container_id: " << container_id;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
it->second->SetSampleDuration(sample_duration);
|
2015-09-10 23:01:00 +00:00
|
|
|
return true;
|
2015-06-15 21:12:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
bool SimpleMpdNotifier::NotifyNewSegment(uint32_t container_id,
|
|
|
|
uint64_t start_time,
|
|
|
|
uint64_t duration,
|
|
|
|
uint64_t size) {
|
2014-05-19 21:30:58 +00:00
|
|
|
base::AutoLock auto_lock(lock_);
|
|
|
|
RepresentationMap::iterator it = representation_map_.find(container_id);
|
|
|
|
if (it == representation_map_.end()) {
|
|
|
|
LOG(ERROR) << "Unexpected container_id: " << container_id;
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-30 05:01:09 +00:00
|
|
|
it->second->AddNewSegment(start_time, duration, size);
|
2015-09-10 23:01:00 +00:00
|
|
|
return true;
|
2014-05-19 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:25:29 +00:00
|
|
|
bool SimpleMpdNotifier::NotifyEncryptionUpdate(
|
|
|
|
uint32_t container_id,
|
2015-09-24 22:03:52 +00:00
|
|
|
const std::string& drm_uuid,
|
2015-08-26 20:25:29 +00:00
|
|
|
const std::vector<uint8_t>& new_key_id,
|
|
|
|
const std::vector<uint8_t>& new_pssh) {
|
|
|
|
base::AutoLock auto_lock(lock_);
|
|
|
|
RepresentationMap::iterator it = representation_map_.find(container_id);
|
|
|
|
if (it == representation_map_.end()) {
|
|
|
|
LOG(ERROR) << "Unexpected container_id: " << container_id;
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-24 22:03:52 +00:00
|
|
|
it->second->UpdateContentProtectionPssh(drm_uuid,
|
|
|
|
Uint8VectorToBase64(new_pssh));
|
2015-08-26 20:25:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-19 21:30:58 +00:00
|
|
|
bool SimpleMpdNotifier::AddContentProtectionElement(
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t container_id,
|
2014-05-19 21:30:58 +00:00
|
|
|
const ContentProtectionElement& content_protection_element) {
|
2015-07-21 21:52:20 +00:00
|
|
|
base::AutoLock auto_lock(lock_);
|
|
|
|
RepresentationMap::iterator it = representation_map_.find(container_id);
|
|
|
|
if (it == representation_map_.end()) {
|
|
|
|
LOG(ERROR) << "Unexpected container_id: " << container_id;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
it->second->AddContentProtectionElement(content_protection_element);
|
2015-09-10 23:01:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleMpdNotifier::Flush() {
|
2015-11-12 21:40:52 +00:00
|
|
|
base::AutoLock auto_lock(lock_);
|
2015-07-21 21:52:20 +00:00
|
|
|
return WriteMpdToFile(output_path_, mpd_builder_.get());
|
2014-05-19 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|