DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
simple_mpd_notifier.cc
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include "packager/mpd/base/simple_mpd_notifier.h"
8 
9 #include "packager/base/logging.h"
10 #include "packager/mpd/base/mpd_builder.h"
11 #include "packager/mpd/base/mpd_notifier_util.h"
12 #include "packager/mpd/base/mpd_utils.h"
13 
14 namespace edash_packager {
15 
16 SimpleMpdNotifier::SimpleMpdNotifier(DashProfile dash_profile,
17  const MpdOptions& mpd_options,
18  const std::vector<std::string>& base_urls,
19  const std::string& output_path)
20  : MpdNotifier(dash_profile),
21  output_path_(output_path),
22  mpd_builder_(new MpdBuilder(dash_profile == kLiveProfile
23  ? MpdBuilder::kDynamic
24  : MpdBuilder::kStatic,
25  mpd_options)) {
26  DCHECK(dash_profile == kLiveProfile || dash_profile == kOnDemandProfile);
27  for (size_t i = 0; i < base_urls.size(); ++i)
28  mpd_builder_->AddBaseUrl(base_urls[i]);
29 }
30 
31 SimpleMpdNotifier::~SimpleMpdNotifier() {
32 }
33 
35  return true;
36 }
37 
38 bool SimpleMpdNotifier::NotifyNewContainer(const MediaInfo& media_info,
39  uint32_t* container_id) {
40  DCHECK(container_id);
41 
42  ContentType content_type = GetContentType(media_info);
43  if (content_type == kContentTypeUnknown)
44  return false;
45 
46  base::AutoLock auto_lock(lock_);
47  // TODO(kqyang): Consider adding a new method MpdBuilder::AddRepresentation.
48  // Most of the codes here can be moved inside.
49  std::string lang;
50  if (media_info.has_audio_info()) {
51  lang = media_info.audio_info().language();
52  }
53  AdaptationSet** adaptation_set = &adaptation_set_map_[content_type][lang];
54  if (*adaptation_set == NULL)
55  *adaptation_set = mpd_builder_->AddAdaptationSet(lang);
56 
57  DCHECK(*adaptation_set);
58  MediaInfo adjusted_media_info(media_info);
59  MpdBuilder::MakePathsRelativeToMpd(output_path_, &adjusted_media_info);
60  Representation* representation =
61  (*adaptation_set)->AddRepresentation(adjusted_media_info);
62  if (representation == NULL)
63  return false;
64 
65  // For SimpleMpdNotifier, just put it in Representation. It should still
66  // generate a valid MPD.
67  AddContentProtectionElements(media_info, representation);
68  *container_id = representation->id();
69  DCHECK(!ContainsKey(representation_map_, representation->id()));
70  representation_map_[representation->id()] = representation;
71  return true;
72 }
73 
74 bool SimpleMpdNotifier::NotifySampleDuration(uint32_t container_id,
75  uint32_t sample_duration) {
76  base::AutoLock auto_lock(lock_);
77  RepresentationMap::iterator it = representation_map_.find(container_id);
78  if (it == representation_map_.end()) {
79  LOG(ERROR) << "Unexpected container_id: " << container_id;
80  return false;
81  }
82  it->second->SetSampleDuration(sample_duration);
83  return true;
84 }
85 
86 bool SimpleMpdNotifier::NotifyNewSegment(uint32_t container_id,
87  uint64_t start_time,
88  uint64_t duration,
89  uint64_t size) {
90  base::AutoLock auto_lock(lock_);
91  RepresentationMap::iterator it = representation_map_.find(container_id);
92  if (it == representation_map_.end()) {
93  LOG(ERROR) << "Unexpected container_id: " << container_id;
94  return false;
95  }
96  it->second->AddNewSegment(start_time, duration, size);
97  return true;
98 }
99 
101  uint32_t container_id,
102  const std::string& drm_uuid,
103  const std::vector<uint8_t>& new_key_id,
104  const std::vector<uint8_t>& new_pssh) {
105  base::AutoLock auto_lock(lock_);
106  RepresentationMap::iterator it = representation_map_.find(container_id);
107  if (it == representation_map_.end()) {
108  LOG(ERROR) << "Unexpected container_id: " << container_id;
109  return false;
110  }
111  it->second->UpdateContentProtectionPssh(drm_uuid,
112  Uint8VectorToBase64(new_pssh));
113  return true;
114 }
115 
117  uint32_t container_id,
118  const ContentProtectionElement& content_protection_element) {
119  base::AutoLock auto_lock(lock_);
120  RepresentationMap::iterator it = representation_map_.find(container_id);
121  if (it == representation_map_.end()) {
122  LOG(ERROR) << "Unexpected container_id: " << container_id;
123  return false;
124  }
125  it->second->AddContentProtectionElement(content_protection_element);
126  return true;
127 }
128 
130  return WriteMpdToFile(output_path_, mpd_builder_.get());
131 }
132 
133 } // namespace edash_packager
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(uint32_t id, const ContentProtectionElement &content_protection_element) override
void AddContentProtectionElements(const MediaInfo &media_info, Representation *parent)
Definition: mpd_utils.cc:253
bool NotifySampleDuration(uint32_t container_id, uint32_t sample_duration) override
static void MakePathsRelativeToMpd(const std::string &mpd_path, MediaInfo *media_info)
Definition: mpd_builder.cc:608
bool NotifyNewContainer(const MediaInfo &media_info, uint32_t *id) override
bool NotifyNewSegment(uint32_t id, uint64_t start_time, uint64_t duration, uint64_t size) override
std::string Uint8VectorToBase64(const std::vector< uint8_t > &input)
Converts uint8 vector into base64 encoded string.
bool WriteMpdToFile(const std::string &output_path, MpdBuilder *mpd_builder)
ContentType GetContentType(const MediaInfo &media_info)