Commit 458dc05c authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: add sequence number to all segments

parent f5bbc438
......@@ -34,6 +34,9 @@
using namespace adaptative::http;
using namespace adaptative::playlist;
const int ISegment::SEQUENCE_INVALID = 0;
const int ISegment::SEQUENCE_FIRST = 1;
ISegment::ISegment(const ICanonicalUrl *parent):
ICanonicalUrl( parent ),
startByte (0),
......@@ -44,6 +47,7 @@ ISegment::ISegment(const ICanonicalUrl *parent):
startTime.Set(0);
duration.Set(0);
chunksuse.Set(0);
sequence = SEQUENCE_INVALID;
}
ISegment::~ISegment()
......@@ -92,6 +96,16 @@ void ISegment::setByteRange(size_t start, size_t end)
endByte = end;
}
void ISegment::setSequenceNumber(uint64_t seq)
{
sequence = SEQUENCE_FIRST + seq;
}
uint64_t ISegment::getSequenceNumber() const
{
return sequence;
}
size_t ISegment::getOffset() const
{
return startByte;
......
......@@ -55,6 +55,8 @@ namespace adaptative
*/
virtual SegmentChunk* toChunk (size_t, BaseRepresentation * = NULL);
virtual void setByteRange (size_t start, size_t end);
virtual void setSequenceNumber(uint64_t);
virtual uint64_t getSequenceNumber() const;
virtual size_t getOffset () const;
virtual std::vector<ISegment*> subSegments () = 0;
virtual void addSubSegment (SubSegment *) = 0;
......@@ -75,6 +77,9 @@ namespace adaptative
size_t endByte;
std::string debugName;
int classId;
uint64_t sequence;
static const int SEQUENCE_INVALID;
static const int SEQUENCE_FIRST;
virtual SegmentChunk * getChunk(const std::string &);
};
......
......@@ -38,7 +38,7 @@ SegmentEncryption::SegmentEncryption()
HLSSegment::HLSSegment( ICanonicalUrl *parent, uint64_t seq ) :
Segment( parent )
{
sequence = seq;
setSequenceNumber(seq);
#ifdef HAVE_GCRYPT
ctx = NULL;
#endif
......@@ -85,10 +85,10 @@ void HLSSegment::onChunkDownload(block_t **pp_block, SegmentChunk *chunk, BaseRe
{
encryption.iv.clear();
encryption.iv.resize(16);
encryption.iv[15] = sequence & 0xff;
encryption.iv[14] = (sequence >> 8)& 0xff;
encryption.iv[13] = (sequence >> 16)& 0xff;
encryption.iv[12] = (sequence >> 24)& 0xff;
encryption.iv[15] = (getSequenceNumber() - Segment::SEQUENCE_FIRST) & 0xff;
encryption.iv[14] = ((getSequenceNumber() - Segment::SEQUENCE_FIRST) >> 8)& 0xff;
encryption.iv[13] = ((getSequenceNumber() - Segment::SEQUENCE_FIRST) >> 16)& 0xff;
encryption.iv[12] = ((getSequenceNumber() - Segment::SEQUENCE_FIRST) >> 24)& 0xff;
}
if( gcry_cipher_open(&ctx, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0) ||
......@@ -148,7 +148,7 @@ void HLSSegment::debug(vlc_object_t *obj, int indent) const
{
std::stringstream ss;
ss << std::string(indent, ' ') << debugName <<
" #" << sequence <<
" #" << (getSequenceNumber() - Segment::SEQUENCE_FIRST) <<
" url=" << getUrlSegment().toString();
if(startByte!=endByte)
ss << " @" << startByte << ".." << endByte;
......@@ -160,9 +160,9 @@ int HLSSegment::compare(ISegment *segment) const
HLSSegment *hlssegment = dynamic_cast<HLSSegment *>(segment);
if(hlssegment)
{
if (sequence > hlssegment->sequence)
if (getSequenceNumber() > hlssegment->getSequenceNumber())
return 1;
else if(sequence < hlssegment->sequence)
else if(getSequenceNumber() < hlssegment->getSequenceNumber())
return -1;
else
return 0;
......
......@@ -63,7 +63,6 @@ namespace hls
virtual void onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *); /* reimpl */
void checkFormat(block_t *, SegmentChunk *, BaseRepresentation *);
uint64_t sequence;
SegmentEncryption encryption;
#ifdef HAVE_GCRYPT
gcry_cipher_hd_t ctx;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment