public ThreadQueue.TaskControl Release(SQLiteQuery qr, ReleaseCallback callback, object state)
	{
		return ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(ReleaseQuery), new WaitCallback(ReleaseQueryComplete), new ReleaseState(qr,callback,state));
	}
示例#2
0
 /// <summary>
 /// Makes a reference to the given memory block.
 /// </summary>
 /// <param name="data">A pointer to the memory.</param>
 /// <param name="size">The size of the memory block.</param>
 /// <param name="userData">Arbitrary user data passed to the release callback.</param>
 /// <param name="callback">A function that will be called when the data is ready to be released.</param>
 /// <returns>A new memory block referring to the given data.</returns>
 /// <remarks>
 /// The memory referred to by the returned memory block must not be modified
 /// or released until the callback fires.
 /// </remarks>
 public static MemoryBlock MakeRef(IntPtr data, int size, IntPtr userData, ReleaseCallback callback)
 {
     return(new MemoryBlock(NativeMethods.bgfx_make_ref_release(data, size, Marshal.GetFunctionPointerForDelegate(callback), userData)));
 }
		public ReleaseState(SQLiteQuery query, ReleaseCallback callback, object state){
			this.query = query; 
			this.callback = callback;
			this.state = state;
		}
示例#4
0
        private ResultCode OpenAudioOutImpl(ServiceCtx context, long sendPosition, long sendSize, long receivePosition, long receiveSize)
        {
            string deviceName = MemoryHelper.ReadAsciiString(
                context.Memory,
                sendPosition,
                sendSize);

            if (deviceName == string.Empty)
            {
                deviceName = DefaultAudioOutput;
            }

            if (deviceName != DefaultAudioOutput)
            {
                Logger.PrintWarning(LogClass.Audio, "Invalid device name!");

                return(ResultCode.DeviceNotFound);
            }

            byte[] deviceNameBuffer = Encoding.ASCII.GetBytes(deviceName + "\0");

            if ((ulong)deviceNameBuffer.Length <= (ulong)receiveSize)
            {
                context.Memory.WriteBytes(receivePosition, deviceNameBuffer);
            }
            else
            {
                Logger.PrintError(LogClass.ServiceAudio, $"Output buffer size {receiveSize} too small!");
            }

            int sampleRate = context.RequestData.ReadInt32();
            int channels   = context.RequestData.ReadInt32();

            if (sampleRate == 0)
            {
                sampleRate = DefaultSampleRate;
            }

            if (sampleRate != DefaultSampleRate)
            {
                Logger.PrintWarning(LogClass.Audio, "Invalid sample rate!");

                return(ResultCode.UnsupportedSampleRate);
            }

            channels = (ushort)channels;

            if (channels == 0)
            {
                channels = DefaultChannelsCount;
            }

            KEvent releaseEvent = new KEvent(context.Device.System);

            ReleaseCallback callback = () =>
            {
                releaseEvent.ReadableEvent.Signal();
            };

            IAalOutput audioOut = context.Device.AudioOut;

            int track = audioOut.OpenTrack(sampleRate, channels, callback);

            MakeObject(context, new IAudioOut(audioOut, releaseEvent, track));

            context.ResponseData.Write(sampleRate);
            context.ResponseData.Write(channels);
            context.ResponseData.Write((int)SampleFormat.PcmInt16);
            context.ResponseData.Write((int)PlaybackState.Stopped);

            return(ResultCode.Success);
        }
示例#5
0
        private long OpenAudioOutImpl(ServiceCtx Context, long SendPosition, long SendSize, long ReceivePosition, long ReceiveSize)
        {
            string DeviceName = AMemoryHelper.ReadAsciiString(
                Context.Memory,
                SendPosition,
                SendSize);

            if (DeviceName == string.Empty)
            {
                DeviceName = DefaultAudioOutput;
            }

            if (DeviceName != DefaultAudioOutput)
            {
                Context.Device.Log.PrintWarning(LogClass.Audio, "Invalid device name!");

                return(MakeError(ErrorModule.Audio, AudErr.DeviceNotFound));
            }

            byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName + "\0");

            if ((ulong)DeviceNameBuffer.Length <= (ulong)ReceiveSize)
            {
                Context.Memory.WriteBytes(ReceivePosition, DeviceNameBuffer);
            }
            else
            {
                Context.Device.Log.PrintError(LogClass.ServiceAudio, $"Output buffer size {ReceiveSize} too small!");
            }

            int SampleRate = Context.RequestData.ReadInt32();
            int Channels   = Context.RequestData.ReadInt32();

            if (SampleRate == 0)
            {
                SampleRate = DefaultSampleRate;
            }

            if (SampleRate != DefaultSampleRate)
            {
                Context.Device.Log.PrintWarning(LogClass.Audio, "Invalid sample rate!");

                return(MakeError(ErrorModule.Audio, AudErr.UnsupportedSampleRate));
            }

            Channels = (ushort)Channels;

            if (Channels == 0)
            {
                Channels = DefaultChannelsCount;
            }

            KEvent ReleaseEvent = new KEvent(Context.Device.System);

            ReleaseCallback Callback = () =>
            {
                ReleaseEvent.ReadableEvent.Signal();
            };

            IAalOutput AudioOut = Context.Device.AudioOut;

            int Track = AudioOut.OpenTrack(SampleRate, Channels, Callback);

            MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track));

            Context.ResponseData.Write(SampleRate);
            Context.ResponseData.Write(Channels);
            Context.ResponseData.Write((int)SampleFormat.PcmInt16);
            Context.ResponseData.Write((int)PlaybackState.Stopped);

            return(0);
        }
示例#6
0
        /// <summary>
        /// Creates a new audio track with the specified parameters
        /// </summary>
        /// <param name="sampleRate">The requested sample rate</param>
        /// <param name="hardwareChannels">The requested hardware channels</param>
        /// <param name="virtualChannels">The requested virtual channels</param>
        /// <param name="callback">A <see cref="ReleaseCallback" /> that represents the delegate to invoke when a buffer has been released by the audio track</param>
        /// <returns>The created track's Track ID</returns>
        public int OpenHardwareTrack(int sampleRate, int hardwareChannels, int virtualChannels, ReleaseCallback callback)
        {
            if (!_trackPool.TryGet(out SoundIoAudioTrack track))
            {
                return(-1);
            }

            // Open the output. We currently only support 16-bit signed LE
            track.Open(sampleRate, hardwareChannels, virtualChannels, callback, SoundIOFormat.S16LE);

            return(track.TrackID);
        }
示例#7
0
        public long OpenAudioOut(ServiceCtx Context)
        {
            IAalOutput AudioOut = Context.Ns.AudioOut;

            string DeviceName = AMemoryHelper.ReadAsciiString(
                Context.Memory,
                Context.Request.SendBuff[0].Position,
                Context.Request.SendBuff[0].Size);

            if (DeviceName == string.Empty)
            {
                DeviceName = DefaultAudioOutput;
            }

            long Position = Context.Request.ReceiveBuff[0].Position;
            long Size     = Context.Request.ReceiveBuff[0].Size;

            byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName + "\0");

            if ((ulong)DeviceNameBuffer.Length <= (ulong)Size)
            {
                AMemoryHelper.WriteBytes(Context.Memory, Position, DeviceNameBuffer);
            }
            else
            {
                Context.Ns.Log.PrintError(LogClass.ServiceAudio, $"Output buffer size {Size} too small!");
            }

            int SampleRate = Context.RequestData.ReadInt32();
            int Channels   = Context.RequestData.ReadInt32();

            Channels = (ushort)(Channels >> 16);

            if (SampleRate == 0)
            {
                SampleRate = 48000;
            }

            if (Channels < 1 || Channels > 2)
            {
                Channels = 2;
            }

            KEvent ReleaseEvent = new KEvent();

            ReleaseCallback Callback = () =>
            {
                ReleaseEvent.WaitEvent.Set();
            };

            int Track = AudioOut.OpenTrack(SampleRate, Channels, Callback, out AudioFormat Format);

            MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track));

            Context.ResponseData.Write(SampleRate);
            Context.ResponseData.Write(Channels);
            Context.ResponseData.Write((int)Format);
            Context.ResponseData.Write((int)PlaybackState.Stopped);

            return(0);
        }
示例#8
0
        public OpenALAudioTrack(int sampleRate, ALFormat format, int hardwareChannels, int virtualChannels, ReleaseCallback callback)
        {
            SampleRate = sampleRate;
            Format     = format;
            State      = PlaybackState.Stopped;
            SourceId   = AL.GenSource();

            HardwareChannels = hardwareChannels;
            VirtualChannels  = virtualChannels;

            _callback = callback;

            _buffers = new ConcurrentDictionary <long, int>();

            _queuedTagsQueue   = new Queue <long>();
            _releasedTagsQueue = new Queue <long>();
        }
示例#9
0
        public int OpenHardwareTrack(int sampleRate, int hardwareChannels, int virtualChannels, ReleaseCallback callback)
        {
            if (!_trackIds.TryDequeue(out int trackId))
            {
                trackId = ++_lastTrackId;
            }

            _releaseCallbacks[trackId] = callback;

            return(trackId);
        }
示例#10
0
 public void Release(SQLiteQuery qr, ReleaseCallback callback, object state)
 {
     ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(ReleaseQuery), new WaitCallback(ReleaseQueryComplete), new ReleaseState(qr, callback, state));
 }
示例#11
0
 public ReleaseState(SQLiteQuery query, ReleaseCallback callback, object state)
 {
     this.query    = query;
     this.callback = callback;
     this.state    = state;
 }
示例#12
0
 public ThreadQueue.TaskControl Release(SQLiteQuery qr, ReleaseCallback callback, object state)
 {
     return(ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(ReleaseQuery), new WaitCallback(ReleaseQueryComplete), new ReleaseState(qr, callback, state)));
 }
示例#13
0
 public int OpenTrack(int sampleRate, int channels, ReleaseCallback callback) => 1;
示例#14
0
	public void Release(SQLiteQuery qr, ReleaseCallback callback, object state)
	{
		ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(ReleaseQuery), new WaitCallback(ReleaseQueryComplete), new ReleaseState(qr,callback,state));
	}