Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
[voice] add on_complete callback to DCADOpusEncoderPlayable
Browse files Browse the repository at this point in the history
  • Loading branch information
b1naryth1ef committed Jul 17, 2017
1 parent a522a90 commit 78ac2c4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions disco/voice/playable.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class DCADOpusEncoderPlayable(BasePlayable, AbstractOpus, OpusEncoder):
def __init__(self, source, *args, **kwargs):
self.source = source
self.command = kwargs.pop('command', 'dcad')
self.on_complete = kwargs.pop('on_complete', None)
super(DCADOpusEncoderPlayable, self).__init__(*args, **kwargs)

self._done = False
Expand Down Expand Up @@ -270,13 +271,15 @@ def next_frame(self):
header = self.proc.stdout.read(OPUS_HEADER_SIZE)
if len(header) < OPUS_HEADER_SIZE:
self._done = True
self.on_complete()
return

size = struct.unpack('<h', header)[0]

data = self.proc.stdout.read(size)
if len(data) < size:
self._done = True
self.on_complete()
return

return data
Expand Down

0 comments on commit 78ac2c4

Please sign in to comment.