JJMumbleBot icon indicating copy to clipboard operation
JJMumbleBot copied to clipboard

[Bug] adding a track to the playlist often causes an audio glitch

Open rhetr opened this issue 4 years ago • 4 comments

often when I add a track to the playlist eg with !link, the audio playback will stutter/glitch, sometimes for up to a second. I also see in htop that the cpu usage of jjmumblebot goes past 100% when it is glitching. it looks like whatever new process is created briefly uses 100% of the cpu, which causes the glitch.

rhetr avatar Jan 30 '22 19:01 rhetr

Unfortunately this isn't something that can be fixed easily, the track provided from the link is prepared and the metadata/thumbnail image data is downloaded causing brief stuttering. There isn't really much I can do to optimize this further at this time.

DuckBoss avatar Jan 31 '22 01:01 DuckBoss

not sure if this is usable but i just tried the following in cmd_link:

            # song_data = md_utility.get_video_info(stripped_url)
            from multiprocessing import Process, Queue
            q = Queue()
            p1 = Process(target = md_utility.get_video_info, args = (stripped_url, q))
            p1.start()
            song_data = q.get()
            p1.join()

then I added q = None as an arg to media_utility.get_video_info:

def get_video_info(video_url, q = None):
...
            prep_struct = {
                'std_url': video_url,
                'main_url': info_dict['url'],
                'main_title': info_dict['title'],
                'main_id': info_dict['id'],
                'duration': info_dict['duration']
            }
            if q:
                q.put(prep_struct)
                return

in preliminary tests there seems to be no glitching :) do you think this might make sense to use?

rhetr avatar Jan 31 '22 02:01 rhetr

That's an interesting solution, I'll have to test it out after I fix some other issues!

DuckBoss avatar Jan 31 '22 15:01 DuckBoss

Your solution seems to work! I'll have to keep testing it further to see if it breaks anywhere, but so far it's looking good.

DuckBoss avatar Jan 31 '22 19:01 DuckBoss