def _update_play_cursor(self): if not self._al_source: return self._lock.acquire() context.lock() # Release spent buffers processed = al.ALint() al.alGetSourcei(self._al_source, al.AL_BUFFERS_PROCESSED, processed) processed = processed.value if processed: buffers = (al.ALuint * processed)() al.alSourceUnqueueBuffers(self._al_source, len(buffers), buffers) error = al.alGetError() if error != 0: if _debug_buffers: print ("Source unqueue error: " + str(error)) else: for b in buffers: bufferPool.dequeueBuffer(self._al_source, b) context.unlock() if processed: if len(self._buffer_timestamps) == processed and self._buffer_timestamps[-1] is not None: # Underrun, take note of timestamp. # We check that the timestamp is not None, because otherwise # our source could have been cleared. self._underrun_timestamp = self._buffer_timestamps[-1] + self._buffer_sizes[-1] / float( self.source_group.audio_format.bytes_per_second ) self._buffer_cursor += sum(self._buffer_sizes[:processed]) del self._buffer_sizes[:processed] del self._buffer_timestamps[:processed] if not context.have_1_1: self._buffer_system_time = time.time() # Update play cursor using buffer cursor + estimate into current # buffer if context.have_1_1: bytes = al.ALint() context.lock() al.alGetSourcei(self._al_source, al.AL_BYTE_OFFSET, bytes) context.unlock() if _debug: print "got bytes offset", bytes.value self._play_cursor = self._buffer_cursor + bytes.value else: # Interpolate system time past buffer timestamp self._play_cursor = self._buffer_cursor + int( (time.time() - self._buffer_system_time) * self.source_group.audio_format.bytes_per_second ) # Process events while self._events and self._events[0][0] < self._play_cursor: _, event = self._events.pop(0) event._sync_dispatch_to_player(self.player) self._lock.release()
def _update_play_cursor(self): if not self._al_source: return self._lock.acquire() context.lock() # Release spent buffers processed = al.ALint() al.alGetSourcei(self._al_source, al.AL_BUFFERS_PROCESSED, processed) processed = processed.value if processed: buffers = (al.ALuint * processed)() al.alSourceUnqueueBuffers(self._al_source, len(buffers), buffers) al.alDeleteBuffers(len(buffers), buffers) context.unlock() if processed: if len(self._buffer_timestamps) == processed: # Underrun, take note of timestamp self._underrun_timestamp = \ self._buffer_timestamps[-1] + \ self._buffer_sizes[-1] / \ float(self.source_group.audio_format.bytes_per_second) self._buffer_cursor += sum(self._buffer_sizes[:processed]) del self._buffer_sizes[:processed] del self._buffer_timestamps[:processed] if not context.have_1_1: self._buffer_system_time = time.time() # Update play cursor using buffer cursor + estimate into current # buffer if context.have_1_1: bytes = al.ALint() context.lock() al.alGetSourcei(self._al_source, al.AL_BYTE_OFFSET, bytes) context.unlock() if _debug: print 'got bytes offset', bytes.value self._play_cursor = self._buffer_cursor + bytes.value else: # Interpolate system time past buffer timestamp self._play_cursor = \ self._buffer_cursor + int( (time.time() - self._buffer_system_time) * \ self.source_group.audio_format.bytes_per_second) # Process events while self._events and self._events[0][0] < self._play_cursor: _, event = self._events.pop(0) event._sync_dispatch_to_player(self.player) self._lock.release()
def _update_play_cursor(self): if not self._al_source: return with self._lock: with context.lock: # Release spent buffers processed = al.ALint() al.alGetSourcei(self._al_source, al.AL_BUFFERS_PROCESSED, processed) processed = processed.value if _debug_buffers: print("Processed buffer count:", processed) if processed: buffers = (al.ALuint * processed)() al.alSourceUnqueueBuffers(self._al_source, len(buffers), buffers) error = al.alGetError() if error != 0: if _debug_buffers: print("Source unqueue error: " + str(error)) else: for b in buffers: bufferPool.dequeueBuffer(self._al_source, b) if processed: if (len(self._buffer_timestamps) == processed and self._buffer_timestamps[-1] is not None): # Underrun, take note of timestamp. # We check that the timestamp is not None, because otherwise # our source could have been cleared. self._underrun_timestamp = \ self._buffer_timestamps[-1] + \ self._buffer_sizes[-1] / \ float(self.source_group.audio_format.bytes_per_second) self._buffer_cursor += sum(self._buffer_sizes[:processed]) del self._buffer_sizes[:processed] del self._buffer_timestamps[:processed] if not context.have_1_1: self._buffer_system_time = time.time() # Update play cursor using buffer cursor + estimate into current # buffer if context.have_1_1: byte_offset = al.ALint() with context.lock: al.alGetSourcei(self._al_source, al.AL_BYTE_OFFSET, byte_offset) if _debug: print 'Current offset in bytes:', byte_offset.value self._play_cursor = self._buffer_cursor + byte_offset.value else: # Interpolate system time past buffer timestamp self._play_cursor = \ self._buffer_cursor + int( (time.time() - self._buffer_system_time) * \ self.source_group.audio_format.bytes_per_second) # Process events while self._events and self._events[0][0] < self._play_cursor: _, event = self._events.pop(0) event._sync_dispatch_to_player(self.player)