Esempio n. 1
0
        public bool SendAudioFrame(int friendNumber, ToxAvAudioFrame frame, out ToxAvErrorSendFrame error)
        {
            ThrowIfDisposed();

            error = ToxAvErrorSendFrame.Ok;
            return(ToxAvFunctions.AudioSendFrame(_toxAv, ToxTools.Map(friendNumber), frame.Data, (uint)(frame.Data.Length / frame.Channels), (byte)frame.Channels, (uint)frame.SamplingRate, ref error));
        }
Esempio n. 2
0
        /// <summary>
        /// Joins an audio groupchat.
        /// </summary>
        /// <param name="friendNumber"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int JoinAvGroupchat(int friendNumber, byte[] data)
        {
            ThrowIfDisposed();

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            ToxAvDelegates.GroupAudioReceiveCallback callback = (IntPtr tox, int groupNumber, int peerNumber, IntPtr frame, uint sampleCount, byte channels, uint sampleRate, IntPtr userData) =>
            {
                if (OnReceivedGroupAudio != null)
                {
                    short[] samples = new short[sampleCount * channels];
                    Marshal.Copy(frame, samples, 0, samples.Length);

                    OnReceivedGroupAudio(this, new ToxAvEventArgs.GroupAudioDataEventArgs(groupNumber, peerNumber, samples, (int)channels, (int)sampleRate));
                }
            };

            int result = ToxAvFunctions.JoinAvGroupchat(_tox, friendNumber, data, (ushort)data.Length, callback, IntPtr.Zero);

            if (result != -1)
            {
                _groupAudioHandlers.Add(callback);
            }

            return(result);
        }
Esempio n. 3
0
        public bool SetVideoBitrate(int friendNumber, int bitrate, out ToxAvErrorSetBitrate error)
        {
            ThrowIfDisposed();

            error = ToxAvErrorSetBitrate.Ok;
            return(ToxAvFunctions.BitrateSet(_toxAv, ToxTools.Map(friendNumber), -1, bitrate, ref error));
        }
Esempio n. 4
0
        public bool SendVideoFrame(int friendNumber, ToxAvVideoFrame frame, out ToxAvErrorSendFrame error)
        {
            ThrowIfDisposed();

            error = ToxAvErrorSendFrame.Ok;
            return(ToxAvFunctions.VideoSendFrame(_toxAv, ToxTools.Map(friendNumber), (ushort)frame.Width, (ushort)frame.Height, frame.Y, frame.U, frame.V, ref error));
        }
Esempio n. 5
0
        public bool SendControl(int friendNumber, ToxAvCallControl control, out ToxAvErrorCallControl error)
        {
            ThrowIfDisposed();

            error = ToxAvErrorCallControl.Ok;
            return(ToxAvFunctions.CallControl(_toxAv, ToxTools.Map(friendNumber), control, ref error));
        }
Esempio n. 6
0
        public bool Answer(int friendNumber, int audioBitrate, int videoBitrate, out ToxAvErrorAnswer error)
        {
            ThrowIfDisposed();

            error = ToxAvErrorAnswer.Ok;
            return(ToxAvFunctions.Answer(_toxAv, ToxTools.Map(friendNumber), (uint)audioBitrate, (uint)videoBitrate, ref error));
        }
Esempio n. 7
0
        /// <summary>
        /// Initialises a new instance of toxav.
        /// </summary>
        /// <param name="tox"></param>
        internal ToxAv(ToxHandle tox)
        {
            _tox = tox;

            var error = ToxAvErrorNew.Ok;

            _toxAv = ToxAvFunctions.New(tox, ref error);

            if (_toxAv == null || _toxAv.IsInvalid || error != ToxAvErrorNew.Ok)
            {
                throw new Exception("Could not create a new instance of toxav.");
            }

            //register audio/video callbacks early on
            //due to toxav being silly, we can't start calls without registering those beforehand
            RegisterAudioVideoCallbacks();
        }
Esempio n. 8
0
        private void RegisterAudioVideoCallbacks()
        {
            _onReceiveAudioFrameCallback = (IntPtr toxAv, uint friendNumber, IntPtr pcm, uint sampleCount, byte channels, uint samplingRate, IntPtr userData) =>
            {
                if (OnAudioFrameReceived != null)
                {
                    OnAudioFrameReceived(this, new ToxAvEventArgs.AudioFrameEventArgs(ToxTools.Map(friendNumber), new ToxAvAudioFrame(pcm, sampleCount, samplingRate, channels)));
                }
            };

            _onReceiveVideoFrameCallback = (IntPtr toxAv, uint friendNumber, ushort width, ushort height, IntPtr y, IntPtr u, IntPtr v, int yStride, int uStride, int vStride, IntPtr userData) =>
            {
                if (OnVideoFrameReceived != null)
                {
                    OnVideoFrameReceived(this, new ToxAvEventArgs.VideoFrameEventArgs(ToxTools.Map(friendNumber), new ToxAvVideoFrame(width, height, y, u, v, yStride, uStride, vStride)));
                }
            };

            ToxAvFunctions.RegisterAudioReceiveFrameCallback(_toxAv, _onReceiveAudioFrameCallback, IntPtr.Zero);
            ToxAvFunctions.RegisterVideoReceiveFrameCallback(_toxAv, _onReceiveVideoFrameCallback, IntPtr.Zero);
        }
Esempio n. 9
0
 /// <summary>
 /// Checks whether or not this version is compatible with the version of ToxAv that we're using.
 /// </summary>
 /// <returns>True if this version is compatible, false if it's not.</returns>
 public bool IsCompatible()
 {
     return(ToxAvFunctions.VersionIsCompatible((uint)Major, (uint)Minor, (uint)Patch));
 }
Esempio n. 10
0
        /// <summary>
        /// Sends an audio frame to a group.
        /// </summary>
        /// <param name="groupNumber"></param>
        /// <param name="pcm"></param>
        /// <param name="perframe"></param>
        /// <param name="channels"></param>
        /// <param name="sampleRate"></param>
        /// <returns></returns>
        public bool GroupSendAudio(int groupNumber, short[] pcm, int perframe, int channels, int sampleRate)
        {
            ThrowIfDisposed();

            return(ToxAvFunctions.GroupSendAudio(_tox, groupNumber, pcm, (uint)perframe, (byte)channels, (uint)sampleRate) == 0);
        }
Esempio n. 11
0
 private int DoIterate()
 {
     ToxAvFunctions.Iterate(_toxAv);
     return((int)ToxAvFunctions.IterationInterval(_toxAv));
 }
Esempio n. 12
0
 /// <summary>
 /// Executes toxav_kill to free the tox handle.
 /// </summary>
 /// <returns></returns>
 protected override bool ReleaseHandle()
 {
     ToxAvFunctions.Kill(handle);
     return(true);
 }