2 * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gst/base/gstadapter.h>
26 #include <gst/video/video.h>
27 #include <gst/audio/audio.h>
28 #include <libvisual/libvisual.h>
30 #define GST_TYPE_VISUAL (gst_visual_get_type())
31 #define GST_IS_VISUAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VISUAL))
32 #define GST_VISUAL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VISUAL,GstVisual))
33 #define GST_IS_VISUAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VISUAL))
34 #define GST_VISUAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VISUAL,GstVisualClass))
35 #define GST_VISUAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VISUAL, GstVisualClass))
37 typedef struct _GstVisual GstVisual;
38 typedef struct _GstVisualClass GstVisualClass;
40 GST_DEBUG_CATEGORY_STATIC (libvisual_debug);
41 #define GST_CAT_DEFAULT (libvisual_debug)
43 /* amounf of samples before we can feed libvisual */
44 #define VISUAL_SAMPLES 512
46 #define DEFAULT_WIDTH 320
47 #define DEFAULT_HEIGHT 240
48 #define DEFAULT_FPS_N 25
49 #define DEFAULT_FPS_D 1
65 /* audio/video state */
67 gint rate; /* Input samplerate */
70 /* framerate numerator & denominator */
75 GstClockTime duration;
78 /* samples per frame based on caps */
85 /* QoS stuff *//* with LOCK */
87 GstClockTime earliest_time;
90 struct _GstVisualClass
92 GstElementClass parent_class;
97 GType gst_visual_get_type (void);
100 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
103 GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN "; "
104 #if G_BYTE_ORDER == G_BIG_ENDIAN
105 GST_VIDEO_CAPS_RGB "; "
107 GST_VIDEO_CAPS_BGR "; "
109 GST_VIDEO_CAPS_RGB_16)
112 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
115 GST_STATIC_CAPS ("audio/x-raw-int, "
118 "endianness = (int) BYTE_ORDER, "
119 "signed = (boolean) TRUE, " "channels = (int) { 1, 2 }, "
120 #if defined(VISUAL_API_VERSION) && VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000
121 "rate = (int) { 8000, 11250, 22500, 32000, 44100, 48000, 96000 }"
123 "rate = (int) [ 1000, MAX ]"
129 static void gst_visual_class_init (gpointer g_class, gpointer class_data);
130 static void gst_visual_init (GstVisual * visual);
131 static void gst_visual_dispose (GObject * object);
133 static GstStateChangeReturn gst_visual_change_state (GstElement * element,
134 GstStateChange transition);
135 static GstFlowReturn gst_visual_chain (GstPad * pad, GstBuffer * buffer);
136 static gboolean gst_visual_sink_event (GstPad * pad, GstEvent * event);
137 static gboolean gst_visual_src_event (GstPad * pad, GstEvent * event);
139 static gboolean gst_visual_src_query (GstPad * pad, GstQuery * query);
141 static gboolean gst_visual_sink_setcaps (GstPad * pad, GstCaps * caps);
142 static gboolean gst_visual_src_setcaps (GstPad * pad, GstCaps * caps);
143 static GstCaps *gst_visual_getcaps (GstPad * pad);
144 static void libvisual_log_handler (const char *message, const char *funcname,
147 static GstElementClass *parent_class = NULL;
150 gst_visual_get_type (void)
152 static GType type = 0;
154 if (G_UNLIKELY (type == 0)) {
155 static const GTypeInfo info = {
156 sizeof (GstVisualClass),
159 gst_visual_class_init,
164 (GInstanceInitFunc) gst_visual_init,
167 type = g_type_register_static (GST_TYPE_ELEMENT, "GstVisual", &info, 0);
173 libvisual_log_handler (const char *message, const char *funcname, void *priv)
175 GST_CAT_LEVEL_LOG (libvisual_debug, (GstDebugLevel) (priv), NULL, "%s - %s",
180 gst_visual_class_init (gpointer g_class, gpointer class_data)
182 GstVisualClass *klass = GST_VISUAL_CLASS (g_class);
183 GstElementClass *element = GST_ELEMENT_CLASS (g_class);
184 GObjectClass *object = G_OBJECT_CLASS (g_class);
186 klass->plugin = class_data;
188 element->change_state = gst_visual_change_state;
190 if (class_data == NULL) {
191 parent_class = g_type_class_peek_parent (g_class);
193 char *longname = g_strdup_printf ("libvisual %s plugin v.%s",
194 klass->plugin->info->name, klass->plugin->info->version);
196 /* FIXME: improve to only register what plugin supports? */
197 gst_element_class_add_static_pad_template (element, &src_template);
198 gst_element_class_add_static_pad_template (element, &sink_template);
199 gst_element_class_set_details_simple (element,
200 longname, "Visualization",
201 klass->plugin->info->about, "Benjamin Otte <otte@gnome.org>");
206 object->dispose = gst_visual_dispose;
210 gst_visual_init (GstVisual * visual)
212 /* create the sink and src pads */
213 visual->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
214 gst_pad_set_setcaps_function (visual->sinkpad, gst_visual_sink_setcaps);
215 gst_pad_set_chain_function (visual->sinkpad, gst_visual_chain);
216 gst_pad_set_event_function (visual->sinkpad, gst_visual_sink_event);
217 gst_element_add_pad (GST_ELEMENT (visual), visual->sinkpad);
219 visual->srcpad = gst_pad_new_from_static_template (&src_template, "src");
220 gst_pad_set_setcaps_function (visual->srcpad, gst_visual_src_setcaps);
221 gst_pad_set_getcaps_function (visual->srcpad, gst_visual_getcaps);
222 gst_pad_set_event_function (visual->srcpad, gst_visual_src_event);
223 gst_pad_set_query_function (visual->srcpad, gst_visual_src_query);
224 gst_element_add_pad (GST_ELEMENT (visual), visual->srcpad);
226 visual->adapter = gst_adapter_new ();
230 gst_visual_clear_actors (GstVisual * visual)
233 visual_object_unref (VISUAL_OBJECT (visual->actor));
234 visual->actor = NULL;
237 visual_object_unref (VISUAL_OBJECT (visual->video));
238 visual->video = NULL;
241 visual_object_unref (VISUAL_OBJECT (visual->audio));
242 visual->audio = NULL;
247 gst_visual_dispose (GObject * object)
249 GstVisual *visual = GST_VISUAL (object);
251 if (visual->adapter) {
252 g_object_unref (visual->adapter);
253 visual->adapter = NULL;
255 gst_visual_clear_actors (visual);
257 GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
261 gst_visual_reset (GstVisual * visual)
263 gst_adapter_clear (visual->adapter);
264 gst_segment_init (&visual->segment, GST_FORMAT_UNDEFINED);
266 GST_OBJECT_LOCK (visual);
267 visual->proportion = 1.0;
268 visual->earliest_time = -1;
269 GST_OBJECT_UNLOCK (visual);
273 gst_visual_getcaps (GstPad * pad)
276 GstVisual *visual = GST_VISUAL (gst_pad_get_parent (pad));
279 if (!visual->actor) {
280 ret = gst_caps_copy (gst_pad_get_pad_template_caps (visual->srcpad));
284 ret = gst_caps_new_empty ();
285 depths = visual_actor_get_supported_depth (visual->actor);
287 /* FIXME: set an error */
290 if (depths == VISUAL_VIDEO_DEPTH_GL) {
291 /* We can't handle GL only plugins */
295 GST_DEBUG_OBJECT (visual, "libvisual plugin supports depths %u (0x%04x)",
297 /* if (depths & VISUAL_VIDEO_DEPTH_32BIT) Always supports 32bit output */
298 gst_caps_append (ret, gst_caps_from_string (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN));
300 if (depths & VISUAL_VIDEO_DEPTH_24BIT) {
301 #if G_BYTE_ORDER == G_BIG_ENDIAN
302 gst_caps_append (ret, gst_caps_from_string (GST_VIDEO_CAPS_RGB));
304 gst_caps_append (ret, gst_caps_from_string (GST_VIDEO_CAPS_BGR));
307 if (depths & VISUAL_VIDEO_DEPTH_16BIT) {
308 gst_caps_append (ret, gst_caps_from_string (GST_VIDEO_CAPS_RGB_16));
313 GST_DEBUG_OBJECT (visual, "returning caps %" GST_PTR_FORMAT, ret);
314 gst_object_unref (visual);
319 gst_visual_src_setcaps (GstPad * pad, GstCaps * caps)
321 GstVisual *visual = GST_VISUAL (gst_pad_get_parent (pad));
322 GstStructure *structure;
325 structure = gst_caps_get_structure (caps, 0);
327 GST_DEBUG_OBJECT (visual, "src pad got caps %" GST_PTR_FORMAT, caps);
329 if (!gst_structure_get_int (structure, "width", &visual->width))
331 if (!gst_structure_get_int (structure, "height", &visual->height))
333 if (!gst_structure_get_int (structure, "bpp", &depth))
335 if (!gst_structure_get_fraction (structure, "framerate", &visual->fps_n,
339 visual_video_set_depth (visual->video,
340 visual_video_depth_enum_from_value (depth));
341 visual_video_set_dimension (visual->video, visual->width, visual->height);
342 pitch = GST_ROUND_UP_4 (visual->width * visual->video->bpp);
343 visual_video_set_pitch (visual->video, pitch);
344 visual_actor_video_negotiate (visual->actor, 0, FALSE, FALSE);
346 /* precalc some values */
347 visual->outsize = visual->video->height * pitch;
349 gst_util_uint64_scale_int (visual->rate, visual->fps_d, visual->fps_n);
351 gst_util_uint64_scale_int (GST_SECOND, visual->fps_d, visual->fps_n);
353 gst_object_unref (visual);
359 GST_DEBUG_OBJECT (visual, "error parsing caps");
360 gst_object_unref (visual);
366 gst_visual_sink_setcaps (GstPad * pad, GstCaps * caps)
368 GstVisual *visual = GST_VISUAL (gst_pad_get_parent (pad));
369 GstStructure *structure;
371 structure = gst_caps_get_structure (caps, 0);
373 gst_structure_get_int (structure, "channels", &visual->channels);
374 gst_structure_get_int (structure, "rate", &visual->rate);
376 /* this is how many samples we need to fill one frame at the requested
378 if (visual->fps_n != 0) {
380 gst_util_uint64_scale_int (visual->rate, visual->fps_d, visual->fps_n);
382 visual->bps = visual->channels * sizeof (gint16);
384 gst_object_unref (visual);
389 gst_vis_src_negotiate (GstVisual * visual)
391 GstCaps *othercaps, *target;
392 GstStructure *structure;
395 caps = gst_pad_get_caps (visual->srcpad);
397 /* see what the peer can do */
398 othercaps = gst_pad_peer_get_caps (visual->srcpad);
400 target = gst_caps_intersect (othercaps, caps);
401 gst_caps_unref (othercaps);
402 gst_caps_unref (caps);
404 if (gst_caps_is_empty (target))
407 gst_caps_truncate (target);
409 /* need a copy, we'll be modifying it when fixating */
410 target = gst_caps_copy (caps);
411 gst_caps_unref (caps);
414 /* fixate in case something is not fixed. This does nothing if the value is
415 * already fixed. For video we always try to fixate to something like
416 * 320x240x25 by convention. */
417 structure = gst_caps_get_structure (target, 0);
418 gst_structure_fixate_field_nearest_int (structure, "width", DEFAULT_WIDTH);
419 gst_structure_fixate_field_nearest_int (structure, "height", DEFAULT_HEIGHT);
420 gst_structure_fixate_field_nearest_fraction (structure, "framerate",
421 DEFAULT_FPS_N, DEFAULT_FPS_D);
423 gst_pad_set_caps (visual->srcpad, target);
424 gst_caps_unref (target);
431 GST_ELEMENT_ERROR (visual, STREAM, FORMAT, (NULL),
432 ("could not negotiate output format"));
433 gst_caps_unref (target);
439 gst_visual_sink_event (GstPad * pad, GstEvent * event)
444 visual = GST_VISUAL (gst_pad_get_parent (pad));
446 switch (GST_EVENT_TYPE (event)) {
447 case GST_EVENT_FLUSH_START:
448 res = gst_pad_push_event (visual->srcpad, event);
450 case GST_EVENT_FLUSH_STOP:
451 /* reset QoS and adapter. */
452 gst_visual_reset (visual);
453 res = gst_pad_push_event (visual->srcpad, event);
455 case GST_EVENT_NEWSEGMENT:
459 gint64 start, stop, time;
462 /* the newsegment values are used to clip the input samples
463 * and to convert the incomming timestamps to running time so
465 gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
466 &start, &stop, &time);
468 /* now configure the values */
469 gst_segment_set_newsegment_full (&visual->segment, update,
470 rate, arate, format, start, stop, time);
473 res = gst_pad_push_event (visual->srcpad, event);
477 res = gst_pad_push_event (visual->srcpad, event);
481 gst_object_unref (visual);
486 gst_visual_src_event (GstPad * pad, GstEvent * event)
491 visual = GST_VISUAL (gst_pad_get_parent (pad));
493 switch (GST_EVENT_TYPE (event)) {
497 GstClockTimeDiff diff;
498 GstClockTime timestamp;
500 gst_event_parse_qos (event, &proportion, &diff, ×tamp);
502 /* save stuff for the _chain function */
503 GST_OBJECT_LOCK (visual);
504 visual->proportion = proportion;
506 /* we're late, this is a good estimate for next displayable
507 * frame (see part-qos.txt) */
508 visual->earliest_time = timestamp + 2 * diff + visual->duration;
510 visual->earliest_time = timestamp + diff;
512 GST_OBJECT_UNLOCK (visual);
514 res = gst_pad_push_event (visual->sinkpad, event);
518 res = gst_pad_push_event (visual->sinkpad, event);
522 gst_object_unref (visual);
527 gst_visual_src_query (GstPad * pad, GstQuery * query)
532 visual = GST_VISUAL (gst_pad_get_parent (pad));
534 switch (GST_QUERY_TYPE (query)) {
535 case GST_QUERY_LATENCY:
537 /* We need to send the query upstream and add the returned latency to our
539 GstClockTime min_latency, max_latency;
541 GstClockTime our_latency;
544 if ((res = gst_pad_peer_query (visual->sinkpad, query))) {
545 gst_query_parse_latency (query, &us_live, &min_latency, &max_latency);
547 GST_DEBUG_OBJECT (visual, "Peer latency: min %"
548 GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
549 GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
551 /* the max samples we must buffer */
552 max_samples = MAX (VISUAL_SAMPLES, visual->spf);
554 gst_util_uint64_scale_int (max_samples, GST_SECOND, visual->rate);
556 GST_DEBUG_OBJECT (visual, "Our latency: %" GST_TIME_FORMAT,
557 GST_TIME_ARGS (our_latency));
559 /* we add some latency but only if we need to buffer more than what
560 * upstream gives us */
561 min_latency += our_latency;
562 if (max_latency != -1)
563 max_latency += our_latency;
565 GST_DEBUG_OBJECT (visual, "Calculated total latency : min %"
566 GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
567 GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
569 gst_query_set_latency (query, TRUE, min_latency, max_latency);
574 res = gst_pad_peer_query (visual->sinkpad, query);
578 gst_object_unref (visual);
583 /* allocate and output buffer, if no format was negotiated, this
584 * function will negotiate one. After calling this function, a
585 * reverse negotiation could have happened. */
587 get_buffer (GstVisual * visual, GstBuffer ** outbuf)
591 /* we don't know an output format yet, pick one */
592 if (GST_PAD_CAPS (visual->srcpad) == NULL) {
593 if (!gst_vis_src_negotiate (visual))
594 return GST_FLOW_NOT_NEGOTIATED;
597 GST_DEBUG_OBJECT (visual, "allocating output buffer with caps %"
598 GST_PTR_FORMAT, GST_PAD_CAPS (visual->srcpad));
600 /* now allocate a buffer with the last negotiated format.
601 * Downstream could renegotiate a new format, which will trigger
602 * our setcaps function on the source pad. */
604 gst_pad_alloc_buffer_and_set_caps (visual->srcpad,
605 GST_BUFFER_OFFSET_NONE, visual->outsize,
606 GST_PAD_CAPS (visual->srcpad), outbuf);
608 /* no buffer allocated, we don't care why. */
609 if (ret != GST_FLOW_OK)
616 gst_visual_chain (GstPad * pad, GstBuffer * buffer)
618 GstBuffer *outbuf = NULL;
620 GstVisual *visual = GST_VISUAL (gst_pad_get_parent (pad));
621 GstFlowReturn ret = GST_FLOW_OK;
624 GST_DEBUG_OBJECT (visual, "chain function called");
626 /* If we don't have an output format yet, preallocate a buffer to try and
628 if (GST_PAD_CAPS (visual->srcpad) == NULL) {
629 ret = get_buffer (visual, &outbuf);
630 if (ret != GST_FLOW_OK) {
631 gst_buffer_unref (buffer);
636 /* resync on DISCONT */
637 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) {
638 gst_adapter_clear (visual->adapter);
641 GST_DEBUG_OBJECT (visual,
642 "Input buffer has %d samples, time=%" G_GUINT64_FORMAT,
643 GST_BUFFER_SIZE (buffer) / visual->bps, GST_BUFFER_TIMESTAMP (buffer));
645 gst_adapter_push (visual->adapter, buffer);
650 guint64 dist, timestamp;
652 GST_DEBUG_OBJECT (visual, "processing buffer");
654 avail = gst_adapter_available (visual->adapter);
655 GST_DEBUG_OBJECT (visual, "avail now %u", avail);
657 /* we need at least VISUAL_SAMPLES samples */
658 if (avail < VISUAL_SAMPLES * visual->bps)
661 /* we need at least enough samples to make one frame */
662 if (avail < visual->spf * visual->bps)
665 /* get timestamp of the current adapter byte */
666 timestamp = gst_adapter_prev_timestamp (visual->adapter, &dist);
667 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
668 /* convert bytes to time */
670 timestamp += gst_util_uint64_scale_int (dist, GST_SECOND, visual->rate);
673 if (timestamp != -1) {
676 /* QoS is done on running time */
677 qostime = gst_segment_to_running_time (&visual->segment, GST_FORMAT_TIME,
679 qostime += visual->duration;
681 GST_OBJECT_LOCK (visual);
682 /* check for QoS, don't compute buffers that are known to be late */
683 need_skip = visual->earliest_time != -1 &&
684 qostime <= visual->earliest_time;
685 GST_OBJECT_UNLOCK (visual);
688 GST_WARNING_OBJECT (visual,
689 "QoS: skip ts: %" GST_TIME_FORMAT ", earliest: %" GST_TIME_FORMAT,
690 GST_TIME_ARGS (qostime), GST_TIME_ARGS (visual->earliest_time));
695 /* Read VISUAL_SAMPLES samples per channel */
697 (const guint16 *) gst_adapter_peek (visual->adapter,
698 VISUAL_SAMPLES * visual->bps);
700 #if defined(VISUAL_API_VERSION) && VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000
702 VisBuffer *lbuf, *rbuf;
703 guint16 ldata[VISUAL_SAMPLES], rdata[VISUAL_SAMPLES];
704 VisAudioSampleRateType rate;
706 lbuf = visual_buffer_new_with_buffer (ldata, sizeof (ldata), NULL);
707 rbuf = visual_buffer_new_with_buffer (rdata, sizeof (rdata), NULL);
709 if (visual->channels == 2) {
710 for (i = 0; i < VISUAL_SAMPLES; i++) {
715 for (i = 0; i < VISUAL_SAMPLES; i++) {
721 switch (visual->rate) {
723 rate = VISUAL_AUDIO_SAMPLE_RATE_8000;
726 rate = VISUAL_AUDIO_SAMPLE_RATE_11250;
729 rate = VISUAL_AUDIO_SAMPLE_RATE_22500;
732 rate = VISUAL_AUDIO_SAMPLE_RATE_32000;
735 rate = VISUAL_AUDIO_SAMPLE_RATE_44100;
738 rate = VISUAL_AUDIO_SAMPLE_RATE_48000;
741 rate = VISUAL_AUDIO_SAMPLE_RATE_96000;
744 visual_object_unref (VISUAL_OBJECT (lbuf));
745 visual_object_unref (VISUAL_OBJECT (rbuf));
746 GST_ERROR_OBJECT (visual, "unsupported rate %d", visual->rate);
747 ret = GST_FLOW_ERROR;
752 visual_audio_samplepool_input_channel (visual->audio->samplepool,
754 rate, VISUAL_AUDIO_SAMPLE_FORMAT_S16,
755 (char *) VISUAL_AUDIO_CHANNEL_LEFT);
756 visual_audio_samplepool_input_channel (visual->audio->samplepool, rbuf,
757 rate, VISUAL_AUDIO_SAMPLE_FORMAT_S16,
758 (char *) VISUAL_AUDIO_CHANNEL_RIGHT);
760 visual_object_unref (VISUAL_OBJECT (lbuf));
761 visual_object_unref (VISUAL_OBJECT (rbuf));
765 if (visual->channels == 2) {
766 for (i = 0; i < VISUAL_SAMPLES; i++) {
767 visual->audio->plugpcm[0][i] = *data++;
768 visual->audio->plugpcm[1][i] = *data++;
771 for (i = 0; i < VISUAL_SAMPLES; i++) {
772 visual->audio->plugpcm[0][i] = *data;
773 visual->audio->plugpcm[1][i] = *data++;
778 /* alloc a buffer if we don't have one yet, this happens
779 * when we pushed a buffer in this while loop before */
780 if (outbuf == NULL) {
781 ret = get_buffer (visual, &outbuf);
782 if (ret != GST_FLOW_OK) {
786 visual_video_set_buffer (visual->video, GST_BUFFER_DATA (outbuf));
787 visual_audio_analyze (visual->audio);
788 visual_actor_run (visual->actor, visual->audio);
789 visual_video_set_buffer (visual->video, NULL);
790 GST_DEBUG_OBJECT (visual, "rendered one frame");
792 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
793 GST_BUFFER_DURATION (outbuf) = visual->duration;
795 ret = gst_pad_push (visual->srcpad, outbuf);
799 GST_DEBUG_OBJECT (visual, "finished frame, flushing %u samples from input",
802 /* Flush out the number of samples per frame */
803 gst_adapter_flush (visual->adapter, visual->spf * visual->bps);
805 /* quit the loop if something was wrong */
806 if (ret != GST_FLOW_OK)
813 gst_buffer_unref (outbuf);
815 gst_object_unref (visual);
820 static GstStateChangeReturn
821 gst_visual_change_state (GstElement * element, GstStateChange transition)
823 GstVisual *visual = GST_VISUAL (element);
824 GstStateChangeReturn ret;
826 switch (transition) {
827 case GST_STATE_CHANGE_NULL_TO_READY:
829 visual_actor_new (GST_VISUAL_GET_CLASS (visual)->plugin->info->
831 visual->video = visual_video_new ();
832 visual->audio = visual_audio_new ();
833 /* can't have a play without actors */
834 if (!visual->actor || !visual->video)
837 if (visual_actor_realize (visual->actor) != 0)
840 visual_actor_set_video (visual->actor, visual->video);
842 case GST_STATE_CHANGE_READY_TO_PAUSED:
843 gst_visual_reset (visual);
845 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
851 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
853 switch (transition) {
854 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
856 case GST_STATE_CHANGE_PAUSED_TO_READY:
858 case GST_STATE_CHANGE_READY_TO_NULL:
859 gst_visual_clear_actors (visual);
870 GST_ELEMENT_ERROR (visual, LIBRARY, INIT, (NULL),
871 ("could not create actors"));
872 gst_visual_clear_actors (visual);
873 return GST_STATE_CHANGE_FAILURE;
877 GST_ELEMENT_ERROR (visual, LIBRARY, INIT, (NULL),
878 ("could not realize actor"));
879 gst_visual_clear_actors (visual);
880 return GST_STATE_CHANGE_FAILURE;
885 make_valid_name (char *name)
888 * Replace invalid chars with _ in the type name
890 static const gchar extra_chars[] = "-_+";
894 int valid = ((p[0] >= 'A' && p[0] <= 'Z') ||
895 (p[0] >= 'a' && p[0] <= 'z') ||
896 (p[0] >= '0' && p[0] <= '9') || strchr (extra_chars, p[0]));
903 gst_visual_actor_plugin_is_gl (VisObject * plugin, const gchar * name)
908 #if !defined(VISUAL_API_VERSION)
910 depth = VISUAL_PLUGIN_ACTOR (plugin)->depth;
911 is_gl = (depth == VISUAL_VIDEO_DEPTH_GL);
913 #elif VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000
915 depth = VISUAL_ACTOR_PLUGIN (plugin)->vidoptions.depth;
916 /* FIXME: how to figure this out correctly in 0.4? */
917 is_gl = (depth & VISUAL_VIDEO_DEPTH_GL) == VISUAL_VIDEO_DEPTH_GL;
920 # error what libvisual version is this?
924 GST_DEBUG ("plugin %s is not a GL plugin (%d), registering", name, depth);
926 GST_DEBUG ("plugin %s is a GL plugin (%d), ignoring", name, depth);
933 plugin_init (GstPlugin * plugin)
938 GST_DEBUG_CATEGORY_INIT (libvisual_debug, "libvisual", 0,
939 "libvisual audio visualisations");
941 #ifdef LIBVISUAL_PLUGINSBASEDIR
942 gst_plugin_add_dependency_simple (plugin, "HOME/.libvisual/actor",
943 LIBVISUAL_PLUGINSBASEDIR "/actor", NULL, GST_PLUGIN_DEPENDENCY_FLAG_NONE);
946 visual_log_set_verboseness (VISUAL_LOG_VERBOSENESS_LOW);
947 visual_log_set_info_handler (libvisual_log_handler, (void *) GST_LEVEL_INFO);
948 visual_log_set_warning_handler (libvisual_log_handler,
949 (void *) GST_LEVEL_WARNING);
950 visual_log_set_critical_handler (libvisual_log_handler,
951 (void *) GST_LEVEL_ERROR);
952 visual_log_set_error_handler (libvisual_log_handler,
953 (void *) GST_LEVEL_ERROR);
955 if (!visual_is_initialized ())
956 if (visual_init (NULL, NULL) != 0)
959 list = visual_actor_get_list ();
961 #if !defined(VISUAL_API_VERSION)
962 count = visual_list_count (list);
963 #elif VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000
964 count = visual_collection_size (VISUAL_COLLECTION (list));
967 for (i = 0; i < count; i++) {
968 VisPluginRef *ref = visual_list_get (list, i);
969 VisPluginData *visplugin = NULL;
970 gboolean skip = FALSE;
974 sizeof (GstVisualClass),
977 gst_visual_class_init,
985 visplugin = visual_plugin_load (ref);
987 if (ref->info->plugname == NULL)
990 /* Blacklist some plugins */
991 if (strcmp (ref->info->plugname, "gstreamer") == 0 ||
992 strcmp (ref->info->plugname, "gdkpixbuf") == 0) {
995 /* Ignore plugins that only support GL output for now */
996 skip = gst_visual_actor_plugin_is_gl (visplugin->info->plugin,
997 visplugin->info->plugname);
1000 visual_plugin_unload (visplugin);
1003 name = g_strdup_printf ("GstVisual%s", ref->info->plugname);
1004 make_valid_name (name);
1005 type = g_type_register_static (GST_TYPE_VISUAL, name, &info, 0);
1008 name = g_strdup_printf ("libvisual_%s", ref->info->plugname);
1009 make_valid_name (name);
1010 if (!gst_element_register (plugin, name, GST_RANK_NONE, type)) {
1021 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1024 "libvisual visualization plugins",
1025 plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)