mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
36c2fc253b
Original commit message from CVS: * examples/indexing/indexmpeg.c: (main): * ext/artsd/gstartsdsink.c: (gst_artsdsink_open_audio), (gst_artsdsink_close_audio), (gst_artsdsink_change_state): * ext/artsd/gstartsdsink.h: * ext/audiofile/gstafparse.c: (gst_afparse_open_file), (gst_afparse_close_file): * ext/audiofile/gstafparse.h: * ext/audiofile/gstafsink.c: (gst_afsink_open_file), (gst_afsink_close_file), (gst_afsink_chain), (gst_afsink_change_state): * ext/audiofile/gstafsink.h: * ext/audiofile/gstafsrc.c: (gst_afsrc_open_file), (gst_afsrc_close_file), (gst_afsrc_change_state): * ext/audiofile/gstafsrc.h: * ext/cdaudio/gstcdaudio.c: (gst_cdaudio_init): * ext/directfb/directfbvideosink.c: (gst_directfbvideosink_init): * ext/dts/gstdtsdec.c: (gst_dtsdec_init): * ext/jack/gstjack.h: * ext/jack/gstjackbin.c: (gst_jack_bin_init), (gst_jack_bin_change_state): * ext/musepack/gstmusepackdec.c: (gst_musepackdec_init): * ext/musicbrainz/gsttrm.c: (gst_musicbrainz_init): * ext/nas/nassink.c: (gst_nassink_open_audio), (gst_nassink_close_audio), (gst_nassink_change_state): * ext/nas/nassink.h: * ext/polyp/polypsink.c: (gst_polypsink_init): * ext/sdl/sdlvideosink.c: (gst_sdlvideosink_change_state): * ext/sdl/sdlvideosink.h: * ext/smoothwave/gstsmoothwave.c: (gst_smoothwave_init): * ext/sndfile/gstsf.c: (gst_sf_set_property), (gst_sf_change_state), (gst_sf_release_request_pad), (gst_sf_open_file), (gst_sf_close_file), (gst_sf_loop): * ext/sndfile/gstsf.h: * ext/swfdec/gstswfdec.c: (gst_swfdec_init): * ext/tarkin/gsttarkindec.c: (gst_tarkindec_init): * gst/apetag/apedemux.c: (gst_ape_demux_init): * gst/cdxaparse/gstcdxaparse.c: (gst_cdxaparse_init): * gst/cdxaparse/gstcdxastrip.c: (gst_cdxastrip_init): * gst/festival/gstfestival.c: (gst_festival_change_state): * gst/festival/gstfestival.h: * gst/mpeg2sub/gstmpeg2subt.c: (gst_mpeg2subt_init): * gst/multifilesink/gstmultifilesink.c: (gst_multifilesink_init), (gst_multifilesink_set_location), (gst_multifilesink_open_file), (gst_multifilesink_close_file), (gst_multifilesink_next_file), (gst_multifilesink_pad_query), (gst_multifilesink_handle_event), (gst_multifilesink_chain), (gst_multifilesink_change_state): * gst/multifilesink/gstmultifilesink.h: * gst/videodrop/gstvideodrop.c: (gst_videodrop_init): * sys/cdrom/gstcdplayer.c: (cdplayer_init): * sys/dxr3/dxr3audiosink.c: (dxr3audiosink_init), (dxr3audiosink_open), (dxr3audiosink_close), (dxr3audiosink_chain_pcm), (dxr3audiosink_chain_ac3), (dxr3audiosink_change_state): * sys/dxr3/dxr3audiosink.h: * sys/dxr3/dxr3spusink.c: (dxr3spusink_init), (dxr3spusink_open), (dxr3spusink_close), (dxr3spusink_chain), (dxr3spusink_change_state): * sys/dxr3/dxr3spusink.h: * sys/dxr3/dxr3videosink.c: (dxr3videosink_init), (dxr3videosink_open), (dxr3videosink_close), (dxr3videosink_write_data), (dxr3videosink_change_state): * sys/dxr3/dxr3videosink.h: * sys/glsink/glimagesink.c: (gst_glimagesink_init): * sys/qcam/gstqcamsrc.c: (gst_qcamsrc_change_state), (gst_qcamsrc_open), (gst_qcamsrc_close): * sys/qcam/gstqcamsrc.h: * sys/v4l2/gstv4l2src.c: (gst_v4l2src_init): * sys/vcd/vcdsrc.c: (gst_vcdsrc_set_property), (gst_vcdsrc_get), (gst_vcdsrc_open_file), (gst_vcdsrc_close_file), (gst_vcdsrc_change_state), (gst_vcdsrc_recalculate): * sys/vcd/vcdsrc.h: renamed GST_FLAGS macros to GST_OBJECT_FLAGS moved bitshift from macro to enum definition
446 lines
13 KiB
C
446 lines
13 KiB
C
/* GStreamer
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
*
|
|
* 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., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
#include <string.h>
|
|
|
|
#include <gst/gst.h>
|
|
#include <gst/video/video.h>
|
|
#include <gst/audio/audio.h>
|
|
|
|
#include "gstsmoothwave.h"
|
|
|
|
static GstElementDetails gst_smoothwave_details =
|
|
GST_ELEMENT_DETAILS ("Smooth waveform",
|
|
"Visualization",
|
|
"Fading grayscale waveform display",
|
|
"Erik Walthinsen <omega@cse.ogi.edu>");
|
|
|
|
|
|
/* SmoothWave signals and args */
|
|
enum
|
|
{
|
|
/* FILL ME */
|
|
LAST_SIGNAL
|
|
};
|
|
|
|
static void gst_smoothwave_base_init (gpointer g_class);
|
|
static void gst_smoothwave_class_init (GstSmoothWaveClass * klass);
|
|
static void gst_smoothwave_init (GstSmoothWave * smoothwave);
|
|
static void gst_smoothwave_dispose (GObject * object);
|
|
static GstStateChangeReturn gst_sw_change_state (GstElement * element,
|
|
GstStateChange transition);
|
|
static void gst_smoothwave_chain (GstPad * pad, GstData * _data);
|
|
static GstPadLinkReturn gst_sw_sinklink (GstPad * pad, const GstCaps * caps);
|
|
static GstPadLinkReturn gst_sw_srclink (GstPad * pad, const GstCaps * caps);
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
/*static guint gst_smoothwave_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
GST_PAD_SRC,
|
|
GST_PAD_ALWAYS,
|
|
GST_STATIC_CAPS ("video/x-raw-rgb, "
|
|
"bpp = (int) 32, "
|
|
"depth = (int) 24, "
|
|
"endianness = (int) BIG_ENDIAN, "
|
|
"red_mask = (int) " GST_VIDEO_BYTE2_MASK_32 ", "
|
|
"green_mask = (int) " GST_VIDEO_BYTE3_MASK_32 ", "
|
|
"blue_mask = (int) " GST_VIDEO_BYTE4_MASK_32 ", "
|
|
"width = (int)512, "
|
|
"height = (int)256, " "framerate = " GST_VIDEO_FPS_RANGE)
|
|
);
|
|
#else
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
GST_PAD_SRC,
|
|
GST_PAD_ALWAYS,
|
|
GST_STATIC_CAPS ("video/x-raw-rgb, "
|
|
"bpp = (int) 32, "
|
|
"depth = (int) 24, "
|
|
"endianness = (int) BIG_ENDIAN, "
|
|
"red_mask = (int) " GST_VIDEO_BYTE3_MASK_32 ", "
|
|
"green_mask = (int) " GST_VIDEO_BYTE2_MASK_32 ", "
|
|
"blue_mask = (int) " GST_VIDEO_BYTE1_MASK_32 ", "
|
|
"width = (int)512, "
|
|
"height = (int)256, " "framerate = " GST_VIDEO_FPS_RANGE)
|
|
);
|
|
#endif
|
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
GST_PAD_SINK,
|
|
GST_PAD_ALWAYS,
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
|
"rate = (int) [ 1, MAX ], "
|
|
"channels = (int) [ 1, 2 ], "
|
|
"endianness = (int) BYTE_ORDER, "
|
|
"width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
|
|
);
|
|
|
|
GType
|
|
gst_smoothwave_get_type (void)
|
|
{
|
|
static GType smoothwave_type = 0;
|
|
|
|
if (!smoothwave_type) {
|
|
static const GTypeInfo smoothwave_info = {
|
|
sizeof (GstSmoothWaveClass),
|
|
gst_smoothwave_base_init,
|
|
NULL,
|
|
(GClassInitFunc) gst_smoothwave_class_init,
|
|
NULL,
|
|
NULL,
|
|
sizeof (GstSmoothWave),
|
|
0,
|
|
(GInstanceInitFunc) gst_smoothwave_init,
|
|
};
|
|
|
|
smoothwave_type =
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstSmoothWave",
|
|
&smoothwave_info, 0);
|
|
}
|
|
return smoothwave_type;
|
|
}
|
|
|
|
static void
|
|
gst_smoothwave_base_init (gpointer g_class)
|
|
{
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
gst_element_class_set_details (element_class, &gst_smoothwave_details);
|
|
}
|
|
|
|
static void
|
|
gst_smoothwave_class_init (GstSmoothWaveClass * klass)
|
|
{
|
|
GObjectClass *gobject_class;
|
|
GstElementClass *element_class;
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
element_class = (GstElementClass *) klass;
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
gobject_class->dispose = gst_smoothwave_dispose;
|
|
element_class->change_state = gst_sw_change_state;
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
gst_static_pad_template_get (&src_template));
|
|
gst_element_class_add_pad_template (element_class,
|
|
gst_static_pad_template_get (&sink_template));
|
|
}
|
|
|
|
static void
|
|
gst_smoothwave_init (GstSmoothWave * smoothwave)
|
|
{
|
|
int i;
|
|
|
|
smoothwave->sinkpad =
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&sink_template),
|
|
"sink");
|
|
smoothwave->srcpad =
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&src_template),
|
|
"src");
|
|
gst_element_add_pad (GST_ELEMENT (smoothwave), smoothwave->sinkpad);
|
|
gst_pad_set_chain_function (smoothwave->sinkpad, gst_smoothwave_chain);
|
|
gst_pad_set_link_function (smoothwave->sinkpad, gst_sw_sinklink);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (smoothwave), smoothwave->srcpad);
|
|
gst_pad_set_link_function (smoothwave->srcpad, gst_sw_srclink);
|
|
|
|
GST_OBJECT_FLAG_SET (smoothwave, GST_ELEMENT_EVENT_AWARE);
|
|
|
|
smoothwave->adapter = gst_adapter_new ();
|
|
|
|
smoothwave->width = 512;
|
|
smoothwave->height = 256;
|
|
|
|
#define SPLIT_PT 96
|
|
|
|
/* Fade in blue up to the split point */
|
|
for (i = 0; i < SPLIT_PT; i++)
|
|
smoothwave->palette[i] = (255 * i / SPLIT_PT);
|
|
|
|
/* After the split point, fade out blue and fade in red */
|
|
for (; i < 256; i++) {
|
|
gint val = (i - SPLIT_PT) * 255 / (255 - SPLIT_PT);
|
|
|
|
smoothwave->palette[i] = (255 - val) | (val << 16);
|
|
}
|
|
|
|
smoothwave->imagebuffer = g_malloc (smoothwave->width * smoothwave->height);
|
|
memset (smoothwave->imagebuffer, 0, smoothwave->width * smoothwave->height);
|
|
|
|
smoothwave->fps = 0;
|
|
smoothwave->sample_rate = 0;
|
|
smoothwave->audio_basetime = GST_CLOCK_TIME_NONE;
|
|
smoothwave->samples_consumed = 0;
|
|
}
|
|
|
|
inline guchar *
|
|
draw_line (guchar * cur_pos, gint diff_y, gint stride)
|
|
{
|
|
gint j;
|
|
|
|
if (diff_y > 0) {
|
|
for (j = diff_y; j > 0; j--) {
|
|
cur_pos += stride;
|
|
*cur_pos = 0xff;
|
|
}
|
|
} else if (diff_y < 0) {
|
|
for (j = diff_y; j < 0; j++) {
|
|
cur_pos -= stride;
|
|
*cur_pos = 0xff;
|
|
}
|
|
} else {
|
|
*cur_pos = 0xff;
|
|
}
|
|
return cur_pos;
|
|
}
|
|
|
|
static void
|
|
gst_smoothwave_dispose (GObject * object)
|
|
{
|
|
GstSmoothWave *sw = GST_SMOOTHWAVE (object);
|
|
|
|
if (sw->adapter != NULL) {
|
|
g_object_unref (sw->adapter);
|
|
sw->adapter = NULL;
|
|
}
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
}
|
|
|
|
static GstPadLinkReturn
|
|
gst_sw_sinklink (GstPad * pad, const GstCaps * caps)
|
|
{
|
|
GstSmoothWave *sw = GST_SMOOTHWAVE (GST_OBJECT_PARENT (pad));
|
|
GstStructure *structure;
|
|
|
|
g_return_val_if_fail (sw != NULL, GST_PAD_LINK_REFUSED);
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
if (!gst_structure_get_int (structure, "channels", &sw->channels) ||
|
|
!gst_structure_get_int (structure, "rate", &sw->sample_rate))
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
return GST_PAD_LINK_OK;
|
|
}
|
|
|
|
static GstPadLinkReturn
|
|
gst_sw_srclink (GstPad * pad, const GstCaps * caps)
|
|
{
|
|
GstSmoothWave *sw = GST_SMOOTHWAVE (GST_OBJECT_PARENT (pad));
|
|
GstStructure *structure;
|
|
|
|
g_return_val_if_fail (sw != NULL, GST_PAD_LINK_REFUSED);
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
if (!gst_structure_get_int (structure, "width", &sw->width) ||
|
|
!gst_structure_get_int (structure, "height", &sw->height) ||
|
|
!gst_structure_get_double (structure, "framerate", &sw->fps))
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
return GST_PAD_LINK_OK;
|
|
}
|
|
|
|
static void
|
|
gst_smoothwave_chain (GstPad * pad, GstData * _data)
|
|
{
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
|
GstSmoothWave *smoothwave;
|
|
guint32 bytesperread;
|
|
gint samples_per_frame;
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
smoothwave = GST_SMOOTHWAVE (GST_OBJECT_PARENT (pad));
|
|
|
|
if (GST_IS_EVENT (_data)) {
|
|
GstEvent *event = GST_EVENT (_data);
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
case GST_EVENT_DISCONTINUOUS:
|
|
{
|
|
gint64 value = 0;
|
|
|
|
gst_event_discont_get_value (event, GST_FORMAT_TIME, &value);
|
|
gst_adapter_clear (smoothwave->adapter);
|
|
smoothwave->audio_basetime = value;
|
|
smoothwave->samples_consumed = 0;
|
|
}
|
|
default:
|
|
gst_pad_event_default (pad, event);
|
|
break;
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (!GST_PAD_IS_USABLE (smoothwave->srcpad)) {
|
|
gst_buffer_unref (buf);
|
|
return;
|
|
}
|
|
if (smoothwave->audio_basetime == GST_CLOCK_TIME_NONE)
|
|
smoothwave->audio_basetime = GST_BUFFER_TIMESTAMP (buf);
|
|
if (smoothwave->audio_basetime == GST_CLOCK_TIME_NONE)
|
|
smoothwave->audio_basetime = 0;
|
|
|
|
bytesperread = smoothwave->width * smoothwave->channels * sizeof (gint16);
|
|
samples_per_frame = smoothwave->sample_rate / smoothwave->fps;
|
|
|
|
gst_adapter_push (smoothwave->adapter, buf);
|
|
while (gst_adapter_available (smoothwave->adapter) > MAX (bytesperread,
|
|
samples_per_frame * smoothwave->channels * sizeof (gint16))) {
|
|
guint32 *ptr;
|
|
gint i;
|
|
gint qheight;
|
|
const gint16 *samples =
|
|
(const guint16 *) gst_adapter_peek (smoothwave->adapter, bytesperread);
|
|
gint stride = smoothwave->width;
|
|
|
|
/* First draw the new waveform */
|
|
if (smoothwave->channels == 2) {
|
|
guchar *cur_pos[2];
|
|
gint prev_y[2];
|
|
|
|
qheight = smoothwave->height / 4;
|
|
prev_y[0] = (gint32) (*samples) * qheight / 32768;
|
|
samples++;
|
|
prev_y[1] = (gint32) (*samples) * qheight / 32768;
|
|
samples++;
|
|
cur_pos[0] = smoothwave->imagebuffer + ((prev_y[0] + qheight) * stride);
|
|
cur_pos[1] =
|
|
smoothwave->imagebuffer + ((prev_y[1] +
|
|
(3 * smoothwave->height / 4)) * stride);
|
|
*(cur_pos[0]) = 0xff;
|
|
*(cur_pos[1]) = 0xff;
|
|
|
|
for (i = 1; i < smoothwave->width; i++) {
|
|
gint diff_y = (gint) (*samples) * qheight / 32768 - prev_y[0];
|
|
|
|
samples++;
|
|
cur_pos[0] = draw_line (cur_pos[0], diff_y, stride);
|
|
cur_pos[0]++;
|
|
prev_y[0] += diff_y;
|
|
|
|
diff_y = (gint) (*samples) * qheight / 32768 - prev_y[1];
|
|
samples++;
|
|
cur_pos[1] = draw_line (cur_pos[1], diff_y, stride);
|
|
cur_pos[1]++;
|
|
prev_y[1] += diff_y;
|
|
}
|
|
} else {
|
|
qheight = smoothwave->height / 2;
|
|
guchar *cur_pos;
|
|
gint prev_y;
|
|
|
|
prev_y = (gint32) (*samples) * qheight / 32768;
|
|
samples++;
|
|
cur_pos = smoothwave->imagebuffer + ((prev_y + qheight) * stride);
|
|
*cur_pos = 0xff;
|
|
for (i = 1; i < smoothwave->width; i++) {
|
|
gint diff_y = (gint) (*samples) * qheight / 32768 - prev_y;
|
|
|
|
samples++;
|
|
cur_pos = draw_line (cur_pos, diff_y, stride);
|
|
cur_pos++;
|
|
prev_y += diff_y;
|
|
}
|
|
}
|
|
|
|
/* Now fade stuff out */
|
|
ptr = (guint32 *) smoothwave->imagebuffer;
|
|
for (i = 0; i < (smoothwave->width * smoothwave->height) / 4; i++) {
|
|
if (*ptr)
|
|
*ptr -= ((*ptr & 0xf0f0f0f0ul) >> 4) + ((*ptr & 0xe0e0e0e0ul) >> 5);
|
|
ptr++;
|
|
}
|
|
|
|
{
|
|
guint32 *out;
|
|
guchar *in;
|
|
GstBuffer *bufout;
|
|
|
|
bufout =
|
|
gst_buffer_new_and_alloc (smoothwave->width * smoothwave->height * 4);
|
|
|
|
GST_BUFFER_TIMESTAMP (bufout) =
|
|
smoothwave->audio_basetime +
|
|
(GST_SECOND * smoothwave->samples_consumed / smoothwave->sample_rate);
|
|
GST_BUFFER_DURATION (bufout) = GST_SECOND / smoothwave->fps;
|
|
out = (guint32 *) GST_BUFFER_DATA (bufout);
|
|
in = smoothwave->imagebuffer;
|
|
|
|
for (i = 0; i < (smoothwave->width * smoothwave->height); i++) {
|
|
*out++ = smoothwave->palette[*in++]; // t | (t << 8) | (t << 16) | (t << 24);
|
|
}
|
|
gst_pad_push (smoothwave->srcpad, GST_DATA (bufout));
|
|
}
|
|
smoothwave->samples_consumed += samples_per_frame;
|
|
gst_adapter_flush (smoothwave->adapter,
|
|
samples_per_frame * smoothwave->channels * sizeof (gint16));
|
|
}
|
|
}
|
|
|
|
static GstStateChangeReturn
|
|
gst_sw_change_state (GstElement * element, GstStateChange transition)
|
|
{
|
|
GstSmoothWave *sw = GST_SMOOTHWAVE (element);
|
|
|
|
switch (transition) {
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
break;
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
break;
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
sw->audio_basetime = GST_CLOCK_TIME_NONE;
|
|
gst_adapter_clear (sw->adapter);
|
|
break;
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
sw->channels = 0;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
}
|
|
|
|
static gboolean
|
|
plugin_init (GstPlugin * plugin)
|
|
{
|
|
if (!gst_library_load ("gstbytestream"))
|
|
return FALSE;
|
|
|
|
if (!gst_element_register (plugin, "smoothwave", GST_RANK_NONE,
|
|
GST_TYPE_SMOOTHWAVE))
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
GST_VERSION_MINOR,
|
|
"smoothwave",
|
|
"Fading greyscale waveform display",
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
|