mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-20 02:00:05 -08:00
hls, webrtc: add FromStream / ToStream (#3752)
Some checks failed
code_lint / golangci_lint (push) Has been cancelled
code_lint / mod_tidy (push) Has been cancelled
code_lint / api_docs (push) Has been cancelled
code_test / test_64 (push) Has been cancelled
code_test / test_32 (push) Has been cancelled
code_test / test_highlevel (push) Has been cancelled
Some checks failed
code_lint / golangci_lint (push) Has been cancelled
code_lint / mod_tidy (push) Has been cancelled
code_lint / api_docs (push) Has been cancelled
code_test / test_64 (push) Has been cancelled
code_test / test_32 (push) Has been cancelled
code_test / test_highlevel (push) Has been cancelled
This commit is contained in:
parent
7b01f48d40
commit
6a38c87a5b
32 changed files with 1776 additions and 1689 deletions
|
|
@ -8,13 +8,14 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/description"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/conf"
|
||||
"github.com/bluenviron/mediamtx/internal/defs"
|
||||
"github.com/bluenviron/mediamtx/internal/logger"
|
||||
"github.com/bluenviron/mediamtx/internal/protocols/tls"
|
||||
"github.com/bluenviron/mediamtx/internal/protocols/webrtc"
|
||||
"github.com/bluenviron/mediamtx/internal/protocols/whip"
|
||||
"github.com/bluenviron/mediamtx/internal/stream"
|
||||
)
|
||||
|
||||
// Source is a WebRTC static source.
|
||||
|
|
@ -44,7 +45,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
|||
}
|
||||
defer tr.CloseIdleConnections()
|
||||
|
||||
client := webrtc.WHIPClient{
|
||||
client := whip.Client{
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: time.Duration(s.ReadTimeout),
|
||||
Transport: tr,
|
||||
|
|
@ -53,13 +54,18 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
|||
Log: s,
|
||||
}
|
||||
|
||||
tracks, err := client.Read(params.Context)
|
||||
_, err = client.Read(params.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.Close() //nolint:errcheck
|
||||
|
||||
medias := webrtc.TracksToMedias(tracks)
|
||||
var stream *stream.Stream
|
||||
|
||||
medias, err := webrtc.ToStream(client.PeerConnection(), &stream)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rres := s.Parent.SetReady(defs.PathSourceStaticSetReadyReq{
|
||||
Desc: &description.Session{Medias: medias},
|
||||
|
|
@ -69,31 +75,11 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
|||
return rres.Err
|
||||
}
|
||||
|
||||
stream = rres.Stream
|
||||
|
||||
defer s.Parent.SetNotReady(defs.PathSourceStaticSetNotReadyReq{})
|
||||
|
||||
timeDecoder := rtptime.NewGlobalDecoder()
|
||||
|
||||
for i, media := range medias {
|
||||
ci := i
|
||||
cmedia := media
|
||||
trackWrapper := &webrtc.TrackWrapper{ClockRat: cmedia.Formats[0].ClockRate()}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
pkt, err := tracks[ci].ReadRTP()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
pts, ok := timeDecoder.Decode(trackWrapper, pkt)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
rres.Stream.WriteRTPPacket(cmedia, cmedia.Formats[0], pkt, time.Now(), pts)
|
||||
}
|
||||
}()
|
||||
}
|
||||
client.StartReading()
|
||||
|
||||
return client.Wait(params.Context)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue