BASS.NET API for the Un4seen BASS Audio Library

ENCODENOTIFYPROC Delegate

BASS.NET API for the Un4seen BASS Audio Library
User defined callback function to receive notifications on an encoder's status.

Namespace:  Un4seen.Bass.AddOn.Enc
Assembly:  Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
Syntax

public delegate void ENCODENOTIFYPROC(
	int handle,
	BASSEncodeNotify status,
	IntPtr user
)

Parameters

handle
Type: SystemInt32
The encoder that the notification is from (as returned by BASS_Encode_SetNotify(Int32, ENCODENOTIFYPROC, IntPtr)).
status
Type: Un4seen.Bass.AddOn.EncBASSEncodeNotify
The encoder's status, one of the following (see BASSEncodeNotify):

BASS_ENCODE_NOTIFY_ENCODER : The encoder died.

BASS_ENCODE_NOTIFY_CAST : Cast server connection died.

BASS_ENCODE_NOTIFY_CAST_TIMEOUT : Cast data sending timeout. The connection is not dead at this point, it may just be a temporary problem.

BASS_ENCODE_NOTIFY_QUEUE_FULL : The queue length has reached its limit (or out of memory) and data has been dropped. The total amount of dropped data is available from BASS_Encode_GetCount(Int32, BASSEncodeCount).

BASS_ENCODE_NOTIFY_FREE : The encoder has been freed.

user
Type: SystemIntPtr
The user instance data given when BASS_Encode_SetNotify(Int32, ENCODENOTIFYPROC, IntPtr) was called.
Remarks

When setting a notification callback on a channel, it only applies to the encoders that are currently set on the channel. Subsequent encoders will not automatically have the notification callback set on them, this function will have to be called again to set them up.

An encoder can only have one notification callback set. Subsequent calls of this function can be used to change the callback function, or disable notifications (proc = ).

If the encoder is already dead when setting up a notification callback, the callback will be triggered immediately.

It is safe to call BASS_Encode_Stop(Int32) to free an encoder from within a notification callback.

Examples

Using the callback with a recording caster:
private ENCODENOTIFYPROC _myEndoderNotify;
private int _encoder = 0;
private int _recChan = 0;
private bool _autoreconnect = true;
...
_recChan = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, 20, null, IntPtr.Zero);
Start();
...
private void Start()
{
  // start an encoder
  _encoder = BassEnc.BASS_Encode_Start(_recChan, "lame -r -x -s 44100 -b 128 -", 
                     BASSEncode.BASS_ENCODE_NOHEAD, null, IntPtr.Zero);
  _myEndoderNotify = new ENCODENOTIFYPROC(EncoderNotify);
  // start a caster
  BassEnc.BASS_Encode_CastInit(_encoder, "server.com:8000", "password", 
          BassEnc.BASS_ENCODE_TYPE_MP3, "name", "url", "genre", null, null, 128, true);
  // notify on dead encoder/connection 
  BassEnc.BASS_Encode_SetNotify(_encoder, _myEndoderNotify, IntPtr.Zero);
}

private void Stop()
{
  if (_encoder != 0)
  {
    BassEnc.BASS_Encode_SetNotify(_encoder, null, IntPtr.Zero);
    BassEnc.BASS_Encode_Stop(_encoder);
    _encoder = 0;
  }
}

private void EncoderNotify(int handle, BASSEncodeNotify status, IntPtr user)
{
  // encoder/connection lost
  Stop();
  if (_autoreconnect)
  {
    // do auto-reconnect...
    Thread.Sleep(1000); // wait a sec
    Start();
  } 
}
See Also

Reference