aboutsummaryrefslogtreecommitdiffstats
path: root/src/libdash/source/mpd/Segment.cpp
blob: 312007623feb510030657e52b7c6700e3c7ebdff (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * Segment.cpp
 *****************************************************************************
 * Copyright (C) 2013, 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 "Segment.h"

using namespace dash::mpd;
using namespace dash::helpers;
using namespace dash::metrics;

Segment::Segment    ()  :
            host(""),
            port(0),
            path(""),
            startByte(0),
            endByte(0),
            hasByteRange(false)
{
}
Segment::~Segment   ()
{
}

bool                Segment::Init               (const std::vector<IBaseUrl *>& baseurls, const std::string &uri, const std::string &range, HTTPTransactionType type)
{
    std::string host        = "";
    size_t      port        = 80;
    std::string path        = "";
    size_t      startByte   = 0;
    size_t      endByte     = 0;

    this->absoluteuri = "";

    for(size_t i = 0; i < baseurls.size(); i++)
        this->absoluteuri = Path::CombinePaths(this->absoluteuri, baseurls.at(i)->GetUrl());

    this->absoluteuri = Path::CombinePaths(this->absoluteuri, uri);

    if (uri != "" && dash::helpers::Path::GetHostPortAndPath(this->absoluteuri, host, port, path))
    {
        this->host = host;
        this->port = port;
        this->path = path;

        if (range != "" && dash::helpers::Path::GetStartAndEndBytes(range, startByte, endByte))
        {
            this->range         = range;
            this->hasByteRange  = true;
            this->startByte     = startByte;
            this->endByte       = endByte;
        }

        this->type = type;

        return true;
    }

    return false;
}
std::string&        Segment::AbsoluteURI        ()
{
    return this->absoluteuri;
}
std::string&        Segment::Host               ()
{
    return this->host;
}
size_t              Segment::Port               ()
{
    return this->port;
}
std::string&        Segment::Path               ()
{
    return this->path;
}
std::string&        Segment::Range              ()
{
    return this->range;
}
size_t              Segment::StartByte          ()
{
    return this->startByte;
}
size_t              Segment::EndByte            ()
{
    return this->endByte;
}
bool                Segment::HasByteRange       ()
{
    return this->hasByteRange;
}
void                Segment::AbsoluteURI        (std::string uri)
{
    this->absoluteuri = uri;
}
void                Segment::Host               (std::string host)
{
    this->host = host;
}
void                Segment::Port               (size_t port)
{
    this->port = port;
}
void                Segment::Path               (std::string path)
{
    this->path = path;
}
void                Segment::Range              (std::string range)
{
    this->range = range;
}
void                Segment::StartByte          (size_t startByte)
{
    this->startByte = startByte;
}
void                Segment::EndByte            (size_t endByte)
{
    this->endByte = endByte;
}
void                Segment::HasByteRange       (bool hasByteRange)
{
    this->hasByteRange = hasByteRange;
}
HTTPTransactionType Segment::GetType            ()
{
    return this->type;
}
void                Segment::SetType            (HTTPTransactionType type)
{
    this->type = type;
}