muaz-khan / RecordRTC

RecordRTC is WebRTC JavaScript library for audio/video as well as screen activity recording. It supports Chrome, Firefox, Opera, Android, and Microsoft Edge. Platforms: Linux, Mac and Windows.
https://www.webrtc-experiment.com/RecordRTC/
MIT License
6.54k stars 1.75k forks source link

Failed to construct 'AudioContext': The number of hardware contexts provided (6) is greater than or equal to the maximum bound (6) #385

Open rusith opened 6 years ago

rusith commented 6 years ago

We use RecordRTC to record the window in a Chrome extension. The recording works fine except when we try to record the same window more continuously, it throws an error

background.js:18632 DOMException: Failed to construct 'AudioContext': The number of hardware contexts provided (6) is greater than or equal to the maximum bound (6).
    at getMixedAudioStream (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:91194:47)
    at MultiStreamsMixer.getMixedStream (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:91150:32)
    at MultiStreamRecorder.record (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:91427:55)
    at initRecorder (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:86221:23)
    at Object.startRecording (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:86201:9)
    at RecordingManager._callee3$ (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:85681:32)
    at tryCatch (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:39004:40)
    at Generator.invoke [as _invoke] (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:39238:22)
    at Generator.prototype.(anonymous function) [as next] (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:39056:21)
    at step (chrome-extension://lfgkmcnkcgpggkkdcblgecnbinfoeipb/scripts/background.js:5405:30)

Error throws from

this.$initializeRecordRtc();
this.state.rtc.startRecording(); // this line

$initializeRecordRtc() is something like below

  $initializeRecordRtc() {
    const config = {
      mimeType: 'video/webm',
      disableLogs: false,
      frameInterval: this.screenInfo.frameInterval,
      canvas: {
        width: this.screenInfo.width,
        height: this.screenInfo.height,
      },
      video: {
        width: this.screenInfo.width,
        height: this.screenInfo.height,
      },
      bufferSize: 16384,
      leftChannel: false,
    };
    if (this.state.rtc) {
      this.$stopAndClearRecorder();
    }
    this.state.rtc = RecordRTC([this.state.tabStream, this.state.audioStream], config);
  }

My code which stops the recording is something like this

$stopAndClearRecorder() {
    if (!this.state) {
      return;
    }
    try {
      if (this.state.rtc) {
        const clear = () => {
          try {
            this.state.rtc.clearRecordedData();
            this.state.rtc.destroy();
          } catch (e) { this.background.error(e); /* Ignored */ }
          this.$cleanStreams();
        };
        if (this.state.rtc.getState() === 'recording') {
          this.state.rtc.stopRecording(clear);
        }
        clear();
      }
    } catch (e) {
      this.background.log('Could not stop recording', e);
    }
  }

Thanks in advance !

jaymo107 commented 6 years ago

I think you should destroy the recorder too once you've cleared the data? Maybe this.state.rtc.destroy()?

If you're re-creating instances of the recorder each time there is a limit on how many you can create.

rusith commented 6 years ago

I updated the issue, now Im calling the destroy function but still the error is there.

rusith commented 6 years ago
DISTROYING
background.js:86887 undefined
background.js:86888 {AudioContext: ƒ}
background.js:86895 RecordRTC is destroyed.  // Destroy function has called 
rusith commented 6 years ago

I checked the RecordRTC's destroy function. when i call the destroy function, Storage.AudioContextConstructor is undefined.

           /*Code from RecordRTC.js from line 747 (I added the console.logs below)*/
            console.log('DESTROYING');
            console.log(Storage.AudioContextConstructor); // This is undefined
            console.log(Storage); // This is a function
            if (Storage.AudioContextConstructor) {
                Storage.AudioContextConstructor.close();
                Storage.AudioContextConstructor = null;
            }

See the above comment for the logs.

osukono commented 6 years ago

You should have only one AudioContext in the page.

rusith commented 6 years ago

RecordRTC should handle that, right ? the problem is, Storage.AudioContextConstructor is undefined when i call the destroy function. so the AudioContext created when starting the recording is not closing when the recording ends.

thijstriemstra commented 6 years ago

Same issue as https://github.com/muaz-khan/RecordRTC/issues/344

lmmProject commented 5 years ago

destroy useless