FEC and PLP exposed

This commit is contained in:
Amish Shah
2017-10-26 18:36:04 +01:00
parent cc4aa75a71
commit 6490d1b911
4 changed files with 19 additions and 12 deletions

View File

@@ -434,7 +434,9 @@ class VoiceConnection extends EventEmitter {
* @property {number} [seek=0] The time to seek to
* @property {number} [volume=1] The volume to play at
* @property {number} [passes=1] How many times to send the voice packet to reduce packet loss
* @property {number|string} [bitrate=48000] The bitrate (quality) of the audio.
* @property {number} [plp] Expected packet loss percentage
* @property {boolean} [fec] Enabled forward error correction
* @property {number|string} [bitrate=96] The bitrate (quality) of the audio in kbps
* If set to 'auto', the voice channel's bitrate will be used
*/

View File

@@ -29,7 +29,8 @@ nonce.fill(0);
* @extends {stream.Writable}
*/
class StreamDispatcher extends Writable {
constructor(player, streamOptions, streams) {
constructor(player, { seek = 0, volume = 1, passes = 1, fec, plp, bitrate = 96 } = {}, streams) {
const streamOptions = { seek, volume, passes, fec, plp, bitrate };
super(streamOptions);
/**
* The Audio Player that controls this dispatcher
@@ -55,6 +56,11 @@ class StreamDispatcher extends Writable {
// Still emitting end for backwards compatibility, probably remove it in the future!
this.emit('end');
});
if (typeof volume !== 'undefined') this.setVolume(volume);
if (typeof fec !== 'undefined') this.setFEC(fec);
if (typeof plp !== 'undefined') this.setPLP(plp);
if (typeof bitrate !== 'undefined') this.setBitrate(bitrate);
}
get _sdata() {

View File

@@ -46,14 +46,14 @@ class AudioPlayer extends EventEmitter {
}
}
playUnknownStream(stream, options = {}) {
playUnknownStream(stream, options) {
this.destroyDispatcher();
const ffmpeg = new prism.FFmpeg({ args: FFMPEG_ARGUMENTS });
stream.pipe(ffmpeg);
return this.playPCMStream(ffmpeg, options, { ffmpeg });
}
playPCMStream(stream, options = {}, streams = {}) {
playPCMStream(stream, options, streams = {}) {
this.destroyDispatcher();
const volume = streams.volume = new prism.VolumeTransformer16LE(null, { volume: 0.2 });
const opus = streams.opus = new prism.opus.Encoder({ channels: 2, rate: 48000, frameSize: 960 });
@@ -61,7 +61,7 @@ class AudioPlayer extends EventEmitter {
return this.playOpusStream(opus, options, streams);
}
playOpusStream(stream, options = {}, streams = {}) {
playOpusStream(stream, options, streams = {}) {
this.destroyDispatcher();
streams.opus = stream;
const dispatcher = this.dispatcher = this.createDispatcher(options, streams);
@@ -69,9 +69,8 @@ class AudioPlayer extends EventEmitter {
return dispatcher;
}
createDispatcher({ seek = 0, volume = 1, passes = 1 } = {}, streams) {
createDispatcher(options, streams) {
this.destroyDispatcher();
const options = { seek, volume, passes };
const dispatcher = new StreamDispatcher(this, options, streams);
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
return dispatcher;

View File

@@ -14,7 +14,7 @@ client.login(auth.token).then(() => console.log('logged')).catch(console.error);
const connections = new Map();
let broadcast;
var d;
client.on('debug', console.log);
client.on('error', console.log);
@@ -29,9 +29,7 @@ client.on('message', m => {
conn.player.on('error', (...e) => console.log('player', ...e));
if (!connections.has(m.guild.id)) connections.set(m.guild.id, { conn, queue: [] });
m.reply('ok!');
const d = conn.playOpusStream(
fs.createReadStream('C:/users/amish/downloads/s.ogg').pipe(new prism.OggOpusDemuxer())
);
d = conn.playStream(ytdl('https://www.youtube.com/watch?v=EUoe7cf0HYw', { filter: 'audioonly' }, { passes: 3 }));
});
} else {
m.reply('Specify a voice channel!');
@@ -42,7 +40,9 @@ client.on('message', m => {
.replace(/</g, '')
.replace(/>/g, '');
const stream = ytdl(url, { filter: 'audioonly' }, { passes: 3 });
m.guild.voiceConnection.playStream(stream);
d = m.guild.voiceConnection.playStream(stream);
d.setBitrate(1);
setTimeout(() => d.setBitrate(320), 5000);
}
} else if (m.content.startsWith('/skip')) {
if (connections.has(m.guild.id)) {