Exemplo n.º 1
0
        private void QueueDataDumps(AtemConnection conn)
        {
            try
            {
                foreach (byte[] cmd in _state)
                {
                    var builder = new OutboundMessageBuilder();
                    if (!builder.TryAddData(cmd))
                    {
                        throw new Exception("Failed to build message!");
                    }

                    Log.InfoFormat("Length {0}", cmd.Length);

                    conn.QueueMessage(builder.Create());
                }

                Log.InfoFormat("Sent all data to {0}", conn.Endpoint);
                //conn.QueueMessage(new OutboundMessage(OutboundMessage.OutboundMessageType.Ping, new byte [0]));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
0
        public override DataTransferStatus OnMessage(ICommand command, AtemConnection connection)
        {
            if (command is DataTransferDataCommand dataCommand && dataCommand.TransferId == _id)
            {
                // TODO - do i need to track ids to avoid duplicate data on retransmits?
                _receivedData.Add(dataCommand.Body);

                connection.QueueCommand(new DataTransferAckCommand()
                {
                    TransferId    = _id,
                    TransferIndex = _index,
                });

                return(DataTransferStatus.OK);
            }

            if (command is DataTransferCompleteCommand completeCommand && completeCommand.TransferId == _id)
            {
                var fullData = _receivedData.SelectMany(d => d).ToArray();
                _onComplete(AtemFrame.FromAtem(_resolution, "", fullData)); // TODO - name
                return(DataTransferStatus.Success);
            }

            return(DataTransferStatus.Unknown);
        }
Exemplo n.º 3
0
        public DataTransferManager(AtemConnection connection)
        {
            _connection = connection;
            _queue      = new ConcurrentQueue <DataTransferJob>();
            _jobLock    = new object();

            _owners     = new Dictionary <uint, LockOwner>();
            _ownersLock = new object();

            StartTimer();
        }
Exemplo n.º 4
0
        public override DataTransferStatus OnMessage(ICommand command, AtemConnection connection)
        {
            if (command is DataTransferUploadContinueCommand continueCommand && continueCommand.TransferId == _id)
            {
                var toSend = new DataTransferFileDescriptionCommand()
                {
                    TransferId  = _id,
                    Name        = _name,
                    Description = _description,
                };
                connection.QueueCommand(toSend);

                // also queue data
                const int maxBodySize = 1350;

                // TODO - base chunking off of UploedMediaFrameJob
                int startPos = 0;
                while (startPos < _dataQueue.Count)
                {
                    int count = 1;
                    for (; count < _dataQueue.Count - startPos; count++)
                    {
                        int d = _dataQueue.Skip(startPos).Take(count + 1).Sum(v => v.Length);
                        if (d > maxBodySize)
                        {
                            break;
                        }
                    }

                    connection.QueueCommand(new DataTransferDataCommand()
                    {
                        TransferId = _id,
                        Body       = _dataQueue.Skip(startPos).Take(count).SelectMany(b => b).ToArray()
                    });

                    startPos += count;
                }

                return(DataTransferStatus.OK);
            }

            if (command is DataTransferCompleteCommand completeCommand && completeCommand.TransferId == _id)
            {
                _onComplete(true);
                return(DataTransferStatus.Success);
            }

            _onComplete(false);
            return(DataTransferStatus.Error);
        }
Exemplo n.º 5
0
 private void QueueDataDumps(AtemConnection conn)
 {
     try
     {
         var messages = AtemProxyUtil.CommandsToMessages(_state.Values());
         foreach (var msg in messages)
         {
             conn.QueueMessage(msg);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Exemplo n.º 6
0
        public override DataTransferStatus OnMessage(ICommand command, AtemConnection connection)
        {
            if (command is DataTransferUploadContinueCommand continueCommand && continueCommand.TransferId == TransferId)
            {
                if (!sentDescription)
                {
                    connection.QueueCommand(GetDescription());
                    sentDescription = true;
                }

                if (_sentData >= Data.Length)
                {
                    return(DataTransferStatus.OK);
                }

                // queue data
                var chunkSize = continueCommand.ChunkSize - 4;
                for (int i = 0; i < continueCommand.ChunkCount; i++)
                {
                    if (_sentData >= Data.Length)
                    {
                        break;
                    }

                    var    len = _sentData + chunkSize > Data.Length ? (long)(Data.Length - _sentData) : chunkSize;
                    byte[] b   = new byte[len];
                    Array.Copy(Data, _sentData, b, 0, len);

                    connection.QueueCommand(new DataTransferDataCommand
                    {
                        TransferId = TransferId,
                        Body       = b,
                    });
                    _sentData += (int)len;
                }

                return(DataTransferStatus.OK);
            }

            if (command is DataTransferCompleteCommand completeCmd && completeCmd.TransferId == TransferId)
            {
                _onComplete(true);
                return(DataTransferStatus.Success);
            }

            _onComplete(false);
            return(DataTransferStatus.Error);
        }
Exemplo n.º 7
0
        public override DataTransferStatus OnMessage(ICommand command, AtemConnection connection)
        {
            if (_currentFrame != null)
            {
                DataTransferStatus r = _currentFrame.OnMessage(command, connection);
                switch (r)
                {
                case DataTransferStatus.OK:
                    return(DataTransferStatus.OK);

                case DataTransferStatus.Error:
                    _onComplete(false);
                    return(DataTransferStatus.Error);
                }
            }
            else if (command.GetType() != typeof(MediaPoolClipDescriptionCommand))   // TODO - check the command values match
            {
                return(DataTransferStatus.OK);
            }

            // status was success, or is first frame
            if (_completedFrames >= _frames.Count)
            {
                connection.QueueCommand(new MediaPoolSetClipCommand()
                {
                    Index  = ClipIndex,
                    Name   = _name,
                    Frames = (uint)_frames.Count,
                });

                _onComplete(true);
                return(DataTransferStatus.Success);
            }

            int       index     = _completedFrames++;
            AtemFrame nextFrame = _frames[index];

            _currentFrame = new UploadMediaFrameJob(StoreId, (uint)index, nextFrame, b => { });
            ICommand cmd = _currentFrame.Start((uint)(_id + index + 5)); // TODO - proper id

            connection.QueueCommand(cmd);
            return(DataTransferStatus.OK);
        }
Exemplo n.º 8
0
        public override DataTransferStatus OnMessage(ICommand command, AtemConnection connection)
        {
            if (command is DataTransferDataCommand dataCommand && dataCommand.TransferId == _id)
            {
                // TODO - do i need to track ids to avoid duplicate data on retransmits?
                _receivedData.Add(dataCommand.Body);

                connection.QueueCommand(new DataTransferAckCommand()
                {
                    TransferId    = _id,
                    TransferIndex = _index,
                });

                return(DataTransferStatus.OK);
            }

            if (command is DataTransferCompleteCommand completeCommand && completeCommand.TransferId == _id)
            {
                var ops      = new List <byte[]>();
                var fullData = _receivedData.SelectMany(d => d).ToArray();

                int length = fullData.Length;
                int pos    = 0;
                while (pos < length)
                {
                    uint opLength = BitConverter.ToUInt16(fullData, pos);

                    byte[] opData = new byte[opLength];
                    Array.Copy(fullData, pos, opData, 0, opLength);
                    pos += (int)opLength;

                    ops.Add(opData);
                }

                _onComplete(ops);
                return(DataTransferStatus.Success);
            }

            _onComplete(null);
            return(DataTransferStatus.Error);
        }
Exemplo n.º 9
0
 private void QueueDataDumps(AtemConnection conn)
 {
     BuildDataDumps().ForEach(conn.QueueMessage);
     Log.InfoFormat("Sent all data to {0}", conn.Endpoint);
 }
Exemplo n.º 10
0
 public abstract DataTransferStatus OnMessage(ICommand command, AtemConnection connection);