deinterlace: Simplify passthrough mode detection
[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-2010 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
28 #include <liboil/liboil.h>
29 #include <liboil/liboilcpu.h>
30 #include <liboil/liboilfunction.h>
31
32 #ifdef HAVE_GCC_ASM
33 #if defined(HAVE_CPU_I386) || defined(HAVE_CPU_X86_64)
34 #define BUILD_X86_ASM
35 #endif
36 #endif
37
38 G_BEGIN_DECLS
39
40 #define GST_TYPE_DEINTERLACE \
41   (gst_deinterlace_get_type())
42 #define GST_DEINTERLACE(obj) \
43   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DEINTERLACE,GstDeinterlace))
44 #define GST_DEINTERLACE_CLASS(klass) \
45   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DEINTERLACE,GstDeinterlace))
46 #define GST_IS_DEINTERLACE(obj) \
47   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DEINTERLACE))
48 #define GST_IS_DEINTERLACE_CLASS(obj) \
49   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DEINTERLACE))
50
51 typedef struct _GstDeinterlace GstDeinterlace;
52 typedef struct _GstDeinterlaceClass GstDeinterlaceClass;
53
54 #define GST_TYPE_DEINTERLACE_METHOD             (gst_deinterlace_method_get_type ())
55 #define GST_IS_DEINTERLACE_METHOD(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DEINTERLACE_METHOD))
56 #define GST_IS_DEINTERLACE_METHOD_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DEINTERLACE_METHOD))
57 #define GST_DEINTERLACE_METHOD_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DEINTERLACE_METHOD, GstDeinterlaceMethodClass))
58 #define GST_DEINTERLACE_METHOD(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DEINTERLACE_METHOD, GstDeinterlaceMethod))
59 #define GST_DEINTERLACE_METHOD_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEINTERLACE_METHOD, GstDeinterlaceMethodClass))
60 #define GST_DEINTERLACE_METHOD_CAST(obj)        ((GstDeinterlaceMethod*)(obj))
61
62 typedef struct _GstDeinterlaceMethod GstDeinterlaceMethod;
63 typedef struct _GstDeinterlaceMethodClass GstDeinterlaceMethodClass;
64
65
66 #define PICTURE_PROGRESSIVE 0
67 #define PICTURE_INTERLACED_BOTTOM 1
68 #define PICTURE_INTERLACED_TOP 2
69 #define PICTURE_INTERLACED_MASK (PICTURE_INTERLACED_BOTTOM | PICTURE_INTERLACED_TOP)
70
71 typedef struct
72 {
73   /* pointer to the start of data for this field */
74   GstBuffer *buf;
75   /* see PICTURE_ flags in *.c */
76   guint flags;
77 } GstDeinterlaceField;
78
79 /*
80  * This structure defines the deinterlacer plugin.
81  */
82
83
84 typedef void (*GstDeinterlaceMethodDeinterlaceFunction) (GstDeinterlaceMethod *self, const GstDeinterlaceField *history, guint history_count, GstBuffer *outbuf);
85
86 struct _GstDeinterlaceMethod {
87   GstObject parent;
88
89   GstVideoFormat format;
90   gint frame_width, frame_height;
91   gint width[4];
92   gint height[4];
93   gint offset[4];
94   gint row_stride[4];
95   gint pixel_stride[4];
96
97   GstDeinterlaceMethodDeinterlaceFunction deinterlace_frame;
98 };
99
100 struct _GstDeinterlaceMethodClass {
101   GstObjectClass parent_class;
102   guint fields_required;
103   guint latency;
104
105   gboolean (*supported) (GstDeinterlaceMethodClass *klass, GstVideoFormat format, gint width, gint height);
106
107   void (*setup) (GstDeinterlaceMethod *self, GstVideoFormat format, gint width, gint height);
108
109   GstDeinterlaceMethodDeinterlaceFunction deinterlace_frame_yuy2;
110   GstDeinterlaceMethodDeinterlaceFunction deinterlace_frame_yvyu;
111
112   const gchar *name;
113   const gchar *nick;
114 };
115
116 GType gst_deinterlace_method_get_type (void);
117
118 #define GST_TYPE_DEINTERLACE_SIMPLE_METHOD              (gst_deinterlace_simple_method_get_type ())
119 #define GST_IS_DEINTERLACE_SIMPLE_METHOD(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DEINTERLACE_SIMPLE_METHOD))
120 #define GST_IS_DEINTERLACE_SIMPLE_METHOD_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DEINTERLACE_SIMPLE_METHOD))
121 #define GST_DEINTERLACE_SIMPLE_METHOD_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DEINTERLACE_SIMPLE_METHOD, GstDeinterlaceSimpleMethodClass))
122 #define GST_DEINTERLACE_SIMPLE_METHOD(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DEINTERLACE_SIMPLE_METHOD, GstDeinterlaceSimpleMethod))
123 #define GST_DEINTERLACE_SIMPLE_METHOD_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEINTERLACE_SIMPLE_METHOD, GstDeinterlaceSimpleMethodClass))
124 #define GST_DEINTERLACE_SIMPLE_METHOD_CAST(obj) ((GstDeinterlaceSimpleMethod*)(obj))
125
126 typedef struct _GstDeinterlaceSimpleMethod GstDeinterlaceSimpleMethod;
127 typedef struct _GstDeinterlaceSimpleMethodClass GstDeinterlaceSimpleMethodClass;
128 typedef struct _GstDeinterlaceScanlineData GstDeinterlaceScanlineData;
129
130 /*
131  * This structure defines the simple deinterlacer plugin.
132  */
133
134 struct _GstDeinterlaceScanlineData {
135  const guint8 *tt0, *t0, *m0, *b0, *bb0;
136  const guint8 *tt1, *t1, *m1, *b1, *bb1;
137  const guint8 *tt2, *t2, *m2, *b2, *bb2;
138  const guint8 *tt3, *t3, *m3, *b3, *bb3;
139  gboolean bottom_field;
140 };
141
142 /**
143  * For interpolate_scanline the input is:
144  *
145  * |   t-3       t-2       t-1       t
146  * | Field 3 | Field 2 | Field 1 | Field 0 |
147  * |  TT3    |         |   TT1   |         |
148  * |         |   T2    |         |   T0    |
149  * |   M3    |         |    M1   |         |
150  * |         |   B2    |         |   B0    |
151  * |  BB3    |         |   BB1   |         |
152  *
153  * For copy_scanline the input is:
154  *
155  * |   t-3       t-2       t-1       t
156  * | Field 3 | Field 2 | Field 1 | Field 0 |
157  * |         |   TT2   |         |  TT0    |
158  * |   T3    |         |   T1    |         |
159  * |         |    M2   |         |   M0    |
160  * |   B3    |         |   B1    |         |
161  * |         |   BB2   |         |  BB0    |
162  *
163  * All other values are NULL.
164  */
165
166 typedef void (*GstDeinterlaceSimpleMethodPackedFunction) (GstDeinterlaceSimpleMethod *self, guint8 *out, const GstDeinterlaceScanlineData *scanlines);
167
168 struct _GstDeinterlaceSimpleMethod {
169   GstDeinterlaceMethod parent;
170
171   GstDeinterlaceSimpleMethodPackedFunction interpolate_scanline_packed;
172   GstDeinterlaceSimpleMethodPackedFunction copy_scanline_packed;
173 };
174
175 struct _GstDeinterlaceSimpleMethodClass {
176   GstDeinterlaceMethodClass parent_class;
177
178   /* Packed formats */
179   GstDeinterlaceSimpleMethodPackedFunction interpolate_scanline_yuy2;
180   GstDeinterlaceSimpleMethodPackedFunction copy_scanline_yuy2;
181   GstDeinterlaceSimpleMethodPackedFunction interpolate_scanline_yvyu;
182   GstDeinterlaceSimpleMethodPackedFunction copy_scanline_yvyu;
183 };
184
185 GType gst_deinterlace_simple_method_get_type (void);
186
187 #define GST_DEINTERLACE_MAX_FIELD_HISTORY 10
188
189 typedef enum
190 {
191   GST_DEINTERLACE_TOMSMOCOMP,
192   GST_DEINTERLACE_GREEDY_H,
193   GST_DEINTERLACE_GREEDY_L,
194   GST_DEINTERLACE_VFIR,
195   GST_DEINTERLACE_LINEAR,
196   GST_DEINTERLACE_LINEAR_BLEND,
197   GST_DEINTERLACE_SCALER_BOB,
198   GST_DEINTERLACE_WEAVE,
199   GST_DEINTERLACE_WEAVE_TFF,
200   GST_DEINTERLACE_WEAVE_BFF
201 } GstDeinterlaceMethods;
202
203 typedef enum
204 {
205   GST_DEINTERLACE_ALL,         /* All (missing data is interp.) */
206   GST_DEINTERLACE_TF,          /* Top Fields Only */
207   GST_DEINTERLACE_BF           /* Bottom Fields Only */
208 } GstDeinterlaceFields;
209
210 typedef enum
211 {
212   GST_DEINTERLACE_LAYOUT_AUTO,
213   GST_DEINTERLACE_LAYOUT_TFF,
214   GST_DEINTERLACE_LAYOUT_BFF
215 } GstDeinterlaceFieldLayout;
216
217 typedef enum {
218   GST_DEINTERLACE_MODE_AUTO,
219   GST_DEINTERLACE_MODE_INTERLACED,
220   GST_DEINTERLACE_MODE_DISABLED
221 } GstDeinterlaceMode;
222
223 struct _GstDeinterlace
224 {
225   GstElement parent;
226
227   GstPad *srcpad, *sinkpad;
228
229   /* <private> */
230   GstDeinterlaceMode mode;
231
232   GstDeinterlaceFieldLayout field_layout;
233
234   GstDeinterlaceFields fields;
235
236   GstDeinterlaceMethods method_id;
237   GstDeinterlaceMethod *method;
238
239   GstVideoFormat format;
240   gint width, height; /* frame width & height */
241   guint frame_size; /* frame size in bytes */
242   gint fps_n, fps_d; /* frame rate */
243   gboolean interlaced; /* is input interlaced? */
244
245   gboolean passthrough;
246
247   GstClockTime field_duration; /* Duration of one field */
248
249   /* The most recent pictures 
250      PictureHistory[0] is always the most recent.
251      Pointers are NULL if the picture in question isn't valid, e.g. because
252      the program just started or a picture was skipped.
253    */
254   GstDeinterlaceField field_history[GST_DEINTERLACE_MAX_FIELD_HISTORY];
255   guint history_count;
256
257   /* Set to TRUE if we're in still frame mode,
258      i.e. just forward all buffers
259    */
260   gboolean still_frame_mode;
261
262   /* Last buffer that was pushed in */
263   GstBuffer *last_buffer;
264
265   /* Current segment */
266   GstSegment segment;
267
268   /* QoS stuff */
269   gdouble proportion;
270   GstClockTime earliest_time;
271
272   /* Upstream negotiation stuff */
273   GstCaps *sink_caps;
274   GstCaps *src_caps;
275
276   GstCaps *request_caps;
277 };
278
279 struct _GstDeinterlaceClass
280 {
281   GstElementClass parent_class;
282 };
283
284 GType gst_deinterlace_get_type (void);
285
286 G_END_DECLS
287
288 #endif /* __GST_DEINTERLACE_H__ */