catalinii / minisatip

minisatip is an SATIP server for linux using local DVB-S2, DVB-C, DVB-T or ATSC cards
https://minisatip.org
324 stars 78 forks source link

Release adapter if there are no listening clients. #1144

Closed andrewjw closed 1 week ago

andrewjw commented 1 month ago

Hi,

I have Sundtek DVB-S/S2 USB device, which works reasonably well. It works most of the time, but is a bit unreliable and sometimes fails to tune correctly. I've been trying to debug where the problem is - it could be MythTV, minisatip, the drivers, device or my cables... Anyway, as part of my research I came across this forum post which contains a patch to get minisatip to correctly release a tuner when no-one is listening, and I can't see it having been submitted. I think this might also relate to #586.

I'm aware that in the forum post there is a comment that this might be better done with a timer, but at least initially I wanted to submit the patch as-is, for completion and for attribution to the original poster, Rainer.

This patch seems to work well for me, and the devices do go offline when not in use, which previously they didn't. It also seems to improve the instability I see a bit, but doesn't fix it completely though. I suspect that's a Sundtek driver issue though.

Thanks, Andrew

catalinii commented 1 month ago

I think there is a feature to close the adapter after 30s by default, if that does not work, please upload the logs of

./minisatip -f -l http

lars18th commented 1 month ago

Hi @catalinii and @andrewjw ,

The current behaviour is that minisatip maintains any tuner "open" until the close delay (30'') is achieved. This resolves a lot of troubles in different scenarios and don't generate side effects. This works because the tuner is left open but without reading any pid. And if the tuner is to be used, then the correct commands are sent to it. So in principle everything works as expected.

However, I think some obscure bug is inside minisatip at the moment. The problem, perhaps the root of your problems, is that in some cases the tuner is in "open" state, there are no users connected, and a new connection requests a new tuning but minisatip doesn't select the "open" tuner. This problem has more effect on servers with a single tuner, because the new request cannot be completed. But it has less effect with multiple tuners. But in any case, in this situation I can see this problem as well. I'm not sure but maybe the problem is related to the internal stream management. And I add that usually the problem happens more frequently when the tuner can't find good signal. In that case it stays "semi-open" (in open state but not selected) until the 30 seconds.

That said, I reject to merge this patch because it only implements a hack: every time a tuner stops having clients, then a counter is incremented. Until a maximum is reached and then it's forced to close. This doesn't solve the problem. And the counter in this patch has a very high value (3000). Therefore, I don't recommend it (but you can compile your own version... of course you can! You're free to do so, and if it works for you, then go for it. But in that case I recommend using a value no larger than 10 for MAX_NOSID).

Finally, I do think there is a problem and it needs to be solved. But in a different way. Regards.

andrewjw commented 1 month ago

Hi,

Sorry for the delay in getting the requested logs, I plan to get those tonight.

I agree that the patch as it stands is a bit of a hack. I found it on the minisatip forums when trying to debug a problem I'm having, and I couldn't find a PR on GitHub about it. I wanted to share it as-is to start a discussion about it. The forum thread was about a Sundtek tuner (which I also use), but I don't know if it also affects other brands.

I am running the patch and it does what I wanted, which is reliably switch off the tuners when my MythTV box goes to sleep.

In the forum thread there is a comment about using a timer rather than a counter, but it's essentially the same strategy. It sounds like you suspect there is a deeper bug that needs fixing? I'm happy to help change the patch to use a timer, but fixing deeper bugs might be beyond my abilities.

Cheers, Andrew

lars18th commented 1 month ago

Hi @andrewjw ,

I suggest to wait until you provide the log to start the discussion. Because, if you change the delay of 30'' to 0 then it will be the same (more or less) that enforcing the close of the tuner by a timer. And I repeat: without this delayed close a lot of other troubles appear. So it's necessary.

Regards.

andrewjw commented 1 month ago

minisatip.log

Here are the logs as promised. I used VLC to view a channel for a few seconds, then disconnected. After three minutes the frontend was still saying 92% signal strength, although the frequency showed 0.

Cheers, Andrew

lars18th commented 1 month ago

I think this is not normal:

[15/05 20:25:53.500 AD0]: leak detected 1 0!!! 

@catalinii , any idea why this message appears?

catalinii commented 1 month ago

Can u upload a log with -v dmx and do the same test ?

Jalle19 commented 1 week ago

Closing this due to inactivity. It's probably better to open an issue about this instead of continuing with this PR (since it's unlikely to get merged).