Author Topic: Detecting stream disconnect/connection errors with BASS-CE on Windows Mobile  (Read 2195 times)

BiggieSmalls

  • Posts: 21
Hey All,

I'm using BASS_StreamCreateURL to stream mp3/ogg data from a server. (BASS-CE on Windows Mobile 6.x)
Everything seems to work fine, however i'm having problems detecting connection failure. If i start streaming (with the Windows Mobile emulator cradled so it shares my desktop connection) and then all of a sudden uncradle the device the stream stalls after a while (my stall sync is called), which is obviously expected since no more data can be received. But my endsync callback is never called? Is this because BASS simply didn't detect the disconnect yet? (perhaps a timeout setting i overlooked?)

I really want to avoid polling to detect dropped connections. Surely there must be some way for BASS to detect a lost connection? A wininet timeout or something.

What's the proper way to detect a disconnected stream with BAS-CE? (by this i mean connection failure which happens frequently for data connections on mobile phones).

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 20437
It does appear that the socket is left open/waiting if the internet connection is taken away. A BASS.DLL update is now in the package (see the WinCE thread) that will timeout the connection if nothing is received for 5 seconds. Let me know if you still have any trouble with it.

BiggieSmalls

  • Posts: 21
It does appear that the socket is left open/waiting if the internet connection is taken away. A BASS.DLL update is now in the package (see the WinCE thread) that will timeout the connection if nothing is received for 5 seconds. Let me know if you still have any trouble with it.

Thanks Ian, seems to work fine. my end sync is getting called now and BASS_StreamGetFilePosition() indicates that the stream is disconnected. Just wondering if the 5 sec. is a hard coded value?

Ian @ un4seen

  • Administrator
  • Posts: 20437
Yes, it is currently a hard-coded value, but a CONFIG option could be added if that proves to be troublesome.

BiggieSmalls

  • Posts: 21
Yes, it is currently a hard-coded value, but a CONFIG option could be added if that proves to be troublesome.

A config option would really help. E.g. sometimes my phone switches from a high speed network (3G) to a lower speed network if the signal isn't very good. this can take a few seconds. During this period the stream might stall, which is acceptable. But 5 sec. seems to be a bit short in this situation. Because the stream would have been able to continue without a problem once the phone switched data connections (no TCP connections are lost in this process, my app isn't even aware that this is happening). It seems a waste to close and reconnect a connection just because BASS didn't receive data for 5 sec.

Ian @ un4seen

  • Administrator
  • Posts: 20437
OK, the following BASS_SetConfig option has now been added (update in the WinCE thread) to set the read timeout (in milliseconds)...

Code: [Select]
#define BASS_CONFIG_NET_READTIMEOUT 37

The default has also been raised to 10000ms. Changes take immediate effect.

BiggieSmalls

  • Posts: 21
OK, the following BASS_SetConfig option has now been added (update in the WinCE thread) to set the read timeout (in milliseconds)...

Code: [Select]
#define BASS_CONFIG_NET_READTIMEOUT 37

The default has also been raised to 10000ms. Changes take immediate effect.

Thanks Ian! Works perfect.

BiggieSmalls

  • Posts: 21
Let met get back to this...

First, I assume this modification works for all plugins too, right? (I have the aac plugin loaded)

Second:
I have the timeout configuration set to 20000. (20 sec.). Sometimes while buffering slowly (I haven't tested this enough to see whether this only happens for the initial buffering (i.e. when calling BASS_StreamCreateURL or afterward, when the stream is stalled, or in both cases). the end stream sync is never called while a call to BASS_StreamGetFilePosition(hStream, BASS_FILEPOS_CONNECTED) tells me that the stream is no longer connected? Shouldn't my end stream sync be getting called?

I'm not sure if this has anything to do with the modification you did since it seemed to happen well within the 20 sec. timeout. But it could be that the server decided to drop the connection since my phone was buffering so slowly and that end stream was not getting called?

Thanks!

Edit:
I should add that my end stream callback gets called in some cases though, it's not like it isn't working at all. I just noticed that the problem of the callback not getting called happens more often when buffering very slowly. (e.g. a 32 kbps connection on my phone)
« Last Edit: 22 Sep '10 - 12:19 by BiggieSmalls »

Ian @ un4seen

  • Administrator
  • Posts: 20437
First, I assume this modification works for all plugins too, right? (I have the aac plugin loaded)

Yes, it would apply then as BASS is handling the downloading.

I have the timeout configuration set to 20000. (20 sec.). Sometimes while buffering slowly (I haven't tested this enough to see whether this only happens for the initial buffering (i.e. when calling BASS_StreamCreateURL or afterward, when the stream is stalled, or in both cases). the end stream sync is never called while a call to BASS_StreamGetFilePosition(hStream, BASS_FILEPOS_CONNECTED) tells me that the stream is no longer connected? Shouldn't my end stream sync be getting called?

Is the connection dropping while pre-buffering, before playback is started? If so, a BASS_SYNC_END sync wouldn't be triggered as that only happens when decoding/playback reaches the end. You could try using a BASS_SYNC_DOWNLOAD sync to be informed of when the connection is closed.

BiggieSmalls

  • Posts: 21
First, I assume this modification works for all plugins too, right? (I have the aac plugin loaded)

Yes, it would apply then as BASS is handling the downloading.

I have the timeout configuration set to 20000. (20 sec.). Sometimes while buffering slowly (I haven't tested this enough to see whether this only happens for the initial buffering (i.e. when calling BASS_StreamCreateURL or afterward, when the stream is stalled, or in both cases). the end stream sync is never called while a call to BASS_StreamGetFilePosition(hStream, BASS_FILEPOS_CONNECTED) tells me that the stream is no longer connected? Shouldn't my end stream sync be getting called?

Is the connection dropping while pre-buffering, before playback is started? If so, a BASS_SYNC_END sync wouldn't be triggered as that only happens when decoding/playback reaches the end. You could try using a BASS_SYNC_DOWNLOAD sync to be informed of when the connection is closed.

ah alright, I think it happens while prebuffering. I'll try the download sync.
Thanks