tizen 2.3 release
[framework/multimedia/gst-plugins-base0.10.git] / gst-libs / gst / video / gstvideofilter.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2003> David Schleef <ds@schleef.org>
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., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21  /**
22  * SECTION:gstvideofilter
23  * @short_description: Base class for video filters
24  * 
25  * <refsect2>
26  * <para>
27  * Provides useful functions and a base class for video filters.
28  * </para>
29  * <para>
30  * The videofilter will by default enable QoS on the parent GstBaseTransform
31  * to implement frame dropping.
32  * </para>
33  * </refsect2>
34  */
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include "gstvideofilter.h"
41
42 #include <gst/video/video.h>
43
44 GST_DEBUG_CATEGORY_STATIC (gst_video_filter_debug);
45 #define GST_CAT_DEFAULT gst_video_filter_debug
46
47 static void gst_video_filter_class_init (gpointer g_class, gpointer class_data);
48 static void gst_video_filter_init (GTypeInstance * instance, gpointer g_class);
49
50 static GstBaseTransformClass *parent_class = NULL;
51
52 GType
53 gst_video_filter_get_type (void)
54 {
55   static GType video_filter_type = 0;
56
57   if (!video_filter_type) {
58     static const GTypeInfo video_filter_info = {
59       sizeof (GstVideoFilterClass),
60       NULL,
61       NULL,
62       gst_video_filter_class_init,
63       NULL,
64       NULL,
65       sizeof (GstVideoFilter),
66       0,
67       gst_video_filter_init,
68     };
69
70     video_filter_type = g_type_register_static (GST_TYPE_BASE_TRANSFORM,
71         "GstVideoFilter", &video_filter_info, G_TYPE_FLAG_ABSTRACT);
72   }
73   return video_filter_type;
74 }
75
76 static gboolean
77 gst_video_filter_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
78     guint * size)
79 {
80   GstVideoFormat fmt;
81   gint width, height;
82
83   if (!gst_video_format_parse_caps (caps, &fmt, &width, &height)) {
84     GST_WARNING_OBJECT (btrans, "Failed to parse caps %" GST_PTR_FORMAT, caps);
85     return FALSE;
86   }
87
88   *size = gst_video_format_get_size (fmt, width, height);
89
90   GST_DEBUG_OBJECT (btrans, "Returning size %u bytes for caps %"
91       GST_PTR_FORMAT, *size, caps);
92
93   return TRUE;
94 }
95
96 static void
97 gst_video_filter_class_init (gpointer g_class, gpointer class_data)
98 {
99   GstBaseTransformClass *trans_class;
100   GstVideoFilterClass *klass;
101
102   klass = (GstVideoFilterClass *) g_class;
103   trans_class = (GstBaseTransformClass *) klass;
104
105   trans_class->get_unit_size =
106       GST_DEBUG_FUNCPTR (gst_video_filter_get_unit_size);
107
108   parent_class = g_type_class_peek_parent (klass);
109
110   GST_DEBUG_CATEGORY_INIT (gst_video_filter_debug, "videofilter", 0,
111       "videofilter");
112 }
113
114 static void
115 gst_video_filter_init (GTypeInstance * instance, gpointer g_class)
116 {
117   GstVideoFilter *videofilter = GST_VIDEO_FILTER (instance);
118
119   GST_DEBUG_OBJECT (videofilter, "gst_video_filter_init");
120
121   videofilter->inited = FALSE;
122   /* enable QoS */
123   gst_base_transform_set_qos_enabled (GST_BASE_TRANSFORM (videofilter), TRUE);
124 }