to be continued
This commit is contained in:
parent
4844944c37
commit
07d3ae3717
3
TODO
3
TODO
@ -10,3 +10,6 @@
|
|||||||
|
|
||||||
# 2022-10-3
|
# 2022-10-3
|
||||||
1. 虚拟设备应当一直运行,无阻塞
|
1. 虚拟设备应当一直运行,无阻塞
|
||||||
|
|
||||||
|
# 2022-10-10
|
||||||
|
1. 视频设备延迟过高
|
@ -68,12 +68,14 @@ func (w *PCMStreamDriver) AudioRecord(p prop.Media) (audio.Reader, error) {
|
|||||||
|
|
||||||
reader := func() (wave.Audio, func(), error) {
|
reader := func() (wave.Audio, func(), error) {
|
||||||
a := wave.NewInt16Interleaved(chunkInfo)
|
a := wave.NewInt16Interleaved(chunkInfo)
|
||||||
|
ticker := time.NewTicker(p.Latency)
|
||||||
|
defer ticker.Stop()
|
||||||
select {
|
select {
|
||||||
case <-w.closed:
|
case <-w.closed:
|
||||||
return nil, func() {}, io.EOF
|
return nil, func() {}, io.EOF
|
||||||
case pcmData := <-w.PCM:
|
case pcmData := <-w.PCM:
|
||||||
copy(a.Data, bytesTo16BitSamples(pcmData[:]))
|
copy(a.Data, bytesTo16BitSamples(pcmData[:]))
|
||||||
case <-time.After(p.Latency):
|
case <-ticker.C:
|
||||||
// no stuck
|
// no stuck
|
||||||
}
|
}
|
||||||
return a, func() {}, nil
|
return a, func() {}, nil
|
||||||
|
@ -59,6 +59,9 @@ func (v *PPMStreamDriver) VideoRecord(p prop.Media) (video.Reader, error) {
|
|||||||
image.YCbCrSubsampleRatio420,
|
image.YCbCrSubsampleRatio420,
|
||||||
)
|
)
|
||||||
r := video.ReaderFunc(func() (img image.Image, release func(), err error) {
|
r := video.ReaderFunc(func() (img image.Image, release func(), err error) {
|
||||||
|
ticker := time.NewTicker(time.Second / time.Duration(p.FrameRate))
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-v.closed:
|
case <-v.closed:
|
||||||
return nil, func() {}, io.EOF
|
return nil, func() {}, io.EOF
|
||||||
@ -82,7 +85,7 @@ func (v *PPMStreamDriver) VideoRecord(p prop.Media) (video.Reader, error) {
|
|||||||
canvas.Cr[canvas.COffset(x, y)] = Cr
|
canvas.Cr[canvas.COffset(x, y)] = Cr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second / time.Duration(p.FrameRate)):
|
case <-ticker.C:
|
||||||
}
|
}
|
||||||
return canvas, func() {}, nil
|
return canvas, func() {}, nil
|
||||||
})
|
})
|
||||||
|
@ -119,6 +119,7 @@ func setupCodec(videoBPS int) (*mediadevices.CodecSelector, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
x264Prarm.BitRate = videoBPS
|
x264Prarm.BitRate = videoBPS
|
||||||
|
x264Prarm.Preset = x264.PresetMedium
|
||||||
|
|
||||||
opusParam, err := opus.NewParams()
|
opusParam, err := opus.NewParams()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,7 +11,7 @@ func ExampleOptions() *Options {
|
|||||||
"stun:stun.l.google.com:19302",
|
"stun:stun.l.google.com:19302",
|
||||||
"stun:wetofu.me:3478",
|
"stun:wetofu.me:3478",
|
||||||
},
|
},
|
||||||
VideoBPS: 500_000,
|
VideoBPS: 2_048_000,
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func NewServer(o *Options) (*Server, error) {
|
|||||||
options: o,
|
options: o,
|
||||||
audioHeader: make(chan *audio.WavHeader, 1),
|
audioHeader: make(chan *audio.WavHeader, 1),
|
||||||
pcm: make(chan []byte),
|
pcm: make(chan []byte),
|
||||||
ppm: make(chan io.ReadCloser, 60), // to be configured
|
ppm: make(chan io.ReadCloser, int(o.Video.FPS)), // to be configured
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := url.Parse(o.QmpAddress)
|
u, err := url.Parse(o.QmpAddress)
|
||||||
@ -115,13 +115,22 @@ func (s *Server) Run() error {
|
|||||||
go func() {
|
go func() {
|
||||||
logrus.Debug("screen capture start")
|
logrus.Debug("screen capture start")
|
||||||
defer close(s.ppm)
|
defer close(s.ppm)
|
||||||
for range time.Tick(time.Second / time.Duration(s.options.Video.FPS)) { // to be configured
|
|
||||||
|
ticker := time.NewTicker(time.Second / time.Duration(s.options.Video.FPS))
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
for { // to be configured
|
||||||
ppm, err := s.qemu.ScreenDump()
|
ppm, err := s.qemu.ScreenDump()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.ppm <- ppm
|
select {
|
||||||
|
case s.ppm <- ppm:
|
||||||
|
case <-ticker.C:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//<-ticker.C
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -144,6 +153,8 @@ func (s *Server) Run() error {
|
|||||||
|
|
||||||
logrus.Debug("start reading PCM")
|
logrus.Debug("start reading PCM")
|
||||||
defer close(s.pcm)
|
defer close(s.pcm)
|
||||||
|
ticker := time.NewTicker(waveHeader.GetLatnecy(s.options.Audio.BufferSize))
|
||||||
|
defer ticker.Stop()
|
||||||
for {
|
for {
|
||||||
b := make([]byte, s.options.Audio.BufferSize) // to be configured
|
b := make([]byte, s.options.Audio.BufferSize) // to be configured
|
||||||
if _, err := f.Read(b[:]); err != nil {
|
if _, err := f.Read(b[:]); err != nil {
|
||||||
@ -151,7 +162,7 @@ func (s *Server) Run() error {
|
|||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case s.pcm <- b:
|
case s.pcm <- b:
|
||||||
case <-time.After(waveHeader.GetLatnecy(s.options.Audio.BufferSize)):
|
case <-ticker.C:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user