jonisb / AudioEndpointControl

A library to access and control audio devices (Soundcard speakers/mics) written in Python for Windows vista and later.
10 stars 3 forks source link

I wanted to touch base with ya. #37

Open kdschlosser opened 6 years ago

kdschlosser commented 6 years ago

I hope you are doing well. I haven't seen you that active in the EG forums. But here is some brain gravy for ya.

This is going to be EG directed. but it is an issue outside of EG as well There have been reports of a few anomalies.

These issues are kind of tricky to try and replicate But they do exist I can toss ya out some EG log files if ya like.

Problem 1 Remote Desktop sessions. They cause the installation of a virtual sound card and the removal of the physical one. As you can see this would cause an issue if the person logs into the machine remotely and an Action that specifies a device that is no longer there. This is easily fixed in EG by using the System.RemoteConnect to disable all actions pertaining to the hardware sound card and the System.RemoteDisconnect to enable them again.

Problem 2 Remote Desktop sessions, If you connect and for some reason get a drop and an automatic reconnect kicks in and while the process of adding back in the physical sound card drivers is taking place. windows will stop the install of the physical ones and remove them and install the virtual ones. if it so happens that the sound card is being processed by AudioEndpoint at that time you will get a traceback because all of a sudden in the middle of gathering information from windows about the card it is deleted and then another call is made to windows for more information about a non existent card.

Problem 3 This has to deal more so with how your library is accessed rather then an issue with the library it's self. But I wanted to make mention of it in any case. This issues causes phantom bugs and weird unrelated issues that don't point to a cause. I ran into the same problem and it took me a while to figure out what it was. You have to start your library from the main thread for a process this is due to the use of the Notifications and callbacks. Windows only likes to deal with the main thread because of reduced overhead. As an example in EG when __start__ is called it is not called from the main thread. it is called from the action thread. Now there are no guarantees on even having an issue. it's very strange about when it decides to cause problems. solution is to move all initialization code for the library to a method/function that we can have the main thread run instead of the action thread.

import threading
import wx

class MyPlugin(eg.PluginBase):
    def __start__(self, **kwargs):
        err = [None]
        event = threading.Event()
        def run():
            try:
                # Do code here
            except Exception as e:
                err.insert(0, e)
            event.set()
        wx.CallAfter(run)
        event.wait(5.0)
        if err[0] is not None:
            raise err[0]
        if not event.isSet():
            raise eg.Exceptions.InitFailed

This will cause the plugin to wait until the main thread has has finished processing the init of the lib. and because if any errors take place in a different thread they will not populate properly and the plugin will continue along it merry way. This allows for proper handling of an Exception and also if the thread simply gets stuck and never returns. Tho this would cause EG to crash because it's the main thread that would get stuck So there is not much we can do about this. as there is no way to terminate the thing from running. The use of wx.CallAfter is what injects the code to be run into the main thread. the main thread is in a looping cycle caused by wx.APP.MainLoop.

On another note. I looked at some of the issues you have posted up. I have been doing some tinkering. I have completely mapped out the whole Core Audio API into python code. and I do mean all of it. I am just tidying up the code and making sure I didn't miss something. But this code removes the need for the tbl files and the use of comtypes to generate the code. It end up being self contained in that respect. You will still need the comtypes lib in order for this to run otherwise you would have to add the bits that comtypes provides into the library. I am not sure if you can grab the most recent version of comtypes from pypi or not. Buy you can include it if ya wanted to i guess.

I should be able to shoot the code for the Core Audio API over to ya if ya want within the next few days.

Happy New Year as well..

jonisb commented 6 years ago

I hope you are doing well. I haven't seen you that active in the EG forums.

Unfortunately not that good, a bit better lately, I haven't been able to keep up on EG forum activities even though I go there every day just to check the moderator queue.

I have gotten a bit more done the last month but only on one project.

Problem 1 & Problem 2

Interesting, I have setup Remote desktop to access my HTPC so I might look into this at some point.

Problem 3

I'll look at this again when I'm actually able to think.

I should be able to shoot the code for the Core Audio API over to ya if ya want within the next few days.

Sure I'm interested but this project has very low priority both because of me failing to finish what I wanted to do last year and also because I don't need the functionality like I did before building my HTPC

Happy New Year as well..

Same to you as well

jonib

kdschlosser commented 6 years ago

I attached a rough draft of what I have been doing with the Core Audio API. I am still doing some tweaking. but you can browse through the code and have a gander.

I think you may change your mind on the usefulness of this. It exposes the speaker orientation, tone control, sound effects. DSP. Basically everything that you can do in the sound properties and more.

I have started to add the ks and ksmedia items but i am thinking they are not going to be of any real use

windows_core_audio.zip

jonisb commented 6 years ago

I attached a rough draft of what I have been doing with the Core Audio API

I check it out later, thanks.

I think you may change your mind on the usefulness of this

I wont dispute its usefulness, but I need to prioritize projects I actually need or want right now or I will never get anything done. :'-(

jonib

kdschlosser commented 6 years ago

I hear ya there, But this is available to ya if ya want it.

Here is a more updated version and if you run the init make sure you turn your speakers down (the physical volume on the speakers)

windows_core_audio.zip

kdschlosser commented 6 years ago

hey buddy. I wanted to show ya where I have gotten with this. You might be able to shed some light on a few things for me, that is if ya want to. I am having an issue with the KsJackSinkInformation maybe you can get it functioning properly.

here is the updated version. You can run the init and it will show a demo

https://github.com/kdschlosser/pyWinCoreAudio

jonisb commented 6 years ago

I am having an issue with the KsJackSinkInformation maybe you can get it functioning properly.

I'm not familiar with that functionality and probably won't look into it for a while, sorry.

here is the updated version. You can run the init and it will show a demo

Cool, I'll have a look at it later.

Working on and learning to do a Kodi plugin at the moment.

jonib