Torc  0.1
torcsegmentedringbuffer.h
Go to the documentation of this file.
1 #ifndef TORCSEGMENTEDRINGBUFFER_H
2 #define TORCSEGMENTEDRINGBUFFER_H
3 
4 // Qt
5 #include <QPair>
6 #include <QQueue>
7 #include <QIODevice>
8 #include <QReadWriteLock>
9 
10 class TorcSegmentedRingBuffer : public QObject
11 {
12  Q_OBJECT
13 
14  public:
15  explicit TorcSegmentedRingBuffer(int Size, int MaxSegments);
17 
18  int GetSize (void);
19  int GetHead (void);
20  int GetSegmentsAvail (int &TailRef);
21  int Write (QByteArray *Data, int Size);
22  int Write (const uint8_t *Data, int Size);
23  int FinishSegment (bool Init);
24  int ReadSegment (uint8_t *Data, int Max, int SegmentRef, int Offset = 0);
25  int ReadSegment (QIODevice *Dst, int SegmentRef);
26  QByteArray GetSegment (int SegmentRef);
27  QByteArray GetInitSegment (void);
28  void SaveInitSegment (void);
29 
30  signals:
31  void InitSegmentReady (void);
32  void SegmentReady (int Segment);
33  void SegmentRemoved (int Segment);
34 
35  protected:
36  int GetBytesFree (void);
37 
38  protected:
39  int m_size;
40  QByteArray m_data;
45  QReadWriteLock m_segmentsLock;
46  QQueue<QPair<int,int> > m_segments;
47  QQueue<int> m_segmentRefs;
50  QByteArray m_initSegment;
51 };
52 
53 #endif // TORCSEGMENTEDRINGBUFFER_H
int GetHead(void)
Return the number of the segment at the head of the queue (the newest).
QQueue< QPair< int, int > > m_segments
QByteArray GetInitSegment(void)
Return a copy of the MP4 &#39;init&#39; segment.
int GetSize(void)
Return the size of the buffer (NOT the number of segments).
int FinishSegment(bool Init)
Finish the current segment and start a new one.
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...
void SegmentReady(int Segment)
void SegmentRemoved(int Segment)
int GetSegmentsAvail(int &TailRef)
Return the number of available segments.
int Write(QByteArray *Data, int Size)
TorcSegmentedRingBuffer(int Size, int MaxSegments)
void SaveInitSegment(void)
Save the MP4 &#39;init&#39; segment.
int GetBytesFree(void)
Return the number of free bytes available for writing.
QByteArray GetSegment(int SegmentRef)
Return a copy of the segment identified by SegmentRef.