Repository navigation
Conversation
…message by up to 50ms CSerialSocket::Read() on POSIX went through SocketRead(), which keeps calling select() and read() until len bytes are in or the timeout passes. The Pulse-Eight communication thread reads 5 bytes with a 50ms timeout, and most adapter messages are 4 bytes, so each one - the end of every received frame included - sat in the buffer until the next byte came in or the 50ms ran out. Read() now waits until the port is readable and returns what read() gives. ReadFromDevice() already hands whatever it gets to the message parser, and ClearInputBytes() reads until the input is quiet, so neither needs a full buffer. SocketRead() is unchanged: the cdev based adapters (TDA995x, IMX) read whole structs through it.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On POSIX,
CSerialSocket::Read()goes throughSocketRead(), which keeps callingselect()andread()untillenbytes are in or the timeout passes.CUSBCECAdapterCommunication::Process()reads the Pulse-Eight adapter withReadFromDevice(50, 5): 5 bytes, 50 ms timeout. Most adapter messages are 4 bytes (MSGSTART, code, value,MSGEND), so each one sits in the buffer until the next byte arrives or the 50 ms run out. The message carrying the EOM flag is the last of every received frame, so every frame reaches the client late, by up to 50 ms. With a TV remote that is added to every key press.Measurement
Pulse-Eight USB-CEC adapter (2548:1002) on
/dev/ttyACM0, LG TV, Debian testing, libCEC 8.1.7 (8.1.7+dfsg-1),cec-client -t r -d 15. Method:strace -f -ttt -e trace=read,writeoncec-client; for each received frame, the time from theread()that completes the adapter message with the EOM flag to thewrite()of that frame'sTRAFFICline.User Control Pressed), beforeMost frames are the TV's once-a-second polls. Before the change the polls show the delay drifting between 0 and 50 ms, since the 50 ms read window is not aligned with the bus.
Idle CPU of
cec-clientis unchanged: 96 clock ticks per 60 s before and 95 after (about 1.6% of one core). When idle the thread still blocks inselect()for up to 50 ms, then sleeps 5 ms, as before.Change
CSerialSocket::Read()on POSIX now waits until the port is readable (same timeout semantics: 0 waits forever) and returns what a singleread()gives. Its callers already handle partial data:ReadFromDevice()hands whatever it gets toCCECAdapterMessageQueue::AddData(), which parses a byte stream;ClearInputBytes()reads until the input is quiet and the last byte wasMSGEND.SocketRead()itself is unchanged:CCDevSocketuses it too, and the TDA995x and IMX backends read whole structs through it. Only the Pulse-Eight backend usesCSerialPort.Windows is not changed.
CSerialSocket::SetTimeouts()sets onlyReadTotalTimeoutConstant, soReadFile()probably waits for the full buffer in the same way, but I can't test it there.Testing
src/is the same atlibcec-8.1.7andmaster; the patch applies to both.8.1.7+dfsg-1with this patch: the exported dynamic symbols oflibcec.so.8match the Debian build (1327 symbols).cec-clientstays on the bus with no reconnects, and Kodi 22 linked against the rebuiltlibcec.so.8starts and exits normally.