sdp交换存在问题
This commit is contained in:
parent
5c93e698b6
commit
acf74153ef
@ -71,7 +71,6 @@ func (w *PCMStreamDriver) AudioRecord(p prop.Media) (audio.Reader, error) {
|
||||
case <-w.closed:
|
||||
return nil, func() {}, io.EOF
|
||||
case pcmData, ok := <-w.PCM:
|
||||
logrus.Debug("got %d bytes pcm data", len(pcmData))
|
||||
if !ok {
|
||||
return nil, func() {}, io.ErrClosedPipe
|
||||
}
|
||||
@ -85,7 +84,7 @@ func (w *PCMStreamDriver) AudioRecord(p prop.Media) (audio.Reader, error) {
|
||||
func bytesTo16BitSamples(b []byte) []int16 {
|
||||
samples := make([]int16, 0)
|
||||
for i := 0; i < len(b); i += 2 {
|
||||
sample := binary.LittleEndian.Uint16(b[i : i+1])
|
||||
sample := binary.LittleEndian.Uint16(b[i : i+2])
|
||||
samples = append(samples, int16(sample))
|
||||
}
|
||||
return samples
|
||||
|
@ -52,6 +52,7 @@ func (v *PPMStreamDriver) Properties() []prop.Media {
|
||||
}
|
||||
|
||||
func (v *PPMStreamDriver) VideoRecord(p prop.Media) (video.Reader, error) {
|
||||
logrus.Debug(p)
|
||||
r := video.ReaderFunc(func() (img image.Image, release func(), err error) {
|
||||
canvas := image.NewYCbCr(
|
||||
image.Rect(0, 0, p.Width, p.Height),
|
||||
|
@ -77,13 +77,6 @@ func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDe
|
||||
|
||||
rtc.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||
logrus.Debug("connection state has changed: ", connectionState.String())
|
||||
|
||||
switch connectionState {
|
||||
case webrtc.ICEConnectionStateFailed:
|
||||
fallthrough
|
||||
case webrtc.ICEConnectionStateClosed:
|
||||
rtc.Close()
|
||||
}
|
||||
})
|
||||
|
||||
for _, track := range c.stream.GetTracks() {
|
||||
@ -110,14 +103,12 @@ func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
gatherComplete := webrtc.GatheringCompletePromise(rtc)
|
||||
|
||||
if err := rtc.SetLocalDescription(answer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logrus.Debug("answer set")
|
||||
|
||||
<-gatherComplete
|
||||
<-webrtc.GatheringCompletePromise(rtc)
|
||||
|
||||
defer logrus.Debug("regist complete")
|
||||
return rtc.LocalDescription(), nil
|
||||
|
@ -2,32 +2,35 @@ package qemuserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.sense-t.eu.org/ACE/ace/drivers/audio"
|
||||
"git.sense-t.eu.org/ACE/ace/drivers/video"
|
||||
"git.sense-t.eu.org/ACE/ace/lib/audiodriver"
|
||||
"git.sense-t.eu.org/ACE/ace/lib/qemuconnection"
|
||||
"github.com/digitalocean/go-qemu/qemu"
|
||||
"github.com/digitalocean/go-qemu/qmp"
|
||||
"github.com/pion/mediadevices/pkg/driver"
|
||||
"github.com/pion/mediadevices/pkg/driver/vncdriver"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const waveHeaderSize = audiodriver.FmtHeaderSizeDefault
|
||||
const waveHeaderSize = audio.FmtHeaderSizeDefault
|
||||
|
||||
var waveHeader *audiodriver.WavHeader
|
||||
var waveHeader *audio.WavHeader
|
||||
|
||||
func init() {
|
||||
waveHeader = audiodriver.DefaultHeader()
|
||||
waveHeader = audio.DefaultHeader()
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
options *Options
|
||||
qemu *qemu.Domain
|
||||
audioHeader chan *audiodriver.WavHeader
|
||||
pcm chan [audiodriver.BufferSize]byte
|
||||
audioHeader chan *audio.WavHeader
|
||||
pcm chan []byte
|
||||
ppm chan io.ReadCloser
|
||||
}
|
||||
|
||||
var DefaultServer *Server
|
||||
@ -39,8 +42,9 @@ func NewServer(o *Options) (*Server, error) {
|
||||
|
||||
server := &Server{
|
||||
options: o,
|
||||
audioHeader: make(chan *audiodriver.WavHeader, 1),
|
||||
pcm: make(chan [audiodriver.BufferSize]byte),
|
||||
audioHeader: make(chan *audio.WavHeader, 1),
|
||||
pcm: make(chan []byte),
|
||||
ppm: make(chan io.ReadCloser),
|
||||
}
|
||||
|
||||
u, err := url.Parse(o.QmpAddress)
|
||||
@ -70,7 +74,11 @@ func NewServer(o *Options) (*Server, error) {
|
||||
}
|
||||
server.qemu = qemu
|
||||
|
||||
audio := audiodriver.New()
|
||||
audio := &audio.PCMStreamDriver{
|
||||
PCM: server.pcm,
|
||||
WaveHeader: waveHeader,
|
||||
BufferSizeByBytes: 2048, // to be configured
|
||||
}
|
||||
if err := driver.GetManager().Register(
|
||||
audio,
|
||||
driver.Info{
|
||||
@ -81,11 +89,15 @@ func NewServer(o *Options) (*Server, error) {
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
audio.PCM = server.pcm
|
||||
audio.WaveHeader = waveHeader
|
||||
|
||||
video := &video.PPMStreamDriver{
|
||||
Height: 768,
|
||||
Width: 1024,
|
||||
FPS: 60,
|
||||
PPMImage: server.ppm,
|
||||
}
|
||||
if err := driver.GetManager().Register(
|
||||
vncdriver.NewVnc(o.VNCAddress),
|
||||
video,
|
||||
driver.Info{
|
||||
Label: "vnc",
|
||||
DeviceType: driver.Camera,
|
||||
@ -101,6 +113,7 @@ func NewServer(o *Options) (*Server, error) {
|
||||
func (s *Server) Run() error {
|
||||
logrus.Debug("qemu server running")
|
||||
|
||||
go func() {
|
||||
f, err := os.Open(s.options.AudioPipe)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
@ -108,6 +121,28 @@ func (s *Server) Run() error {
|
||||
defer f.Close()
|
||||
logrus.Debug("start reading fifo")
|
||||
|
||||
logrus.Debug("skip wave headers, to the PCM!")
|
||||
// skip to pcm data, for 44 bytes.
|
||||
var _dataChunkHeader [audiodriver.FmtHeaderOffset +
|
||||
audiodriver.FmtHeaderIDSize + audiodriver.FmtHeaderChunkSizeSize + waveHeaderSize +
|
||||
audiodriver.DataChunkIDSize + audiodriver.DataChunkSizeSize]byte
|
||||
if _, err := f.Read(_dataChunkHeader[:]); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
defer close(s.pcm)
|
||||
for {
|
||||
b := make([]byte, 2048) // to be configured
|
||||
if _, err := f.Read(b[:]); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
select {
|
||||
case s.pcm <- b:
|
||||
case <-time.After(waveHeader.GetLatnecy(2048)):
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
logrus.Debug("setting audio capture")
|
||||
if _, err := s.qemu.Run(qmp.Command{
|
||||
@ -128,26 +163,20 @@ func (s *Server) Run() error {
|
||||
logrus.Debug("audio capture set")
|
||||
}()
|
||||
|
||||
logrus.Debug("skip wave headers, to the PCM!")
|
||||
// skip to pcm data, for 44 bytes.
|
||||
var _dataChunkHeader [audiodriver.FmtHeaderOffset +
|
||||
audiodriver.FmtHeaderIDSize + audiodriver.FmtHeaderChunkSizeSize + waveHeaderSize +
|
||||
audiodriver.DataChunkIDSize + audiodriver.DataChunkSizeSize]byte
|
||||
if _, err := f.Read(_dataChunkHeader[:]); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
defer close(s.pcm)
|
||||
for {
|
||||
var b [audiodriver.BufferSize]byte
|
||||
if _, err := f.Read(b[:]); err != nil {
|
||||
go func() {
|
||||
logrus.Debug("screen capture start")
|
||||
defer close(s.ppm)
|
||||
for range time.Tick(time.Second / 60) { // to be configured
|
||||
ppm, err := s.qemu.ScreenDump()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
select {
|
||||
case s.pcm <- b:
|
||||
case <-time.After(waveHeader.GetLatnecy()):
|
||||
}
|
||||
s.ppm <- ppm
|
||||
}
|
||||
}()
|
||||
|
||||
select {}
|
||||
}
|
||||
|
||||
func (s *Server) SendEvent(b []byte) error {
|
||||
|
Loading…
Reference in New Issue
Block a user