From de24203100aa56142be5e5fbb03ac3c0369ffe0b Mon Sep 17 00:00:00 2001 From: TonyChyi Date: Tue, 27 Sep 2022 16:59:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E9=A2=91=E6=B5=81=E4=BB=8D=E7=84=B6?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E9=97=AE=E9=A2=98=EF=BC=8C=E5=90=8E=E7=BB=AD?= =?UTF-8?q?debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/audiodriver/wavheader.go | 18 +++++++++++++++--- lib/webrtcconnection/connection.go | 5 ++--- lib/webrtcconnection/options.go | 4 ---- servers/qemuserver/server.go | 13 +++++-------- web/src/components/AceScreen.vue | 11 +++++++---- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/lib/audiodriver/wavheader.go b/lib/audiodriver/wavheader.go index 4e3613a..2f0c2dd 100644 --- a/lib/audiodriver/wavheader.go +++ b/lib/audiodriver/wavheader.go @@ -11,9 +11,10 @@ import ( // Skip riff header and `fmt ` just 16 bytes const ( - FmtHeaderOffset int64 = 0x0c - FmtHeaderIDSize int64 = 4 - FmtHeaderChunkSizeSize int64 = 4 + FmtHeaderOffset = 0x0c + FmtHeaderIDSize = 4 + FmtHeaderChunkSizeSize = 4 + FmtHeaderSizeDefault = 16 ) type WavHeader struct { @@ -35,6 +36,17 @@ func NewHeader(f io.Reader) (*WavHeader, error) { return w, nil } +func DefaultHeader() *WavHeader { + return &WavHeader{ + Size: uint32(FmtHeaderSizeDefault), + AudioFormat: 1, + NumChannels: 2, + SampleRate: 48000, // opus only support 48kHz + BlockAlign: 4, + BitsPerSample: 16, + } +} + func (w *WavHeader) Parse(f io.Reader) error { // skip headers var headers [FmtHeaderOffset]byte diff --git a/lib/webrtcconnection/connection.go b/lib/webrtcconnection/connection.go index d827d8c..abc4da8 100644 --- a/lib/webrtcconnection/connection.go +++ b/lib/webrtcconnection/connection.go @@ -24,7 +24,7 @@ func New(o *Options) (*Connection, error) { connection := &Connection{ option: o, } - codecSelector, err := setupCodec(o.Video.BPS, o.Audio.BPS) + codecSelector, err := setupCodec(o.Video.BPS) if err != nil { return nil, err } @@ -123,7 +123,7 @@ func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDe return rtc.LocalDescription(), nil } -func setupCodec(videoBPS, audioBPS int) (*mediadevices.CodecSelector, error) { +func setupCodec(videoBPS int) (*mediadevices.CodecSelector, error) { x264Prarm, err := x264.NewParams() if err != nil { return nil, err @@ -134,7 +134,6 @@ func setupCodec(videoBPS, audioBPS int) (*mediadevices.CodecSelector, error) { if err != nil { return nil, err } - opusParam.BitRate = audioBPS codecSelector := mediadevices.NewCodecSelector( mediadevices.WithAudioEncoders(&opusParam), diff --git a/lib/webrtcconnection/options.go b/lib/webrtcconnection/options.go index cc321ce..38d41fd 100644 --- a/lib/webrtcconnection/options.go +++ b/lib/webrtcconnection/options.go @@ -7,9 +7,6 @@ type Options struct { Width int `yaml:"width"` BPS int `yaml:"bps"` } `yaml:"video"` - Audio struct { - BPS int `yaml:"bps"` - } `yaml:"audio"` } func ExampleOptions() *Options { @@ -22,6 +19,5 @@ func ExampleOptions() *Options { options.Video.BPS = 500_000 options.Video.Height = 768 options.Video.Width = 1024 - options.Audio.BPS = 96_000 return options } diff --git a/servers/qemuserver/server.go b/servers/qemuserver/server.go index e854e78..1d1983f 100644 --- a/servers/qemuserver/server.go +++ b/servers/qemuserver/server.go @@ -15,15 +15,12 @@ import ( "github.com/sirupsen/logrus" ) -const waveHeaderSize = 16 +const waveHeaderSize = audiodriver.FmtHeaderSizeDefault -var waveHeader = &audiodriver.WavHeader{ - Size: waveHeaderSize, - AudioFormat: 1, - NumChannels: 2, - SampleRate: 48000, // opus only support 48kHz - BlockAlign: 4, - BitsPerSample: 16, +var waveHeader *audiodriver.WavHeader + +func init() { + waveHeader = audiodriver.DefaultHeader() } type Server struct { diff --git a/web/src/components/AceScreen.vue b/web/src/components/AceScreen.vue index 4645b60..815fe7b 100644 --- a/web/src/components/AceScreen.vue +++ b/web/src/components/AceScreen.vue @@ -1,7 +1,10 @@ @@ -90,11 +93,11 @@ onMounted(() => { }; pc.ontrack = (ev) => { console.log(ev); - const el = document.createElement(ev.track.kind); - el.id = ev.track.kind; + const el = document.querySelector(`${ev.track.kind}#${ev.track.kind}`); el.srcObject = ev.streams[0]; el.autoplay = true; - el.controls = true; + el.controls = false; + el.oncontextmenu = () => false; document.getElementById("data").appendChild(el); };