mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
implement webcam.
This commit is contained in:
parent
9f9956d047
commit
d70ae4410f
@ -122,10 +122,26 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
|
|||||||
videoIDs: config.VideoIDs,
|
videoIDs: config.VideoIDs,
|
||||||
|
|
||||||
// sources
|
// 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{
|
microphone: streamSrcNew(map[string]string{
|
||||||
codec.Opus().Name: "appsrc format=time is-live=true do-timestamp=true name=src " +
|
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 " +
|
"! rtpopusdepay " +
|
||||||
"! decodebin " +
|
"! decodebin " +
|
||||||
"! pulsesink device=audio_input",
|
"! pulsesink device=audio_input",
|
||||||
|
@ -157,19 +157,11 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
connection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
|
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().
|
logger.Info().
|
||||||
Str("stream-id", track.StreamID()).
|
Str("stream-id", track.StreamID()).
|
||||||
Str("id", track.ID()).
|
Str("id", track.ID()).
|
||||||
Str("rid", track.RID()).
|
Str("rid", track.RID()).
|
||||||
Str("codec", codecName).
|
Str("mime", track.Codec().RTPCodecCapability.MimeType).
|
||||||
Uint8("payload-type", uint8(track.PayloadType())).
|
Uint8("payload-type", uint8(track.PayloadType())).
|
||||||
Msgf("received new track")
|
Msgf("received new track")
|
||||||
|
|
||||||
@ -180,10 +172,17 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// add microphone
|
var srcManager types.StreamSrcManager
|
||||||
microphone := manager.capture.Microphone()
|
if track.Kind() == webrtc.RTPCodecTypeAudio {
|
||||||
microphone.Start(codec)
|
// audio -> microphone
|
||||||
defer microphone.Stop() // TODO: Ensure no new publisher took over.
|
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
|
// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
|
||||||
ticker := time.NewTicker(time.Second * 3)
|
ticker := time.NewTicker(time.Second * 3)
|
||||||
@ -206,10 +205,10 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
break
|
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) {
|
connection.OnDataChannel(func(dc *webrtc.DataChannel) {
|
||||||
|
Loading…
Reference in New Issue
Block a user