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

Add readRTX function for TrackRemote #2519

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 5 additions & 4 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ var (
errPeerConnWriteRTCPOpenWriteStream = errors.New("WriteRTCP failed to open WriteStream")
errPeerConnTranscieverMidNil = errors.New("cannot find transceiver with mid")

errRTPReceiverDTLSTransportNil = errors.New("DTLSTransport must not be nil")
errRTPReceiverReceiveAlreadyCalled = errors.New("Receive has already been called")
errRTPReceiverWithSSRCTrackStreamNotFound = errors.New("unable to find stream for Track with SSRC")
errRTPReceiverForRIDTrackStreamNotFound = errors.New("no trackStreams found for RID")
errRTPReceiverDTLSTransportNil = errors.New("DTLSTransport must not be nil")
errRTPReceiverReceiveAlreadyCalled = errors.New("Receive has already been called")
errRTPReceiverWithSSRCTrackStreamNotFound = errors.New("unable to find stream for Track with SSRC")
errRTPReceiverWithRtxSSRCTrackStreamNotFound = errors.New("unable to find stream for Track with RtxSSRC")
errRTPReceiverForRIDTrackStreamNotFound = errors.New("no trackStreams found for RID")

errRTPSenderTrackNil = errors.New("Track must not be nil")
errRTPSenderDTLSTransportNil = errors.New("DTLSTransport must not be nil")
Expand Down
77 changes: 77 additions & 0 deletions examples/read-rtx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# read-rtx
read-rtx is a simple application that shows how to record your webcam/microphone using Pion WebRTC and read packets from streams of rtp and rtx

## Instructions
### Download read-rtx
```
export GO111MODULE=on
go get github.com/pion/webrtc/v3/examples/read-rtx
```

### Open read-rtx example page
[jsfiddle.net](https://jsfiddle.net/s179hacu/) you should see your Webcam, two text-areas and two buttons: `Copy browser SDP to clipboard`, `Start Session`.

### Run read-rtx, with your browsers SessionDescription as stdin
In the jsfiddle the top textarea is your browser's Session Description. Press `Copy browser SDP to clipboard` or copy the base64 string manually.
We will use this value in the next step.

#### Linux/macOS
Run `echo $BROWSER_SDP | read-rtx`

or

Run `cd examples/read-rtx` and then
`echo $BROWSER_SDP | go run .`

#### Windows
1. Paste the SessionDescription into a file.
1. Run `read-rtx < my_file`

### Input read-rtx's SessionDescription into your browser
Copy the text that `read-rtx` just emitted and copy into second text area

### Hit 'Start Session'
You will see output like below:
```bash
Connection State has changed connected
Ctrl+C the remote client to stop the demo
Got Audio track hasRTX: false
Got Video track hasRTX: true
Got RTX padding packets. rtx sn: 24254
Got RTX padding packets. rtx sn: 24255
Send Nack sequence:17721
Got RTX Packet. osn: 17721 , rtx sn: 24256
Send Nack sequence:17791
Got RTX Packet. osn: 17791 , rtx sn: 24257
Send Nack sequence:17857
Got RTX Packet. osn: 17857 , rtx sn: 24258
Send Nack sequence:17929
Got RTX Packet. osn: 17929 , rtx sn: 24259
Send Nack sequence:17999
Got RTX Packet. osn: 17999 , rtx sn: 24260
Send Nack sequence:18063
Got RTX Packet. osn: 18063 , rtx sn: 24261
Send Nack sequence:18123
Got RTX Packet. osn: 18123 , rtx sn: 24262
Got RTX padding packets. rtx sn: 24263
Got RTX Packet. osn: 18185 , rtx sn: 24264
Got RTX padding packets. rtx sn: 24265
Got RTX Packet. osn: 18186 , rtx sn: 24266
Got RTX padding packets. rtx sn: 24267
Got RTX Packet. osn: 18184 , rtx sn: 24268
Got RTX Packet. osn: 18183 , rtx sn: 24269
Got RTX Packet. osn: 18182 , rtx sn: 24270
Got RTX Packet. osn: 18181 , rtx sn: 24271
Got RTX Packet. osn: 18180 , rtx sn: 24272
Got RTX Packet. osn: 18179 , rtx sn: 24273
Got RTX Packet. osn: 18178 , rtx sn: 24274
Send Nack sequence:18190
Got RTX Packet. osn: 18190 , rtx sn: 24275
Send Nack sequence:18303
Got RTX Packet. osn: 18303 , rtx sn: 24276
Send Nack sequence:18434
Got RTX Packet. osn: 18434 , rtx sn: 24277
Send Nack sequence:18608
Got RTX Packet. osn: 18608 , rtx sn: 24278

```
8 changes: 8 additions & 0 deletions examples/read-rtx/jsfiddle/demo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
SPDX-License-Identifier: MIT
*/
textarea {
width: 500px;
min-height: 75px;
}
8 changes: 8 additions & 0 deletions examples/read-rtx/jsfiddle/demo.details
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
# SPDX-License-Identifier: MIT

name: read-rtx
description: Example of using Pion WebRTC to read rtx packet
authors:
- San9H0 <[email protected]> <[email protected]>
23 changes: 23 additions & 0 deletions examples/read-rtx/jsfiddle/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
SPDX-License-Identifier: MIT
-->
Browser base64 Session Description<br />
<textarea id="localSessionDescription" readonly="true"></textarea> <br />
<button onclick="window.copySDP()">
Copy browser SDP to clipboard
</button>
<br />
<br />

Golang base64 Session Description<br />
<textarea id="remoteSessionDescription"></textarea> <br/>
<button onclick="window.startSession()"> Start Session </button><br />

<br />

Video<br />
<video id="video1" width="160" height="120" autoplay muted></video> <br />

Logs<br />
<div id="logs"></div>
58 changes: 58 additions & 0 deletions examples/read-rtx/jsfiddle/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-env browser */

// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

const pc = new RTCPeerConnection({
iceServers: [
{
urls: 'stun:stun.l.google.com:19302'
}
]
})
const log = msg => {
document.getElementById('logs').innerHTML += msg + '<br>'
}

navigator.mediaDevices.getUserMedia({ video: true, audio: true })
.then(stream => {
document.getElementById('video1').srcObject = stream
stream.getTracks().forEach(track => pc.addTrack(track, stream))

pc.createOffer().then(d => pc.setLocalDescription(d)).catch(log)
}).catch(log)

pc.oniceconnectionstatechange = e => log(pc.iceConnectionState)
pc.onicecandidate = event => {
if (event.candidate === null) {
document.getElementById('localSessionDescription').value = btoa(JSON.stringify(pc.localDescription))
}
}

window.startSession = () => {
const sd = document.getElementById('remoteSessionDescription').value
if (sd === '') {
return alert('Session Description must not be empty')
}

try {
pc.setRemoteDescription(JSON.parse(atob(sd)))
} catch (e) {
alert(e)
}
}

window.copySDP = () => {
const browserSDP = document.getElementById('localSessionDescription')

browserSDP.focus()
browserSDP.select()

try {
const successful = document.execCommand('copy')
const msg = successful ? 'successful' : 'unsuccessful'
log('Copying SDP was ' + msg)
} catch (err) {
log('Unable to copy SDP ' + err)
}
}
Loading
Loading