waveformsink: Port to 0.11

https://bugzilla.gnome.org/show_bug.cgi?id=669612
This commit is contained in:
Raimo Järvi 2012-02-08 00:08:49 +02:00 committed by Tim-Philipp Müller
parent 412510d6ed
commit b7b3161c26

View file

@ -54,17 +54,18 @@ static void gst_waveform_sink_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec); guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_waveform_sink_get_property (GObject * object, static void gst_waveform_sink_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec); guint prop_id, GValue * value, GParamSpec * pspec);
static GstCaps *gst_waveform_sink_getcaps (GstBaseSink * bsink); static GstCaps *gst_waveform_sink_getcaps (GstBaseSink * bsink,
GstCaps * filter);
/************************************************************************/ /************************************************************************/
/* GstAudioSink functions */ /* GstAudioSink functions */
/************************************************************************/ /************************************************************************/
static gboolean gst_waveform_sink_prepare (GstAudioSink * asink, static gboolean gst_waveform_sink_prepare (GstAudioSink * asink,
GstRingBufferSpec * spec); GstAudioRingBufferSpec * spec);
static gboolean gst_waveform_sink_unprepare (GstAudioSink * asink); static gboolean gst_waveform_sink_unprepare (GstAudioSink * asink);
static gboolean gst_waveform_sink_open (GstAudioSink * asink); static gboolean gst_waveform_sink_open (GstAudioSink * asink);
static gboolean gst_waveform_sink_close (GstAudioSink * asink); static gboolean gst_waveform_sink_close (GstAudioSink * asink);
static guint gst_waveform_sink_write (GstAudioSink * asink, gpointer data, static gint gst_waveform_sink_write (GstAudioSink * asink, gpointer data,
guint length); guint length);
static guint gst_waveform_sink_delay (GstAudioSink * asink); static guint gst_waveform_sink_delay (GstAudioSink * asink);
static void gst_waveform_sink_reset (GstAudioSink * asink); static void gst_waveform_sink_reset (GstAudioSink * asink);
@ -73,42 +74,23 @@ static void gst_waveform_sink_reset (GstAudioSink * asink);
/* Utils */ /* Utils */
/************************************************************************/ /************************************************************************/
GstCaps *gst_waveform_sink_create_caps (gint rate, gint channels, GstCaps *gst_waveform_sink_create_caps (gint rate, gint channels,
gint bits_per_sample); const gchar * format);
WAVEHDR *bufferpool_get_buffer (GstWaveFormSink * wfsink, gpointer data, WAVEHDR *bufferpool_get_buffer (GstWaveFormSink * wfsink, gpointer data,
guint length); guint length);
void CALLBACK waveOutProc (HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, void CALLBACK waveOutProc (HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
DWORD_PTR dwParam1, DWORD_PTR dwParam2); DWORD_PTR dwParam1, DWORD_PTR dwParam2);
static GstStaticPadTemplate waveformsink_sink_factory = static GstStaticPadTemplate waveformsink_sink_factory =
GST_STATIC_PAD_TEMPLATE ("sink", GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, " GST_STATIC_CAPS ("audio/x-raw, "
"signed = (boolean) { TRUE, FALSE }, " "format = (string) { " GST_AUDIO_NE (S16) ", S8 }, "
"width = (int) 16, " "layout = (string) interleaved, "
"depth = (int) 16, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 2 ]; "
"audio/x-raw-int, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 8, "
"depth = (int) 8, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 2 ]")); "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 2 ]"));
GST_BOILERPLATE (GstWaveFormSink, gst_waveform_sink, GstAudioSink, #define gst_waveform_sink_parent_class parent_class
GST_TYPE_AUDIO_SINK); G_DEFINE_TYPE (GstWaveFormSink, gst_waveform_sink, GST_TYPE_AUDIO_SINK);
static void
gst_waveform_sink_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_set_details_simple (element_class, "WaveForm Audio Sink",
"Sink/Audio",
"Output to a sound card via WaveForm API",
"Sebastien Moutte <sebastien@moutte.net>");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&waveformsink_sink_factory));
}
static void static void
gst_waveform_sink_class_init (GstWaveFormSinkClass * klass) gst_waveform_sink_class_init (GstWaveFormSinkClass * klass)
@ -116,14 +98,14 @@ gst_waveform_sink_class_init (GstWaveFormSinkClass * klass)
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
GstBaseSinkClass *gstbasesink_class; GstBaseSinkClass *gstbasesink_class;
GstBaseAudioSinkClass *gstbaseaudiosink_class;
GstAudioSinkClass *gstaudiosink_class; GstAudioSinkClass *gstaudiosink_class;
GstElementClass *element_class;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass; gstelement_class = (GstElementClass *) klass;
gstbasesink_class = (GstBaseSinkClass *) klass; gstbasesink_class = (GstBaseSinkClass *) klass;
gstbaseaudiosink_class = (GstBaseAudioSinkClass *) klass;
gstaudiosink_class = (GstAudioSinkClass *) klass; gstaudiosink_class = (GstAudioSinkClass *) klass;
element_class = GST_ELEMENT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
@ -144,6 +126,14 @@ gst_waveform_sink_class_init (GstWaveFormSinkClass * klass)
GST_DEBUG_CATEGORY_INIT (waveformsink_debug, "waveformsink", 0, GST_DEBUG_CATEGORY_INIT (waveformsink_debug, "waveformsink", 0,
"Waveform sink"); "Waveform sink");
gst_element_class_set_details_simple (element_class, "WaveForm Audio Sink",
"Sink/Audio",
"Output to a sound card via WaveForm API",
"Sebastien Moutte <sebastien@moutte.net>");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&waveformsink_sink_factory));
} }
static void static void
@ -173,8 +163,7 @@ gst_waveform_sink_get_property (GObject * object, guint prop_id,
} }
static void static void
gst_waveform_sink_init (GstWaveFormSink * wfsink, gst_waveform_sink_init (GstWaveFormSink * wfsink)
GstWaveFormSinkClass * g_class)
{ {
/* initialize members */ /* initialize members */
wfsink->hwaveout = NULL; wfsink->hwaveout = NULL;
@ -205,7 +194,7 @@ gst_waveform_sink_finalise (GObject * object)
} }
static GstCaps * static GstCaps *
gst_waveform_sink_getcaps (GstBaseSink * bsink) gst_waveform_sink_getcaps (GstBaseSink * bsink, GstCaps * filter)
{ {
GstWaveFormSink *wfsink = GST_WAVEFORM_SINK (bsink); GstWaveFormSink *wfsink = GST_WAVEFORM_SINK (bsink);
MMRESULT mmresult; MMRESULT mmresult;
@ -232,97 +221,97 @@ gst_waveform_sink_getcaps (GstBaseSink * bsink)
/* create a caps for all wave formats supported by the device /* create a caps for all wave formats supported by the device
starting by the best quality format */ starting by the best quality format */
if (wocaps.dwFormats & WAVE_FORMAT_96S16) { if (wocaps.dwFormats & WAVE_FORMAT_96S16) {
caps_temp = gst_waveform_sink_create_caps (96000, 2, 16); caps_temp = gst_waveform_sink_create_caps (96000, 2, GST_AUDIO_NE (S16));
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_96S08) { if (wocaps.dwFormats & WAVE_FORMAT_96S08) {
caps_temp = gst_waveform_sink_create_caps (96000, 2, 8); caps_temp = gst_waveform_sink_create_caps (96000, 2, "S8");
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_96M16) { if (wocaps.dwFormats & WAVE_FORMAT_96M16) {
caps_temp = gst_waveform_sink_create_caps (96000, 1, 16); caps_temp = gst_waveform_sink_create_caps (96000, 1, GST_AUDIO_NE (S16));
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_96M08) { if (wocaps.dwFormats & WAVE_FORMAT_96M08) {
caps_temp = gst_waveform_sink_create_caps (96000, 1, 8); caps_temp = gst_waveform_sink_create_caps (96000, 1, "S8");
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_4S16) { if (wocaps.dwFormats & WAVE_FORMAT_4S16) {
caps_temp = gst_waveform_sink_create_caps (44100, 2, 16); caps_temp = gst_waveform_sink_create_caps (44100, 2, GST_AUDIO_NE (S16));
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_4S08) { if (wocaps.dwFormats & WAVE_FORMAT_4S08) {
caps_temp = gst_waveform_sink_create_caps (44100, 2, 8); caps_temp = gst_waveform_sink_create_caps (44100, 2, "S8");
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_4M16) { if (wocaps.dwFormats & WAVE_FORMAT_4M16) {
caps_temp = gst_waveform_sink_create_caps (44100, 1, 16); caps_temp = gst_waveform_sink_create_caps (44100, 1, GST_AUDIO_NE (S16));
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_4M08) { if (wocaps.dwFormats & WAVE_FORMAT_4M08) {
caps_temp = gst_waveform_sink_create_caps (44100, 1, 8); caps_temp = gst_waveform_sink_create_caps (44100, 1, "S8");
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_2S16) { if (wocaps.dwFormats & WAVE_FORMAT_2S16) {
caps_temp = gst_waveform_sink_create_caps (22050, 2, 16); caps_temp = gst_waveform_sink_create_caps (22050, 2, GST_AUDIO_NE (S16));
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_2S08) { if (wocaps.dwFormats & WAVE_FORMAT_2S08) {
caps_temp = gst_waveform_sink_create_caps (22050, 2, 8); caps_temp = gst_waveform_sink_create_caps (22050, 2, "S8");
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_2M16) { if (wocaps.dwFormats & WAVE_FORMAT_2M16) {
caps_temp = gst_waveform_sink_create_caps (22050, 1, 16); caps_temp = gst_waveform_sink_create_caps (22050, 1, GST_AUDIO_NE (S16));
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_2M08) { if (wocaps.dwFormats & WAVE_FORMAT_2M08) {
caps_temp = gst_waveform_sink_create_caps (22050, 1, 8); caps_temp = gst_waveform_sink_create_caps (22050, 1, "S8");
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_1S16) { if (wocaps.dwFormats & WAVE_FORMAT_1S16) {
caps_temp = gst_waveform_sink_create_caps (11025, 2, 16); caps_temp = gst_waveform_sink_create_caps (11025, 2, GST_AUDIO_NE (S16));
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_1S08) { if (wocaps.dwFormats & WAVE_FORMAT_1S08) {
caps_temp = gst_waveform_sink_create_caps (11025, 2, 8); caps_temp = gst_waveform_sink_create_caps (11025, 2, "S8");
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_1M16) { if (wocaps.dwFormats & WAVE_FORMAT_1M16) {
caps_temp = gst_waveform_sink_create_caps (11025, 1, 16); caps_temp = gst_waveform_sink_create_caps (11025, 1, GST_AUDIO_NE (S16));
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
} }
if (wocaps.dwFormats & WAVE_FORMAT_1M08) { if (wocaps.dwFormats & WAVE_FORMAT_1M08) {
caps_temp = gst_waveform_sink_create_caps (11025, 1, 8); caps_temp = gst_waveform_sink_create_caps (11025, 1, "S8");
if (caps_temp) { if (caps_temp) {
gst_caps_append (caps, caps_temp); gst_caps_append (caps, caps_temp);
} }
@ -352,7 +341,7 @@ gst_waveform_sink_open (GstAudioSink * asink)
} }
static gboolean static gboolean
gst_waveform_sink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec) gst_waveform_sink_prepare (GstAudioSink * asink, GstAudioRingBufferSpec * spec)
{ {
GstWaveFormSink *wfsink = GST_WAVEFORM_SINK (asink); GstWaveFormSink *wfsink = GST_WAVEFORM_SINK (asink);
WAVEFORMATEX wfx; WAVEFORMATEX wfx;
@ -363,14 +352,14 @@ gst_waveform_sink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec)
memset (&wfx, 0, sizeof (wfx)); memset (&wfx, 0, sizeof (wfx));
wfx.cbSize = 0; wfx.cbSize = 0;
wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = spec->channels; wfx.nChannels = spec->info.channels;
wfx.nSamplesPerSec = spec->rate; wfx.nSamplesPerSec = spec->info.rate;
wfx.wBitsPerSample = (spec->bytes_per_sample * 8) / wfx.nChannels; wfx.wBitsPerSample = (spec->info.bpf * 8) / wfx.nChannels;
wfx.nBlockAlign = spec->bytes_per_sample; wfx.nBlockAlign = spec->info.bpf;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
/* save bytes per sample to use it in delay */ /* save bytes per sample to use it in delay */
wfsink->bytes_per_sample = spec->bytes_per_sample; wfsink->bytes_per_sample = spec->info.bpf;
/* open the default audio device with the given caps */ /* open the default audio device with the given caps */
mmresult = waveOutOpen (&wfsink->hwaveout, WAVE_MAPPER, mmresult = waveOutOpen (&wfsink->hwaveout, WAVE_MAPPER,
@ -449,7 +438,7 @@ gst_waveform_sink_close (GstAudioSink * asink)
return TRUE; return TRUE;
} }
static guint static gint
gst_waveform_sink_write (GstAudioSink * asink, gpointer data, guint length) gst_waveform_sink_write (GstAudioSink * asink, gpointer data, guint length)
{ {
GstWaveFormSink *wfsink = GST_WAVEFORM_SINK (asink); GstWaveFormSink *wfsink = GST_WAVEFORM_SINK (asink);
@ -554,15 +543,13 @@ gst_waveform_sink_reset (GstAudioSink * asink)
} }
GstCaps * GstCaps *
gst_waveform_sink_create_caps (gint rate, gint channels, gint bits_per_sample) gst_waveform_sink_create_caps (gint rate, gint channels, const gchar * format)
{ {
GstCaps *caps = NULL; GstCaps *caps = NULL;
caps = gst_caps_new_simple ("audio/x-raw-int", caps = gst_caps_new_simple ("audio/x-raw",
"width", G_TYPE_INT, bits_per_sample, "format", G_TYPE_STRING, format,
"depth", G_TYPE_INT, bits_per_sample, "layout", G_TYPE_STRING, "interleaved",
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"signed", G_TYPE_BOOLEAN, TRUE,
"channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, rate, NULL); "channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, rate, NULL);
return caps; return caps;
} }