def music_delivery(self, session, frames, frame_size, num_frames, sample_type, sample_rate, channels): """Callback used by pyspotify""" if not self.push_audio_data: return 0 assert sample_type == 0, 'Expects 16-bit signed integer samples' capabilites = """ audio/x-raw-int, endianness=(int)1234, channels=(int)%(channels)d, width=(int)16, depth=(int)16, signed=(boolean)true, rate=(int)%(sample_rate)d """ % { 'sample_rate': sample_rate, 'channels': channels, } duration = audio.calculate_duration(num_frames, sample_rate) buffer_ = audio.create_buffer(bytes(frames), capabilites=capabilites, timestamp=self.buffer_timestamp, duration=duration) self.buffer_timestamp += duration if self.audio.emit_data(buffer_).get(): return num_frames else: return 0
def music_delivery(self, session, frames, frame_size, num_frames, sample_type, sample_rate, channels): """Callback used by pyspotify""" # pylint: disable = R0913 # Too many arguments (8/5) if not self.push_audio_data: return 0 assert sample_type == 0, 'Expects 16-bit signed integer samples' capabilites = """ audio/x-raw-int, endianness=(int)1234, channels=(int)%(channels)d, width=(int)16, depth=(int)16, signed=(boolean)true, rate=(int)%(sample_rate)d """ % { 'sample_rate': sample_rate, 'channels': channels, } duration = audio.calculate_duration(num_frames, sample_rate) buffer_ = audio.create_buffer(bytes(frames), capabilites=capabilites, timestamp=self.buffer_timestamp, duration=duration) self.buffer_timestamp += duration if self.audio.emit_data(buffer_).get(): return num_frames else: return 0
def music_delivery_callback( session, audio_format, frames, num_frames, audio_actor, seeking_event, push_audio_data_event, buffer_timestamp, held_buffers, ): # This is called from an internal libspotify thread. # Ideally, nothing here should block. if seeking_event.is_set(): # A seek has happened, but libspotify hasn't confirmed yet, so # we're dropping all audio data from libspotify. if num_frames == 0: # libspotify signals that it has completed the seek. We'll accept # the next audio data delivery. seeking_event.clear() return num_frames if not push_audio_data_event.is_set(): return 0 # Reject the audio data. It will be redelivered later. if not frames: return 0 # No audio data; return immediately. known_format = ( audio_format.sample_type == spotify.SampleType.INT16_NATIVE_ENDIAN ) assert known_format, "Expects 16-bit signed integer samples" duration = audio.calculate_duration(num_frames, audio_format.sample_rate) buffer_ = audio.create_buffer( bytes(frames), timestamp=buffer_timestamp.get(), duration=duration ) # Try to consume any held buffers. if held_buffers: while held_buffers: buf = held_buffers.popleft() consumed = audio_actor.emit_data(buf).get() if not consumed: held_buffers.appendleft(buf) break else: # No held buffer, don't apply back-pressure consumed = True if consumed: # Consumed all held buffers so take the new one libspotify delivered us. held_buffers.append(buffer_) buffer_timestamp.increase(duration) return num_frames else: # Pass back-pressure on to libspotify, next buffer will be redelivered. return 0
def music_delivery_callback( session, audio_format, frames, num_frames, audio_actor, seeking_event, push_audio_data_event, buffer_timestamp, ): # This is called from an internal libspotify thread. # Ideally, nothing here should block. if seeking_event.is_set(): # A seek has happened, but libspotify hasn't confirmed yet, so # we're dropping all audio data from libspotify. if num_frames == 0: # libspotify signals that it has completed the seek. We'll accept # the next audio data delivery. seeking_event.clear() return num_frames if not push_audio_data_event.is_set(): return 0 # Reject the audio data. It will be redelivered later. if not frames: return 0 # No audio data; return immediately. known_format = ( audio_format.sample_type == spotify.SampleType.INT16_NATIVE_ENDIAN) assert known_format, "Expects 16-bit signed integer samples" duration = audio.calculate_duration(num_frames, audio_format.sample_rate) buffer_ = audio.create_buffer(bytes(frames), timestamp=buffer_timestamp.get(), duration=duration) # We must block here to know if the buffer was consumed successfully. consumed = audio_actor.emit_data(buffer_).get() if consumed: buffer_timestamp.increase(duration) return num_frames else: return 0
def music_delivery_callback( session, audio_format, frames, num_frames, audio_actor, push_audio_data_event, buffer_timestamp): # This is called from an internal libspotify thread. # Ideally, nothing here should block. if not push_audio_data_event.is_set(): return 0 # Reject the audio data. It will be redelivered later. known_format = ( audio_format.sample_type == spotify.SampleType.INT16_NATIVE_ENDIAN) assert known_format, 'Expects 16-bit signed integer samples' capabilites = """ audio/x-raw-int, endianness=(int)1234, channels=(int)%(channels)d, width=(int)16, depth=(int)16, signed=(boolean)true, rate=(int)%(sample_rate)d """ % { 'channels': audio_format.channels, 'sample_rate': audio_format.sample_rate, } duration = audio.calculate_duration(num_frames, audio_format.sample_rate) buffer_ = audio.create_buffer( bytes(frames), capabilites=capabilites, timestamp=buffer_timestamp.get(), duration=duration) buffer_timestamp.increase(duration) # We must block here to know if the buffer was consumed successfully. consumed = audio_actor.emit_data(buffer_).get() if consumed: return num_frames else: return 0
def music_delivery_callback(session, audio_format, frames, num_frames, audio_actor, push_audio_data_event, buffer_timestamp): # This is called from an internal libspotify thread. # Ideally, nothing here should block. if not push_audio_data_event.is_set(): return 0 known_format = ( audio_format.sample_type == spotify.SampleType.INT16_NATIVE_ENDIAN) assert known_format, 'Expects 16-bit signed integer samples' capabilites = """ audio/x-raw-int, endianness=(int)1234, channels=(int)%(channels)d, width=(int)16, depth=(int)16, signed=(boolean)true, rate=(int)%(sample_rate)d """ % { 'channels': audio_format.channels, 'sample_rate': audio_format.sample_rate, } duration = audio.calculate_duration(num_frames, audio_format.sample_rate) buffer_ = audio.create_buffer(bytes(frames), capabilites=capabilites, timestamp=buffer_timestamp.get(), duration=duration) buffer_timestamp.increase(duration) # We must block here to know if the buffer was consumed successfully. if audio_actor.emit_data(buffer_).get(): return num_frames else: return 0
def music_delivery_callback( session, audio_format, frames, num_frames, audio_actor, seeking_event, push_audio_data_event, buffer_timestamp): # This is called from an internal libspotify thread. # Ideally, nothing here should block. if seeking_event.is_set(): # A seek has happened, but libspotify hasn't confirmed yet, so # we're dropping all audio data from libspotify. if num_frames == 0: # libspotify signals that it has completed the seek. We'll accept # the next audio data delivery. seeking_event.clear() return num_frames if not push_audio_data_event.is_set(): return 0 # Reject the audio data. It will be redelivered later. if not frames: return 0 # No audio data; return immediately. known_format = ( audio_format.sample_type == spotify.SampleType.INT16_NATIVE_ENDIAN) assert known_format, 'Expects 16-bit signed integer samples' duration = audio.calculate_duration(num_frames, audio_format.sample_rate) buffer_ = audio.create_buffer( bytes(frames), timestamp=buffer_timestamp.get(), duration=duration) # We must block here to know if the buffer was consumed successfully. consumed = audio_actor.emit_data(buffer_).get() if consumed: buffer_timestamp.increase(duration) return num_frames else: return 0