structured: Enhance error message when no clip duration set
[platform/upstream/gst-editing-services.git] / ges / ges-source-clip.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3  *               2009 Nokia Corporation
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., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * SECTION:gessourceclip
23  * @title: GESSourceClip
24  * @short_description: Base Class for sources of a GESLayer
25  */
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "ges-internal.h"
31 #include "ges-clip.h"
32 #include "ges-source-clip.h"
33 #include "ges-source.h"
34
35
36 struct _GESSourceClipPrivate
37 {
38   /*  dummy variable */
39   void *nothing;
40 };
41
42 enum
43 {
44   PROP_0,
45 };
46
47 G_DEFINE_TYPE_WITH_PRIVATE (GESSourceClip, ges_source_clip, GES_TYPE_CLIP);
48
49 static gboolean
50 _set_start (GESTimelineElement * element, GstClockTime start)
51 {
52   GESTimelineElement *toplevel =
53       ges_timeline_element_get_toplevel_parent (element);
54
55   gst_object_unref (toplevel);
56   if (element->timeline
57       && !ELEMENT_FLAG_IS_SET (element, GES_TIMELINE_ELEMENT_SET_SIMPLE)
58       && !ELEMENT_FLAG_IS_SET (toplevel, GES_TIMELINE_ELEMENT_SET_SIMPLE)) {
59     ges_timeline_move_object_simple (element->timeline, element, NULL,
60         GES_EDGE_NONE, start);
61     return FALSE;
62   }
63
64   return
65       GES_TIMELINE_ELEMENT_CLASS (ges_source_clip_parent_class)->set_start
66       (element, start);
67 }
68
69 static gboolean
70 _set_duration (GESTimelineElement * element, GstClockTime duration)
71 {
72   GESTimelineElement *toplevel =
73       ges_timeline_element_get_toplevel_parent (element);
74
75   gst_object_unref (toplevel);
76   if (element->timeline
77       && !ELEMENT_FLAG_IS_SET (element, GES_TIMELINE_ELEMENT_SET_SIMPLE)
78       && !ELEMENT_FLAG_IS_SET (toplevel, GES_TIMELINE_ELEMENT_SET_SIMPLE)) {
79     return !timeline_trim_object (element->timeline, element,
80         GES_TIMELINE_ELEMENT_LAYER_PRIORITY (element), NULL, GES_EDGE_END,
81         element->start + duration);
82   }
83
84   return
85       GES_TIMELINE_ELEMENT_CLASS (ges_source_clip_parent_class)->set_duration
86       (element, duration);
87 }
88
89 static void
90 ges_source_clip_get_property (GObject * object, guint property_id,
91     GValue * value, GParamSpec * pspec)
92 {
93   switch (property_id) {
94     default:
95       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
96   }
97 }
98
99 static void
100 ges_source_clip_set_property (GObject * object, guint property_id,
101     const GValue * value, GParamSpec * pspec)
102 {
103   switch (property_id) {
104     default:
105       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
106   }
107 }
108
109 static void
110 ges_source_clip_finalize (GObject * object)
111 {
112   G_OBJECT_CLASS (ges_source_clip_parent_class)->finalize (object);
113 }
114
115 static void
116 ges_source_clip_class_init (GESSourceClipClass * klass)
117 {
118   GObjectClass *object_class = G_OBJECT_CLASS (klass);
119   GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
120
121   object_class->get_property = ges_source_clip_get_property;
122   object_class->set_property = ges_source_clip_set_property;
123   object_class->finalize = ges_source_clip_finalize;
124
125   element_class->set_start = _set_start;
126   element_class->set_duration = _set_duration;
127 }
128
129 static void
130 ges_source_clip_init (GESSourceClip * self)
131 {
132   self->priv = ges_source_clip_get_instance_private (self);
133 }