Exemplo n.º 1
0
        public IXAudio2VoiceCallbackWrapper(IXAudio2VoiceCallback callback)
        {
            if (callback == null)
            {
                return;
            }

            _callback = callback;
            // Store callbacks to prevent them from being garbage collected
            _startCallback       = (_, bytesRequired) => _callback.OnVoiceProcessingPassStart(bytesRequired);
            _endCallback         = _ => _callback.OnVoiceProcessingPassEnd();
            _streamEndCallback   = _ => _callback.OnStreamEnd();
            _bufferStartCallback = (_, context) => _callback.OnBufferStart(context);
            _bufferEndCallback   = (_, context) => _callback.OnBufferEnd(context);
            _loopEndCallback     = (_, context) => _callback.OnLoopEnd(context);
            _voiceErrorCallback  = (_, context, error) => _callback.OnVoiceError(context, error);

            // Allocate memory for the C++ interface
            _nativePointer = Marshal.AllocHGlobal(IntPtr.Size * 8); // 7 methods + vtbl

            // Write pointer to vtbl
            Marshal.WriteIntPtr(_nativePointer, IntPtr.Add(_nativePointer, IntPtr.Size));

            // Write the functions to the vtable
            WriteFunctionPointer(1, _startCallback);
            WriteFunctionPointer(2, _endCallback);
            WriteFunctionPointer(3, _streamEndCallback);
            WriteFunctionPointer(4, _bufferStartCallback);
            WriteFunctionPointer(5, _bufferEndCallback);
            WriteFunctionPointer(6, _loopEndCallback);
            WriteFunctionPointer(7, _voiceErrorCallback);
        }
Exemplo n.º 2
0
        private void EndTag(byte[] buf, int offset, ContentToken ct, TOK tok)
        {
            this.m_Depth--;
            this.m_ns.PopScope();

            if (this.current == null)
            {            // end of doc
                OnStreamEnd?.Invoke(this, this.m_root);
                //				FireOnDocumentEnd();
                return;
            }

            string name = null;

            if ((tok == TOK.EMPTY_ELEMENT_WITH_ATTS) ||
                (tok == TOK.EMPTY_ELEMENT_NO_ATTS))
            {
                name = utf.GetString(buf,
                                     offset + this.m_enc.MinBytesPerChar,
                                     ct.NameEnd - offset -
                                     this.m_enc.MinBytesPerChar);
            }
            else
            {
                name = utf.GetString(buf,
                                     offset + this.m_enc.MinBytesPerChar * 2,
                                     ct.NameEnd - offset -
                                     this.m_enc.MinBytesPerChar * 2);
            }


            //			if (current.Name != name)
            //				throw new Exception("Invalid end tag: " + name +
            //					" != " + current.Name);

            var parent = (Element)this.current.Parent;

            if (parent == null)
            {
                this.DoRaiseOnStreamElement(this.current);
                //if (OnStreamElement!=null)
                //    OnStreamElement(this, current);
                //FireOnElement(current);
            }
            this.current = parent;
        }
Exemplo n.º 3
0
        private void EndTag()
        {
            _mDepth--;
            _mNamespaceStack.Pop();

            if (_current == null)
            {
// end of doc
                OnStreamEnd?.Invoke(this, _mRoot);
//				FireOnDocumentEnd();
                return;
            }

            /*
             *          string name = null;
             *
             *          if ((tok == TOK.EMPTY_ELEMENT_WITH_ATTS) ||
             *                  (tok == TOK.EMPTY_ELEMENT_NO_ATTS))
             *                  name = utf.GetString(buf,
             *                          offset + m_enc.MinBytesPerChar,
             *                          ct.NameEnd - offset -
             *                          m_enc.MinBytesPerChar);
             *          else
             *                  name = utf.GetString(buf,
             *                          offset + m_enc.MinBytesPerChar*2,
             *                          ct.NameEnd - offset -
             *                          m_enc.MinBytesPerChar*2);
             *  //*/

//			if (current.Name != name)
//				throw new Exception("Invalid end tag: " + name +
//					" != " + current.Name);

            var parent = (Element)_current.Parent;

            if (parent == null)
            {
                DoRaiseOnStreamElement(_current);
                //if (OnStreamElement!=null)
                //    OnStreamElement(this, current);
                //FireOnElement(current);
            }
            _current = parent;
        }
Exemplo n.º 4
0
        private void EndTag(byte[] buf, int offset, ContentToken ct, Tokens tok)
        {
            // TODO we don't validate Xml right now
            // could check here if end tag name equals the start tag name
            depth--;
            nsStack.Pop();

            if (current == null)
            {
                OnStreamEnd?.Invoke();
                return;
            }

            var parent = current.Parent as XmppXElement;

            if (parent == null)
            {
                OnStreamElement?.Invoke(current);
            }
            current = parent;
        }
Exemplo n.º 5
0
 public void StreamEnd()
 {
     OnStreamEnd?.Invoke();
 }