From 7b39d55850d32a2ecfb5c7552d2cd542f7897db5 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 24 May 2006 10:00:50 +0000 Subject: [PATCH] gst/law/: Some cleanups in the chain functions. Original commit message from CVS: * gst/law/alaw-decode.c: (gst_alawdec_chain): * gst/law/alaw-decode.h: * gst/law/alaw-encode.c: (gst_alawenc_chain): * gst/law/alaw-encode.h: * gst/law/mulaw-decode.c: (gst_mulawdec_chain): * gst/law/mulaw-decode.h: * gst/law/mulaw-encode.c: (gst_mulawenc_chain): * gst/law/mulaw-encode.h: Some cleanups in the chain functions. Remove some GStreamer 0.0.2 bits. --- ChangeLog | 13 +++++++++++++ gst/law/alaw-decode.c | 31 +++++++++++++++++++++---------- gst/law/alaw-decode.h | 16 ++-------------- gst/law/alaw-encode.c | 36 +++++++++++++++++++++++------------- gst/law/alaw-encode.h | 16 ++-------------- gst/law/mulaw-decode.c | 23 ++++++++++++++++++----- gst/law/mulaw-decode.h | 17 ++--------------- gst/law/mulaw-encode.c | 35 ++++++++++++++++++++++------------- gst/law/mulaw-encode.h | 15 ++------------- 9 files changed, 105 insertions(+), 97 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6f95aa9602..06bd139cd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-05-24 Wim Taymans + + * gst/law/alaw-decode.c: (gst_alawdec_chain): + * gst/law/alaw-decode.h: + * gst/law/alaw-encode.c: (gst_alawenc_chain): + * gst/law/alaw-encode.h: + * gst/law/mulaw-decode.c: (gst_mulawdec_chain): + * gst/law/mulaw-decode.h: + * gst/law/mulaw-encode.c: (gst_mulawenc_chain): + * gst/law/mulaw-encode.h: + Some cleanups in the chain functions. + Remove some GStreamer 0.0.2 bits. + 2006-05-23 Tim-Philipp Müller Patch by: Mark Nauwelaerts diff --git a/gst/law/alaw-decode.c b/gst/law/alaw-decode.c index 69951853a5..294406b76d 100644 --- a/gst/law/alaw-decode.c +++ b/gst/law/alaw-decode.c @@ -229,24 +229,35 @@ gst_alawdec_chain (GstPad * pad, GstBuffer * buffer) GstALawDec *alawdec; gint16 *linear_data; guint8 *alaw_data; + guint alaw_size; GstBuffer *outbuf; gint i; + GstFlowReturn ret; - alawdec = GST_ALAWDEC (GST_OBJECT_PARENT (pad)); + alawdec = GST_ALAWDEC (gst_pad_get_parent (pad)); + + alaw_data = GST_BUFFER_DATA (buffer); + alaw_size = GST_BUFFER_SIZE (buffer); + + outbuf = gst_buffer_new_and_alloc (alaw_size * 2); + linear_data = (gint16 *) GST_BUFFER_DATA (outbuf); + + /* copy discont flag */ + if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) + GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); - alaw_data = (guint8 *) GST_BUFFER_DATA (buffer); - outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer) * 2); GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer); GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (alawdec->srcpad)); - linear_data = (gint16 *) GST_BUFFER_DATA (outbuf); - for (i = 0; i < GST_BUFFER_SIZE (buffer); i++) { - *linear_data = alaw_to_s16 (*alaw_data); - linear_data++; - alaw_data++; + for (i = 0; i < alaw_size; i++) { + linear_data[i] = alaw_to_s16 (alaw_data[i]); } - gst_buffer_unref (buffer); - return gst_pad_push (alawdec->srcpad, outbuf); + + ret = gst_pad_push (alawdec->srcpad, outbuf); + + gst_object_unref (alawdec); + + return ret; } diff --git a/gst/law/alaw-decode.h b/gst/law/alaw-decode.h index aa3a418c29..19f97189cb 100644 --- a/gst/law/alaw-decode.h +++ b/gst/law/alaw-decode.h @@ -21,15 +21,9 @@ #ifndef __GST_ALAWDECODE_H__ #define __GST_ALAWDECODE_H__ - #include -/* #include */ - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +G_BEGIN_DECLS #define GST_TYPE_ALAWDEC \ (gst_alawdec_get_type()) @@ -49,9 +43,6 @@ struct _GstALawDec { GstElement element; GstPad *sinkpad,*srcpad; - - /*MetaAudioRaw meta; */ - }; struct _GstALawDecClass { @@ -60,9 +51,6 @@ struct _GstALawDecClass { GType gst_alawdec_get_type(void); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - +G_END_DECLS #endif /* __GST_STEREO_H__ */ diff --git a/gst/law/alaw-encode.c b/gst/law/alaw-encode.c index fbd7d6692e..991085da63 100644 --- a/gst/law/alaw-encode.c +++ b/gst/law/alaw-encode.c @@ -269,40 +269,50 @@ gst_alawenc_chain (GstPad * pad, GstBuffer * buffer) { GstALawEnc *alawenc; gint16 *linear_data; + guint linear_size; guint8 *alaw_data; + guint alaw_size; GstBuffer *outbuf; - gint bufsize; gint i; + GstFlowReturn ret; - alawenc = GST_ALAWENC (GST_OBJECT_PARENT (pad)); + alawenc = GST_ALAWENC (gst_pad_get_parent (pad)); if (!alawenc->rate || !alawenc->channels) goto not_negotiated; linear_data = (gint16 *) GST_BUFFER_DATA (buffer); - bufsize = GST_BUFFER_SIZE (buffer) / 2; - outbuf = gst_buffer_new_and_alloc (bufsize); + linear_size = GST_BUFFER_SIZE (buffer); - GST_BUFFER_DURATION (outbuf) = GST_SECOND * (bufsize) / - (alawenc->rate * alawenc->channels); + alaw_size = linear_size / 2; + + outbuf = gst_buffer_new_and_alloc (alaw_size); + alaw_data = (guint8 *) GST_BUFFER_DATA (outbuf); + + /* FIXME, just copy (and interpolate) timestamp */ + GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale_int (alaw_size, + GST_SECOND, alawenc->rate * alawenc->channels); GST_BUFFER_TIMESTAMP (outbuf) = alawenc->ts; alawenc->ts += GST_BUFFER_DURATION (outbuf); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (alawenc->srcpad)); - alaw_data = (guint8 *) GST_BUFFER_DATA (outbuf); - for (i = 0; i < GST_BUFFER_SIZE (outbuf); i++) { - *alaw_data = s16_to_alaw (*linear_data); - alaw_data++; - linear_data++; + for (i = 0; i < alaw_size; i++) { + alaw_data[i] = s16_to_alaw (linear_data[i]); } gst_buffer_unref (buffer); - return gst_pad_push (alawenc->srcpad, outbuf); + ret = gst_pad_push (alawenc->srcpad, outbuf); + +done: + gst_object_unref (alawenc); + + return ret; not_negotiated: { - return GST_FLOW_NOT_NEGOTIATED; + ret = GST_FLOW_NOT_NEGOTIATED; + goto done; } } diff --git a/gst/law/alaw-encode.h b/gst/law/alaw-encode.h index d7ed5be531..8e37cf3b7e 100644 --- a/gst/law/alaw-encode.h +++ b/gst/law/alaw-encode.h @@ -21,15 +21,9 @@ #ifndef __GST_ALAWENCODE_H__ #define __GST_ALAWENCODE_H__ - #include -/* #include */ - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +G_BEGIN_DECLS #define GST_TYPE_ALAWENC \ (gst_alawenc_get_type()) @@ -53,9 +47,6 @@ struct _GstALawEnc { gint channels; gint rate; - - /*MetaAudioRaw meta; */ - }; struct _GstALawEncClass { @@ -64,9 +55,6 @@ struct _GstALawEncClass { GType gst_alawenc_get_type(void); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - +G_END_DECLS #endif /* __GST_STEREO_H__ */ diff --git a/gst/law/mulaw-decode.c b/gst/law/mulaw-decode.c index 983c814b8a..d9babea407 100644 --- a/gst/law/mulaw-decode.c +++ b/gst/law/mulaw-decode.c @@ -205,20 +205,33 @@ gst_mulawdec_chain (GstPad * pad, GstBuffer * buffer) GstMuLawDec *mulawdec; gint16 *linear_data; guint8 *mulaw_data; + guint mulaw_size; GstBuffer *outbuf; + GstFlowReturn ret; - mulawdec = GST_MULAWDEC (GST_OBJECT_PARENT (pad)); + mulawdec = GST_MULAWDEC (gst_pad_get_parent (pad)); mulaw_data = (guint8 *) GST_BUFFER_DATA (buffer); - outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer) * 2); + mulaw_size = GST_BUFFER_SIZE (buffer); + + outbuf = gst_buffer_new_and_alloc (mulaw_size * 2); + linear_data = (gint16 *) GST_BUFFER_DATA (outbuf); + + /* copy discont flag */ + if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) + GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); + GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer); GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (mulawdec->srcpad)); - linear_data = (gint16 *) GST_BUFFER_DATA (outbuf); - mulaw_decode (mulaw_data, linear_data, GST_BUFFER_SIZE (buffer)); + mulaw_decode (mulaw_data, linear_data, mulaw_size); gst_buffer_unref (buffer); - return gst_pad_push (mulawdec->srcpad, outbuf); + ret = gst_pad_push (mulawdec->srcpad, outbuf); + + gst_object_unref (mulawdec); + + return ret; } diff --git a/gst/law/mulaw-decode.h b/gst/law/mulaw-decode.h index d34c8c068f..ea9aba06ee 100644 --- a/gst/law/mulaw-decode.h +++ b/gst/law/mulaw-decode.h @@ -17,19 +17,12 @@ * Boston, MA 02111-1307, USA. */ - #ifndef __GST_MULAWDECODE_H__ #define __GST_MULAWDECODE_H__ - #include -/* #include */ - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +G_BEGIN_DECLS #define GST_TYPE_MULAWDEC \ (gst_mulawdec_get_type()) @@ -49,9 +42,6 @@ struct _GstMuLawDec { GstElement element; GstPad *sinkpad,*srcpad; - - /*MetaAudioRaw meta; */ - }; struct _GstMuLawDecClass { @@ -60,9 +50,6 @@ struct _GstMuLawDecClass { GType gst_mulawdec_get_type(void); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - +G_END_DECLS #endif /* __GST_STEREO_H__ */ diff --git a/gst/law/mulaw-encode.c b/gst/law/mulaw-encode.c index 467553bbba..ae92fc4055 100644 --- a/gst/law/mulaw-encode.c +++ b/gst/law/mulaw-encode.c @@ -205,34 +205,43 @@ gst_mulawenc_chain (GstPad * pad, GstBuffer * buffer) GstMuLawEnc *mulawenc; gint16 *linear_data; guint8 *mulaw_data; + guint mulaw_size; GstBuffer *outbuf; - gint bufsize; + GstFlowReturn ret; - mulawenc = GST_MULAWENC (GST_OBJECT_PARENT (pad)); + mulawenc = GST_MULAWENC (gst_pad_get_parent (pad)); if (!mulawenc->rate || !mulawenc->channels) goto not_negotiated; linear_data = (gint16 *) GST_BUFFER_DATA (buffer); - bufsize = GST_BUFFER_SIZE (buffer) / 2; - outbuf = gst_buffer_new_and_alloc (bufsize); + mulaw_size = GST_BUFFER_SIZE (buffer) / 2; - GST_BUFFER_DURATION (outbuf) = GST_SECOND * (bufsize) / - (mulawenc->rate * mulawenc->channels); - GST_BUFFER_TIMESTAMP (outbuf) = mulawenc->ts; - mulawenc->ts += GST_BUFFER_DURATION (outbuf); - - gst_buffer_set_caps (outbuf, GST_PAD_CAPS (mulawenc->srcpad)); + outbuf = gst_buffer_new_and_alloc (mulaw_size); mulaw_data = (guint8 *) GST_BUFFER_DATA (outbuf); - mulaw_encode (linear_data, mulaw_data, GST_BUFFER_SIZE (outbuf)); + /* copy discont flag */ + if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) + GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); + + GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer); + GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer); + gst_buffer_set_caps (outbuf, GST_PAD_CAPS (mulawenc->srcpad)); + + mulaw_encode (linear_data, mulaw_data, mulaw_size); gst_buffer_unref (buffer); - return gst_pad_push (mulawenc->srcpad, outbuf); + ret = gst_pad_push (mulawenc->srcpad, outbuf); + +done: + gst_object_unref (mulawenc); + + return ret; not_negotiated: { - return GST_FLOW_NOT_NEGOTIATED; + ret = GST_FLOW_NOT_NEGOTIATED; + goto done; } } diff --git a/gst/law/mulaw-encode.h b/gst/law/mulaw-encode.h index 3f431fd6b4..0db3e1af83 100644 --- a/gst/law/mulaw-encode.h +++ b/gst/law/mulaw-encode.h @@ -21,15 +21,9 @@ #ifndef __GST_MULAWENCODE_H__ #define __GST_MULAWENCODE_H__ - #include -/* #include */ - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +G_BEGIN_DECLS #define GST_TYPE_MULAWENC \ (gst_mulawenc_get_type()) @@ -54,8 +48,6 @@ struct _GstMuLawEnc { gint channels; gint rate; - /*MetaAudioRaw meta; */ - }; struct _GstMuLawEncClass { @@ -64,9 +56,6 @@ struct _GstMuLawEncClass { GType gst_mulawenc_get_type(void); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - +G_END_DECLS #endif /* __GST_STEREO_H__ */