[cecd-devel] [PATCH 2/2] [libcec] fix logical address allocation
Status: Beta
Brought to you by:
pbatard
|
From: Florian F. <f.f...@gm...> - 2012-01-05 17:14:05
|
The current logical address allocation will iterate over all possible
logical addresses no matter what device type we configured. According
to the specification this is wrong, for instance, if we are a recording
device, we should:
- take the unregistered address
- poll the <N>th logical address corresponding to a recording device
* if available, take it
* if not available continue to the next logical address
- until we either have a valid address or remain unregistered
---
libcec/libcec.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/libcec/libcec.c b/libcec/libcec.c
index 9bcf5c8..18330a9 100644
--- a/libcec/libcec.c
+++ b/libcec/libcec.c
@@ -26,6 +26,7 @@
#include <sys/types.h>
#include "libceci.h"
+#include "decoder.h"
#if defined(LINUX_REALTEK_SOC)
const _ceci_backend* const ceci_backend = &linux_realtek_soc_backend;
@@ -195,12 +196,54 @@ int libcec_set_logical_address(libcec_device_handle* handle, uint8_t logical_add
return ceci_backend->set_logical_address(handle, logical_address);
}
+static uint8_t libcec_get_first_logical_address(uint8_t device_type)
+{
+ switch (device_type & 0x0f) {
+ default:
+ case CEC_DEVTYPE_TV:
+ return 0;
+ case CEC_DEVTYPE_RECORDING:
+ return 1;
+ case CEC_DEVTYPE_TUNER:
+ return 3;
+ case CEC_DEVTYPE_PLAYBACK:
+ return 4;
+ case CEC_DEVTYPE_AUDIO:
+ return 5;
+ }
+}
+
+static uint8_t libcec_get_next_logical_address(uint8_t addr)
+{
+ switch (addr & 0x0f) {
+ default:
+ return 14;
+ case 1:
+ return 2;
+ case 2:
+ return 9;
+ case 3:
+ return 6;
+ case 4:
+ return 8;
+ case 6:
+ return 7;
+ case 7:
+ return 10;
+ case 8:
+ return 11;
+ case 14:
+ case 15:
+ return 15;
+ }
+}
+
DEFAULT_VISIBILITY
int libcec_allocate_logical_address(libcec_device_handle* handle, uint8_t device_type, uint16_t* physical_address)
{
const uint8_t logical_address_table[15] = {0, 1, 1, 3, 4, 5, 3, 3, 4, 1, 3, 4, 2, 2, 0};
int r;
- uint8_t logical_address, polling_message;
+ uint8_t logical_address, polling_message, first_logical_address;
if (handle == NULL) {
return LIBCEC_ERROR_INVALID_PARAM;
@@ -239,7 +282,11 @@ int libcec_allocate_logical_address(libcec_device_handle* handle, uint8_t device
return libcec_set_logical_address(handle, 0);
}
- for (logical_address = 1; logical_address < 15; logical_address++) {
+ first_logical_address = libcec_get_first_logical_address(device_type);
+
+ for (logical_address = first_logical_address;
+ logical_address < 15;
+ logical_address = libcec_get_next_logical_address(logical_address)) {
if (logical_address_table[logical_address] != device_type) {
continue;
}
--
1.7.5.4
|