Documentation
¶
Overview ¶
Package xk6mediasoup registers the mediasoup load-testing extension (k6/x/mediasoup) with k6.
Index ¶
- func CalculateMOS(lossPercent float64, jitterMs float64) float64
- func CreateSyntheticIVFBytes(width, height uint16, fps int, numFrames int) ([]byte, error)
- func CreateWebRTCAPI(profiles ...mediasoup.SDPProfile) (*webrtc.API, stats.Getter, error)
- func GenerateSilentOpusFrames(count int) [][]byte
- func GenerateTestPatternVP8Frames(width, height uint16, count int) [][]byte
- func MakeTags(base *metrics.TagSet, tags map[string]string) *metrics.TagSet
- func RecordValue(ctx context.Context, samples chan<- metrics.SampleContainer, ...)
- type AudioSample
- type Client
- func (c *Client) CanProduce(kind string) bool
- func (c *Client) Close() error
- func (c *Client) CloseSpeaking() (bool, error)
- func (c *Client) Connect() (bool, error)
- func (c *Client) DataBufferedAmount() uint64
- func (c *Client) GetStats() map[string]any
- func (c *Client) Listen(opts map[string]any)
- func (c *Client) PauseConsumers() (bool, error)
- func (c *Client) PauseSpeaking() (bool, error)
- func (c *Client) RequestKeyFrame() (bool, error)
- func (c *Client) RestartIce() (bool, error)
- func (c *Client) ResumeConsumers() (bool, error)
- func (c *Client) ResumeSpeaking(opts map[string]any) (bool, error)
- func (c *Client) SendData(payload any, label string) error
- func (c *Client) SetConsumerPreferredLayers(opts map[string]any) (bool, error)
- func (c *Client) SetConsumerPriority(priority int) (bool, error)
- func (c *Client) SetMaxSpatialLayer(n int) (bool, error)
- func (c *Client) SetRtpEncodingParameters(params map[string]any) (bool, error)
- func (c *Client) StartDataChannel(opts map[string]any) (bool, error)
- func (c *Client) StartSpeaking(opts map[string]any) (bool, error)
- func (c *Client) StopSpeaking(opts map[string]any)
- func (c *Client) StreamVideo(opts map[string]any) (bool, error)
- func (c *Client) UpdateIceServers(list []map[string]any) (bool, error)
- type ClientOptions
- type ConsumerStats
- type ConsumerTrack
- type ControlSender
- type DataMessageCallback
- type DataOptions
- type Metrics
- type Module
- type RecvTransport
- func (rt *RecvTransport) Close() error
- func (rt *RecvTransport) ConsumerIDs() []string
- func (rt *RecvTransport) ConsumerInfo(id string) (kind, priority string, ok bool)
- func (rt *RecvTransport) ConsumerKind(id string) string
- func (rt *RecvTransport) GetStats() []ConsumerStats
- func (rt *RecvTransport) HandleNewConsumer(ctx context.Context, req *mediasoup.NewConsumerRequest) error
- func (rt *RecvTransport) HandleNewDataConsumer(ctx context.Context, data json.RawMessage) error
- func (rt *RecvTransport) ID() string
- func (rt *RecvTransport) PeerConnection() *webrtc.PeerConnection
- func (rt *RecvTransport) RemoveConsumer(consumerID string)
- func (rt *RecvTransport) RemoveConsumersByProducerID(producerID string)
- func (rt *RecvTransport) RemoveDataConsumer(dataConsumerID string) bool
- func (rt *RecvTransport) RestartIce(ctx context.Context, ice mediasoup.IceParameters) error
- func (rt *RecvTransport) SetConsumersPaused(ids []string, paused bool) []string
- type RootModule
- type SendTransport
- func (st *SendTransport) Close() error
- func (st *SendTransport) CloseProducers(ctx context.Context, send ControlSender) error
- func (st *SendTransport) DataBufferedAmount() uint64
- func (st *SendTransport) DefaultDataLabel() string
- func (st *SendTransport) ID() string
- func (st *SendTransport) PauseProducers(ctx context.Context, send ControlSender) error
- func (st *SendTransport) PeerConnection() *webrtc.PeerConnection
- func (st *SendTransport) Produce(ctx context.Context, priority string) (string, error)
- func (st *SendTransport) ProduceData(ctx context.Context, opts DataOptions, appData map[string]any) (*webrtc.DataChannel, string, error)
- func (st *SendTransport) ProduceVideo(ctx context.Context, priority string) (string, error)
- func (st *SendTransport) ProducerIDs() []string
- func (st *SendTransport) ProducerKind(id string) string
- func (st *SendTransport) RestartIce(ice mediasoup.IceParameters) error
- func (st *SendTransport) ResumeProducers(ctx context.Context, send ControlSender) error
- func (st *SendTransport) SendDataMessage(label string, data []byte, text bool) error
- func (st *SendTransport) SetLayersActive(active []bool) error
- func (st *SendTransport) StopSpeaking()
- func (st *SendTransport) StreamAudio(frames [][]byte, duration time.Duration)
- func (st *SendTransport) StreamVideo(frames [][]byte, fps int, duration time.Duration)
- type StateChangeCallback
- type StatsCollector
- type VideoSample
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateMOS ¶
CalculateMOS estimates Mean Opinion Score (MOS) using simplified ITU-T G.107 E-model proxy.
NOTE: This is a proxy derived from RTP-layer stats (loss % and jitter ms), not MOS measured directly on received audio content — it does not replace listening tests in edge cases (Full load, SOS full load).
func CreateSyntheticIVFBytes ¶
CreateSyntheticIVFBytes creates a valid in-memory IVF VP8 container byte slice for testing.
func CreateWebRTCAPI ¶
CreateWebRTCAPI initializes the Pion WebRTC API instance with stats interceptor and media engines. If an SDPProfile is provided, custom Opus channels, clock rate, and payload type are registered.
func GenerateSilentOpusFrames ¶
GenerateSilentOpusFrames returns valid Opus silent frames (1-byte TOC + silence).
func GenerateTestPatternVP8Frames ¶
GenerateTestPatternVP8Frames creates minimal valid VP8 keyframe payloads for testing / fallback.
func RecordValue ¶
func RecordValue(ctx context.Context, samples chan<- metrics.SampleContainer, metric *metrics.Metric, val float64, tags *metrics.TagSet, t time.Time)
RecordValue pushes a sample point to k6 metrics engine. Many callers are background goroutines (notifications, DataChannel, recovery, stats polls) that outlive the run: once ctx (the VU's context) is done k6 stops draining samples, so the send gives up instead of blocking forever.
Types ¶
type AudioSample ¶
type AudioSample struct {
ID uint64 `json:"id" js:"id"`
Path string `json:"path" js:"path"`
Frames [][]byte `json:"-" js:"-"` // not exposed: large, only Go reads it
// LevelsDecoded is how many frames got a real level from decoding (the rest use the size heuristic).
LevelsDecoded int `json:"levelsDecoded" js:"levelsDecoded"`
// FrameCount is len(Frames), for scripts.
FrameCount int `json:"frameCount" js:"frameCount"`
}
AudioSample represents pre-parsed Opus frames loaded in RAM.
func LoadAudio ¶
func LoadAudio(filePath string) (*AudioSample, error)
LoadAudio loads an Ogg/Opus file into memory: one entry per Opus packet (20 ms), with the OpusHead/OpusTags header packets skipped, plus a per-frame audio level. Ponytail note: Read once into shared memory, reuse across thousands of VUs.
func ResolveAudioSample ¶
func ResolveAudioSample(val any) (*AudioSample, error)
ResolveAudioSample safely extracts or loads an AudioSample from various JS representations.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a single virtual user PTT endpoint.
func NewClient ¶
func NewClient(vu modules.VU, m *Metrics, opts ClientOptions) *Client
NewClient instantiates a new Client.
func (*Client) CanProduce ¶
CanProduce reports whether the router has a codec for the kind ("audio"/"video"), like mediasoup-client Device.canProduce. False before connect.
func (*Client) CloseSpeaking ¶
CloseSpeaking closes the producers on the SFU, the next startSpeaking produces new ones.
func (*Client) Connect ¶
Connect performs the signaling handshake, joins the room, and initializes RecvTransport.
func (*Client) DataBufferedAmount ¶
DataBufferedAmount is the bytes queued on the data producer (DataProducer.bufferedAmount).
func (*Client) GetStats ¶
GetStats returns the WebRTC stats reports of both transports ({send: {...}, recv: {...}}), like Transport/Producer/Consumer.getStats in mediasoup-client.
func (*Client) Listen ¶
Listen keeps the client active and polls stats periodically for the specified duration.
func (*Client) PauseConsumers ¶
PauseConsumers pauses receiving for every open consumer, locally and on the SFU (pauseConsumer).
func (*Client) PauseSpeaking ¶
PauseSpeaking pauses the audio/video producers (mic released, producers kept on the SFU).
func (*Client) RequestKeyFrame ¶
RequestKeyFrame asks the SFU for a key frame on every video consumer (requestConsumerKeyFrame).
func (*Client) RestartIce ¶
RestartIce restarts ICE on every transport, like calling mediasoup-client's transport.restartIce after the app's restartIce request.
func (*Client) ResumeConsumers ¶
ResumeConsumers resumes every consumer paused with PauseConsumers or by the SFU.
func (*Client) ResumeSpeaking ¶
ResumeSpeaking resumes paused producers and streams again with the same options as startSpeaking.
func (*Client) SendData ¶
SendData sends a payload on the data channel of label ("" or omitted = the first one opened). Strings and objects (as JSON) go as text like a browser's send(string), bytes as binary.
func (*Client) SetConsumerPreferredLayers ¶
SetConsumerPreferredLayers asks the SFU for a spatial/temporal layer on every video consumer (mediasoup-client Consumer.setPreferredLayers plus the app's setConsumerPreferredLayers).
func (*Client) SetConsumerPriority ¶
SetConsumerPriority sends setConsumerPriority for every consumer (app-level message of mediasoup-demo, the SFU uses it to share bandwidth between consumers).
func (*Client) SetMaxSpatialLayer ¶
SetMaxSpatialLayer sends simulcast layers 0..n only (Producer.setMaxSpatialLayer).
func (*Client) SetRtpEncodingParameters ¶
SetRtpEncodingParameters applies {encodings: [{active}]} per simulcast layer (Producer.setRtpEncodingParameters). Only "active" applies: the media is pre-encoded, so bitrate or resolution fields cannot change the stream.
func (*Client) StartDataChannel ¶
StartDataChannel opens the data producer. opts (optional) are mediasoup-client produceData options: label, protocol, ordered, maxPacketLifeTime, maxRetransmits.
func (*Client) StartSpeaking ¶
StartSpeaking initializes SendTransport if needed, registers producer, and transmits audio.
func (*Client) StopSpeaking ¶
StopSpeaking releases the mic. opts.mode: "stop" (default, only stops sending), "pause" (pauseProducer) or "close" (closeProducer). Which one GTalk uses is still to be confirmed. With floorControl, floorRelease follows in every mode.
func (*Client) StreamVideo ¶
StreamVideo starts standalone video streaming for PTV speaker.
type ClientOptions ¶
type ClientOptions struct {
ServerURL string `json:"serverUrl"`
RoomID any `json:"roomId"`
PeerID string `json:"peerId"`
Token string `json:"token"`
Priority string `json:"priority"`
InsecureSkipVerify bool `json:"insecureSkipVerify"`
DumpAudioPath string `json:"dumpAudioPath"`
// Media & Protocol Tuning
AudioChannels int `json:"audioChannels"`
OpusPayloadType int `json:"opusPayloadType"`
OpusClockRate int `json:"opusClockRate"`
EnableAudioLevelExt bool `json:"enableAudioLevelExt"`
EnableRTX bool `json:"enableRtx"`
ForceTCP bool `json:"forceTcp"`
StrictPriority bool `json:"strictPriority"`
SimulcastLayers int `json:"simulcastLayers"` // video simulcast encodings r0..rN-1 (0/1 = off, max 3)
ScalabilityMode string `json:"scalabilityMode"` // copied into video encodings (e.g. "L1T3")
IceServers []mediasoup.IceServer `json:"iceServers"` // STUN/TURN servers (RTCIceServer: urls, username, credential)
IceTransportPolicy string `json:"iceTransportPolicy"` // "all" (default) or "relay": media only through TURN
mediasoup.OpusOptions // opusStereo, opusFec, opusDtx, opusMaxPlaybackRate, opusMaxAverageBitrate, opusPtime
ServerStatsIntervalMs int `json:"serverStatsIntervalMs"` // poll getProducerStats/getConsumerStats (0 = off)
NackMaxPerPacket int `json:"nackMaxPerPacket"` // NACKs per missing packet (0 = 10, negative = unlimited)
SimulateRecvLossPercent float64 `json:"simulateRecvLossPercent"` // drop % of incoming RTP to exercise NACK/RTX towards the client
SimulateSendLossPercent float64 `json:"simulateSendLossPercent"` // drop % of outgoing RTP to exercise NACK
SendTransportOnJoin bool `json:"sendTransportOnJoin"` // create the send transport with the recv one, not at the first startSpeaking
TransportFirst bool `json:"transportFirst"` // create the recv transport before join (mediasoup-client order)
IceDisconnectedTimeoutMs int `json:"iceDisconnectedTimeoutMs"` // Pion ICE disconnected timeout (0 = 5000)
IceFailedTimeoutMs int `json:"iceFailedTimeoutMs"` // Pion ICE failed timeout after disconnected (0 = 25000)
AutoRestartIce *bool `json:"autoRestartIce"` // restart ICE when a transport goes disconnected/failed (default true)
RejoinOnReconnect *bool `json:"rejoinOnReconnect"` // join again after the WebSocket reconnected (default true)
ControlMode string `json:"controlMode"` // "request" (default) or "notification" for pause/resume/close messages
JoinPriority bool `json:"joinPriority"` // send priority in the join request (unconfirmed by backend)
FloorControl bool `json:"floorControl"` // GTalk floorRequest before speaking, floorRelease at stopSpeaking
// PTV & DataChannel Options (CSV Scenario parameters)
EnablePTV *bool `json:"enablePtv"`
PTVWidth int `json:"ptvWidth"`
PTVHeight int `json:"ptvHeight"`
PTVFPS int `json:"ptvFps"`
VideoCodec string `json:"videoCodec"`
EnableDataChannel *bool `json:"enableDataChannel"`
DataIntervalMs int `json:"dataIntervalMs"`
}
ClientOptions represents options passed from JS to new Client().
func (ClientOptions) IsAutoRestartIce ¶
func (o ClientOptions) IsAutoRestartIce() bool
func (ClientOptions) IsEnableDataChannel ¶
func (o ClientOptions) IsEnableDataChannel() bool
func (ClientOptions) IsEnablePTV ¶
func (o ClientOptions) IsEnablePTV() bool
func (ClientOptions) IsRejoinOnReconnect ¶
func (o ClientOptions) IsRejoinOnReconnect() bool
type ConsumerStats ¶
type ConsumerStats struct {
ConsumerID string
Kind string
SSRC uint32
Priority string
PacketsLost int64
PacketsTotal uint64
DeltaPackets uint64 // packets received since previous poll
DeltaLost int64 // packets lost since previous poll
// Residual loss after NACK/RTX repairs, as read by the application (see seqTracker).
ResidualExpected, ResidualLost int64
Jitter float64
Bitrate float64 // in bps
}
ConsumerStats holds extracted metrics from an active consumer.
type ConsumerTrack ¶
type ConsumerTrack struct {
ID string
ProducerID string
PeerID string
Kind string // "audio" | "video"
SSRC uint32
Priority string
Mid string // SFU-assigned rtpParameters.mid (arrival index when absent)
Exts []mediasoup.RtpHeaderExtension
RtxPT uint8
RtxSSRC uint32
Feedback []string
PT uint8 // payload type override (probator: 127)
Codec string // video codec name from the consumer (VP8, VP9, H264)
Track *webrtc.TrackRemote
LastBytesReceived uint64
LastPackets uint64
LastLost int64
LastStatsTime time.Time
// contains filtered or unexported fields
}
ConsumerTrack holds state and stats of an active consumer stream.
type ControlSender ¶
ControlSender delivers an app-level control message (request or notification, see ControlMode).
type DataMessageCallback ¶
DataMessageCallback receives incoming SCTP DataChannel messages.
type DataOptions ¶
type DataOptions struct {
Label string `json:"label"`
Protocol string `json:"protocol"`
Ordered *bool `json:"ordered"`
MaxPacketLifeTime *uint16 `json:"maxPacketLifeTime"`
MaxRetransmits *uint16 `json:"maxRetransmits"`
}
ProduceData registers the SCTP DataChannel producer on Mediasoup SFU. DataOptions are mediasoup-client produceData options (zero value = reliable, ordered "chat").
type Metrics ¶
type Metrics struct {
JoinDuration *metrics.Metric
Jitter *metrics.Metric
PacketLossRate *metrics.Metric
PacketsLost *metrics.Metric
PacketsReceived *metrics.Metric
Bitrate *metrics.Metric
MOS *metrics.Metric
ActiveSessions *metrics.Metric
ConnectionFailed *metrics.Metric
Errors *metrics.Metric
DataMessagesSent *metrics.Metric
DataMessagesReceived *metrics.Metric
DataSendLatency *metrics.Metric
VideoJitter *metrics.Metric
VideoPacketLossRate *metrics.Metric
VideoBitrate *metrics.Metric
FallbackUsed *metrics.Metric
ProducerControl *metrics.Metric
ConsumerStateChanges *metrics.Metric
ProducerScore *metrics.Metric
ConsumerScore *metrics.Metric
ConsumerProdScore *metrics.Metric
ConsumerLayers *metrics.Metric
ConsumerSpatialLayer *metrics.Metric
IceRestarts *metrics.Metric
QualitySamples *metrics.Metric
ServerLossRate *metrics.Metric
ServerJitter *metrics.Metric
ServerRTT *metrics.Metric
ServerBitrate *metrics.Metric
ServerNacks *metrics.Metric
ServerRetransmitted *metrics.Metric
ServerPlis *metrics.Metric
ServerTransportRecvBitrate *metrics.Metric
ServerTransportSendBitrate *metrics.Metric
ServerProbationBitrate *metrics.Metric
ServerAvailableOutgoing *metrics.Metric
ResidualLossRate *metrics.Metric
VideoResidualLossRate *metrics.Metric
RecoveryTime *metrics.Metric
Rejoins *metrics.Metric
RejoinDuration *metrics.Metric
FloorRequest *metrics.Metric
}
Metrics holds k6 metric descriptors.
func RegisterMetrics ¶
RegisterMetrics registers all PTT metrics into k6 registry.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module is the VU-specific module instance.
type RecvTransport ¶
type RecvTransport struct {
// contains filtered or unexported fields
}
RecvTransport manages the downstream WebRTC connection for audio consumption (Listener).
func NewRecvTransport ¶
func NewRecvTransport(protooCli *protoo.Client, params *mediasoup.TransportParams, api *webrtc.API, statsGetter stats.Getter, profile mediasoup.SDPProfile, onStateChange StateChangeCallback, onDataMessage DataMessageCallback, dumpAudioPath string, strictPriority bool) (*RecvTransport, error)
NewRecvTransport creates a RecvTransport.
func (*RecvTransport) Close ¶
func (rt *RecvTransport) Close() error
Close terminates the recv transport.
func (*RecvTransport) ConsumerIDs ¶
func (rt *RecvTransport) ConsumerIDs() []string
ConsumerIDs returns the ids of the open consumers.
func (*RecvTransport) ConsumerInfo ¶
func (rt *RecvTransport) ConsumerInfo(id string) (kind, priority string, ok bool)
ConsumerInfo returns kind and priority of an open consumer (ok is false when unknown).
func (*RecvTransport) ConsumerKind ¶
func (rt *RecvTransport) ConsumerKind(id string) string
ConsumerKind returns the media kind of an open consumer ("" when unknown).
func (*RecvTransport) GetStats ¶
func (rt *RecvTransport) GetStats() []ConsumerStats
GetStats collects stats across all active consumers and calculates real bitrate (Fix Issue 10).
func (*RecvTransport) HandleNewConsumer ¶
func (rt *RecvTransport) HandleNewConsumer(ctx context.Context, req *mediasoup.NewConsumerRequest) error
HandleNewConsumer processes a server request for a new incoming audio consumer.
func (*RecvTransport) HandleNewDataConsumer ¶
func (rt *RecvTransport) HandleNewDataConsumer(ctx context.Context, data json.RawMessage) error
HandleNewDataConsumer follows mediasoup-client's receiveDataChannel: create a negotiated DataChannel on the recv PC (id = streamId) and, the first time, add the m=application section.
func (*RecvTransport) PeerConnection ¶
func (rt *RecvTransport) PeerConnection() *webrtc.PeerConnection
PeerConnection exposes the PC for getStats and updateIceServers.
func (*RecvTransport) RemoveConsumer ¶
func (rt *RecvTransport) RemoveConsumer(consumerID string)
RemoveConsumer closes a consumer and renegotiates its m-section as closed (mediasoup-client's stopReceiving), so the section can be recycled by a later consumer of the same kind.
func (*RecvTransport) RemoveConsumersByProducerID ¶
func (rt *RecvTransport) RemoveConsumersByProducerID(producerID string)
RemoveConsumersByProducerID closes every consumer of a producer.
func (*RecvTransport) RemoveDataConsumer ¶
func (rt *RecvTransport) RemoveDataConsumer(dataConsumerID string) bool
RemoveDataConsumer closes the channel of a dataConsumerClosed notification. It reports whether the data consumer was known.
func (*RecvTransport) RestartIce ¶
func (rt *RecvTransport) RestartIce(ctx context.Context, ice mediasoup.IceParameters) error
RestartIce applies new SFU iceParameters, like mediasoup-client's recv handler: a new remote offer with the new credentials (Pion restarts ICE when the remote ufrag changes), then the answer.
func (*RecvTransport) SetConsumersPaused ¶
func (rt *RecvTransport) SetConsumersPaused(ids []string, paused bool) []string
SetConsumersPaused records the paused state of consumers (Consumer.pause/resume). Unknown ids are ignored. Returns the ids changed.
type RootModule ¶
type RootModule struct {
// contains filtered or unexported fields
}
RootModule represents the root extension module.
func (*RootModule) NewModuleInstance ¶
func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance
NewModuleInstance creates a new module instance for each VU.
type SendTransport ¶
type SendTransport struct {
// contains filtered or unexported fields
}
SendTransport manages the upstream WebRTC connection for audio/video publishing (Speaker).
func NewSendTransport ¶
func NewSendTransport(ctx context.Context, protooCli *protoo.Client, params *mediasoup.TransportParams, api *webrtc.API, profile mediasoup.SDPProfile, onStateChange StateChangeCallback) (*SendTransport, error)
NewSendTransport creates and negotiates a SendTransport with Mediasoup SFU.
func (*SendTransport) Close ¶
func (st *SendTransport) Close() error
Close terminates the send transport and peer connection.
func (*SendTransport) CloseProducers ¶
func (st *SendTransport) CloseProducers(ctx context.Context, send ControlSender) error
CloseProducers stops media, closes the producers on the SFU and forgets their ids, so the next StartSpeaking produces again (mediasoup-client Producer.close plus closeProducer).
func (*SendTransport) DataBufferedAmount ¶
func (st *SendTransport) DataBufferedAmount() uint64
DataBufferedAmount is the bytes queued on the data channel (DataProducer.bufferedAmount).
func (*SendTransport) DefaultDataLabel ¶ added in v0.2.0
func (st *SendTransport) DefaultDataLabel() string
DefaultDataLabel is the label of the first produced data channel ("" before any).
func (*SendTransport) PauseProducers ¶
func (st *SendTransport) PauseProducers(ctx context.Context, send ControlSender) error
PauseProducers stops sending media and tells the SFU (mediasoup-client Producer.pause with zeroRtpOnPause, plus the app's pauseProducer message).
func (*SendTransport) PeerConnection ¶
func (st *SendTransport) PeerConnection() *webrtc.PeerConnection
PeerConnection exposes the PC for getStats and updateIceServers.
func (*SendTransport) ProduceData ¶
func (st *SendTransport) ProduceData(ctx context.Context, opts DataOptions, appData map[string]any) (*webrtc.DataChannel, string, error)
ProduceData opens a DataChannel and registers it with produceData. The default reliable "chat" channel is created with the transport (so the first SDP has m=application), other options get a channel of their own on the already running SCTP association. The first produced channel is the default one (SendData without a label, periodic sender), each further label gets its own DataProducer, like calling mediasoup-client's produceData again. A known label is returned as is.
func (*SendTransport) ProduceVideo ¶
ProduceVideo registers the video producer on Mediasoup SFU for PTV.
func (*SendTransport) ProducerIDs ¶
func (st *SendTransport) ProducerIDs() []string
ProducerIDs returns the open audio/video producer ids.
func (*SendTransport) ProducerKind ¶
func (st *SendTransport) ProducerKind(id string) string
ProducerKind returns "audio"/"video" for one of this transport's producers ("" when unknown).
func (*SendTransport) RestartIce ¶
func (st *SendTransport) RestartIce(ice mediasoup.IceParameters) error
RestartIce applies new SFU iceParameters (from the restartIce request), like mediasoup-client's send handler: ICE-restart offer, then the remote answer rebuilt with the new credentials.
func (*SendTransport) ResumeProducers ¶
func (st *SendTransport) ResumeProducers(ctx context.Context, send ControlSender) error
ResumeProducers tells the SFU to resume, and the caller restarts the media writers.
func (*SendTransport) SendDataMessage ¶
func (st *SendTransport) SendDataMessage(label string, data []byte, text bool) error
SendDataMessage sends bytes through the SCTP DataChannel. SendDataMessage sends on the channel of label ("" = the default one). text sends a WebRTC string (PPID 51) like a browser's send(string), since mediasoup apps may ignore binary (e.g. the demo's bot).
func (*SendTransport) SetLayersActive ¶
func (st *SendTransport) SetLayersActive(active []bool) error
SetLayersActive enables/disables simulcast layers (lowest first), like setting encodings[i].active in mediasoup-client. Layers beyond the list keep their state.
func (*SendTransport) StopSpeaking ¶
func (st *SendTransport) StopSpeaking()
StopSpeaking cancels ongoing audio, video, and data transmissions.
func (*SendTransport) StreamAudio ¶
func (st *SendTransport) StreamAudio(frames [][]byte, duration time.Duration)
StreamAudio sends audio frames with 20ms pacing until duration expires or cancel is called.
func (*SendTransport) StreamVideo ¶
func (st *SendTransport) StreamVideo(frames [][]byte, fps int, duration time.Duration)
StreamVideo sends video frames paced by the configured FPS until duration expires or cancel is called.
type StateChangeCallback ¶
type StateChangeCallback func(transportType string, state webrtc.PeerConnectionState)
StateChangeCallback receives connection state changes.
type StatsCollector ¶
type StatsCollector struct {
// contains filtered or unexported fields
}
StatsCollector proxies stats.Getter across all PeerConnections on an API instance.
func (*StatsCollector) Add ¶
func (s *StatsCollector) Add(g stats.Getter)
type VideoSample ¶
type VideoSample struct {
ID uint64 `json:"id" js:"id"`
Path string `json:"path" js:"path"`
FourCC string `json:"fourcc" js:"fourcc"`
Width uint16 `json:"width" js:"width"`
Height uint16 `json:"height" js:"height"`
FPS int `json:"fps" js:"fps"`
NumFrames int `json:"numFrames" js:"numFrames"`
Frames [][]byte `json:"-" js:"-"` // not exposed: large, only Go reads it
}
VideoSample represents pre-parsed IVF video frames loaded in RAM.
func LoadVideo ¶
func LoadVideo(filePath string) (*VideoSample, error)
LoadVideo loads an IVF video file (VP8/VP9/AV1) into memory. Ponytail note: Read once into shared memory, reuse across thousands of VUs.
func ResolveVideoSample ¶
func ResolveVideoSample(val any) (*VideoSample, error)
ResolveVideoSample safely extracts or loads a VideoSample from various JS representations.