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
|
|
|
}
|