音频流仍然存在问题,后续debug

This commit is contained in:
TonyChyi
2022-09-27 16:59:47 +08:00
parent b7b7e78614
commit de24203100
5 changed files with 29 additions and 22 deletions

View File

@@ -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

View File

@@ -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),

View File

@@ -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
}