def run(self): for oqueue, settings in zip(self.oqueues, self.settings): e = Lame(oqueue=oqueue, **settings) self.encoders.append(e) e.start() try: self.ctime = None for i, actions in enumerate(self.loop()): log.info("Rendering audio data for %d actions.", len(actions)) for a in actions: try: with Timer() as t: # TODO: Move the "multiple encoding" support into # LAME itself - it should be able to multiplex the # streams itself. self.encoders[0].add_pcm(a) self.infoqueue.put(generate_metadata(a)) log.info("Rendered in %fs!", t.ms) except: log.error("Could not render %s. Skipping.\n%s", a, traceback.format_exc()) gc.collect() except: log.error("Something failed in mixer.run:\n%s", traceback.format_exc()) self.stop() return
async def ensure_playing(self): async with self.cond: if not self.load_future: print('Waiting to play %s' % trackId) self.audio_fetcher.semaphore.acquire() print('Playing %s' % trackId) self.lame = Lame(**lame_args) self.lame.init_params() self.audio_fetcher.sink.target = self load_future = self.audio_fetcher.player.load( SpotifyId(trackId)) self.load_future = asyncio.futures.wrap_future( load_future, loop=self.audio_fetcher.loop) def done_cb(fut): x = asyncio.run_coroutine_threadsafe( self._load_complete(fut.exception()), loop=self.audio_fetcher.loop) self.load_future.add_done_callback(done_cb)