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
|
/* Libvisual-plugins - Standard plugins for libvisual
*
* Copyright (C) 2004, 2005, 2006 Dennis Smit <ds@nerds-incorporated.org>
*
* Authors: Dennis Smit <ds@nerds-incorporated.org>
*
* $Id: actor_gstreamer.c,v 1.9 2006/01/27 20:19:16 synap Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <gettext.h>
#include <libvisual/libvisual.h>
#include <gst/gst.h>
#define BARS 16
typedef struct {
VisVideo *old_video;
GstPipeline *pipe;
} GstreamerPrivate;
static void have_data (GstElement *sink, GstBuffer *buffer, gpointer data);
int act_gstreamer_init (VisPluginData *plugin);
int act_gstreamer_cleanup (VisPluginData *plugin);
int act_gstreamer_requisition (VisPluginData *plugin, int *width, int *height);
int act_gstreamer_dimension (VisPluginData *plugin, VisVideo *video, int width, int height);
int act_gstreamer_events (VisPluginData *plugin, VisEventQueue *events);
VisPalette *act_gstreamer_palette (VisPluginData *plugin);
int act_gstreamer_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio);
VISUAL_PLUGIN_API_VERSION_VALIDATOR
const VisPluginInfo *get_plugin_info (int *count)
{
static VisActorPlugin actor[] = {{
.requisition = act_gstreamer_requisition,
.palette = act_gstreamer_palette,
.render = act_gstreamer_render,
.vidoptions.depth = VISUAL_VIDEO_DEPTH_24BIT
}};
static VisPluginInfo info[] = {{
.type = VISUAL_PLUGIN_TYPE_ACTOR,
.plugname = "gstreamer",
.name = "libvisual gstreamer",
.author = N_("Dennis Smit <synap@yourbase.nl>"),
.version = "0.1",
.about = N_("Libvisual gstreamer plugin"),
.help = N_("Capable of using gstreamer to play video, or do effects using the gstreamer pipeline"),
.license = VISUAL_PLUGIN_LICENSE_LGPL,
.init = act_gstreamer_init,
.cleanup = act_gstreamer_cleanup,
.events = act_gstreamer_events,
.plugin = VISUAL_OBJECT (&actor[0])
}};
*count = sizeof (info) / sizeof (*info);
return info;
}
int act_gstreamer_init (VisPluginData *plugin)
{
GstreamerPrivate *priv;
#if ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
#endif
priv = visual_mem_new0 (GstreamerPrivate, 1);
visual_object_set_private (VISUAL_OBJECT (plugin), priv);
return 0;
}
int act_gstreamer_cleanup (VisPluginData *plugin)
{
GstreamerPrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
visual_mem_free (priv);
return 0;
}
int act_gstreamer_requisition (VisPluginData *plugin, int *width, int *height)
{
return 0;
}
int act_gstreamer_dimension (VisPluginData *plugin, VisVideo *video, int width, int height)
{
visual_video_set_dimension (video, width, height);
return 0;
}
int act_gstreamer_events (VisPluginData *plugin, VisEventQueue *events)
{
VisEvent ev;
while (visual_event_queue_poll (events, &ev)) {
switch (ev.type) {
case VISUAL_EVENT_RESIZE:
act_gstreamer_dimension (plugin, ev.event.resize.video,
ev.event.resize.width, ev.event.resize.height);
break;
default:
break;
}
}
return 0;
}
VisPalette *act_gstreamer_palette (VisPluginData *plugin)
{
return NULL;
}
int act_gstreamer_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio)
{
GstreamerPrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
static int playing = 0;
if (playing == 0) {
char pipe[1024];
gst_init (NULL, NULL);
/*
snprintf(pipe, 1024, "filesrc location=%s ! decodebin ! ffmpegcolorspace ! "
"videoscale ! video/x-raw-rgb,bpp=32,depth=32,width=%d,height=%d,"
"red_mask=0xff000000,green_mask=0x00ff0000,blue_mask=0x0000ff00 !"
"fakesink name=sink sync=true", "test.mpg", video->width, video->height);
*/
snprintf(pipe, 1024, "filesrc location=%s ! decodebin ! ffmpegcolorspace ! "
"video/x-raw-rgb,bpp=24,depth=24 ! "
"fakesink name=sink signal-handoffs=true", "test.mpg");
GError *err = NULL;
priv->pipe = gst_parse_launch (pipe, &err);
if (err)
g_print ("FUCK UUU %s\n", err->message);
printf ("ja hooradfh\n");
gst_element_set_state (GST_ELEMENT (priv->pipe), GST_STATE_PLAYING);
g_signal_connect (gst_bin_get_by_name_recurse_up (GST_BIN (priv->pipe), "sink"),
"handoff", G_CALLBACK (have_data), video);
playing = 1;
}
// g_signal_handlers_disconnect_by_func (gst_bin_get_by_name_recurse_up (GST_BIN (priv->pipe), "sink"),
// G_CALLBACK (have_data), priv->old_video);
gst_bin_iterate (GST_BIN (priv->pipe));
priv->old_video = video;
return 0;
}
static void have_data (GstElement *sink, GstBuffer *buffer, gpointer data)
{
VisVideo *video = data;
uint32_t *dest = visual_video_get_pixels (video);
uint32_t *src = (uint32_t *) GST_BUFFER_DATA (buffer);
printf ("ja hoor\n");
visual_mem_copy (dest, src, GST_BUFFER_SIZE (buffer));
}
|