1 /* Gstreamer Editing Services
2  *
3  * Copyright (C) <2011> 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  * SECTION: gesclipasset
22  * @title: GESClipAsset
23  * @short_description: A GESAsset subclass specialized in GESClip extraction
24  *
25  * The #GESUriClipAsset is a special #GESAsset specilized in #GESClip.
26  * it is mostly used to get information about the #GESTrackType-s the objects extracted
27  * from it can potentialy create #GESTrackElement for.
28  */
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 
33 #include "ges-clip-asset.h"
34 
35 #define GES_CLIP_ASSET_GET_PRIVATE(o)\
36   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GES_TYPE_CLIP_ASSET, \
37    GESClipAssetPrivate))
38 
39 #define parent_class ges_clip_asset_parent_class
40 
41 struct _GESClipAssetPrivate
42 {
43   GESTrackType supportedformats;
44 };
45 
46 
47 enum
48 {
49   PROP_0,
50   PROP_SUPPORTED_FORMATS,
51   PROP_LAST
52 };
53 
54 static GParamSpec *properties[PROP_LAST];
55 
56 G_DEFINE_TYPE_WITH_PRIVATE (GESClipAsset, ges_clip_asset, GES_TYPE_ASSET);
57 
58 /***********************************************
59  *                                             *
60  *      GObject vmetods implemenation          *
61  *                                             *
62  ***********************************************/
63 
64 static void
_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)65 _get_property (GObject * object, guint property_id,
66     GValue * value, GParamSpec * pspec)
67 {
68   GESClipAssetPrivate *priv = GES_CLIP_ASSET (object)->priv;
69   switch (property_id) {
70     case PROP_SUPPORTED_FORMATS:
71       g_value_set_flags (value, priv->supportedformats);
72       break;
73     default:
74       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
75   }
76 }
77 
78 static void
_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)79 _set_property (GObject * object, guint property_id,
80     const GValue * value, GParamSpec * pspec)
81 {
82   GESClipAssetPrivate *priv = GES_CLIP_ASSET (object)->priv;
83 
84   switch (property_id) {
85     case PROP_SUPPORTED_FORMATS:
86       priv->supportedformats = g_value_get_flags (value);
87       break;
88     default:
89       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
90   }
91 }
92 
93 static void
ges_clip_asset_init(GESClipAsset * self)94 ges_clip_asset_init (GESClipAsset * self)
95 {
96   self->priv = ges_clip_asset_get_instance_private (self);
97 }
98 
99 static void
_constructed(GObject * object)100 _constructed (GObject * object)
101 {
102   GType extractable_type = ges_asset_get_extractable_type (GES_ASSET (object));
103   GObjectClass *class = g_type_class_ref (extractable_type);
104   GParamSpecFlags *pspec;
105 
106   pspec = G_PARAM_SPEC_FLAGS (g_object_class_find_property (class,
107           "supported-formats"));
108 
109   GES_CLIP_ASSET (object)->priv->supportedformats = pspec->default_value;
110   g_type_class_unref (class);
111 
112   G_OBJECT_CLASS (parent_class)->constructed (object);
113 }
114 
115 static void
ges_clip_asset_class_init(GESClipAssetClass * self_class)116 ges_clip_asset_class_init (GESClipAssetClass * self_class)
117 {
118   GObjectClass *object_class = G_OBJECT_CLASS (self_class);
119 
120   object_class->constructed = _constructed;
121   object_class->get_property = _get_property;
122   object_class->set_property = _set_property;
123 
124   /**
125    * GESClipAsset:supported-formats:
126    *
127    * The formats supported by the asset.
128    */
129   properties[PROP_SUPPORTED_FORMATS] = g_param_spec_flags ("supported-formats",
130       "Supported formats", "Formats supported by the file",
131       GES_TYPE_TRACK_TYPE, GES_TRACK_TYPE_AUDIO | GES_TRACK_TYPE_VIDEO,
132       G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
133 
134   g_object_class_install_property (object_class, PROP_SUPPORTED_FORMATS,
135       properties[PROP_SUPPORTED_FORMATS]);
136 }
137 
138 /***********************************************
139  *                                             *
140  *              Public methods                 *
141  *                                             *
142  ***********************************************/
143 /**
144  * ges_clip_asset_set_supported_formats:
145  * @self: a #GESClipAsset
146  * @supportedformats: The track types supported by the GESClipAsset
147  *
148  * Sets track types for which objects extracted from @self can create #GESTrackElement
149  */
150 void
ges_clip_asset_set_supported_formats(GESClipAsset * self,GESTrackType supportedformats)151 ges_clip_asset_set_supported_formats (GESClipAsset * self,
152     GESTrackType supportedformats)
153 {
154   g_return_if_fail (GES_IS_CLIP_ASSET (self));
155 
156   self->priv->supportedformats = supportedformats;
157 }
158 
159 /**
160  * ges_clip_asset_get_supported_formats:
161  * @self: a #GESClipAsset
162  *
163  * Gets track types for which objects extracted from @self can create #GESTrackElement
164  *
165  * Returns: The track types on which @self will create TrackElement when added to
166  * a layer
167  */
168 GESTrackType
ges_clip_asset_get_supported_formats(GESClipAsset * self)169 ges_clip_asset_get_supported_formats (GESClipAsset * self)
170 {
171   g_return_val_if_fail (GES_IS_CLIP_ASSET (self), GES_TRACK_TYPE_UNKNOWN);
172 
173   return self->priv->supportedformats;
174 }
175