docs: trim sections file more
[platform/upstream/gst-plugins-good.git] / gst / deinterlace / gstdeinterlace.h
1 /*
2  * GStreamer
3  * Copyright (C) 2005 Martin Eikermann <meiker@upb.de>
4  * Copyright (C) 2008-2009 Sebastian Dröge <slomo@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef __GST_DEINTERLACE_H__
23 #define __GST_DEINTERLACE_H__
24
25 #include <gst/gst.h>
26 #include <gst/video/video.h>
27 #include <liboil/liboil.h>
28 #include <liboil/liboilcpu.h>
29 #include <liboil/liboilfunction.h>
30
31 #ifdef HAVE_GCC_ASM
32 #if defined(HAVE_CPU_I386) || defined(HAVE_CPU_X86_64)
33 #define BUILD_X86_ASM
34 #endif
35 #endif
36
37 G_BEGIN_DECLS
38
39 #define GST_TYPE_DEINTERLACE \
40   (gst_deinterlace_get_type())
41 #define GST_DEINTERLACE(obj) \
42   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DEINTERLACE,GstDeinterlace))
43 #define GST_DEINTERLACE_CLASS(klass) \
44   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DEINTERLACE,GstDeinterlace))
45 #define GST_IS_DEINTERLACE(obj) \
46   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DEINTERLACE))
47 #define GST_IS_DEINTERLACE_CLASS(obj) \
48   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DEINTERLACE))
49
50 typedef struct _GstDeinterlace GstDeinterlace;
51 typedef struct _GstDeinterlaceClass GstDeinterlaceClass;
52
53 #define GST_TYPE_DEINTERLACE_METHOD             (gst_deinterlace_method_get_type ())
54 #define GST_IS_DEINTERLACE_METHOD(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DEINTERLACE_METHOD))
55 #define GST_IS_DEINTERLACE_METHOD_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DEINTERLACE_METHOD))
56 #define GST_DEINTERLACE_METHOD_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DEINTERLACE_METHOD, GstDeinterlaceMethodClass))
57 #define GST_DEINTERLACE_METHOD(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DEINTERLACE_METHOD, GstDeinterlaceMethod))
58 #define GST_DEINTERLACE_METHOD_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEINTERLACE_METHOD, GstDeinterlaceMethodClass))
59 #define GST_DEINTERLACE_METHOD_CAST(obj)        ((GstDeinterlaceMethod*)(obj))
60
61 typedef struct _GstDeinterlaceMethod GstDeinterlaceMethod;
62 typedef struct _GstDeinterlaceMethodClass GstDeinterlaceMethodClass;
63
64 /*
65  * This structure defines the deinterlacer plugin.
66  */
67
68 struct _GstDeinterlaceMethod {
69   GstObject parent;
70 };
71
72 struct _GstDeinterlaceMethodClass {
73   GstObjectClass parent_class;
74   guint fields_required;
75   guint latency;
76
77   void (*deinterlace_frame) (GstDeinterlaceMethod *self, GstDeinterlace * parent, GstBuffer *outbuf);
78
79   const gchar *name;
80   const gchar *nick;
81 };
82
83 GType gst_deinterlace_method_get_type (void);
84
85 #define GST_TYPE_DEINTERLACE_SIMPLE_METHOD              (gst_deinterlace_simple_method_get_type ())
86 #define GST_IS_DEINTERLACE_SIMPLE_METHOD(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DEINTERLACE_SIMPLE_METHOD))
87 #define GST_IS_DEINTERLACE_SIMPLE_METHOD_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DEINTERLACE_SIMPLE_METHOD))
88 #define GST_DEINTERLACE_SIMPLE_METHOD_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DEINTERLACE_SIMPLE_METHOD, GstDeinterlaceSimpleMethodClass))
89 #define GST_DEINTERLACE_SIMPLE_METHOD(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DEINTERLACE_SIMPLE_METHOD, GstDeinterlaceSimpleMethod))
90 #define GST_DEINTERLACE_SIMPLE_METHOD_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEINTERLACE_SIMPLE_METHOD, GstDeinterlaceSimpleMethodClass))
91 #define GST_DEINTERLACE_SIMPLE_METHOD_CAST(obj) ((GstDeinterlaceSimpleMethod*)(obj))
92
93 typedef struct _GstDeinterlaceSimpleMethod GstDeinterlaceSimpleMethod;
94 typedef struct _GstDeinterlaceSimpleMethodClass GstDeinterlaceSimpleMethodClass;
95 typedef struct _GstDeinterlaceScanlineData GstDeinterlaceScanlineData;
96
97 /*
98  * This structure defines the simple deinterlacer plugin.
99  */
100
101 struct _GstDeinterlaceScanlineData {
102  guint8 *tt0, *t0, *m0, *b0, *bb0;
103  guint8 *tt1, *t1, *m1, *b1, *bb1;
104  guint8 *tt2, *t2, *m2, *b2, *bb2;
105  guint8 *tt3, *t3, *m3, *b3, *bb3;
106  gboolean bottom_field;
107 };
108
109 /**
110  * For interpolate_scanline the input is:
111  *
112  * |   t-3       t-2       t-1       t
113  * | Field 3 | Field 2 | Field 1 | Field 0 |
114  * |  TT3    |         |   TT1   |         |
115  * |         |   T2    |         |   T0    |
116  * |   M3    |         |    M1   |         |
117  * |         |   B2    |         |   B0    |
118  * |  BB3    |         |   BB1   |         |
119  *
120  * For copy_scanline the input is:
121  *
122  * |   t-3       t-2       t-1       t
123  * | Field 3 | Field 2 | Field 1 | Field 0 |
124  * |         |   TT2   |         |  TT0    |
125  * |   T3    |         |   T1    |         |
126  * |         |    M2   |         |   M0    |
127  * |   B3    |         |   B1    |         |
128  * |         |   BB2   |         |  BB0    |
129  *
130  * All other values are NULL.
131  */
132
133 struct _GstDeinterlaceSimpleMethod {
134   GstDeinterlaceMethod parent;
135 };
136
137 struct _GstDeinterlaceSimpleMethodClass {
138   GstDeinterlaceMethodClass parent_class;
139
140   void (*interpolate_scanline) (GstDeinterlaceMethod *self, GstDeinterlace * parent, guint8 *out, GstDeinterlaceScanlineData *scanlines, gint width);
141   void (*copy_scanline) (GstDeinterlaceMethod *self, GstDeinterlace * parent, guint8 *out, GstDeinterlaceScanlineData *scanlines, gint width);
142 };
143
144 GType gst_deinterlace_simple_method_get_type (void);
145
146
147 #define GST_DEINTERLACE_MAX_FIELD_HISTORY 10
148
149 #define PICTURE_PROGRESSIVE 0
150 #define PICTURE_INTERLACED_BOTTOM 1
151 #define PICTURE_INTERLACED_TOP 2
152 #define PICTURE_INTERLACED_MASK (PICTURE_INTERLACED_BOTTOM | PICTURE_INTERLACED_TOP)
153
154 typedef struct
155 {
156   /* pointer to the start of data for this field */
157   GstBuffer *buf;
158   /* see PICTURE_ flags in *.c */
159   guint flags;
160 } GstPicture;
161
162 typedef enum
163 {
164   GST_DEINTERLACE_TOMSMOCOMP,
165   GST_DEINTERLACE_GREEDY_H,
166   GST_DEINTERLACE_GREEDY_L,
167   GST_DEINTERLACE_VFIR,
168   GST_DEINTERLACE_LINEAR,
169   GST_DEINTERLACE_LINEAR_BLEND,
170   GST_DEINTERLACE_SCALER_BOB,
171   GST_DEINTERLACE_WEAVE,
172   GST_DEINTERLACE_WEAVE_TFF,
173   GST_DEINTERLACE_WEAVE_BFF
174 } GstDeinterlaceMethods;
175
176 typedef enum
177 {
178   GST_DEINTERLACE_ALL,         /* All (missing data is interp.) */
179   GST_DEINTERLACE_TF,          /* Top Fields Only */
180   GST_DEINTERLACE_BF           /* Bottom Fields Only */
181 } GstDeinterlaceFields;
182
183 typedef enum
184 {
185   GST_DEINTERLACE_LAYOUT_AUTO,
186   GST_DEINTERLACE_LAYOUT_TFF,
187   GST_DEINTERLACE_LAYOUT_BFF
188 } GstDeinterlaceFieldLayout;
189
190 typedef enum {
191   GST_DEINTERLACE_MODE_AUTO,
192   GST_DEINTERLACE_MODE_INTERLACED,
193   GST_DEINTERLACE_MODE_DISABLED
194 } GstDeinterlaceMode;
195
196 struct _GstDeinterlace
197 {
198   GstElement parent;
199
200   GstPad *srcpad, *sinkpad;
201
202   /* <private> */
203
204   GstDeinterlaceMode mode;
205
206   GstDeinterlaceFieldLayout field_layout;
207
208   GstDeinterlaceFields fields;
209
210   GstDeinterlaceMethods method_id;
211   GstDeinterlaceMethod *method;
212
213   guint frame_size;
214   gint frame_rate_n, frame_rate_d;
215   gboolean interlaced;
216
217   /* Number of bytes of actual data in each scanline.  May be less than
218      OverlayPitch since the overlay's scanlines might have alignment
219      requirements.  Generally equal to FrameWidth * 2.
220    */
221   guint row_stride;
222
223   /* Number of pixels in each scanline. */
224   gint frame_width;
225
226   /* Number of scanlines per frame. */
227   gint frame_height;
228
229   /* Number of scanlines per field.  FrameHeight / 2, mostly for
230      cleanliness so we don't have to keep dividing FrameHeight by 2.
231    */
232   gint field_height;
233
234   /* distance between lines in image
235      need not match the pixel width
236    */
237   guint field_stride;
238
239   /* Duration of one field */
240   GstClockTime field_duration;
241
242   /* The most recent pictures 
243      PictureHistory[0] is always the most recent.
244      Pointers are NULL if the picture in question isn't valid, e.g. because
245      the program just started or a picture was skipped.
246    */
247   GstPicture field_history[GST_DEINTERLACE_MAX_FIELD_HISTORY];
248   guint history_count;
249
250   /* Set to TRUE if we're in still frame mode,
251      i.e. just forward all buffers
252    */
253   gboolean still_frame_mode;
254
255   /* Last buffer that was pushed in */
256   GstBuffer *last_buffer;
257
258   /* Current segment */
259   GstSegment segment;
260
261   /* QoS stuff */
262   gdouble proportion;
263   GstClockTime earliest_time;
264
265   /* Upstream negotiation stuff */
266   GstCaps *sink_caps;
267   GstCaps *src_caps;
268
269   GstCaps *request_caps;
270 };
271
272 struct _GstDeinterlaceClass
273 {
274   GstElementClass parent_class;
275 };
276
277 GType gst_deinterlace_get_type (void);
278
279 G_END_DECLS
280 #endif /* __GST_DEINTERLACE_H__ */