Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_on() sometimes freezes cec #49

Open
mjm987 opened this issue Dec 16, 2020 · 2 comments
Open

is_on() sometimes freezes cec #49

mjm987 opened this issue Dec 16, 2020 · 2 comments

Comments

@mjm987
Copy link

mjm987 commented Dec 16, 2020

When using is_on() on a Raspberry Pi, the cec driver sometimes freezes completely so a reboot of the Raspi is needed to recover cec functionality.
Possibly this crash is caused when my TV does not respond to the request.
May be it is a problem in libcec or the raspi kernel driver (?) but I had a quick look in this projects device.cpp file on function Device_is_on(Device * self) and saw that a reference counting is done on a local variable. Isn't this wrong?

I suggest following correction:

--- device.cpp	2020-12-16 17:50:54.178413383 +0100
+++ b.cpp	2020-12-16 17:52:34.042359608 +0100
@@ -85,23 +85,20 @@
    Py_BEGIN_ALLOW_THREADS
    power = adapter->GetDevicePowerStatus(self->addr);
    Py_END_ALLOW_THREADS
-   PyObject * ret;
    switch(power) {
       case CEC_POWER_STATUS_ON:
       case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
-         ret = Py_True;
+         Py_RETURN_TRUE;
          break;
       case CEC_POWER_STATUS_STANDBY:
       case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
-         ret = Py_False;
+         Py_RETURN_FALSE;
          break;
       case CEC_POWER_STATUS_UNKNOWN:
       default:
          PyErr_SetString(PyExc_IOError, "Power status not found");
          return NULL;
    }
-   Py_INCREF(ret);
-   return ret;
 }

@nforro
Copy link
Collaborator

nforro commented Dec 16, 2020

May be it is a problem in libcec or the raspi kernel driver (?) but I had a quick look in this projects device.cpp file on function Device_is_on(Device * self) and saw that a reference counting is done on a local variable. Isn't this wrong?

No, it's not wrong. Py_INCREF() is called on either Py_True or Py_False, which is the same thing Py_RETURN_* macros do.

@mjm987
Copy link
Author

mjm987 commented Dec 16, 2020

ok, thanks for the explanation.
Because is_on() does not work reliable on my TV, I added a cec handler in which I check all events recevied for a power standby event.
Is there a better solution? Eg. is it possible to set a event filter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants