Author Topic: How to clear BASS_StreamCreateURL's stream buffer to play fresh data?  (Read 240 times)

XDMiner5

  • Posts: 21
Im wondering if I can clear the (BASS_StreamCreateURL's) buffer.
So I can play newly downloaded data from a webstream.

Currently, when the (BASS_StreamCreateURL's) buffer isn't sending data to another buffer.
The buffer keeps the data from where it left off.
And when it continue's sending data to another buffer. it continues playing the old data first.
But i want it to start playing with new incoming data instead the old data.

Ian @ un4seen

  • Administrator
  • Posts: 21741
One way you could clear the download buffer is to seek past it by using BASS_ChannelSetPosition with the BASS_POS_DECODETO flag. For example:

Code: [Select]
BASS_ChannelSetPosition(stream, -1, BASS_POS_BYTE | BASS_POS_DECODETO);

That will skip as much data as possible, ie. clear out the download buffer.

XDMiner5

  • Posts: 21
Its working. but sometimes after executing:
Code: [Select]
Bass.BASS_ChannelSetPosition(_streamID, -1, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODETO);It is not downloading more data then what it's playing. so there appears to be some silence at the beginning. after some time it restored itself.
So, can I set the channels position a little less from the end then entirely move it to the end?

I've tried:
Code: [Select]
                    long pos = Bass.BASS_ChannelGetPosition(_streamID, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODE);
                    int netBuffer = Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_NET_BUFFER);
                    netBuffer += (netBuffer / 100) * Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_NET_PREBUF);
                    pos -= Bass.BASS_ChannelSeconds2Bytes(_streamID, netBuffer / 1000);
                    bool b = Bass.BASS_ChannelSetPosition(_streamID, pos, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODETO);
But I think this isn't working.
Any suggestions?

XDMiner5

  • Posts: 21
With a bit more thinkering.

Code: [Select]
                    Bass.BASS_ChannelSetPosition(_streamID, -1, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODETO);
                    long pos = Bass.BASS_ChannelGetPosition(_streamID, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODE);
                    int netBuffer = Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_NET_BUFFER);
                    netBuffer = (netBuffer / 100) * Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_NET_PREBUF);
                    pos -= Bass.BASS_ChannelSeconds2Bytes(_streamID, netBuffer / 1000);
                    Bass.BASS_ChannelSetPosition(_streamID, pos, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODETO);

This seems to work. but this doesn't look that efficiŽnt.

Is there a better way to go to the end of the buffer but keep the amount of pre-buffered data like how the BASS_StreamCreateURL's stream started?

Ian @ un4seen

  • Administrator
  • Posts: 21741
It isn't possible to go backwards when using the BASS_POS_DECODETO flag, so I don't think that last code is ultimately any different from just calling BASS_ChannelSetPosition with pos=-1, as the 2nd BASS_ChannelSetPosition call will be failing.

If you want to keep some data buffered, you could try repeatedly calling BASS_ChannelSetPosition to seek a small amount until the download buffer reaches the level that you want. Something like this:

Code: [Select]
while (1) {
int buffered = BASS_StreamGetFilePosition(stream, BASS_FILEPOS_BUFFER); // get download buffer level
if (buffered <= wanted) break;
QWORD pos = BASS_ChannelGetPosition(stream, BASS_POS_BYTE | BASS_POS_DECODE); // get current position
if (!BASS_ChannelSetPosition(stream, pos + 50000, BASS_POS_BYTE | BASS_POS_DECODETO)) // seek 50000 bytes ahead
break; // failed
}

The stream should be stopped/paused while doing that.