mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-01 09:21:03 +00:00
gst/wavenc/gstwavenc.*: Set caps on first outgoing buffer, so that it doesn't error out immediately with a non-negoti...
Original commit message from CVS: * gst/wavenc/gstwavenc.c: (gst_wavenc_base_init), (gst_wavenc_class_init), (gst_wavenc_init), (gst_wavenc_create_header_buf), (gst_wavenc_push_header), (gst_wavenc_sink_setcaps), (get_id_from_name), (gst_wavenc_event), (gst_wavenc_chain), (gst_wavenc_change_state): * gst/wavenc/gstwavenc.h: Set caps on first outgoing buffer, so that it doesn't error out immediately with a non-negotiated error (#338716). Rewrite and clean up a bit; fix setcaps function to parse things properly; fix sink caps (8bit audio is unsigned and doesn't have depth); use boilerplate macros; remove unused properties stuff.
This commit is contained in:
parent
9b14d8f398
commit
7f74c39a10
3 changed files with 248 additions and 281 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
||||||
|
2006-04-19 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
|
* gst/wavenc/gstwavenc.c: (gst_wavenc_base_init),
|
||||||
|
(gst_wavenc_class_init), (gst_wavenc_init),
|
||||||
|
(gst_wavenc_create_header_buf), (gst_wavenc_push_header),
|
||||||
|
(gst_wavenc_sink_setcaps), (get_id_from_name), (gst_wavenc_event),
|
||||||
|
(gst_wavenc_chain), (gst_wavenc_change_state):
|
||||||
|
* gst/wavenc/gstwavenc.h:
|
||||||
|
Set caps on first outgoing buffer, so that it doesn't error out
|
||||||
|
immediately with a non-negotiated error (#338716). Rewrite and
|
||||||
|
clean up a bit; fix setcaps function to parse things properly;
|
||||||
|
fix sink caps (8bit audio is unsigned and doesn't have depth);
|
||||||
|
use boilerplate macros; remove unused properties stuff.
|
||||||
|
|
||||||
2006-04-18 Tim-Philipp Müller <tim at centricular dot net>
|
2006-04-18 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
* ext/gdk_pixbuf/gstgdkpixbuf.c:
|
* ext/gdk_pixbuf/gstgdkpixbuf.c:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* -*- mOde: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
|
/* -*- mOde: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
|
||||||
/* GStreamer
|
/* GStreamer .wav encoder
|
||||||
* Copyright (C) <2002> Iain Holmes <iain@prettypeople.org>
|
* Copyright (C) <2002> Iain Holmes <iain@prettypeople.org>
|
||||||
|
* Copyright (C) <2006> Tim-Philipp Müller <tim centricular net>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
@ -30,12 +31,6 @@
|
||||||
GST_DEBUG_CATEGORY_STATIC (wavenc_debug);
|
GST_DEBUG_CATEGORY_STATIC (wavenc_debug);
|
||||||
#define GST_CAT_DEFAULT wavenc_debug
|
#define GST_CAT_DEFAULT wavenc_debug
|
||||||
|
|
||||||
static void gst_wavenc_base_init (gpointer g_class);
|
|
||||||
static void gst_wavenc_class_init (GstWavEncClass * klass);
|
|
||||||
static void gst_wavenc_init (GstWavEnc * wavenc);
|
|
||||||
static GstFlowReturn gst_wavenc_chain (GstPad * pad, GstBuffer * buf);
|
|
||||||
static gboolean gst_wavenc_event (GstPad * pad, GstEvent * event);
|
|
||||||
|
|
||||||
#define WAVE_FORMAT_PCM 0x0001
|
#define WAVE_FORMAT_PCM 0x0001
|
||||||
|
|
||||||
struct riff_struct
|
struct riff_struct
|
||||||
|
@ -69,21 +64,34 @@ struct wave_header
|
||||||
struct chunk_struct data;
|
struct chunk_struct data;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GstElementDetails gst_wavenc_details =
|
static const GstElementDetails gst_wavenc_details =
|
||||||
GST_ELEMENT_DETAILS ("WAV audio muxer",
|
GST_ELEMENT_DETAILS ("WAV audio muxer",
|
||||||
"Codec/Muxer/Audio",
|
"Codec/Muxer/Audio",
|
||||||
"Encode raw audio into WAV",
|
"Encode raw audio into WAV",
|
||||||
"Iain Holmes <iain@prettypeople.org>");
|
"Iain Holmes <iain@prettypeople.org>");
|
||||||
|
|
||||||
|
/* FIXME: mono doesn't produce correct files it seems, at least mplayer xruns */
|
||||||
|
/* Max. of two channels, more channels need WAVFORMATEX with
|
||||||
|
* channel layout, which we do not support yet */
|
||||||
|
#define SINK_CAPS \
|
||||||
|
"audio/x-raw-int, " \
|
||||||
|
"rate = (int) [ 1, MAX ], " \
|
||||||
|
"channels = (int) [ 1, 2 ], " \
|
||||||
|
"endianness = (int) LITTLE_ENDIAN, " \
|
||||||
|
"width = (int) 16, " \
|
||||||
|
"depth = (int) 16, " \
|
||||||
|
"signed = (boolean) true" \
|
||||||
|
"; " \
|
||||||
|
"audio/x-raw-int, " \
|
||||||
|
"rate = (int) [ 1, MAX ], " \
|
||||||
|
"channels = (int) [ 1, 2 ], " \
|
||||||
|
"width = (int) 8, " \
|
||||||
|
"signed = (boolean) false"
|
||||||
|
|
||||||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
static GstStaticPadTemplate sink_factory = 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 (SINK_CAPS)
|
||||||
"rate = (int) [ 1, MAX ], "
|
|
||||||
"channels = (int) [ 1, MAX ], "
|
|
||||||
"endianness = (int) LITTLE_ENDIAN, "
|
|
||||||
"width = (int) { 8, 16 }, "
|
|
||||||
"depth = (int) { 8, 16 }, " "signed = (boolean) true")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
@ -92,72 +100,13 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_STATIC_CAPS ("audio/x-wav")
|
GST_STATIC_CAPS ("audio/x-wav")
|
||||||
);
|
);
|
||||||
|
|
||||||
enum
|
GST_BOILERPLATE (GstWavEnc, gst_wavenc, GstElement, GST_TYPE_ELEMENT);
|
||||||
{
|
|
||||||
PROP_0
|
|
||||||
};
|
|
||||||
|
|
||||||
static GstElementClass *parent_class = NULL;
|
static GstFlowReturn gst_wavenc_chain (GstPad * pad, GstBuffer * buf);
|
||||||
|
static gboolean gst_wavenc_event (GstPad * pad, GstEvent * event);
|
||||||
static GType
|
static GstStateChangeReturn gst_wavenc_change_state (GstElement * element,
|
||||||
gst_wavenc_get_type (void)
|
GstStateChange transition);
|
||||||
{
|
static gboolean gst_wavenc_sink_setcaps (GstPad * pad, GstCaps * caps);
|
||||||
static GType type = 0;
|
|
||||||
|
|
||||||
if (type == 0) {
|
|
||||||
static const GTypeInfo info = {
|
|
||||||
sizeof (GstWavEncClass),
|
|
||||||
gst_wavenc_base_init,
|
|
||||||
NULL,
|
|
||||||
(GClassInitFunc) gst_wavenc_class_init,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
sizeof (GstWavEnc),
|
|
||||||
0,
|
|
||||||
(GInstanceInitFunc) gst_wavenc_init
|
|
||||||
};
|
|
||||||
|
|
||||||
type = g_type_register_static (GST_TYPE_ELEMENT, "GstWavEnc", &info, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstStateChangeReturn
|
|
||||||
gst_wavenc_change_state (GstElement * element, GstStateChange transition)
|
|
||||||
{
|
|
||||||
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
||||||
GstWavEnc *wavenc = GST_WAVENC (element);
|
|
||||||
|
|
||||||
ret = parent_class->change_state (element, transition);
|
|
||||||
if (ret != GST_STATE_CHANGE_SUCCESS)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
switch (transition) {
|
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
||||||
wavenc->setup = FALSE;
|
|
||||||
wavenc->flush_header = TRUE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
set_property (GObject * object,
|
|
||||||
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
GstWavEnc *enc;
|
|
||||||
|
|
||||||
enc = GST_WAVENC (object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_wavenc_base_init (gpointer g_class)
|
gst_wavenc_base_init (gpointer g_class)
|
||||||
|
@ -170,42 +119,63 @@ gst_wavenc_base_init (gpointer g_class)
|
||||||
gst_static_pad_template_get (&src_factory));
|
gst_static_pad_template_get (&src_factory));
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&sink_factory));
|
gst_static_pad_template_get (&sink_factory));
|
||||||
}
|
|
||||||
static void
|
|
||||||
gst_wavenc_class_init (GstWavEncClass * klass)
|
|
||||||
{
|
|
||||||
GstElementClass *element_class;
|
|
||||||
GObjectClass *object_class;
|
|
||||||
|
|
||||||
element_class = (GstElementClass *) klass;
|
|
||||||
object_class = (GObjectClass *) klass;
|
|
||||||
object_class->set_property = set_property;
|
|
||||||
|
|
||||||
element_class->change_state = gst_wavenc_change_state;
|
|
||||||
|
|
||||||
parent_class = g_type_class_peek_parent (klass);
|
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT (wavenc_debug, "wavenc", 0, "WAV encoder element");
|
GST_DEBUG_CATEGORY_INIT (wavenc_debug, "wavenc", 0, "WAV encoder element");
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gst_wavenc_setup (GstWavEnc * wavenc)
|
gst_wavenc_class_init (GstWavEncClass * klass)
|
||||||
|
{
|
||||||
|
GstElementClass *element_class;
|
||||||
|
|
||||||
|
element_class = (GstElementClass *) klass;
|
||||||
|
|
||||||
|
element_class->change_state = GST_DEBUG_FUNCPTR (gst_wavenc_change_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_wavenc_init (GstWavEnc * wavenc, GstWavEncClass * klass)
|
||||||
|
{
|
||||||
|
wavenc->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||||
|
gst_pad_set_chain_function (wavenc->sinkpad,
|
||||||
|
GST_DEBUG_FUNCPTR (gst_wavenc_chain));
|
||||||
|
gst_pad_set_event_function (wavenc->sinkpad,
|
||||||
|
GST_DEBUG_FUNCPTR (gst_wavenc_event));
|
||||||
|
gst_pad_set_setcaps_function (wavenc->sinkpad,
|
||||||
|
GST_DEBUG_FUNCPTR (gst_wavenc_sink_setcaps));
|
||||||
|
gst_element_add_pad (GST_ELEMENT (wavenc), wavenc->sinkpad);
|
||||||
|
|
||||||
|
wavenc->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
||||||
|
gst_pad_use_fixed_caps (wavenc->srcpad);
|
||||||
|
gst_pad_set_caps (wavenc->srcpad,
|
||||||
|
gst_static_pad_template_get_caps (&src_factory));
|
||||||
|
gst_element_add_pad (GST_ELEMENT (wavenc), wavenc->srcpad);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define WAV_HEADER_LEN 44
|
||||||
|
|
||||||
|
/* FIXME: we are probably not handling depth != width correctly here */
|
||||||
|
static GstBuffer *
|
||||||
|
gst_wavenc_create_header_buf (GstWavEnc * wavenc, guint audio_data_size)
|
||||||
{
|
{
|
||||||
struct wave_header wave;
|
struct wave_header wave;
|
||||||
gint size = 0x7fffffff; /* Use a bogus size initially */
|
GstBuffer *buf;
|
||||||
|
guint8 *header;
|
||||||
|
|
||||||
|
buf = gst_buffer_new_and_alloc (WAV_HEADER_LEN);
|
||||||
|
header = GST_BUFFER_DATA (buf);
|
||||||
|
memset (header, 0, WAV_HEADER_LEN);
|
||||||
|
|
||||||
wave.common.wChannels = wavenc->channels;
|
wave.common.wChannels = wavenc->channels;
|
||||||
wave.common.wBitsPerSample = wavenc->bits;
|
wave.common.wBitsPerSample = wavenc->depth;
|
||||||
wave.common.dwSamplesPerSec = wavenc->rate;
|
wave.common.dwSamplesPerSec = wavenc->rate;
|
||||||
|
|
||||||
memset (wavenc->header, 0, WAV_HEADER_LEN);
|
|
||||||
|
|
||||||
/* Fill out our wav-header with some information */
|
/* Fill out our wav-header with some information */
|
||||||
strncpy ((char *) wave.riff.id, "RIFF", 4);
|
memcpy (wave.riff.id, "RIFF", 4);
|
||||||
wave.riff.len = size - 8;
|
wave.riff.len = audio_data_size + WAV_HEADER_LEN - 8;
|
||||||
strncpy ((char *) wave.riff.wav_id, "WAVE", 4);
|
memcpy (wave.riff.wav_id, "WAVE", 4);
|
||||||
|
|
||||||
strncpy ((char *) wave.format.id, "fmt ", 4);
|
memcpy (wave.format.id, "fmt ", 4);
|
||||||
wave.format.len = 16;
|
wave.format.len = 16;
|
||||||
|
|
||||||
wave.common.wFormatTag = WAVE_FORMAT_PCM;
|
wave.common.wFormatTag = WAVE_FORMAT_PCM;
|
||||||
|
@ -215,26 +185,52 @@ gst_wavenc_setup (GstWavEnc * wavenc)
|
||||||
wave.common.wBlockAlign =
|
wave.common.wBlockAlign =
|
||||||
wave.common.wChannels * (wave.common.wBitsPerSample >> 3);
|
wave.common.wChannels * (wave.common.wBitsPerSample >> 3);
|
||||||
|
|
||||||
strncpy ((char *) wave.data.id, "data", 4);
|
memcpy (wave.data.id, "data", 4);
|
||||||
wave.data.len = size - 44;
|
wave.data.len = audio_data_size;
|
||||||
|
|
||||||
strncpy ((char *) wavenc->header, (char *) wave.riff.id, 4);
|
memcpy (header, (char *) wave.riff.id, 4);
|
||||||
GST_WRITE_UINT32_LE (wavenc->header + 4, wave.riff.len);
|
GST_WRITE_UINT32_LE (header + 4, wave.riff.len);
|
||||||
strncpy ((char *) wavenc->header + 8, (char *) wave.riff.wav_id, 4);
|
memcpy (header + 8, (char *) wave.riff.wav_id, 4);
|
||||||
strncpy ((char *) wavenc->header + 12, (char *) wave.format.id, 4);
|
memcpy (header + 12, (char *) wave.format.id, 4);
|
||||||
GST_WRITE_UINT32_LE (wavenc->header + 16, wave.format.len);
|
GST_WRITE_UINT32_LE (header + 16, wave.format.len);
|
||||||
GST_WRITE_UINT16_LE (wavenc->header + 20, wave.common.wFormatTag);
|
GST_WRITE_UINT16_LE (header + 20, wave.common.wFormatTag);
|
||||||
GST_WRITE_UINT16_LE (wavenc->header + 22, wave.common.wChannels);
|
GST_WRITE_UINT16_LE (header + 22, wave.common.wChannels);
|
||||||
GST_WRITE_UINT32_LE (wavenc->header + 24, wave.common.dwSamplesPerSec);
|
GST_WRITE_UINT32_LE (header + 24, wave.common.dwSamplesPerSec);
|
||||||
GST_WRITE_UINT32_LE (wavenc->header + 28, wave.common.dwAvgBytesPerSec);
|
GST_WRITE_UINT32_LE (header + 28, wave.common.dwAvgBytesPerSec);
|
||||||
GST_WRITE_UINT16_LE (wavenc->header + 32, wave.common.wBlockAlign);
|
GST_WRITE_UINT16_LE (header + 32, wave.common.wBlockAlign);
|
||||||
GST_WRITE_UINT16_LE (wavenc->header + 34, wave.common.wBitsPerSample);
|
GST_WRITE_UINT16_LE (header + 34, wave.common.wBitsPerSample);
|
||||||
strncpy ((char *) wavenc->header + 36, (char *) wave.data.id, 4);
|
memcpy (header + 36, (char *) wave.data.id, 4);
|
||||||
GST_WRITE_UINT32_LE (wavenc->header + 40, wave.data.len);
|
GST_WRITE_UINT32_LE (header + 40, wave.data.len);
|
||||||
|
|
||||||
wavenc->length = 0;
|
gst_buffer_set_caps (buf, GST_PAD_CAPS (wavenc->srcpad));
|
||||||
wavenc->setup = TRUE;
|
|
||||||
return TRUE;
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
gst_wavenc_push_header (GstWavEnc * wavenc, guint audio_data_size)
|
||||||
|
{
|
||||||
|
GstFlowReturn ret;
|
||||||
|
GstBuffer *outbuf;
|
||||||
|
|
||||||
|
/* seek to beginning of file */
|
||||||
|
gst_pad_push_event (wavenc->srcpad,
|
||||||
|
gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES,
|
||||||
|
0, GST_CLOCK_TIME_NONE, 0));
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (wavenc, "writing header with datasize=%u", audio_data_size);
|
||||||
|
|
||||||
|
outbuf = gst_wavenc_create_header_buf (wavenc, audio_data_size);
|
||||||
|
GST_BUFFER_OFFSET (outbuf) = 0;
|
||||||
|
|
||||||
|
ret = gst_pad_push (wavenc->srcpad, outbuf);
|
||||||
|
|
||||||
|
if (ret != GST_FLOW_OK) {
|
||||||
|
GST_WARNING_OBJECT (wavenc, "push header failed: flow = %s",
|
||||||
|
gst_flow_get_name (ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -242,120 +238,71 @@ gst_wavenc_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstWavEnc *wavenc;
|
GstWavEnc *wavenc;
|
||||||
GstStructure *structure;
|
GstStructure *structure;
|
||||||
|
gint chans, rate, width, depth;
|
||||||
|
|
||||||
wavenc = GST_WAVENC (gst_pad_get_parent (pad));
|
wavenc = GST_WAVENC (gst_pad_get_parent (pad));
|
||||||
wavenc->setup = FALSE;
|
|
||||||
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
if (wavenc->sent_header) {
|
||||||
gst_structure_get_int (structure, "channels", (gint *) & wavenc->channels);
|
GST_WARNING_OBJECT (wavenc, "cannot change format in middle of stream");
|
||||||
gst_structure_get_int (structure, "rate", (gint *) & wavenc->rate);
|
goto fail;
|
||||||
gst_structure_get_int (structure, "depth", (gint *) & wavenc->bits);
|
|
||||||
|
|
||||||
gst_wavenc_setup (wavenc);
|
|
||||||
|
|
||||||
if (wavenc->setup) {
|
|
||||||
gst_object_unref (wavenc);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_object_unref (wavenc);
|
GST_DEBUG_OBJECT (wavenc, "got caps: %" GST_PTR_FORMAT, caps);
|
||||||
|
|
||||||
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
|
if (!gst_structure_get_int (structure, "channels", &chans) ||
|
||||||
|
!gst_structure_get_int (structure, "rate", &rate) ||
|
||||||
|
!gst_structure_get_int (structure, "width", &width) ||
|
||||||
|
(width != 8 && !gst_structure_get_int (structure, "depth", &depth))) {
|
||||||
|
GST_WARNING_OBJECT (wavenc, "caps incomplete");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
wavenc->channels = chans;
|
||||||
|
wavenc->width = width;
|
||||||
|
wavenc->depth = (width == 8) ? 8 : depth;
|
||||||
|
wavenc->rate = rate;
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (wavenc, "accepted caps: chans=%u width=%u depth=%u rate=%u",
|
||||||
|
wavenc->channels, wavenc->width, wavenc->depth, wavenc->rate);
|
||||||
|
|
||||||
|
gst_object_unref (wavenc);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
gst_object_unref (wavenc);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
#if 0
|
||||||
gst_wavenc_stop_file (GstWavEnc * wavenc)
|
static struct _maps
|
||||||
{
|
{
|
||||||
GstEvent *event;
|
const guint32 id;
|
||||||
GstBuffer *outbuf;
|
const gchar *name;
|
||||||
|
} maps[] = {
|
||||||
event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES,
|
|
||||||
0, GST_CLOCK_TIME_NONE, 0);
|
|
||||||
|
|
||||||
gst_pad_push_event (wavenc->srcpad, event);
|
|
||||||
|
|
||||||
outbuf = gst_buffer_new_and_alloc (WAV_HEADER_LEN);
|
|
||||||
GST_WRITE_UINT32_LE (wavenc->header + 4,
|
|
||||||
wavenc->length + (WAV_HEADER_LEN - 8));
|
|
||||||
GST_WRITE_UINT32_LE (wavenc->header + 40, wavenc->length);
|
|
||||||
memcpy (GST_BUFFER_DATA (outbuf), wavenc->header, WAV_HEADER_LEN);
|
|
||||||
GST_BUFFER_OFFSET (outbuf) = 0;
|
|
||||||
GST_BUFFER_OFFSET_END (outbuf) = WAV_HEADER_LEN;
|
|
||||||
GST_BUFFER_TIMESTAMP (outbuf) = 0;
|
|
||||||
|
|
||||||
if ((gst_pad_push (wavenc->srcpad, outbuf)) != GST_FLOW_OK)
|
|
||||||
GST_WARNING_OBJECT (wavenc, "couldn't push header....");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_wavenc_init (GstWavEnc * wavenc)
|
|
||||||
{
|
|
||||||
GstElementClass *klass = GST_ELEMENT_GET_CLASS (wavenc);
|
|
||||||
|
|
||||||
wavenc->sinkpad =
|
|
||||||
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
|
|
||||||
"sink"), "sink");
|
|
||||||
gst_element_add_pad (GST_ELEMENT (wavenc), wavenc->sinkpad);
|
|
||||||
gst_pad_set_chain_function (wavenc->sinkpad, gst_wavenc_chain);
|
|
||||||
gst_pad_set_event_function (wavenc->sinkpad, gst_wavenc_event);
|
|
||||||
gst_pad_set_setcaps_function (wavenc->sinkpad, gst_wavenc_sink_setcaps);
|
|
||||||
|
|
||||||
wavenc->srcpad =
|
|
||||||
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
|
|
||||||
"src"), "src");
|
|
||||||
gst_element_add_pad (GST_ELEMENT (wavenc), wavenc->srcpad);
|
|
||||||
|
|
||||||
wavenc->setup = FALSE;
|
|
||||||
wavenc->flush_header = TRUE;
|
|
||||||
wavenc->newmediacount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct _maps
|
|
||||||
{
|
|
||||||
guint32 id;
|
|
||||||
char *name;
|
|
||||||
}
|
|
||||||
maps[] = {
|
|
||||||
{
|
{
|
||||||
GST_RIFF_INFO_IARL, "Location"}
|
GST_RIFF_INFO_IARL, "Location"}, {
|
||||||
, {
|
GST_RIFF_INFO_IART, "Artist"}, {
|
||||||
GST_RIFF_INFO_IART, "Artist"}
|
GST_RIFF_INFO_ICMS, "Commissioner"}, {
|
||||||
, {
|
GST_RIFF_INFO_ICMT, "Comment"}, {
|
||||||
GST_RIFF_INFO_ICMS, "Commissioner"}
|
GST_RIFF_INFO_ICOP, "Copyright"}, {
|
||||||
, {
|
GST_RIFF_INFO_ICRD, "Creation Date"}, {
|
||||||
GST_RIFF_INFO_ICMT, "Comment"}
|
GST_RIFF_INFO_IENG, "Engineer"}, {
|
||||||
, {
|
GST_RIFF_INFO_IGNR, "Genre"}, {
|
||||||
GST_RIFF_INFO_ICOP, "Copyright"}
|
GST_RIFF_INFO_IKEY, "Keywords"}, {
|
||||||
, {
|
GST_RIFF_INFO_INAM, "Title"}, {
|
||||||
GST_RIFF_INFO_ICRD, "Creation Date"}
|
GST_RIFF_INFO_IPRD, "Product"}, {
|
||||||
, {
|
GST_RIFF_INFO_ISBJ, "Subject"}, {
|
||||||
GST_RIFF_INFO_IENG, "Engineer"}
|
GST_RIFF_INFO_ISFT, "Software"}, {
|
||||||
, {
|
|
||||||
GST_RIFF_INFO_IGNR, "Genre"}
|
|
||||||
, {
|
|
||||||
GST_RIFF_INFO_IKEY, "Keywords"}
|
|
||||||
, {
|
|
||||||
GST_RIFF_INFO_INAM, "Title"}
|
|
||||||
, /* Name */
|
|
||||||
{
|
|
||||||
GST_RIFF_INFO_IPRD, "Product"}
|
|
||||||
, {
|
|
||||||
GST_RIFF_INFO_ISBJ, "Subject"}
|
|
||||||
, {
|
|
||||||
GST_RIFF_INFO_ISFT, "Software"}
|
|
||||||
, {
|
|
||||||
GST_RIFF_INFO_ITCH, "Technician"}
|
GST_RIFF_INFO_ITCH, "Technician"}
|
||||||
, {
|
|
||||||
0, NULL}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
|
||||||
static guint32
|
static guint32
|
||||||
get_id_from_name (const char *name)
|
get_id_from_name (const char *name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; maps[i].name; i++) {
|
for (i = 0; i < G_N_ELEMENTS (maps); i++) {
|
||||||
if (strcasecmp (maps[i].name, name) == 0) {
|
if (strcasecmp (maps[i].name, name) == 0) {
|
||||||
return maps[i].id;
|
return maps[i].id;
|
||||||
}
|
}
|
||||||
|
@ -616,9 +563,8 @@ gst_wavenc_event (GstPad * pad, GstEvent * event)
|
||||||
wavenc = GST_WAVENC (gst_pad_get_parent (pad));
|
wavenc = GST_WAVENC (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
case GST_EVENT_EOS:
|
case GST_EVENT_EOS:{
|
||||||
wavenc->pad_eos = TRUE;
|
GST_DEBUG_OBJECT (wavenc, "got EOS");
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Write our metadata if we have any */
|
/* Write our metadata if we have any */
|
||||||
if (wavenc->metadata) {
|
if (wavenc->metadata) {
|
||||||
|
@ -627,25 +573,23 @@ gst_wavenc_event (GstPad * pad, GstEvent * event)
|
||||||
write_labels (wavenc);
|
write_labels (wavenc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
/* write header with correct length values */
|
||||||
|
gst_wavenc_push_header (wavenc, wavenc->length);
|
||||||
|
|
||||||
gst_wavenc_stop_file (wavenc);
|
/* and forward the EOS event */
|
||||||
|
res = gst_pad_event_default (pad, event);
|
||||||
break;
|
break;
|
||||||
case GST_EVENT_NEWSEGMENT:
|
|
||||||
if (wavenc->newmediacount++ > 0) {
|
|
||||||
gst_wavenc_stop_file (wavenc);
|
|
||||||
wavenc->setup = FALSE;
|
|
||||||
wavenc->flush_header = TRUE;
|
|
||||||
gst_wavenc_setup (wavenc);
|
|
||||||
}
|
}
|
||||||
|
case GST_EVENT_NEWSEGMENT:
|
||||||
|
/* Just drop it, it's probably in TIME format
|
||||||
|
* anyway. We'll send our own newsegment event */
|
||||||
|
gst_event_unref (event);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
res = gst_pad_event_default (pad, event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* and forward it */
|
|
||||||
res = gst_pad_event_default (pad, event);
|
|
||||||
|
|
||||||
gst_object_unref (wavenc);
|
gst_object_unref (wavenc);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -653,48 +597,62 @@ gst_wavenc_event (GstPad * pad, GstEvent * event)
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_wavenc_chain (GstPad * pad, GstBuffer * buf)
|
gst_wavenc_chain (GstPad * pad, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstWavEnc *wavenc;
|
GstWavEnc *wavenc = GST_WAVENC (GST_PAD_PARENT (pad));
|
||||||
GstFlowReturn result = GST_FLOW_OK;
|
GstFlowReturn flow = GST_FLOW_OK;
|
||||||
|
|
||||||
wavenc = GST_WAVENC (gst_pad_get_parent (pad));
|
g_return_val_if_fail (wavenc->channels > 0, GST_FLOW_WRONG_STATE);
|
||||||
|
|
||||||
if (!wavenc->setup) {
|
if (!wavenc->sent_header) {
|
||||||
gst_buffer_unref (buf);
|
/* use bogus size initially, we'll write the real
|
||||||
GST_ELEMENT_ERROR (wavenc, CORE, NEGOTIATION, (NULL),
|
* header when we get EOS and know the exact length */
|
||||||
("encoder not initialised (input is not audio?)"));
|
flow = gst_wavenc_push_header (wavenc, 0x7FFF0000);
|
||||||
result = GST_FLOW_ERROR;
|
|
||||||
goto beach;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wavenc->flush_header) {
|
if (flow != GST_FLOW_OK)
|
||||||
GstBuffer *outbuf;
|
return flow;
|
||||||
|
|
||||||
result =
|
GST_DEBUG_OBJECT (wavenc, "wrote dummy header");
|
||||||
gst_pad_alloc_buffer_and_set_caps (wavenc->srcpad,
|
wavenc->sent_header = TRUE;
|
||||||
GST_BUFFER_OFFSET_NONE, WAV_HEADER_LEN, GST_PAD_CAPS (wavenc->srcpad),
|
|
||||||
&outbuf);
|
|
||||||
if (result != GST_FLOW_OK) {
|
|
||||||
GST_WARNING_OBJECT (wavenc, "failed when allocating a %d bytes buffer "
|
|
||||||
"for headers", WAV_HEADER_LEN);
|
|
||||||
goto beach;
|
|
||||||
}
|
|
||||||
memcpy (GST_BUFFER_DATA (outbuf), wavenc->header, WAV_HEADER_LEN);
|
|
||||||
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
|
|
||||||
|
|
||||||
result = gst_pad_push (wavenc->srcpad, outbuf);
|
|
||||||
if (result != GST_FLOW_OK) {
|
|
||||||
GST_WARNING_OBJECT (wavenc, "failed when pushing header buffer");
|
|
||||||
goto beach;
|
|
||||||
}
|
|
||||||
wavenc->flush_header = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wavenc->length += GST_BUFFER_SIZE (buf);
|
wavenc->length += GST_BUFFER_SIZE (buf);
|
||||||
result = gst_pad_push (wavenc->srcpad, buf);
|
|
||||||
|
|
||||||
beach:
|
GST_LOG_OBJECT (wavenc, "pushing %u bytes raw audio, ts=%" GST_TIME_FORMAT,
|
||||||
gst_object_unref (wavenc);
|
GST_BUFFER_SIZE (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
|
||||||
return result;
|
|
||||||
|
buf = gst_buffer_make_metadata_writable (buf);
|
||||||
|
gst_buffer_set_caps (buf, GST_PAD_CAPS (wavenc->srcpad));
|
||||||
|
GST_BUFFER_OFFSET (buf) = WAV_HEADER_LEN + wavenc->length;
|
||||||
|
GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE;
|
||||||
|
|
||||||
|
flow = gst_pad_push (wavenc->srcpad, buf);
|
||||||
|
|
||||||
|
return flow;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstStateChangeReturn
|
||||||
|
gst_wavenc_change_state (GstElement * element, GstStateChange transition)
|
||||||
|
{
|
||||||
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
||||||
|
GstWavEnc *wavenc = GST_WAVENC (element);
|
||||||
|
|
||||||
|
switch (transition) {
|
||||||
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||||
|
wavenc->channels = 0;
|
||||||
|
wavenc->width = 0;
|
||||||
|
wavenc->depth = 0;
|
||||||
|
wavenc->rate = 0;
|
||||||
|
wavenc->length = 0;
|
||||||
|
wavenc->sent_header = FALSE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = parent_class->change_state (element, transition);
|
||||||
|
if (ret != GST_STATE_CHANGE_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __GST_WAVENC_H__
|
#ifndef __GST_WAV_ENC_H__
|
||||||
#define __GST_WAVENC_H__
|
#define __GST_WAV_ENC_H__
|
||||||
|
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
@ -34,31 +34,26 @@ G_BEGIN_DECLS
|
||||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_WAVENC,GstWavEncClass))
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_WAVENC,GstWavEncClass))
|
||||||
#define GST_IS_WAVENC(obj) \
|
#define GST_IS_WAVENC(obj) \
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WAVENC))
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WAVENC))
|
||||||
#define GST_IS_WAVENC_CLASS(obj) \
|
#define GST_IS_WAVENC_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_WAVENC))
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_WAVENC))
|
||||||
|
|
||||||
typedef struct _GstWavEnc GstWavEnc;
|
typedef struct _GstWavEnc GstWavEnc;
|
||||||
typedef struct _GstWavEncClass GstWavEncClass;
|
typedef struct _GstWavEncClass GstWavEncClass;
|
||||||
|
|
||||||
#define WAV_HEADER_LEN 44
|
|
||||||
|
|
||||||
struct _GstWavEnc {
|
struct _GstWavEnc {
|
||||||
GstElement element;
|
GstElement element;
|
||||||
|
|
||||||
/* pads */
|
GstPad *sinkpad;
|
||||||
GstPad *sinkpad,*srcpad;
|
GstPad *srcpad;
|
||||||
|
|
||||||
/* useful audio data */
|
/* useful audio data */
|
||||||
guint bits;
|
guint depth;
|
||||||
|
guint width;
|
||||||
guint rate;
|
guint rate;
|
||||||
guint channels;
|
guint channels;
|
||||||
guint width;
|
|
||||||
guint32 length;
|
guint32 length;
|
||||||
|
|
||||||
gboolean setup, flush_header, pad_eos;
|
gboolean sent_header;
|
||||||
guchar header[WAV_HEADER_LEN];
|
|
||||||
|
|
||||||
guint16 newmediacount;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstWavEncClass {
|
struct _GstWavEncClass {
|
||||||
|
@ -67,4 +62,4 @@ struct _GstWavEncClass {
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_ENC_H__ */
|
#endif /* __GST_WAV_ENC_H__ */
|
||||||
|
|
Loading…
Reference in a new issue