2020-01-19 12:30:09 +13:00
|
|
|
package webrtc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
"github.com/pion/webrtc/v2"
|
|
|
|
)
|
|
|
|
|
2020-02-13 12:13:33 +13:00
|
|
|
func (m *WebRTCManager) createVideoTrack() (*webrtc.Track, error) {
|
2020-01-19 12:30:09 +13:00
|
|
|
var codec *webrtc.RTPCodec
|
2020-02-13 12:13:33 +13:00
|
|
|
for _, videoCodec := range m.engine.GetCodecsByKind(webrtc.RTPCodecTypeVideo) {
|
2020-01-25 04:47:37 +13:00
|
|
|
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-02-13 12:13:33 +13:00
|
|
|
func (m *WebRTCManager) createAudioTrack() (*webrtc.Track, error) {
|
2020-01-19 12:30:09 +13:00
|
|
|
var codec *webrtc.RTPCodec
|
2020-02-13 12:13:33 +13:00
|
|
|
for _, videoCodec := range m.engine.GetCodecsByKind(webrtc.RTPCodecTypeAudio) {
|
2020-01-25 04:47:37 +13:00
|
|
|
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
|
|
|
}
|