1 /* 2 * SegmentInformation.hpp 3 ***************************************************************************** 4 * Copyright (C) 2014 - VideoLAN and VLC Authors 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as published 8 * by the Free Software Foundation; either version 2.1 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 19 *****************************************************************************/ 20 #ifndef SEGMENTINFORMATION_HPP 21 #define SEGMENTINFORMATION_HPP 22 23 #include "ICanonicalUrl.hpp" 24 #include "../tools/Properties.hpp" 25 #include "../encryption/CommonEncryption.hpp" 26 #include "SegmentInfoCommon.h" 27 #include <vlc_common.h> 28 #include <vector> 29 30 namespace adaptive 31 { 32 namespace playlist 33 { 34 class SegmentBase; 35 class SegmentList; 36 class SegmentTimeline; 37 class SegmentTemplate; 38 class MediaSegmentTemplate; 39 class AbstractPlaylist; 40 class ISegment; 41 42 /* common segment elements for period/adaptset/rep 5.3.9.1, 43 * with properties inheritance */ 44 class SegmentInformation : public ICanonicalUrl, 45 public TimescaleAble, 46 public Unique 47 { 48 friend class MediaSegmentTemplate; 49 public: 50 SegmentInformation( SegmentInformation * = 0 ); 51 explicit SegmentInformation( AbstractPlaylist * ); 52 virtual ~SegmentInformation(); 53 54 virtual mtime_t getPeriodStart() const; 55 virtual mtime_t getPeriodDuration() const; 56 virtual AbstractPlaylist *getPlaylist() const; 57 58 class SplitPoint 59 { 60 public: 61 size_t offset; 62 stime_t time; 63 stime_t duration; 64 }; 65 void SplitUsingIndex(std::vector<SplitPoint>&); 66 67 enum SegmentInfoType 68 { 69 INFOTYPE_INIT = 0, 70 INFOTYPE_MEDIA, 71 INFOTYPE_INDEX 72 }; 73 static const int InfoTypeCount = INFOTYPE_INDEX + 1; 74 75 ISegment * getSegment(SegmentInfoType, uint64_t = 0) const; 76 ISegment * getNextSegment(SegmentInfoType, uint64_t, uint64_t *, bool *) const; 77 bool getSegmentNumberByTime(mtime_t, uint64_t *) const; 78 bool getPlaybackTimeDurationBySegmentNumber(uint64_t, mtime_t *, mtime_t *) const; 79 bool getMediaPlaybackRange(mtime_t *, mtime_t *, mtime_t *) const; 80 virtual void updateWith(SegmentInformation *); 81 virtual void mergeWithTimeline(SegmentTimeline *); /* ! don't use with global merge */ 82 virtual void pruneBySegmentNumber(uint64_t); 83 virtual void pruneByPlaybackTime(mtime_t); 84 virtual uint64_t translateSegmentNumber(uint64_t, const SegmentInformation *) const; 85 void setEncryption(const CommonEncryption &); 86 const CommonEncryption & intheritEncryption() const; 87 88 protected: 89 std::size_t getAllSegments(std::vector<ISegment *> &) const; 90 virtual std::size_t getSegments(SegmentInfoType, std::vector<ISegment *>&) const; 91 std::vector<SegmentInformation *> childs; 92 SegmentInformation * getChildByID( const ID & ); 93 SegmentInformation *parent; 94 95 public: 96 void updateSegmentList(SegmentList *, bool = false); 97 void setSegmentBase(SegmentBase *); 98 void setSegmentTemplate(MediaSegmentTemplate *); 99 virtual Url getUrlSegment() const; /* impl */ 100 Property<Url *> baseUrl; 101 void setAvailabilityTimeOffset(mtime_t); 102 void setAvailabilityTimeComplete(bool); 103 SegmentBase * inheritSegmentBase() const; 104 SegmentList * inheritSegmentList() const; 105 MediaSegmentTemplate * inheritSegmentTemplate() const; 106 mtime_t inheritAvailabilityTimeOffset() const; 107 bool inheritAvailabilityTimeComplete() const; 108 109 private: 110 void init(); 111 SegmentBase *segmentBase; 112 SegmentList *segmentList; 113 MediaSegmentTemplate *mediaSegmentTemplate; 114 CommonEncryption commonEncryption; 115 Undef<bool> availabilityTimeComplete; 116 Undef<mtime_t> availabilityTimeOffset; 117 }; 118 } 119 } 120 121 #endif // SEGMENTINFORMATION_HPP 122