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

Integrate WebRTC with RESTful API for Milestone XProtect VMS #1051

Merged
merged 5 commits into from
Apr 28, 2024

Conversation

ggenny
Copy link

@ggenny ggenny commented Apr 18, 2024

This pull request adds a WebRTC module to the Milestone XProtect VMS by integrating it with RESTful API services for authentication, session creation, and session updates. The integration aims to streamline the process of establishing a WebRTC connection with an XProtect VMS via the API Gateway. This implementation adheres to the architectural principles outlined in the Milestone SDK WebRTC JavaScript Sample.

@AlexxIT AlexxIT self-assigned this Apr 18, 2024
@ggenny
Copy link
Author

ggenny commented Apr 22, 2024

I've noticed that the video is visible but the timestamp I receive is not correct. I'm not sure if this stems from a bug in the Milestone server. It appears to be 100 times smaller than it should be, and needs to be multiplied by a factor. The API includes a video speed factor, but it seems to only pertain to playback and not to live streaming. Is this correct, or am I missing a time factor/time scale somewhere that I haven't noticed in the stream negotiation?

diff --git a/internal/webrtc/milestone.go b/internal/webrtc/milestone.go
index f63f49e..947183d 100644
--- a/internal/webrtc/milestone.go
+++ b/internal/webrtc/milestone.go
@@ -229,6 +229,7 @@ func milestoneClient(rawURL string, query url.Values, desc string) (core.Produce
        prod := webrtc.NewConn(mc.PeerConnection)
        prod.Desc = "WebRTC/OpenIPC"
        prod.Mode = core.ModeActiveProducer
+       prod.TimeSpeed = 100
 
        resp, err := createWebRTCSession(mc, details)
        if err != nil {
diff --git a/pkg/webrtc/conn.go b/pkg/webrtc/conn.go
index 6483535..053da5b 100644
--- a/pkg/webrtc/conn.go
+++ b/pkg/webrtc/conn.go
@@ -15,6 +15,7 @@ type Conn struct {
        UserAgent string
        Desc      string
        Mode      core.Mode
+       TimeSpeed float32
 
        pc *webrtc.PeerConnection
 
@@ -99,6 +100,10 @@ func NewConn(pc *webrtc.PeerConnection) *Conn {
                                return
                        }
 
+                       if c.TimeSpeed != 0 {
+                               packet.Timestamp = uint32(float32(packet.Timestamp) * c.TimeSpeed)
+                       }
+
                        if len(packet.Payload) == 0 {
                                continue
                        }

@AlexxIT
Copy link
Owner

AlexxIT commented Apr 28, 2024

Thanks! I have made big code refactoring for your PR. I hope nothing breaks, because I can't test this code.

@AlexxIT
Copy link
Owner

AlexxIT commented Apr 28, 2024

I don't know about timespeed. Maybe some problems on milestone side. Because there is no problems with all other clients.

@AlexxIT AlexxIT merged commit 51c5d51 into AlexxIT:master Apr 28, 2024
@AlexxIT AlexxIT added this to the v1.9.0 milestone Apr 28, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Apr 30, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants