SegmentTemplate.cpp 3.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*****************************************************************************
 * SegmentTemplate.cpp: Implement the UrlTemplate element.
 *****************************************************************************
 * Copyright (C) 1998-2007 VLC authors and VideoLAN
 * $Id$
 *
 * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
23
24
25
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include "SegmentTemplate.h"
#include "SegmentTimeline.h"
#include "Representation.h"
#include "Group.h"
#include "SegmentInfoDefault.h"

#include <cassert>
#include <cstring>
#include <iostream>
#include <sstream>

using namespace dash::mpd;

SegmentTemplate::SegmentTemplate( bool containRuntimeIdentifier,
                                  Representation* representation ) :
42
    Segment( representation ),
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    containRuntimeIdentifier( containRuntimeIdentifier ),
    beginTime( std::string::npos ),
    beginIndex( std::string::npos ),
    currentSegmentIndex( 0 )
{
}

std::string     SegmentTemplate::getSourceUrl() const
{
    std::string     res = this->sourceUrl;

    if ( this->containRuntimeIdentifier == false )
        return Segment::getSourceUrl();

    if ( this->beginIndex != std::string::npos )
        std::cerr << "Unhandled identifier \"$Index$\"" << std::endl;
    if ( this->beginTime != std::string::npos )
    {
        //FIXME: This should use the current representation SegmentInfo
        //which "inherits" the SegmentInfoDefault values.
63
64
        if ( this->parentRepresentation->getParentGroup()->getSegmentInfoDefault() != NULL &&
             this->parentRepresentation->getParentGroup()->getSegmentInfoDefault()->getSegmentTimeline() != NULL )
65
        {
66
            const SegmentTimeline::Element  *el = this->parentRepresentation->getParentGroup()->
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
                    getSegmentInfoDefault()->getSegmentTimeline()->getElement( this->currentSegmentIndex );
            if ( el != NULL )
            {
                std::ostringstream  oss;
                oss << el->t;
                res.replace( this->beginTime, strlen("$Time$"), oss.str() );
            }
        }
    }
    return res;
}

void    SegmentTemplate::setSourceUrl( const std::string &url )
{
    if ( this->containRuntimeIdentifier == true )
    {
        this->beginTime = url.find( "$Time$" );
        this->beginIndex = url.find( "$Index$" );
    }
    Segment::setSourceUrl( url );
}

bool            SegmentTemplate::isSingleShot() const
{
    return false;
}

void SegmentTemplate::done()
{
    this->currentSegmentIndex++;
}