Convert elements to use fractions for their framerate.
[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 const GValue *
29 gst_video_frame_rate (GstPad * pad)
30 {
31   const GValue *fps;
32   gchar *fps_string;
33
34   const GstCaps *caps = NULL;
35   GstStructure *structure;
36
37   /* get pad caps */
38   caps = GST_PAD_CAPS (pad);
39   if (caps == NULL) {
40     g_warning ("gstvideo: failed to get caps of pad %s:%s",
41         GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
42     return NULL;
43   }
44
45   structure = gst_caps_get_structure (caps, 0);
46   if ((fps = gst_structure_get_value (structure, "framerate")) == NULL) {
47     g_warning ("gstvideo: failed to get framerate property of pad %s:%s",
48         GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
49     return NULL;
50   }
51   if (!GST_VALUE_HOLDS_FRACTION (fps)) {
52     g_warning
53         ("gstvideo: framerate property of pad %s:%s is not of type Fraction",
54         GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
55     return NULL;
56   }
57
58   fps_string = gst_value_serialize (fps);
59   GST_DEBUG ("Framerate request on pad %s:%s: %s",
60       GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad),
61       fps_string);
62   g_free (fps_string);
63
64   return fps;
65 }
66
67 gboolean
68 gst_video_get_size (GstPad * pad, gint * width, gint * height)
69 {
70   const GstCaps *caps = NULL;
71   GstStructure *structure;
72   gboolean ret;
73
74   g_return_val_if_fail (pad != NULL, FALSE);
75   g_return_val_if_fail (width != NULL, FALSE);
76   g_return_val_if_fail (height != NULL, FALSE);
77
78   caps = GST_PAD_CAPS (pad);
79
80   if (caps == NULL) {
81     g_warning ("gstvideo: failed to get caps of pad %s:%s",
82         GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
83     return FALSE;
84   }
85
86   structure = gst_caps_get_structure (caps, 0);
87   ret = gst_structure_get_int (structure, "width", width);
88   ret &= gst_structure_get_int (structure, "height", height);
89
90   if (!ret) {
91     g_warning ("gstvideo: failed to get size properties on pad %s:%s",
92         GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
93     return FALSE;
94   }
95
96   GST_DEBUG ("size request on pad %s:%s: %dx%d",
97       GST_ELEMENT_NAME (gst_pad_get_parent (pad)),
98       GST_PAD_NAME (pad), width ? *width : -1, height ? *height : -1);
99
100   return TRUE;
101 }