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 support for SRT in URL Pull ingress #206

Merged
merged 2 commits into from
Jan 26, 2024
Merged
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
1 change: 1 addition & 0 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
ErrSourceNotReady = psrpc.NewErrorf(psrpc.FailedPrecondition, "source encoder not ready")
ErrUnsupportedDecodeFormat = psrpc.NewErrorf(psrpc.NotAcceptable, "unsupported format for the source media")
ErrUnsupportedEncodeFormat = psrpc.NewErrorf(psrpc.InvalidArgument, "unsupported mime type for encoder")
ErrUnsupportedURLFormat = psrpc.NewErrorf(psrpc.InvalidArgument, "unsupported URL type")
ErrDuplicateTrack = psrpc.NewErrorf(psrpc.NotAcceptable, "more than 1 track with given media kind")
ErrUnableToAddPad = psrpc.NewErrorf(psrpc.Internal, "could not add pads to bin")
ErrMissingResourceId = psrpc.NewErrorf(psrpc.InvalidArgument, "missing resource ID")
Expand Down
32 changes: 18 additions & 14 deletions pkg/media/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,29 @@ func (i *Input) addBitrateProbe(kind types.StreamKind) {

for _, pad := range pads {
caps := pad.GetCurrentCaps()
gstStruct := caps.GetStructureAt(0)
padKind := getKindFromGstMimeType(gstStruct)
if caps != nil && caps.GetSize() > 0 {
gstStruct := caps.GetStructureAt(0)
padKind := getKindFromGstMimeType(gstStruct)

if padKind == kind {
g := i.trackStatsGatherer[kind]
if padKind == kind {
g := i.trackStatsGatherer[kind]

pad.AddProbe(gst.PadProbeTypeBuffer, func(pad *gst.Pad, info *gst.PadProbeInfo) gst.PadProbeReturn {
buffer := info.GetBuffer()
if buffer == nil {
return gst.PadProbeOK
}
pad.AddProbe(gst.PadProbeTypeBuffer, func(pad *gst.Pad, info *gst.PadProbeInfo) gst.PadProbeReturn {
buffer := info.GetBuffer()
if buffer == nil {
return gst.PadProbeOK
}

size := buffer.GetSize()
g.MediaReceived(size)
size := buffer.GetSize()
g.MediaReceived(size)

return gst.PadProbeOK
})
return gst.PadProbeOK
})

return
return
}
} else {
logger.Debugw("could not retrieve multiqueue pad caps", "error", err)
}
}

Expand Down
39 changes: 29 additions & 10 deletions pkg/media/urlpull/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package urlpull

import (
"context"
"strings"

"github.com/go-gst/go-gst/gst"

Expand Down Expand Up @@ -46,24 +47,42 @@ type URLSource struct {
func NewURLSource(ctx context.Context, p *params.Params) (*URLSource, error) {
bin := gst.NewBin("input")

elem, err := gst.NewElement("souphttpsrc")
if err != nil {
return nil, err
}
var elem *gst.Element
var err error
if strings.HasPrefix(p.Url, "http://") || strings.HasPrefix(p.Url, "https://") {
elem, err = gst.NewElement("souphttpsrc")
if err != nil {
return nil, err
}

err = elem.SetProperty("location", p.Url)
if err != nil {
return nil, err
err = elem.SetProperty("location", p.Url)
if err != nil {
return nil, err
}

} else if strings.HasPrefix(p.Url, "srt://") {
elem, err = gst.NewElement("srtclientsrc")
if err != nil {
return nil, err
}
err = elem.SetProperty("uri", p.Url)
if err != nil {
return nil, err
}
} else {
return nil, errors.ErrUnsupportedURLFormat
}

queue, err := gst.NewElement("queue2")
if err != nil {
return nil, err
}

err = queue.SetProperty("use-buffering", true)
if err != nil {
return nil, err
if strings.HasPrefix(p.Url, "http://") || strings.HasPrefix(p.Url, "https://") {
err = queue.SetProperty("use-buffering", true)
if err != nil {
return nil, err
}
}

err = bin.AddMany(elem, queue)
Expand Down