• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef __GST_MPEG4UTIL_H__
22 #define __GST_MPEG4UTIL_H__
23 
24 #include <gst/gst.h>
25 #include <gst/base/gstbitreader.h>
26 
27 #define CHECK_ALLOWED(val, min, max) { \
28   if (val < min || val > max) { \
29     GST_WARNING ("value not in allowed range. value: %d, range %d-%d", \
30                      val, min, max); \
31     goto error; \
32   } \
33 }
34 
35 #define READ_UINT8(reader, val, nbits) { \
36   if (!gst_bit_reader_get_bits_uint8 (reader, &val, nbits)) { \
37     GST_WARNING ("failed to read uint8, nbits: %d", nbits); \
38     goto error; \
39   } \
40 }
41 
42 #define READ_UINT16(reader, val, nbits) { \
43   if (!gst_bit_reader_get_bits_uint16 (reader, &val, nbits)) { \
44     GST_WARNING ("failed to read uint16, nbits: %d", nbits); \
45     goto error; \
46   } \
47 }
48 
49 #define READ_UINT32(reader, val, nbits) { \
50   if (!gst_bit_reader_get_bits_uint32 (reader, &val, nbits)) { \
51     GST_WARNING ("failed to read uint32, nbits: %d", nbits); \
52     goto error; \
53   } \
54 }
55 
56 #define READ_UINT64(reader, val, nbits) { \
57   if (!gst_bit_reader_get_bits_uint64 (reader, &val, nbits)) { \
58     GST_WARNING ("failed to read uint64, nbits: %d", nbits); \
59     goto error; \
60   } \
61 }
62 
63 #define SKIP(reader, nbits) { \
64   if (!gst_bit_reader_skip (reader, nbits)) { \
65     GST_WARNING ("failed to skip nbits: %d", nbits); \
66     goto error; \
67   } \
68 }
69 
70 typedef struct _Mpeg4VisualObjectSequence Mpeg4VisualObjectSequence;
71 typedef struct _Mpeg4VisualObject Mpeg4VisualObject;
72 typedef struct _Mpeg4VideoObjectLayer Mpeg4VideoObjectLayer;
73 typedef struct _Mpeg4GroupofVideoObjectPlane Mpeg4GroupofVideoObjectPlane;
74 typedef struct _Mpeg4VideoObjectPlane Mpeg4VideoObjectPlane;
75 
76 #define MPEG4_PACKET_VOL_MIN 0x20
77 #define MPEG4_PACKET_VOL_MAX 0x2f
78 
79 #define MPEG4_PACKET_VOS     0xb0
80 #define MPEG4_PACKET_EVOS    0xb1
81 #define MPEG4_PACKET_GOV     0xb3
82 #define MPEG4_PACKET_VO      0xb5
83 #define MPEG4_PACKET_VOP     0xb6
84 
85 #define I_VOP 0x0
86 #define P_VOP 0x1
87 #define B_VOP 0x2
88 #define S_VOP 0x3
89 
90 struct _Mpeg4VisualObjectSequence {
91   guint8 profile_and_level_indication;
92 };
93 
94 struct _Mpeg4VisualObject {
95   guint8 verid;
96   guint8 priority;
97   guint8 type;
98 };
99 
100 struct _Mpeg4VideoObjectLayer {
101   guint8 random_accesible_vol;
102   guint8 video_object_type_indication;
103 
104   guint8 is_object_layer_identifier;
105   /* if is_object_layer_identifier */
106   guint8 verid;
107   guint8 priority;
108 
109   guint8 par_n;
110   guint8 par_d;
111 
112   guint8 chroma_format;
113   guint8 low_delay;
114   guint8 vbv_parameters;
115   /* if vbv_parameters */
116   guint32 bit_rate;
117   guint32 vbv_buffer_size;
118 
119   guint8 shape;
120 
121   guint16 vop_time_increment_resolution;
122   guint8 vop_time_increment_bits;
123   guint8 fixed_vop_rate;
124   /* if fixed_vop_rate */
125   guint16 fixed_vop_time_increment;
126 
127   guint16 width;
128   guint16 height;
129   guint8 interlaced;
130   guint8 obmc_disable;
131 
132   guint8 sprite_enable;
133 
134   guint8 quant_precision;
135   guint8 bits_per_pixel;
136 
137   guint8 quant_type;
138   guint8 intra_quant_mat[64];
139   guint8 non_intra_quant_mat[64];
140 
141   guint8 quarter_sample;
142   guint8 complexity_estimation_disable;
143   guint8 resync_marker_disable;
144 };
145 
146 struct _Mpeg4GroupofVideoObjectPlane {
147   guint8 hours;
148   guint8 minutes;
149   guint8 seconds;
150 
151   guint8 closed;
152   guint8 broken_link;
153 };
154 
155 struct _Mpeg4VideoObjectPlane {
156   guint8 coding_type;
157   guint8 modulo_time_base;
158   guint16 time_increment;
159 
160   guint8 coded;
161   guint8 rounding_type;
162   guint8 intra_dc_vlc_thr;
163 
164   guint8 top_field_first;
165   guint8 alternate_vertical_scan_flag;
166 
167   guint16 quant;
168 
169   guint8 fcode_forward;
170   guint8 fcode_backward;
171 };
172 
173 gboolean mpeg4_util_parse_VOP (GstBuffer *buf, Mpeg4VideoObjectLayer *vol, Mpeg4VideoObjectPlane *vop);
174 gboolean mpeg4_util_parse_GOV (GstBuffer *buf, Mpeg4GroupofVideoObjectPlane *gov);
175 gboolean mpeg4_util_parse_VOL (GstBuffer *buf, Mpeg4VisualObject *vo, Mpeg4VideoObjectLayer *vol);
176 gboolean mpeg4_util_parse_VO (GstBuffer *buf, Mpeg4VisualObject *vo);
177 gboolean mpeg4_util_parse_VOS (GstBuffer *buf, Mpeg4VisualObjectSequence *vos);
178 
179 #endif /* __GST_MPEG4UTIL_H__ */