go_scrcpy_recv

package module
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 6 Imported by: 1

README

go-scrcpy-video-receiver

A simple golang lib for receiving and decoding scrcpy frames in png format for Windows only.

It is designed to listen to a tcp port. So it can receive video stream from scrcpy's android app.

This package can handle multiple scrcpy client(android) connections. And you need to add your own callbacks to handle frame images. You can also config the image size so this package will scale the image for you.

Open source software used(check lib folder):

  1. ffmpeg
  2. opencv

How to use it?

go get -u github.com/ColinZou/go_scrcpy_recv@v0.2.7

Check examples/basic.go for more details.

How to build and run?

  1. install ms build tool

You also need to have Windows Kits and Visual Studio(Community is ok) installed. Just go to download visualstudio installer. And make sure "Desktop development with C++" is checked before you hit install.

  1. install cmake

You need to download from here. Making sure cmake.exe is in your path before you move on.

  1. install dependencies with vcpkg
vcpkg install --recurse --triplet x64-windows-static ffmpeg[avcodec] ffmpeg[x264] ffmpeg[swscale] ffmpeg[avresample] opencv4[png] boost-asio

DO NOT FORGET TO SET VCPKG_ROOT to vcpkg folder.

  1. run script\build.bat

  2. run build\basic.exe

  3. run scripts\adb-prepare.ps1 in powershell

Note for running the example

There's a modified scrcpy-server (andoird app "scrcpy-server-debug") include inside scripts folder. This modified version supports pass device id as command line argument. You may need to set environment variable ADB_CMD, point it to path of adb.exe.

The source code of scrcpy-server-debug can be found here.

You need to set environment variable SCRCPY_SAVE_FRAMES=y if you want to save frame images into "images" folder. The images folder will be created in PWD(current directory).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Release

func Release(handle Receiver, timeout int)

Types

type DeviceDisconnectedCallback

type DeviceDisconnectedCallback func(string, string, string)

device disconnected callback, arguments will be: token deviceId and connectionType(video/ctrl)

type ImageSize

type ImageSize struct {
	Width  int
	Height int
}

func (*ImageSize) String

func (i *ImageSize) String() string

type Receiver

type Receiver interface {
	/**
	* start up the receiver
	* CAUTION: this a blocking method
	* @param            listenAddr              receiver's listening address
	* @param            networkBufferSizeKb     netowrk buffer size, recommend 2048KB for lagger screens
	* @param            videoBufferSizeKb       video deocder's buffer size
	 */
	Startup(listenAddr string, networkBufferSizeKb int, videoBufferSizeKb int)

	/**
	 * shutdown the receiver
	 */
	Shutdown()

	/**
	* setup image size for a device
	* @param           deviceId                device's id
	* @param           width                   image width
	* @param           height                  image height
	 */
	SetFrameImageSize(deviceId string, width int, height int)

	/**
	 * Get frame image size configured for a device
	 * @param            deviceId            device's include
	 * @return       the image size struct
	 */
	GetFrameImageSize(deviceId string) *ImageSize

	/**
	 * Get original frame image size configured for a device
	 * @param            deviceId            device's include
	 * @return       the image size struct
	 */
	GetOriginalFrameImageSize(deviceId string) *ImageSize

	/**
	 * Add frame image callback for device
	 * @param            deviceId            device's id
	 * @param            callbackMethod      the callback method. (deviceId, png image data, png image size, screen size) in order.
	 */
	AddFrameImageCallback(deviceId string, callbackMethod func(string, *[]byte, *ImageSize, *ImageSize))

	/**
	 * Remove all frame image callback methods for a device
	 * @param           deviceId            device's id
	 */
	RemoveAllImageCallbacks(deviceId string)

	/**
	 * Add device info callback
	 * @param           deviceId            device's id
	 * @param           callbackMethod      the callback method. (deviceId, screen width, screen height) in order.
	 */
	AddDeviceInfoCallback(deviceId string, callbackMethod func(string, int, int))

	/**
	 * Remove all device info callback methods
	 * @param           deviceId            device's id
	 */
	RemoveAllDeviceInfoCallbacks(deviceId string)
	/**
	 * Get instance token name
	 */
	GetToken() string

	/**
	 * Add controll event send callback
	 * @param       deviceId        the device's identifier
	 * @param       callbackMethod  callback method ref
	 * callbackMethod will receive deviceId, msgId, sendStatus, dataLen in order
	 * dataLen should equals to sendStatus  if send ok
	**/
	AddCtrlEventSendCallback(deviceId string, callbackMethod func(string, string, int, int))
	/**
	 * Remove all callback for controll event sending
	 * @param       deviceId        the device's id
	**/
	RemoveAllCtrlEventSendCallback(deviceId string)

	/**
	 * Send controll events to device
	 * @param       deviceId        the device's identifier
	 * @param       msgId           msg identifier
	 * @param       data            event data
	**/
	SendCtrlEvent(deviceId string, msgId string, data *[]byte)

	/**
	 * Add a callback for device disconnected
	 * @param        deviceId        the device's identifier
	 * @param        callback        the callback method
	 **/
	AddDeviceDisconnectedCallback(deviceId string, callback DeviceDisconnectedCallback)
	/**
	 * Remove all callbacks of a device's disconnected event
	 * @param         deviceId        the device's identifier
	 **/
	RemoveAllDisconnectedCallbck(deviceId string)
}

func New

func New(token string) Receiver

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL