-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
When creating a stream with opus that is volume controled volume: true it does NOT destroy the stream upon .end() or .destroy() function calls. In contrary, when source stream ends, it gets destroyed from source.
On playOpusStream in line 71 you can see that a pipe is used to enable for volume adjustments.
streams.opus = stream
.pipe(decoder)
.pipe(streams.volume)
.pipe(new prism.opus.Encoder({ channels: 2, rate: 48000, frameSize: 960 }));Piping the source stream to current dispatcher creates an intermediate which prevents _destroy() from destroying the source opus stream.
_destroy(err, cb) {
this._cleanup();
super._destroy(err, cb);
}
_cleanup() {
if (this.player.dispatcher === this) this.player.dispatcher = null;
const { streams } = this;
if (streams.broadcast) streams.broadcast.delete(this);
if (streams.opus) streams.opus.destroy();
if (streams.ffmpeg) streams.ffmpeg.destroy();
}Reproduce
With the following code, you execute the destroy function dispatcher.destroy(); and the stream will still run, in the background idle (can be seen using top in terminal)
function create_dispatcher(
video_options: yts.VideoSearchResult, voice_connection: VoiceConnection
): StreamDispatcher {
const stream = ytdl(video_options.url, {
filter: 'audioonly',
opusEncoded: true,
encoderArgs: ['-af', 'bass=g=10, dynaudnorm=f=200']
});
const stream_options = <StreamOptions>{
type: 'opus'
}
return voice_connection.play(stream, stream_options);
}In order to destroy the source stream you must add volume: false option in StreamOptions
const stream_options = <StreamOptions>{
type: 'opus',
volume: false
}Note that setting a custom
bitratewill also trigger a pipe and thus not destroy upon destroy()
This probably is not the intended behaviour, and should probably be handled seperately.
Related errors:
Further details:
- discord.js version: 12.5.1 (stable)
- Node.js version: 14.16.0
- Operating system: (Ubuntu 20.04.2 LTS focal)
- Priority this issue should have: medium
not essential but causes bots to crash and run artificially slow