Blame tests/examples/gl/clutter/clutteractortee.c

Packit 971217
/*
Packit 971217
 * GStreamer
Packit 971217
 * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#define GLIB_DISABLE_DEPRECATION_WARNINGS
Packit 971217
#define CLUTTER_VERSION_MIN_REQUIRED CLUTTER_VERSION_1_8
Packit 971217
Packit 971217
#include <X11/Xlib.h>
Packit 971217
#include <X11/extensions/Xcomposite.h>
Packit 971217
#include <clutter/clutter.h>
Packit 971217
#include <clutter/x11/clutter-x11.h>
Packit 971217
#include <clutter/glx/clutter-glx.h>
Packit 971217
#include <gst/gst.h>
Packit 971217
#include <gst/video/videooverlay.h>
Packit 971217
Packit 971217
#define ROWS 3
Packit 971217
#define COLS 3
Packit 971217
#define N_ACTORS ROWS*COLS
Packit 971217
#define W 160
Packit 971217
#define H 120
Packit 971217
Packit 971217
struct GstGLClutterActor_
Packit 971217
{
Packit 971217
  Window win;
Packit 971217
  Window root;
Packit 971217
  ClutterActor *texture;
Packit 971217
  ClutterActor *stage;
Packit 971217
};
Packit 971217
Packit 971217
typedef struct GstGLClutterActor_ GstGLClutterActor;
Packit 971217
Packit 971217
static gboolean
Packit 971217
create_actor (GstGLClutterActor * actor)
Packit 971217
{
Packit 971217
  static gint xpos = 0;
Packit 971217
  static gint ypos = 0;
Packit 971217
  actor->texture = g_object_new (CLUTTER_X11_TYPE_TEXTURE_PIXMAP,
Packit 971217
      "window", actor->win, "automatic-updates", TRUE, NULL);
Packit 971217
  clutter_container_add_actor (CLUTTER_CONTAINER (actor->stage),
Packit 971217
      actor->texture);
Packit 971217
  clutter_actor_set_position (actor->texture, xpos, ypos);
Packit 971217
Packit 971217
  if (xpos > (COLS - 1) * W) {
Packit 971217
    xpos = 0;
Packit 971217
    ypos += H + 1;
Packit 971217
  } else
Packit 971217
    xpos += W + 1;
Packit 971217
  clutter_actor_show (actor->texture);
Packit 971217
Packit 971217
  return FALSE;
Packit 971217
}
Packit 971217
Packit 971217
static GstBusSyncReply
Packit 971217
create_window (GstBus * bus, GstMessage * message, gpointer data)
Packit 971217
{
Packit 971217
  GstGLClutterActor **actor = (GstGLClutterActor **) data;
Packit 971217
  static gint count = 0;
Packit 971217
  static GMutex mutex;
Packit 971217
  // ignore anything but 'prepare-window-handle' element messages
Packit 971217
  if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
Packit 971217
    return GST_BUS_PASS;
Packit 971217
Packit 971217
  if (!gst_is_video_overlay_prepare_window_handle_message (message))
Packit 971217
    return GST_BUS_PASS;
Packit 971217
Packit 971217
  g_mutex_lock (&mutex);
Packit 971217
Packit 971217
  if (count < N_ACTORS) {
Packit 971217
    g_message ("adding actor %d", count);
Packit 971217
    gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC
Packit 971217
            (message)), actor[count]->win);
Packit 971217
    clutter_threads_add_idle ((GSourceFunc) create_actor, actor[count]);
Packit 971217
    count++;
Packit 971217
  }
Packit 971217
Packit 971217
  g_mutex_unlock (&mutex);
Packit 971217
Packit 971217
  gst_message_unref (message);
Packit 971217
  return GST_BUS_DROP;
Packit 971217
}
Packit 971217
Packit 971217
#if 0
Packit 971217
void
Packit 971217
apply_fx (GstElement * element, const gchar * fx)
Packit 971217
{
Packit 971217
  GEnumClass *p_class;
Packit 971217
Packit 971217
  /* from fxtest ;) */
Packit 971217
  /* heeeellppppp!! */
Packit 971217
  p_class =
Packit 971217
      G_PARAM_SPEC_ENUM (g_object_class_find_property (G_OBJECT_GET_CLASS
Packit 971217
          (G_OBJECT (data)), "effect")
Packit 971217
      )->enum_class;
Packit 971217
Packit 971217
  g_print ("setting: %s - %s\n", fx, g_enum_get_value_by_nick (p_class,
Packit 971217
          fx)->value_name);
Packit 971217
  g_object_set (G_OBJECT (element), "effect", g_enum_get_value_by_nick (p_class,
Packit 971217
          fx)->value, NULL);
Packit 971217
}
Packit 971217
#endif
Packit 971217
Packit 971217
int
Packit 971217
main (int argc, char *argv[])
Packit 971217
{
Packit 971217
  GstPipeline *pipeline;
Packit 971217
  GstBus *bus;
Packit 971217
Packit 971217
  GstElement *srcbin;
Packit 971217
  GstElement *tee;
Packit 971217
  GstElement *queue[N_ACTORS], *sink[N_ACTORS];
Packit 971217
  GstElement *upload[N_ACTORS];
Packit 971217
/*
Packit 971217
  GstElement *effect[N_ACTORS];
Packit 971217
*/
Packit 971217
  ClutterActor *stage;
Packit 971217
  GstGLClutterActor *actor[N_ACTORS];
Packit 971217
  Display *disp;
Packit 971217
  Window stage_win;
Packit 971217
  const gchar *desc;
Packit 971217
  gint i;
Packit 971217
  gint ok = FALSE;
Packit 971217
  ClutterInitError clutter_err = CLUTTER_INIT_ERROR_UNKNOWN;
Packit 971217
Packit 971217
  clutter_err = clutter_init (&argc, &argv);
Packit 971217
  if (clutter_err != CLUTTER_INIT_SUCCESS)
Packit 971217
    g_warning ("Failed to initalize clutter: %d\n", clutter_err);
Packit 971217
Packit 971217
  gst_init (&argc, &argv);
Packit 971217
Packit 971217
  disp = clutter_x11_get_default_display ();
Packit 971217
  if (!clutter_x11_has_composite_extension ()) {
Packit 971217
    g_error ("XComposite extension missing");
Packit 971217
  }
Packit 971217
Packit 971217
  stage = clutter_stage_get_default ();
Packit 971217
  clutter_actor_set_size (CLUTTER_ACTOR (stage),
Packit 971217
      W * COLS + (COLS - 1), H * ROWS + (ROWS - 1));
Packit 971217
Packit 971217
  stage_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
Packit 971217
  XCompositeRedirectSubwindows (disp, stage_win, CompositeRedirectManual);
Packit 971217
Packit 971217
  for (i = 0; i < N_ACTORS; i++) {
Packit 971217
    actor[i] = g_new0 (GstGLClutterActor, 1);
Packit 971217
    actor[i]->stage = stage;
Packit 971217
    actor[i]->win = XCreateSimpleWindow (disp, stage_win, 0, 0, W, H, 0, 0, 0);
Packit 971217
    XMapRaised (disp, actor[i]->win);
Packit 971217
    XSync (disp, FALSE);
Packit 971217
  }
Packit 971217
/*
Packit 971217
  desc = g_strdup_printf ("v4l2src ! "
Packit 971217
                          "video/x-raw, width=640, height=480, framerate=30/1 ! "
Packit 971217
                          "videoscale !"
Packit 971217
                          "video/x-raw, width=%d, height=%d ! "
Packit 971217
                          "identity", W, H);
Packit 971217
*/
Packit 971217
  desc = g_strdup_printf ("videotestsrc ! "
Packit 971217
      "video/x-raw, format=RGB, width=%d, height=%d !" "identity", W, H);
Packit 971217
  pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
Packit 971217
Packit 971217
  srcbin = gst_parse_bin_from_description (desc, TRUE, NULL);
Packit 971217
  if (!srcbin)
Packit 971217
    g_error ("Source bin creation failed");
Packit 971217
Packit 971217
  tee = gst_element_factory_make ("tee", NULL);
Packit 971217
Packit 971217
  gst_bin_add_many (GST_BIN (pipeline), srcbin, tee, NULL);
Packit 971217
Packit 971217
  for (i = 0; i < N_ACTORS; i++) {
Packit 971217
    queue[i] = gst_element_factory_make ("queue", NULL);
Packit 971217
    upload[i] = gst_element_factory_make ("glupload", NULL);
Packit 971217
/*      effect[i] = gst_element_factory_make ("gleffects", NULL); */
Packit 971217
    sink[i] = gst_element_factory_make ("glimagesink", NULL);
Packit 971217
/*    gst_bin_add_many (GST_BIN (pipeline),
Packit 971217
        queue[i], upload[i], effect[i], sink[i], NULL); */
Packit 971217
    gst_bin_add_many (GST_BIN (pipeline), queue[i], upload[i], sink[i], NULL);
Packit 971217
  }
Packit 971217
Packit 971217
  gst_element_link_many (srcbin, tee, NULL);
Packit 971217
Packit 971217
  for (i = 0; i < N_ACTORS; i++) {
Packit 971217
    ok |=
Packit 971217
//        gst_element_link_many (tee, queue[i], upload[i], effect[i], sink[i],
Packit 971217
        gst_element_link_many (tee, queue[i], upload[i], sink[i], NULL);
Packit 971217
  }
Packit 971217
Packit 971217
  if (!ok)
Packit 971217
    g_error ("Failed to link one or more elements");
Packit 971217
Packit 971217
/*
Packit 971217
  for (i = 0; i < N_ACTORS; i++) {
Packit 971217
    g_message ("setting effect %d on %s", i + 1,
Packit 971217
        gst_element_get_name (effect[i]));
Packit 971217
    g_object_set (G_OBJECT (effect[i]), "effect", i + 1, NULL);
Packit 971217
  }
Packit 971217
*/
Packit 971217
Packit 971217
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
Packit 971217
Packit 971217
  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, actor,
Packit 971217
      NULL);
Packit 971217
  gst_object_unref (bus);
Packit 971217
Packit 971217
  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
Packit 971217
Packit 971217
  clutter_actor_show_all (stage);
Packit 971217
Packit 971217
  clutter_main ();
Packit 971217
Packit 971217
  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
Packit 971217
  gst_object_unref (pipeline);
Packit 971217
Packit 971217
  return 0;
Packit 971217
}