1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2015 - VideoLAN Authors
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 by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
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.
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 *****************************************************************************/
24 #include "SmoothSegment.hpp"
26 #include "../../adaptive/playlist/BaseRepresentation.h"
27 #include "../../adaptive/playlist/AbstractPlaylist.hpp"
28 #include "../mp4/IndexReader.hpp"
30 using namespace smooth::playlist
;
31 using namespace smooth::mp4
;
33 SmoothSegmentChunk::SmoothSegmentChunk(AbstractChunkSource
*source
, BaseRepresentation
*rep
)
34 : SegmentChunk(source
, rep
)
39 SmoothSegmentChunk::~SmoothSegmentChunk()
44 void SmoothSegmentChunk::onDownload(block_t
**pp_block
)
48 if(!rep
|| ((*pp_block
)->i_flags
& BLOCK_FLAG_HEADER
) == 0)
51 IndexReader
br(rep
->getPlaylist()->getVLCObject());
52 br
.parseIndex(*pp_block
, rep
);
54 /* If timeshift depth is present, we use it for expiring segments
55 as we never update playlist itself */
56 if(rep
->getPlaylist()->timeShiftBufferDepth
.Get())
58 vlc_tick_t start
, end
, length
;
59 if(rep
->getMediaPlaybackRange(&start
, &end
, &length
))
61 start
= std::max(start
, end
- rep
->getPlaylist()->timeShiftBufferDepth
.Get());
62 rep
->pruneByPlaybackTime(start
);
67 SmoothSegmentTemplate::SmoothSegmentTemplate(SegmentInformation
*parent
) :
68 SegmentTemplate( parent
)
73 SmoothSegmentTemplate::~SmoothSegmentTemplate()
78 SegmentChunk
* SmoothSegmentTemplate::createChunk(AbstractChunkSource
*source
, BaseRepresentation
*rep
)
81 return new (std::nothrow
) SmoothSegmentChunk(source
, rep
);