Example #1
0
        public void PushImageAsync(ImageBufferNative buf)
        {
            if (disposed)
            {
                return;
            }

            if (!imageEncodeThreadStarted)
            {
                voiceClient.frontend.LogInfo(LogPrefix + ": Starting image encode thread");
#if NETFX_CORE
                ThreadPool.RunAsync((x) =>
                {
                    PushImageAsyncThread();
                });
#else
                var t = new Thread(PushImageAsyncThread);
                t.Name = LogPrefix + " image encode";
                t.Start();
#endif
                imageEncodeThreadStarted = true;
            }

            lock (pushImageQueue)
            {
                pushImageQueue.Enqueue(buf);
            }
            pushImageQueueReady.Set();
        }
Example #2
0
        private void PushImageAsyncThread()
        {
            try
            {
                while (!exitThread)
                {
                    pushImageQueueReady.WaitOne(); // Wait until data is pushed to the queue or Dispose signals.

                    while (true)                   // Dequeue and process while the queue is not empty.
                    {
                        if (exitThread)
                        {
                            break;             // early exit to save few resources
                        }
                        ImageBufferNative b = null;
                        lock (pushImageQueue)
                        {
                            if (pushImageQueue.Count > 0)
                            {
                                b = pushImageQueue.Dequeue();
                            }
                        }

                        if (b != null)
                        {
                            PushImage(b.Planes, b.Info.Width, b.Info.Height, b.Info.Stride, b.Info.Format, b.Info.Rotation, b.Info.Flip);
                            b.Release();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                voiceClient.frontend.LogError(LogPrefix + ": Exception in encode thread: " + e);
                throw e;
            }
            finally
            {
                lock (disposeLock)
                {
                    disposed = true;
                }
                lock (pushImageQueue)
                {
                    while (pushImageQueue.Count > 0)
                    {
                        pushImageQueue.Dequeue().Dispose();
                    }
                }

#if NETFX_CORE
                pushImageQueueReady.Dispose();
#else
                pushImageQueueReady.Close();
#endif

                voiceClient.frontend.LogInfo(LogPrefix + ": Exiting image encode thread");
            }
        }