srtgo

package module
v0.0.0-...-12f28e2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2021 License: MPL-2.0 Imports: 9 Imported by: 0

README

PkgGoDev

srtgo

Go bindings for SRT (Secure Reliable Transport), the open source transport technology that optimizes streaming performance across unpredictable networks.

Why srtgo?

To make easier the adoption of SRT transport technology. Using Go, with just a few lines of code you can implement an application that sends/receives data, with all the benefits of SRT technology: security and reliability, while keeping latency low.

Is this a new implementation of SRT?

No! We are just exposing the great work done by the community with [SRT project]((https://github.com/Haivision/srt) as a golang library. All the functionality and implementation still resides on SRT official project.

Features supported

  • Basic API exposed to easy develop SRT sender/receiver apps
  • Caller and Listener mode
  • Live transport type
  • File transport type
  • Message/Buffer API
  • SRT transport options up to SRT 1.4.1
  • SRT Stats retrieval

Usage

Example of a SRT receiver application:

package main

import (
    "github.com/haivision/srtgo"
    "fmt"
)

func main() {
    options := make(map[string]string)
    options["transtype"] = "file"

	sck := srtgo.NewSrtSocket("0.0.0.0", 8090, options)
	sck.Listen(1)
    s, _ := sck.Accept()

    buff := make([]byte, 2048)
    for {
        n, _ := s.Read(buff, 10000)
        if n == 0 {
            break
        }
        fmt.Println("Received %d bytes", n)
    }
    //....
}

Dependencies

  • srtlib

You can find detailed instructions about how to install srtlib in its README file

gosrt has been developed with srt 1.4.1 as its main target and has been successfully tested in srt 1.3.4 and above.

Documentation

Index

Constants

View Source
const (
	ModeFailure = iota
	ModeListener
	ModeCaller
	ModeRendezvouz
)

SRT Socket mode

View Source
const (
	SRTO_TRANSTYPE          = C.SRTO_TRANSTYPE
	SRTO_MAXBW              = C.SRTO_MAXBW
	SRTO_PBKEYLEN           = C.SRTO_PBKEYLEN
	SRTO_PASSPHRASE         = C.SRTO_PASSPHRASE
	SRTO_MSS                = C.SRTO_MSS
	SRTO_FC                 = C.SRTO_FC
	SRTO_SNDBUF             = C.SRTO_SNDBUF
	SRTO_RCVBUF             = C.SRTO_RCVBUF
	SRTO_IPTTL              = C.SRTO_IPTTL
	SRTO_IPTOS              = C.SRTO_IPTOS
	SRTO_INPUTBW            = C.SRTO_INPUTBW
	SRTO_OHEADBW            = C.SRTO_OHEADBW
	SRTO_LATENCY            = C.SRTO_LATENCY
	SRTO_TSBPDMODE          = C.SRTO_TSBPDMODE
	SRTO_TLPKTDROP          = C.SRTO_TLPKTDROP
	SRTO_SNDDROPDELAY       = C.SRTO_SNDDROPDELAY
	SRTO_NAKREPORT          = C.SRTO_NAKREPORT
	SRTO_CONNTIMEO          = C.SRTO_CONNTIMEO
	SRTO_LOSSMAXTTL         = C.SRTO_LOSSMAXTTL
	SRTO_RCVLATENCY         = C.SRTO_RCVLATENCY
	SRTO_PEERLATENCY        = C.SRTO_PEERLATENCY
	SRTO_MINVERSION         = C.SRTO_MINVERSION
	SRTO_STREAMID           = C.SRTO_STREAMID
	SRTO_CONGESTION         = C.SRTO_CONGESTION
	SRTO_MESSAGEAPI         = C.SRTO_MESSAGEAPI
	SRTO_PAYLOADSIZE        = C.SRTO_PAYLOADSIZE
	SRTO_KMREFRESHRATE      = C.SRTO_KMREFRESHRATE
	SRTO_KMPREANNOUNCE      = C.SRTO_KMPREANNOUNCE
	SRTO_ENFORCEDENCRYPTION = C.SRTO_ENFORCEDENCRYPTION
	SRTO_PEERIDLETIMEO      = C.SRTO_PEERIDLETIMEO
	SRTO_PACKETFILTER       = C.SRTO_PACKETFILTER
	SRTO_STATE              = C.SRTO_STATE
)

Variables

View Source
var (
	SRT_INVALID_SOCK   = C.get_srt_invalid_sock()
	SRT_ERROR          = C.get_srt_error()
	SRT_REJX_FORBIDDEN = C.get_srt_error_access_forbidden()
	SRTS_CONNECTED     = C.SRTS_CONNECTED
)

Static consts from library

View Source
var SocketOptions = []socketOption{
	{"transtype", 0, SRTO_TRANSTYPE, bindingPre, tTransType},
	{"maxbw", 0, SRTO_MAXBW, bindingPre, tInteger64},
	{"pbkeylen", 0, SRTO_PBKEYLEN, bindingPre, tInteger32},
	{"passphrase", 0, SRTO_PASSPHRASE, bindingPre, tString},
	{"mss", 0, SRTO_MSS, bindingPre, tInteger32},
	{"fc", 0, SRTO_FC, bindingPre, tInteger32},
	{"sndbuf", 0, SRTO_SNDBUF, bindingPre, tInteger32},
	{"rcvbuf", 0, SRTO_RCVBUF, bindingPre, tInteger32},
	{"ipttl", 0, SRTO_IPTTL, bindingPre, tInteger32},
	{"iptos", 0, SRTO_IPTOS, bindingPre, tInteger32},
	{"inputbw", 0, SRTO_INPUTBW, bindingPost, tInteger64},
	{"oheadbw", 0, SRTO_OHEADBW, bindingPost, tInteger32},
	{"latency", 0, SRTO_LATENCY, bindingPre, tInteger32},
	{"tsbpdmode", 0, SRTO_TSBPDMODE, bindingPre, tBoolean},
	{"tlpktdrop", 0, SRTO_TLPKTDROP, bindingPre, tBoolean},
	{"snddropdelay", 0, SRTO_SNDDROPDELAY, bindingPost, tInteger32},
	{"nakreport", 0, SRTO_NAKREPORT, bindingPre, tBoolean},
	{"conntimeo", 0, SRTO_CONNTIMEO, bindingPre, tInteger32},
	{"lossmaxttl", 0, SRTO_LOSSMAXTTL, bindingPre, tInteger32},
	{"rcvlatency", 0, SRTO_RCVLATENCY, bindingPre, tInteger32},
	{"peerlatency", 0, SRTO_PEERLATENCY, bindingPre, tInteger32},
	{"minversion", 0, SRTO_MINVERSION, bindingPre, tInteger32},
	{"streamid", 0, SRTO_STREAMID, bindingPre, tString},
	{"congestion", 0, SRTO_CONGESTION, bindingPre, tString},
	{"messageapi", 0, SRTO_MESSAGEAPI, bindingPre, tBoolean},
	{"payloadsize", 0, SRTO_PAYLOADSIZE, bindingPre, tInteger32},
	{"kmrefreshrate", 0, SRTO_KMREFRESHRATE, bindingPre, tInteger32},
	{"kmpreannounce", 0, SRTO_KMPREANNOUNCE, bindingPre, tInteger32},
	{"enforcedencryption", 0, SRTO_ENFORCEDENCRYPTION, bindingPre, tBoolean},
	{"peeridletimeo", 0, SRTO_PEERIDLETIMEO, bindingPre, tInteger32},
	{"packetfilter", 0, SRTO_PACKETFILTER, bindingPre, tString},
}

List of possible srt socket options

Functions

func CleanupSRT

func CleanupSRT()

CleanupSRT - Cleanup SRT lib

func CreateAddrInet

func CreateAddrInet(name string, port uint16) (*C.struct_sockaddr, int, error)

func InitSRT

func InitSRT()

InitSRT - Initialize srt library

Types

type SrtSocket

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

SrtSocket - SRT socket

func NewSrtSocket

func NewSrtSocket(host string, port uint16, options map[string]string) *SrtSocket

NewSrtSocket - Create a new SRT Socket

func (SrtSocket) Accept

func (s SrtSocket) Accept() (*SrtSocket, *net.UDPAddr, error)

Accept an incoming connection

func (SrtSocket) Close

func (s SrtSocket) Close()

Close the SRT socket

func (SrtSocket) Connect

func (s SrtSocket) Connect() error

Connect to a remote endpoint

func (SrtSocket) GetSockOptBool

func (s SrtSocket) GetSockOptBool(opt int) (bool, error)

GetSockOptBool - return bool value obtained with srt_getsockopt

func (SrtSocket) GetSockOptByte

func (s SrtSocket) GetSockOptByte(opt int) (byte, error)

GetSockOptByte - return byte value obtained with srt_getsockopt

func (SrtSocket) GetSockOptInt

func (s SrtSocket) GetSockOptInt(opt int) (int, error)

GetSockOptInt - return int value obtained with srt_getsockopt

func (SrtSocket) GetSockOptInt64

func (s SrtSocket) GetSockOptInt64(opt int) (int64, error)

GetSockOptInt64 - return int64 value obtained with srt_getsockopt

func (SrtSocket) GetSockOptString

func (s SrtSocket) GetSockOptString(opt int) (string, error)

GetSockOptString - return string value obtained with srt_getsockopt

func (SrtSocket) GetSocket

func (s SrtSocket) GetSocket() C.int

func (SrtSocket) InstantStats

func (s SrtSocket) InstantStats(clear bool) (*SrtStats, error)

Stats - Retrieve stats from the SRT socket

func (SrtSocket) Listen

func (s SrtSocket) Listen(clients int) error

Listen for incoming connections

func (SrtSocket) Mode

func (s SrtSocket) Mode() int

Mode - Return working mode of the SRT socket

func (SrtSocket) PacketSize

func (s SrtSocket) PacketSize() int

PacketSize - Return packet size of the SRT socket

func (SrtSocket) Read

func (s SrtSocket) Read(b []byte, timeout int) (n int, err error)

Read data from the SRT socket

func (SrtSocket) SetSockOptBool

func (s SrtSocket) SetSockOptBool(opt int, value bool) error

SetSockOptBool - set bool value using srt_setsockopt

func (SrtSocket) SetSockOptByte

func (s SrtSocket) SetSockOptByte(opt int, value byte) error

SetSockOptByte - set byte value using srt_setsockopt

func (SrtSocket) SetSockOptInt

func (s SrtSocket) SetSockOptInt(opt int, value int) error

SetSockOptInt - set int value using srt_setsockopt

func (SrtSocket) SetSockOptInt64

func (s SrtSocket) SetSockOptInt64(opt int, value int64) error

SetSockOptInt64 - set int64 value using srt_setsockopt

func (SrtSocket) SetSockOptString

func (s SrtSocket) SetSockOptString(opt int, value string) error

SetSockOptString - set string value using srt_setsockopt

func (SrtSocket) Stats

func (s SrtSocket) Stats(clear bool) (*SrtStats, error)

Stats - Retrieve stats from the SRT socket

func (SrtSocket) Write

func (s SrtSocket) Write(b []byte, timeout int) (n int, err error)

Write data to the SRT socket

type SrtStats

type SrtStats struct {
	// Global measurements
	MsTimeStamp        int64 // time since the UDT entity is started, in milliseconds
	PktSentTotal       int64 // total number of sent data packets, including retransmissions
	PktRecvTotal       int64 // total number of received packets
	PktSndLossTotal    int   // total number of lost packets (sender side)
	PktRcvLossTotal    int   // total number of lost packets (receiver side)
	PktRetransTotal    int   // total number of retransmitted packets
	PktSentACKTotal    int   // total number of sent ACK packets
	PktRecvACKTotal    int   // total number of received ACK packets
	PktSentNAKTotal    int   // total number of sent NAK packets
	PktRecvNAKTotal    int   // total number of received NAK packets
	UsSndDurationTotal int64 // total time duration when UDT is sending data (idle time exclusive)

	PktSndDropTotal      int   // number of too-late-to-send dropped packets
	PktRcvDropTotal      int   // number of too-late-to play missing packets
	PktRcvUndecryptTotal int   // number of undecrypted packets
	ByteSentTotal        int64 // total number of sent data bytes, including retransmissions
	ByteRecvTotal        int64 // total number of received bytes
	ByteRcvLossTotal     int64 // total number of lost bytes

	ByteRetransTotal      int64 // total number of retransmitted bytes
	ByteSndDropTotal      int64 // number of too-late-to-send dropped bytes
	ByteRcvDropTotal      int64 // number of too-late-to play missing bytes (estimate based on average packet size)
	ByteRcvUndecryptTotal int64 // number of undecrypted bytes

	// Local measurements
	PktSent              int64   // number of sent data packets, including retransmissions
	PktRecv              int64   // number of received packets
	PktSndLoss           int     // number of lost packets (sender side)
	PktRcvLoss           int     // number of lost packets (receiver side)
	PktRetrans           int     // number of retransmitted packets
	PktRcvRetrans        int     // number of retransmitted packets received
	PktSentACK           int     // number of sent ACK packets
	PktRecvACK           int     // number of received ACK packets
	PktSentNAK           int     // number of sent NAK packets
	PktRecvNAK           int     // number of received NAK packets
	MbpsSendRate         float64 // sending rate in Mb/s
	MbpsRecvRate         float64 // receiving rate in Mb/s
	UsSndDuration        int64   // busy sending time (i.e., idle time exclusive)
	PktReorderDistance   int     // size of order discrepancy in received sequences
	PktRcvAvgBelatedTime float64 // average time of packet delay for belated packets (packets with sequence past the ACK)
	PktRcvBelated        int64   // number of received AND IGNORED packets due to having come too late

	PktSndDrop      int   // number of too-late-to-send dropped packets
	PktRcvDrop      int   // number of too-late-to play missing packets
	PktRcvUndecrypt int   // number of undecrypted packets
	ByteSent        int64 // number of sent data bytes, including retransmissions
	ByteRecv        int64 // number of received bytes

	ByteRcvLoss      int64 // number of retransmitted Bytes
	ByteRetrans      int64 // number of retransmitted Bytes
	ByteSndDrop      int64 // number of too-late-to-send dropped Bytes
	ByteRcvDrop      int64 // number of too-late-to play missing Bytes (estimate based on average packet size)
	ByteRcvUndecrypt int64 // number of undecrypted bytes

	// Instant measurements
	UsPktSndPeriod      float64 // packet sending period, in microseconds
	PktFlowWindow       int     // flow window size, in number of packets
	PktCongestionWindow int     // congestion window size, in number of packets
	PktFlightSize       int     // number of packets on flight
	MsRTT               float64 // RTT, in milliseconds
	MbpsBandwidth       float64 // estimated bandwidth, in Mb/s
	ByteAvailSndBuf     int     // available UDT sender buffer size
	ByteAvailRcvBuf     int     // available UDT receiver buffer size

	MbpsMaxBW float64 // Transmit Bandwidth ceiling (Mbps)
	ByteMSS   int     // MTU

	PktSndBuf       int // UnACKed packets in UDT sender
	ByteSndBuf      int // UnACKed bytes in UDT sender
	MsSndBuf        int // UnACKed timespan (msec) of UDT sender
	MsSndTsbPdDelay int // Timestamp-based Packet Delivery Delay

	PktRcvBuf       int // Undelivered packets in UDT receiver
	ByteRcvBuf      int // Undelivered bytes of UDT receiver
	MsRcvBuf        int // Undelivered timespan (msec) of UDT receiver
	MsRcvTsbPdDelay int // Timestamp-based Packet Delivery Delay

	PktSndFilterExtraTotal  int // number of control packets supplied by packet filter
	PktRcvFilterExtraTotal  int // number of control packets received and not supplied back
	PktRcvFilterSupplyTotal int // number of packets that the filter supplied extra (e.g. FEC rebuilt)
	PktRcvFilterLossTotal   int // number of packet loss not coverable by filter

	PktSndFilterExtra   int // number of control packets supplied by packet filter
	PktRcvFilterExtra   int // number of control packets received and not supplied back
	PktRcvFilterSupply  int // number of packets that the filter supplied extra (e.g. FEC rebuilt)
	PktRcvFilterLoss    int // number of packet loss not coverable by filter
	PktReorderTolerance int // packet reorder tolerance value
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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