rtpvp8: port some more to new memory API
[platform/upstream/gstreamer.git] / gst / rtp / gstrtph263pay.h
1 /* GStreamer
2  * Copyright (C) <2005> Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  *
19  * Author: Dejan Sakelsak sahel@kiberpipa.org
20  */
21
22 #ifndef __GST_RTP_H263_PAY_H__
23 #define __GST_RTP_H263_PAY_H__
24
25 #include <gst/gst.h>
26 #include <gst/rtp/gstrtpbasepayload.h>
27 #include <gst/base/gstadapter.h>
28
29 G_BEGIN_DECLS
30 #define GST_TYPE_RTP_H263_PAY \
31   (gst_rtp_h263_pay_get_type())
32 #define GST_RTP_H263_PAY(obj) \
33  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_H263_PAY,GstRtpH263Pay))
34 #define GST_RTP_H263_PAY_CLASS(klass) \
35  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_H263_PAY,GstRtpH263PayClass))
36 #define GST_IS_RTP_H263_PAY(obj) \
37   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_H263_PAY))
38 #define GST_IS_RTP_H263_PAY_CLASS(klass) \
39   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_H263_PAY))
40 // blocks per macroblock
41 #define N_BLOCKS 6
42 #define DEFAULT_MODE_A FALSE
43 #define MTU_SECURITY_OFFSET 50
44     typedef enum _GstRtpH263PayHeaderMode
45 {
46   GST_RTP_H263_PAYLOAD_HEADER_MODE_A = 4,
47   GST_RTP_H263_PAYLOAD_HEADER_MODE_B = 8,
48   GST_RTP_H263_PAYLOAD_HEADER_MODE_C = 12
49 } GstRtpH263PayHeaderMode;
50
51 typedef struct _GstRtpH263PayContext GstRtpH263PayContext;
52 typedef struct _GstRtpH263PayPic GstRtpH263PayPic;
53 typedef struct _GstRtpH263PayClass GstRtpH263PayClass;
54 typedef struct _GstRtpH263Pay GstRtpH263Pay;
55 typedef struct _GstRtpH263PayBoundry GstRtpH263PayBoundry;
56 typedef struct _GstRtpH263PayMB GstRtpH263PayMB;
57 typedef struct _GstRtpH263PayGob GstRtpH263PayGob;
58 typedef struct _GstRtpH263PayPackage GstRtpH263PayPackage;
59
60 //typedef enum _GstRtpH263PayHeaderMode GstRtpH263PayHeaderMode;
61
62 struct _GstRtpH263Pay
63 {
64   GstRTPBasePayload payload;
65
66   GstAdapter *adapter;
67   GstClockTime first_ts;
68   gboolean prop_payload_mode;
69   guint8 *data;
70   guint available_data;
71
72 };
73
74 struct _GstRtpH263PayContext
75 {
76   GstRtpH263PayPic *piclayer;
77
78   guint mtu;
79   guint window;
80   guint8 *win_end;
81   guint8 cpm;
82
83   guint no_gobs;
84   GstRtpH263PayGob **gobs;
85
86 };
87
88 struct _GstRtpH263PayClass
89 {
90   GstRTPBasePayloadClass parent_class;
91 };
92
93 typedef struct _GstRtpH263PayAHeader
94 {
95 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
96   unsigned int ebit:3;          /* End position */
97   unsigned int sbit:3;          /* Start position */
98   unsigned int p:1;             /* PB-frames mode */
99   unsigned int f:1;             /* flag bit */
100
101   unsigned int r1:1;            /* Reserved */
102   unsigned int a:1;             /* Advanced Prediction */
103   unsigned int s:1;             /* syntax based arithmetic coding */
104   unsigned int u:1;             /* Unrestricted motion vector */
105   unsigned int i:1;             /* Picture coding type */
106   unsigned int src:3;           /* Source format */
107
108   unsigned int trb:3;           /* Temporal ref for B frame */
109   unsigned int dbq:2;           /* Differential Quantisation parameter */
110   unsigned int r2:3;            /* Reserved */
111 #elif G_BYTE_ORDER == G_BIG_ENDIAN
112   unsigned int f:1;             /* flag bit */
113   unsigned int p:1;             /* PB-frames mode */
114   unsigned int sbit:3;          /* Start position */
115   unsigned int ebit:3;          /* End position */
116
117   unsigned int src:3;           /* Source format */
118   unsigned int i:1;             /* Picture coding type */
119   unsigned int u:1;             /* Unrestricted motion vector */
120   unsigned int s:1;             /* syntax based arithmetic coding */
121   unsigned int a:1;             /* Advanced Prediction */
122   unsigned int r1:1;            /* Reserved */
123
124   unsigned int r2:3;            /* Reserved */
125   unsigned int dbq:2;           /* Differential Quantisation parameter */
126   unsigned int trb:3;           /* Temporal ref for B frame */
127 #else
128 #error "G_BYTE_ORDER should be big or little endian."
129 #endif
130   unsigned int tr:8;            /* Temporal ref for P frame */
131 } GstRtpH263PayAHeader;
132
133 typedef struct _GstRtpH263PayBHeader
134 {
135 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
136   unsigned int ebit:3;          /* End position */
137   unsigned int sbit:3;          /* Start position */
138   unsigned int p:1;             /* PB-frames mode */
139   unsigned int f:1;             /* flag bit */
140
141   unsigned int quant:5;         /* Quantization value for first MB */
142   unsigned int src:3;           /* Source format */
143
144   unsigned int mba1:3;          /* Address of first MB starting count from 0 - part1 */
145   unsigned int gobn:5;          /* GOB number in effect at start of packet */
146
147   unsigned int r:2;             /* Reserved */
148   unsigned int mba2:6;          /* Address of first MB starting count from 0 - part2 */
149
150   unsigned int hmv11:4;         /* horizontal motion vector predictor for MB 1 - part 1 */
151   unsigned int a:1;             /* Advanced Prediction */
152   unsigned int s:1;             /* syntax based arithmetic coding */
153   unsigned int u:1;             /* Unrestricted motion vector */
154   unsigned int i:1;             /* Picture coding type */
155
156   unsigned int vmv11:5;         /* vertical motion vector predictor for MB 1 - part 1 */
157   unsigned int hmv12:3;         /* horizontal motion vector predictor for MB 1 - part 2 */
158
159   unsigned int hmv21:6;         /* horizontal motion vector predictor for MB 3 - part 1 */
160   unsigned int vmv12:2;         /* vertical motion vector predictor for MB 1 - part 2 */
161
162   unsigned int vmv21:7;         /* vertical motion vector predictor for MB 3 */
163   unsigned int hmv22:1;         /* horizontal motion vector predictor for MB 3 - part 2 */
164
165 #elif G_BYTE_ORDER == G_BIG_ENDIAN
166   unsigned int f:1;             /* flag bit */
167   unsigned int p:1;             /* PB-frames mode */
168   unsigned int sbit:3;          /* Start position */
169   unsigned int ebit:3;          /* End position */
170
171   unsigned int src:3;           /* Source format */
172   unsigned int quant:5;         /* Quantization value for first MB */
173
174   unsigned int gobn:5;          /* GOB number in effect at start of packet */
175   unsigned int mba1:3;          /* Address of first MB starting count from 0 - part1 */
176
177   unsigned int mba2:6;          /* Address of first MB starting count from 0 - part2 */
178   unsigned int r:2;             /* Reserved */
179
180   unsigned int i:1;             /* Picture coding type */
181   unsigned int u:1;             /* Unrestricted motion vector */
182   unsigned int s:1;             /* syntax based arithmetic coding */
183   unsigned int a:1;             /* Advanced Prediction */
184   unsigned int hmv11:4;         /* horizontal motion vector predictor for MB 1 - part 1 */
185
186   unsigned int hmv12:3;         /* horizontal motion vector predictor for MB 1 - part 2 */
187   unsigned int vmv11:5;         /* vertical motion vector predictor for MB 1 - part 1 */
188
189   unsigned int vmv12:2;         /* vertical motion vector predictor for MB 1 - part 2 */
190   unsigned int hmv21:6;         /* horizontal motion vector predictor for MB 3 - part 1 */
191
192   unsigned int hmv22:1;         /* horizontal motion vector predictor for MB 3 - part 2 */
193   unsigned int vmv21:7;          /* vertical motion vector predictor for MB 3 */
194 #else
195 #error "G_BYTE_ORDER should be big or little endian."
196 #endif
197 } GstRtpH263PayBHeader;
198
199 typedef struct _GstRtpH263PayCHeader
200 {
201 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
202   unsigned int ebit:3;          /* End position */
203   unsigned int sbit:3;          /* Start position */
204   unsigned int p:1;             /* PB-frames mode */
205   unsigned int f:1;             /* flag bit */
206
207   unsigned int quant:5;         /* Quantization value for first MB */
208   unsigned int src:3;           /* Source format */
209
210   unsigned int mba1:3;          /* Address of first MB starting count from 0 - part1 */
211   unsigned int gobn:5;          /* GOB number in effect at start of packet */
212
213   unsigned int r:2;             /* Reserved */
214   unsigned int mba2:6;          /* Address of first MB starting count from 0 - part2 */
215
216   unsigned int hmv11:4;         /* horizontal motion vector predictor for MB 1 - part 1 */
217   unsigned int a:1;             /* Advanced Prediction */
218   unsigned int s:1;             /* syntax based arithmetic coding */
219   unsigned int u:1;             /* Unrestricted motion vector */
220   unsigned int i:1;             /* Picture coding type */
221
222   unsigned int vmv11:5;         /* vertical motion vector predictor for MB 1 - part 1 */
223   unsigned int hmv12:3;         /* horizontal motion vector predictor for MB 1 - part 2 */
224
225   unsigned int hmv21:6;         /* horizontal motion vector predictor for MB 3 - part 1 */
226   unsigned int vmv12:2;         /* vertical motion vector predictor for MB 1 - part 2 */
227
228   unsigned int vmv21:7;         /* vertical motion vector predictor for MB 3 */
229   unsigned int hmv22:1;         /* horizontal motion vector predictor for MB 3 - part 2 */
230
231   unsigned int rr1:8;           /* reserved */
232
233   unsigned int rr2:8;           /* reserved */
234
235   unsigned int trb:3;           /* Temporal Reference for the B */
236   unsigned int dbq:2;           /* Differential quantization parameter */
237   unsigned int rr3:3;           /* reserved */
238
239   unsigned int tr:8;            /* Temporal Reference for the P frame */
240
241 #elif G_BYTE_ORDER == G_BIG_ENDIAN
242   unsigned int f:1;             /* flag bit */
243   unsigned int p:1;             /* PB-frames mode */
244   unsigned int sbit:3;          /* Start position */
245   unsigned int ebit:3;          /* End position */
246
247   unsigned int src:3;           /* Source format */
248   unsigned int quant:5;         /* Quantization value for first MB */
249
250   unsigned int gobn:5;          /* GOB number in effect at start of packet */
251   unsigned int mba1:3;          /* Address of first MB starting count from 0 - part1 */
252
253   unsigned int mba2:6;          /* Address of first MB starting count from 0 - part2 */
254   unsigned int r:2;             /* Reserved */
255
256   unsigned int i:1;             /* Picture coding type */
257   unsigned int u:1;             /* Unrestricted motion vector */
258   unsigned int s:1;             /* syntax based arithmetic coding */
259   unsigned int a:1;             /* Advanced Prediction */
260   unsigned int hmv11:4;         /* horizontal motion vector predictor for MB 1 - part 1 */
261
262   unsigned int hmv12:3;         /* horizontal motion vector predictor for MB 1 - part 2 */
263   unsigned int vmv11:5;         /* vertical motion vector predictor for MB 1 - part 1 */
264
265   unsigned int vmv12:2;         /* vertical motion vector predictor for MB 1 - part 2 */
266   unsigned int hmv21:6;         /* horizontal motion vector predictor for MB 3 - part 1 */
267
268   unsigned int hmv22:1;         /* horizontal motion vector predictor for MB 3 - part 2 */
269   unsigned int vmv21:7;          /* vertical motion vector predictor for MB 3 */
270   unsigned int rr1:8;           /* reserved */
271   unsigned int rr2:8;           /* reserved */
272
273   unsigned int rr3:3;           /* reserved */
274   unsigned int dbq:2;           /* Differential quantization parameter */
275   unsigned int trb:3;           /* Temporal Reference for the B */
276
277   unsigned int tr:8;            /* Temporal Reference for the P frame */
278 #else
279 #error "G_BYTE_ORDER should be big or little endian."
280 #endif
281 } GstRtpH263PayCHeader;
282
283 struct _GstRtpH263PayPic
284 {
285 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
286   unsigned int psc1:16;
287
288   unsigned int tr1:2;
289   unsigned int psc2:6;
290
291   unsigned int ptype_263:1;
292   unsigned int ptype_start:1;
293   unsigned int tr2:6;
294
295   unsigned int ptype_umvmode:1;
296   unsigned int ptype_pictype:1;
297   unsigned int ptype_srcformat:3;
298   unsigned int ptype_freeze:1;
299   unsigned int ptype_camera:1;
300   unsigned int ptype_split:1;
301
302   unsigned int pquant:5;
303   unsigned int ptype_pbmode:1;
304   unsigned int ptype_apmode:1;
305   unsigned int ptype_sacmode:1;
306
307 #elif G_BYTE_ORDER == G_BIG_ENDIAN
308   unsigned int psc1:16;
309
310   unsigned int psc2:6;
311   unsigned int tr1:2;
312
313   unsigned int tr2:6;
314   unsigned int ptype_start:2;
315
316   unsigned int ptype_split:1;
317   unsigned int ptype_camera:1;
318   unsigned int ptype_freeze:1;
319   unsigned int ptype_srcformat:3;
320   unsigned int ptype_pictype:1;
321   unsigned int ptype_umvmode:1;
322
323   unsigned int ptype_sacmode:1;
324   unsigned int ptype_apmode:1;
325   unsigned int ptype_pbmode:1;
326   unsigned int pquant:5;
327
328 #else
329 #error "G_BYTE_ORDER should be big or little endian."
330 #endif
331 };
332
333 struct _GstRtpH263PayBoundry
334 {
335
336   guint8 *start;
337   guint8 *end;
338   guint8 sbit;
339   guint8 ebit;
340
341 };
342
343 struct _GstRtpH263PayMB
344 {
345   guint8 *start;
346   guint8 *end;
347   guint8 sbit;
348   guint8 ebit;
349   guint length;
350
351   guint8 mb_type;
352   guint quant;
353
354   guint mba;
355   guint8 mvd[10];
356 };
357
358 struct _GstRtpH263PayGob
359 {
360   guint8 *start;
361   guint8 *end;
362   guint length;
363   guint8 sbit;
364   guint8 ebit;
365
366   guint gobn;
367   guint quant;
368
369   GstRtpH263PayMB **macroblocks;
370   guint nmacroblocs;
371 };
372
373 struct _GstRtpH263PayPackage
374 {
375   guint8 *payload_start;
376   guint8 *payload_end;
377   guint payload_len;
378   guint8 sbit;
379   guint8 ebit;
380   GstBuffer *outbuf;
381   gboolean marker;
382
383   GstRtpH263PayHeaderMode mode;
384
385   /*
386    *  mode B,C data
387    */
388
389   guint16 mba;
390   guint nmvd;
391   guint8 mvd[10];
392   guint gobn;
393   guint quant;
394 };
395
396 #define GST_H263_PICTURELAYER_PLSRC(buf) (((GstRtpH263PayPic *)(buf))->ptype_srcformat)
397 #define GST_H263_PICTURELAYER_PLTYPE(buf) (((GstRtpH263PayPic *)(buf))->ptype_pictype)
398 #define GST_H263_PICTURELAYER_PLUMV(buf) (((GstRtpH263PayPic *)(buf))->ptype_umvmode)
399 #define GST_H263_PICTURELAYER_PLSAC(buf) (((GstRtpH263PayPic *)(buf))->ptype_sacmode)
400 #define GST_H263_PICTURELAYER_PLAP(buf) (((GstRtpH263PayPic *)(buf))->ptype_apmode)
401
402 /*
403  * TODO: PB frame relevant tables
404  */
405
406 #define GST_RTP_H263_PAY_END(start, len) (((guint8 *)start) + ((guint)len))
407 #define GST_RTP_H263_PAY_GOBN(gob) (((((guint8 *) gob)[2] >> 2) & 0x1f)
408
409 GType gst_rtp_h263_pay_get_type (void);
410
411 gboolean gst_rtp_h263_pay_plugin_init (GstPlugin * plugin);
412
413 G_END_DECLS
414 #endif /* __GST_RTP_H263_PAY_H__ */