KVIrc 5.2.6
Developer APIs
KviOggIrcText.h
Go to the documentation of this file.
1#ifndef KVI_OGGIRCT_H_
2#define KVI_OGGIRCT_H_
3//=============================================================================
4//
5// File : KviOggIrcText.h
6// Creation date : Sat Apr 8 2010 22:10:10 CEST by Fabio Bas
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2010 Fabio Bas (ctrlaltca at libero dot it)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
37namespace KviOggIrcText
38{
46 static void _tp_readbuffer(oggpack_buffer * opb, char * buf, const long len)
47 {
48 long i;
49
50 for(i = 0; i < len; i++)
51 *buf++ = oggpack_read(opb, 8);
52 }
53
61 static void _tp_writebuffer(oggpack_buffer * opb, const char * buf, const long len)
62 {
63 long i;
64
65 for(i = 0; i < len; i++)
66 oggpack_write(opb, *buf++, 8);
67 }
68
73 static int irct_encode_init()
74 {
75 return 0;
76 };
77
82 static int irct_encode_clear()
83 {
84 return 0;
85 };
86
92 static int irct_encode_headerout(ogg_packet * op)
93 {
94 oggpack_buffer ob;
95 oggpack_writeinit(&ob);
96 oggpack_write(&ob, 0, 8); //header init
97 _tp_writebuffer(&ob, "irct", 32);
98 oggpack_write(&ob, 0, 8); //version 0
99 oggpack_write(&ob, 1, 8); //subversion 1
100 int bytes = oggpack_bytes(&ob);
101 op->packet = (unsigned char *)KviMemory::allocate(bytes);
102 memcpy(op->packet, oggpack_get_buffer(&ob), bytes);
103 op->bytes = bytes;
104 oggpack_writeclear(&ob);
105 op->b_o_s = 1; //begins a logical bitstream
106 op->e_o_s = 0;
107 op->packetno = 0;
108 op->granulepos = 0;
109
110 return 0;
111 }
112
121 static int irct_encode_packetout(const char * textPkt, int textSize, int last_p, ogg_packet * op)
122 {
123 if(!textSize)
124 return (0);
125
126 oggpack_buffer ob;
127 oggpack_writeinit(&ob);
128
129 _tp_writebuffer(&ob, textPkt, textSize); //pre-encoded text
130 int bytes = oggpack_bytes(&ob);
131 op->packet = (unsigned char *)KviMemory::allocate(bytes);
132 memcpy(op->packet, oggpack_get_buffer(&ob), bytes);
133 op->bytes = bytes;
134 oggpack_writeclear(&ob);
135 op->b_o_s = 0;
136 op->e_o_s = last_p;
137
138 op->packetno = last_p;
139 op->granulepos = 0;
140
141 return 0;
142 }
143
149 static int irct_decode_headerin(ogg_packet * op)
150 {
151 oggpack_buffer ob;
152 oggpack_readinit(&ob, op->packet, op->bytes);
153 quint8 ret, version, subversion;
154 ret = oggpack_read(&ob, 8);
155 if(ret != 0)
156 return 1;
157 char * buf = (char *)KviMemory::allocate(4);
158 _tp_readbuffer(&ob, buf, 4);
159 if(strncmp(buf, "irct", 4) != 0)
160 return 1;
161 version = oggpack_read(&ob, 8);
162 subversion = oggpack_read(&ob, 8);
163 return 0;
164 }
165
173 static int irct_decode_packetin(char ** textPkt, int * textSize, ogg_packet * op)
174 {
175 oggpack_buffer ob;
176 oggpack_readinit(&ob, op->packet, op->bytes);
177 *textSize = op->bytes;
178 *textPkt = (char *)KviMemory::allocate(*textSize);
179 _tp_readbuffer(&ob, *textPkt, *textSize);
180 return 0;
181 }
182};
183
184#endif //KVI_OGGIRCT_H_
#define i
Definition detector.cpp:74
void * allocate(int size)
COMPILE_MEMORY_PROFILE.
Definition KviMemory.h:112
A namespace implementing our tricky codec to send and receive text multiplexed inside an ogg stream.
static void _tp_writebuffer(oggpack_buffer *opb, const char *buf, const long len)
Writes len bytes from buf to the bitpacking buffer opb.
Definition KviOggIrcText.h:61
static int irct_encode_headerout(ogg_packet *op)
Creates an irct header (used when encoding)
Definition KviOggIrcText.h:92
static int irct_encode_packetout(const char *textPkt, int textSize, int last_p, ogg_packet *op)
Creates an irct packet from some binary text (used when encoding)
Definition KviOggIrcText.h:121
static void _tp_readbuffer(oggpack_buffer *opb, char *buf, const long len)
Reads len bytes from the bitpacking buffer opb to buf.
Definition KviOggIrcText.h:46
static int irct_decode_packetin(char **textPkt, int *textSize, ogg_packet *op)
Extracts some bunary text from an irct packet (used when decoding)
Definition KviOggIrcText.h:173
static int irct_encode_clear()
Irct codec destructor function; this is where the codec state gets cleared (unused by now)
Definition KviOggIrcText.h:82
static int irct_decode_headerin(ogg_packet *op)
Decoded an irct header (used when decoding)
Definition KviOggIrcText.h:149
static int irct_encode_init()
Irct codec constructor function; this is where the codec state gets created (unused by now)
Definition KviOggIrcText.h:73