summaryrefslogtreecommitdiff
path: root/gst/siren
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.com>2012-09-12 12:14:53 -0400
committerOlivier CrĂȘte <olivier.crete@collabora.com>2012-09-12 12:14:53 -0400
commitf207edfc44c9a2ae4a19824c5b500503e8899253 (patch)
treef31fdf3bd1ecf4b974915107253e4dc0d5fc606a /gst/siren
parent56ef4054eea31e296e5894ca46ffb0a55c05c2ef (diff)
siren: Port to 1.0 API
Diffstat (limited to 'gst/siren')
-rw-r--r--gst/siren/gstsirendec.c90
-rw-r--r--gst/siren/gstsirenenc.c67
2 files changed, 48 insertions, 109 deletions
diff --git a/gst/siren/gstsirendec.c b/gst/siren/gstsirendec.c
index 9dd12c359..72f44770f 100644
--- a/gst/siren/gstsirendec.c
+++ b/gst/siren/gstsirendec.c
@@ -50,25 +50,9 @@ static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-int, "
- "width = (int) 16, "
- "depth = (int) 16, "
- "endianness = (int) 1234, "
- "signed = (boolean) true, "
+ GST_STATIC_CAPS ("audio/x-raw, format = (string) \"S16LE\", "
"rate = (int) 16000, " "channels = (int) 1"));
-/* signals and args */
-enum
-{
- /* FILL ME */
- LAST_SIGNAL
-};
-
-enum
-{
- ARG_0,
-};
-
static gboolean gst_siren_dec_start (GstAudioDecoder * dec);
static gboolean gst_siren_dec_stop (GstAudioDecoder * dec);
static gboolean gst_siren_dec_set_format (GstAudioDecoder * dec,
@@ -78,19 +62,18 @@ static gboolean gst_siren_dec_parse (GstAudioDecoder * dec,
static GstFlowReturn gst_siren_dec_handle_frame (GstAudioDecoder * dec,
GstBuffer * buffer);
-static void
-_do_init (GType type)
-{
- GST_DEBUG_CATEGORY_INIT (sirendec_debug, "sirendec", 0, "sirendec");
-}
-GST_BOILERPLATE_FULL (GstSirenDec, gst_siren_dec, GstAudioDecoder,
- GST_TYPE_AUDIO_DECODER, _do_init);
+G_DEFINE_TYPE (GstSirenDec, gst_siren_dec, GST_TYPE_AUDIO_DECODER);
static void
-gst_siren_dec_base_init (gpointer klass)
+gst_siren_dec_class_init (GstSirenDecClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+ GstAudioDecoderClass *base_class = GST_AUDIO_DECODER_CLASS (klass);
+
+ GST_DEBUG ("Initializing Class");
+
+ GST_DEBUG_CATEGORY_INIT (sirendec_debug, "sirendec", 0, "sirendec");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&srctemplate));
@@ -101,14 +84,6 @@ gst_siren_dec_base_init (gpointer klass)
"Codec/Decoder/Audio ",
"Decode streams encoded with the Siren7 codec into 16bit PCM",
"Youness Alaoui <kakaroto@kakaroto.homelinux.net>");
-}
-
-static void
-gst_siren_dec_class_init (GstSirenDecClass * klass)
-{
- GstAudioDecoderClass *base_class = GST_AUDIO_DECODER_CLASS (klass);
-
- GST_DEBUG ("Initializing Class");
base_class->start = GST_DEBUG_FUNCPTR (gst_siren_dec_start);
base_class->stop = GST_DEBUG_FUNCPTR (gst_siren_dec_stop);
@@ -120,7 +95,7 @@ gst_siren_dec_class_init (GstSirenDecClass * klass)
}
static void
-gst_siren_dec_init (GstSirenDec * dec, GstSirenDecClass * klass)
+gst_siren_dec_init (GstSirenDec * dec)
{
}
@@ -152,26 +127,13 @@ gst_siren_dec_stop (GstAudioDecoder * dec)
}
static gboolean
-gst_siren_dec_negotiate (GstSirenDec * dec)
-{
- gboolean res;
- GstCaps *outcaps;
-
- outcaps = gst_static_pad_template_get_caps (&srctemplate);
- res = gst_pad_set_caps (GST_AUDIO_DECODER_SRC_PAD (dec), outcaps);
- gst_caps_unref (outcaps);
-
- return res;
-}
-
-static gboolean
gst_siren_dec_set_format (GstAudioDecoder * bdec, GstCaps * caps)
{
- GstSirenDec *dec;
-
- dec = GST_SIREN_DEC (bdec);
+ GstAudioInfo info;
- return gst_siren_dec_negotiate (dec);
+ gst_audio_info_init (&info);
+ gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_S16LE, 16000, 1, NULL);
+ return gst_audio_decoder_set_output_format (bdec, &info);
}
static GstFlowReturn
@@ -190,7 +152,7 @@ gst_siren_dec_parse (GstAudioDecoder * dec, GstAdapter * adapter,
*offset = 0;
*length = size - (size % 40);
} else {
- ret = GST_FLOW_UNEXPECTED;
+ ret = GST_FLOW_EOS;
}
return ret;
@@ -206,10 +168,11 @@ gst_siren_dec_handle_frame (GstAudioDecoder * bdec, GstBuffer * buf)
guint i, size, num_frames;
gint out_size, in_size;
gint decode_ret;
+ GstMapInfo inmap, outmap;
dec = GST_SIREN_DEC (bdec);
- size = GST_BUFFER_SIZE (buf);
+ size = gst_buffer_get_size (buf);
GST_LOG_OBJECT (dec, "Received buffer of size %u", size);
@@ -226,20 +189,16 @@ gst_siren_dec_handle_frame (GstAudioDecoder * bdec, GstBuffer * buf)
GST_LOG_OBJECT (dec, "we have %u frames, %u in, %u out", num_frames, in_size,
out_size);
- /* allow and handle un-negotiated input */
- if (G_UNLIKELY (GST_PAD_CAPS (GST_AUDIO_DECODER_SRC_PAD (dec)) == NULL)) {
- gst_siren_dec_negotiate (dec);
- }
-
- /* get a buffer */
- ret = gst_pad_alloc_buffer_and_set_caps (GST_AUDIO_DECODER_SRC_PAD (dec), -1,
- out_size, GST_PAD_CAPS (GST_AUDIO_DECODER_SRC_PAD (dec)), &out_buf);
- if (ret != GST_FLOW_OK)
+ out_buf = gst_audio_decoder_allocate_output_buffer (bdec, out_size);
+ if (out_buf == NULL)
goto alloc_failed;
/* get the input data for all the frames */
- in_data = GST_BUFFER_DATA (buf);
- out_data = GST_BUFFER_DATA (out_buf);
+ gst_buffer_map (buf, &inmap, GST_MAP_READ);
+ gst_buffer_map (out_buf, &outmap, GST_MAP_WRITE);
+
+ in_data = inmap.data;
+ out_data = outmap.data;
for (i = 0; i < num_frames; i++) {
GST_LOG_OBJECT (dec, "Decoding frame %u/%u", i, num_frames);
@@ -254,6 +213,9 @@ gst_siren_dec_handle_frame (GstAudioDecoder * bdec, GstBuffer * buf)
in_data += 40;
}
+ gst_buffer_unmap (buf, &inmap);
+ gst_buffer_unmap (out_buf, &outmap);
+
GST_LOG_OBJECT (dec, "Finished decoding");
/* might really be multiple frames,
diff --git a/gst/siren/gstsirenenc.c b/gst/siren/gstsirenenc.c
index 6bcf20568..a16ccafc7 100644
--- a/gst/siren/gstsirenenc.c
+++ b/gst/siren/gstsirenenc.c
@@ -50,25 +50,9 @@ static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-int, "
- "width = (int) 16, "
- "depth = (int) 16, "
- "endianness = (int) 1234, "
- "signed = (boolean) true, "
+ GST_STATIC_CAPS ("audio/x-raw, format = (string) \"S16LE\", "
"rate = (int) 16000, " "channels = (int) 1"));
-/* signals and args */
-enum
-{
- /* FILL ME */
- LAST_SIGNAL
-};
-
-enum
-{
- ARG_0,
-};
-
static gboolean gst_siren_enc_start (GstAudioEncoder * enc);
static gboolean gst_siren_enc_stop (GstAudioEncoder * enc);
static gboolean gst_siren_enc_set_format (GstAudioEncoder * enc,
@@ -76,19 +60,18 @@ static gboolean gst_siren_enc_set_format (GstAudioEncoder * enc,
static GstFlowReturn gst_siren_enc_handle_frame (GstAudioEncoder * enc,
GstBuffer * in_buf);
-static void
-_do_init (GType type)
-{
- GST_DEBUG_CATEGORY_INIT (sirenenc_debug, "sirenenc", 0, "sirenenc");
-}
+G_DEFINE_TYPE (GstSirenEnc, gst_siren_enc, GST_TYPE_AUDIO_ENCODER);
-GST_BOILERPLATE_FULL (GstSirenEnc, gst_siren_enc, GstAudioEncoder,
- GST_TYPE_AUDIO_ENCODER, _do_init);
static void
-gst_siren_enc_base_init (gpointer klass)
+gst_siren_enc_class_init (GstSirenEncClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+ GstAudioEncoderClass *base_class = GST_AUDIO_ENCODER_CLASS (klass);
+
+ GST_DEBUG ("Initializing Class");
+
+ GST_DEBUG_CATEGORY_INIT (sirenenc_debug, "sirenenc", 0, "sirenenc");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&srctemplate));
@@ -99,14 +82,6 @@ gst_siren_enc_base_init (gpointer klass)
"Codec/Encoder/Audio ",
"Encode 16bit PCM streams into the Siren7 codec",
"Youness Alaoui <kakaroto@kakaroto.homelinux.net>");
-}
-
-static void
-gst_siren_enc_class_init (GstSirenEncClass * klass)
-{
- GstAudioEncoderClass *base_class = GST_AUDIO_ENCODER_CLASS (klass);
-
- GST_DEBUG ("Initializing Class");
base_class->start = GST_DEBUG_FUNCPTR (gst_siren_enc_start);
base_class->stop = GST_DEBUG_FUNCPTR (gst_siren_enc_stop);
@@ -117,7 +92,7 @@ gst_siren_enc_class_init (GstSirenEncClass * klass)
}
static void
-gst_siren_enc_init (GstSirenEnc * enc, GstSirenEncClass * klass)
+gst_siren_enc_init (GstSirenEnc * enc)
{
}
@@ -148,14 +123,11 @@ gst_siren_enc_stop (GstAudioEncoder * enc)
static gboolean
gst_siren_enc_set_format (GstAudioEncoder * benc, GstAudioInfo * info)
{
- GstSirenEnc *enc;
gboolean res;
GstCaps *outcaps;
- enc = GST_SIREN_ENC (benc);
-
outcaps = gst_static_pad_template_get_caps (&srctemplate);
- res = gst_pad_set_caps (GST_AUDIO_ENCODER_SRC_PAD (enc), outcaps);
+ res = gst_audio_encoder_set_output_format (benc, outcaps);
gst_caps_unref (outcaps);
/* report needs to base class */
@@ -178,14 +150,15 @@ gst_siren_enc_handle_frame (GstAudioEncoder * benc, GstBuffer * buf)
guint i, size, num_frames;
gint out_size, in_size;
gint encode_ret;
+ GstMapInfo inmap, outmap;
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
enc = GST_SIREN_ENC (benc);
- size = GST_BUFFER_SIZE (buf);
+ size = gst_buffer_get_size (buf);
- GST_LOG_OBJECT (enc, "Received buffer of size %d", GST_BUFFER_SIZE (buf));
+ GST_LOG_OBJECT (enc, "Received buffer of size %d", size);
g_return_val_if_fail (size > 0, GST_FLOW_ERROR);
g_return_val_if_fail (size % 640 == 0, GST_FLOW_ERROR);
@@ -202,14 +175,15 @@ gst_siren_enc_handle_frame (GstAudioEncoder * benc, GstBuffer * buf)
out_size);
/* get a buffer */
- ret = gst_pad_alloc_buffer_and_set_caps (GST_AUDIO_ENCODER_SRC_PAD (benc),
- -1, out_size, GST_PAD_CAPS (GST_AUDIO_ENCODER_SRC_PAD (benc)), &out_buf);
- if (ret != GST_FLOW_OK)
+ out_buf = gst_audio_encoder_allocate_output_buffer (benc, out_size);
+ if (out_buf == NULL)
goto alloc_failed;
/* get the input data for all the frames */
- in_data = GST_BUFFER_DATA (buf);
- out_data = GST_BUFFER_DATA (out_buf);
+ gst_buffer_map (buf, &inmap, GST_MAP_READ);
+ gst_buffer_map (out_buf, &outmap, GST_MAP_READ);
+ in_data = inmap.data;
+ out_data = outmap.data;
for (i = 0; i < num_frames; i++) {
GST_LOG_OBJECT (enc, "Encoding frame %u/%u", i, num_frames);
@@ -224,6 +198,9 @@ gst_siren_enc_handle_frame (GstAudioEncoder * benc, GstBuffer * buf)
in_data += 640;
}
+ gst_buffer_unmap (buf, &inmap);
+ gst_buffer_unmap (out_buf, &outmap);
+
GST_LOG_OBJECT (enc, "Finished encoding");
/* we encode all we get, pass it along */