音频流仍然存在问题,后续debug
This commit is contained in:
parent
b7b7e78614
commit
de24203100
@ -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
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -1,7 +1,10 @@
|
||||
<template>
|
||||
<div>
|
||||
<canvas id="vnc" />
|
||||
<div id="data"></div>
|
||||
<div id="data">
|
||||
<video id="video" muted autoplay />
|
||||
<audio id="audio" autoplay />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user