siren: Port to 1.0 API

This commit is contained in:
Olivier Crête 2012-09-12 12:14:53 -04:00
parent 56ef4054ee
commit f207edfc44
3 changed files with 49 additions and 110 deletions

View file

@ -318,7 +318,7 @@ GST_PLUGINS_NONPORTED=" aiff \
kate liveadder librfb \ kate liveadder librfb \
mpegpsmux mve mxf mythtv nsf nuvdemux \ mpegpsmux mve mxf mythtv nsf nuvdemux \
patchdetect pnm real \ patchdetect pnm real \
sdi siren speed subenc stereo tta videofilters \ sdi speed subenc stereo tta videofilters \
videomeasure videosignal vmnc \ videomeasure videosignal vmnc \
decklink fbdev linsys vcd \ decklink fbdev linsys vcd \
apexsink cdaudio cog dc1394 dirac directfb \ apexsink cdaudio cog dc1394 dirac directfb \

View file

@ -50,25 +50,9 @@ static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, " GST_STATIC_CAPS ("audio/x-raw, format = (string) \"S16LE\", "
"width = (int) 16, "
"depth = (int) 16, "
"endianness = (int) 1234, "
"signed = (boolean) true, "
"rate = (int) 16000, " "channels = (int) 1")); "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_start (GstAudioDecoder * dec);
static gboolean gst_siren_dec_stop (GstAudioDecoder * dec); static gboolean gst_siren_dec_stop (GstAudioDecoder * dec);
static gboolean gst_siren_dec_set_format (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, static GstFlowReturn gst_siren_dec_handle_frame (GstAudioDecoder * dec,
GstBuffer * buffer); 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, G_DEFINE_TYPE (GstSirenDec, gst_siren_dec, GST_TYPE_AUDIO_DECODER);
GST_TYPE_AUDIO_DECODER, _do_init);
static void static void
gst_siren_dec_base_init (gpointer klass) gst_siren_dec_class_init (GstSirenDecClass * klass)
{ {
GstElementClass *element_class = GST_ELEMENT_CLASS (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_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&srctemplate)); gst_static_pad_template_get (&srctemplate));
@ -101,14 +84,6 @@ gst_siren_dec_base_init (gpointer klass)
"Codec/Decoder/Audio ", "Codec/Decoder/Audio ",
"Decode streams encoded with the Siren7 codec into 16bit PCM", "Decode streams encoded with the Siren7 codec into 16bit PCM",
"Youness Alaoui <kakaroto@kakaroto.homelinux.net>"); "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->start = GST_DEBUG_FUNCPTR (gst_siren_dec_start);
base_class->stop = GST_DEBUG_FUNCPTR (gst_siren_dec_stop); base_class->stop = GST_DEBUG_FUNCPTR (gst_siren_dec_stop);
@ -120,7 +95,7 @@ gst_siren_dec_class_init (GstSirenDecClass * klass)
} }
static void static void
gst_siren_dec_init (GstSirenDec * dec, GstSirenDecClass * klass) gst_siren_dec_init (GstSirenDec * dec)
{ {
} }
@ -151,27 +126,14 @@ gst_siren_dec_stop (GstAudioDecoder * dec)
return TRUE; return TRUE;
} }
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 static gboolean
gst_siren_dec_set_format (GstAudioDecoder * bdec, GstCaps * caps) gst_siren_dec_set_format (GstAudioDecoder * bdec, GstCaps * caps)
{ {
GstSirenDec *dec; GstAudioInfo info;
dec = GST_SIREN_DEC (bdec); gst_audio_info_init (&info);
gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_S16LE, 16000, 1, NULL);
return gst_siren_dec_negotiate (dec); return gst_audio_decoder_set_output_format (bdec, &info);
} }
static GstFlowReturn static GstFlowReturn
@ -190,7 +152,7 @@ gst_siren_dec_parse (GstAudioDecoder * dec, GstAdapter * adapter,
*offset = 0; *offset = 0;
*length = size - (size % 40); *length = size - (size % 40);
} else { } else {
ret = GST_FLOW_UNEXPECTED; ret = GST_FLOW_EOS;
} }
return ret; return ret;
@ -206,10 +168,11 @@ gst_siren_dec_handle_frame (GstAudioDecoder * bdec, GstBuffer * buf)
guint i, size, num_frames; guint i, size, num_frames;
gint out_size, in_size; gint out_size, in_size;
gint decode_ret; gint decode_ret;
GstMapInfo inmap, outmap;
dec = GST_SIREN_DEC (bdec); 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); 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, GST_LOG_OBJECT (dec, "we have %u frames, %u in, %u out", num_frames, in_size,
out_size); out_size);
/* allow and handle un-negotiated input */ out_buf = gst_audio_decoder_allocate_output_buffer (bdec, out_size);
if (G_UNLIKELY (GST_PAD_CAPS (GST_AUDIO_DECODER_SRC_PAD (dec)) == NULL)) { if (out_buf == 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)
goto alloc_failed; goto alloc_failed;
/* get the input data for all the frames */ /* get the input data for all the frames */
in_data = GST_BUFFER_DATA (buf); gst_buffer_map (buf, &inmap, GST_MAP_READ);
out_data = GST_BUFFER_DATA (out_buf); gst_buffer_map (out_buf, &outmap, GST_MAP_WRITE);
in_data = inmap.data;
out_data = outmap.data;
for (i = 0; i < num_frames; i++) { for (i = 0; i < num_frames; i++) {
GST_LOG_OBJECT (dec, "Decoding frame %u/%u", i, num_frames); 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; in_data += 40;
} }
gst_buffer_unmap (buf, &inmap);
gst_buffer_unmap (out_buf, &outmap);
GST_LOG_OBJECT (dec, "Finished decoding"); GST_LOG_OBJECT (dec, "Finished decoding");
/* might really be multiple frames, /* might really be multiple frames,

View file

@ -50,25 +50,9 @@ static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", static GstStaticPadTemplate sinktemplate = 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, format = (string) \"S16LE\", "
"width = (int) 16, "
"depth = (int) 16, "
"endianness = (int) 1234, "
"signed = (boolean) true, "
"rate = (int) 16000, " "channels = (int) 1")); "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_start (GstAudioEncoder * enc);
static gboolean gst_siren_enc_stop (GstAudioEncoder * enc); static gboolean gst_siren_enc_stop (GstAudioEncoder * enc);
static gboolean gst_siren_enc_set_format (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, static GstFlowReturn gst_siren_enc_handle_frame (GstAudioEncoder * enc,
GstBuffer * in_buf); GstBuffer * in_buf);
static void G_DEFINE_TYPE (GstSirenEnc, gst_siren_enc, GST_TYPE_AUDIO_ENCODER);
_do_init (GType type)
{
GST_DEBUG_CATEGORY_INIT (sirenenc_debug, "sirenenc", 0, "sirenenc");
}
GST_BOILERPLATE_FULL (GstSirenEnc, gst_siren_enc, GstAudioEncoder,
GST_TYPE_AUDIO_ENCODER, _do_init);
static void static void
gst_siren_enc_base_init (gpointer klass) gst_siren_enc_class_init (GstSirenEncClass * klass)
{ {
GstElementClass *element_class = GST_ELEMENT_CLASS (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_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&srctemplate)); gst_static_pad_template_get (&srctemplate));
@ -99,14 +82,6 @@ gst_siren_enc_base_init (gpointer klass)
"Codec/Encoder/Audio ", "Codec/Encoder/Audio ",
"Encode 16bit PCM streams into the Siren7 codec", "Encode 16bit PCM streams into the Siren7 codec",
"Youness Alaoui <kakaroto@kakaroto.homelinux.net>"); "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->start = GST_DEBUG_FUNCPTR (gst_siren_enc_start);
base_class->stop = GST_DEBUG_FUNCPTR (gst_siren_enc_stop); base_class->stop = GST_DEBUG_FUNCPTR (gst_siren_enc_stop);
@ -117,7 +92,7 @@ gst_siren_enc_class_init (GstSirenEncClass * klass)
} }
static void 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 static gboolean
gst_siren_enc_set_format (GstAudioEncoder * benc, GstAudioInfo * info) gst_siren_enc_set_format (GstAudioEncoder * benc, GstAudioInfo * info)
{ {
GstSirenEnc *enc;
gboolean res; gboolean res;
GstCaps *outcaps; GstCaps *outcaps;
enc = GST_SIREN_ENC (benc);
outcaps = gst_static_pad_template_get_caps (&srctemplate); 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); gst_caps_unref (outcaps);
/* report needs to base class */ /* report needs to base class */
@ -178,14 +150,15 @@ gst_siren_enc_handle_frame (GstAudioEncoder * benc, GstBuffer * buf)
guint i, size, num_frames; guint i, size, num_frames;
gint out_size, in_size; gint out_size, in_size;
gint encode_ret; gint encode_ret;
GstMapInfo inmap, outmap;
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR); g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
enc = GST_SIREN_ENC (benc); 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 > 0, GST_FLOW_ERROR);
g_return_val_if_fail (size % 640 == 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); out_size);
/* get a buffer */ /* get a buffer */
ret = gst_pad_alloc_buffer_and_set_caps (GST_AUDIO_ENCODER_SRC_PAD (benc), out_buf = gst_audio_encoder_allocate_output_buffer (benc, out_size);
-1, out_size, GST_PAD_CAPS (GST_AUDIO_ENCODER_SRC_PAD (benc)), &out_buf); if (out_buf == NULL)
if (ret != GST_FLOW_OK)
goto alloc_failed; goto alloc_failed;
/* get the input data for all the frames */ /* get the input data for all the frames */
in_data = GST_BUFFER_DATA (buf); gst_buffer_map (buf, &inmap, GST_MAP_READ);
out_data = GST_BUFFER_DATA (out_buf); gst_buffer_map (out_buf, &outmap, GST_MAP_READ);
in_data = inmap.data;
out_data = outmap.data;
for (i = 0; i < num_frames; i++) { for (i = 0; i < num_frames; i++) {
GST_LOG_OBJECT (enc, "Encoding frame %u/%u", i, num_frames); 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; in_data += 640;
} }
gst_buffer_unmap (buf, &inmap);
gst_buffer_unmap (out_buf, &outmap);
GST_LOG_OBJECT (enc, "Finished encoding"); GST_LOG_OBJECT (enc, "Finished encoding");
/* we encode all we get, pass it along */ /* we encode all we get, pass it along */