Beispiel #1
0
 public void OnGetServerVersionAndMetadataComplete(Object result, AsyncRequestObject aro)
 {
     if (result is Exception)
     {
     }
     else
     {
         m_serverVersion = VIServices.Deserialize <string>(result);
         GetServerMetadata();
     }
 }
Beispiel #2
0
 public void OnGetDNSComplete(Object result, AsyncRequestObject aro)
 {
     if (result is Exception)
     {
     }
     else
     {
         m_serverCommand.ipAddress = (IPAddress)result;
         m_serverData.ipAddress    = (IPAddress)result;
         GetServerVersionAndMetadata();
     }
 }
Beispiel #3
0
        public void OnGetLiveConnect(Object result, AsyncRequestObject aro)
        {
            if (result is Exception)
            {
            }
            else
            {
                // Store return value to cancel task
                AsyncRequestObject aroTask = VIServices.LiveStream((Socket)result, m_onNewLiveFrame, m_cuda);

                // save aroTask as member variable so that I can call aroTask.cancel to stop
            }
        }
Beispiel #4
0
        public void OnGetServerMetadataComplete(Object result, AsyncRequestObject aro)
        {
            if (result is Exception)
            {
            }
            else
            {
                m_serverClass = VIServices.Deserialize <Videoinsight.LIB.Server>(result);

                // ready to send command telling server which cameras to stream
                if (Connected != null)
                {
                    Connected(this, e);  // raise event signaling that server controller is connected, metadata is ready to ready
                }
            }
        }
Beispiel #5
0
        public static AsyncRequestObject LiveStream(Socket socket, OnNewLiveFrame NewLiveFrameCallback, CancellationTokenSource cts = null, TaskScheduler ts = null)
        {
            AsyncRequestObject aro = new AsyncRequestObject(cts);

            ts = ts == null?TaskScheduler.FromCurrentSynchronizationContext() : ts;

            BlockingCollection <LiveCompressedFrame> queueCompressed = new BlockingCollection <LiveCompressedFrame>(1);

            #region Streaming task


            aro.task = Task.Factory.StartNew(() =>
            {
                byte[] bytes = null;

                HiResTimer t = new HiResTimer();

                Int64 t1     = t.Value;
                Int64 frames = 0;

                while (!aro.CancellationToken.WaitHandle.WaitOne(0))
                {
                    bytes = IPServices.ReceiveOnSocket(socket, aro.CancellationToken, 30000, Marshal.SizeOf(typeof(DATA_FRAME_HEADER)));
                    if (bytes != null && bytes.Length != 0)
                    {
                        // Full header received
                        GCHandle pinnedPacket = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                        DATA_FRAME_HEADER dfh = (DATA_FRAME_HEADER)Marshal.PtrToStructure(pinnedPacket.AddrOfPinnedObject(), typeof(DATA_FRAME_HEADER));
                        pinnedPacket.Free();

                        // Get frame
                        bytes = IPServices.ReceiveOnSocket(socket, aro.CancellationToken, 5000, dfh.TotalLength - Marshal.SizeOf(typeof(DATA_FRAME_HEADER)));
                        if (bytes != null && bytes.Length != 0)
                        {
                            //queueCompressed.Add(new LiveCompressedFrame(dfh, bytes), aro.CancellationToken);
                            Debug.Print(dfh.CameraID.ToString() + " " + bytes.Length.ToString());

                            // add code here to put frame into decoder input queue
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        // Server closed connection?
                        break;
                    }

                    ++frames;
                    if (frames % 100 == 0)
                    {
                        Int64 timeTicks           = t.Value - t1;
                        Int64 timeElapseInSeconds =
                            timeTicks / t.Frequency;
                        Debug.Print("Frame rate = {0}", (float)frames / (float)timeElapseInSeconds);
                    }
                }

                //fs.Close();
            }, aro.CancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);

            #endregion

            return(aro);
        }