DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
mpd_utils.h
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 // Funtions used by MpdBuilder class to generate an MPD file.
8 
9 #ifndef MPD_BASE_MPD_UTILS_H_
10 #define MPD_BASE_MPD_UTILS_H_
11 
12 #include <libxml/tree.h>
13 
14 #include <list>
15 #include <string>
16 
17 #include "packager/base/base64.h"
18 #include "packager/base/strings/string_util.h"
19 #include "packager/mpd/base/content_protection_element.h"
20 #include "packager/mpd/base/media_info.pb.h"
21 #include "packager/mpd/base/mpd_builder.h"
22 
23 namespace edash_packager {
24 
25 class MediaInfo;
26 struct ContentProtectionElement;
27 struct SegmentInfo;
28 
29 const char kEncryptedMp4Scheme[] = "urn:mpeg:dash:mp4protection:2011";
30 const char kPsshElementName[] = "cenc:pssh";
31 const char kEncryptedMp4Value[] = "cenc";
32 
33 bool HasVODOnlyFields(const MediaInfo& media_info);
34 
35 bool HasLiveOnlyFields(const MediaInfo& media_info);
36 
37 // If |content_protection_element| has 'value' or 'schemeIdUri' set but it's
38 // also in the map, then this removes them from the map.
39 // |content_protection_element| cannot be NULL.
40 void RemoveDuplicateAttributes(
41  ContentProtectionElement* content_protection_element);
42 
43 // Returns a language tag. May be blank for video.
44 std::string GetLanguage(const MediaInfo& media_info);
45 
46 // Returns a 'codecs' string that has all the video and audio codecs joined with
47 // comma.
48 std::string GetCodecs(const MediaInfo& media_info);
49 
50 // Returns a codec string without variants. For example, "mp4a" instead of
51 // "mp4a.40.2". May return a format for text streams.
52 std::string GetBaseCodec(const MediaInfo& media_info);
53 
54 // Returns a key made from the characteristics that separate AdaptationSets.
55 std::string GetAdaptationSetKey(const MediaInfo& media_info);
56 
57 std::string SecondsToXmlDuration(double seconds);
58 
59 // Tries to get "duration" attribute from |node|. On success |duration| is set.
60 bool GetDurationAttribute(xmlNodePtr node, float* duration);
61 
62 bool MoreThanOneTrue(bool b1, bool b2, bool b3);
63 bool AtLeastOneTrue(bool b1, bool b2, bool b3);
64 bool OnlyOneTrue(bool b1, bool b2, bool b3);
65 
69 bool HexToUUID(const std::string& data, std::string* uuid_format);
70 
71 // Update the <cenc:pssh> element for |drm_uuid| ContentProtection element.
72 // If the element does not exist, this will add one.
73 void UpdateContentProtectionPsshHelper(
74  const std::string& drm_uuid,
75  const std::string& pssh,
76  std::list<ContentProtectionElement>* content_protection_elements);
77 
84 void AddContentProtectionElements(const MediaInfo& media_info,
85  Representation* parent);
86 
92 void AddContentProtectionElements(const MediaInfo& media_info,
93  AdaptationSet* parent);
94 
95 } // namespace edash_packager
96 
97 #endif // MPD_BASE_MPD_UTILS_H_
void AddContentProtectionElements(const MediaInfo &media_info, Representation *parent)
Definition: mpd_utils.cc:338
bool HexToUUID(const std::string &data, std::string *uuid_format)
Definition: mpd_utils.cc:175