aboutsummaryrefslogtreecommitdiffstats
path: root/MPD/AdaptationSetStream.cpp
blob: 62bc1912db67695cc6da170ae0508845bdf5e54d (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
/*
 * AdaptationSetStream.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 "AdaptationSetStream.h"

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

AdaptationSetStream::AdaptationSetStream(IMPD *mpd, IPeriod *period, IAdaptationSet *adaptationSet) :
    mpd                 (mpd),
    period              (period),
    adaptationSet       (adaptationSet)
{
    initialize();
}

AdaptationSetStream::~AdaptationSetStream()
{
    std::map<IRepresentation *, IRepresentationStream *>::iterator iter;
    for (iter = representations.begin(); iter != representations.end(); ++iter)
    {
        delete(iter->second);
    }
}

IRepresentationStream* AdaptationSetStream::getRepresentationStream(IRepresentation *representation)
{
    return this->representations.find(representation)->second;
}

RepresentationStreamType AdaptationSetStream::determineRepresentationStreamType (IRepresentation *representation)
{
    /* check on Representation Level */
    if (representation->GetSegmentList())
        return libdash::framework::mpd::SegmentList;

    if (representation->GetSegmentTemplate())
        return libdash::framework::mpd::SegmentTemplate;

    if (representation->GetSegmentBase() || representation->GetBaseURLs().size() > 0)
        return libdash::framework::mpd::SingleMediaSegment;

    /* check on AdaptationSet Level */
    if (this->adaptationSet->GetSegmentList())
        return libdash::framework::mpd::SegmentList;

    if (this->adaptationSet->GetSegmentTemplate())
        return libdash::framework::mpd::SegmentTemplate;

    if (this->adaptationSet->GetSegmentBase())
        return libdash::framework::mpd::SingleMediaSegment;

    /* check on Period Level */
    if (this->period->GetSegmentList())
        return libdash::framework::mpd::SegmentList;

    if (this->period->GetSegmentTemplate())
        return libdash::framework::mpd::SegmentTemplate;

    if (this->period->GetSegmentBase())
        return libdash::framework::mpd::SingleMediaSegment;

    return libdash::framework::mpd::UNDEFINED;
}

void AdaptationSetStream::initialize()
{
    for (size_t i = 0; i < adaptationSet->GetRepresentation().size(); i++)
    {
        IRepresentation *representation = adaptationSet->GetRepresentation().at(i);
        RepresentationStreamType type   = determineRepresentationStreamType(representation);
        representations[representation] = RepresentationStreamFactory::create(type, mpd, period, adaptationSet, representation);
    }
}