command-line-formatter: Stop uselessly looping over options
[platform/upstream/gstreamer.git] / ges / ges-track-element-asset.c
1 /* Gstreamer Editing Services
2  *
3  * Copyright (C) <2012> Thibault Saunier <thibault.saunier@collabora.com>
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: gestrackelementasset
23  * @title: GESTrackElementAsset
24  * @short_description: A GESAsset subclass specialized in GESTrackElement extraction
25  */
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "ges-track-element-asset.h"
31
32 enum
33 {
34   PROP_0,
35   PROP_TRACK_TYPE,
36   PROP_LAST
37 };
38
39 static GParamSpec *properties[PROP_LAST];
40
41 struct _GESTrackElementAssetPrivate
42 {
43   GESTrackType type;
44 };
45
46 G_DEFINE_TYPE_WITH_PRIVATE (GESTrackElementAsset, ges_track_element_asset,
47     GES_TYPE_ASSET);
48
49 static void
50 _get_property (GObject * object, guint property_id,
51     GValue * value, GParamSpec * pspec)
52 {
53   GESTrackElementAsset *asset = GES_TRACK_ELEMENT_ASSET (object);
54
55   switch (property_id) {
56     case PROP_TRACK_TYPE:
57       g_value_set_flags (value, asset->priv->type);
58       break;
59     default:
60       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
61   }
62 }
63
64 static void
65 _set_property (GObject * object, guint property_id,
66     const GValue * value, GParamSpec * pspec)
67 {
68   GESTrackElementAsset *asset = GES_TRACK_ELEMENT_ASSET (object);
69
70   switch (property_id) {
71     case PROP_TRACK_TYPE:
72       asset->priv->type = g_value_get_flags (value);
73       break;
74     default:
75       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
76   }
77 }
78
79 static void
80 ges_track_element_asset_class_init (GESTrackElementAssetClass * klass)
81 {
82   GObjectClass *object_class = G_OBJECT_CLASS (klass);
83
84   object_class->get_property = _get_property;
85   object_class->set_property = _set_property;
86
87   /**
88    * GESClip:track-type:
89    *
90    * The formats supported by the object.
91    */
92   properties[PROP_TRACK_TYPE] = g_param_spec_flags ("track-type",
93       "Track type", "The GESTrackType in which the object is",
94       GES_TYPE_TRACK_TYPE, GES_TRACK_TYPE_UNKNOWN,
95       G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
96
97   g_object_class_install_property (object_class, PROP_TRACK_TYPE,
98       properties[PROP_TRACK_TYPE]);
99 }
100
101 static void
102 ges_track_element_asset_init (GESTrackElementAsset * self)
103 {
104   GESTrackElementAssetPrivate *priv;
105
106   priv = self->priv = ges_track_element_asset_get_instance_private (self);
107
108   priv->type = GES_TRACK_TYPE_UNKNOWN;
109
110 }
111
112 /**
113  * ges_track_element_asset_set_track_type:
114  * @asset: A #GESAsset
115  * @type: A #GESTrackType
116  *
117  * Set the #GESTrackType the #GESTrackElement extracted from @self
118  * should get into
119  */
120 void
121 ges_track_element_asset_set_track_type (GESTrackElementAsset * asset,
122     GESTrackType type)
123 {
124   g_return_if_fail (GES_IS_TRACK_ELEMENT_ASSET (asset));
125
126   asset->priv->type = type;
127 }
128
129 /**
130  * ges_track_element_asset_get_track_type:
131  * @asset: A #GESAsset
132  *
133  * Get the GESAssetTrackType the #GESTrackElement extracted from @self
134  * should get into
135  *
136  * Returns: a #GESTrackType
137  */
138 const GESTrackType
139 ges_track_element_asset_get_track_type (GESTrackElementAsset * asset)
140 {
141   g_return_val_if_fail (GES_IS_TRACK_ELEMENT_ASSET (asset),
142       GES_TRACK_TYPE_UNKNOWN);
143
144   return asset->priv->type;
145 }
146
147 /**
148  * ges_track_element_asset_get_natural_framerate:
149  * @self: A #GESAsset
150  * @framerate_n: The framerate numerator
151  * @framerate_d: The framerate denominator
152  *
153  * Result: %TRUE if @self has a natural framerate %FALSE otherwise
154  *
155  * Since: 1.18
156  */
157 gboolean
158 ges_track_element_asset_get_natural_framerate (GESTrackElementAsset * self,
159     gint * framerate_n, gint * framerate_d)
160 {
161   GESTrackElementAssetClass *klass;
162
163   g_return_val_if_fail (GES_IS_TRACK_ELEMENT_ASSET (self), FALSE);
164   g_return_val_if_fail (framerate_n && framerate_d, FALSE);
165
166   klass = GES_TRACK_ELEMENT_ASSET_GET_CLASS (self);
167
168   *framerate_n = 0;
169   *framerate_d = -1;
170
171   if (klass->get_natural_framerate)
172     return klass->get_natural_framerate (self, framerate_n, framerate_d);
173
174   return FALSE;
175 }