ges-effect-clip.c 5.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* GStreamer Editing Services
 * Copyright (C) 2011 Thibault Saunier <thibault.saunier@collabora.co.uk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
16 17
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
18 19 20
 */

/**
21
 * SECTION: geseffectclip
22
 * @title: GESEffectClip
23
 * @short_description: An effect created by parse-launch style bin descriptions
24
 * in a GESLayer
25 26 27 28 29 30 31 32 33
 *
 * The effect will be applied on the sources that have lower priorities
 * (higher number) between the inpoint and the end of it.
 */

#include <ges/ges.h>
#include "ges-internal.h"
#include "ges-types.h"

34
G_DEFINE_TYPE (GESEffectClip, ges_effect_clip, GES_TYPE_BASE_EFFECT_CLIP);
35

36
struct _GESEffectClipPrivate
37 38 39 40 41 42 43 44 45 46 47 48
{
  gchar *video_bin_description;
  gchar *audio_bin_description;
};

enum
{
  PROP_0,
  PROP_VIDEO_BIN_DESCRIPTION,
  PROP_AUDIO_BIN_DESCRIPTION,
};

49
static void ges_effect_clip_finalize (GObject * object);
50
static GESTrackElement *_create_track_element (GESClip * self,
51
    GESTrackType type);
52

53
static void
54
ges_effect_clip_finalize (GObject * object)
55
{
56
  GESEffectClipPrivate *priv = GES_EFFECT_CLIP (object)->priv;
57 58 59 60

  g_free (priv->audio_bin_description);
  g_free (priv->video_bin_description);

61
  G_OBJECT_CLASS (ges_effect_clip_parent_class)->finalize (object);
62 63
}

64
static void
65
ges_effect_clip_get_property (GObject * object,
66 67
    guint property_id, GValue * value, GParamSpec * pspec)
{
68
  GESEffectClipPrivate *priv = GES_EFFECT_CLIP (object)->priv;
69 70 71 72 73 74 75 76 77 78 79 80 81 82

  switch (property_id) {
    case PROP_VIDEO_BIN_DESCRIPTION:
      g_value_set_string (value, priv->video_bin_description);
      break;
    case PROP_AUDIO_BIN_DESCRIPTION:
      g_value_set_string (value, priv->audio_bin_description);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  }
}

static void
83
ges_effect_clip_set_property (GObject * object,
84 85
    guint property_id, const GValue * value, GParamSpec * pspec)
{
86
  GESEffectClip *self = GES_EFFECT_CLIP (object);
87 88 89 90 91 92 93 94 95 96 97 98 99 100

  switch (property_id) {
    case PROP_VIDEO_BIN_DESCRIPTION:
      self->priv->video_bin_description = g_value_dup_string (value);
      break;
    case PROP_AUDIO_BIN_DESCRIPTION:
      self->priv->audio_bin_description = g_value_dup_string (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  }
}

static void
101
ges_effect_clip_class_init (GESEffectClipClass * klass)
102 103
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
104
  GESClipClass *timobj_class = GES_CLIP_CLASS (klass);
105

106
  g_type_class_add_private (klass, sizeof (GESEffectClipPrivate));
107

108 109 110
  object_class->get_property = ges_effect_clip_get_property;
  object_class->set_property = ges_effect_clip_set_property;
  object_class->finalize = ges_effect_clip_finalize;
111 112

  /**
113
   * GESEffectClip:video-bin-description:
114 115 116
   *
   * The description of the video track of the effect bin with a gst-launch-style
   * pipeline description. This should be used for test purposes.
Edward Hervey's avatar
Edward Hervey committed
117 118
   *
   * Example: "videobalance saturation=1.5 hue=+0.5"
119 120 121 122 123 124 125 126
   */
  g_object_class_install_property (object_class, PROP_VIDEO_BIN_DESCRIPTION,
      g_param_spec_string ("video-bin-description",
          "Video bin description",
          "Description of the video track of the effect",
          NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));

  /**
127
   * GESEffectClip:audio-bin-description:
128 129 130
   *
   * The description of the audio track of the effect bin with a gst-launch-style
   * pipeline description. This should be used for test purposes.
Edward Hervey's avatar
Edward Hervey committed
131 132
   *
   * Example: "audiopanorama panorama=1.0"
133 134 135 136 137 138 139
   */
  g_object_class_install_property (object_class, PROP_AUDIO_BIN_DESCRIPTION,
      g_param_spec_string ("audio-bin-description",
          "bin description",
          "Bin description of the audio track of the effect",
          NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));

140
  timobj_class->create_track_element = _create_track_element;
141 142 143
}

static void
144
ges_effect_clip_init (GESEffectClip * self)
145 146
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
147
      GES_TYPE_EFFECT_CLIP, GESEffectClipPrivate);
148 149 150

}

151
static GESTrackElement *
152
_create_track_element (GESClip * self, GESTrackType type)
153
{
154
  const gchar *bin_description = NULL;
155
  GESEffectClip *effect = GES_EFFECT_CLIP (self);
156

157 158 159 160
  if (type == GES_TRACK_TYPE_VIDEO) {
    bin_description = effect->priv->video_bin_description;
  } else if (type == GES_TRACK_TYPE_AUDIO) {
    bin_description = effect->priv->audio_bin_description;
161
  }
162 163 164

  if (bin_description) {
    /* FIXME Work with a GESAsset here! */
165
    return g_object_new (GES_TYPE_EFFECT, "bin-description",
166
        bin_description, "track-type", type, NULL);
167 168 169 170 171 172 173
  }

  GST_WARNING ("Effect doesn't handle this track type");
  return NULL;
}

/**
174
 * ges_effect_clip_new:
175 176 177
 * @video_bin_description: The gst-launch like bin description of the effect
 * @audio_bin_description: The gst-launch like bin description of the effect
 *
178
 * Creates a new #GESEffectClip from the description of the bin.
179
 *
180
 * Returns: (transfer floating) (nullable): a newly created #GESEffectClip, or
181 182
 * %NULL if something went wrong.
 */
183 184
GESEffectClip *
ges_effect_clip_new (const gchar * video_bin_description,
185 186
    const gchar * audio_bin_description)
{
187
  /*  FIXME Handle GESAsset! */
188
  return g_object_new (GES_TYPE_EFFECT_CLIP,
189 190 191
      "video-bin-description", video_bin_description,
      "audio-bin-description", audio_bin_description, NULL);
}