webrtc

package
v0.0.0-...-8a90fd1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package webrtc contains WebRTC utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ICEFragmentMarshal

func ICEFragmentMarshal(offer string, candidates []*webrtc.ICECandidateInit) ([]byte, error)

ICEFragmentMarshal encodes an ICE fragment.

func ICEFragmentUnmarshal

func ICEFragmentUnmarshal(buf []byte) ([]*webrtc.ICECandidateInit, error)

ICEFragmentUnmarshal decodes an ICE fragment.

func LinkHeaderMarshal

func LinkHeaderMarshal(iceServers []webrtc.ICEServer) []string

LinkHeaderMarshal encodes a link header.

func LinkHeaderUnmarshal

func LinkHeaderUnmarshal(link []string) ([]webrtc.ICEServer, error)

LinkHeaderUnmarshal decodes a link header.

func NewAPI

func NewAPI(cnf APIConf) (*webrtc.API, error)

NewAPI allocates a webrtc API.

func TrackCount

func TrackCount(medias []*sdp.MediaDescription) (int, error)

TrackCount returns the track count.

func TracksToMedias

func TracksToMedias(tracks []*IncomingTrack) []*description.Media

TracksToMedias converts WebRTC tracks into a media description.

func WHIPDeleteSession

func WHIPDeleteSession(
	ctx context.Context,
	hc *http.Client,
	ur string,
) error

WHIPDeleteSession deletes a WHIP/WHEP session.

func WHIPOptionsICEServers

func WHIPOptionsICEServers(
	ctx context.Context,
	hc *http.Client,
	ur string,
) ([]webrtc.ICEServer, error)

WHIPOptionsICEServers sends a WHIP/WHEP request for ICE servers.

func WHIPPatchCandidate

func WHIPPatchCandidate(
	ctx context.Context,
	hc *http.Client,
	ur string,
	offer *webrtc.SessionDescription,
	etag string,
	candidate *webrtc.ICECandidateInit,
) error

WHIPPatchCandidate sends a WHIP/WHEP candidate.

Types

type APIConf

type APIConf struct {
	ICEUDPMux             ice.UDPMux
	ICETCPMux             ice.TCPMux
	LocalRandomUDP        bool
	IPsFromInterfaces     bool
	IPsFromInterfacesList []string
	AdditionalHosts       []string
}

APIConf is the configuration passed to NewAPI().

type IncomingTrack

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

IncomingTrack is an incoming track.

func (*IncomingTrack) Format

func (t *IncomingTrack) Format() format.Format

Format returns the track format.

func (*IncomingTrack) ReadRTP

func (t *IncomingTrack) ReadRTP() (*rtp.Packet, error)

ReadRTP reads a RTP packet.

type OutgoingTrack

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

OutgoingTrack is a WebRTC outgoing track

func (*OutgoingTrack) WriteRTP

func (t *OutgoingTrack) WriteRTP(pkt *rtp.Packet) error

WriteRTP writes a RTP packet.

type PeerConnection

type PeerConnection struct {
	ICEServers []webrtc.ICEServer
	API        *webrtc.API
	Publish    bool
	Log        logger.Writer
	// contains filtered or unexported fields
}

PeerConnection is a wrapper around webrtc.PeerConnection.

func (*PeerConnection) AddRemoteCandidate

func (co *PeerConnection) AddRemoteCandidate(candidate webrtc.ICECandidateInit) error

AddRemoteCandidate adds a remote candidate.

func (*PeerConnection) BytesReceived

func (co *PeerConnection) BytesReceived() uint64

BytesReceived returns received bytes.

func (*PeerConnection) BytesSent

func (co *PeerConnection) BytesSent() uint64

BytesSent returns sent bytes.

func (*PeerConnection) Close

func (co *PeerConnection) Close()

Close closes the connection.

func (*PeerConnection) Connected

func (co *PeerConnection) Connected() <-chan struct{}

Connected returns when connected.

func (*PeerConnection) CreateFullAnswer

func (co *PeerConnection) CreateFullAnswer(
	ctx context.Context,
	offer *webrtc.SessionDescription,
) (*webrtc.SessionDescription, error)

CreateFullAnswer creates a full answer.

func (*PeerConnection) CreatePartialOffer

func (co *PeerConnection) CreatePartialOffer() (*webrtc.SessionDescription, error)

CreatePartialOffer creates a partial offer.

func (*PeerConnection) Disconnected

func (co *PeerConnection) Disconnected() <-chan struct{}

Disconnected returns when disconnected.

func (*PeerConnection) GatherIncomingTracks

func (co *PeerConnection) GatherIncomingTracks(
	ctx context.Context,
	count int,
) ([]*IncomingTrack, error)

GatherIncomingTracks gathers incoming tracks.

func (*PeerConnection) GatheringDone

func (co *PeerConnection) GatheringDone() <-chan struct{}

GatheringDone returns when candidate gathering is complete.

func (*PeerConnection) LocalCandidate

func (co *PeerConnection) LocalCandidate() string

LocalCandidate returns the local candidate.

func (*PeerConnection) NewLocalCandidate

func (co *PeerConnection) NewLocalCandidate() <-chan *webrtc.ICECandidateInit

NewLocalCandidate returns when there's a new local candidate.

func (*PeerConnection) RemoteCandidate

func (co *PeerConnection) RemoteCandidate() string

RemoteCandidate returns the remote candidate.

func (*PeerConnection) SetAnswer

func (co *PeerConnection) SetAnswer(answer *webrtc.SessionDescription) error

SetAnswer sets the answer.

func (*PeerConnection) SetupOutgoingTracks

func (co *PeerConnection) SetupOutgoingTracks(
	videoTrack format.Format,
	audioTrack format.Format,
) ([]*OutgoingTrack, error)

SetupOutgoingTracks setups outgoing tracks.

func (*PeerConnection) Start

func (co *PeerConnection) Start() error

Start starts the peer connection.

func (*PeerConnection) WaitGatheringDone

func (co *PeerConnection) WaitGatheringDone(ctx context.Context) error

WaitGatheringDone waits until candidate gathering is complete.

func (*PeerConnection) WaitUntilConnected

func (co *PeerConnection) WaitUntilConnected(
	ctx context.Context,
) error

WaitUntilConnected waits until connection is established.

type TrackWrapper

type TrackWrapper struct {
	ClockRat int
}

TrackWrapper provides ClockRate() and PTSEqualsDTS() to WebRTC tracks.

func (TrackWrapper) ClockRate

func (w TrackWrapper) ClockRate() int

ClockRate returns the clock rate.

func (TrackWrapper) PTSEqualsDTS

func (TrackWrapper) PTSEqualsDTS(*rtp.Packet) bool

PTSEqualsDTS returns whether PTS equals DTS.

type WHIPClient

type WHIPClient struct {
	HTTPClient *http.Client
	URL        *url.URL
	Log        logger.Writer
	// contains filtered or unexported fields
}

WHIPClient is a WHIP client.

func (*WHIPClient) Close

func (c *WHIPClient) Close() error

Close closes the client.

func (*WHIPClient) Publish

func (c *WHIPClient) Publish(
	ctx context.Context,
	videoTrack format.Format,
	audioTrack format.Format,
) ([]*OutgoingTrack, error)

Publish publishes tracks.

func (*WHIPClient) Read

func (c *WHIPClient) Read(ctx context.Context) ([]*IncomingTrack, error)

Read reads tracks.

func (*WHIPClient) Wait

func (c *WHIPClient) Wait(ctx context.Context) error

Wait waits for client errors.

type WHIPPostOfferResponse

type WHIPPostOfferResponse struct {
	Answer   *webrtc.SessionDescription
	Location string
	ETag     string
}

WHIPPostOfferResponse is the response to a post offer.

func PostOffer

func PostOffer(
	ctx context.Context,
	hc *http.Client,
	ur string,
	offer *webrtc.SessionDescription,
) (*WHIPPostOfferResponse, error)

PostOffer posts a WHIP/WHEP offer.

Jump to

Keyboard shortcuts

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