Skip to content

Commit

Permalink
[Live] Disallow seek to expired segments / fix presentationTimeOffset…
Browse files Browse the repository at this point in the history
… / compile issue fixed
  • Loading branch information
peak3d committed Aug 12, 2017
1 parent 0e6bb85 commit 25b96fa
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/libbento4/Codecs/Ap4AvcParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class AP4_AvcFrameParser {
AP4_AvcFrameParser();
~AP4_AvcFrameParser();

static AP4_Result AP4_AvcFrameParser::ParseFrameForSPS(const AP4_Byte* data,
static AP4_Result ParseFrameForSPS(const AP4_Byte* data,
AP4_Size data_size,
AP4_UI08 naluLengthSize,
AP4_AvcSequenceParameterSet &sps);
Expand Down
4 changes: 4 additions & 0 deletions src/common/AdaptiveStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ bool AdaptiveStream::seek_time(double seek_seconds, double current_seconds, bool
if (choosen_seg && current_rep_->get_segment(choosen_seg)->startPTS_ > sec_in_ts)
--choosen_seg;

// Never seek into expired segments.....
if (choosen_seg < current_rep_->expired_segments_)
choosen_seg = current_rep_->expired_segments_;

const AdaptiveTree::Segment *old_seg(current_seg_), *newSeg(current_rep_->get_segment(choosen_seg));
if (newSeg)
{
Expand Down
11 changes: 10 additions & 1 deletion src/common/AdaptiveTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "AdaptiveTree.h"
#include <string.h>
#include <algorithm>
#include <stdlib.h>

namespace adaptive
{
Expand Down Expand Up @@ -98,7 +99,7 @@ namespace adaptive
return;

//Get a modifiable adaptationset
AdaptationSet *adpm(static_cast<AdaptationSet *>((void*)adp));
AdaptationSet *adpm(const_cast<AdaptationSet *>(adp));

// Check if its the last frame we watch
if (adp->segment_durations_.data.size())
Expand All @@ -108,7 +109,10 @@ namespace adaptive
adpm->segment_durations_.insert(static_cast<std::uint64_t>(fragmentDuration)*adp->timescale_ / movie_timescale);
}
else
{
++const_cast<Representation*>(rep)->expired_segments_;
return;
}
}
else if (pos != rep->segments_.data.size() - 1)
return;
Expand All @@ -128,6 +132,11 @@ namespace adaptive
(*b)->segments_.insert(seg);
}

void AdaptiveTree::OnDataArrived(Representation *rep, const Segment *seg, const uint8_t *src, uint8_t *dst, size_t dstOffset, size_t dataSize)
{
memcpy(dst + dstOffset, src, dataSize);
}

uint8_t AdaptiveTree::insert_psshset(StreamType type)
{
if (!current_pssh_.empty())
Expand Down
5 changes: 3 additions & 2 deletions src/common/AdaptiveTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace adaptive
struct Representation
{
Representation() :bandwidth_(0), samplingRate_(0), width_(0), height_(0), fpsRate_(0), fpsScale_(1), aspect_(0.0f),
flags_(0), hdcpVersion_(0), indexRangeMin_(0), indexRangeMax_(0), channelCount_(0), nalLengthSize_(0), pssh_set_(0),
flags_(0), hdcpVersion_(0), indexRangeMin_(0), indexRangeMax_(0), channelCount_(0), nalLengthSize_(0), pssh_set_(0), expired_segments_(0),
containerType_(AdaptiveTree::CONTAINERTYPE_MP4), duration_(0), timescale_(0), segmentBaseId_(~0ULL), nextPTS_(0){};
std::string url_;
std::string id;
Expand Down Expand Up @@ -143,6 +143,7 @@ namespace adaptive
uint32_t indexRangeMin_, indexRangeMax_;
uint8_t channelCount_, nalLengthSize_;
uint8_t pssh_set_;
uint32_t expired_segments_;
ContainerType containerType_;
SegmentTemplate segtpl_;
//SegmentList
Expand Down Expand Up @@ -267,7 +268,7 @@ namespace adaptive

virtual bool open(const char *url) = 0;
virtual bool prepareRepresentation(Representation *rep, uint64_t segmentId = 0) { return true; };
virtual void OnDataArrived(Representation *rep, const Segment *seg, const uint8_t *src, uint8_t *dst, size_t dstOffset, size_t dataSize) { memcpy(dst + dstOffset, src, dataSize); };
virtual void OnDataArrived(Representation *rep, const Segment *seg, const uint8_t *src, uint8_t *dst, size_t dstOffset, size_t dataSize);
virtual void OnSegmentDownloaded(Representation *rep, const Segment *seg) {};

uint8_t insert_psshset(StreamType type);
Expand Down
2 changes: 1 addition & 1 deletion src/parser/DASHTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static void ParseSegmentTemplate(const char **attr, std::string baseURL, DASHTre
pto = atoll((const char*)*(attr + 1));
attr += 2;
}
tpl.presentationTimeOffset = tpl.timescale ? (pto * 1000000) / tpl.timescale : 0;
tpl.presentationTimeOffset = tpl.timescale ? static_cast<uint64_t>((static_cast<double>(pto) / tpl.timescale) * 1000000) : 0;
tpl.media = baseURL + tpl.media;
}

Expand Down
3 changes: 3 additions & 0 deletions src/parser/HLSTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ bool HLSTree::prepareRepresentation(Representation *rep, uint64_t segmentId)
rep->segments_.insert(segment);
++rep->segmentBaseId_;
--freeSegments;
if (rep->expired_segments_)
--rep->expired_segments_;
rep->nextPTS_ = pts;
}
else if (byteRange)
Expand All @@ -366,6 +368,7 @@ bool HLSTree::prepareRepresentation(Representation *rep, uint64_t segmentId)
return false;
freeSegments = static_cast<size_t>(segmentId - rep->segmentBaseId_); // Number of slots to fill
segmentId += rep->segments_.data.size() - freeSegments; //First segmentId to be inserted
rep->expired_segments_ = segmentBaseId - rep->segmentBaseId_;
}
else if (line.compare(0, 21, "#EXT-X-PLAYLIST-TYPE:") == 0)
{
Expand Down

0 comments on commit 25b96fa

Please sign in to comment.