diff --git a/TODO b/TODO index 4e5292f..3aa5427 100644 --- a/TODO +++ b/TODO @@ -15,4 +15,4 @@ 1. 视频设备延迟过高 # 2022-10-11 -1. 解决视频设备延迟 \ No newline at end of file +1. 解决视频设备延迟->丢帧机制?或者使用tmpfs \ No newline at end of file diff --git a/drivers/video/ppm.go b/drivers/video/ppm.go index 7269ce4..0555f96 100644 --- a/drivers/video/ppm.go +++ b/drivers/video/ppm.go @@ -5,7 +5,6 @@ import ( "image" "image/color" "io" - "time" "github.com/nfnt/resize" "github.com/pion/mediadevices/pkg/frame" @@ -59,9 +58,6 @@ func (v *PPMStreamDriver) VideoRecord(p prop.Media) (video.Reader, error) { image.YCbCrSubsampleRatio420, ) r := video.ReaderFunc(func() (img image.Image, release func(), err error) { - ticker := time.NewTicker(time.Second / time.Duration(p.FrameRate)) - defer ticker.Stop() - select { case <-v.closed: return nil, func() {}, io.EOF @@ -74,7 +70,7 @@ func (v *PPMStreamDriver) VideoRecord(p prop.Media) (video.Reader, error) { } // resize image and draw it to canvas - resized := resize.Resize(uint(p.Width), uint(p.Height), img, resize.Lanczos3) + resized := resize.Resize(uint(p.Width), uint(p.Height), img, resize.Bilinear) for y := 0; y < resized.Bounds().Dy(); y++ { for x := 0; x < resized.Bounds().Dx(); x++ { r, g, b, _ := resized.At(x, y).RGBA() @@ -85,7 +81,7 @@ func (v *PPMStreamDriver) VideoRecord(p prop.Media) (video.Reader, error) { canvas.Cr[canvas.COffset(x, y)] = Cr } } - case <-ticker.C: + default: } return canvas, func() {}, nil }) diff --git a/servers/qemuserver/server.go b/servers/qemuserver/server.go index 7d63af6..543250e 100644 --- a/servers/qemuserver/server.go +++ b/servers/qemuserver/server.go @@ -39,7 +39,7 @@ func NewServer(o *Options) (*Server, error) { options: o, audioHeader: make(chan *audio.WavHeader, 1), pcm: make(chan []byte), - ppm: make(chan io.ReadCloser), // to be configured + ppm: make(chan io.ReadCloser, 1), // to be configured } u, err := url.Parse(o.QmpAddress)