Re: Cannot callback the server in notification thread!

Ethan Funk <[email protected]> Fri, 09 Aug 2019 09:01:08 -0700
Newsgroups gmane.comp.audio.jackit
Organization Red Mountain Radio LLC
Message-ID <101e4ba2e4e76be0004cfaae902b62a5cdf0a805.camel@redmountainradio.com>
--===============8151974264177947617==
Content-Type: multipart/signed; micalg="pgp-sha512";
	protocol="application/pgp-signature"; boundary="=-iuIbU5optu/UKRUiPDol"


--=-iuIbU5optu/UKRUiPDol
Content-Type: multipart/alternative; boundary="=-eqNwecimh4Tvlz+a3A0+"


--=-eqNwecimh4Tvlz+a3A0+
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Yes, what you describe is what I am implementing.  I have also called
it "persistence" in my application. Normally, when all audio ports are
disconnected, my application quits.  But I have an command line option
to keep it running and have it "persist," not quit, try to reconnect.
I just implemented a simple queue of jack_port_ids.  Callbacks add
their relevant port_ids into the queue, with my main thread checking
the queue periodically, to further check the queued ports for re-
connection.  This was not as hard as I though it would be, and works
well so far.  Just queueing the port id is a lot simpler that what you
are doing in MusE, but it is sufficient for my application.
One remaining question: Am I safe assuming that jack2 will call my
callbacks one at a time from a single thread, or do I need to make my
port id queue writing function thread safe, just in case jack2 calls my
callbacks concurrently?
Ethan...
On Fri, 2019-08-09 at 01:52 -0400, Tim wrote:
> On 8/8/19 10:20 PM, Ethan Funk wrote:
> > In an application I am writing, I am getting an error message out
> > stderr (see email subject), and a connection failure return result,
> > when I try to use jack_connect() from inside a
> > jack_set_port_registration_callback function, using Jack2. My goal
> > is to have the application remember and re-connect to a
> > disconnected port if/when it "comes back." Am I going to need to
> > create a mostly sleeping thread just for port re-connections
> > attempts, or is there something obvious I am missing?
> > Thanks,Ethan...
>=20
> If I understand your goal, I did this in MusE.I called it 'persistent
> connections', or 'persistent ports'.
> For example you can unplug a USB midi device currently  in use by
> MusE as a 'Jack device', then re-plug it,  and MusE will
> automatically reconnect to its ports  as if nothing happened and you
> may continue playing.(I made our 'ALSA devices' do the same thing!)It
> should also work with other Jack clients.
> Look in our driver/jack.cpp, at:   static void
> registration_callback(...),   static void
> port_connect_callback(...),  and   static int
> graph_callback(...),   // This is called in the gui
> context,   //  triggered by graph_callback()   void
> JackAudioDevice::graphChanged().
> It was complicated. Very. I needed to support Jack 1 and 2.So there
> are a few sequences of calls and resulting  sequences of callbacks
> for example that are different  in Jack 1 and 2. Several tricks and
> traps. See comments.
> My system relies HEAVILY on the jack port 'alias names',  because it
> was pretty much the ONLY thing you can rely on,  because the regular
> port names and port numbers change  upon re-plugging. It
> automatically chooses which alias is  best or falls back to the not
> so good canonical port name.
> So, that's what it 'remembers' between device plug ins -  simply the
> port alias or name text.
> HTH.Tim._______________________________________________Jack-Devel
> mailing [email protected]
> http://lists.jackaudio.org/listinfo.cgi/jack-devel-jackaudio.org

--=-eqNwecimh4Tvlz+a3A0+
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<html dir=3D"ltr"><head></head><body style=3D"text-align:left; direction:lt=
r;"><div>Yes, what you describe is what I am implementing.  I have also cal=
led it "persistence" in my application. Normally, when all audio ports are =
disconnected, my application quits.  But I have an command line option to k=
eep it running and have it "persist," not quit, try to reconnect.</div><div=
><br></div><div>I just implemented a simple queue of jack_port_ids.  Callba=
cks add their relevant port_ids into the queue, with my main thread checkin=
g the queue periodically, to further check the queued ports for re-connecti=
on.  This was not as hard as I though it would be, and works well so far.  =
Just queueing the port id is a lot simpler that what you are doing in MusE,=
 but it is sufficient for my application.</div><div><br></div><div>One rema=
ining question: Am I safe assuming that jack2 will call my callbacks one at=
 a time from a single thread, or do I need to make my port id queue writing=
 function thread safe, just in case jack2 calls my callbacks concurrently?<=
/div><div><br></div><div>Ethan...</div><div><br></div><div>On Fri, 2019-08-=
09 at 01:52 -0400, Tim wrote:</div><blockquote type=3D"cite" style=3D"margi=
n:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>On 8/8/1=
9 10:20 PM, Ethan Funk wrote:</pre><blockquote type=3D"cite" style=3D"margi=
n:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>In an ap=
plication I am writing, I am getting an error message out stderr </pre><pre=
>(see email subject), and a connection failure return result, when I try </=
pre><pre>to use jack_connect() from inside a jack_set_port_registration_cal=
lback </pre><pre>function, using Jack2. My goal is to have the application =
remember and </pre><pre>re-connect to a disconnected port if/when it "comes=
 back." Am I going to </pre><pre>need to create a mostly sleeping thread ju=
st for port re-connections </pre><pre>attempts, or is there something obvio=
us I am missing?</pre><pre><br></pre><pre>Thanks,</pre><pre>Ethan...</pre><=
/blockquote><pre><br></pre><pre>If I understand your goal, I did this in Mu=
sE.</pre><pre>I called it 'persistent connections', or 'persistent ports'.<=
/pre><pre><br></pre><pre>For example you can unplug a USB midi device curre=
ntly</pre><pre>  in use by MusE as a 'Jack device', then re-plug it,</pre><=
pre>  and MusE will automatically reconnect to its ports</pre><pre>  as if =
nothing happened and you may continue playing.</pre><pre>(I made our 'ALSA =
devices' do the same thing!)</pre><pre>It should also work with other Jack =
clients.</pre><pre><br></pre><pre>Look in our driver/jack.cpp, at:</pre><pr=
e>   static void registration_callback(...),</pre><pre>   static void port_=
connect_callback(...),</pre><pre>  and</pre><pre>   static int graph_callba=
ck(...),</pre><pre>   // This is called in the gui context,</pre><pre>   //=
  triggered by graph_callback()</pre><pre>   void JackAudioDevice::graphCha=
nged().</pre><pre><br></pre><pre>It was complicated. Very. I needed to supp=
ort Jack 1 and 2.</pre><pre>So there are a few sequences of calls and resul=
ting</pre><pre>  sequences of callbacks for example that are different</pre=
><pre>  in Jack 1 and 2. Several tricks and traps. See comments.</pre><pre>=
<br></pre><pre>My system relies HEAVILY on the jack port 'alias names',</pr=
e><pre>  because it was pretty much the ONLY thing you can rely on,</pre><p=
re>  because the regular port names and port numbers change</pre><pre>  upo=
n re-plugging. It automatically chooses which alias is</pre><pre>  best or =
falls back to the not so good canonical port name.</pre><pre><br></pre><pre=
>So, that's what it 'remembers' between device plug ins -</pre><pre>  simpl=
y the port alias or name text.</pre><pre><br></pre><pre>HTH.</pre><pre>Tim.=
</pre><pre>_______________________________________________</pre><pre>Jack-D=
evel mailing list</pre><a href=3D"mailto:[email protected]"><p=
re>[email protected]</pre></a><pre><br></pre><a href=3D"http:/=
/lists.jackaudio.org/listinfo.cgi/jack-devel-jackaudio.org"><pre>http://lis=
ts.jackaudio.org/listinfo.cgi/jack-devel-jackaudio.org</pre></a><pre><br></=
pre></blockquote></body></html>

--=-eqNwecimh4Tvlz+a3A0+--

--=-iuIbU5optu/UKRUiPDol
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEqU7GtX8ebNmJMAKgrX6X36Kjo04FAl1NmMQACgkQrX6X36Kj
o05+ohAApB15uQp6oYxFx2H0whH77cILudZECJGX8Of7erZktT9Ikir94TZQD6nT
vSxoJ/0u/g4ojtcie4O50aBbYAyUTnCTeFRhTa81Wf9uc6WVwUGC1s3kWkgC7Lhr
Nv+oIsc7WIdqrzFmL/n/91k2w7tZrCb8UE9iyH2up6M9TMfUspifbqI4JonSrr8Y
m6wT4jaIbXYDLLTnvmSHwpeOFIM7RbC5jVHQDhPt9E0nMiUBgD6RAfl7weepeqU4
26432GrFjkAUB1XAwRyPpAL9Iy+B2vZyno5ROZzQfor6U3aWuDBB3h671JfkAvim
ENpD9wWJgBcRqVJdyhSdCTqSLvJkIzgjJMVZhIFJZtx9ukn/FUUqgjAXL23dK/6g
KDHzcMek+Y18EiVPheimg6WM8d3AdsfSy1feG1fbXmR4kjiZYlufNw3g0dga9F2K
W5NR7nkAxvrkDw5ElGKqxzosLhP4zHDt7rctZGwKxkMZbH/mL8+wdn6Z0DV5RBPq
G0fxaOT7NvWpoqa1wvkGFSXO8I3v13SmbxVouISxlpbxk3QVtemtMShadWJ1de1e
aM9NZk5oebg3BIbA+IDJIHNomm9FoDbvWdzcBh/dvO4Gplwmr96zUBz/3urWJrkq
/mIwO+g8Ni9EobXbrg7zGKMqijrpU27qJPFl8LOXXjF6q2h/vbk=
=YL58
-----END PGP SIGNATURE-----

--=-iuIbU5optu/UKRUiPDol--


--===============8151974264177947617==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Jack-Devel mailing list
[email protected]
http://lists.jackaudio.org/listinfo.cgi/jack-devel-jackaudio.org

--===============8151974264177947617==--