Posts by JeffR

    SOLVED!!!!

    I found an example of an exclusive IO grab in python in PythonUSBBarcodeScanner.py written by Richard Aplin https://gist.github.com/raplin

    The key lines of code are:

    definitions of IOW and IOC functions up front

    EVIOCGRAB = lambda len: IOW(ord('E'), 0x90, ctypes.c_int)

    fcntl.ioctl(fd, EVIOCGRAB(1), True) #add this line to right after the event file is opened

    As noted earlier, I created a service to launch the python program before Kodi.

    I now log all touch X Y data to a text file that can be read by my Kodi addon.

    Kodi never sees the touch events, so the "Now Playing" popup doesn't pop up.

    Update:

    After some iteration, I have a working service based on the service.touchscreen.service example, as vpeter suggested.

    (Yeah, I had little errors all over the place when I made the previous post. Sorry about that)

    The service launches my updated touch.py reader program, which reads from the touch panel and logs the results to a file.

    If I touch the screen during bootup, the log shows about 6 seconds of touchpanel reads, and then stops.

    While kodi is running, it does not log any touchscreen events.

    If I systemctl stop kodi, the log starts reporting touches again.

    The touch.py program opens the event file, but does not close it.

    I had hoped that by opening the event file first, it would prevent Kodi from doing an exclusive grab, but no luck.

    I also tried adding this command after opening the event file, with no change in behavior.

    fcntl.flock(fd, fcntl.LOCK_EX)

    vpeter:

    I tried to follow your 2019 suggestion

    JeffR, you just need to run python script before kodi is started. Make a service like I did for touchscreen addon: LibreELEC.tv/service.touchscreen.service at master · LibreELEC/LibreELEC.tv · GitHub

    Based on your service.touchscreen.service example, I created mytouch.service in /storage/.config/system.d
    I replaced your commands with: ExecStart=-/bin/sh -c "exec /bin/sh /storage/mytouch.sh service"

    And my mstouch.sh was:

    $!/usr/bin/sh

    echo "Starting touch.py from mytouch.sh"

    python /storage/3touch.py >>3touch.out 2>&1 &

    3touch.py tries to open the USB device, read events, and print out the event, which should be captured to 3touch.out

    I enabled the service and systemctl is-active mytouch.service shows that it is running after rebooting.

    But neither mytouch.sh or 3touch.py shows up with a ps listing.

    Oh, and I disabled your Touchscreen addon and service, to make it cleaner..

    I also tried HiassofT's suggestion of creating a udev rule using LIBINPUT_IGNORE_DEVICE, but again, I am not familiar with this at all, and again failed.

    My current thought is to explore /dev/usb/hiddev0. I can detect events, but they don't decode like event0 events, so I'm a little stuped right now.

    Like 3 years ago, I'm pretty stumped.

    vpeter:

    Thanks for the response. Funny enough, you pointed me to my original post on this topic 3 years ago.

    At the time, I was unable to figure out how to do some of the things suggested.

    But, I just re-read the thread, and I'm going to try some of the suggestions again. Maybe my programming skills are better now.

    I want to create an addon that uses simple touchscreen events (x y location of a touch) to control video interactions, such as sending seeks to different locations in a video.

    And, I want Kodi to ignore the touchscreen events

    evtest identifies my touchscreen as using event 1.

    But Libreelec/Kodi seems to have grabbed exclusive access to /dev/input/event1, and evtest can't read the events. A simple python event reader program can't read any events.

    I installed the Touchscreen addon, which gives Kodi access to the touchscreen, but evtest says that the events are still not available.

    I've looked through the Touchscreen addon, but I can't quite figure out what is going on, let alone figure out how to modify it to do what I want.

    Any suggestions?

    Thanks,

    -Jeff

    I created a Kodi addon that plays a single video file in a playlist, and then seeks to different positions in the video based on GPIO input.

    The player works fine, with a clean transition to the seek locations, and stable operation for hours.

    But, after roughly 980 seeks, Kodi starts throwing error messages,and the video starts to distort with stuttered playing and color distortions.

    At about 1100 seeks, the processor reboots.

    This occurs whether the seeks are driven by the GPIO input, or a for loop that seeks back to 0 after a few seconds.

    The error message that appears after seek ~980 is:

    ERROR <general>: CDVDVideoCodecDRMPRIME::AddData - send packet failed: Operation not permitted (-1)

    I am using

    Pine64 Rock64 (Rockchip RK3328)processor, 4 GB

    Libreelec 10.0.2 with Kodi 19.4.

    Memory usage is ~500MB out of 4 GBR

    CPU loading is 25% on all 4 cores, per htop.

    Seek commands sent 1 or 2 times per minute

    4k h264 video (3840 x 2160, 29.97 fps) with 48000 Hz aac audio

    also tested with same video recoded by ffmpeg to 1080p

    also tested with the 4k video with audio re-encoded to mp3

    The attached python plugin recreates the problem, but with a seek cycle of 0.2 seconds.

    This lets me recreate the error in about 6 minutes instead of 15 hours.

    The test program includes a Kodi popup message to display the seek count.

    Note that this fast loop version throws additional errors I did not see in my 15 hour test.

    It is possible that they are caused by the short play duration

    ERROR <general>: CDVDVideoCodecDRMPRIME::Drain - send packet failed: Operation not permitted (-1)

    ERROR <general>: CDVDVideoCodecDRMPRIME::Reset - receive frame failed: Operation not permitted (-1)

    Note: the logfile include a lot of warnings, which seem to be about losing audio sync. But I ignore these since I don't use the audio.

    The problem does not occur with an h265 encoded video.

    And, just for "fun", I put Libreelec on two Raspberry Pi's to test it.

    The problem does not occur with the h264 video on a Raspberry Pi 4 with Libreelec 10.0.2

    The problem does not occur with the h264 video on a Raspberry Pi Zero with Libreelec 9.2.6

    Has anyone else seen this issue? Is there a workaround, other than converting everything to h265?

    I'm attaching my plugin files (addon.xml and loop.py, with .txt added to the names) and the crash log.

    vpeter:

    I currently have a Kodi python addon that uses GPIO input to select which video to play. To make for seamless transitions, I concatenate 4 videos into a single .mp4, and use the GPIO to select what section of the video to seek to, play it, and return to the beginning.

    I want to change this to be a touchpanel control.

    My main video section will display 4 or more square zones on the screen. When I read a touch event, I will determine which zone is selected and then seek to that part of the video, play it, and return to the main video section.

    Python seemed to be the easiest way to implement the kodi addon.

    Does your touch daemon/addon really run while Kodi is running?
    Like I said, I understand how one could create a daemon that autoruns before Kodi starts to exclusively grab the touchpanel.

    Or do you kill Kodi and relaunch it, as I think I saw in your code?

    Hias:

    The documentation for LIBINPUT_IGNORE_DEVICE indicates that the device will not be set up by libinput. I can see why that would prevent Kodi from grabbing it. But won't that also prevent an open and read in python?


    Thanks,

    -Jeff

    Changing the amount of audio channels at the LE audio settings doesn't help?

    Da Flex:

    I am currently letting Kodi autoselect the audio settings (System - Settings- Audio shows ALSA:HDMI, HDMI) with 2.0 channels.

    This seems to match the TVs I am using.

    I'll try using different audio settings and see if that improves things. I'm not sure why this would only be a problem on 3 of my 10 players. You would think that if there was a problem, it would manifest on all the players.

    Thanks for the suggestion.

    vpeter:
    Once again, some great suggestions.

    Thanks for the pointer to system tools.

    evtest does see the touchscreen and correctly identifies the touchscreen and properties.
    But, it also notes that "The device is grabbed by another process". Which confirms your earlier assumption that Kodi grabs control of all IO. I guess that makes sense from a performance point of view.

    Your code is a little difficult for me to digest all at once. I do see in the .sh script that you kill Kodi to launch the calibrate.py, and then restart Kodi.
    This seems to confirm that Kodi runs with exclusive access to device input.

    I'll have to research your suggestion to "create another input device in Python". I'm not sure how to do that, but I can look into it.

    Your suggestion to run a background program with autostart interesting. I assume I could try to exclusively grab the input before Kodi starts (I don't need Kodi to have access to the touchpanel inputs).
    I assume that the program would read the touchscreen events and send the data to my python addon (through a fifo pipe or file I/O?).
    Is that what you had in mind?

    Da Flex: interesting suggestion, but no, changing the "Enable mouse and touch screen support" setting has no effect.

    Yes, this is running while Kodi is running. My plan was to use this for a Kodi addon to switch videos based on the location of the touch.

    I tried to do an evtest test per vPeter's suggestion, but LibreELEC has blocked apt-get, so I can't install the package.

    If Kodi on LibreELEC has really completely blocked access to input devices, it sounds like I'm out of luck using LibreELEC.
    I'll try a clean install of Armbian and Kodi on my Rock64 and see how far I get.

    It's a shame, I really liked how smoothly Kodi was running on LibreELEC.

    vpeter:

    Great suggestion on testing select.select() with keyboard input. I wrote another test program (even simpler than before) to test this out, as well as testing with mouse and keyboard events.

    I tested this, but failed for both keyboard and mouse events, too.

    On Armbian, print (r) will correctly print out a data structure when I use the device, for touchpanel, keyboard, and mouse.

    On LibreELEC, I only get a stream of [ ] printed out.

    To reply to the other comments:

    Whoops! I snipped out too much in my original example code when I was posting it. I used the following:

    FORMAT = 'llHHI'
    EVENT_SIZE = struct.calcsize(FORMAT)
    But, the code never got to the read statement, due to the select.select() problem, so I didn't notice.

    Interesting note about USB reliability vs. GPIO. Unfortunately I have 22 of these type of cheap touchpanels, and I can't change at this point. (This is for interactive displays at a charity haunted house)

    Hi,

    I'm trying to create a Kodi addon that uses USB touchpanel input to make choices about what video to play.

    I have python code that reads the touchpanel events and extracts raw x and y values.

    To make it non-blocking, I use select.select() to first test to see if there is a touch event to read, and to set a timeout.

    Everything works fine when I test it on Armbian, but when I embed the code into my Kodi addon, I never see any touchpanel events.

    The program below represents my code.
    On Armbian, the print (r) statement returns a data structure that points to the USB device file, whenever there is a touch event to read.

    On LibreElec, the print [r] statement always returns []

    Is there something stripped out of LibreElec that is making select.select not work right?

    Note: from a python shell, "import select" succeeds, so I don't think it is a missing library.

    Are there any other LibreElec restrictions that would inhibit a direct read of an input device?

    Configuration:

    Rock64 4GB

    LibreELEC/Kodi (LibreELEC 9.1.002)

    Confluence skin

    Thanks,

    -Jeff


    Hi.

    I posted last week about an odd problem with 3 of 10 of my Rock64 LibreElec/Kodi video players freezing up.

    Random Kodi freezes on Rock64

    It was recommended that I post in this thread, too.

    Bottom line: on 3 of 10 video players, I occasionally get a video freeze in a random location. The only error I could trap was:

    ERROR: ffmpeg[E2E2C380]: [AVBSFContext] Channel mapping 2 is only specified for channel counts which can be written as (n + 1)^2 or (n + 1)^2 + 2 for nonnegative integer n

    Rock64 4GB

    LibreELEC/Kodi (LibreELEC 9.1.002), playing a simple addon to loop the video based on a timer.

    Confluence skin, SAMBA turned off

    4k video, playing on a 1080p monitor for debugging. The freeze happens both in 1080 and 4k.

    The video is playing from SanDisk Ultra microSDHC UHS-1 16GB cards

    The CPUs have heatsinks with cooling fans, and run at 43 deg C. CPU cores show <20% loading in general.

    Memory use is ~0.4GB (10%)

    I have 3 Amp power supplies from Pine64 and Ameridroid

    I've purchased replacement Rock64s, but I would love any suggestions on something I can do to eliminate around the freezeing.
    Should I set the CPU speed to a fixed speed?

    Is there a build that might be more stable?

    Thanks,

    -Jeff

    Hi. I hope this is the right forum to post this. I've read other posts about freezing, but most of these seem to be at startup.
    My problem comes intermittently after many minutes of playing perfectly, and only manifests itself on some of my Rock64 players.

    I have 10 of these players for a low cost 4k video player for my local charity Haunted House.
    7 of them run flawlessly for many hours.
    Of these, 2 of them froze once, but seem to have been fixed simply by cloning a "good" SD card and restarting.
    But, one of them keeps freezing, and replacing the SD card with a new copy does not fix it.

    The freezing time is somewhat random, from 20 minutes to 120 minutes.

    The video freezes on an image in a random location in the middle of the video file.

    Mouse movements to not make the menus pop up.

    I can still SSH and FTP to the device.

    I am running LibreELEC/Kodi on a 4 GB Rock64 and I occasionally get freezes on one of 10 Rock64s that I am running.

    LibreELEC 9.1.002

    Confluence skin

    It's a 4k video, playing on a 1080p monitor for debugging. The freeze happens both in 1080 and 4k.

    The CPUs have heatsinks with cooling fans, and run at 43 deg C. CPU cores show <20% loading in general. Memory use is ~0.4GB (10%)
    It plays one video file that is on the SD card, and I am using SanDisk Ultra microSDHC UHS-1 cards that claim to be good to 80 MB/s
    I have 3 Amp power supplies.

    My Kodi runs with a addon which seeks back to the beginning after ~180 seconds. It also seeks to different locations based on GPIO inputs.

    I have disabled SAMBA, but left the other default addons enabled.

    I've uploaded the log files from a good run to http://ix.io/1xek

    If you search for "hhloop", you will see a few "normal" sequences when the player seeks to 0.

    From a bad run, the log file showed one extra line after a normal loop sequence.

    ERROR: ffmpeg[E2E2C380]: [AVBSFContext] Channel mapping 2 is only specified for channel counts which can be written as (n + 1)^2 or (n + 1)^2 + 2 for nonnegative integer n

    Can anyone make any suggestions on what I can try next?

    Thanks