Commit 7b39d558 authored by Wim Taymans's avatar Wim Taymans

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.
parent d4e266cd
2006-05-24 Wim Taymans <wim@fluendo.com>
* 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 <tim at centricular dot net>
Patch by: Mark Nauwelaerts <manauw at skynet be>
......
......@@ -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;
}
......@@ -21,15 +21,9 @@
#ifndef __GST_ALAWDECODE_H__
#define __GST_ALAWDECODE_H__
#include <gst/gst.h>
/* #include <gst/meta/audioraw.h> */
#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__ */
......@@ -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;
}
}
......@@ -21,15 +21,9 @@
#ifndef __GST_ALAWENCODE_H__
#define __GST_ALAWENCODE_H__
#include <gst/gst.h>
/* #include <gst/meta/audioraw.h> */
#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__ */
......@@ -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;
}
......@@ -17,19 +17,12 @@
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_MULAWDECODE_H__
#define __GST_MULAWDECODE_H__
#include <gst/gst.h>
/* #include <gst/meta/audioraw.h> */
#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__ */
......@@ -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;
outbuf = gst_buffer_new_and_alloc (mulaw_size);
mulaw_data = (guint8 *) GST_BUFFER_DATA (outbuf);
GST_BUFFER_DURATION (outbuf) = GST_SECOND * (bufsize) /
(mulawenc->rate * mulawenc->channels);
GST_BUFFER_TIMESTAMP (outbuf) = mulawenc->ts;
mulawenc->ts += GST_BUFFER_DURATION (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_data = (guint8 *) GST_BUFFER_DATA (outbuf);
mulaw_encode (linear_data, mulaw_data, GST_BUFFER_SIZE (outbuf));
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;
}
}
......@@ -21,15 +21,9 @@
#ifndef __GST_MULAWENCODE_H__
#define __GST_MULAWENCODE_H__
#include <gst/gst.h>
/* #include <gst/meta/audioraw.h> */
#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__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment