diff options
author | Andy Wingo <wingo@pobox.com> | 2001-12-22 23:27:31 +0000 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2001-12-22 23:27:31 +0000 |
commit | 185612aae3b8acae2b32e0e6561691a7c640cd0d (patch) | |
tree | 7cd1990c3df5c63f402f3e0bdf6b51b3ed58fc41 /gst/law | |
parent | 87dab192cf5792f847a22e0c3e9afe78553739b5 (diff) |
Initial revision
Original commit message from CVS:
Initial revision
Diffstat (limited to 'gst/law')
-rw-r--r-- | gst/law/Makefile.am | 12 | ||||
-rw-r--r-- | gst/law/alaw-conversion.c | 195 | ||||
-rw-r--r-- | gst/law/alaw-conversion.h | 12 | ||||
-rw-r--r-- | gst/law/alaw-decode.c | 186 | ||||
-rw-r--r-- | gst/law/alaw-decode.h | 69 | ||||
-rw-r--r-- | gst/law/alaw-encode.c | 182 | ||||
-rw-r--r-- | gst/law/alaw-encode.h | 69 | ||||
-rw-r--r-- | gst/law/alaw.c | 95 | ||||
-rw-r--r-- | gst/law/mulaw-conversion.c | 102 | ||||
-rw-r--r-- | gst/law/mulaw-conversion.h | 10 | ||||
-rw-r--r-- | gst/law/mulaw-decode.c | 181 | ||||
-rw-r--r-- | gst/law/mulaw-decode.h | 69 | ||||
-rw-r--r-- | gst/law/mulaw-encode.c | 181 | ||||
-rw-r--r-- | gst/law/mulaw-encode.h | 69 | ||||
-rw-r--r-- | gst/law/mulaw.c | 103 |
15 files changed, 1535 insertions, 0 deletions
diff --git a/gst/law/Makefile.am b/gst/law/Makefile.am new file mode 100644 index 00000000..76a73f79 --- /dev/null +++ b/gst/law/Makefile.am @@ -0,0 +1,12 @@ +filterdir = $(libdir)/gst + +filter_LTLIBRARIES = libgstalaw.la libgstmulaw.la + +libgstalaw_la_SOURCES = alaw-encode.c mulaw-conversion.c alaw-conversion.c alaw-decode.c alaw.c +libgstalaw_la_CFLAGS = $(GST_CFLAGS) + +libgstmulaw_la_SOURCES = mulaw-encode.c mulaw-conversion.c mulaw-decode.c mulaw.c +libgstmulaw_la_CFLAGS = $(GST_CFLAGS) + +noinst_HEADERS = mulaw-conversion.h alaw-encode.h alaw-decode.h alaw-conversion.h mulaw-encode.h mulaw-decode.h +filterdir = $(libdir)/gst diff --git a/gst/law/alaw-conversion.c b/gst/law/alaw-conversion.c new file mode 100644 index 00000000..cb3be3e9 --- /dev/null +++ b/gst/law/alaw-conversion.c @@ -0,0 +1,195 @@ +/* $Id$ + + * Linux ISDN subsystem, audio conversion and compression (linklevel). + * + * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de) + * DTMF code (c) 1996 by Christian Mock (cm@kukuruz.ping.at) + * Silence detection (c) 1998 by Armin Schindler (mac@gismo.telekom.de) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <glib.h> +/* + * Misc. lookup-tables. + */ + +/* ulaw -> signed 16-bit */ +static gint16 isdn_audio_ulaw_to_s16[] = +{ + 0x8284, 0x8684, 0x8a84, 0x8e84, 0x9284, 0x9684, 0x9a84, 0x9e84, + 0xa284, 0xa684, 0xaa84, 0xae84, 0xb284, 0xb684, 0xba84, 0xbe84, + 0xc184, 0xc384, 0xc584, 0xc784, 0xc984, 0xcb84, 0xcd84, 0xcf84, + 0xd184, 0xd384, 0xd584, 0xd784, 0xd984, 0xdb84, 0xdd84, 0xdf84, + 0xe104, 0xe204, 0xe304, 0xe404, 0xe504, 0xe604, 0xe704, 0xe804, + 0xe904, 0xea04, 0xeb04, 0xec04, 0xed04, 0xee04, 0xef04, 0xf004, + 0xf0c4, 0xf144, 0xf1c4, 0xf244, 0xf2c4, 0xf344, 0xf3c4, 0xf444, + 0xf4c4, 0xf544, 0xf5c4, 0xf644, 0xf6c4, 0xf744, 0xf7c4, 0xf844, + 0xf8a4, 0xf8e4, 0xf924, 0xf964, 0xf9a4, 0xf9e4, 0xfa24, 0xfa64, + 0xfaa4, 0xfae4, 0xfb24, 0xfb64, 0xfba4, 0xfbe4, 0xfc24, 0xfc64, + 0xfc94, 0xfcb4, 0xfcd4, 0xfcf4, 0xfd14, 0xfd34, 0xfd54, 0xfd74, + 0xfd94, 0xfdb4, 0xfdd4, 0xfdf4, 0xfe14, 0xfe34, 0xfe54, 0xfe74, + 0xfe8c, 0xfe9c, 0xfeac, 0xfebc, 0xfecc, 0xfedc, 0xfeec, 0xfefc, + 0xff0c, 0xff1c, 0xff2c, 0xff3c, 0xff4c, 0xff5c, 0xff6c, 0xff7c, + 0xff88, 0xff90, 0xff98, 0xffa0, 0xffa8, 0xffb0, 0xffb8, 0xffc0, + 0xffc8, 0xffd0, 0xffd8, 0xffe0, 0xffe8, 0xfff0, 0xfff8, 0x0000, + 0x7d7c, 0x797c, 0x757c, 0x717c, 0x6d7c, 0x697c, 0x657c, 0x617c, + 0x5d7c, 0x597c, 0x557c, 0x517c, 0x4d7c, 0x497c, 0x457c, 0x417c, + 0x3e7c, 0x3c7c, 0x3a7c, 0x387c, 0x367c, 0x347c, 0x327c, 0x307c, + 0x2e7c, 0x2c7c, 0x2a7c, 0x287c, 0x267c, 0x247c, 0x227c, 0x207c, + 0x1efc, 0x1dfc, 0x1cfc, 0x1bfc, 0x1afc, 0x19fc, 0x18fc, 0x17fc, + 0x16fc, 0x15fc, 0x14fc, 0x13fc, 0x12fc, 0x11fc, 0x10fc, 0x0ffc, + 0x0f3c, 0x0ebc, 0x0e3c, 0x0dbc, 0x0d3c, 0x0cbc, 0x0c3c, 0x0bbc, + 0x0b3c, 0x0abc, 0x0a3c, 0x09bc, 0x093c, 0x08bc, 0x083c, 0x07bc, + 0x075c, 0x071c, 0x06dc, 0x069c, 0x065c, 0x061c, 0x05dc, 0x059c, + 0x055c, 0x051c, 0x04dc, 0x049c, 0x045c, 0x041c, 0x03dc, 0x039c, + 0x036c, 0x034c, 0x032c, 0x030c, 0x02ec, 0x02cc, 0x02ac, 0x028c, + 0x026c, 0x024c, 0x022c, 0x020c, 0x01ec, 0x01cc, 0x01ac, 0x018c, + 0x0174, 0x0164, 0x0154, 0x0144, 0x0134, 0x0124, 0x0114, 0x0104, + 0x00f4, 0x00e4, 0x00d4, 0x00c4, 0x00b4, 0x00a4, 0x0094, 0x0084, + 0x0078, 0x0070, 0x0068, 0x0060, 0x0058, 0x0050, 0x0048, 0x0040, + 0x0038, 0x0030, 0x0028, 0x0020, 0x0018, 0x0010, 0x0008, 0x0000 +}; + +/* alaw -> signed 16-bit */ +static gint16 isdn_audio_alaw_to_s16[] = +{ + 0x13fc, 0xec04, 0x0144, 0xfebc, 0x517c, 0xae84, 0x051c, 0xfae4, + 0x0a3c, 0xf5c4, 0x0048, 0xffb8, 0x287c, 0xd784, 0x028c, 0xfd74, + 0x1bfc, 0xe404, 0x01cc, 0xfe34, 0x717c, 0x8e84, 0x071c, 0xf8e4, + 0x0e3c, 0xf1c4, 0x00c4, 0xff3c, 0x387c, 0xc784, 0x039c, 0xfc64, + 0x0ffc, 0xf004, 0x0104, 0xfefc, 0x417c, 0xbe84, 0x041c, 0xfbe4, + 0x083c, 0xf7c4, 0x0008, 0xfff8, 0x207c, 0xdf84, 0x020c, 0xfdf4, + 0x17fc, 0xe804, 0x018c, 0xfe74, 0x617c, 0x9e84, 0x061c, 0xf9e4, + 0x0c3c, 0xf3c4, 0x0084, 0xff7c, 0x307c, 0xcf84, 0x030c, 0xfcf4, + 0x15fc, 0xea04, 0x0164, 0xfe9c, 0x597c, 0xa684, 0x059c, 0xfa64, + 0x0b3c, 0xf4c4, 0x0068, 0xff98, 0x2c7c, 0xd384, 0x02cc, 0xfd34, + 0x1dfc, 0xe204, 0x01ec, 0xfe14, 0x797c, 0x8684, 0x07bc, 0xf844, + 0x0f3c, 0xf0c4, 0x00e4, 0xff1c, 0x3c7c, 0xc384, 0x03dc, 0xfc24, + 0x11fc, 0xee04, 0x0124, 0xfedc, 0x497c, 0xb684, 0x049c, 0xfb64, + 0x093c, 0xf6c4, 0x0028, 0xffd8, 0x247c, 0xdb84, 0x024c, 0xfdb4, + 0x19fc, 0xe604, 0x01ac, 0xfe54, 0x697c, 0x9684, 0x069c, 0xf964, + 0x0d3c, 0xf2c4, 0x00a4, 0xff5c, 0x347c, 0xcb84, 0x034c, 0xfcb4, + 0x12fc, 0xed04, 0x0134, 0xfecc, 0x4d7c, 0xb284, 0x04dc, 0xfb24, + 0x09bc, 0xf644, 0x0038, 0xffc8, 0x267c, 0xd984, 0x026c, 0xfd94, + 0x1afc, 0xe504, 0x01ac, 0xfe54, 0x6d7c, 0x9284, 0x06dc, 0xf924, + 0x0dbc, 0xf244, 0x00b4, 0xff4c, 0x367c, 0xc984, 0x036c, 0xfc94, + 0x0f3c, 0xf0c4, 0x00f4, 0xff0c, 0x3e7c, 0xc184, 0x03dc, 0xfc24, + 0x07bc, 0xf844, 0x0008, 0xfff8, 0x1efc, 0xe104, 0x01ec, 0xfe14, + 0x16fc, 0xe904, 0x0174, 0xfe8c, 0x5d7c, 0xa284, 0x05dc, 0xfa24, + 0x0bbc, 0xf444, 0x0078, 0xff88, 0x2e7c, 0xd184, 0x02ec, 0xfd14, + 0x14fc, 0xeb04, 0x0154, 0xfeac, 0x557c, 0xaa84, 0x055c, 0xfaa4, + 0x0abc, 0xf544, 0x0058, 0xffa8, 0x2a7c, 0xd584, 0x02ac, 0xfd54, + 0x1cfc, 0xe304, 0x01cc, 0xfe34, 0x757c, 0x8a84, 0x075c, 0xf8a4, + 0x0ebc, 0xf144, 0x00d4, 0xff2c, 0x3a7c, 0xc584, 0x039c, 0xfc64, + 0x10fc, 0xef04, 0x0114, 0xfeec, 0x457c, 0xba84, 0x045c, 0xfba4, + 0x08bc, 0xf744, 0x0018, 0xffe8, 0x227c, 0xdd84, 0x022c, 0xfdd4, + 0x18fc, 0xe704, 0x018c, 0xfe74, 0x657c, 0x9a84, 0x065c, 0xf9a4, + 0x0cbc, 0xf344, 0x0094, 0xff6c, 0x327c, 0xcd84, 0x032c, 0xfcd4 +}; + +/* alaw -> ulaw */ +static guint8 isdn_audio_alaw_to_ulaw[] = +{ + 0xab, 0x2b, 0xe3, 0x63, 0x8b, 0x0b, 0xc9, 0x49, + 0xba, 0x3a, 0xf6, 0x76, 0x9b, 0x1b, 0xd7, 0x57, + 0xa3, 0x23, 0xdd, 0x5d, 0x83, 0x03, 0xc1, 0x41, + 0xb2, 0x32, 0xeb, 0x6b, 0x93, 0x13, 0xcf, 0x4f, + 0xaf, 0x2f, 0xe7, 0x67, 0x8f, 0x0f, 0xcd, 0x4d, + 0xbe, 0x3e, 0xfe, 0x7e, 0x9f, 0x1f, 0xdb, 0x5b, + 0xa7, 0x27, 0xdf, 0x5f, 0x87, 0x07, 0xc5, 0x45, + 0xb6, 0x36, 0xef, 0x6f, 0x97, 0x17, 0xd3, 0x53, + 0xa9, 0x29, 0xe1, 0x61, 0x89, 0x09, 0xc7, 0x47, + 0xb8, 0x38, 0xf2, 0x72, 0x99, 0x19, 0xd5, 0x55, + 0xa1, 0x21, 0xdc, 0x5c, 0x81, 0x01, 0xbf, 0x3f, + 0xb0, 0x30, 0xe9, 0x69, 0x91, 0x11, 0xce, 0x4e, + 0xad, 0x2d, 0xe5, 0x65, 0x8d, 0x0d, 0xcb, 0x4b, + 0xbc, 0x3c, 0xfa, 0x7a, 0x9d, 0x1d, 0xd9, 0x59, + 0xa5, 0x25, 0xde, 0x5e, 0x85, 0x05, 0xc3, 0x43, + 0xb4, 0x34, 0xed, 0x6d, 0x95, 0x15, 0xd1, 0x51, + 0xac, 0x2c, 0xe4, 0x64, 0x8c, 0x0c, 0xca, 0x4a, + 0xbb, 0x3b, 0xf8, 0x78, 0x9c, 0x1c, 0xd8, 0x58, + 0xa4, 0x24, 0xde, 0x5e, 0x84, 0x04, 0xc2, 0x42, + 0xb3, 0x33, 0xec, 0x6c, 0x94, 0x14, 0xd0, 0x50, + 0xb0, 0x30, 0xe8, 0x68, 0x90, 0x10, 0xce, 0x4e, + 0xbf, 0x3f, 0xfe, 0x7e, 0xa0, 0x20, 0xdc, 0x5c, + 0xa8, 0x28, 0xe0, 0x60, 0x88, 0x08, 0xc6, 0x46, + 0xb7, 0x37, 0xf0, 0x70, 0x98, 0x18, 0xd4, 0x54, + 0xaa, 0x2a, 0xe2, 0x62, 0x8a, 0x0a, 0xc8, 0x48, + 0xb9, 0x39, 0xf4, 0x74, 0x9a, 0x1a, 0xd6, 0x56, + 0xa2, 0x22, 0xdd, 0x5d, 0x82, 0x02, 0xc0, 0x40, + 0xb1, 0x31, 0xea, 0x6a, 0x92, 0x12, 0xcf, 0x4f, + 0xae, 0x2e, 0xe6, 0x66, 0x8e, 0x0e, 0xcc, 0x4c, + 0xbd, 0x3d, 0xfc, 0x7c, 0x9e, 0x1e, 0xda, 0x5a, + 0xa6, 0x26, 0xdf, 0x5f, 0x86, 0x06, 0xc4, 0x44, + 0xb5, 0x35, 0xee, 0x6e, 0x96, 0x16, 0xd2, 0x52 +}; + +/* ulaw -> alaw */ +static guint8 isdn_audio_ulaw_to_alaw[] = +{ + 0xab, 0x55, 0xd5, 0x15, 0x95, 0x75, 0xf5, 0x35, + 0xb5, 0x45, 0xc5, 0x05, 0x85, 0x65, 0xe5, 0x25, + 0xa5, 0x5d, 0xdd, 0x1d, 0x9d, 0x7d, 0xfd, 0x3d, + 0xbd, 0x4d, 0xcd, 0x0d, 0x8d, 0x6d, 0xed, 0x2d, + 0xad, 0x51, 0xd1, 0x11, 0x91, 0x71, 0xf1, 0x31, + 0xb1, 0x41, 0xc1, 0x01, 0x81, 0x61, 0xe1, 0x21, + 0x59, 0xd9, 0x19, 0x99, 0x79, 0xf9, 0x39, 0xb9, + 0x49, 0xc9, 0x09, 0x89, 0x69, 0xe9, 0x29, 0xa9, + 0xd7, 0x17, 0x97, 0x77, 0xf7, 0x37, 0xb7, 0x47, + 0xc7, 0x07, 0x87, 0x67, 0xe7, 0x27, 0xa7, 0xdf, + 0x9f, 0x7f, 0xff, 0x3f, 0xbf, 0x4f, 0xcf, 0x0f, + 0x8f, 0x6f, 0xef, 0x2f, 0x53, 0x13, 0x73, 0x33, + 0xb3, 0x43, 0xc3, 0x03, 0x83, 0x63, 0xe3, 0x23, + 0xa3, 0x5b, 0xdb, 0x1b, 0x9b, 0x7b, 0xfb, 0x3b, + 0xbb, 0xbb, 0x4b, 0x4b, 0xcb, 0xcb, 0x0b, 0x0b, + 0x8b, 0x8b, 0x6b, 0x6b, 0xeb, 0xeb, 0x2b, 0x2b, + 0xab, 0x54, 0xd4, 0x14, 0x94, 0x74, 0xf4, 0x34, + 0xb4, 0x44, 0xc4, 0x04, 0x84, 0x64, 0xe4, 0x24, + 0xa4, 0x5c, 0xdc, 0x1c, 0x9c, 0x7c, 0xfc, 0x3c, + 0xbc, 0x4c, 0xcc, 0x0c, 0x8c, 0x6c, 0xec, 0x2c, + 0xac, 0x50, 0xd0, 0x10, 0x90, 0x70, 0xf0, 0x30, + 0xb0, 0x40, 0xc0, 0x00, 0x80, 0x60, 0xe0, 0x20, + 0x58, 0xd8, 0x18, 0x98, 0x78, 0xf8, 0x38, 0xb8, + 0x48, 0xc8, 0x08, 0x88, 0x68, 0xe8, 0x28, 0xa8, + 0xd6, 0x16, 0x96, 0x76, 0xf6, 0x36, 0xb6, 0x46, + 0xc6, 0x06, 0x86, 0x66, 0xe6, 0x26, 0xa6, 0xde, + 0x9e, 0x7e, 0xfe, 0x3e, 0xbe, 0x4e, 0xce, 0x0e, + 0x8e, 0x6e, 0xee, 0x2e, 0x52, 0x12, 0x72, 0x32, + 0xb2, 0x42, 0xc2, 0x02, 0x82, 0x62, 0xe2, 0x22, + 0xa2, 0x5a, 0xda, 0x1a, 0x9a, 0x7a, 0xfa, 0x3a, + 0xba, 0xba, 0x4a, 0x4a, 0xca, 0xca, 0x0a, 0x0a, + 0x8a, 0x8a, 0x6a, 0x6a, 0xea, 0xea, 0x2a, 0x2a +}; + +static inline void +isdn_audio_tlookup(const guint8 *table, guint8 *buff, gulong n) +{ + while (n--) + *buff++ = table[*(unsigned char *)buff]; +} + +void +isdn_audio_ulaw2alaw(guint8 *buff, gulong len) +{ + isdn_audio_tlookup(isdn_audio_ulaw_to_alaw, buff, len); +} + +void +isdn_audio_alaw2ulaw(guint8 *buff, gulong len) +{ + isdn_audio_tlookup(isdn_audio_alaw_to_ulaw, buff, len); +} diff --git a/gst/law/alaw-conversion.h b/gst/law/alaw-conversion.h new file mode 100644 index 00000000..b7d1297b --- /dev/null +++ b/gst/law/alaw-conversion.h @@ -0,0 +1,12 @@ +#ifndef _GST_ALAW_CONVERSION_H +#define _GST_ALAW_CONVERSION_H + +#include <glib.h> + +void +isdn_audio_ulaw2alaw(guint8 *buff, gulong len); + +void +isdn_audio_alaw2ulaw(guint8 *buff, gulong len); + +#endif diff --git a/gst/law/alaw-decode.c b/gst/law/alaw-decode.c new file mode 100644 index 00000000..872d5335 --- /dev/null +++ b/gst/law/alaw-decode.c @@ -0,0 +1,186 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gst/gst.h> +#include "alaw-decode.h" +#include "mulaw-conversion.h" +#include "alaw-conversion.h" + +extern GstPadTemplate *alawdec_src_template, *alawdec_sink_template; + + +/* Stereo signals and args */ +enum { + /* FILL ME */ + LAST_SIGNAL +}; + +enum { + ARG_0 +}; + +static void gst_alawdec_class_init (GstALawDecClass *klass); +static void gst_alawdec_init (GstALawDec *alawdec); + +static void gst_alawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void gst_alawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); + +static void gst_alawdec_chain (GstPad *pad, GstBuffer *buf); + + +static GstElementClass *parent_class = NULL; +//static guint gst_stereo_signals[LAST_SIGNAL] = { 0 }; + +static GstPadNegotiateReturn +alawdec_negotiate_sink (GstPad *pad, GstCaps **caps, gint counter) +{ + GstCaps* tempcaps; + + GstALawDec* alawdec=GST_ALAWDEC (GST_OBJECT_PARENT (pad)); + + if (*caps==NULL) + return GST_PAD_NEGOTIATE_FAIL; + + tempcaps = gst_caps_copy(*caps); + + gst_caps_set(tempcaps,"format",GST_PROPS_STRING("int")); + gst_caps_set(tempcaps,"law",GST_PROPS_INT(0)); + gst_caps_set(tempcaps,"depth",GST_PROPS_INT(16)); + gst_caps_set(tempcaps,"width",GST_PROPS_INT(16)); + gst_caps_set(tempcaps,"signed",GST_PROPS_BOOLEAN(TRUE)); + + if (gst_pad_set_caps (alawdec->srcpad, tempcaps)) + { + return GST_PAD_NEGOTIATE_AGREE; + } + else { + gst_caps_unref (tempcaps); + return GST_PAD_NEGOTIATE_FAIL; + } +} + +GType +gst_alawdec_get_type(void) { + static GType alawdec_type = 0; + + if (!alawdec_type) { + static const GTypeInfo alawdec_info = { + sizeof(GstALawDecClass), NULL, + NULL, + (GClassInitFunc)gst_alawdec_class_init, + NULL, + NULL, + sizeof(GstALawDec), + 0, + (GInstanceInitFunc)gst_alawdec_init, + }; + alawdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstALawDec", &alawdec_info, 0); + } + return alawdec_type; +} + +static void +gst_alawdec_class_init (GstALawDecClass *klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + + gobject_class = (GObjectClass*)klass; + gstelement_class = (GstElementClass*)klass; + + parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + + gobject_class->set_property = gst_alawdec_set_property; + gobject_class->get_property = gst_alawdec_get_property; +} + +static void +gst_alawdec_init (GstALawDec *alawdec) +{ + alawdec->sinkpad = gst_pad_new_from_template(alawdec_sink_template,"sink"); + alawdec->srcpad = gst_pad_new_from_template(alawdec_src_template,"src"); + gst_pad_set_negotiate_function(alawdec->sinkpad, alawdec_negotiate_sink); + + gst_element_add_pad(GST_ELEMENT(alawdec),alawdec->sinkpad); + gst_pad_set_chain_function(alawdec->sinkpad,gst_alawdec_chain); + gst_element_add_pad(GST_ELEMENT(alawdec),alawdec->srcpad); +} + +static void +gst_alawdec_chain (GstPad *pad,GstBuffer *buf) +{ + GstALawDec *alawdec; + gint16 *linear_data; + guint8 *alaw_data; + GstBuffer* outbuf; + + g_return_if_fail(pad != NULL); + g_return_if_fail(GST_IS_PAD(pad)); + g_return_if_fail(buf != NULL); + + alawdec = GST_ALAWDEC(GST_OBJECT_PARENT (pad)); + g_return_if_fail(alawdec != NULL); + g_return_if_fail(GST_IS_ALAWDEC(alawdec)); + + alaw_data = (guint8 *)GST_BUFFER_DATA(buf); + outbuf=gst_buffer_new(); + GST_BUFFER_DATA(outbuf) = (gchar*)g_new(gint16,GST_BUFFER_SIZE(buf)); + GST_BUFFER_SIZE(outbuf) = GST_BUFFER_SIZE(buf)*2; + + linear_data = (gint16*)GST_BUFFER_DATA(outbuf); + + isdn_audio_alaw2ulaw(alaw_data,GST_BUFFER_SIZE(buf)); + mulaw_decode(alaw_data,linear_data,GST_BUFFER_SIZE(buf)); + + gst_buffer_unref(buf); + gst_pad_push(alawdec->srcpad,outbuf); +} + +static void +gst_alawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + GstALawDec *alawdec; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_ALAWDEC(object)); + alawdec = GST_ALAWDEC(object); + + switch (prop_id) { + default: + break; + } +} + +static void +gst_alawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + GstALawDec *alawdec; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_ALAWDEC(object)); + alawdec = GST_ALAWDEC(object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + diff --git a/gst/law/alaw-decode.h b/gst/law/alaw-decode.h new file mode 100644 index 00000000..f487009f --- /dev/null +++ b/gst/law/alaw-decode.h @@ -0,0 +1,69 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_ALAWDECODE_H__ +#define __GST_ALAWDECODE_H__ + + +#include <config.h> +#include <gst/gst.h> +// #include <gst/meta/audioraw.h> + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define GST_TYPE_ALAWDEC \ + (gst_alawdec_get_type()) +#define GST_ALAWDEC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ALAWDEC,GstALawDec)) +#define GST_ALAWDEC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ALAWDEC,GstALawDec)) +#define GST_IS_ALAWDEC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ALAWDEC)) +#define GST_IS_ALAWDEC_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ALAWDEC)) + +typedef struct _GstALawDec GstALawDec; +typedef struct _GstALawDecClass GstALawDecClass; + +struct _GstALawDec { + GstElement element; + + GstPad *sinkpad,*srcpad; + + //MetaAudioRaw meta; + +}; + +struct _GstALawDecClass { + GstElementClass parent_class; +}; + +GType gst_alawdec_get_type(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __GST_STEREO_H__ */ diff --git a/gst/law/alaw-encode.c b/gst/law/alaw-encode.c new file mode 100644 index 00000000..ab54bd16 --- /dev/null +++ b/gst/law/alaw-encode.c @@ -0,0 +1,182 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gst/gst.h> +#include "alaw-encode.h" +#include "mulaw-conversion.h" +#include "alaw-conversion.h" + +extern GstPadTemplate *alawenc_src_template, *alawenc_sink_template; + + +/* Stereo signals and args */ +enum { + /* FILL ME */ + LAST_SIGNAL +}; + +enum { + ARG_0 +}; + +static void gst_alawenc_class_init (GstALawEncClass *klass); +static void gst_alawenc_init (GstALawEnc *alawenc); + +static void gst_alawenc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void gst_alawenc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); + +static void gst_alawenc_chain (GstPad *pad, GstBuffer *buf); + + +static GstElementClass *parent_class = NULL; +//static guint gst_stereo_signals[LAST_SIGNAL] = { 0 }; + +static GstPadNegotiateReturn +alawenc_negotiate_sink (GstPad *pad, GstCaps **caps, gint counter) +{ + GstCaps* tempcaps; + + GstALawEnc* alawenc=GST_ALAWENC (GST_OBJECT_PARENT (pad)); + + if (*caps==NULL) + return GST_PAD_NEGOTIATE_FAIL; + + tempcaps = gst_caps_copy(*caps); + + gst_caps_set(tempcaps,"format",GST_PROPS_STRING("int")); + gst_caps_set(tempcaps,"law",GST_PROPS_INT(2)); + gst_caps_set(tempcaps,"depth",GST_PROPS_INT(8)); + gst_caps_set(tempcaps,"width",GST_PROPS_INT(8)); + gst_caps_set(tempcaps,"signed",GST_PROPS_BOOLEAN(FALSE)); + + if (gst_pad_set_caps (alawenc->srcpad, tempcaps)) + { + return GST_PAD_NEGOTIATE_AGREE; + } + else { + gst_caps_unref (tempcaps); + return GST_PAD_NEGOTIATE_FAIL; + } +} + +GType +gst_alawenc_get_type(void) { + static GType alawenc_type = 0; + + if (!alawenc_type) { + static const GTypeInfo alawenc_info = { + sizeof(GstALawEncClass), NULL, + NULL, + (GClassInitFunc)gst_alawenc_class_init, + NULL, + NULL, + sizeof(GstALawEnc), + 0, + (GInstanceInitFunc)gst_alawenc_init, + }; + alawenc_type = g_type_register_static(GST_TYPE_ELEMENT, "GstALawEnc", &alawenc_info, 0); + } + return alawenc_type; +} + +static void +gst_alawenc_class_init (GstALawEncClass *klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + + gobject_class = (GObjectClass*)klass; + gstelement_class = (GstElementClass*)klass; + + parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + + gobject_class->set_property = gst_alawenc_set_property; + gobject_class->get_property = gst_alawenc_get_property; +} + +static void +gst_alawenc_init (GstALawEnc *alawenc) +{ + alawenc->sinkpad = gst_pad_new_from_template(alawenc_sink_template,"sink"); + alawenc->srcpad = gst_pad_new_from_template(alawenc_src_template,"src"); + gst_pad_set_negotiate_function(alawenc->sinkpad, alawenc_negotiate_sink); + + gst_element_add_pad(GST_ELEMENT(alawenc),alawenc->sinkpad); + gst_pad_set_chain_function(alawenc->sinkpad,gst_alawenc_chain); + gst_element_add_pad(GST_ELEMENT(alawenc),alawenc->srcpad); +} + +static void +gst_alawenc_chain (GstPad *pad,GstBuffer *buf) +{ + GstALawEnc *alawenc; + gint16 *linear_data; + guint8 *alaw_data; + GstBuffer* outbuf; + + g_return_if_fail(pad != NULL); + g_return_if_fail(GST_IS_PAD(pad)); + g_return_if_fail(buf != NULL); + + alawenc = GST_ALAWENC(GST_OBJECT_PARENT (pad)); + g_return_if_fail(alawenc != NULL); + g_return_if_fail(GST_IS_ALAWENC(alawenc)); + + linear_data = (gint16 *)GST_BUFFER_DATA(buf); + outbuf=gst_buffer_new(); + GST_BUFFER_DATA(outbuf) = (gchar*)g_new(gint16,GST_BUFFER_SIZE(buf)/4); + GST_BUFFER_SIZE(outbuf) = GST_BUFFER_SIZE(buf)/2; + + alaw_data = (guint8*)GST_BUFFER_DATA(outbuf); + mulaw_encode(linear_data,alaw_data,GST_BUFFER_SIZE(outbuf)); + isdn_audio_ulaw2alaw(alaw_data,GST_BUFFER_SIZE(outbuf)); + gst_buffer_unref(buf); + gst_pad_push(alawenc->srcpad,outbuf); +} + +static void +gst_alawenc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + GstALawEnc *alawenc; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_ALAWENC(object)); + alawenc = GST_ALAWENC(object); + + switch (prop_id) { + default: + break; + } +} + +static void +gst_alawenc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + GstALawEnc *alawenc; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_ALAWENC(object)); + alawenc = GST_ALAWENC(object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} diff --git a/gst/law/alaw-encode.h b/gst/law/alaw-encode.h new file mode 100644 index 00000000..023d0633 --- /dev/null +++ b/gst/law/alaw-encode.h @@ -0,0 +1,69 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_ALAWENCODE_H__ +#define __GST_ALAWENCODE_H__ + + +#include <config.h> +#include <gst/gst.h> +// #include <gst/meta/audioraw.h> + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define GST_TYPE_ALAWENC \ + (gst_alawenc_get_type()) +#define GST_ALAWENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ALAWENC,GstALawEnc)) +#define GST_ALAWENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ALAWENC,GstALawEnc)) +#define GST_IS_ALAWENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ALAWENC)) +#define GST_IS_ALAWENC_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ALAWENC)) + +typedef struct _GstALawEnc GstALawEnc; +typedef struct _GstALawEncClass GstALawEncClass; + +struct _GstALawEnc { + GstElement element; + + GstPad *sinkpad,*srcpad; + + //MetaAudioRaw meta; + +}; + +struct _GstALawEncClass { + GstElementClass parent_class; +}; + +GType gst_alawenc_get_type(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __GST_STEREO_H__ */ diff --git a/gst/law/alaw.c b/gst/law/alaw.c new file mode 100644 index 00000000..1b9afb5c --- /dev/null +++ b/gst/law/alaw.c @@ -0,0 +1,95 @@ +#include "alaw-encode.h" +#include "alaw-decode.h" + +static GstElementDetails alawenc_details = { + "PCM to A Law conversion", + "Filter/Effect", + "Convert 16bit PCM to 8bit A law", + VERSION, + "Zaheer Merali <zaheer@bellworldwide.net>", + "(C) 2001" +}; + +static GstElementDetails alawdec_details = { + "A Law to PCM conversion", + "Filter/Effect", + "Convert 8bit A law to 16bit PCM", + VERSION, + "Zaheer Merali <zaheer@bellworldwide.net>", + "(C) 2001" +}; + +static GstCaps* +alaw_factory (void) +{ + return + gst_caps_new ( + "test_src", + "audio/raw", + gst_props_new ( + "format", GST_PROPS_STRING ("int"), + "law", GST_PROPS_INT (2), + "width", GST_PROPS_INT(8), + "depth", GST_PROPS_INT(8), + "signed", GST_PROPS_BOOLEAN(FALSE), + NULL)); +} + +static GstCaps* +linear_factory (void) +{ + return + gst_caps_new ( + "test_sink", + "audio/raw", + gst_props_new ( + "format", GST_PROPS_STRING ("int"), + "law", GST_PROPS_INT(0), + "width", GST_PROPS_INT(16), + "depth", GST_PROPS_INT(16), + "signed", GST_PROPS_BOOLEAN(TRUE), + NULL)); +} + +GstPadTemplate *alawenc_src_template, *alawenc_sink_template; +GstPadTemplate *alawdec_src_template, *alawdec_sink_template; + +static gboolean +plugin_init (GModule *module, GstPlugin *plugin) +{ + GstElementFactory *alawenc_factory, *alawdec_factory; + GstCaps* alaw_caps, *linear_caps; + + alawenc_factory = gst_elementfactory_new("alawencode",GST_TYPE_ALAWENC, + &alawenc_details); + g_return_val_if_fail(alawenc_factory != NULL, FALSE); + alawdec_factory = gst_elementfactory_new("alawdecode",GST_TYPE_ALAWDEC, + &alawdec_details); + g_return_val_if_fail(alawdec_factory != NULL, FALSE); + + alaw_caps = alaw_factory (); + linear_caps = linear_factory (); + + alawenc_src_template = gst_padtemplate_new ("src",GST_PAD_SRC,GST_PAD_ALWAYS,alaw_caps, NULL); + alawenc_sink_template = gst_padtemplate_new ("sink",GST_PAD_SINK,GST_PAD_ALWAYS,linear_caps, NULL); + gst_elementfactory_add_padtemplate (alawenc_factory, alawenc_src_template); + gst_elementfactory_add_padtemplate (alawenc_factory, alawenc_sink_template); + + alawdec_src_template = gst_padtemplate_new ("src",GST_PAD_SRC,GST_PAD_ALWAYS,linear_caps, NULL); + alawdec_sink_template = gst_padtemplate_new ("sink",GST_PAD_SINK,GST_PAD_ALWAYS,alaw_caps, NULL); + + gst_elementfactory_add_padtemplate (alawdec_factory, alawdec_src_template); + gst_elementfactory_add_padtemplate (alawdec_factory, alawdec_sink_template); + gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (alawenc_factory)); + gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (alawdec_factory)); + + return TRUE; +} + +GstPluginDesc plugin_desc = { + GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "alaw", + plugin_init +}; + diff --git a/gst/law/mulaw-conversion.c b/gst/law/mulaw-conversion.c new file mode 100644 index 00000000..ad3fcce6 --- /dev/null +++ b/gst/law/mulaw-conversion.c @@ -0,0 +1,102 @@ +/* + * This routine converts from linear to ulaw + * 29 September 1989 + * + * Craig Reese: IDA/Supercomputing Research Center + * Joe Campbell: Department of Defense + * + * References: + * 1) CCITT Recommendation G.711 (very difficult to follow) + * 2) "A New Digital Technique for Implementation of Any + * Continuous PCM Companding Law," Villeret, Michel, + * et al. 1973 IEEE Int. Conf. on Communications, Vol 1, + * 1973, pg. 11.12-11.17 + * 3) MIL-STD-188-113,"Interoperability and Performance Standards + * for Analog-to_Digital Conversion Techniques," + * 17 February 1987 + * + * Input: Signed 16 bit linear sample + * Output: 8 bit ulaw sample + */ + +#include <glib.h> + +#define ZEROTRAP /* turn on the trap as per the MIL-STD */ +#define BIAS 0x84 /* define the add-in bias for 16 bit samples */ +#define CLIP 32635 + +void +mulaw_encode(gint16* in, guint8* out, gint numsamples) +{ + static gint16 exp_lut[256] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3, + 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7}; + gint16 sign, exponent, mantissa,i; + gint16 sample; + guint8 ulawbyte; + + for(i=0;i<numsamples;i++) { + sample=in[i]; + /** get the sample into sign-magnitude **/ + sign = (sample >> 8) & 0x80; /* set aside the sign */ + if (sign != 0) sample = -sample; /* get magnitude */ + if (sample > CLIP) sample = CLIP; /* clip the magnitude */ + /** convert from 16 bit linear to ulaw **/ + sample = sample + BIAS; + exponent = exp_lut[(sample>>7) & 0xFF]; + mantissa = (sample >> (exponent+3)) & 0x0F; + ulawbyte = ~(sign | (exponent << 4) | mantissa); +#ifdef ZEROTRAP + if (ulawbyte == 0 ) ulawbyte = 0x02; /* optional CCITT trap */ +#endif + out[i]=ulawbyte; + } +} + +/* + * This routine converts from ulaw to 16 bit linear + * 29 September 1989 + * + * Craig Reese: IDA/Supercomputing Research Center + * + * References: + * 1) CCITT Recommendation G.711 (very difficult to follow) + * 2) MIL-STD-188-113,"Interoperability and Performance Standards + * for Analog-to_Digital Conversion Techniques," + * 17 February 1987 + * + * Input: 8 bit ulaw sample + * Output: signed 16 bit linear sample + */ + +void +mulaw_decode(guint8* in,gint16* out,gint numsamples) +{ + static gint16 exp_lut[8]={0,132,396,924,1980,4092,8316,16764}; + gint16 sign, exponent, mantissa; + guint8 ulawbyte; + gint16 linear,i; + for(i=0;i<numsamples;i++) { + ulawbyte=in[i]; + ulawbyte = ~ulawbyte; + sign = (ulawbyte & 0x80); + exponent = (ulawbyte >> 4) & 0x07; + mantissa = ulawbyte & 0x0F; + linear = exp_lut[exponent] + (mantissa << (exponent+3)); + if (sign != 0) linear = -linear; + out[i]=linear; + } +} diff --git a/gst/law/mulaw-conversion.h b/gst/law/mulaw-conversion.h new file mode 100644 index 00000000..55180121 --- /dev/null +++ b/gst/law/mulaw-conversion.h @@ -0,0 +1,10 @@ +#ifndef _GST_ULAWDECODE_H +#define _GST_ULAWDECODE_H + +#include <glib.h> + +void +mulaw_encode(gint16* in, guint8* out, gint numsamples); +void +mulaw_decode(guint8* in,gint16* out,gint numsamples); +#endif diff --git a/gst/law/mulaw-decode.c b/gst/law/mulaw-decode.c new file mode 100644 index 00000000..d93c6904 --- /dev/null +++ b/gst/law/mulaw-decode.c @@ -0,0 +1,181 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gst/gst.h> +#include "mulaw-decode.h" +#include "mulaw-conversion.h" + +extern GstPadTemplate *mulawdec_src_template, *mulawdec_sink_template; + + +/* Stereo signals and args */ +enum { + /* FILL ME */ + LAST_SIGNAL +}; + +enum { + ARG_0 +}; + +static void gst_mulawdec_class_init (GstMuLawDecClass *klass); +static void gst_mulawdec_init (GstMuLawDec *mulawdec); + +static void gst_mulawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void gst_mulawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); + +static void gst_mulawdec_chain (GstPad *pad, GstBuffer *buf); + + +static GstElementClass *parent_class = NULL; +//static guint gst_stereo_signals[LAST_SIGNAL] = { 0 }; + +static GstPadNegotiateReturn +mulawdec_negotiate_sink (GstPad *pad, GstCaps **caps, gint counter) +{ + GstCaps* tempcaps; + + GstMuLawDec* mulawdec=GST_MULAWDEC (GST_OBJECT_PARENT (pad)); + + if (*caps==NULL) + return GST_PAD_NEGOTIATE_FAIL; + + tempcaps = gst_caps_copy(*caps); + + gst_caps_set(tempcaps,"format",GST_PROPS_STRING("int")); + gst_caps_set(tempcaps,"law",GST_PROPS_INT(0)); + gst_caps_set(tempcaps,"depth",GST_PROPS_INT(16)); + gst_caps_set(tempcaps,"width",GST_PROPS_INT(16)); + gst_caps_set(tempcaps,"signed",GST_PROPS_BOOLEAN(TRUE)); + + if (gst_pad_set_caps (mulawdec->srcpad, tempcaps)) + { + return GST_PAD_NEGOTIATE_AGREE; + } + else { + gst_caps_unref (tempcaps); + return GST_PAD_NEGOTIATE_FAIL; + } +} + +GType +gst_mulawdec_get_type(void) { + static GType mulawdec_type = 0; + + if (!mulawdec_type) { + static const GTypeInfo mulawdec_info = { + sizeof(GstMuLawDecClass), NULL, + NULL, + (GClassInitFunc)gst_mulawdec_class_init, + NULL, + NULL, + sizeof(GstMuLawDec), + 0, + (GInstanceInitFunc)gst_mulawdec_init, + }; + mulawdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMuLawDec", &mulawdec_info, 0); + } + return mulawdec_type; +} + +static void +gst_mulawdec_class_init (GstMuLawDecClass *klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + + gobject_class = (GObjectClass*)klass; + gstelement_class = (GstElementClass*)klass; + + parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + + gobject_class->set_property = gst_mulawdec_set_property; + gobject_class->get_property = gst_mulawdec_get_property; +} + +static void +gst_mulawdec_init (GstMuLawDec *mulawdec) +{ + mulawdec->sinkpad = gst_pad_new_from_template(mulawdec_sink_template,"sink"); + mulawdec->srcpad = gst_pad_new_from_template(mulawdec_src_template,"src"); + gst_pad_set_negotiate_function(mulawdec->sinkpad, mulawdec_negotiate_sink); + + gst_element_add_pad(GST_ELEMENT(mulawdec),mulawdec->sinkpad); + gst_pad_set_chain_function(mulawdec->sinkpad,gst_mulawdec_chain); + gst_element_add_pad(GST_ELEMENT(mulawdec),mulawdec->srcpad); +} + +static void +gst_mulawdec_chain (GstPad *pad,GstBuffer *buf) +{ + GstMuLawDec *mulawdec; + gint16 *linear_data; + guint8 *mulaw_data; + GstBuffer* outbuf; + + g_return_if_fail(pad != NULL); + g_return_if_fail(GST_IS_PAD(pad)); + g_return_if_fail(buf != NULL); + + mulawdec = GST_MULAWDEC(GST_OBJECT_PARENT (pad)); + g_return_if_fail(mulawdec != NULL); + g_return_if_fail(GST_IS_MULAWDEC(mulawdec)); + + mulaw_data = (guint8 *)GST_BUFFER_DATA(buf); + outbuf=gst_buffer_new(); + GST_BUFFER_DATA(outbuf) = (gchar*)g_new(gint16,GST_BUFFER_SIZE(buf)); + GST_BUFFER_SIZE(outbuf) = GST_BUFFER_SIZE(buf)*2; + + linear_data = (gint16*)GST_BUFFER_DATA(outbuf); + mulaw_decode(mulaw_data,linear_data,GST_BUFFER_SIZE(buf)); + + gst_buffer_unref(buf); + gst_pad_push(mulawdec->srcpad,outbuf); +} + +static void +gst_mulawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + GstMuLawDec *mulawdec; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_MULAWDEC(object)); + mulawdec = GST_MULAWDEC(object); + + switch (prop_id) { + default: + break; + } +} + +static void +gst_mulawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + GstMuLawDec *mulawdec; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_MULAWDEC(object)); + mulawdec = GST_MULAWDEC(object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} diff --git a/gst/law/mulaw-decode.h b/gst/law/mulaw-decode.h new file mode 100644 index 00000000..431b1bdc --- /dev/null +++ b/gst/law/mulaw-decode.h @@ -0,0 +1,69 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_MULAWDECODE_H__ +#define __GST_MULAWDECODE_H__ + + +#include <config.h> +#include <gst/gst.h> +// #include <gst/meta/audioraw.h> + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define GST_TYPE_MULAWDEC \ + (gst_mulawdec_get_type()) +#define GST_MULAWDEC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MULAWDEC,GstMuLawDec)) +#define GST_MULAWDEC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MULAWDEC,GstMuLawDec)) +#define GST_IS_MULAWDEC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MULAWDEC)) +#define GST_IS_MULAWDEC_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MULAWDEC)) + +typedef struct _GstMuLawDec GstMuLawDec; +typedef struct _GstMuLawDecClass GstMuLawDecClass; + +struct _GstMuLawDec { + GstElement element; + + GstPad *sinkpad,*srcpad; + + //MetaAudioRaw meta; + +}; + +struct _GstMuLawDecClass { + GstElementClass parent_class; +}; + +GType gst_mulawdec_get_type(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __GST_STEREO_H__ */ diff --git a/gst/law/mulaw-encode.c b/gst/law/mulaw-encode.c new file mode 100644 index 00000000..40d868d9 --- /dev/null +++ b/gst/law/mulaw-encode.c @@ -0,0 +1,181 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gst/gst.h> +#include "mulaw-encode.h" +#include "mulaw-conversion.h" + +extern GstPadTemplate *mulawenc_src_template, *mulawenc_sink_template; + + +/* Stereo signals and args */ +enum { + /* FILL ME */ + LAST_SIGNAL +}; + +enum { + ARG_0 +}; + +static void gst_mulawenc_class_init (GstMuLawEncClass *klass); +static void gst_mulawenc_init (GstMuLawEnc *mulawenc); + +static void gst_mulawenc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void gst_mulawenc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); + +static void gst_mulawenc_chain (GstPad *pad, GstBuffer *buf); + + +static GstElementClass *parent_class = NULL; +//static guint gst_stereo_signals[LAST_SIGNAL] = { 0 }; + +static GstPadNegotiateReturn +mulawenc_negotiate_sink (GstPad *pad, GstCaps **caps, gint counter) +{ + GstCaps* tempcaps; + + GstMuLawEnc* mulawenc=GST_MULAWENC (GST_OBJECT_PARENT (pad)); + + if (*caps==NULL) + return GST_PAD_NEGOTIATE_FAIL; + + tempcaps = gst_caps_copy(*caps); + + gst_caps_set(tempcaps,"format",GST_PROPS_STRING("int")); + gst_caps_set(tempcaps,"law",GST_PROPS_INT(1)); + gst_caps_set(tempcaps,"depth",GST_PROPS_INT(8)); + gst_caps_set(tempcaps,"width",GST_PROPS_INT(8)); + gst_caps_set(tempcaps,"signed",GST_PROPS_BOOLEAN(FALSE)); + + if (gst_pad_set_caps (mulawenc->srcpad, tempcaps)) + { + return GST_PAD_NEGOTIATE_AGREE; + } + else { + gst_caps_unref (tempcaps); + return GST_PAD_NEGOTIATE_FAIL; + } +} + +GType +gst_mulawenc_get_type(void) { + static GType mulawenc_type = 0; + + if (!mulawenc_type) { + static const GTypeInfo mulawenc_info = { + sizeof(GstMuLawEncClass), NULL, + NULL, + (GClassInitFunc)gst_mulawenc_class_init, + NULL, + NULL, + sizeof(GstMuLawEnc), + 0, + (GInstanceInitFunc)gst_mulawenc_init, + }; + mulawenc_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMuLawEnc", &mulawenc_info, 0); + } + return mulawenc_type; +} + +static void +gst_mulawenc_class_init (GstMuLawEncClass *klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + + gobject_class = (GObjectClass*)klass; + gstelement_class = (GstElementClass*)klass; + + parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + + gobject_class->set_property = gst_mulawenc_set_property; + gobject_class->get_property = gst_mulawenc_get_property; +} + +static void +gst_mulawenc_init (GstMuLawEnc *mulawenc) +{ + mulawenc->sinkpad = gst_pad_new_from_template(mulawenc_sink_template,"sink"); + mulawenc->srcpad = gst_pad_new_from_template(mulawenc_src_template,"src"); + gst_pad_set_negotiate_function(mulawenc->sinkpad, mulawenc_negotiate_sink); + + gst_element_add_pad(GST_ELEMENT(mulawenc),mulawenc->sinkpad); + gst_pad_set_chain_function(mulawenc->sinkpad,gst_mulawenc_chain); + gst_element_add_pad(GST_ELEMENT(mulawenc),mulawenc->srcpad); +} + +static void +gst_mulawenc_chain (GstPad *pad,GstBuffer *buf) +{ + GstMuLawEnc *mulawenc; + gint16 *linear_data; + guint8 *mulaw_data; + GstBuffer* outbuf; + + g_return_if_fail(pad != NULL); + g_return_if_fail(GST_IS_PAD(pad)); + g_return_if_fail(buf != NULL); + + mulawenc = GST_MULAWENC(GST_OBJECT_PARENT (pad)); + g_return_if_fail(mulawenc != NULL); + g_return_if_fail(GST_IS_MULAWENC(mulawenc)); + + linear_data = (gint16 *)GST_BUFFER_DATA(buf); + outbuf=gst_buffer_new(); + GST_BUFFER_DATA(outbuf) = (gchar*)g_new(gint16,GST_BUFFER_SIZE(buf)/4); + GST_BUFFER_SIZE(outbuf) = GST_BUFFER_SIZE(buf)/2; + + mulaw_data = (gint8*)GST_BUFFER_DATA(outbuf); + mulaw_encode(linear_data,mulaw_data,GST_BUFFER_SIZE(outbuf)); + + gst_buffer_unref(buf); + gst_pad_push(mulawenc->srcpad,outbuf); +} + +static void +gst_mulawenc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + GstMuLawEnc *mulawenc; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_MULAWENC(object)); + mulawenc = GST_MULAWENC(object); + + switch (prop_id) { + default: + break; + } +} + +static void +gst_mulawenc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + GstMuLawEnc *mulawenc; + + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail(GST_IS_MULAWENC(object)); + mulawenc = GST_MULAWENC(object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} diff --git a/gst/law/mulaw-encode.h b/gst/law/mulaw-encode.h new file mode 100644 index 00000000..009b470b --- /dev/null +++ b/gst/law/mulaw-encode.h @@ -0,0 +1,69 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_MULAWENCODE_H__ +#define __GST_MULAWENCODE_H__ + + +#include <config.h> +#include <gst/gst.h> +// #include <gst/meta/audioraw.h> + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define GST_TYPE_MULAWENC \ + (gst_mulawenc_get_type()) +#define GST_MULAWENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MULAWENC,GstMuLawEnc)) +#define GST_MULAWENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MULAWENC,GstMuLawEnc)) +#define GST_IS_MULAWENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MULAWENC)) +#define GST_IS_MULAWENC_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MULAWENC)) + +typedef struct _GstMuLawEnc GstMuLawEnc; +typedef struct _GstMuLawEncClass GstMuLawEncClass; + +struct _GstMuLawEnc { + GstElement element; + + GstPad *sinkpad,*srcpad; + + //MetaAudioRaw meta; + +}; + +struct _GstMuLawEncClass { + GstElementClass parent_class; +}; + +GType gst_mulawenc_get_type(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __GST_STEREO_H__ */ diff --git a/gst/law/mulaw.c b/gst/law/mulaw.c new file mode 100644 index 00000000..5b97eca3 --- /dev/null +++ b/gst/law/mulaw.c @@ -0,0 +1,103 @@ +#include "mulaw-encode.h" +#include "mulaw-decode.h" + +static GstElementDetails mulawenc_details = { + "PCM to Mu Law conversion", + "Filter/Effect", + "Convert 16bit PCM to 8bit mu law", + VERSION, + "Zaheer Merali <zaheer@bellworldwide.net>", + "(C) 2001" +}; + +static GstElementDetails mulawdec_details = { + "Mu Law to PCM conversion", + "Filter/Effect", + "Convert 8bit mu law to 16bit PCM", + VERSION, + "Zaheer Merali <zaheer@bellworldwide.net>", + "(C) 2001" +}; + +static GstCaps* +mulaw_factory (void) +{ + return + gst_caps_new ( + "test_src", + "audio/raw", + gst_props_new ( + "format", GST_PROPS_STRING ("int"), + "law", GST_PROPS_INT (1), + "width", GST_PROPS_INT(8), + "depth", GST_PROPS_INT(8), + "signed", GST_PROPS_BOOLEAN(FALSE), + NULL)); +} + +static GstCaps* +linear_factory (void) +{ + return + gst_caps_new ( + "test_sink", + "audio/raw", + gst_props_new ( + "format", GST_PROPS_STRING ("int"), + "law", GST_PROPS_INT(0), + "width", GST_PROPS_INT(16), + "depth", GST_PROPS_INT(16), + "signed", GST_PROPS_BOOLEAN(TRUE), + NULL)); +} + +GstPadTemplate *mulawenc_src_template, *mulawenc_sink_template; +GstPadTemplate *mulawdec_src_template, *mulawdec_sink_template; + +static gboolean +plugin_init (GModule *module, GstPlugin *plugin) +{ + GstElementFactory *mulawenc_factory, *mulawdec_factory; + GstCaps* mulaw_caps, *linear_caps; + + mulawenc_factory = gst_elementfactory_new("mulawencode",GST_TYPE_MULAWENC, + &mulawenc_details); + g_return_val_if_fail(mulawenc_factory != NULL, FALSE); + mulawdec_factory = gst_elementfactory_new("mulawdecode",GST_TYPE_MULAWDEC, + &mulawdec_details); + g_return_val_if_fail(mulawdec_factory != NULL, FALSE); + + mulaw_caps = mulaw_factory (); + linear_caps = linear_factory (); + + mulawenc_src_template = gst_padtemplate_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + mulaw_caps, NULL); + mulawenc_sink_template = gst_padtemplate_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + linear_caps, NULL); + + gst_elementfactory_add_padtemplate (mulawenc_factory, mulawenc_src_template); + gst_elementfactory_add_padtemplate (mulawenc_factory, mulawenc_sink_template); + + mulawdec_src_template = gst_padtemplate_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + linear_caps, NULL); + mulawdec_sink_template = gst_padtemplate_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + mulaw_caps, NULL); + + gst_elementfactory_add_padtemplate (mulawdec_factory, mulawdec_src_template); + gst_elementfactory_add_padtemplate (mulawdec_factory, mulawdec_sink_template); + + gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (mulawenc_factory)); + gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (mulawdec_factory)); + + + + return TRUE; +} + +GstPluginDesc plugin_desc = { + GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mulaw", + plugin_init +}; + |