声音部分的代码仍需调试,现在panic

This commit is contained in:
TonyChyi
2022-09-27 14:36:25 +08:00
parent 7ef721afb7
commit edbe406f5b
6 changed files with 104 additions and 116 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/pion/mediadevices/pkg/codec/opus"
"github.com/pion/mediadevices/pkg/codec/x264"
"github.com/pion/mediadevices/pkg/driver"
"github.com/pion/mediadevices/pkg/prop"
"github.com/pion/webrtc/v3"
"github.com/sirupsen/logrus"
)
@@ -45,7 +46,10 @@ func New(o *Options) (*Connection, error) {
}
s, err := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
Video: func(mtc *mediadevices.MediaTrackConstraints) {},
Video: func(mtc *mediadevices.MediaTrackConstraints) {
mtc.Height = prop.Int(o.Video.Height)
mtc.Width = prop.Int(o.Video.Width)
},
Audio: func(mtc *mediadevices.MediaTrackConstraints) {},
Codec: codecSelector,
})
@@ -84,7 +88,7 @@ func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDe
for _, track := range c.stream.GetTracks() {
track.OnEnded(func(err error) {
logrus.Errorf("Track (ID: %s) ended with error: %v", track.ID(), err)
logrus.Errorf("Track (ID: %s, kind: %s) ended with error: %v", track.ID(), track.Kind().String(), err)
})
_, err := rtc.AddTransceiverFromTrack(track, webrtc.RTPTransceiverInit{
Direction: webrtc.RTPTransceiverDirectionSendonly,