aboutsummaryrefslogtreecommitdiffstats
path: root/MPD/AbstractRepresentationStream.cpp
blob: 1ffee924204580a7651b898a0400debfde0e00c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * AbstractRepresentationStream.cpp
 *****************************************************************************
 * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
 *
 * Email: libdash-dev@vicky.bitmovin.net
 *
 * This source code and its use and distribution, is subject to the terms
 * and conditions of the applicable license agreement.
 *****************************************************************************/

#include "AbstractRepresentationStream.h"

using namespace libdash::framework::mpd;
using namespace dash::mpd;

AbstractRepresentationStream::AbstractRepresentationStream(viper::managers::StreamType type, IMPDWrapper *mpdWrapper, IPeriod *period, IAdaptationSet *adaptationSet, IRepresentation *representation) :
                              type			    (type),
			      mpdWrapper                    (mpdWrapper),
                              period                        (period),
                              adaptationSet                 (adaptationSet),
                              representation                (representation)
{
}
AbstractRepresentationStream::~AbstractRepresentationStream()
{
}

void AbstractRepresentationStream::setBaseUrls(const std::vector<dash::mpd::IBaseUrl *> baseurls)
{
    this->baseUrls.clear();

    for (size_t i = 0; i < baseurls.size(); i++)
        this->baseUrls.push_back(baseurls.at(i));
}

uint32_t AbstractRepresentationStream::getSize()
{
    return UINT32_MAX - 1;
}

uint32_t AbstractRepresentationStream::getFirstSegmentNumber()
{
    if (this->mpdWrapper->getTypeWithoutLock() == "dynamic")
    {
        uint32_t currTime = TimeResolver::getCurrentTimeInSec();
        uint32_t availStT = TimeResolver::getUTCDateTimeInSec(this->mpdWrapper->getAvailabilityStarttime());
        uint32_t duration = this->getAverageSegmentDuration();
        uint32_t timeshift = TimeResolver::getDurationInSec(this->mpdWrapper->getTimeShiftBufferDepth());
        uint32_t timescale = this->getTimescale();
        return (double)((double)currTime - (double)availStT - (double)timeshift ) < 0? 0 : (currTime - availStT - timeshift );
    }
    return 0;
}

uint32_t AbstractRepresentationStream::getCurrentSegmentNumber()
{
    if (this->mpdWrapper->getTypeWithoutLock() == "dynamic")
    {
        uint32_t currTime = TimeResolver::getCurrentTimeInSec();
        uint32_t duration = this->getAverageSegmentDuration();
        uint32_t availStT = TimeResolver::getUTCDateTimeInSec(this->mpdWrapper->getAvailabilityStarttime());

        return (double)((double)currTime - (double)availStT) < 0 ? 0 : (currTime - availStT);
    //    return (currTime - duration - availStT) / duration;
    }
    return 0;
}

uint32_t AbstractRepresentationStream::getLastSegmentNumber      ()
{
    if (this->mpdWrapper->getTypeWithoutLock() == "dynamic")
    {
        uint32_t currTime   = TimeResolver::getCurrentTimeInSec();
        uint32_t duration = this->getAverageSegmentDuration();
        uint32_t availStT   = TimeResolver::getUTCDateTimeInSec(this->mpdWrapper->getAvailabilityStarttime());
        uint32_t checkTime  = mpdWrapper->getFetchTime() + 
                              TimeResolver::getDurationInSec(this->mpdWrapper->getMinimumUpdatePeriodWithoutLock());
        return ( ((checkTime > currTime) ? currTime : checkTime) - duration - availStT) / duration;
    }
    return 0;
}

uint32_t AbstractRepresentationStream::getAverageSegmentDuration()
{
    return 1;
}
uint32_t    AbstractRepresentationStream::getTimescale ()
{
    return 1;
}
void	    AbstractRepresentationStream::setSegmentOffset (uint32_t offset)
{
    this->segmentOffset = offset;
}

uint64_t AbstractRepresentationStream::getTime(size_t segmentNumber)
{
    return 0;
}
size_t AbstractRepresentationStream::getSegmentNumber(uint64_t time)
{
    return 0;
}