1 /*
2 * module.h --
3 *
4 * Various Module header for video codec
5 *
6 * Copyright (c) 1995-2002 The Regents of the University of California.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * A. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * B. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * C. Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
22 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * @(#) $Header: /usr/mash/src/repository/mash/mash-1/codec/module.h,v 1.24 2004/02/16 04:49:08 weitsang Exp $
34 */
35
36 #ifndef mash_module_h
37 #define mash_module_h
38
39 #include "tclcl.h"
40 #include "rtp/config.h"
41 #include "rtp/rtp.h"
42 #ifdef DMALLOC
43 #include "dmalloc.h"
44 #endif
45 #include "codec/module-list.h"
46
47 class RTP_BufferPool;
48 class pktbuf;
49
50 //----------------------------------------------------------------------
51 // Class:
52 // Buffer
53 // Description:
54 // This abstract class is one of the most basic class in Mash.
55 // It represents the data that flows from one module to another.
56 //----------------------------------------------------------------------
57
58 class Buffer {
59 public:
60 virtual Buffer* copy() = 0;
61 virtual void release();
62 };
63
64
65 //----------------------------------------------------------------------
66 // Class:
67 // AudioFrame
68 //
69 // Superclass:
70 // Buffer
71 //
72 // Description:
73 // Represents a buffer of audio samples.
74 //
75 // Members:
76 // ts_ -- timestamp of the samples.
77 // bp_ -- a pointer to the audio samples.
78 // len_ -- the length of this buffer.
79 //
80 // See Also:
81 // PCM_Encoder, ADPCMTranscoder, PCMTranscoder
82 //----------------------------------------------------------------------
83
84 struct AudioFrame : public Buffer {
85 public:
86 inline Buffer* copy() { return 0; }//currently not used
87 inline AudioFrame(u_int32_t ts, const u_int8_t* bp, int len) :
88 ts_(ts), bp_(bp), len_(len) {}
89 u_int32_t ts_;
90 const u_int8_t* bp_;
91 int len_;
92 };
93
94
95 //----------------------------------------------------------------------
96 // Class:
97 // VideoFrame
98 //
99 // Superclass:
100 // Buffer
101 //
102 // Description:
103 // Represents a buffer for a video frame.
104 //
105 // Members:
106 // ts_ -- timestamp of the frame.
107 // bp_ -- a pointer to the frame data.
108 // width_,height_ -- the width and height of this video frame.
109 // layer_ -- layer of this frame (for layered coding)
110 // csss_ -- color subsampling scheme of this frame (444, 422, 420, 411)
111 //----------------------------------------------------------------------
112
113 class VideoFrame : public Buffer {
114 public:
115 inline Buffer* copy() { return 0; }//currently not used
116 inline VideoFrame(u_int32_t ts, u_int8_t* bp, int w, int h,
117 int layer, int csss) :
118 ts_(ts), bp_(bp), width_(w), height_(h), layer_(layer),
119 csss_(csss) { }
120 u_int32_t ts_;
121 u_int8_t* bp_;
122 int width_;
123 int height_;
124 int layer_;
125 int csss_;
126 };
127
128
129 //----------------------------------------------------------------------
130 // Class:
131 // YuvFrame
132 //
133 // Superclass:
134 // VideoFrame
135 //
136 // Description:
137 // Represents a buffer for a video frame with conditional replenishment
138 // Vector.
139 //
140 // Members:
141 // crvec_ -- an array of conditional replenishment flags.
142 //----------------------------------------------------------------------
143
144 class YuvFrame : public VideoFrame {
145 public:
146 inline YuvFrame(u_int32_t ts, u_int8_t* bp, u_int8_t* crvec,
147 int w, int h, int csss, int layer = 0) :
148 VideoFrame(ts, bp, w, h, layer, csss), crvec_(crvec) {}
149 const u_int8_t* crvec_;
150
151 void write(char* filename);
152 void append(char* filename);
153 };
154
155
156 //----------------------------------------------------------------------
157 // Class:
158 // JpegFrame
159 //
160 // Superclass:
161 // VideoFrame
162 //
163 // Description:
164 // Represents a buffer for a JPEG-encoded video frame. Typically
165 // this frame comes from a hardware capture card.
166 //
167 // Members:
168 // len_ -- size of the frame in bytes.
169 // q_ -- quantization factor.
170 // type_ -- type of the frame (as defined in RTP JPEG header).
171 //----------------------------------------------------------------------
172
173 class JpegFrame : public VideoFrame {
174 public:
175 inline JpegFrame(u_int32_t ts, u_int8_t* bp, int len, int q, int type,
176 int w, int h, int csss) :
177 VideoFrame(ts, bp, w, h, 0, csss), len_(len), q_(q), type_(type) {}
178 int len_;
179 int q_;
180 int type_;
181 };
182
183
184 //----------------------------------------------------------------------
185 // Class:
186 // DCTFrame
187 //
188 // Superclass:
189 // VideoFrame
190 //
191 // Description:
192 // Represents a buffer for a DCT-encoded video frame. Typically
193 // for H26X family of codec.
194 //
195 // Members:
196 // q_ -- quantization factor.
197 // crvec_ -- conditional replenishment vector.
198 //----------------------------------------------------------------------
199
200 class DCTFrame : public VideoFrame {
201 public:
202 inline DCTFrame(u_int32_t ts, short* bp, u_int8_t* crv,
203 int w, int h, int csss, int q = -1) :
204 VideoFrame(ts, (u_int8_t*)bp, w, h, 0, csss), crvec_(crv), q_(q) {}
205
206 const u_int8_t *crvec_;
207 int q_; // original q (if applicable)
208 };
209
210
211 //----------------------------------------------------------------------
212 // Class:
213 // Module
214 //
215 // Superclass:
216 // TclObject
217 //
218 // Description:
219 // Module is one of the most basic class in OpenMash. It represents
220 // an object with multiple input ports and a single output port.
221 // Multiple modules can be linked together through a member called
222 // target_. Data is typically pushed into a Module, by calling
223 // recv(). The module processes the data, and pushes it down to
224 // target_ (by calling target_->recv(..)).
225 //
226 // The concept is similar to "filters" in DirectX and "objects" in
227 // Berkeley CMT.
228 //
229 // Members:
230 // q_ -- quantization factor.
231 // crvec_ -- conditional replenishment vector.
232 //----------------------------------------------------------------------
233
234 class ModuleList;
235 class Module : public TclObject {
236 public:
237 ~Module();
238 virtual void recv(Buffer*) = 0;
239 virtual void sched_exec (Buffer *buf) { recv(buf); }
240 int command(int argc, const char*const* argv);
241 inline Module* target() { return (target_); }
242 inline Module* next() { return next_; }
243 inline void next(Module *m) { next_ = m; }
244 protected:
245 Module();
246 Module* next_;
247 Module* target_;
248 ModuleList *target_list_;
249 };
250
251 //----------------------------------------------------------------------
252 // Class:
253 // SourceModule
254 //
255 // Superclass:
256 // Module
257 //
258 // Description:
259 // A SourceModule is a Module without input ports, i.e. no meaningful
260 // recv() calls.
261 //
262 //----------------------------------------------------------------------
263
264 class SourceModule : public Module {
265 public:
266 virtual void recv(Buffer*) {}
267 };
268
269
270 //----------------------------------------------------------------------
271 // Class:
272 // FrameModule
273 //
274 // Superclass:
275 // Module
276 //
277 // Description:
278 // A FrameModule is a Module that deals with frames. It keeps some
279 // states about previous frames that it processed. The states include
280 // width, and height and frame size.
281 //
282 // Members:
283 // width_ -- width of the frame in some unit (pixel, blocks..).
284 // height_ -- height of the frame in some unit (pixel, blocks..).
285 // framesize_ -- precomputed width_*height_.
286 //
287 //----------------------------------------------------------------------
288
289 class FrameModule : public Module {
290 protected:
291 FrameModule();
292 inline void size(int w, int h) {
293 width_ = w;
294 height_ = h;
295 framesize_ = w * h;
296 }
297 inline int samesize(const VideoFrame* vf) {
298 return (vf->width_ == width_ && vf->height_ == height_);
299 }
300 int width_;
301 int height_;
302 int framesize_;
303 };
304
305
306 //----------------------------------------------------------------------
307 // Class:
308 // PacketModule
309 //
310 // Superclass:
311 // Module
312 //
313 // Description:
314 // A PacketModule is a Module that deals with packets. The data
315 // passed into a PacketModule through recv() is of type pktbuf*.
316 //
317 // Important!!! Subclasses of PacketModule must call pb->release()
318 // on the pktbuf that is passed to recv() if it's a data packet or
319 // if they pass the packet to someone, that someone needs to make
320 // make sure pb->release is called.
321 //----------------------------------------------------------------------
322
323 class PacketModule : public Module {
324 public:
325 virtual void recv(Buffer* p) {
326 recv((pktbuf*)p);
327 }
328 virtual void recv(pktbuf* pb) = 0;
329 };
330
331
332 //----------------------------------------------------------------------
333 // Class:
334 // EncoderModule
335 //
336 // Superclass:
337 // FrameModule
338 //
339 // Description:
340 // An EncoderModule is the base class for writing an encoder. It keeps
341 // buffer pool for RTP packets to be sent, and some states about the
342 // encoding process (e.g. maximum transfer unit, number of bytes so far).
343 //
344 // Members:
345 // pool_ -- An RTP buffer pool.
346 // mtu_ -- Maximum transfer unit. This is needed to determine the size
347 // of the packet.
348 // nb_ -- Number of bytes encoded so far.
349 // dump_ -- An RTP dump filename for the transmitter (i.e. target_).
350 //----------------------------------------------------------------------
351
352 class EncoderModule : public FrameModule {
353 public:
354 virtual int command(int argc, const char*const* argv);
355 inline u_int32_t nb() const { return nb_; }
356 protected:
357 EncoderModule();
358 RTP_BufferPool* pool_;
359 int mtu_;
360 u_int32_t nb_;
361 int dumpfd_;
362 };
363
364
365 //----------------------------------------------------------------------
366 // Class:
367 // MultiInputManager
368 //
369 // Description:
370 // A pure abstract class that defines two methods for recving packets.
371 // recv_data() and recv_ctrl().
372 //
373 //----------------------------------------------------------------------
374
375 class MultiInputManager {
376 public:
377 virtual void recv_data(pktbuf*) = 0;
378 virtual void recv_ctrl(pktbuf*) = 0;
379 };
380
381
382 //----------------------------------------------------------------------
383 // Class:
384 // DataInputHandler
385 //
386 // Superclass:
387 // PacketModule
388 //
389 // Description:
390 // A DataInputHandler is a PacketModule that treats all packets received
391 // as DataPacket.
392 //
393 // See Also:
394 // ControlInputHandler
395 //----------------------------------------------------------------------
396
397 class DataInputHandler : public PacketModule {
398 public:
399 DataInputHandler() : manager_(0) {}
400 inline void manager(MultiInputManager* m) { manager_ = m; }
401 virtual void recv(pktbuf* pb) {
402 manager_->recv_data(pb);
403 }
404 protected:
405 MultiInputManager* manager_;
406 };
407
408
409 //----------------------------------------------------------------------
410 // Class:
411 // ControlInputHandler
412 //
413 // Superclass:
414 // DataInputHandler
415 //
416 // Description:
417 // A ControlInputHandler is a PacketModule that treats all packets
418 // received as control packet.
419 //
420 // See Also:
421 // DataInputHandler
422 //----------------------------------------------------------------------
423
424 class ControlInputHandler : public DataInputHandler {
425 public:
426 virtual void recv(pktbuf* pb) {
427 manager_->recv_ctrl(pb);
428 }
429 };
430
431 #endif
432
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.