willprice / python-omxplayer-wrapper

:tv: Control OMXPlayer, the Raspberry Pi media player, from Python
http://python-omxplayer-wrapper.readthedocs.io
GNU Lesser General Public License v3.0
253 stars 72 forks source link

Quit function on files with ALSA option locks up OMXPlayer #206

Open DazB opened 3 years ago

DazB commented 3 years ago

Issue Report

Description

When you quit an OMX process, the wrapper sends a SIGTERM signal: https://github.com/willprice/python-omxplayer-wrapper/blob/a9875e30ba0195df772259b909aaa9e80f2cab1a/omxplayer/player.py#L213-L219

When starting OMX processes with -o alsa parameter, after quitting a few videos, OMXPlayer freezes, and no other OMXPlayer process can start (even manually from the command line). Any OMXPlayer process currently running cannot be killed (even manually from htop). The only way to fix this by rebooting.

I found this issue when attempting to implement a video switching feature.

Problem reproduction

Fix

I believe the issue is due to the fact a SIGTERM sent to OMXPlayer does not call the internal OMXPlayer cleanup functions. When called with ALSA, this leaves some ALSA I/O things open (honestly don't know the details, this is an educated guess), and eventually causes OMXPlayer to completely lock up.

Instead, call _terminal_process with SIGINT. This will call the internal cleanup functions, and allow the ALSA I/O to cleanup. When using SIGINT, I could no longer replicate the issue. Here is a link to a fork of my fix (the fork also includes other custom functions I added for my application): https://github.com/DazB/python-omxplayer-wrapper/blob/de0ca5eed87ca9094efa81d5b2099d5e9779be86/omxplayer/player.py#L215-L221

BTW thanks for the great library. It's been really useful 👍

Environment details

Software Version
python-omxplayer-wrapper 0.1.0
python (python --version) 3.7.3
omxplayer (omxplayer --version) 2cfe612 (this is a custom build of OMXPlayer with slight modifications)