MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
ogg.h
Go to the documentation of this file.
1 #pragma once
2 #include <cstdlib>
3 #include <string>
4 #include <vector>
5 #include <deque>
6 #include <sstream>
7 #include "dtsc.h"
8 #include "theora.h"
9 #include "vorbis.h"
10 #include "socket.h"
11 
12 namespace OGG {
13 
14  class oggSegment {
15  public:
16  oggSegment();
17  std::string dataString;
19  long long unsigned int lastKeyFrameSeen;
20  long long unsigned int framesSinceKeyFrame;
21  unsigned int frameNumber;
22  long long unsigned int timeStamp;
23  };
24 
26 
27  enum HeaderType {
28  Plain = 0,
29  Continued = 1,
32  };
33 
34  std::deque<unsigned int> decodeXiphSize(char * data, size_t len);
35 
36 
37 
38 
39  class Page {
40  public:
41  Page();
42  Page(const Page & rhs);
43  void operator = (const Page & rhs);
44  bool read(std::string & newData);
45  bool read(FILE * inFile);
46  bool getSegment(unsigned int index, std::string & ret);
47  const char * getSegment(unsigned int index);
48  unsigned long getSegmentLen(unsigned int index);
49  void setMagicNumber();
50  char getVersion();
51  void setVersion(char newVal = 0);
52  char getHeaderType();
53  void setHeaderType(char newVal);
54  long long unsigned int getGranulePosition();
55  void setGranulePosition(long long unsigned int newVal);
56  long unsigned int getBitstreamSerialNumber();
57  void setBitstreamSerialNumber(long unsigned int newVal);
58  long unsigned int getCRCChecksum();
59  void setCRCChecksum(long unsigned int newVal);
60  long unsigned int getPageSequenceNumber();
61  void setPageSequenceNumber(long unsigned int newVal);
62  char getPageSegments();//get the amount of page segments
63  inline void setPageSegments(char newVal);//set the amount of page segments
64  int getPayloadSize();
65  const std::deque<std::string> & getAllSegments();
66 
67  bool possiblyContinued();
68 
69  std::string toPrettyString(size_t indent = 0);
70 
71  long unsigned int calcChecksum();
72  bool verifyChecksum();
73  unsigned int calcPayloadSize();
74  //void clear();
75  void clear(char HeaderType, long long unsigned int GranPos, long unsigned int BSN, long unsigned int PSN);
76  void prepareNext(bool continueMe = false);//prepare the page to become the next page
77  bool setPayload(char * newData, unsigned int length); //probably obsolete
78  unsigned int addSegment(const std::string & content); //add a segment to the page, returns added bytes
79  unsigned int addSegment(const char * content, unsigned int length); //add a segment to the page, returns added bytes
80  void sendTo(Socket::Connection & destination, int calcGranule = -2); //combines all data and sends it to socket
81  unsigned int setNextSegmentTableEntry(unsigned int entrySize);//returns the size that could not be added to the table
82  unsigned int overFlow();//returns the amount of bytes that don't fit in this page from the segments;
83 
84  long long unsigned int calculateGranule(oggSegment & currentSegment);
85  bool shouldSend();
86  void vorbisStuff();//process most recent segment
87  long long unsigned int totalFrames;
88  int granules;
90  std::deque<oggSegment> oggSegments; //used for ogg output
91  unsigned int pageSequenceNumber;
92 
93  unsigned int framesSeen;
94  unsigned int lastKeyFrame;
95  unsigned int firstSample;//for vorbis, to handle "when to send the page"
96  unsigned int sampleRate;//for vorbis, to handle the sampleRate
98  char blockSize[2];
99  std::deque<vorbis::mode> vorbisModes;//modes for vorbis
100  unsigned int split; //KFGShift for theora
101  private:
102  char data[282];//Fulldata
103  std::deque<std::string> segments;
104 
105 
106  };
107 
108  class oggTrack {
109  public:
110  oggTrack() : KFGShift(0), lastTime(0), parsedHeaders(false), lastPageOffset(0), nxtSegment(0){ }
112  std::string name;
113  std::string contBuffer;//buffer for continuing pages
114  long long unsigned int dtscID;
115  char KFGShift;
116  double lastTime;
117  long long unsigned int lastGran;
119  long long unsigned int lastPageOffset;
120  unsigned int nxtSegment;
121  double msPerFrame;
123  //Codec specific elements
124  //theora
125  // theora::header idHeader;//needed to determine keyframe //bullshit?
126  //vorbis
127  std::deque<vorbis::mode> vModes;
128  char channels;
129  long long unsigned int blockSize[2];
130  //unsigned long getBlockSize(unsigned int vModeIndex);
131  };
132 
133  class headerPages {
134  public:
135  std::map <long long unsigned int, unsigned int> DTSCID2OGGSerial;
136  std::map <long long unsigned int, unsigned int> DTSCID2seqNum;
137  std::string parsedPages;
138  };
139 }
140 
141 
long long unsigned int timeStamp
Definition: ogg.h:22
long long unsigned int lastGran
Definition: ogg.h:117
std::string contBuffer
Definition: ogg.h:113
oggCodec
Definition: ogg.h:25
HeaderType
Definition: ogg.h:27
char channels
Definition: ogg.h:128
long long unsigned int lastKeyFrameSeen
Definition: ogg.h:19
oggTrack()
Definition: ogg.h:110
bool parsedHeaders
Definition: ogg.h:118
char KFGShift
Definition: ogg.h:115
unsigned int nxtSegment
Definition: ogg.h:120
std::string name
Definition: ogg.h:112
std::deque< oggSegment > oggSegments
Definition: ogg.h:90
int prevBlockFlag
Definition: ogg.h:97
std::deque< unsigned int > decodeXiphSize(char *data, size_t len)
Definition: ogg.cpp:19
unsigned int pageSequenceNumber
Definition: ogg.h:91
Definition: ogg.h:14
unsigned int framesSeen
Definition: ogg.h:93
std::string parsedPages
Definition: ogg.h:137
std::deque< std::string > segments
Definition: ogg.h:103
double msPerFrame
Definition: ogg.h:121
long long unsigned int lastPageOffset
Definition: ogg.h:119
Page myPage
Definition: ogg.h:122
Definition: ogg.h:25
Definition: ogg.h:28
unsigned int split
Definition: ogg.h:100
Definition: ogg.h:25
Definition: ogg.h:31
oggSegment()
Definition: ogg.cpp:12
Definition: ogg.h:133
std::string dataString
Definition: ogg.h:17
Definition: ogg.h:25
int granules
Definition: ogg.h:88
Definition: ogg.h:108
Definition: ogg.cpp:10
Definition: ogg.h:39
unsigned int sampleRate
Definition: ogg.h:96
unsigned int firstSample
Definition: ogg.h:95
long long unsigned int totalFrames
Definition: ogg.h:87
Definition: ogg.h:29
long long unsigned int framesSinceKeyFrame
Definition: ogg.h:20
std::map< long long unsigned int, unsigned int > DTSCID2seqNum
Definition: ogg.h:136
long long unsigned int dtscID
Definition: ogg.h:114
unsigned int frameNumber
Definition: ogg.h:21
Definition: ogg.h:30
OGG::oggCodec codec
Definition: ogg.h:89
unsigned int lastKeyFrame
Definition: ogg.h:94
std::deque< vorbis::mode > vModes
Definition: ogg.h:127
std::deque< vorbis::mode > vorbisModes
Definition: ogg.h:99
double lastTime
Definition: ogg.h:116
This class is for easy communicating through sockets, either TCP or Unix.
Definition: socket.h:47
std::map< long long unsigned int, unsigned int > DTSCID2OGGSerial
Definition: ogg.h:135
Canvas prototype clear
Definition: jquery.flot.min.js:1
int isKeyframe
Definition: ogg.h:18
oggCodec codec
Definition: ogg.h:111