gst-indent
[platform/upstream/gstreamer.git] / gst-libs / gst / video / video.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Library       <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
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 #ifdef HAVE_CONFIG_H
22 #  include "config.h"
23 #endif
24
25 #include "video.h"
26
27 /* This is simply a convenience function, nothing more or less */
28
29 gdouble
30 gst_video_frame_rate (GstPad * pad)
31 {
32   gdouble fps = 0.;
33   const GstCaps *caps = NULL;
34   GstStructure *structure;
35
36   /* get pad caps */
37   caps = GST_PAD_CAPS (pad);
38   if (caps == NULL) {
39     g_warning ("gstvideo: failed to get caps of pad %s:%s",
40         GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
41     return 0.;
42   }
43
44   structure = gst_caps_get_structure (caps, 0);
45   if (!gst_structure_get_double (structure, "framerate", &fps)) {
46     g_warning ("gstvideo: failed to get framerate property of pad %s:%s",
47         GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
48     return 0.;
49   }
50
51   GST_DEBUG ("Framerate request on pad %s:%s: %f",
52       GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad), fps);
53
54   return fps;
55 }
56
57 gboolean
58 gst_video_get_size (GstPad * pad, gint * width, gint * height)
59 {
60   const GstCaps *caps = NULL;
61   GstStructure *structure;
62   gboolean ret;
63
64   g_return_val_if_fail (pad != NULL, FALSE);
65   g_return_val_if_fail (width != NULL, FALSE);
66   g_return_val_if_fail (height != NULL, FALSE);
67
68   caps = GST_PAD_CAPS (pad);
69
70   if (caps == NULL) {
71     g_warning ("gstvideo: failed to get caps of pad %s:%s",
72         GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
73     return FALSE;
74   }
75
76   structure = gst_caps_get_structure (caps, 0);
77   ret = gst_structure_get_int (structure, "width", width);
78   ret &= gst_structure_get_int (structure, "height", height);
79
80   if (!ret) {
81     g_warning ("gstvideo: failed to get size properties on pad %s:%s",
82         GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
83     return FALSE;
84   }
85
86   GST_DEBUG ("size request on pad %s:%s: %dx%d",
87       GST_ELEMENT_NAME (gst_pad_get_parent (pad)),
88       GST_PAD_NAME (pad), width ? *width : -1, height ? *height : -1);
89
90   return TRUE;
91 }
92
93 static gboolean
94 plugin_init (GstPlugin * plugin)
95 {
96   return TRUE;
97 }
98
99 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
100     GST_VERSION_MINOR,
101     "gstvideo",
102     "Convenience routines for video plugins",
103     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)