Compare commits

...

15 Commits

Author SHA1 Message Date
Cedric Verstraeten
cf3e491462 upgrade bento4 2025-02-11 12:12:04 +01:00
Cedric Verstraeten
6068705c07 Merge branch 'master' of https://github.com/kerberos-io/agent 2025-02-09 19:28:03 +01:00
Cedric Verstraeten
37beaa64d7 delay sending response answer 2025-02-09 19:28:01 +01:00
Cédric Verstraeten
8c5b03487b Merge pull request #165 from kerberos-io/fix/iceconnection-state-event
Correct peerconnection states + proper cleanup peerconnection
2025-02-09 11:50:35 +01:00
Cedric Verstraeten
360ae0c0db correct peerconnection states 2025-02-09 11:01:54 +01:00
Cédric Verstraeten
6aad8b7b35 Merge pull request #164 from kerberos-io/fix/webrtc-packettimestamp
Fix / WebRTC skip AAC audio + introduce packet timestamps
2025-02-06 10:38:40 +01:00
Cedric Verstraeten
9ce037fdc0 Update main.go 2025-02-06 10:35:36 +01:00
Cedric Verstraeten
0eb77ccd16 Update main.go 2025-02-06 10:15:47 +01:00
Cedric Verstraeten
fb876bd216 Update main.go 2025-02-06 08:32:30 +01:00
Cédric Verstraeten
865aec88fc Merge pull request #163 from kerberos-io/fix/webrtc-sample-timing
Fix / WebRTC sample timing
2025-02-06 08:32:04 +01:00
Cedric Verstraeten
9792bdf494 Update main.go 2025-02-06 08:28:17 +01:00
Cedric Verstraeten
d836e89e7f upgrade to v3.3.3 2025-02-05 20:55:08 +01:00
Cédric Verstraeten
53a52b3594 Merge pull request #162 from kerberos-io/fix/webrtc-sample-duration
fix / revert to old webrtc sample format (duration instead of packettimestamp)
2025-02-05 20:54:18 +01:00
Cedric Verstraeten
ba6ce25b21 revert to old webrtc sample format (duration instead of packettimestamp) 2025-02-05 20:50:57 +01:00
Cedric Verstraeten
8c9e18475f Update README.md 2025-01-31 16:35:11 +01:00
4 changed files with 32 additions and 26 deletions

View File

@@ -61,7 +61,7 @@ RUN /dist/agent/main version
###############################################
# Build Bento4 -> we want fragmented mp4 files
ENV BENTO4_VERSION 1.6.0-639
ENV BENTO4_VERSION 1.6.0-641
RUN cd /tmp && git clone https://github.com/axiomatic-systems/Bento4 && cd Bento4 && \
git checkout tags/v${BENTO4_VERSION} && \
cd Build && \

View File

@@ -413,7 +413,7 @@ Read more about this [at the FAQ](#faq) below.
## Contributors
This project exists thanks to all the people who contribute.
This project exists thanks to all the people who contribute. Bravo!
<a href="https://github.com/kerberos-io/agent/graphs/contributors">
<img src="https://contrib.rocks/image?repo=kerberos-io/agent" />

View File

@@ -23,7 +23,7 @@ import (
"github.com/kerberos-io/agent/machinery/src/models"
)
const VERSION = "3.3.1"
const VERSION = "3.3.5"
const letterBytes = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

View File

@@ -64,7 +64,6 @@ func CreateWebRTC(name string, stunServers []string, turnServers []string, turnS
TurnServersUsername: turnServersUsername,
TurnServersCredential: turnServersCredential,
Timer: time.NewTimer(time.Second * 10),
PacketsCount: make(chan int),
}
}
@@ -167,35 +166,37 @@ func InitializeWebRTCConnection(configuration *models.Configuration, communicati
log.Log.Error("webrtc.main.InitializeWebRTCConnection(): something went wrong while adding audio track: " + err.Error())
}
peerConnection.OnICEConnectionStateChange(func(connectionState pionWebRTC.ICEConnectionState) {
if connectionState == pionWebRTC.ICEConnectionStateDisconnected {
atomic.AddInt64(&peerConnectionCount, -1)
peerConnection.OnConnectionStateChange(func(connectionState pionWebRTC.PeerConnectionState) {
if connectionState == pionWebRTC.PeerConnectionStateDisconnected || connectionState == pionWebRTC.PeerConnectionStateClosed {
// Set lock
CandidatesMutex.Lock()
atomic.AddInt64(&peerConnectionCount, -1)
peerConnections[handshake.SessionID] = nil
_, ok := CandidateArrays[sessionKey]
if ok {
close(CandidateArrays[sessionKey])
delete(CandidateArrays, sessionKey)
}
CandidatesMutex.Unlock()
close(w.PacketsCount)
if err := peerConnection.Close(); err != nil {
log.Log.Error("webrtc.main.InitializeWebRTCConnection(): something went wrong while closing peer connection: " + err.Error())
}
} else if connectionState == pionWebRTC.ICEConnectionStateConnected {
CandidatesMutex.Unlock()
} else if connectionState == pionWebRTC.PeerConnectionStateConnected {
CandidatesMutex.Lock()
atomic.AddInt64(&peerConnectionCount, 1)
} else if connectionState == pionWebRTC.ICEConnectionStateChecking {
CandidatesMutex.Unlock()
} else if connectionState == pionWebRTC.PeerConnectionStateConnecting {
// Iterate over the candidates and send them to the remote client
// Non blocking channel
// Non blocking channe
for candidate := range CandidateArrays[sessionKey] {
CandidatesMutex.Lock()
log.Log.Info("webrtc.main.InitializeWebRTCConnection(): Received candidate from channel: " + candidate)
if candidateErr := peerConnection.AddICECandidate(pionWebRTC.ICECandidateInit{Candidate: string(candidate)}); candidateErr != nil {
log.Log.Error("webrtc.main.InitializeWebRTCConnection(): something went wrong while adding candidate: " + candidateErr.Error())
}
CandidatesMutex.Unlock()
}
} else if connectionState == pionWebRTC.ICEConnectionStateFailed {
} else if connectionState == pionWebRTC.PeerConnectionStateFailed {
log.Log.Info("webrtc.main.InitializeWebRTCConnection(): ICEConnectionStateFailed")
}
log.Log.Info("webrtc.main.InitializeWebRTCConnection(): connection state changed to: " + connectionState.String())
@@ -217,9 +218,10 @@ func InitializeWebRTCConnection(configuration *models.Configuration, communicati
// When an ICE candidate is available send to the other peer using the signaling server (MQTT).
// The other peer will add this candidate by calling AddICECandidate
peerConnection.OnICECandidate(func(candidate *pionWebRTC.ICECandidate) {
if candidate == nil {
if candidate == nil || peerConnection.ICEConnectionState() == pionWebRTC.ICEConnectionStateConnected {
return
}
// Create a config map
valueMap := make(map[string]interface{})
candateJSON := candidate.ToJSON()
@@ -271,6 +273,7 @@ func InitializeWebRTCConnection(configuration *models.Configuration, communicati
}
payload, err := models.PackageMQTTMessage(configuration, message)
if err == nil {
time.Sleep(1000 * time.Millisecond)
token := mqttClient.Publish("kerberos/hub/"+hubKey, 2, false, payload)
token.Wait()
} else {
@@ -341,8 +344,8 @@ func WriteToTrack(livestreamCursor *packets.QueueCursor, configuration *models.C
var cursorError error
var pkt packets.Packet
//var previousTimeVideo int64
//var previousTimeAudio int64
var previousTimeVideo int64
var previousTimeAudio int64
start := false
receivedKeyFrame := false
@@ -401,16 +404,17 @@ func WriteToTrack(livestreamCursor *packets.QueueCursor, configuration *models.C
if pkt.IsVideo {
// Calculate the difference
//bufferDuration := pkt.Time - previousTimeVideo
//previousTimeVideo = pkt.Time
bufferDuration := pkt.Time - previousTimeVideo
previousTimeVideo = pkt.Time
// Start at the first keyframe
if pkt.IsKeyFrame {
start = true
}
if start {
//bufferDurationCasted := time.Duration(bufferDuration) * time.Millisecond
sample := pionMedia.Sample{Data: pkt.Data, PacketTimestamp: uint32(pkt.Time)}
bufferDurationCasted := time.Duration(bufferDuration) * time.Millisecond
sample := pionMedia.Sample{Data: pkt.Data, Duration: bufferDurationCasted, PacketTimestamp: uint32(pkt.Time)}
//sample = pionMedia.Sample{Data: pkt.Data, Duration: time.Second}
if config.Capture.ForwardWebRTC == "true" {
// We will send the video to a remote peer
// TODO..
@@ -430,15 +434,17 @@ func WriteToTrack(livestreamCursor *packets.QueueCursor, configuration *models.C
// We will transcode the audio
// TODO..
//d := fdkaac.NewAacDecoder()
continue
}
// Calculate the difference
//bufferDuration := pkt.Time - previousTimeAudio
//previousTimeAudio = pkt.Time
bufferDuration := pkt.Time - previousTimeAudio
previousTimeAudio = pkt.Time
// We will send the audio
//bufferDurationCasted := time.Duration(bufferDuration) * time.Millisecond
sample := pionMedia.Sample{Data: pkt.Data, PacketTimestamp: uint32(pkt.Time)}
bufferDurationCasted := time.Duration(bufferDuration) * time.Millisecond
sample := pionMedia.Sample{Data: pkt.Data, Duration: bufferDurationCasted, PacketTimestamp: uint32(pkt.Time)}
//sample = pionMedia.Sample{Data: pkt.Data, Duration: time.Second}
if err := audioTrack.WriteSample(sample); err != nil && err != io.ErrClosedPipe {
log.Log.Error("webrtc.main.WriteToTrack(): something went wrong while writing sample: " + err.Error())
}