Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove setSimulcast function #467

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ classDiagram
+setStereo(sdp) string
+setDTX(sdp) string
+setVideoBitrate(sdp, bitrate) string
+setSimulcast(sdp, codec) string
}
class Logger {
<<Singleton>>
Expand Down
17 changes: 12 additions & 5 deletions packages/millicast-sdk/src/PeerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ export default class PeerConnection extends EventEmitter {
}
this.sessionDescription.sdp = SdpParser.setMultiopus(this.sessionDescription.sdp, mediaStream)
}

if (!options.disableVideo && options.simulcast) {
this.sessionDescription.sdp = SdpParser.setSimulcast(this.sessionDescription.sdp, options.codec)
}
if (options.absCaptureTime) {
this.sessionDescription.sdp = SdpParser.setAbsoluteCaptureTime(this.sessionDescription.sdp)
}
Expand Down Expand Up @@ -518,13 +514,24 @@ const addMediaStreamToPeer = (peer: RTCPeerConnection, mediaStream: MediaStream,

if (track.kind === 'video') {
initOptions.direction = !options.disableVideo ? 'sendonly' : 'inactive'
const encodings = []

if (options.scalabilityMode && new UserAgent().isChrome()) {
logger.debug(`Video track with scalability mode: ${options.scalabilityMode}.`)
initOptions.sendEncodings = [{ scalabilityMode: options.scalabilityMode } as RTCRtpEncodingParameters]
encodings.push({ scalabilityMode: options.scalabilityMode } as RTCRtpEncodingParameters)
} else if (options.scalabilityMode) {
logger.warn('SVC is only supported in Google Chrome')
}
if (options.simulcast) {
encodings.push(
{ rid: 'f', scaleResolutionDownBy: 1.0 },
{ rid: 'h', scaleResolutionDownBy: 2.0 },
{ rid: 'q', scaleResolutionDownBy: 4.0 }
)
}
if (encodings.length > 0) {
initOptions.sendEncodings = encodings
}
}

peer.addTransceiver(track, initOptions)
Expand Down
91 changes: 1 addition & 90 deletions packages/millicast-sdk/src/utils/SdpParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,95 +39,6 @@ const headerExtensionIdUppperRange = Array.from(
* @description Simplify SDP parser.
*/
const SdpParser = {
/**
* @function
* @name setSimulcast
* @description Parse SDP for support simulcast.
* **Only available in Chromium based browsers.**
* @param {String} sdp - Current SDP.
* @param {String} codec - Codec.
* @returns {String} SDP parsed with simulcast support.
* @example SdpParser.setSimulcast(sdp, 'h264')
*/
setSimulcast(sdp = '', codec = '') : string {
logger.info('Setting simulcast. Codec: ', codec)
const browserData = new UserAgent()
if (!browserData.isChromium()) {
logger.warn(
'Your browser does not appear to support Simulcast. For a better experience, use a Chromium based browser.'
)
return sdp
}
if (codec !== 'h264' && codec !== 'vp8') {
logger.warn(
`Your selected codec ${codec} does not appear to support Simulcast. To broadcast using simulcast, please use H.264 or VP8.`
)
return sdp
}
// Check if there is video available to set simulcast
if (!/m=video/.test(sdp)) {
logger.warn('There is no available video for simulcast to be enabled.')
return sdp
}

try {
const reg1 = new RegExp('m=video.*?a=ssrc:(\\d*) cname:(.+?)\\r\\n', 's')
const reg2 = new RegExp('m=video.*?a=ssrc:(\\d*) msid:(.+?)\\r\\n', 's')
// Get ssrc and cname and msid
const res1 = reg1.exec(sdp) ?? []
const ssrc = res1[1]
const cname = res1[2]
const res2 = reg2.exec(sdp) ?? []
const msid = res2[2]
// Add simulcasts ssrcs
const num = 2
const ssrcs = [ssrc]
for (let i = 0; i < num; ++i) {
// Create new ssrcs
const ssrc = 100 + i * 2
const rtx = ssrc + 1
// Add to ssrc list
ssrcs.push(ssrc.toString())
// Add sdp stuff
sdp +=
'a=ssrc-group:FID ' +
ssrc +
' ' +
rtx.toString() +
'\r\n' +
'a=ssrc:' +
ssrc.toString() +
' cname:' +
cname +
'\r\n' +
'a=ssrc:' +
ssrc.toString() +
' msid:' +
msid +
'\r\n' +
'a=ssrc:' +
rtx.toString() +
' cname:' +
cname +
'\r\n' +
'a=ssrc:' +
rtx.toString() +
' msid:' +
msid +
'\r\n'
}
// Add SIM group
sdp += 'a=ssrc-group:SIM ' + ssrcs.join(' ') + '\r\n'

logger.info('Simulcast setted')
logger.debug('Simulcast SDP: ', sdp)
return sdp
} catch (e) {
logger.error('Error setting SDP for simulcast: ', e)
throw e
}
},

/**
* @function
* @name setStereo
Expand Down Expand Up @@ -441,7 +352,7 @@ const SdpParser = {

// Checks if mediaStream has more than 2 audio channels.
const hasAudioMultichannel = (mediaStream: MediaStream) => {
return mediaStream.getAudioTracks().some((value) => value.getSettings().channelCount as number > 2)
return mediaStream.getAudioTracks().some((value) => (value.getSettings().channelCount as number) > 2)
}

export default SdpParser
Loading