Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

Chrome produces no audio after reaching 50 audio output streams

During my testing, I have found out that reaching 50 audio output streams (as displayed in chrome://media-internals/ Audio tab) on a single tab causes the audio output to disappear. Does Chrome have a set maximum limit of audio output streams allowed per displayed tab? If so, is there some workaround for that? The Chrome version that I am using is Version 87.0.4280.141.

Whenever we're muting/unmuting the audio(second function below) and adjusting the mic volume(first function below), we create a new audio context. Does too many audio context instances caused the issue?

private setLocalStreamVolume(stream: MediaStream | undefined) {
    const context = new AudioContext()
    const destination = context.createMediaStreamDestination()
    const gainNode = context.createGain()
    if (stream) {
        for(const track of stream.getTracks()){
            const sourceStream = context.createMediaStreamSource(new MediaStream([track]));    
            sourceStream.connect(gainNode)
            gainNode.connect(destination)
            gainNode.gain.value = this._micVolume            
        }        
    }
    return destination.stream
  }


export function mixStreams(streams: Iterable<(MediaStream | undefined)>) {
    const context = new AudioContext()
    const mixedOutput = context.createMediaStreamDestination()
    for(const stream of streams)
        if(stream)
            for(const track of stream.getTracks()){
                const sourceStream = context.createMediaStreamSource(new MediaStream([track]));
                sourceStream.connect(mixedOutput);
            }
    return mixedOutput.stream.getTracks()[0]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Does too many audio context interactions caused the issue?

Too many AudioContext instances certainly will. In fact, on some systems you can only use a single AudioContext.

I'm not sure what your specific use case is, but you probably only need one AudioContext. All your MediaStreamSourceNodes can live in the same context.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...