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

41 lines
1.1 KiB
Go
Raw Normal View History

2020-01-19 12:30:09 +13:00
package webrtc
import (
"fmt"
"math/rand"
"github.com/pion/webrtc/v2"
)
2020-01-25 04:47:37 +13:00
func (m *WebRTCManager) createVideoTrack(engine webrtc.MediaEngine) (*webrtc.Track, error) {
2020-01-19 12:30:09 +13:00
var codec *webrtc.RTPCodec
2020-01-25 04:47:37 +13:00
for _, videoCodec := range engine.GetCodecsByKind(webrtc.RTPCodecTypeVideo) {
if videoCodec.Name == m.videoPipeline.CodecName {
codec = videoCodec
break
}
2020-01-19 12:30:09 +13:00
}
2020-01-25 04:47:37 +13:00
if codec == nil || codec.PayloadType == 0 {
2020-01-26 03:29:52 +13:00
return nil, fmt.Errorf("remote peer does not support video codec %s", m.videoPipeline.CodecName)
2020-01-19 12:30:09 +13:00
}
2020-01-25 04:47:37 +13:00
return webrtc.NewTrack(codec.PayloadType, rand.Uint32(), "stream", "stream", codec)
2020-01-19 12:30:09 +13:00
}
2020-01-25 04:47:37 +13:00
func (m *WebRTCManager) createAudioTrack(engine webrtc.MediaEngine) (*webrtc.Track, error) {
2020-01-19 12:30:09 +13:00
var codec *webrtc.RTPCodec
2020-01-25 04:47:37 +13:00
for _, videoCodec := range engine.GetCodecsByKind(webrtc.RTPCodecTypeAudio) {
if videoCodec.Name == m.audioPipeline.CodecName {
codec = videoCodec
break
}
2020-01-19 12:30:09 +13:00
}
2020-01-25 04:47:37 +13:00
if codec == nil || codec.PayloadType == 0 {
2020-01-26 03:29:52 +13:00
return nil, fmt.Errorf("remote peer does not support audio codec %s", m.audioPipeline.CodecName)
2020-01-19 12:30:09 +13:00
}
2020-01-25 04:47:37 +13:00
return webrtc.NewTrack(codec.PayloadType, rand.Uint32(), "stream", "stream", codec)
2020-01-19 12:30:09 +13:00
}