[MPlayer-dev-eng] Re: [PATCH] ao_nas.c network audio freezes
Tobias Diedrich
td at sim.uni-hannover.de
Fri Oct 4 22:12:47 CEST 2002
Arpi wrote:
> > Small error, the buffer size got set incorrectly.
> > (Now BUFFER_SIZE * 3 instead of BUFFER_SIZE * 2)
>
> what about this one? should i apply to cvs, or it's for testing yet?
Well current cvs works ok if you ignore the error messages and the
ocasional stuttering at the beginning. :-)
I think it should be ok to apply it, works like a charm here. ^_^
Log message: fix event_handler and stuttering (on start/pause/seek)
If you decide to apply it, here is an additional patch to apply on top
of that one which converts ao_nas.c to use mp_msg.
--
Tobias PGP: 0x9AC7E0BC
This mail is made of 100% recycled bits
Now playing: Chobits: OST 001 02 - Katakoto koi
-------------- next part --------------
--- libao2/ao_nas.c.should_become_1.7 2002-10-02 19:23:30.000000000 +0200
+++ libao2/ao_nas.c 2002-10-02 19:22:12.000000000 +0200
@@ -31,6 +31,8 @@
#include <pthread.h>
#include <audio/audiolib.h>
+#include "../mp_msg.h"
+
#include "audio_out.h"
#include "audio_out_internal.h"
#include "afmt.h"
@@ -39,10 +41,6 @@
#define NAS_FRAG_COUNT 8
#define NAS_BUFFER_SIZE NAS_FRAG_SIZE * NAS_FRAG_COUNT
-#define NAS_DEBUG 0
-
-#if NAS_DEBUG == 1
-
static char *nas_event_types[] = {
"Undefined",
"Undefined",
@@ -99,12 +97,6 @@
return nas_states[state];
}
-#define DPRINTF(format, args...) fprintf(stderr, format, ## args); \
- fflush(stderr)
-#else
-#define DPRINTF(format, args...)
-#endif
-
static ao_info_t info =
{
"NAS audio output",
@@ -142,8 +134,7 @@
{
char s[100];
AuGetErrorText(aud, as, s, 100);
- fprintf(stderr, "ao_nas: %s: returned status %d (%s)\n", prefix, as, s);
- fflush(stderr);
+ mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: %s: returned status %d (%s)\n", prefix, as, s);
}
static int nas_readBuffer(struct ao_nas_data *nas_data, int num)
@@ -151,13 +142,13 @@
AuStatus as;
pthread_mutex_lock(&nas_data->buffer_mutex);
- DPRINTF("ao_nas: nas_readBuffer(): num=%d client=%d/%d server=%d/%d\n",
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: nas_readBuffer(): num=%d client=%d/%d server=%d/%d\n",
num,
nas_data->client_buffer_used, nas_data->client_buffer_size,
nas_data->server_buffer_used, nas_data->server_buffer_size);
if (nas_data->client_buffer_used == 0) {
- DPRINTF("ao_nas: buffer is empty, nothing read.\n");
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: buffer is empty, nothing read.\n");
pthread_mutex_unlock(&nas_data->buffer_mutex);
return 0;
}
@@ -200,7 +191,7 @@
static void nas_writeBuffer(struct ao_nas_data *nas_data, void *data, int len)
{
pthread_mutex_lock(&nas_data->buffer_mutex);
- DPRINTF("ao_nas: nas_writeBuffer(): len=%d client=%d/%d server=%d/%d\n",
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: nas_writeBuffer(): len=%d client=%d/%d server=%d/%d\n",
len, nas_data->client_buffer_used, nas_data->client_buffer_size,
nas_data->server_buffer_used, nas_data->server_buffer_size);
@@ -239,7 +230,7 @@
{
char s[100];
AuGetErrorText(aud, ev->error_code, s, 100);
- fprintf(stderr,"ao_nas: error [%s]\n"
+ mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: error [%s]\n"
"error_code: %d\n"
"request_code: %d\n"
"minor_code: %d\n",
@@ -247,7 +238,6 @@
ev->error_code,
ev->request_code,
ev->minor_code);
- fflush(stderr);
return AuTrue;
}
@@ -260,7 +250,7 @@
switch (ev->type) {
case AuEventTypeElementNotify:
- DPRINTF("ao_nas: event_handler(): kind %s state %s->%s reason %s numbytes %d expect_underrun %d\n",
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: event_handler(): kind %s state %s->%s reason %s numbytes %d expect_underrun %d\n",
nas_elementnotify_kind(event->kind),
nas_state(event->prev_state),
nas_state(event->cur_state),
@@ -283,10 +273,11 @@
// buffer underrun -> refill buffer
if (nas_data->expect_underrun)
nas_data->expect_underrun = 0;
- else
- fprintf(stderr, "ao_nas: Buffer underrun.\n"
- "Possible reasons are network congestion or your NAS server is too slow.\n"
+ else {
+ mp_msg(MSGT_AO, MSGL_WARN, "ao_nas: Buffer underrun.\n");
+ mp_msg(MSGT_AO, MSGL_HINT, "Possible reasons are network congestion or your NAS server is too slow.\n"
"Try renicing your nasd to e.g. -15.\n");
+ }
nas_data->server_buffer_used = 0;
if (nas_readBuffer(nas_data, nas_data->server_buffer_size - nas_data->server_buffer_used) == 0)
nas_data->flow_stopped = 1;
@@ -301,7 +292,7 @@
}
break;
default:
- printf("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 %d\n", ev->type);
break;
}
return AuTrue;
@@ -358,11 +349,11 @@
nas_data=malloc(sizeof(struct ao_nas_data));
memset(nas_data, 0, sizeof(struct ao_nas_data));
- printf("ao2: %d Hz %d chans %s\n",rate,channels,
+ mp_msg(MSGT_AO, MSGL_V, "ao2: %d Hz %d chans %s\n",rate,channels,
audio_out_format_name(format));
if (!auformat) {
- printf("ao_nas: init(): Unsupported format -> nosound\n");
+ mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Unsupported format -> nosound\n");
return 0;
}
@@ -373,13 +364,12 @@
ao_data.samplerate = rate;
ao_data.channels = channels;
- ao_data.buffersize = nas_data->client_buffer_size +
- nas_data->server_buffer_size;
+ ao_data.buffersize = NAS_BUFFER_SIZE * 2;
ao_data.outburst = NAS_FRAG_SIZE;
ao_data.bps = rate * bytes_per_sample;
if (!bytes_per_sample) {
- printf("ao_nas: init(): Zero bytes per sample -> nosound\n");
+ mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Zero bytes per sample -> nosound\n");
return 0;
}
@@ -389,17 +379,17 @@
if (!server) // default to tcp/localhost:8000
server = "tcp/localhost:8000";
- printf("ao_nas: init(): Using audioserver %s\n", server);
+ 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){
- printf("ao_nas: init(): Can't open nas audio server -> nosound\n");
+ 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)))) {
- printf("ao_nas: init(): Can't find a device serving that many channels -> nosound\n");
+ mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't find a device serving that many channels -> nosound\n");
AuCloseServer(nas_data->aud);
nas_data->aud = 0;
return 0;
@@ -432,7 +422,7 @@
static void uninit(){
AuStatus as;
- DPRINTF("ao_nas: uninit()\n");
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: uninit()\n");
nas_data->stop_thread = 1;
pthread_join(nas_data->event_thread, NULL);
@@ -451,7 +441,7 @@
static void reset(){
AuStatus as;
- DPRINTF("ao_nas: reset()\n");
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: reset()\n");
pthread_mutex_lock(&nas_data->buffer_mutex);
nas_data->client_buffer_used = 0;
@@ -471,7 +461,7 @@
{
AuStatus as;
- DPRINTF("ao_nas: audio_pause()\n");
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: audio_pause()\n");
nas_data->flow_paused = 1;
}
@@ -482,7 +472,7 @@
AuStatus as;
AuEvent ev;
- DPRINTF("ao_nas: audio_resume()\n");
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: audio_resume()\n");
nas_data->flow_stopped = 0;
nas_data->flow_paused = 0;
@@ -498,7 +488,7 @@
{
int result;
- DPRINTF("ao_nas: get_space()\n");
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: get_space()\n");
pthread_mutex_lock(&nas_data->buffer_mutex);
result = nas_data->client_buffer_size - nas_data->client_buffer_used;
@@ -515,7 +505,7 @@
int maxbursts, playbursts, writelen;
AuStatus as;
- DPRINTF("ao_nas: play()\n");
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play()\n");
pthread_mutex_lock(&nas_data->buffer_mutex);
maxbursts = (nas_data->client_buffer_size -
@@ -545,7 +535,7 @@
{
float result;
- DPRINTF("ao_nas: get_delay()\n");
+ mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: get_delay()\n");
pthread_mutex_lock(&nas_data->buffer_mutex);
result = ((float)(nas_data->client_buffer_used +
-------------- 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/20021004/b5fc3237/attachment.pgp>
More information about the MPlayer-dev-eng
mailing list