[Freeswitch-svn] [commit] r9675 - freeswitch/trunk/src/mod/formats/mod_shout

Freeswitch SVN anthm at freeswitch.org
Fri Sep 26 19:14:20 EDT 2008


Author: anthm
Date: Fri Sep 26 19:14:19 2008
New Revision: 9675

Removed:
   freeswitch/trunk/src/mod/formats/mod_shout/common.c
   freeswitch/trunk/src/mod/formats/mod_shout/dct64_i386.c
   freeswitch/trunk/src/mod/formats/mod_shout/decode_i386.c
   freeswitch/trunk/src/mod/formats/mod_shout/decode_ntom.c
   freeswitch/trunk/src/mod/formats/mod_shout/huffman.h
   freeswitch/trunk/src/mod/formats/mod_shout/interface.c
   freeswitch/trunk/src/mod/formats/mod_shout/layer3.c
   freeswitch/trunk/src/mod/formats/mod_shout/mpg123.h
   freeswitch/trunk/src/mod/formats/mod_shout/mpglib.h
   freeswitch/trunk/src/mod/formats/mod_shout/tabinit.c
Modified:
   freeswitch/trunk/src/mod/formats/mod_shout/Makefile
   freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c

Log:
break mod_shout

Modified: freeswitch/trunk/src/mod/formats/mod_shout/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/formats/mod_shout/Makefile	(original)
+++ freeswitch/trunk/src/mod/formats/mod_shout/Makefile	Fri Sep 26 19:14:19 2008
@@ -1,21 +1,22 @@
 LAME=lame-3.97
 SHOUT=libshout-2.2.2
+MPG123=mpg123
 switch_srcdir=../../../..
 
 WANT_CURL=yes
 
 LAME_DIR=$(switch_srcdir)/libs/$(LAME)
 SHOUT_DIR=$(switch_srcdir)/libs/$(SHOUT)
+MPG123_DIR=$(switch_srcdir)/libs/$(MPG123)
 
 LAMELA=$(LAME_DIR)/libmp3lame/libmp3lame.la
 SHOUTLA=$(SHOUT_DIR)/src/libshout.la
+MPG123LA=$(MPG123_DIR)/src/libmpg123/.libs/libmpg123.la
 
-LOCAL_CFLAGS=-I$(SHOUT_DIR)/include -I$(LAME_DIR)/include
-LOCAL_LIBADD=$(LAMELA) $(SHOUTLA) 
+LOCAL_CFLAGS=-I$(SHOUT_DIR)/include -I$(LAME_DIR)/include -I$(MPG123_DIR)/src
+LOCAL_LIBADD=$(LAMELA) $(SHOUTLA) $(MPG123LA)
 
-LOCAL_LDFLAGS=`cat ../../../../libs/libshout-2.2.2/Makefile | grep SPEEX_LIBS | sed -e 's|^SPEEX_LIBS =||'`
-MP3SOURCES=common.c dct64_i386.c decode_ntom.c layer3.c tabinit.c interface.c
-MP3OBJS=common.o dct64_i386.o decode_ntom.o layer3.o tabinit.o interface.o
+LOCAL_LDFLAGS=`cat ../../../../libs/libshout-2.2.2/Makefile | grep SPEEX_LIBS | sed -e 's|^SPEEX_LIBS =||'` 
 LOCAL_OBJS=$(MP3OBJS)
 LOCAL_SOURCES=$(MP3SOURCES)
 
@@ -25,6 +26,17 @@
 
 $(LOCAL_OBJS): $(LOCAL_SOURCES)
 
+$(MPG123_DIR):
+	$(GETLIB) $(MPG123).tar.gz
+
+$(MPG123_DIR)/Makefile: $(MPG123_DIR)
+	cd $(MPG123_DIR) && ./configure $(DEFAULT_ARGS) --disable-shared
+	$(TOUCH_TARGET)
+
+$(MPG123LA): $(MPG123_DIR)/Makefile
+	cd $(MPG123_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
+
 $(LAME_DIR):
 	$(GETLIB) $(LAME).tar.gz
 
@@ -40,7 +52,7 @@
 	$(GETLIB) $(SHOUT).tar.gz
 
 $(SHOUT_DIR)/Makefile: $(SHOUT_DIR)
-	cd $(SHOUT_DIR) && ./configure $(DEFAULT_ARGS) --with-speex=no --without-vorbis
+	cd $(SHOUT_DIR) && ./configure $(DEFAULT_ARGS) --without-speex --without-vorbis --without-ogg
 	$(TOUCH_TARGET)
 
 $(SHOUTLA): $(SHOUT_DIR)/Makefile

Modified: freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c
==============================================================================
--- freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c	(original)
+++ freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c	Fri Sep 26 19:14:19 2008
@@ -30,8 +30,7 @@
  * example filename: shout://user:pass@host.com/mount.mp3
  *
  */
-#include "mpg123.h"
-#include "mpglib.h"
+#include "libmpg123/mpg123.h"
 #include <switch.h>
 #include <shout/shout.h>
 #include <lame.h>
@@ -40,6 +39,7 @@
 #define OUTSCALE 8192 * 2
 #define MP3_SCACHE 16384 * 2
 #define MP3_DCACHE 8192 *2
+#define MP3_TOOSMALL -1234
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_shout_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_shout_shutdown);
@@ -54,8 +54,10 @@
 	switch_mutex_t *audio_mutex;
 	switch_buffer_t *audio_buffer;
 	switch_memory_pool_t *memory_pool;
-	char decode_buf[MP3_DCACHE];
-	struct mpstr mp;
+	unsigned char decode_buf[MP3_DCACHE];
+	//struct mpstr mp;
+	switch_file_handle_t *handle;
+	mpg123_handle *mh;
 	int err;
 	int mp3err;
 	int dlen;
@@ -141,7 +143,12 @@
 				}
 			}
 
-			ExitMP3(&context->mp);
+			
+		}
+
+		if (context->mh) {
+			mpg123_close(context->mh);
+			mpg123_delete(context->mh);
 		}
 	}
 }
@@ -227,24 +234,24 @@
 static size_t decode_fd(shout_context_t *context, void *data, size_t bytes)
 {
 	int decode_status = 0;
-	int dlen = 0;
+	size_t dlen = 0;
 	int x = 0;
-	char *in;
+	unsigned char *in;
 	int inlen = 0;
-	char *out;
+	unsigned char *out;
 	int outlen;
 	int usedlen;
-	char inbuf[MP3_SCACHE];
+	unsigned char inbuf[MP3_SCACHE];
 	int done = 0;
 	size_t used;
 	size_t lp;
 	size_t rb = 0;
 	
-	while (!context->eof && switch_buffer_inuse(context->audio_buffer) < bytes) {
+	while (context->eof < 2 && switch_buffer_inuse(context->audio_buffer) < bytes) {
 		lp = sizeof(inbuf);
-		if ((switch_file_read(context->fd, inbuf, &lp) != SWITCH_STATUS_SUCCESS) || lp == 0) {
+		if (!context->eof && ((switch_file_read(context->fd, inbuf, &lp) != SWITCH_STATUS_SUCCESS) || lp == 0)) {
 			context->eof++;
-			goto end;
+			//goto end;
 		}
 
 		inlen = (int) lp;
@@ -260,8 +267,13 @@
 		}
 		
 		do {
-			decode_status = decodeMP3(&context->mp, in, inlen, out, outlen, &dlen);
-			
+			if (context->eof) {
+				decode_status = mpg123_read(context->mh, out, outlen, &dlen);
+			} else {
+				decode_status = mpg123_decode(context->mh, in, inlen, out, outlen, &dlen);
+			}
+
+
 			if (context->err) {
 				goto error;
 			}
@@ -272,7 +284,11 @@
 				x++;
 			}
 
-			if (decode_status == MP3_TOOSMALL) {
+			if (decode_status == MPG123_NEW_FORMAT) {
+				continue;
+			} else if (decode_status == MPG123_OK) {
+				usedlen = dlen;
+				break;
 				if (context->audio_buffer) {
 					switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
 				} else {
@@ -285,7 +301,10 @@
 				
 				continue;
 				
-			} else if (decode_status == MP3_ERR) {
+			} else if (decode_status == MPG123_DONE) {
+				context->eof++;
+				goto end;
+			} else if (decode_status == MPG123_ERR || decode_status > 0) {
 				if (++context->mp3err >= 5) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decoder Error!\n");
 					context->eof++;
@@ -302,7 +321,7 @@
 			dlen = 0;
 
 
-		} while (decode_status != MP3_NEED_MORE);
+		} while (decode_status != MPG123_NEED_MORE);
 
 		if (context->audio_buffer) {
 			switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
@@ -318,7 +337,7 @@
  end:
 	
 	used = switch_buffer_inuse(context->audio_buffer);
-	
+
 	if (context->eof || done || used >= bytes) {
 		if (!(rb = switch_buffer_read(context->audio_buffer, data, bytes))) {
 			goto error;
@@ -342,15 +361,15 @@
 	register unsigned int realsize = (unsigned int) (size * nmemb);
 	shout_context_t *context = data;
 	int decode_status = 0;
-	int dlen = 0;
+	size_t dlen = 0;
 	int x = 0;
-	char *in;
+	unsigned char *in;
 	int inlen;
-	char *out;
+	unsigned char *out;
 	int outlen;
 	int usedlen;
 	uint32_t used, buf_size = 1024 * 64;
-
+	
 	in = ptr;
 	inlen = realsize;
 	out = context->decode_buf;
@@ -387,7 +406,7 @@
 	error_check();
 
 	do {
-		decode_status = decodeMP3(&context->mp, in, inlen, out, outlen, &dlen);
+		decode_status = mpg123_decode(context->mh, in, inlen, out, outlen, &dlen);
 
 		error_check();
 
@@ -409,16 +428,19 @@
 			usedlen = 0;
 			switch_mutex_unlock(context->audio_mutex);
 
-		} else if (decode_status == MP3_ERR) {
+		} else if (decode_status == MPG123_ERR) {
 
 			if (++context->mp3err >= 20) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decoder Error!\n");
 				goto error;
 			}
 
-			ExitMP3(&context->mp);
-			InitMP3(&context->mp, OUTSCALE, context->samplerate);
-
+			mpg123_close(context->mh);
+			//InitMP3(context->mh, OUTSCALE, context->samplerate);
+			context->mh = mpg123_new(NULL, NULL);
+			mpg123_open_feed(context->mh);
+			mpg123_format(context->mh, context->samplerate, MPG123_MONO, 0);
+			
 			return realsize;
 		}
 
@@ -427,7 +449,7 @@
 		out += dlen;
 		outlen -= dlen;
 		dlen = 0;
-	} while (decode_status != MP3_NEED_MORE);
+	} while (decode_status != MPG123_NEED_MORE);
 
 
 	switch_mutex_lock(context->audio_mutex);
@@ -598,6 +620,7 @@
 
 	context->memory_pool = handle->memory_pool;
 	context->samplerate = handle->samplerate;
+	context->handle = handle;
 
 	if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) {
 		if (switch_buffer_create_dynamic(&context->audio_buffer, TC_BUFFER_SIZE, TC_BUFFER_SIZE * 2, 0) != SWITCH_STATUS_SUCCESS) {
@@ -606,17 +629,23 @@
 		}
 
 		switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, context->memory_pool);
-		InitMP3(&context->mp, OUTSCALE, context->samplerate);
+		//InitMP3(context->mh, OUTSCALE, context->samplerate);
+		context->mh = mpg123_new(NULL, NULL);
+		mpg123_open_feed(context->mh);
+		mpg123_param(context->mh, MPG123_FORCE_RATE, context->samplerate, 0);
+		
+
 		if (handle->handler) {
 			context->stream_url = switch_core_sprintf(context->memory_pool, "http://%s", path);
 			context->prebuf = handle->prebuf;
 			launch_read_stream_thread(context);
 		} else {
-			if (switch_file_open(&context->fd, path, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, handle->memory_pool) !=
+			if (switch_file_open(&context->fd, path, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, handle->memory_pool) != 
 				SWITCH_STATUS_SUCCESS) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
 				goto error;
 			}
+			
 		}
 	} else if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
 		if (!(context->gfp = lame_init())) {
@@ -794,8 +823,11 @@
 				*cur_sample = fseek(context->fp, *cur_sample, whence);
 			}
 
-			ExitMP3(&context->mp);
-			InitMP3(&context->mp, OUTSCALE, context->samplerate);
+			mpg123_close(context->mh);
+			//InitMP3(context->mh, OUTSCALE, context->samplerate);
+			context->mh = mpg123_new(NULL, NULL);
+			mpg123_open_feed(context->mh);
+			mpg123_format(context->mh, context->samplerate, MPG123_MONO, 0);
 			switch_buffer_zero(context->audio_buffer);
 
 		} else {
@@ -1385,7 +1417,8 @@
 	//*module_interface = &shout_module_interface;
 
 	shout_init();
-	InitMP3Constants();
+	//InitMP3Constants();
+	mpg123_init();
 
 	SWITCH_ADD_API(shout_api_interface, "telecast", "telecast", telecast_api_function, TELECAST_SYNTAX);
 



More information about the Freeswitch-svn mailing list