Skip to content

Commit

Permalink
Remove unused Transceiver relevant functions
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Jan 25, 2023
1 parent 7661528 commit a7d3992
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ import org.webrtc.MediaStream
import org.webrtc.MediaStreamTrack
import org.webrtc.PeerConnection
import org.webrtc.RTCStatsReport
import org.webrtc.RtpParameters
import org.webrtc.RtpReceiver
import org.webrtc.RtpTransceiver
import org.webrtc.RtpTransceiver.RtpTransceiverInit
import org.webrtc.SessionDescription

/**
Expand Down Expand Up @@ -75,18 +73,6 @@ class StreamPeerConnection(
lateinit var connection: PeerConnection
private set

/**
* Transceiver used to send video in different resolutions.
*/
var videoTransceiver: RtpTransceiver? = null
private set

/**
* Transceiver used to send audio.
*/
var audioTransceiver: RtpTransceiver? = null
private set

/**
* Used to manage the stats observation lifecycle.
*/
Expand Down Expand Up @@ -208,108 +194,6 @@ class StreamPeerConnection(
}
}

/**
* Adds a local [MediaStreamTrack] with audio to a given [connection], with its [streamIds].
* The audio is then sent through a transceiver.
*
* @param track The track that contains audio.
* @param streamIds The IDs that represent the stream tracks.
*/
fun addAudioTransceiver(
track: MediaStreamTrack,
streamIds: List<String>
) {
logger.i { "[addAudioTransceiver] #sfu; #$typeTag; track: ${track.stringify()}, streamIds: $streamIds" }
val transceiverInit = buildAudioTransceiverInit(streamIds)

audioTransceiver = connection.addTransceiver(track, transceiverInit)
}

/**
* Creates the initialization configuration for the [RtpTransceiver], when sending audio.
*
* @param streamIds The list of stream IDs to bind to this transceiver.
*/
private fun buildAudioTransceiverInit(streamIds: List<String>): RtpTransceiverInit {
val fullQuality = RtpParameters.Encoding(
"a",
true,
1.0
).apply {
maxBitrateBps = 500_000
}

val encodings = listOf(fullQuality)

return RtpTransceiverInit(
RtpTransceiver.RtpTransceiverDirection.SEND_ONLY,
streamIds,
encodings
)
}

/**
* Adds a local [MediaStreamTrack] with video to a given [connection], with its [streamIds].
* The video is then sent in a few different resolutions using simulcast.
*
* @param track The track that contains video.
* @param streamIds The IDs that represent the stream tracks.
*/
fun addVideoTransceiver(track: MediaStreamTrack, streamIds: List<String>) {
logger.d { "[addVideoTransceiver] #sfu; #$typeTag; track: ${track.stringify()}, streamIds: $streamIds" }
val transceiverInit = buildVideoTransceiverInit(streamIds)

videoTransceiver = connection.addTransceiver(track, transceiverInit)
}

/**
* Creates the initialization configuration for the [RtpTransceiver], when sending video.
*
* @param streamIds The list of stream IDs to bind to this transceiver.
*/
private fun buildVideoTransceiverInit(streamIds: List<String>): RtpTransceiverInit {
/**
* We create different RTP encodings for the transceiver.
* Full quality, represented by "f" ID.
* Half quality, represented by "h" ID.
* Quarter quality, represented by "q" ID.
*
* Their bitrate is also roughly as the name states - maximum for "full", ~half of that
* for "half" and another half, or total quarter of maximum, for "quarter".
*/
val quarterQuality = RtpParameters.Encoding(
"q",
true,
4.0
).apply {
maxBitrateBps = 125_000
}

val halfQuality = RtpParameters.Encoding(
"h",
true,
2.0
).apply {
maxBitrateBps = 500_000
}

val fullQuality = RtpParameters.Encoding(
"f",
true,
1.0
).apply {
maxBitrateBps = 1_200_000
}

val encodings = listOf(quarterQuality, halfQuality, fullQuality)

return RtpTransceiverInit(
RtpTransceiver.RtpTransceiverDirection.SEND_ONLY,
streamIds,
encodings
)
}

/**
* Peer connection listeners.
*/
Expand Down Expand Up @@ -381,12 +265,10 @@ class StreamPeerConnection(
override fun onIceConnectionChange(newState: PeerConnection.IceConnectionState?) {
logger.i { "[onIceConnectionChange] #sfu; #$typeTag; newState: $newState" }
when (newState) {
PeerConnection.IceConnectionState.CLOSED, PeerConnection.IceConnectionState.FAILED, PeerConnection.IceConnectionState.DISCONNECTED -> {
statsJob?.cancel()
}
PeerConnection.IceConnectionState.CONNECTED -> {
statsJob = observeStats()
}
PeerConnection.IceConnectionState.CLOSED,
PeerConnection.IceConnectionState.FAILED,
PeerConnection.IceConnectionState.DISCONNECTED -> statsJob?.cancel()
PeerConnection.IceConnectionState.CONNECTED -> statsJob = observeStats()
else -> Unit
}
}
Expand Down Expand Up @@ -419,7 +301,6 @@ class StreamPeerConnection(
/**
* Domain - [PeerConnection] and [PeerConnection.Observer] related callbacks.
*/

override fun onRemoveTrack(receiver: RtpReceiver?) {
logger.i { "[onRemoveTrack] #sfu; #$typeTag; receiver: $receiver" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class WebRtcSessionManagerImpl(
result.onSuccess {
signalingClient.sendCommand(SignalingCommand.OFFER, offer.description)
}
logger.d { "[SDP] send offer: $offer" }
}

private suspend fun sendAnswer() {
Expand All @@ -250,13 +251,16 @@ class WebRtcSessionManagerImpl(
result.onSuccess {
signalingClient.sendCommand(SignalingCommand.ANSWER, answer.description)
}
logger.d { "[SDP] send answer: $answer" }
}

private fun handleOffer(sdp: String) {
logger.d { "[SDP] handle offer: $sdp" }
offer = sdp
}

private suspend fun handleAnswer(sdp: String) {
logger.d { "[SDP] handle answer: $sdp" }
peerConnection.setRemoteDescription(
SessionDescription(SessionDescription.Type.ANSWER, sdp)
)
Expand Down

0 comments on commit a7d3992

Please sign in to comment.