public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] IR: let all protocol decoders have a go at raw data
@ 2010-05-28 19:59 Jarod Wilson
  2010-05-29 17:17 ` [PATCH v2] " Jarod Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: Jarod Wilson @ 2010-05-28 19:59 UTC (permalink / raw)
  To: linux-media

The mceusb driver I'm about to submit handles just about any raw IR you
can throw at it. The ir-core loads up all protocol decoders, starting
with NEC, then RC5, then RC6. RUN_DECODER() was trying them in the same
order, and exiting if any of the decoders didn't like the data. The
default mceusb remote talks RC6(6A). Well, the RC6 decoder never gets a
chance to run unless you move the RC6 decoder to the front of the list.

What I believe to be correct is to have RUN_DECODER keep trying all of
the decoders, even when one triggers an error. I don't think the errors
matter so much as it matters that at least one was successful -- i.e.,
that _sumrc is > 0. The following works for me w/my mceusb driver and
the default decoder ordering -- NEC and RC5 still fail, but RC6 still
gets a crack at it, and successfully does its job.

Signed-off-by: Jarod Wilson <jarod@redhat.com>

---
 drivers/media/IR/ir-raw-event.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index ea68a3f..44162db 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -36,14 +36,15 @@ static DEFINE_SPINLOCK(ir_raw_handler_lock);
  */
 #define RUN_DECODER(ops, ...) ({					    \
 	struct ir_raw_handler		*_ir_raw_handler;		    \
-	int _sumrc = 0, _rc;						    \
+	int _sumrc = 0, _rc, _fail;					    \
 	spin_lock(&ir_raw_handler_lock);				    \
 	list_for_each_entry(_ir_raw_handler, &ir_raw_handler_list, list) {  \
 		if (_ir_raw_handler->ops) {				    \
 			_rc = _ir_raw_handler->ops(__VA_ARGS__);	    \
 			if (_rc < 0)					    \
-				break;					    \
-			_sumrc += _rc;					    \
+				_fail++;				    \
+			else						    \
+				_sumrc += _rc;				    \
 		}							    \
 	}								    \
 	spin_unlock(&ir_raw_handler_lock);				    \

-- 
Jarod Wilson
jarod@redhat.com


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v2] IR: let all protocol decoders have a go at raw data
  2010-05-28 19:59 [PATCH] IR: let all protocol decoders have a go at raw data Jarod Wilson
@ 2010-05-29 17:17 ` Jarod Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Jarod Wilson @ 2010-05-29 17:17 UTC (permalink / raw)
  To: linux-media

On Fri, May 28, 2010 at 3:59 PM, Jarod Wilson <jarod@redhat.com> wrote:
> The mceusb driver I'm about to submit handles just about any raw IR you
> can throw at it. The ir-core loads up all protocol decoders, starting
> with NEC, then RC5, then RC6. RUN_DECODER() was trying them in the same
> order, and exiting if any of the decoders didn't like the data. The
> default mceusb remote talks RC6(6A). Well, the RC6 decoder never gets a
> chance to run unless you move the RC6 decoder to the front of the list.
>
> What I believe to be correct is to have RUN_DECODER keep trying all of
> the decoders, even when one triggers an error. I don't think the errors
> matter so much as it matters that at least one was successful -- i.e.,
> that _sumrc is > 0. The following works for me w/my mceusb driver and
> the default decoder ordering -- NEC and RC5 still fail, but RC6 still
> gets a crack at it, and successfully does its job.
>
> Signed-off-by: Jarod Wilson <jarod@redhat.com>
>
> ---
>  drivers/media/IR/ir-raw-event.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
> index ea68a3f..44162db 100644
> --- a/drivers/media/IR/ir-raw-event.c
> +++ b/drivers/media/IR/ir-raw-event.c
> @@ -36,14 +36,15 @@ static DEFINE_SPINLOCK(ir_raw_handler_lock);
>  */
>  #define RUN_DECODER(ops, ...) ({                                           \
>        struct ir_raw_handler           *_ir_raw_handler;                   \
> -       int _sumrc = 0, _rc;                                                \
> +       int _sumrc = 0, _rc, _fail;                                         \
>        spin_lock(&ir_raw_handler_lock);                                    \
>        list_for_each_entry(_ir_raw_handler, &ir_raw_handler_list, list) {  \
>                if (_ir_raw_handler->ops) {                                 \
>                        _rc = _ir_raw_handler->ops(__VA_ARGS__);            \
>                        if (_rc < 0)                                        \
> -                               break;                                      \
> -                       _sumrc += _rc;                                      \
> +                               _fail++;                                    \
> +                       else                                                \
> +                               _sumrc += _rc;                              \


Self-NAK. The only place we actually *care* about the retval from a
RUN_DECODER() call is in __ir_input_register(), and currently, its
looking for retval < 0, which is currently never possible. When we're
running the decoders, either they fail and return -EINVAL or they
succeed and return 0, and in the register case, we get either a
negative error (ex: -ENOMEM from rc6) or 0, so with the above, _sumrc
will *always* be 0 in the two cases I'm looking at. The third place
where RUN_DECODER gets called (decoder unregister) doesn't care about
the retval either. New patch below, including updated comments about
the macro.

Signed-off-by: Jarod Wilson <jarod@redhat.com>
---
 drivers/media/IR/ir-raw-event.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index ea68a3f..b832717 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -31,8 +31,9 @@ static DEFINE_SPINLOCK(ir_raw_handler_lock);
  *
  * Calls ir_raw_handler::ops for all registered IR handlers. It prevents
  * new decode addition/removal while running, by locking ir_raw_handler_lock
- * mutex. If an error occurs, it stops the ops. Otherwise, it returns a sum
- * of the return codes.
+ * mutex. If an error occurs, we keep going, as in the decode case, each
+ * decoder must have a crack at decoding the data. We return a sum of the
+ * return codes, which will be either 0 or negative for current callers.
  */
 #define RUN_DECODER(ops, ...) ({					    \
 	struct ir_raw_handler		*_ir_raw_handler;		    \
@@ -41,8 +42,6 @@ static DEFINE_SPINLOCK(ir_raw_handler_lock);
 	list_for_each_entry(_ir_raw_handler, &ir_raw_handler_list, list) {  \
 		if (_ir_raw_handler->ops) {				    \
 			_rc = _ir_raw_handler->ops(__VA_ARGS__);	    \
-			if (_rc < 0)					    \
-				break;					    \
 			_sumrc += _rc;					    \
 		}							    \
 	}								    \


-- 
Jarod Wilson
jarod@wilsonet.com

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-29 17:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-28 19:59 [PATCH] IR: let all protocol decoders have a go at raw data Jarod Wilson
2010-05-29 17:17 ` [PATCH v2] " Jarod Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox