2022-09-26 03:04:07 +00:00
|
|
|
package qemuserver
|
|
|
|
|
|
|
|
import (
|
2022-10-02 11:29:57 +00:00
|
|
|
"fmt"
|
2022-09-26 03:04:07 +00:00
|
|
|
"net/url"
|
|
|
|
"os"
|
2022-10-02 11:29:57 +00:00
|
|
|
"path"
|
2022-09-26 03:04:07 +00:00
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
2022-10-02 11:29:57 +00:00
|
|
|
QmpAddress string `yaml:"address"`
|
|
|
|
Timeout time.Duration `yaml:"timeout"`
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
Audio AudioOptions `yaml:"audio_options"`
|
|
|
|
Video VideoOptions `yaml:"video_options"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AudioOptions struct {
|
|
|
|
Device string `yaml:"device"`
|
|
|
|
BufferSize uint16 `yaml:"buffer_size"` // in bytes
|
|
|
|
}
|
|
|
|
|
|
|
|
type VideoOptions struct {
|
|
|
|
Height int `yaml:"height"`
|
|
|
|
Width int `yaml:"width"`
|
|
|
|
FPS float32 `yaml:"fps"`
|
2022-09-26 03:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleOptions() *Options {
|
|
|
|
return &Options{
|
|
|
|
QmpAddress: (&url.URL{
|
2022-10-02 11:29:57 +00:00
|
|
|
Scheme: "tcp",
|
|
|
|
Host: "localhost:4444",
|
2022-09-26 03:04:07 +00:00
|
|
|
}).String(),
|
2022-10-02 11:29:57 +00:00
|
|
|
Timeout: time.Duration(30 * time.Second),
|
|
|
|
Name: "ace-qemu",
|
|
|
|
Audio: AudioOptions{
|
|
|
|
Device: "snd0",
|
|
|
|
BufferSize: 2048,
|
|
|
|
},
|
|
|
|
Video: VideoOptions{
|
2022-10-11 06:07:42 +00:00
|
|
|
Height: 768,
|
|
|
|
Width: 1024,
|
2022-10-12 03:23:14 +00:00
|
|
|
FPS: 30,
|
2022-10-02 11:29:57 +00:00
|
|
|
},
|
2022-09-26 03:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-02 11:29:57 +00:00
|
|
|
func (o *Options) MakeFIFO() (string, error) {
|
|
|
|
path := path.Join(
|
|
|
|
os.TempDir(),
|
|
|
|
fmt.Sprintf("%s-%s-audio", o.Name, o.Audio.Device),
|
|
|
|
)
|
|
|
|
os.Remove(path)
|
|
|
|
return path, syscall.Mkfifo(path, 0600)
|
2022-09-26 03:04:07 +00:00
|
|
|
}
|