add media to capture config.

This commit is contained in:
Miroslav Šedivý
2021-12-09 23:22:24 +01:00
parent 21140d3dd3
commit 6b14e01415
5 changed files with 72 additions and 28 deletions

View File

@ -122,7 +122,7 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
videoIDs: config.VideoIDs,
// sources
webcam: streamSrcNew(map[string]string{
webcam: streamSrcNew(config.WebcamEnabled, map[string]string{
codec.VP8().Name: "appsrc format=time is-live=true do-timestamp=true name=appsrc " +
fmt.Sprintf("! application/x-rtp, payload=%d, encoding-name=VP8-DRAFT-IETF-01 ", codec.VP8().PayloadType) +
"! rtpvp8depay " +
@ -130,7 +130,8 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
"! videoconvert " +
"! videorate " +
"! identity drop-allocation=true " +
"! v4l2sink sync=false device=/dev/video0",
fmt.Sprintf("! v4l2sink sync=false device=%s", config.WebcamDevice),
// TODO: Test this pipeline.
codec.VP9().Name: "appsrc format=time is-live=true do-timestamp=true name=appsrc " +
"! application/x-rtp " +
"! rtpvp9depay " +
@ -138,7 +139,8 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
"! videoconvert " +
"! videorate " +
"! identity drop-allocation=true " +
"! v4l2sink sync=false device=/dev/video0",
fmt.Sprintf("! v4l2sink sync=false device=%s", config.WebcamDevice),
// TODO: Test this pipeline.
codec.H264().Name: "appsrc format=time is-live=true do-timestamp=true name=appsrc " +
"! application/x-rtp " +
"! rtph264depay " +
@ -146,19 +148,20 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
"! videoconvert " +
"! videorate " +
"! identity drop-allocation=true " +
"! v4l2sink sync=false device=/dev/video0",
fmt.Sprintf("! v4l2sink sync=false device=%s", config.WebcamDevice),
}, "webcam"),
microphone: streamSrcNew(map[string]string{
microphone: streamSrcNew(config.MicrophoneEnabled, map[string]string{
codec.Opus().Name: "appsrc format=time is-live=true do-timestamp=true name=appsrc " +
fmt.Sprintf("! application/x-rtp, payload=%d, encoding-name=OPUS ", codec.Opus().PayloadType) +
"! rtpopusdepay " +
"! decodebin " +
"! pulsesink device=audio_input",
fmt.Sprintf("! pulsesink device=%s", config.MicrophoneDevice),
// TODO: Test this pipeline.
codec.G722().Name: "appsrc format=time is-live=true do-timestamp=true name=appsrc " +
"! application/x-rtp clock-rate=8000 " +
"! rtpg722depay " +
"! decodebin " +
"! pulsesink device=audio_input",
fmt.Sprintf("! pulsesink device=%s", config.MicrophoneDevice),
}, "microphone"),
}
}

View File

@ -131,7 +131,7 @@ func (manager *ScreencastManagerCtx) start() error {
defer manager.mu.Unlock()
if !manager.enabled {
return errors.New("screenshot pipeline not enabled")
return errors.New("screencast not enabled")
}
err := manager.createPipeline()

View File

@ -14,6 +14,7 @@ import (
type StreamSrcManagerCtx struct {
logger zerolog.Logger
enabled bool
codecPipeline map[string]string // codec -> pipeline
codec codec.RTPCodec
@ -22,7 +23,7 @@ type StreamSrcManagerCtx struct {
pipelineStr string
}
func streamSrcNew(codecPipeline map[string]string, video_id string) *StreamSrcManagerCtx {
func streamSrcNew(enabled bool, codecPipeline map[string]string, video_id string) *StreamSrcManagerCtx {
logger := log.With().
Str("module", "capture").
Str("submodule", "stream-src").
@ -30,6 +31,7 @@ func streamSrcNew(codecPipeline map[string]string, video_id string) *StreamSrcMa
return &StreamSrcManagerCtx{
logger: logger,
enabled: enabled,
codecPipeline: codecPipeline,
}
}
@ -52,6 +54,10 @@ func (manager *StreamSrcManagerCtx) Start(codec codec.RTPCodec) error {
return types.ErrCapturePipelineAlreadyExists
}
if !manager.enabled {
return errors.New("stream-src not enabled")
}
found := false
for codecName, pipeline := range manager.codecPipeline {
if codecName == codec.Name {