mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 15:02:19 +00:00
Update package webrtc with Quality structure
This commit is contained in:
parent
340d0447a8
commit
34200afaed
@ -6,50 +6,43 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"gitlab.crans.org/nounous/ghostream/stream"
|
"gitlab.crans.org/nounous/ghostream/messaging"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
func autoIngest(streams *messaging.Streams) {
|
||||||
activeStream map[string]struct{}
|
// Subscribe to new stream event
|
||||||
)
|
event := make(chan string, 8)
|
||||||
|
streams.Subscribe(event)
|
||||||
|
|
||||||
func autoIngest(streams map[string]*stream.Stream) {
|
// For each new stream
|
||||||
// Regulary check existing streams
|
for name := range event {
|
||||||
activeStream = make(map[string]struct{})
|
// Get stream
|
||||||
for {
|
stream, err := streams.Get(name)
|
||||||
for name, st := range streams {
|
if err != nil {
|
||||||
if strings.Contains(name, "@") {
|
log.Printf("Failed to get stream '%s'", name)
|
||||||
// Not a source stream, pass
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := activeStream[name]; ok {
|
// Get specific quality
|
||||||
// Stream is already ingested
|
// FIXME: make it possible to forward other qualities
|
||||||
continue
|
qualityName := "source"
|
||||||
|
quality, err := stream.GetQuality(qualityName)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to get quality '%s'", qualityName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start ingestion
|
// Start forwarding
|
||||||
log.Printf("Starting webrtc for '%s'", name)
|
log.Printf("Starting webrtc for '%s' quality '%s'", name, qualityName)
|
||||||
go ingest(name, st)
|
go ingest(name, quality)
|
||||||
}
|
|
||||||
|
|
||||||
// Regulary pull stream list,
|
|
||||||
// it may be better to tweak the messaging system
|
|
||||||
// to get an event on a new stream.
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ingest(name string, input *stream.Stream) {
|
func ingest(name string, q *messaging.Quality) {
|
||||||
// Register to get stream
|
// Register to get stream
|
||||||
videoInput := make(chan []byte, 1024)
|
videoInput := make(chan []byte, 1024)
|
||||||
input.Register(videoInput)
|
q.Register(videoInput)
|
||||||
activeStream[name] = struct{}{}
|
|
||||||
|
|
||||||
// Open a UDP Listener for RTP Packets on port 5004
|
// Open a UDP Listener for RTP Packets on port 5004
|
||||||
videoListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5004})
|
videoListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5004})
|
||||||
@ -146,7 +139,7 @@ func ingest(name string, input *stream.Stream) {
|
|||||||
if err = audioListener.Close(); err != nil {
|
if err = audioListener.Close(); err != nil {
|
||||||
log.Printf("Faited to close UDP listener: %s", err)
|
log.Printf("Faited to close UDP listener: %s", err)
|
||||||
}
|
}
|
||||||
delete(activeStream, name)
|
q.Unregister(videoInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startFFmpeg(in <-chan []byte) (ffmpeg *exec.Cmd, err error) {
|
func startFFmpeg(in <-chan []byte) (ffmpeg *exec.Cmd, err error) {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
|
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
|
||||||
"gitlab.crans.org/nounous/ghostream/stream"
|
"gitlab.crans.org/nounous/ghostream/messaging"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options holds web package configuration
|
// Options holds web package configuration
|
||||||
@ -182,7 +182,7 @@ func getPayloadType(m webrtc.MediaEngine, codecType webrtc.RTPCodecType, codecNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Serve WebRTC media streaming server
|
// Serve WebRTC media streaming server
|
||||||
func Serve(streams map[string]*stream.Stream, remoteSdpChan chan struct {
|
func Serve(streams *messaging.Streams, remoteSdpChan chan struct {
|
||||||
StreamID string
|
StreamID string
|
||||||
RemoteDescription webrtc.SessionDescription
|
RemoteDescription webrtc.SessionDescription
|
||||||
}, localSdpChan chan webrtc.SessionDescription, cfg *Options) {
|
}, localSdpChan chan webrtc.SessionDescription, cfg *Options) {
|
||||||
|
@ -5,12 +5,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"gitlab.crans.org/nounous/ghostream/stream"
|
"gitlab.crans.org/nounous/ghostream/messaging"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServe(t *testing.T) {
|
func TestServe(t *testing.T) {
|
||||||
// Init streams messaging and WebRTC server
|
// Init streams messaging and WebRTC server
|
||||||
streams := make(map[string]*stream.Stream)
|
streams := messaging.New()
|
||||||
remoteSdpChan := make(chan struct {
|
remoteSdpChan := make(chan struct {
|
||||||
StreamID string
|
StreamID string
|
||||||
RemoteDescription webrtc.SessionDescription
|
RemoteDescription webrtc.SessionDescription
|
||||||
|
Loading…
Reference in New Issue
Block a user