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

Tobias Diedrich td at sim.uni-hannover.de
Sun Oct 6 22:21:36 CEST 2002


Arpi wrote:

> it depends on the ao_data fields channels,samplerate,bps(bytes per _second_)
> and format (see afmt.h), so every -ao driver HAVE TO set up them properly.
> please check your ao driver!
> 
> the ao driver should not fail if channels/format/rate not acceptable - they
> should change them (in ao_data) to the wanted/accepted values. the
> conversion will be done automatically by libaf then.

Patch attached.

-- 
Tobias								PGP: 0x9AC7E0BC
This mail is made of 100% recycled bits
Now playing: RahXephon: OST1 01 - Hemisphere
-------------- next part --------------
Index: libao2/ao_nas.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_nas.c,v
retrieving revision 1.8
diff -u -r1.8 ao_nas.c
--- libao2/ao_nas.c	6 Oct 2002 17:31:36 -0000	1.8
+++ libao2/ao_nas.c	6 Oct 2002 20:46:14 -0000
@@ -311,23 +311,30 @@
 	return AuNone;
 }
 
-static unsigned char nas_aformat_to_auformat(unsigned int format)
+static unsigned int nas_aformat_to_auformat(unsigned int format)
 {
+	unsigned int res=format << 8;
 	switch (format) {
-	case	AFMT_U8:	return AuFormatLinearUnsigned8;
-	case	AFMT_S8:	return AuFormatLinearSigned8;
-	case	AFMT_U16_LE:	return AuFormatLinearUnsigned16LSB;
-	case	AFMT_U16_BE:	return AuFormatLinearUnsigned16MSB;
+	case	AFMT_U8:
+		return res + AuFormatLinearUnsigned8;
+	case	AFMT_S8:
+		return res + AuFormatLinearSigned8;
+	case	AFMT_U16_LE:
+		return res + AuFormatLinearUnsigned16LSB;
+	case	AFMT_U16_BE:
+		return res + AuFormatLinearUnsigned16MSB;
 #ifndef WORDS_BIGENDIAN
-	case AFMT_AC3:
+	default:
 #endif
-	case	AFMT_S16_LE:	return AuFormatLinearSigned16LSB;
+	case	AFMT_S16_LE:
+		return AFMT_S16_LE << 8 + AuFormatLinearSigned16LSB;
 #ifdef WORDS_BIGENDIAN
-	case AFMT_AC3:
+	default:
 #endif
-	case	AFMT_S16_BE:	return AuFormatLinearSigned16MSB;
-	case	AFMT_MU_LAW:	return AuFormatULAW8;
-	default: return 0;
+	case	AFMT_S16_BE:
+		return AFMT_S16_BE << 8 + AuFormatLinearSigned16MSB;
+	case	AFMT_MU_LAW:
+		return res + AuFormatULAW8;
 	}
 }
 
@@ -352,16 +359,12 @@
 	mp_msg(MSGT_AO, MSGL_V, "ao2: %d Hz  %d chans  %s\n",rate,channels,
 		audio_out_format_name(format));
 
-	if (!auformat) {
-		mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Unsupported format -> nosound\n");
-		return 0;
-	}
-
 	nas_data->client_buffer_size = NAS_BUFFER_SIZE*2;
 	nas_data->client_buffer = malloc(nas_data->client_buffer_size);
 	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.samplerate = rate;
 	ao_data.channels = channels;
 	ao_data.buffersize = NAS_BUFFER_SIZE * 2;
@@ -373,29 +376,36 @@
 		return 0;
 	}
 
-	if (!(server = getenv("AUDIOSERVER")))
-		server = getenv("DISPLAY");
-
-	if (!server) // default to tcp/localhost:8000
-		server = "tcp/localhost:8000";
+	if (!(server = getenv("AUDIOSERVER")) &&
+	    !(server = getenv("DISPLAY"))) {
+		mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): AUDIOSERVER environment variable not set -> nosound\n");
+		return 0;
+	}
 
 	mp_msg(MSGT_AO, MSGL_V, "ao_nas: init(): Using audioserver %s\n", server);
 
 	nas_data->aud = AuOpenServer(server, 0, NULL, 0, NULL, NULL);
-	if (!nas_data->aud){ 
+	if (!nas_data->aud) { 
 		mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't open nas audio server -> nosound\n");
 		return 0;
 	}
 
-	nas_data->dev = nas_find_device(nas_data->aud, channels);
-	if ((nas_data->dev == AuNone) || (!(nas_data->flow = AuCreateFlow(nas_data->aud, NULL)))) {
-		mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't find a device serving that many channels -> nosound\n");
+	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))
+			break;
+		channels--;
+	}
+
+	if (nas_data->flow == 0) {
+		mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't find a suitable output device -> nosound\n");
 		AuCloseServer(nas_data->aud);
 		nas_data->aud = 0;
 		return 0;
 	}
 
-	AuMakeElementImportClient(elms, rate, auformat, channels, AuTrue,
+	AuMakeElementImportClient(elms, rate, auformat & 0xff, channels, AuTrue,
 				NAS_BUFFER_SIZE / bytes_per_sample,
 				(NAS_BUFFER_SIZE - NAS_FRAG_SIZE) / bytes_per_sample,
 				0, NULL);


More information about the MPlayer-dev-eng mailing list