Torc  0.1
Signals | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
TorcSegmentedRingBuffer Class Reference

#include <torcsegmentedringbuffer.h>

Inheritance diagram for TorcSegmentedRingBuffer:
[legend]

Signals

void InitSegmentReady (void)
 
void SegmentReady (int Segment)
 
void SegmentRemoved (int Segment)
 

Public Member Functions

 TorcSegmentedRingBuffer (int Size, int MaxSegments)
 
 ~TorcSegmentedRingBuffer ()
 
int GetSize (void)
 Return the size of the buffer (NOT the number of segments). More...
 
int GetHead (void)
 Return the number of the segment at the head of the queue (the newest). More...
 
int GetSegmentsAvail (int &TailRef)
 Return the number of available segments. More...
 
int Write (QByteArray *Data, int Size)
 
int Write (const uint8_t *Data, int Size)
 Write data to the current segment. More...
 
int FinishSegment (bool Init)
 Finish the current segment and start a new one. More...
 
int ReadSegment (uint8_t *Data, int Max, int SegmentRef, int Offset=0)
 Copy Max bytes of a segment identified by SegmentRef into the memory pointed to at Dst. More...
 
int ReadSegment (QIODevice *Dst, int SegmentRef)
 Copy the segment identified by SegmentRef to the IODevice specified by Dst. More...
 
QByteArray GetSegment (int SegmentRef)
 Return a copy of the segment identified by SegmentRef. More...
 
QByteArray GetInitSegment (void)
 Return a copy of the MP4 'init' segment. More...
 
void SaveInitSegment (void)
 Save the MP4 'init' segment. More...
 

Protected Member Functions

int GetBytesFree (void)
 Return the number of free bytes available for writing. More...
 

Protected Attributes

int m_size
 
QByteArray m_data
 
int m_readPosition
 
int m_writePosition
 
int m_currentSize
 
int m_currentStartPosition
 
QReadWriteLock m_segmentsLock
 
QQueue< QPair< int, int > > m_segments
 
QQueue< int > m_segmentRefs
 
int m_segmentCounter
 
int m_maxSegments
 
QByteArray m_initSegment
 

Detailed Description

A circular buffer customised for storing segmented media data - principally fragmented MP4 files but should work with other formats such as transport streams (TS).

The owner is responsible for ensuring the total buffer size is appropriate for the use case (i.e. media type/bitrate and buffering required).

Definition at line 10 of file torcsegmentedringbuffer.h.

Constructor & Destructor Documentation

TorcSegmentedRingBuffer::TorcSegmentedRingBuffer ( int  Size,
int  MaxSegments 
)
explicit

Definition at line 35 of file torcsegmentedringbuffer.cpp.

TorcSegmentedRingBuffer::~TorcSegmentedRingBuffer ( )

Definition at line 52 of file torcsegmentedringbuffer.cpp.

Member Function Documentation

int TorcSegmentedRingBuffer::FinishSegment ( bool  Init)

Finish the current segment and start a new one.

The buffer's owner is responsible for indicating that the segment is finished.

Parameters
InitIndicates that this is an MP4 'init' segment that should be saved separately.

Definition at line 110 of file torcsegmentedringbuffer.cpp.

int TorcSegmentedRingBuffer::GetBytesFree ( void  )
inlineprotected

Return the number of free bytes available for writing.

Definition at line 60 of file torcsegmentedringbuffer.cpp.

int TorcSegmentedRingBuffer::GetHead ( void  )

Return the number of the segment at the head of the queue (the newest).

Definition at line 78 of file torcsegmentedringbuffer.cpp.

QByteArray TorcSegmentedRingBuffer::GetInitSegment ( void  )

Return a copy of the MP4 'init' segment.

Definition at line 287 of file torcsegmentedringbuffer.cpp.

QByteArray TorcSegmentedRingBuffer::GetSegment ( int  SegmentRef)

Return a copy of the segment identified by SegmentRef.

Definition at line 267 of file torcsegmentedringbuffer.cpp.

int TorcSegmentedRingBuffer::GetSegmentsAvail ( int &  TailRef)

Return the number of available segments.

If the buffer is not empty, TailRef will be set to the value of the oldest segment.

Definition at line 92 of file torcsegmentedringbuffer.cpp.

int TorcSegmentedRingBuffer::GetSize ( void  )

Return the size of the buffer (NOT the number of segments).

Definition at line 72 of file torcsegmentedringbuffer.cpp.

void TorcSegmentedRingBuffer::InitSegmentReady ( void  )
signal
int TorcSegmentedRingBuffer::ReadSegment ( uint8_t *  Dst,
int  Max,
int  SegmentRef,
int  Offset = 0 
)

Copy Max bytes of a segment identified by SegmentRef into the memory pointed to at Dst.

If returned value == MAX, try again with offset

Returns
-1 on error and the number of bytes copied/read on sucess (0 indicates no more bytes to read)

Definition at line 185 of file torcsegmentedringbuffer.cpp.

int TorcSegmentedRingBuffer::ReadSegment ( QIODevice *  Dst,
int  SegmentRef 
)

Copy the segment identified by SegmentRef to the IODevice specified by Dst.

Returns
-1 on error and the size of the copied/read segment on success.

Definition at line 214 of file torcsegmentedringbuffer.cpp.

void TorcSegmentedRingBuffer::SaveInitSegment ( void  )

Save the MP4 'init' segment.

Definition at line 233 of file torcsegmentedringbuffer.cpp.

void TorcSegmentedRingBuffer::SegmentReady ( int  Segment)
signal
void TorcSegmentedRingBuffer::SegmentRemoved ( int  Segment)
signal
int TorcSegmentedRingBuffer::Write ( QByteArray *  Data,
int  Size 
)

Definition at line 172 of file torcsegmentedringbuffer.cpp.

int TorcSegmentedRingBuffer::Write ( const uint8_t *  Data,
int  Size 
)

Write data to the current segment.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 137 of file torcsegmentedringbuffer.cpp.

Member Data Documentation

int TorcSegmentedRingBuffer::m_currentSize
protected

Definition at line 43 of file torcsegmentedringbuffer.h.

int TorcSegmentedRingBuffer::m_currentStartPosition
protected

Definition at line 44 of file torcsegmentedringbuffer.h.

QByteArray TorcSegmentedRingBuffer::m_data
protected

Definition at line 40 of file torcsegmentedringbuffer.h.

QByteArray TorcSegmentedRingBuffer::m_initSegment
protected

Definition at line 50 of file torcsegmentedringbuffer.h.

int TorcSegmentedRingBuffer::m_maxSegments
protected

Definition at line 49 of file torcsegmentedringbuffer.h.

int TorcSegmentedRingBuffer::m_readPosition
protected

Definition at line 41 of file torcsegmentedringbuffer.h.

int TorcSegmentedRingBuffer::m_segmentCounter
protected

Definition at line 48 of file torcsegmentedringbuffer.h.

QQueue<int> TorcSegmentedRingBuffer::m_segmentRefs
protected

Definition at line 47 of file torcsegmentedringbuffer.h.

QQueue<QPair<int,int> > TorcSegmentedRingBuffer::m_segments
protected

Definition at line 46 of file torcsegmentedringbuffer.h.

QReadWriteLock TorcSegmentedRingBuffer::m_segmentsLock
protected

Definition at line 45 of file torcsegmentedringbuffer.h.

int TorcSegmentedRingBuffer::m_size
protected

Definition at line 39 of file torcsegmentedringbuffer.h.

int TorcSegmentedRingBuffer::m_writePosition
protected

Definition at line 42 of file torcsegmentedringbuffer.h.


The documentation for this class was generated from the following files: