Shaka Packager SDK
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 namespace shaka {
18 
19 class AdaptationSet;
20 class MediaInfo;
21 class Representation;
22 struct ContentProtectionElement;
23 struct SegmentInfo;
24 
25 const char kEncryptedMp4Scheme[] = "urn:mpeg:dash:mp4protection:2011";
26 const char kPsshElementName[] = "cenc:pssh";
27 const char kMsproElementName[] = "mspr:pro";
28 
29 bool HasVODOnlyFields(const MediaInfo& media_info);
30 
31 bool HasLiveOnlyFields(const MediaInfo& media_info);
32 
33 // If |content_protection_element| has 'value' or 'schemeIdUri' set but it's
34 // also in the map, then this removes them from the map.
35 // |content_protection_element| cannot be NULL.
36 void RemoveDuplicateAttributes(
37  ContentProtectionElement* content_protection_element);
38 
39 // Returns a language in ISO-639 shortest form. May be blank for video.
40 std::string GetLanguage(const MediaInfo& media_info);
41 
42 // Returns a 'codecs' string that has all the video and audio codecs joined with
43 // comma.
44 std::string GetCodecs(const MediaInfo& media_info);
45 
46 // Returns a codec string without variants. For example, "mp4a" instead of
47 // "mp4a.40.2". May return a format for text streams.
48 std::string GetBaseCodec(const MediaInfo& media_info);
49 
50 // Returns a key made from the characteristics that separate AdaptationSets.
51 std::string GetAdaptationSetKey(const MediaInfo& media_info, bool ignore_codec);
52 
53 std::string SecondsToXmlDuration(double seconds);
54 
55 // Tries to get "duration" attribute from |node|. On success |duration| is set.
56 bool GetDurationAttribute(xmlNodePtr node, float* duration);
57 
58 bool MoreThanOneTrue(bool b1, bool b2, bool b3);
59 bool AtLeastOneTrue(bool b1, bool b2, bool b3);
60 bool OnlyOneTrue(bool b1, bool b2, bool b3);
61 
65 bool HexToUUID(const std::string& data, std::string* uuid_format);
66 
67 // Update the <cenc:pssh> element for |drm_uuid| ContentProtection element.
68 // If the element does not exist, this will add one.
69 void UpdateContentProtectionPsshHelper(
70  const std::string& drm_uuid,
71  const std::string& pssh,
72  std::list<ContentProtectionElement>* content_protection_elements);
73 
80 void AddContentProtectionElements(const MediaInfo& media_info,
81  Representation* parent);
82 
88 void AddContentProtectionElements(const MediaInfo& media_info,
89  AdaptationSet* parent);
90 
91 } // namespace shaka
92 
93 #endif // MPD_BASE_MPD_UTILS_H_
All the methods that are virtual are virtual for mocking.
bool HexToUUID(const std::string &data, std::string *uuid_format)
Definition: mpd_utils.cc:232
void AddContentProtectionElements(const MediaInfo &media_info, Representation *parent)
Definition: mpd_utils.cc:473