Skip to content

Commit

Permalink
- Stopped recording before stopping the decoder (I think this should …
Browse files Browse the repository at this point in the history
…fix the other issue

- Added a timeout for stop so it never goes infinite
  • Loading branch information
baribarton committed May 28, 2024
1 parent 0ed1f2c commit fbdf6a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions discord/opus.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ def decode(self, data, *, fec=False):
frame_size = frames * samples_per_frame

pcm = (
ctypes.c_int16
* (frame_size * channel_count * ctypes.sizeof(ctypes.c_int16))
ctypes.c_int16
* (frame_size * channel_count * ctypes.sizeof(ctypes.c_int16))
)()
pcm_ptr = ctypes.cast(pcm, c_int16_ptr)

Expand Down Expand Up @@ -556,11 +556,22 @@ def run(self):
self.client.recv_decoded_audio(data)

def stop(self):
start_time = time.time() # Capture the start time of the loop
timeout_duration = 5 # Timeout duration in seconds

while self.decoding:
elapsed_time = time.time() - start_time
if elapsed_time > timeout_duration:
_log.error(
f"Timeout exceeded while waiting for the decoder to stop. "
f"Discarding the {len(self.decode_queue)} remaining in the queue. Decoder Process Killed")
break

time.sleep(0.1)
self.decoder = {}
gc.collect()
print("Decoder Process Killed")

print("Decoder Process Killed")
self._end_thread.set()

def get_decoder(self, ssrc):
Expand Down
2 changes: 1 addition & 1 deletion discord/voice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,9 @@ def stop_recording(self):
"""
if not self.recording:
raise RecordingException("Not currently recording audio.")
self.decoder.stop()
self.recording = False
self.paused = False
self.decoder.stop()

def toggle_pause(self):
"""Pauses or unpauses the recording.
Expand Down

0 comments on commit fbdf6a6

Please sign in to comment.