Skip to content

Commit 1f3e734

Browse files
committed
fix: not properly apply filters
This commit fixes a bug that when seeking then later using only native filters, it would not continue from where it start (quick-filtering).
1 parent ccbf670 commit 1f3e734

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/connection/voiceHandler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ class VoiceConnection {
260260
const filter = new Filters()
261261
filter.configure(this.config.filters)
262262

263+
this.config.filters = {}
263264
filter.filters.forEach((filter) => {
264265
if (typeof filter.type !== 'number' && filter.name !== 'timescale') return;
265266

@@ -346,6 +347,7 @@ class VoiceConnection {
346347
const filter = new Filters()
347348
filter.configure(filters, this.config.track.info)
348349

350+
this.config.filters = {}
349351
filter.filters.forEach((filter) => {
350352
if (typeof filter.type !== 'number' && filter.name !== 'timescale') return;
351353

src/filters.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class Filters {
193193
const startTime = this.filters.find((filter) => filter.name === 'seek')?.data
194194
const endTime = this.filters.find((filter) => filter.name === 'endTime')?.data
195195

196-
const isDecodedInternally = voiceUtils.isDecodedInternally(streamInfo.format)
196+
const isDecodedInternally = voiceUtils.isDecodedInternally(currentStream, streamInfo.format)
197197
if (startTime === undefined && isDecodedInternally !== false && this.command.length === 0 && !endTime) {
198198
const filtersClasses = []
199199

@@ -203,7 +203,7 @@ class Filters {
203203
filtersClasses.push(new filters.Interface(filter.type, filter.data))
204204
})
205205

206-
if (currentStream && !currentStream.ffmpeged) {
206+
if (currentStream && (currentStream.ffmpegState !== 1 || !currentStream.ffmpegState)) {
207207
if (currentStream.filtersIndex.length === 0) {
208208
currentStream.detach()
209209
currentStream.pipes = addPartAt(currentStream.pipes, isDecodedInternally, filtersClasses)
@@ -229,7 +229,7 @@ class Filters {
229229

230230
const pureStream = await sources.getTrackStream(decodedTrack, streamInfo.url, streamInfo.protocol)
231231

232-
const stream = new voiceUtils.createAudioResource(pureStream.stream, streamInfo.format, filterClasses, true)
232+
const stream = new voiceUtils.createAudioResource(pureStream.stream, streamInfo.format, filterClasses, 0)
233233

234234
resolve({ stream })
235235
}
@@ -282,7 +282,10 @@ class Filters {
282282
})
283283
)
284284

285-
resolve({ stream: new voiceUtils.NodeLinkStream(stream, pipelines, [], true) })
285+
const onlySeeked = Object.keys(this.filters).length === 1 && this.filters.find((filter) => filter.name === 'seek')
286+
const ffmpegState = (this.command.length !== 0 || !onlySeeked) ? 1 : 2
287+
288+
resolve({ stream: new voiceUtils.NodeLinkStream(stream, pipelines, ffmpegState) })
286289
})
287290
}
288291
} catch (err) {

src/voice/utils.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import constants from '../../constants.js'
44
import prism from 'prism-media'
55

66
class NodeLinkStream {
7-
constructor(stream, pipes, ffmpeged) {
7+
constructor(stream, pipes, ffmpegState) {
88
pipes.unshift(stream)
99

1010
for (let i = 0; i < pipes.length - 1; i++) {
@@ -18,7 +18,7 @@ class NodeLinkStream {
1818
this.listeners = []
1919
this.pipes = pipes
2020
this.filtersIndex = []
21-
this.ffmpeged = ffmpeged
21+
this.ffmpegState = ffmpegState
2222

2323
/* @performanc/voice event */
2424
stream.on('finishBuffering', () => this.emit('finishBuffering'))
@@ -90,16 +90,16 @@ class NodeLinkStream {
9090
}
9191
}
9292

93-
function isDecodedInternally(type) {
93+
function isDecodedInternally(stream, type) {
9494
switch (type) {
9595
case 'webm/opus':
96-
case 'ogg/opus': return 3 + 1
97-
case 'wav': return 2 + 1
96+
case 'ogg/opus': return 3 + 1 + (stream.ffmpegState === 2 ? -2 : 0)
97+
case 'wav': return 2 + 1 + (stream.ffmpegState === 2 ? -2 : 0)
9898
default: return false
9999
}
100100
}
101101

102-
function createAudioResource(stream, type, additionalPipes = [], ffmpeged = false) {
102+
function createAudioResource(stream, type, additionalPipes = [], ffmpegState = false) {
103103
if ([ 'webm/opus', 'ogg/opus' ].includes(type)) {
104104
return new NodeLinkStream(stream, [
105105
new prism.opus[type === 'webm/opus' ? 'WebmDemuxer' : 'OggDemuxer'](),
@@ -111,7 +111,7 @@ function createAudioResource(stream, type, additionalPipes = [], ffmpeged = fals
111111
channels: constants.opus.channels,
112112
frameSize: constants.opus.frameSize
113113
})
114-
], ffmpeged)
114+
], ffmpegState)
115115
}
116116

117117
if (type === 'wav') {
@@ -123,7 +123,7 @@ function createAudioResource(stream, type, additionalPipes = [], ffmpeged = fals
123123
channels: constants.opus.channels / 2,
124124
frameSize: constants.opus.frameSize / 2
125125
})
126-
], ffmpeged)
126+
], ffmpegState)
127127
}
128128

129129
const ffmpeg = new prism.FFmpeg({
@@ -151,7 +151,7 @@ function createAudioResource(stream, type, additionalPipes = [], ffmpeged = fals
151151
channels: constants.opus.channels,
152152
frameSize: constants.opus.frameSize
153153
})
154-
], ffmpeged)
154+
], ffmpegState)
155155
}
156156

157157
export default {

0 commit comments

Comments
 (0)