OSDN Git Service

WebGUIのレスポンスが悪かったのを修正
[peercast-im/PeerCastIM.git] / core / common / ogg.h
1 // ------------------------------------------------
2 // File : ogg.h
3 // Date: 28-may-2003
4 // Author: giles
5 //
6 // (c) 2002-3 peercast.org
7 // ------------------------------------------------
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 // ------------------------------------------------
18
19 #ifndef _OGG_H
20 #define _OGG_H
21
22
23 #include "channel.h"
24 // ----------------------------------------------
25 class OggPage;
26
27 // ----------------------------------
28 class OggPacket
29 {
30 public:
31         enum 
32         {
33                 MAX_BODYLEN = 65536,            // probably too small
34                 MAX_PACKETS = 256                       // prolly too small too, but realloc?!?!?!
35         };
36
37         void    addLacing(OggPage &);
38
39         int     bodyLen;
40         unsigned char body[MAX_BODYLEN];
41
42
43         int     numPackets;
44         unsigned int packetSizes[MAX_PACKETS];
45 };
46
47 // ----------------------------------------------
48 class OggSubStream
49 {
50 public:
51         OggSubStream()
52         :maxHeaders(0),serialNo(0),bitrate(0)
53         {}
54
55         bool needHeader()
56         {
57                 return maxHeaders && (pack.numPackets < maxHeaders);
58         }
59
60         void eos()
61         {
62                 maxHeaders=0;
63                 serialNo=0;
64         }
65
66         void bos(unsigned int ser)
67         {
68                 maxHeaders = 3;
69                 pack.numPackets=0;
70                 pack.packetSizes[0]=0;
71                 pack.bodyLen = 0;
72                 serialNo = ser;
73                 bitrate = 0;
74         }
75
76         bool    isActive() {return serialNo!=0;}
77
78         void readHeader(Channel *,OggPage &);
79
80         virtual void procHeaders(Channel *) = 0;
81
82         int     bitrate;
83
84         OggPacket       pack;
85         int     maxHeaders;
86         unsigned int serialNo;
87 };
88 // ----------------------------------------------
89 class OggVorbisSubStream : public OggSubStream
90 {
91 public:
92         OggVorbisSubStream()
93         :samplerate(0)
94         {}
95
96         virtual void procHeaders(Channel *);
97
98         void    readIdent(Stream &, ChanInfo &);
99         void    readSetup(Stream &);
100         void    readComment(Stream &, ChanInfo &);
101
102         double  getTime(OggPage &);
103
104         int samplerate;
105
106 };
107 // ----------------------------------------------
108 class OggTheoraSubStream : public OggSubStream
109 {
110 public:
111         OggTheoraSubStream() : granposShift(0), frameTime(0) {}
112
113         virtual void procHeaders(Channel *);
114
115         void readInfo(Stream &, ChanInfo &);
116
117         double  getTime(OggPage &);
118
119         int granposShift;
120         double frameTime;
121 };
122
123 // ----------------------------------------------
124 class OGGStream : public ChannelStream
125 {
126 public:
127         OGGStream()
128         {}
129
130
131         virtual void readHeader(Stream &,Channel *);
132         virtual int readPacket(Stream &,Channel *);
133         virtual void readEnd(Stream &,Channel *);
134
135
136         void    readHeaders(Stream &,Channel *, OggPage &);
137
138         OggVorbisSubStream      vorbis;
139         OggTheoraSubStream      theora; 
140 };
141
142 // ----------------------------------
143 class OggPage
144 {
145 public:
146         enum 
147         {
148                 MAX_BODYLEN = 65536,
149                 MAX_HEADERLEN = 27+256
150         };
151
152         void    read(Stream &);
153         bool    isBOS();
154         bool    isEOS();
155         bool    isNewPacket();
156         bool    isHeader();
157         unsigned int getSerialNo();
158
159         bool    detectVorbis();
160         bool    detectTheora();
161
162
163         int64_t granPos;
164         int headLen,bodyLen;
165         unsigned char data[MAX_HEADERLEN+MAX_BODYLEN];
166 };
167
168
169 #endif