Beispiel #1
0
        /// <include file='IAdbClient.xml' path='/IAdbClient/GetFrameBuffer/*'/>
        public async Task <Image> GetFrameBuffer(DeviceData device, CancellationToken cancellationToken)
        {
            using (IAdbSocket socket = Factories.AdbSocketFactory(this.EndPoint))
            {
                // Select the target device
                this.SetDevice(socket, device);

                // Send the framebuffer command
                socket.SendAdbRequest("framebuffer:");
                socket.ReadAdbResponse();

                // The result first is a FramebufferHeader object,
                var size       = Marshal.SizeOf(typeof(FramebufferHeader));
                var headerData = new byte[size];
                await socket.ReadAsync(headerData, cancellationToken).ConfigureAwait(false);

                var header = FramebufferHeader.Read(headerData);

                // followed by the actual framebuffer content
                var imageData = new byte[header.Size];
                socket.Read(imageData);

                // Convert the framebuffer to an image, and return that.
                return(header.ToImage(imageData));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Asynchronously refreshes the framebuffer: fetches the latest framebuffer data from the device. Access the <see cref="Header"/>
        /// and <see cref="Data"/> properties to get the updated framebuffer data.
        /// </summary>
        /// <param name="cancellationToken">
        /// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous task.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> which represents the asynchronous operation.
        /// </returns>
        public async Task RefreshAsync(CancellationToken cancellationToken)
        {
            var socket = Factories.AdbSocketFactory(this.client.EndPoint);

            // Select the target device
            this.client.SetDevice(socket, this.Device);

            // Send the framebuffer command
            socket.SendAdbRequest("framebuffer:");
            socket.ReadAdbResponse();

            // The result first is a FramebufferHeader object,
            await socket.ReadAsync(this.headerData, cancellationToken).ConfigureAwait(false);

            if (!this.headerInitialized)
            {
                this.Header            = FramebufferHeader.Read(this.headerData);
                this.headerInitialized = true;
            }

            if (this.Data == null || this.Data.Length < this.Header.Size)
            {
                this.Data = new byte[this.Header.Size];
            }

            // followed by the actual framebuffer content
            await socket.ReadAsync(this.Data, (int)this.Header.Size, cancellationToken).ConfigureAwait(false);
        }
Beispiel #3
0
        /// <summary>
        /// Asynchronously refreshes the framebuffer: fetches the latest framebuffer data from the device. Access the <see cref="Header"/>
        /// and <see cref="Data"/> properties to get the updated framebuffer data.
        /// </summary>
        /// <param name="cancellationToken">
        /// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous task.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> which represents the asynchronous operation.
        /// </returns>
        public async Task RefreshAsync(CancellationToken cancellationToken)
        {
            this.EnsureNotDisposed();

            using (var socket = Factories.AdbSocketFactory(this.client.EndPoint))
            {
                // Select the target device
                this.client.SetDevice(socket, this.Device);

                // Send the framebuffer command
                socket.SendAdbRequest("framebuffer:");
                socket.ReadAdbResponse();

                // The result first is a FramebufferHeader object,
                await socket.ReadAsync(this.headerData, cancellationToken).ConfigureAwait(false);

                if (!this.headerInitialized)
                {
                    this.Header            = FramebufferHeader.Read(this.headerData);
                    this.headerInitialized = true;
                }

                if (this.Data == null || this.Data.Length < this.Header.Size)
                {
#if !NETFX
                    // Optimization on .NET Core: Use the BufferPool to rent buffers
                    if (this.Data != null)
                    {
                        ArrayPool <byte> .Shared.Return(this.Data, clearArray : false);
                    }

                    this.Data = ArrayPool <byte> .Shared.Rent((int)this.Header.Size);
#else
                    this.Data = new byte[(int)this.Header.Size];
#endif
                }

                // followed by the actual framebuffer content
                await socket.ReadAsync(this.Data, (int)this.Header.Size, cancellationToken).ConfigureAwait(false);
            }
        }