engine

package module
v0.0.0-...-34547cc Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 27 Imported by: 0

README

remote-control-client-go2

功能探讨: 1.提供视频、音频、直播等功能,可配置 2.能在网页上配置树莓派的端口,第一次连接后,发送配置信息到网页,网页能提供相应的控制界面

1.远程能控制终端,如设置某一个IO口为输出,这需要一个高权限的datachannnel 2.一路是视屏加控制,另一路是旁观 3.需要完整的控制流程,有加入、断开、断线处理 4.人员管理,排队想控制的人,排队想旁观的人,如何管理?

工作流程: 1.视频源向服务器发register,role=videosoure登记新视频源,这个client需要标记为视频源,client需要state来标记是视频源、等待的控制端、正在控制、等待旁观、正在旁观等 2.控制方(APP)向服务器发join,不带sdp,轮到连接的时候才发送sdp,但是这个sdp需要设置检测超时,所有要跟其他的sdp分开处理 3.旁观方(App)的控制跟控制方类似

声音:

oto

网页版vscode https://coder.com/docs/code-server/latest/install 到这里下载下来 https://github.com/coder/code-server/ sudo dpkg -i code-server_${VERSION}_amd64.deb sudo systemctl enable --now code-server@$USER 如果是在云里,修改~/.config/code-server/config.yaml里的地址为0.0.0.0

Prerequisite

On some platforms you will need a C/C++ compiler in your path that Go can use.

  • macOS: On newer macOS versions type clang on your terminal and a dialog with installation instructions will appear if you don't have it
    • If you get an error with clang use xcode instead xcode-select --install
  • Linux and other Unix systems: Should be installed by default, but if not try GCC or Clang
macOS

Oto requires AudioToolbox.framework, but this is automatically linked.

iOS

Oto requires these frameworks:

  • AVFoundation.framework
  • AudioToolbox.framework

Add them to "Linked Frameworks and Libraries" on your Xcode project.

Linux

ALSA is required. On Ubuntu or Debian, run this command:

apt install libasound2-dev

In most cases this command must be run by root user or through sudo command.

FreeBSD, OpenBSD

BSD systems are not tested well. If ALSA works, Oto should work.

Usage

The two main components of Oto are a Context and Players. The context handles interactions with the OS and audio drivers, and as such there can only be one context in your program.

From a context you can create any number of different players, where each player is given an io.Reader that it reads bytes representing sounds from and plays.

Note that a single io.Reader must not be used by multiple players.

opus

API Docs

Go wrapper API reference: https://godoc.org/gopkg.in/hraban/opus.v2

Full libopus C API reference: https://www.opus-codec.org/docs/opus_api-1.1.3/

For more examples, see the _test.go files.

Build & Installation

This package requires libopus and libopusfile development packages to be installed on your system. These are available on Debian based systems from aptitude as libopus-dev and libopusfile-dev, and on Mac OS X from homebrew. They are linked into the app using pkg-config.

Debian, Ubuntu, ...:

sudo apt-get install pkg-config libopus-dev libopusfile-dev

Mac:

brew install pkg-config opus opusfile
Building Without libopusfile

This package can be built without libopusfile by using the build tag nolibopusfile. This enables the compilation of statically-linked binaries with no external dependencies on operating systems without a static libopusfile, such as Alpine Linux.

Note: this will disable all file and Stream APIs.

To enable this feature, add -tags nolibopusfile to your go build or go test commands:

# Build
go build -tags nolibopusfile ...

# Test
go test -tags nolibopusfile ./...

Documentation

Index

Constants

View Source
const (
	MimeTypeH264 = "video/H264"
	MimeTypeOpus = "audio/opus"
	MimeTypeVP8  = "video/VP8"
	MimeTypeVP9  = "video/VP9"
)
View Source
const (
	API_CHANNEL = "ion-sfu"
)

Variables

View Source
var (
	DefaultConfig = RTCConfig{
		WebRTC: WebRTCTransportConfig{
			Configuration: webrtc.Configuration{
				ICEServers: []webrtc.ICEServer{
					{
						URLs: []string{"stun:stun.stunprotocol.org:3478", "stun:stun.l.google.com:19302"},
					},
				},
			},
		},
	}
)

Functions

func FileExist

func FileExist(path string) bool

func GetArgs

func GetArgs(args ...string) (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 string)

func RandomKey

func RandomKey(n int) string

RandomKey generate a random string key

Types

type Call

type Call struct {
	StreamID string `json:"streamId"`
	Video    string `json:"video"`
	Audio    bool   `json:"audio"`
}

Call dc api

type Client

type Client struct {
	Id string

	StartControlTime time.Time
	StartViewTime    time.Time
	ControlTimer     *time.Timer
	//role           Target
	//Role                       rtc.Role
	ConnectType rtclib.ConnectType

	OnIceConnectionStateChange func(webrtc.ICEConnectionState, *webrtc.PeerConnection)
	DataChannelEable           bool
	// contains filtered or unexported fields
}

Client is pub/sub transport

func NewClient

func NewClient(uid string, rtc *RTC, connectType rtclib.ConnectType) *Client

NewTransport create a transport

type Connector

type Connector struct {
	Metadata metadata.MD

	OnOpen  func(Service)
	OnClose func(Service, ServiceEvent)
	// contains filtered or unexported fields
}

func NewConnector

func NewConnector(addr string, config ...ConnectorConfig) *Connector

NewConnector create a ion connector

func (*Connector) Close

func (c *Connector) Close()

func (*Connector) OnEnd

func (c *Connector) OnEnd(service Service, headers metadata.MD)

func (*Connector) OnHeaders

func (c *Connector) OnHeaders(service Service, headers metadata.MD)

func (*Connector) RegisterService

func (c *Connector) RegisterService(service Service)

func (*Connector) Signal

func (c *Connector) Signal(r *RTC) (Signaller, error)

type ConnectorConfig

type ConnectorConfig struct {
	SSL    bool
	Cafile string
	Token  string
}

type DataChannelMsg

type DataChannelMsg struct {
	Cmd string `json:"cmd"`
	//Data string `json:"data"`
	Data interface{} `json:"data"`
}

type DataChannelMsgDataSdp

type DataChannelMsgDataSdp struct {
	Type string `json:"type"`
	Sdp  string `json:"sdp"`
}

type JoinConfig

type JoinConfig map[string]string

func NewJoinConfig

func NewJoinConfig() *JoinConfig

func SetRelay

func SetRelay(j JoinConfig) *JoinConfig

func (JoinConfig) SetNoAutoSubscribe

func (j JoinConfig) SetNoAutoSubscribe() *JoinConfig

func (JoinConfig) SetNoPublish

func (j JoinConfig) SetNoPublish() *JoinConfig

func (JoinConfig) SetNoSubscribe

func (j JoinConfig) SetNoSubscribe() *JoinConfig

type MediaType

type MediaType int32
const (
	MediaType_MediaUnknown  MediaType = 0
	MediaType_UserMedia     MediaType = 1
	MediaType_ScreenCapture MediaType = 2
	MediaType_Cavans        MediaType = 3
	MediaType_Streaming     MediaType = 4
	MediaType_VoIP          MediaType = 5
)

type PiControl

type PiControl struct {
	// contains filtered or unexported fields
}

func Init

func Init() *PiControl

func (*PiControl) BladeSwitch

func (pi *PiControl) BladeSwitch(bladeOn int) error

刀片开关

func (*PiControl) DirectionControl

func (pi *PiControl) DirectionControl(direction int) error

两轮差速控制小车的方向控制

func (*PiControl) SpeedControl

func (pi *PiControl) SpeedControl(speed int) error

type RTC

type RTC struct {
	Service

	MaxTimeControl int
	MaxTimeView    int
	MaxClientsNum  int

	//controlClient *Client
	//viewClients map[string]*Client
	//export to user
	OnTrack              func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver)
	OnDataChannel        func(*webrtc.DataChannel)
	OnError              func(error)
	OnTrackEvent         func(event TrackEvent)
	OnDataChannelMessage func(webrtc.DataChannelMessage)
	OnSpeaker            func(event []string)
	ControlFunc          func(control string, data float64)

	sync.Mutex
	OnPubIceConnectionStateChange func(webrtc.ICEConnectionState)
	OnSubIceConnectionStateChange func(webrtc.ICEConnectionState)
	OnIceConnectionStateChange    func(webrtc.ICEConnectionState, *webrtc.PeerConnection)
	VedioTrack                    *webrtc.TrackLocalStaticSample
	AudioTrack                    *webrtc.TrackLocalStaticSample
	// contains filtered or unexported fields
}

Client a sdk client

func NewRTC

func NewRTC(connector *Connector, config ...RTCConfig) (*RTC, error)

NewRTC creates an RTC using the default GRPC signaller

func NewRTCWithSignaller

func NewRTCWithSignaller(signaller Signaller, config ...RTCConfig) *RTC

NewRTCWithSignaller creates an RTC with a specified signaller

func (*RTC) Close

func (r *RTC) Close()

Close client close

func (*RTC) Connect

func (r *RTC) Connect()

func (*RTC) Connected

func (r *RTC) Connected() bool

func (*RTC) CreateDataChannel

func (r *RTC) CreateDataChannel(label string) (*webrtc.DataChannel, error)

CreateDataChannel create a custom datachannel

func (*RTC) GetBandWidth

func (r *RTC) GetBandWidth(cycle int) (int, int)

GetBandWidth call this api cyclely

func (*RTC) GetPubStats

func (r *RTC) GetPubStats() webrtc.StatsReport

GetPubStats get pub stats

func (*RTC) GetPubTransport

func (r *RTC) GetPubTransport() *Transport

func (*RTC) GetSubStats

func (r *RTC) GetSubStats() webrtc.StatsReport

GetSubStats get sub stats

func (*RTC) GetSubTransport

func (r *RTC) GetSubTransport() *Transport

func (*RTC) Name

func (r *RTC) Name() string

func (*RTC) Publish

func (r *RTC) Publish(tracks ...webrtc.TrackLocal) ([]*webrtc.RTPSender, error)

Publish local tracks

func (*RTC) PublishFile

func (r *RTC) PublishFile(file string, video, audio bool) error

PublishWebm publish a webm producer

func (*RTC) Reconnect

func (r *RTC) Reconnect()

func (*RTC) RegisterNewVideoSource

func (r *RTC) RegisterNewVideoSource(uid, name string, sourceType rtc.SourceType, config ...*JoinConfig) error

Creata new session

func (*RTC) SendAnswer

func (r *RTC) SendAnswer(sdp webrtc.SessionDescription) error

func (*RTC) SendAnswer2

func (r *RTC) SendAnswer2(sdp webrtc.SessionDescription, to string) error

func (*RTC) SendJoin

func (r *RTC) SendJoin(sid string, uid string, offer webrtc.SessionDescription, config map[string]string) error

func (*RTC) SendOffer

func (r *RTC) SendOffer(sdp webrtc.SessionDescription) error

func (*RTC) SendTrickle

func (r *RTC) SendTrickle(candidate *webrtc.ICECandidate, target Target)

func (*RTC) SendTrickle2

func (r *RTC) SendTrickle2(candidate *webrtc.ICECandidate, destination string)

func (*RTC) SendWantConnectReply

func (r *RTC) SendWantConnectReply(sdp webrtc.SessionDescription, to string) error

func (*RTC) Subscribe

func (r *RTC) Subscribe(trackInfos []*Subscription) error

Subscribe to tracks

func (*RTC) SubscribeFromEvent

func (r *RTC) SubscribeFromEvent(event TrackEvent, audio, video bool, layer string) error

SubscribeFromEvent will parse event and subscribe what you want

func (*RTC) UnPublish

func (r *RTC) UnPublish(senders ...*webrtc.RTPSender) error

UnPublish local tracks by transceivers

type RTCConfig

type RTCConfig struct {
	WebRTC WebRTCTransportConfig `mapstructure:"webrtc"`
}

type Service

type Service interface {
	Name() string
	Connect()
	Close()
	Connected() bool
}

type ServiceEvent

type ServiceEvent struct {
	Name      string
	ErrStatus *status.Status
}

type Signaller

type Signaller interface {
	Send(request *rtc.Request) error
	Recv() (*rtc.Reply, error)
	CloseSend() error
}

Signaller sends and receives signalling messages with peers. Signaller is derived from rtc.RTC_SignalClient, matching the exported API of the GRPC Signal Service. Signaller allows alternative signalling implementations if the GRPC Signal Service does not fit your use case.

type Subscription

type Subscription struct {
	TrackId   string
	Mute      bool
	Subscribe bool
	Layer     string
}

type Target

type Target int32
const (
	Target_PUBLISHER  Target = 0
	Target_SUBSCRIBER Target = 1
)

type TrackEvent

type TrackEvent struct {
	State  TrackEvent_State
	Uid    string
	Tracks []*TrackInfo
}

TrackEvent info

type TrackEvent_State

type TrackEvent_State int32
const (
	TrackEvent_ADD    TrackEvent_State = 0
	TrackEvent_UPDATE TrackEvent_State = 1
	TrackEvent_REMOVE TrackEvent_State = 2
)

type TrackInfo

type TrackInfo struct {
	Id        string
	Kind      string
	Muted     bool
	Type      MediaType
	StreamId  string
	Label     string
	Subscribe bool
	Layer     string
	Direction string
	Width     uint32
	Height    uint32
	FrameRate uint32
}

type Transport

type Transport struct {
	SendCandidates []*webrtc.ICECandidate
	RecvCandidates []webrtc.ICECandidateInit
	// contains filtered or unexported fields
}

Transport is pub/sub transport

func NewTransport

func NewTransport(uid string, role Target, rtc *RTC) *Transport

NewTransport create a transport

func (*Transport) GetPeerConnection

func (t *Transport) GetPeerConnection() *webrtc.PeerConnection

type WebMProducer

type WebMProducer struct {
	// contains filtered or unexported fields
}

WebMProducer support streaming by webm which encode with vp8 and opus

func NewWebMProducer

func NewWebMProducer(name string, offset int) *WebMProducer

NewWebMProducer new a WebMProducer

func (*WebMProducer) GetAudioTrack

func (t *WebMProducer) GetAudioTrack() (*webrtc.TrackLocalStaticSample, error)

GetAudioTrack get audio track

func (*WebMProducer) GetSendBandwidth

func (t *WebMProducer) GetSendBandwidth(cycle int) int

GetSendBandwidth calc the sending bandwidth with cycle(s)

func (*WebMProducer) GetVideoTrack

func (t *WebMProducer) GetVideoTrack() (*webrtc.TrackLocalStaticSample, error)

GetVideoTrack get video track

func (*WebMProducer) Pause

func (t *WebMProducer) Pause(pause bool)

func (*WebMProducer) SeekP

func (t *WebMProducer) SeekP(ts int)

func (*WebMProducer) Start

func (t *WebMProducer) Start()

func (*WebMProducer) Stop

func (t *WebMProducer) Stop()

type WebRTCTransportConfig

type WebRTCTransportConfig struct {
	// if set, only this codec will be registered. leave unset to register all codecs.
	VideoMime     string
	Configuration webrtc.Configuration
	Setting       webrtc.SettingEngine
}

WebRTCTransportConfig represents configuration options

Directories

Path Synopsis
pkg
gstreamer-sink
Package gst provides an easy API to create an appsrc pipeline
Package gst provides an easy API to create an appsrc pipeline
gstreamer-src
Package gst provides an easy API to create an appsink pipeline
Package gst provides an easy API to create an appsink pipeline

Jump to

Keyboard shortcuts

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