mediasoup v3 API 之三 Producer Consumer & RtpObserver

Producer

ProducerOptions

FieldTypeDescriptionRequiredDefault
kindMediaKind媒体类型audio或者videoYes
rtpParametersRtpSendParameters发送端的rtp参数,produce出来的类型Yes
pausedBooleanstart之后,end端,建议先pause,等待resume,建议给true,后续跟进需要resumeNofalse
keyFrameRequestDelayNumbervideo才有.询问key frame的间隔No0
appDataObjectCustom application data.No{}

ProducerScore

FieldTypeDescriptionRequiredDefault
encodingIdxNumberProducer rtpParams array indexYes
ssrcNumberRTP stream SSRC.Yes
ridStringRTP stream RID value.No
scoreNumberRTP stream score (from 0 to 10) representing the transmission quality.Yes

ProducerVideoOrientation

FieldTypeDescriptionRequiredDefault
cameraBoolean摄像头数据源Yes
flipBoolean视频资源是否被翻转Yes
rotationNumber旋转0,80,180,270度Yes

ProducerTraceEventData

FieldTypeDescriptionRequiredDefault
typeProducerTraceEventTypeTrace event type.Yes
timestampNumberEvent timestamp.Yes
directionString“in” (icoming direction) or “out” (outgoing direction).Yes
infoObjectPer type specific information.Yes

Enums

ProducerType

ValueDescription
“simple”A single RTP stream is received with no spatial/temporal layers.
“simulcast”Two or more RTP streams are received, each of them with one or more temporal layers.
“svc”A single RTP stream is received with spatial/temporal layers.

ProducerTraceEventType

ValueDescription
“rtp”RTP packet.
“keyframe”RTP video keyframe packet.
“nack”RTCP NACK packet.
“pli”RTCP PLI packet.
“fir”RTCP FIR packet.

Properties

producer.id
producer.closed
producer.kind
producer.rtpParameters
producer.type // single,simulcast, svc ?
producer.paused // resume 最好先判断确认,使用该域
producer.score // 表示的实际是传输的质量
producer.appData
producer.observer

Methods

producer.close()
// 触发 producerclose 事件
producer.getStats()
producer.pause()
producer.resume()
producer.enableTraceEvent(types)

Events

producer.on(“transportclose”, fn())
producer.on(“score”, fn(score)) // SCORE 发生变化
producer.on(“videoorientationchange”, fn(videoOrientation))
// urn:3gpp:video-orientation,该选项如果被协商设置,那么才会触发该事件。主要针对的是摄像头设备被旋转了的情况
producer.on(“trace”, fn(trace))

producer.observer.on(“close”, fn())
producer.observer.on(“pause”, fn())
producer.observer.on(“resume”, fn())
producer.observer.on(“score”, fn(score))
producer.observer.on(“videoorientationchange”, fn(videoOrientation))
producer.observer.on(“trace”, fn(trace))

Consumer

ConsumerOptions

FieldTypeDescriptionRequiredDefault
producerIdStringThe id of the producer to consume.Yes
rtpCapabilitiesRtpCapabilitiesRTP capabilities of the consuming endpoint.Yes
pausedBooleanpause模式启动,详见下面Note.Nofalse
preferredLayersConsumerLayersPreferred spatial and temporal layer for simulcast or SVC media sources. If unset, the highest ones are selected.No
appDataObjectCustom application data.No{ }

Note:
建议先 pause 启动,根据需要 resume。

ConsumerLayers

FieldTypeDescriptionRequiredDefault
spatialLayerNumberThe spatial layer index (from 0 to N).Yes
temporalLayerNumberThe temporal layer index (from 0 to N).No

ConsumerScore

FieldTypeDescriptionRequiredDefault
scoreNumberScore of the RTP stream in the consumer (from 0 to 10) representing its transmission quality.Yes
producerScoreNumberScore of the currently selected RTP stream in the associated producer (from 0 to 10) representing its transmission quality.Yes
producerScoresArray单producer多RTP流,仅适用于Sulmcast场景Yes

ConsumerTraceEventData

FieldTypeDescriptionRequiredDefault
typeConsumerTraceEventTypeTrace event type.Yes
timestampNumberEvent timestamp.Yes
directionString“in” (icoming direction) or “out” (outgoing direction).Yes
infoObjectPer type specific information.Yes

Enums

ConsumerType

ValueDescription
“simple”A single RTP stream is sent with no spatial/temporal layers.
“simulcast”Two or more RTP streams are sent, each of them with one or more temporal layers.
“svc”A single RTP stream is sent with spatial/temporal layers.
“pipe”Special type for consumers created on a PipeTransport.

ConsumerTraceEventType

ValueDescription
“rtp”RTP packet.
“keyframe”RTP video keyframe packet.
“nack”RTCP NACK packet.
“pli”RTCP PLI packet.
“fir”RTCP FIR packet.

Properties

consumer. id
consumer.producerId
consumer.closed
consumer.kind
consumer.rtpParameters
consumer.type
consumer.paused
consumer.producerPaused
consumer.preferredLayers
consumer.currentLayers
// simulcast and SVC 模式下使用
consumer.priority
// 见 Method setPriority()
consumer.appData
consumer.observer

Methods

consumer.close()
consumer.getStats()
consumer.pause()
// if paused, no RTP will be sent to the consuming endpoint
consumer.resume()
consumer.setPreferredLayers(preferredLayers)
consumer.setPriority(priority)
// priority 会影响到transport中outgoing bitrate 在其他所有consumer中的分发:重新按照 priority 分排。
// 该选项只会在 该transport 中的outgoing bitrate评估不够的情况下,才会生效,按照priority分发。
consumer.unsetPriority()
consumer.requestKeyFrame()
// just for video
consumer.enableTraceEvent(types)

Events

consumer.on(“transportclose”, fn())
consumer.on(“producerclose”, fn())
consumer.on(“producerpause”, fn())
consumer.on(“producerresume”, fn())
consumer.on(“score”, fn(score))
consumer.on(“layerschange”, fn(layers))
consumer.on(“trace”, fn(trace))

consumer.observer.on(“close”, fn())
consumer.observer.on(“pause”, fn())
consumer.observer.on(“resume”, fn())
consumer.observer.on(“score”, fn(score))
consumer.observer.on(“layerschange”, fn(layers))
consumer.observer.on(“trace”, fn(trace))

DataProducer & DataConsumer

基于 SCTP 或者 direct 方式的 producer & consumer

DataProducerOptions

FieldTypeDescriptionRequiredDefault
sctpStreamParametersSctpStreamParameters不能用于DirectTransport中,确认如果使用SCTP/DataChannel,给定该参数No
labelStringDataChannel标识No
protocolStringName of the sub-protocol used by this DataChannel.No
appDataObjectCustom application data.No{ }

SctpStreamParameters

FieldTypeDescriptionRequiredDefault
streamIdNumberSCTP stream idtrue
orderedBooleanWhether data messages must be received in order. if true the messages will be sent reliably.Notrue
maxPacketLifeTimeNumberWhen ordered is false indicates the time (in milliseconds) after which a SCTP packet will stop being retransmitted.No
maxRetransmitsNumberWhen ordered is false indicates the maximum number of times a packet will be retransmitted.No
  • If ordered is true then maxPacketLifeTime and maxRetransmits must be false.
  • If ordered if false, only one of maxPacketLifeTime or maxRetransmits can be true.

DataConsumerOptions

FieldTypeDescriptionRequiredDefault
dataProducerIdStringThe id of the data producer to consume.Yes
orderedBooleanSCTP 传输生效. 按序接收,如果true,发送端reliably 发送.NoThe value in the data producer (if it’s of type ‘sctp’) or true (if it’s of type ‘direct’).
maxPacketLifeTimeNumberSCTP 传输生效. When ordered is false, it indicates the time (in milliseconds) after which a SCTP packet will stop being retransmitted.NoThe value in the data producer (if it’s of type ‘sctp’) or unset (if it’s of type ‘direct’).
maxRetransmitsNumberSCTP 传输生效. When ordered is false, it indicates the maximum number of times a packet will be retransmitted.NoThe value in the data producer (if it’s of type ‘sctp’) or unset (if it’s of type ‘direct’).
appDataObjectCustom application data.No{ }

RtpObserver

Properties

rtpObserver.id
rtpObserver.closed
rtpObserver.paused
rtpObserver.appData
rtpObserver.observer

Methods

rtpObserver.close()
rtpObserver.pause()
rtpObserver.resume()
rtpObserver.addProducer(producer)
rtpObserver.removeProducer(producer)

Events

rtpObserver.on(“routerclose”)

Observer Events

rtpObserver.observer.on(“close”, fn())
rtpObserver.observer.on(“pause”, fn())
rtpObserver.observer.on(“resume”, fn())
rtpObserver.observer.on(“addproducer”, fn(producer))
rtpObserver.observer.on(“removeproducer”, fn(producer))

AudioLevelObserver

audio level observer 监控的是被选中的 audio producer 的音量。并且,仅监控 audio producer。

Dictionaries

AudioLevelObserverOptions

FieldTypeDescriptionRequiredDefault
maxEntriesNumberMaximum number of entries in the “volumes” event.No1
thresholdNumberMinimum average volume (in dBvo from -127 to 0) for entries in the “volumes” event.No-80
intervalNumberInterval in ms for checking audio volumes.No1000
appDataObjectCustom application data.No{ }

AudioLevelObserverVolume

FieldTypeDescriptionRequiredDefault
producerProducerThe audio producer instance.Yes
volumeNumberThe average volume (in dBvo from -127 to 0) of the audio producer in the last interval.Yes
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值