summaryrefslogtreecommitdiff
path: root/ges/gstframepositioner.c
blob: 9255c09e56c8f9514c458976ba5b14a2caf9ffec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
/* GStreamer
 * Copyright (C) 2013 Mathieu Duponchelle <mduponchelle1@gmail.com>
 *
 * 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
 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
 * Boston, MA 02110-1335, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <math.h>
#include <gst/gst.h>
#include <gst/video/video.h>

#include "gstframepositioner.h"

GST_DEBUG_CATEGORY_STATIC (_framepositioner);
#undef GST_CAT_DEFAULT
#define GST_CAT_DEFAULT _framepositioner

/* We  need to define a max number of pixel so we can interpolate them */
#define MAX_PIXELS 100000
#define MIN_PIXELS -100000

static void gst_frame_positioner_set_property (GObject * object,
    guint property_id, const GValue * value, GParamSpec * pspec);
static void gst_frame_positioner_get_property (GObject * object,
    guint property_id, GValue * value, GParamSpec * pspec);
static GstFlowReturn gst_frame_positioner_transform_ip (GstBaseTransform *
    trans, GstBuffer * buf);

static gboolean
gst_frame_positioner_meta_init (GstMeta * meta, gpointer params,
    GstBuffer * buffer);
static gboolean gst_frame_positioner_meta_transform (GstBuffer * dest,
    GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data);

enum
{
  PROP_0,
  PROP_ALPHA,
  PROP_POSX,
  PROP_POSY,
  PROP_ZORDER,
  PROP_WIDTH,
  PROP_HEIGHT,
  PROP_LAST,
};

static GParamSpec *properties[PROP_LAST];

static GstStaticPadTemplate gst_frame_positioner_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("video/x-raw")
    );

static GstStaticPadTemplate gst_frame_positioner_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("video/x-raw")
    );

G_DEFINE_TYPE (GstFramePositioner, gst_frame_positioner,
    GST_TYPE_BASE_TRANSFORM);

static void
_weak_notify_cb (GstFramePositioner * pos, GObject * old)
{
  pos->current_track = NULL;
}

static gboolean
is_user_positionned (GstFramePositioner * self)
{
  gint i;
  GParamSpec *positioning_props[] = {
    properties[PROP_WIDTH],
    properties[PROP_HEIGHT],
    properties[PROP_POSX],
    properties[PROP_POSY],
  };

  if (self->user_positioned)
    return TRUE;

  for (i = 0; i < G_N_ELEMENTS (positioning_props); i++) {
    GstControlBinding *b = gst_object_get_control_binding (GST_OBJECT (self),
        positioning_props[i]->name);

    if (b) {
      gst_object_unref (b);
      return TRUE;
    }
  }

  return FALSE;
}

static gboolean
auto_position (GstFramePositioner * self)
{
  gdouble scaled_width = -1, scaled_height = -1, x, y;

  if (is_user_positionned (self)) {
    GST_DEBUG_OBJECT (self, "Was positioned by the user, not auto positioning");
    return FALSE;
  }

  if (!self->natural_width || !self->natural_height)
    return FALSE;

  if (self->track_width == self->natural_width &&
      self->track_height == self->natural_height)
    return TRUE;

  scaled_height =
      gst_util_uint64_scale_int (self->natural_height, self->track_width,
      self->natural_width);
  scaled_width = self->track_width;
  if (scaled_height > self->track_height) {
    scaled_height = self->track_height;
    scaled_width =
        gst_util_uint64_scale_int (self->natural_width, self->track_height,
        self->natural_height);
  }

  x = MAX (0, (self->track_width - scaled_width) / 2.f);
  y = MAX (0, (self->track_height - scaled_height) / 2.f);

  GST_INFO_OBJECT (self, "Scalling video to match track size from "
      "%dx%d to %fx%f",
      self->natural_width, self->natural_height, scaled_width, scaled_height);
  self->width = scaled_width;
  self->height = scaled_height;
  self->posx = x;
  self->posy = y;

  return TRUE;
}

typedef struct
{
  gdouble *value;
  gint old_track_value;
  gint track_value;
  GParamSpec *pspec;
} RepositionPropertyData;

static void
reposition_properties (GstFramePositioner * pos, gint old_track_width,
    gint old_track_height)
{
  gint i;
  RepositionPropertyData props_data[] = {
    {&pos->width, old_track_width, pos->track_width, properties[PROP_WIDTH]},
    {&pos->height, old_track_height, pos->track_height,
        properties[PROP_HEIGHT]},
    {&pos->posx, old_track_width, pos->track_width, properties[PROP_POSX]},
    {&pos->posy, old_track_height, pos->track_height, properties[PROP_POSY]},
  };

  for (i = 0; i < G_N_ELEMENTS (props_data); i++) {
    GList *values, *tmp;
    gboolean absolute;
    GstTimedValueControlSource *source = NULL;

    RepositionPropertyData d = props_data[i];
    GstControlBinding *binding =
        gst_object_get_control_binding (GST_OBJECT (pos), d.pspec->name);

    *(d.value) =
        *(d.value) * (gdouble) d.track_value / (gdouble) d.old_track_value;

    if (!binding)
      continue;

    if (!GST_IS_DIRECT_CONTROL_BINDING (binding)) {
      GST_FIXME_OBJECT (pos, "Implement support for control binding type: %s",
          G_OBJECT_TYPE_NAME (binding));

      goto next;
    }

    g_object_get (binding, "control_source", &source, NULL);
    if (!source || !GST_IS_TIMED_VALUE_CONTROL_SOURCE (source)) {
      GST_FIXME_OBJECT (pos, "Implement support for control source type: %s",
          source ? G_OBJECT_TYPE_NAME (source) : "NULL");

      goto next;
    }

    values =
        gst_timed_value_control_source_get_all (GST_TIMED_VALUE_CONTROL_SOURCE
        (source));

    if (!values)
      goto next;

    g_object_get (binding, "absolute", &absolute, NULL);
    for (tmp = values; tmp; tmp = tmp->next) {
      GstTimedValue *value = tmp->data;

      gst_timed_value_control_source_set (source, value->timestamp,
          value->value * d.track_value / d.old_track_value);
    }

    g_list_free (values);

  next:
    gst_clear_object (&source);
    gst_object_unref (binding);
  }
}

static void
gst_frame_positioner_update_properties (GstFramePositioner * pos,
    gboolean track_mixing, gint old_track_width, gint old_track_height)
{
  GstCaps *caps;

  if (pos->capsfilter == NULL)
    return;

  if (pos->track_width && pos->track_height &&
      (!track_mixing || !pos->scale_in_compositor)) {
    caps =
        gst_caps_new_simple ("video/x-raw", "width", G_TYPE_INT,
        pos->track_width, "height", G_TYPE_INT, pos->track_height, NULL);
  } else {
    caps = gst_caps_new_empty_simple ("video/x-raw");
  }

  if (pos->fps_n != -1)
    gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, pos->fps_n,
        pos->fps_d, NULL);

  if (pos->par_n != -1)
    gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
        pos->par_n, pos->par_d, NULL);

  if (!pos->track_width || !pos->track_height) {
    GST_INFO_OBJECT (pos, "Track doesn't have a proper size, not "
        "positioning the source");
    goto done;
  } else if (auto_position (pos))
    goto done;

  if (!old_track_height || !old_track_width) {
    GST_DEBUG_OBJECT (pos, "No old track size, can not properly reposition");
    goto done;
  }

  if ((!pos->natural_width || !pos->natural_height) &&
      (!pos->width || !pos->height)) {
    GST_DEBUG_OBJECT (pos, "No natural aspect ratio and no user set "
        " image size, can't not reposition.");
    goto done;
  }

  if (gst_util_fraction_compare (old_track_width, old_track_height,
          pos->track_width, pos->track_height)) {
    GST_INFO_OBJECT (pos, "Not repositioning as track size change didn't"
        " keep the same aspect ratio (previous %dx%d("
        "ratio=%f), new: %dx%d(ratio=%f)",
        old_track_width, old_track_height,
        (gdouble) old_track_width / (gdouble) old_track_height,
        pos->track_width, pos->track_height,
        (gdouble) pos->track_width / (gdouble) pos->track_height);
    goto done;
  }

  reposition_properties (pos, old_track_width, old_track_height);

done:
  GST_DEBUG_OBJECT (caps, "setting caps");

  g_object_set (pos->capsfilter, "caps", caps, NULL);

  gst_caps_unref (caps);
}

static void
sync_properties_from_track (GstFramePositioner * pos, GESTrack * track)
{
  gint width, height;
  gint old_track_width, old_track_height;
  GstCaps *caps;

  g_object_get (track, "restriction-caps", &caps, NULL);

  width = height = 0;

  if (caps && gst_caps_get_size (caps) > 0) {
    GstStructure *structure;

    structure = gst_caps_get_structure (caps, 0);
    if (!gst_structure_get_int (structure, "width", &width))
      width = 0;
    if (!gst_structure_get_int (structure, "height", &height))
      height = 0;
    if (!gst_structure_get_fraction (structure, "framerate", &(pos->fps_n),
            &(pos->fps_d)))
      pos->fps_n = -1;

    if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio",
            &(pos->par_n), &(pos->par_d)))
      pos->par_n = -1;
  }

  old_track_width = pos->track_width;
  old_track_height = pos->track_height;

  pos->track_width = width;
  pos->track_height = height;

  GST_DEBUG_OBJECT (pos, "syncing framerate from caps : %d/%d", pos->fps_n,
      pos->fps_d);
  if (caps)
    gst_caps_unref (caps);

  gst_frame_positioner_update_properties (pos, ges_track_get_mixing (track),
      old_track_width, old_track_height);
}

static void
_track_restriction_changed_cb (GESTrack * track, GParamSpec * arg G_GNUC_UNUSED,
    GstFramePositioner * pos)
{
  sync_properties_from_track (pos, track);
}

static void
set_track (GstFramePositioner * pos)
{
  GESTrack *new_track;

  if (pos->current_track) {
    g_signal_handlers_disconnect_by_func (pos->current_track,
        (GCallback) _track_restriction_changed_cb, pos);
    g_object_weak_unref (G_OBJECT (pos->current_track),
        (GWeakNotify) _weak_notify_cb, pos);
  }

  new_track = ges_track_element_get_track (pos->track_source);
  if (new_track) {
    pos->current_track = new_track;
    g_object_weak_ref (G_OBJECT (new_track), (GWeakNotify) _weak_notify_cb,
        pos);
    GST_DEBUG_OBJECT (pos, "connecting to track : %p", pos->current_track);

    g_signal_connect (pos->current_track, "notify::restriction-caps",
        (GCallback) _track_restriction_changed_cb, pos);
    sync_properties_from_track (pos, pos->current_track);
  } else {
    pos->current_track = NULL;
  }
}

static void
_track_changed_cb (GESTrackElement * trksrc, GParamSpec * arg G_GNUC_UNUSED,
    GstFramePositioner * pos)
{
  set_track (pos);
}

static void
_trk_element_weak_notify_cb (GstFramePositioner * pos, GObject * old)
{
  pos->track_source = NULL;
  gst_object_unref (pos);
}

void
ges_frame_positioner_set_source_and_filter (GstFramePositioner * pos,
    GESTrackElement * trksrc, GstElement * capsfilter)
{
  pos->track_source = trksrc;
  pos->capsfilter = capsfilter;
  pos->current_track = ges_track_element_get_track (trksrc);

  g_object_weak_ref (G_OBJECT (trksrc),
      (GWeakNotify) _trk_element_weak_notify_cb, gst_object_ref (pos));
  g_signal_connect (trksrc, "notify::track", (GCallback) _track_changed_cb,
      pos);
  set_track (pos);
}

static void
gst_frame_positioner_dispose (GObject * object)
{
  GstFramePositioner *pos = GST_FRAME_POSITIONNER (object);

  if (pos->track_source) {
    g_signal_handlers_disconnect_by_func (pos->track_source, _track_changed_cb,
        pos);
    pos->track_source = NULL;
  }

  if (pos->current_track) {
    g_signal_handlers_disconnect_by_func (pos->current_track,
        _track_restriction_changed_cb, pos);
    g_object_weak_unref (G_OBJECT (pos->current_track),
        (GWeakNotify) _weak_notify_cb, pos);
    pos->current_track = NULL;
  }

  G_OBJECT_CLASS (gst_frame_positioner_parent_class)->dispose (object);
}

static void
gst_frame_positioner_class_init (GstFramePositionerClass * klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  GstBaseTransformClass *base_transform_class =
      GST_BASE_TRANSFORM_CLASS (klass);

  GST_DEBUG_CATEGORY_INIT (_framepositioner, "framepositioner",
      GST_DEBUG_FG_YELLOW, "ges frame positioner");

  gst_element_class_add_static_pad_template (GST_ELEMENT_CLASS (klass),
      &gst_frame_positioner_src_template);
  gst_element_class_add_static_pad_template (GST_ELEMENT_CLASS (klass),
      &gst_frame_positioner_sink_template);

  gobject_class->set_property = gst_frame_positioner_set_property;
  gobject_class->get_property = gst_frame_positioner_get_property;
  gobject_class->dispose = gst_frame_positioner_dispose;
  base_transform_class->transform_ip =
      GST_DEBUG_FUNCPTR (gst_frame_positioner_transform_ip);

  /**
   * gstframepositioner:alpha:
   *
   * The desired alpha for the stream.
   */
  properties[PROP_ALPHA] =
      g_param_spec_double ("alpha", "alpha", "alpha of the stream", 0.0, 1.0,
      1.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE);

  /**
   * gstframepositioner:posx:
   *
   * The desired x position for the stream.
   */
  properties[PROP_POSX] =
      g_param_spec_int ("posx", "posx", "x position of the stream", MIN_PIXELS,
      MAX_PIXELS, 0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE);


  /**
   * gstframepositioner:posy:
   *
   * The desired y position for the stream.
   */
  properties[PROP_POSY] =
      g_param_spec_int ("posy", "posy", "y position of the stream", MIN_PIXELS,
      MAX_PIXELS, 0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE);

  /**
   * gstframepositioner:zorder:
   *
   * The desired z order for the stream.
   */
  properties[PROP_ZORDER] =
      g_param_spec_uint ("zorder", "zorder", "z order of the stream", 0,
      G_MAXUINT, 0, G_PARAM_READWRITE);

  /**
   * gesframepositioner:width:
   *
   * The desired width for that source.
   * Set to 0 if size is not mandatory, will be set to width of the current track.
   */
  properties[PROP_WIDTH] =
      g_param_spec_int ("width", "width", "width of the source", 0, MAX_PIXELS,
      0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE);

  /**
   * gesframepositioner:height:
   *
   * The desired height for that source.
   * Set to 0 if size is not mandatory, will be set to height of the current track.
   */
  properties[PROP_HEIGHT] =
      g_param_spec_int ("height", "height", "height of the source", 0,
      MAX_PIXELS, 0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE);

  g_object_class_install_properties (gobject_class, PROP_LAST, properties);

  gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
      "frame positioner", "Metadata",
      "This element provides with tagging facilities",
      "mduponchelle1@gmail.com");
}

static void
gst_frame_positioner_init (GstFramePositioner * framepositioner)
{
  framepositioner->alpha = 1.0;
  framepositioner->posx = 0.0;
  framepositioner->posy = 0.0;
  framepositioner->zorder = 0;
  framepositioner->width = 0;
  framepositioner->height = 0;
  framepositioner->fps_n = -1;
  framepositioner->fps_d = -1;
  framepositioner->track_width = 0;
  framepositioner->track_height = 0;
  framepositioner->capsfilter = NULL;
  framepositioner->track_source = NULL;
  framepositioner->current_track = NULL;
  framepositioner->scale_in_compositor = TRUE;

  framepositioner->par_n = -1;
  framepositioner->par_d = 1;
}

void
gst_frame_positioner_set_property (GObject * object, guint property_id,
    const GValue * value, GParamSpec * pspec)
{
  GstFramePositioner *framepositioner = GST_FRAME_POSITIONNER (object);
  gboolean track_mixing = TRUE;

  if (framepositioner->current_track)
    track_mixing = ges_track_get_mixing (framepositioner->current_track);


  GST_OBJECT_LOCK (framepositioner);
  switch (property_id) {
    case PROP_ALPHA:
      framepositioner->alpha = g_value_get_double (value);
      break;
    case PROP_POSX:
      framepositioner->posx = g_value_get_int (value);
      framepositioner->user_positioned = TRUE;
      break;
    case PROP_POSY:
      framepositioner->posy = g_value_get_int (value);
      framepositioner->user_positioned = TRUE;
      break;
    case PROP_ZORDER:
      framepositioner->zorder = g_value_get_uint (value);
      break;
    case PROP_WIDTH:
      framepositioner->user_positioned = TRUE;
      framepositioner->width = g_value_get_int (value);
      gst_frame_positioner_update_properties (framepositioner, track_mixing,
          0, 0);
      break;
    case PROP_HEIGHT:
      framepositioner->user_positioned = TRUE;
      framepositioner->height = g_value_get_int (value);
      gst_frame_positioner_update_properties (framepositioner, track_mixing,
          0, 0);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
  }
  GST_OBJECT_UNLOCK (framepositioner);
}

void
gst_frame_positioner_get_property (GObject * object, guint property_id,
    GValue * value, GParamSpec * pspec)
{
  GstFramePositioner *pos = GST_FRAME_POSITIONNER (object);
  gint real_width, real_height;

  switch (property_id) {
    case PROP_ALPHA:
      g_value_set_double (value, pos->alpha);
      break;
    case PROP_POSX:
      g_value_set_int (value, round (pos->posx));
      break;
    case PROP_POSY:
      g_value_set_int (value, round (pos->posy));
      break;
    case PROP_ZORDER:
      g_value_set_uint (value, pos->zorder);
      break;
    case PROP_WIDTH:
      if (pos->scale_in_compositor) {
        g_value_set_int (value, round (pos->width));
      } else {
        real_width =
            pos->width > 0 ? round (pos->width) : round (pos->track_width);
        g_value_set_int (value, real_width);
      }
      break;
    case PROP_HEIGHT:
      if (pos->scale_in_compositor) {
        g_value_set_int (value, round (pos->height));
      } else {
        real_height =
            pos->height > 0 ? round (pos->height) : round (pos->track_height);
        g_value_set_int (value, real_height);
      }
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
  }
}

GType
gst_frame_positioner_meta_api_get_type (void)
{
  static volatile GType type;
  static const gchar *tags[] = { "video", NULL };

  if (g_once_init_enter (&type)) {
    GType _type = gst_meta_api_type_register ("GstFramePositionerApi", tags);
    g_once_init_leave (&type, _type);
  }
  return type;
}

static const GstMetaInfo *
gst_frame_positioner_get_info (void)
{
  static const GstMetaInfo *meta_info = NULL;

  if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
    const GstMetaInfo *meta =
        gst_meta_register (gst_frame_positioner_meta_api_get_type (),
        "GstFramePositionerMeta",
        sizeof (GstFramePositionerMeta), gst_frame_positioner_meta_init,
        NULL,
        gst_frame_positioner_meta_transform);
    g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) meta);
  }
  return meta_info;
}

static gboolean
gst_frame_positioner_meta_init (GstMeta * meta, gpointer params,
    GstBuffer * buffer)
{
  GstFramePositionerMeta *smeta;

  smeta = (GstFramePositionerMeta *) meta;

  smeta->alpha = 0.0;
  smeta->posx = smeta->posy = smeta->height = smeta->width = 0;
  smeta->zorder = 0;

  return TRUE;
}

static gboolean
gst_frame_positioner_meta_transform (GstBuffer * dest, GstMeta * meta,
    GstBuffer * buffer, GQuark type, gpointer data)
{
  GstFramePositionerMeta *dmeta, *smeta;

  smeta = (GstFramePositionerMeta *) meta;

  if (GST_META_TRANSFORM_IS_COPY (type)) {
    /* only copy if the complete data is copied as well */
    dmeta =
        (GstFramePositionerMeta *) gst_buffer_add_meta (dest,
        gst_frame_positioner_get_info (), NULL);
    dmeta->alpha = smeta->alpha;
    dmeta->posx = smeta->posx;
    dmeta->posy = smeta->posy;
    dmeta->width = smeta->width;
    dmeta->height = smeta->height;
    dmeta->zorder = smeta->zorder;
  }

  return TRUE;
}

static GstFlowReturn
gst_frame_positioner_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
  GstFramePositionerMeta *meta;
  GstFramePositioner *framepositioner = GST_FRAME_POSITIONNER (trans);
  GstClockTime timestamp = GST_BUFFER_PTS (buf);

  if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
    gst_object_sync_values (GST_OBJECT (trans), timestamp);
  }

  meta =
      (GstFramePositionerMeta *) gst_buffer_add_meta (buf,
      gst_frame_positioner_get_info (), NULL);

  GST_OBJECT_LOCK (framepositioner);
  meta->alpha = framepositioner->alpha;
  meta->posx = round (framepositioner->posx);
  meta->posy = round (framepositioner->posy);
  meta->width = round (framepositioner->width);
  meta->height = round (framepositioner->height);
  meta->zorder = framepositioner->zorder;
  GST_OBJECT_UNLOCK (framepositioner);

  return GST_FLOW_OK;
}