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

49 lines
1.3 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-02-14 16:51:41 +13:00
"n.eko.moe/neko/internal/gst"
2020-01-19 12:30:09 +13:00
)
2020-04-05 19:07:45 +12:00
func (m *WebRTCManager) createTrack(codecName string, pipelineDevice string, pipelineSrc string) (*gst.Pipeline, *webrtc.Track, *webrtc.RTPCodec, error) {
2020-02-14 16:51:41 +13:00
pipeline, err := gst.CreatePipeline(
codecName,
pipelineDevice,
pipelineSrc,
)
2020-01-19 12:30:09 +13:00
2020-02-14 16:51:41 +13:00
if err != nil {
2020-04-05 19:07:45 +12:00
return nil, nil, nil, err
2020-01-19 12:30:09 +13:00
}
var codec *webrtc.RTPCodec
2020-02-14 16:51:41 +13:00
switch codecName {
case webrtc.VP8:
codec = webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000)
case webrtc.VP9:
codec = webrtc.NewRTPVP9Codec(webrtc.DefaultPayloadTypeVP9, 90000)
case webrtc.H264:
codec = webrtc.NewRTPH264Codec(webrtc.DefaultPayloadTypeH264, 90000)
case webrtc.Opus:
codec = webrtc.NewRTPOpusCodec(webrtc.DefaultPayloadTypeOpus, 48000)
case webrtc.G722:
codec = webrtc.NewRTPG722Codec(webrtc.DefaultPayloadTypeG722, 8000)
case webrtc.PCMU:
codec = webrtc.NewRTPPCMUCodec(webrtc.DefaultPayloadTypePCMU, 8000)
case webrtc.PCMA:
codec = webrtc.NewRTPPCMACodec(webrtc.DefaultPayloadTypePCMA, 8000)
default:
2020-04-05 19:07:45 +12:00
return nil, nil, nil, fmt.Errorf("unknown codec %s", codecName)
2020-01-19 12:30:09 +13:00
}
2020-02-14 16:51:41 +13:00
track, err := webrtc.NewTrack(codec.PayloadType, rand.Uint32(), "stream", "stream", codec)
if err != nil {
2020-04-05 19:07:45 +12:00
return nil, nil, nil, err
2020-01-19 12:30:09 +13:00
}
2020-04-05 19:07:45 +12:00
return pipeline, track, codec, nil
2020-01-19 12:30:09 +13:00
}