Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/webrtc/tracks.go
2020-02-12 23:13:33 +00:00

41 lines
1.1 KiB
Go

package webrtc
import (
"fmt"
"math/rand"
"github.com/pion/webrtc/v2"
)
func (m *WebRTCManager) createVideoTrack() (*webrtc.Track, error) {
var codec *webrtc.RTPCodec
for _, videoCodec := range m.engine.GetCodecsByKind(webrtc.RTPCodecTypeVideo) {
if videoCodec.Name == m.videoPipeline.CodecName {
codec = videoCodec
break
}
}
if codec == nil || codec.PayloadType == 0 {
return nil, fmt.Errorf("remote peer does not support video codec %s", m.videoPipeline.CodecName)
}
return webrtc.NewTrack(codec.PayloadType, rand.Uint32(), "stream", "stream", codec)
}
func (m *WebRTCManager) createAudioTrack() (*webrtc.Track, error) {
var codec *webrtc.RTPCodec
for _, videoCodec := range m.engine.GetCodecsByKind(webrtc.RTPCodecTypeAudio) {
if videoCodec.Name == m.audioPipeline.CodecName {
codec = videoCodec
break
}
}
if codec == nil || codec.PayloadType == 0 {
return nil, fmt.Errorf("remote peer does not support audio codec %s", m.audioPipeline.CodecName)
}
return webrtc.NewTrack(codec.PayloadType, rand.Uint32(), "stream", "stream", codec)
}