[MPlayer-dev-eng] Re: ANNOUNCE: new audio filter layer in use

Tobias Diedrich td at sim.uni-hannover.de
Tue Oct 8 22:59:40 CEST 2002


Tobias Diedrich wrote:
> Arpi wrote:
> 
> > imho it should be (AFMT_S16_LE << 8) + AuFormatLinearSigned16LSB, as
> > << has lower priority than +

Trying to stuff to return values into one seems to be a bad idea anyway,
at least it did not work properly... This patch changes this back and
format to *format so the format we use is passed that way.
It also fixes a few warnings and one missing check in init(), it did not
abort when AuSetElements failed because of missing brackets in
"(nas_data->flow = AuCreateFlow(nas_data->aud, NULL) != 0))".

Somehow I was sure I did check it worked before sending the patch, but
now it seems I forgot that...

So here is the bugfix patch.

-- 
Tobias								PGP: 0x9AC7E0BC
This mail is made of 100% recycled bits
Now playing: Chihiro Yonekura: Merry-MP3go-Around - Sweet True Love
-------------- next part --------------
Index: main/libao2/ao_nas.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_nas.c,v
retrieving revision 1.9
diff -u -r1.9 ao_nas.c
--- main/libao2/ao_nas.c	7 Oct 2002 01:50:49 -0000	1.9
+++ main/libao2/ao_nas.c	8 Oct 2002 21:17:46 -0000
@@ -26,8 +26,10 @@
  * accounting of what we think how much of the server buffer is filled)
  */
 
+#include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <pthread.h>
 #include <audio/audiolib.h>
 
@@ -217,13 +219,13 @@
 static void *nas_event_thread_start(void *data)
 {
 	struct ao_nas_data *nas_data = data;
-	AuEvent ev;
-	AuBool result;
 
 	do {
 		nas_empty_event_queue(nas_data);
 		usleep(10000);
 	} while (!nas_data->stop_thread);
+
+	return NULL;
 }
 
 static AuBool nas_error_handler(AuServer* aud, AuErrorEvent* ev)
@@ -245,7 +247,6 @@
 static AuBool nas_event_handler(AuServer *aud, AuEvent *ev, AuEventHandlerRec *hnd)
 {
 	AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev;
-	AuStatus as;
 	struct ao_nas_data *nas_data = hnd->data;
 
 	switch (ev->type) {
@@ -292,7 +293,7 @@
 		}
 		break;
 	default: 
-		mp_msg(MSGT_AO, MSGL_WARN, "ao_nas: nas_event_handler(): unhandled event type %d\n", ev->type);
+		mp_msg(MSGT_AO, MSGL_WARN, "ao_nas: nas_event_handler(): unhandled event type %s\n", nas_event_type(ev->type));
 		break;
 	}
 	return AuTrue;
@@ -311,30 +312,31 @@
 	return AuNone;
 }
 
-static unsigned int nas_aformat_to_auformat(unsigned int format)
+static unsigned int nas_aformat_to_auformat(unsigned int *format)
 {
-	unsigned int res=format << 8;
-	switch (format) {
+	switch (*format) {
 	case	AFMT_U8:
-		return res + AuFormatLinearUnsigned8;
+		return AuFormatLinearUnsigned8;
 	case	AFMT_S8:
-		return res + AuFormatLinearSigned8;
+		return AuFormatLinearSigned8;
 	case	AFMT_U16_LE:
-		return res + AuFormatLinearUnsigned16LSB;
+		return AuFormatLinearUnsigned16LSB;
 	case	AFMT_U16_BE:
-		return res + AuFormatLinearUnsigned16MSB;
+		return AuFormatLinearUnsigned16MSB;
 #ifndef WORDS_BIGENDIAN
 	default:
+		*format=AFMT_S16_LE;
 #endif
 	case	AFMT_S16_LE:
-		return (AFMT_S16_LE << 8) + AuFormatLinearSigned16LSB;
+		return AuFormatLinearSigned16LSB;
 #ifdef WORDS_BIGENDIAN
 	default:
+		*format=AFMT_S16_BE;
 #endif
 	case	AFMT_S16_BE:
-		return (AFMT_S16_BE << 8) + AuFormatLinearSigned16MSB;
+		return AuFormatLinearSigned16MSB;
 	case	AFMT_MU_LAW:
-		return res + AuFormatULAW8;
+		return AuFormatULAW8;
 	}
 }
 
@@ -349,7 +351,7 @@
 {
 	AuElement elms[3];
 	AuStatus as;
-	unsigned char auformat = nas_aformat_to_auformat(format);
+	unsigned char auformat = nas_aformat_to_auformat(&format);
 	int bytes_per_sample = channels * AuSizeofFormat(auformat);
 	char *server;
 
@@ -364,7 +366,7 @@
 	nas_data->server_buffer_size = NAS_BUFFER_SIZE;
 	nas_data->server_buffer = malloc(nas_data->server_buffer_size);
 
-	ao_data.format = auformat >> 8;
+	ao_data.format = format;
 	ao_data.samplerate = rate;
 	ao_data.channels = channels;
 	ao_data.buffersize = NAS_BUFFER_SIZE * 2;
@@ -393,7 +395,7 @@
 	while (channels>1) {
 		nas_data->dev = nas_find_device(nas_data->aud, channels);
 		if (nas_data->dev != AuNone &&
-		    (nas_data->flow = AuCreateFlow(nas_data->aud, NULL) != 0))
+		    ((nas_data->flow = AuCreateFlow(nas_data->aud, NULL)) != 0))
 			break;
 		channels--;
 	}
@@ -405,15 +407,19 @@
 		return 0;
 	}
 
-	AuMakeElementImportClient(elms, rate, auformat & 0xff, channels, AuTrue,
+	AuMakeElementImportClient(elms, rate, auformat, channels, AuTrue,
 				NAS_BUFFER_SIZE / bytes_per_sample,
 				(NAS_BUFFER_SIZE - NAS_FRAG_SIZE) / bytes_per_sample,
 				0, NULL);
 	AuMakeElementExportDevice(elms+1, 0, nas_data->dev, rate,
 				AuUnlimitedSamples, 0, NULL);
 	AuSetElements(nas_data->aud, nas_data->flow, AuTrue, 2, elms, &as);
-	if (as != AuSuccess)
+	if (as != AuSuccess) {
 		nas_print_error(nas_data->aud, "init(): AuSetElements", as);
+		AuCloseServer(nas_data->aud);
+		nas_data->aud = 0;
+		return 0;
+	}
 	AuRegisterEventHandler(nas_data->aud, AuEventHandlerIDMask |
 				AuEventHandlerTypeMask,
 				AuEventTypeElementNotify, nas_data->flow,
@@ -469,8 +475,6 @@
 // stop playing, keep buffers (for pause)
 static void audio_pause()
 {
-	AuStatus as;
-
 	mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: audio_pause()\n");
 
 	nas_data->flow_paused = 1;
@@ -480,7 +484,6 @@
 static void audio_resume()
 {
 	AuStatus as;
-	AuEvent ev;
 
 	mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: audio_resume()\n");
 
@@ -528,8 +531,6 @@
 	nas_writeBuffer(nas_data, data, writelen);
 
 	if (nas_data->flow_stopped) {
-		AuEvent ev;
-
 		nas_data->expect_underrun = 1;
 		AuStartFlow(nas_data->aud, nas_data->flow, &as);
 		if (as != AuSuccess)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20021008/7c03d5a0/attachment.pgp>


More information about the MPlayer-dev-eng mailing list