Пример #1
0
 /** @} */
 /** @addtogroup desktopshare
  * @{ */
 /**
  * @brief Transmit a desktop window (bitmap) to users in the same
  * channel.
  *
  * When TeamTalk.SendDesktopWindow() is called the first time a new
  * desktop session will be started. To update the current desktop
  * session call TeamTalk.SendDesktopWindow() again once the previous
  * desktop transmission has finished. Tracking progress of the
  * current desktop transmission is done by checking for the
  * TeamTalk.OnDesktopTransferUpdate() event. While the desktop
  * transmission is active the flag #ClientFlag ::CLIENT_TX_DESKTOP will be set
  * on the local client instance.
  *
  * If the desktop window (bitmap) changes size (width/height) or
  * format a new desktop session will be started. Also if the user
  * changes channel a new desktop session will be started. Check @c
  * nSessionID of #BearWare.DesktopWindow to see if a new desktop session is
  * started or the TeamTalk.OnUserDesktopWindow() event.
  *
  * Remote users will get the TeamTalk.OnUserDesktopWindow() event
  * and can call TeamTalk.AcquireUserDesktopWindow() to retrieve the desktop
  * window.
  *
  * User rights required:
  * - ::USERRIGHT_TRANSMIT_DESKTOP
  *
  * @param lpDesktopWindow Properties of the bitmap. Set the @c nSessionID
  * property to 0.
  * @param nConvertBmpFormat Before transmission convert the bitmap to this
  * format.
  * @return TRUE if desktop window is queued for transmission. FALSE if
  * @c nBitmapSize is invalid or if a desktop transmission is already
  * active.
  * @return -1 on error. 0 if bitmap has no changes. Greater than 0 on
  * success.
  * @see TeamTalk.CloseDesktopWindow()
  * @see TeamTalk.SendDesktopCursorPosition() */
 public int SendDesktopWindow(DesktopWindow lpDesktopWindow,
     BitmapFormat nConvertBmpFormat)
 {
     return TTDLL.TT_SendDesktopWindow(m_ttInst, ref lpDesktopWindow, nConvertBmpFormat);
 }
Пример #2
0
 /** @brief Release memory allocated by the #BearWare.DesktopWindow.
  * @see TeamTalk.AcquireUserDesktopWindow() */
 public bool ReleaseUserDesktopWindow(DesktopWindow lpDesktopWindow)
 {
     IntPtr ptr;
     if (desktopwindows.TryGetValue(lpDesktopWindow.frameBuffer, out ptr))
     {
         desktopwindows.Remove(lpDesktopWindow.frameBuffer);
         return TTDLL.TT_ReleaseUserDesktopWindow(m_ttInst, ptr);
     }
     return false;
 }
Пример #3
0
        public void TestDesktopShare()
        {
            const string USERNAME = "******", PASSWORD = "******"; string NICKNAME = "TeamTalk.NET - " + GetCurrentMethod();
            const UserRight USERRIGHTS = UserRight.USERRIGHT_TRANSMIT_DESKTOP | UserRight.USERRIGHT_MULTI_LOGIN;
            MakeUserAccount(GetCurrentMethod(), USERNAME, PASSWORD, USERRIGHTS);
            TeamTalk ttclient = NewClientInstance();

            Connect(ttclient);
            Login(ttclient, NICKNAME, USERNAME, PASSWORD);
            JoinRoot(ttclient);

            int BMP_HEIGHT = 168, BMP_WIDTH = 120;
            PixelFormat pixelformat = PixelFormat.Format32bppRgb;
            Bitmap bmp = new Bitmap(BMP_WIDTH, BMP_HEIGHT, pixelformat);
            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
            BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
                                              bmp.PixelFormat);
            IntPtr ptr = bmpData.Scan0;

            DesktopWindow wnd = new DesktopWindow();
            wnd.nBytesPerLine = bmpData.Stride;
            wnd.nHeight = bmp.Height;
            wnd.nWidth = bmp.Width;
            wnd.nProtocol = DesktopProtocol.DESKTOPPROTOCOL_ZLIB_1;
            wnd.bmpFormat = BitmapFormat.BMP_RGB32;
            wnd.frameBuffer = ptr;
            wnd.nFrameBufferSize = bmpData.Stride * bmpData.Height;

            int tx = ttclient.SendDesktopWindow(wnd, BitmapFormat.BMP_RGB32);
            Assert.IsTrue(tx > 0, "tx bitmap");
            bmp.UnlockBits(bmpData);

            TTMessage msg = new TTMessage();
            Assert.IsTrue(WaitForEvent(ttclient, ClientEvent.CLIENTEVENT_DESKTOPWINDOW_TRANSFER, 2000, ref msg), "tx bmp started");
            int remain = (int)msg.DataToObject();
            while (remain > 0)
            {
                Assert.IsTrue(WaitForEvent(ttclient, ClientEvent.CLIENTEVENT_DESKTOPWINDOW_TRANSFER, 2000, ref msg), "tx bmp started");
                remain = (int)msg.DataToObject();
            }

            Assert.IsFalse(ttclient.Flags.HasFlag(ClientFlag.CLIENT_TX_DESKTOP), "tx desktop done");
            Assert.IsTrue(ttclient.Flags.HasFlag(ClientFlag.CLIENT_DESKTOP_ACTIVE), "desktop active");

            TeamTalk ttclient2 = NewClientInstance();
            InitSound(ttclient2);
            Connect(ttclient2);
            Login(ttclient2, NICKNAME, USERNAME, PASSWORD);
            JoinRoot(ttclient2);

            Assert.IsTrue(WaitForEvent(ttclient2, ClientEvent.CLIENTEVENT_USER_DESKTOPWINDOW, 5000, ref msg), "receive desktop window");

            Assert.AreEqual(msg.nSource, ttclient.GetMyUserID(), "desktop window from same source");

            DesktopWindow wnd2 = ttclient2.AcquireUserDesktopWindow(msg.nSource);
            Assert.IsTrue(wnd2.nSessionID>0, "get wnd info");
            Assert.AreEqual(wnd.bmpFormat, wnd2.bmpFormat, "bmp fmt");
            Assert.AreEqual(wnd.nBytesPerLine, wnd2.nBytesPerLine, "bmp line");
            Assert.AreEqual(wnd.nHeight, wnd2.nHeight, "height");
            Assert.AreEqual(wnd.nWidth, wnd2.nWidth, "width");
            Bitmap bmp2 = new Bitmap(BMP_WIDTH, BMP_HEIGHT, wnd2.nBytesPerLine, pixelformat, wnd2.frameBuffer);
            for (int x = 0; x < BMP_WIDTH; x++)
            {
                for (int y = 0; y < BMP_HEIGHT; y++)
                    Assert.AreEqual(bmp.GetPixel(x, y), bmp2.GetPixel(x, y), "pixels match");
            }

            Assert.IsTrue(ttclient2.ReleaseUserDesktopWindow(wnd2), "release desk wnd");
            Assert.IsTrue(ttclient.CloseDesktopWindow(), "close desk");

            Assert.IsTrue(WaitForEvent(ttclient2, ClientEvent.CLIENTEVENT_USER_DESKTOPWINDOW, 3000, ref msg), "get close msg");
            Assert.AreEqual(msg.nSource, ttclient.GetMyUserID(), "desktop window from same source");
            Assert.AreEqual(0, (int)msg.DataToObject(), "desktop session is 0");


            tx = ttclient.SendDesktopWindow(wnd, BitmapFormat.BMP_RGB32);
            Assert.IsTrue(tx > 0, "tx bitmap");

            Assert.IsTrue(WaitForEvent(ttclient, ClientEvent.CLIENTEVENT_DESKTOPWINDOW_TRANSFER, 2000, ref msg), "tx bmp started");
            remain = (int)msg.DataToObject();
            while (remain > 0)
            {
                Assert.IsTrue(WaitForEvent(ttclient, ClientEvent.CLIENTEVENT_DESKTOPWINDOW_TRANSFER, 2000, ref msg), "tx bmp started");
                remain = (int)msg.DataToObject();
            }

            Assert.IsFalse(ttclient.Flags.HasFlag(ClientFlag.CLIENT_TX_DESKTOP), "tx desktop done");
            Assert.IsTrue(ttclient.Flags.HasFlag(ClientFlag.CLIENT_DESKTOP_ACTIVE), "desktop active");

            Assert.IsTrue(WaitForEvent(ttclient2, ClientEvent.CLIENTEVENT_USER_DESKTOPWINDOW, 5000, ref msg), "receive desktop window");

            wnd2 = ttclient2.AcquireUserDesktopWindowEx(msg.nSource, BitmapFormat.BMP_RGB16_555);
            Assert.AreNotEqual(wnd.nFrameBufferSize, wnd2.nFrameBufferSize);
            Assert.IsTrue(wnd2.nSessionID > 0, "get wnd info");
            Assert.AreEqual(wnd.nHeight, wnd2.nHeight, "height");
            Assert.AreEqual(wnd.nWidth, wnd2.nWidth, "width");

            Assert.IsTrue(ttclient2.ReleaseUserDesktopWindow(wnd2), "release desk wnd");

        }
Пример #4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            deskwnd = ttclient.AcquireUserDesktopWindow(userid);
            if (deskwnd.nSessionID <= 0)
            {
                this.Close();
                return;
            }

            if (ClientSize.Height != deskwnd.nHeight || ClientSize.Width != deskwnd.nWidth)
            {
                ClientSize = new Size(deskwnd.nWidth, deskwnd.nHeight);
                //int width_diff = deskwnd.nWidth - ClientSize.Width;
                //int height_diff = deskwnd.nHeight - ClientSize.Height;
                //this.Size.Width += width_diff;
                //this.Size.Height += height_diff;
            }

            if (bmp != null)
                bmp.Dispose();
            bmp = null;

            switch(deskwnd.bmpFormat)
            {
                case BitmapFormat.BMP_RGB8_PALETTE:
                    bmp = new Bitmap(deskwnd.nWidth, deskwnd.nHeight, deskwnd.nBytesPerLine,
                                     PixelFormat.Format8bppIndexed, deskwnd.frameBuffer);
                    ColorPalette pal = bmp.Palette;
                    for (int i = 0; i < 256; i++)
                        pal.Entries[i] = TeamTalk.Palette_GetColorTable(BitmapFormat.BMP_RGB8_PALETTE, i);
                    bmp.Palette = pal;
                    break;
                case BitmapFormat.BMP_RGB16_555:
                    bmp = new Bitmap(deskwnd.nWidth, deskwnd.nHeight,
                                     deskwnd.nBytesPerLine, PixelFormat.Format16bppRgb555,
                                     deskwnd.frameBuffer);
                    break;
                case BitmapFormat.BMP_RGB24 :
                    bmp = new Bitmap(deskwnd.nWidth, deskwnd.nHeight, deskwnd.nBytesPerLine,
                                     PixelFormat.Format24bppRgb, deskwnd.frameBuffer);
                    break;
                case BitmapFormat.BMP_RGB32:
                    bmp = new Bitmap(deskwnd.nWidth, deskwnd.nHeight, deskwnd.nBytesPerLine,
                                     PixelFormat.Format32bppRgb, deskwnd.frameBuffer);
                    break;
            }

            Invalidate();
        }
Пример #5
0
        public void TestDesktopShareLeak()
        {
            const string USERNAME = "******", PASSWORD = "******"; string NICKNAME = "TeamTalk.NET - " + GetCurrentMethod();
            const UserRight USERRIGHTS = UserRight.USERRIGHT_TRANSMIT_DESKTOP | UserRight.USERRIGHT_MULTI_LOGIN;
            MakeUserAccount(GetCurrentMethod(), USERNAME, PASSWORD, USERRIGHTS);
            TeamTalk ttclient = NewClientInstance();

            Connect(ttclient);
            Login(ttclient, NICKNAME, USERNAME, PASSWORD);
            JoinRoot(ttclient);

            int BMP_HEIGHT = 168, BMP_WIDTH = 120;
            PixelFormat pixelformat = PixelFormat.Format32bppRgb;
            Bitmap bmp = new Bitmap(BMP_WIDTH, BMP_HEIGHT, pixelformat);
            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

            int again = 50;
            while (again-- > 0)
            {
                for (int x = 0; x < BMP_WIDTH; x++)
                {
                    for (int y = 0; y < BMP_HEIGHT; y++)
                    {
                        if (again % 2 == 0)
                            bmp.SetPixel(x, y, Color.Beige);
                        else
                            bmp.SetPixel(x, y, Color.Blue);
                    }
                }

                BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
                                  bmp.PixelFormat);
                IntPtr ptr = bmpData.Scan0;

                DesktopWindow wnd = new DesktopWindow();
                wnd.nBytesPerLine = bmpData.Stride;
                wnd.nHeight = bmp.Height;
                wnd.nWidth = bmp.Width;
                wnd.nProtocol = DesktopProtocol.DESKTOPPROTOCOL_ZLIB_1;
                wnd.bmpFormat = BitmapFormat.BMP_RGB32;
                wnd.frameBuffer = ptr;
                wnd.nFrameBufferSize = bmpData.Stride * bmpData.Height;

                int tx = ttclient.SendDesktopWindow(wnd, BitmapFormat.BMP_RGB32);
                Assert.IsTrue(tx > 0, "tx bitmap");
                bmp.UnlockBits(bmpData);

                TTMessage msg = new TTMessage();
                Assert.IsTrue(WaitForEvent(ttclient, ClientEvent.CLIENTEVENT_DESKTOPWINDOW_TRANSFER, 2000, ref msg), "tx bmp started");
                int remain = (int)msg.DataToObject();
                while (remain > 0)
                {
                    Assert.IsTrue(WaitForEvent(ttclient, ClientEvent.CLIENTEVENT_DESKTOPWINDOW_TRANSFER, 2000, ref msg), "tx bmp started");
                    remain = (int)msg.DataToObject();
                }

                Assert.IsFalse(ttclient.Flags.HasFlag(ClientFlag.CLIENT_TX_DESKTOP), "Desktop tx ended");
            }
        }