diff --git a/internal/capture/manager.go b/internal/capture/manager.go index 89bb7630..4b6a27de 100644 --- a/internal/capture/manager.go +++ b/internal/capture/manager.go @@ -122,10 +122,26 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt videoIDs: config.VideoIDs, // sources - webcam: streamSrcNew(map[string]string{}, "webcam"), // TODO + webcam: streamSrcNew(map[string]string{ + codec.VP8().Name: "appsrc format=time is-live=true do-timestamp=true name=src " + + fmt.Sprintf("! application/x-rtp, payload=%d, encoding-name=VP8-DRAFT-IETF-01 ", codec.VP8().PayloadType) + + "! rtpvp8depay " + + "! decodebin " + + "! v4l2sink device=/dev/video0", + codec.VP9().Name: "appsrc format=time is-live=true do-timestamp=true name=src " + + "! application/x-rtp " + + "! rtpvp9depay " + + "! decodebin " + + "! v4l2sink device=/dev/video0", + codec.H264().Name: "appsrc format=time is-live=true do-timestamp=true name=src " + + "! application/x-rtp " + + "! rtph264depay " + + "! decodebin " + + "! v4l2sink device=/dev/video0", + }, "webcam"), microphone: streamSrcNew(map[string]string{ codec.Opus().Name: "appsrc format=time is-live=true do-timestamp=true name=src " + - "! application/x-rtp, payload=111, encoding-name=OPUS " + + fmt.Sprintf("! application/x-rtp, payload=%d, encoding-name=OPUS ", codec.Opus().PayloadType) + "! rtpopusdepay " + "! decodebin " + "! pulsesink device=audio_input", diff --git a/internal/webrtc/manager.go b/internal/webrtc/manager.go index b7cae274..c462081f 100644 --- a/internal/webrtc/manager.go +++ b/internal/webrtc/manager.go @@ -157,19 +157,11 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin } connection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) { - // if we did not get audio - if track.Kind() != webrtc.RTPCodecTypeAudio { - logger.Warn().Msg("got remote track, but not audio") - return - } - - codecName := strings.Split(track.Codec().RTPCodecCapability.MimeType, "/")[1] - logger.Info(). Str("stream-id", track.StreamID()). Str("id", track.ID()). Str("rid", track.RID()). - Str("codec", codecName). + Str("mime", track.Codec().RTPCodecCapability.MimeType). Uint8("payload-type", uint8(track.PayloadType())). Msgf("received new track") @@ -180,10 +172,17 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin return } - // add microphone - microphone := manager.capture.Microphone() - microphone.Start(codec) - defer microphone.Stop() // TODO: Ensure no new publisher took over. + var srcManager types.StreamSrcManager + if track.Kind() == webrtc.RTPCodecTypeAudio { + // audio -> microphone + srcManager = manager.capture.Microphone() + } else if track.Kind() == webrtc.RTPCodecTypeVideo { + // video -> webcam + srcManager = manager.capture.Webcam() + } + + srcManager.Start(codec) + defer srcManager.Stop() // TODO: Ensure no new publisher took over. // Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval ticker := time.NewTicker(time.Second * 3) @@ -206,10 +205,10 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin break } - microphone.Push(buf[:i]) + srcManager.Push(buf[:i]) } - logger.Warn().Msg("microphone connection died") + logger.Warn().Msg("src manager stream connection died") }) connection.OnDataChannel(func(dc *webrtc.DataChannel) {