[dvblast-devel] [PATCH 5/5] dvb/si: Add support for descriptor 0x4e (Extended event descriptor).

Georgi Chorbadzhiyski gf at unixsol.org
Mon Sep 19 19:57:28 CEST 2011


---
 dvb/si.h       |  182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dvb/si_print.h |    1 +
 2 files changed, 183 insertions(+), 0 deletions(-)

diff --git a/dvb/si.h b/dvb/si.h
index 619f64d..1a84259 100644
--- a/dvb/si.h
+++ b/dvb/si.h
@@ -977,6 +977,188 @@ static inline void desc4d_print(const uint8_t *p_desc,
 }
 
 /*****************************************************************************
+ * Descriptor 0x4e: Extended event descriptor
+ *****************************************************************************/
+#define DESC4E_HEADER_SIZE      (DESC_HEADER_SIZE + 4)
+
+static inline void desc4e_init(uint8_t *p_desc)
+{
+    desc_set_tag(p_desc, 0x4e);
+}
+
+static inline uint8_t desc4e_get_desc_number(uint8_t *p_desc)
+{
+    return p_desc[2] >> 4;
+}
+
+static inline void desc4e_set_desc_number(uint8_t *p_desc, uint8_t i_desc_number)
+{
+    p_desc[2] |= i_desc_number << 4;
+}
+
+static inline uint8_t desc4e_get_last_desc_number(uint8_t *p_desc)
+{
+    return p_desc[2] & 0x0f;
+}
+
+static inline void desc4e_set_last_desc_number(uint8_t *p_desc, uint8_t i_last_desc_number)
+{
+    p_desc[2] |= i_last_desc_number & 0xf0;
+}
+
+static inline const uint8_t *desc4e_get_code(const uint8_t *p_desc)
+{
+    return p_desc + 3;
+}
+
+static inline void desc4e_set_code(uint8_t *p_desc_n, const uint8_t p_code[3])
+{
+    p_desc_n[3] = p_code[0];
+    p_desc_n[4] = p_code[1];
+    p_desc_n[5] = p_code[2];
+}
+
+static inline const uint8_t *desc4e_get_item(const uint8_t *p_desc, uint8_t n)
+{
+    const uint8_t *p = p_desc + DESC4E_HEADER_SIZE;
+    const uint8_t *p_item, *p_items, *p_items_end;
+
+    uint8_t i_items_len = *p;
+    if (!i_items_len)
+        return NULL;
+
+    p_items = p_item = p + 1;
+    p_items_end = p_items + i_items_len;
+
+    if (n == 0)
+        return p_item;
+
+    while ( p_item < p_items_end ) {
+        p_item += 1 + p_item[0]; /* Calc item description */
+        p_item += 1 + p_item[0]; /* Calc item text */
+        if (--n == 0 && p_item < p_items_end )
+            return p_item;
+    }
+
+    return NULL;
+}
+
+static inline const uint8_t *desc4en_get_item_description(const uint8_t *p_desc_n, uint8_t *i_length)
+{
+    *i_length = p_desc_n[0];
+    return p_desc_n + 1;
+}
+
+static inline const uint8_t *desc4en_get_item_text(const uint8_t *p_desc_n, uint8_t *i_length)
+{
+    const uint8_t *p_ret = p_desc_n + 1 + p_desc_n[0];
+    *i_length = p_ret[0];
+    return p_ret + 1;
+}
+
+static inline uint8_t *desc4e_get_text(uint8_t *p_desc, uint8_t *i_length)
+{
+    uint8_t *p = p_desc + DESC4E_HEADER_SIZE;
+    p += 1 + p[0];
+    *i_length = p[0];
+    return p + 1;
+}
+
+static inline bool desc4e_validate(const uint8_t *p_desc)
+{
+    uint8_t i_length = desc_get_length(p_desc);
+    int i_items_len;
+    const uint8_t *p = p_desc + DESC4E_HEADER_SIZE;
+    const uint8_t *p_items, *p_items_end, *p_item;
+
+    if (DESC4E_HEADER_SIZE + 2 > i_length + DESC_HEADER_SIZE)
+        return false;
+
+    i_items_len = *p;
+    p_items = p_item = p + 1;
+    p_items_end = p_items + i_items_len;
+
+    p += 1 + p[0]; /* Check item loop */
+    if (p + 1 - p_desc > i_length + DESC_HEADER_SIZE)
+        return false;
+
+    p += 1 + p[0]; /* Check text */
+    if (p - p_desc > i_length + DESC_HEADER_SIZE)
+        return false;
+
+    while ( p_item < p_items_end ) {
+        p_item += 1 + p_item[0]; /* Check item description */
+        if ( p_item > p_items_end )
+            return false;
+        p_item += 1 + p_item[0]; /* Check item text */
+        if ( p_item > p_items_end )
+            return false;
+    }
+
+    return true;
+}
+
+static inline void desc4e_print(uint8_t *p_desc,
+                                f_print pf_print, void *print_opaque,
+                                f_iconv pf_iconv, void *iconv_opaque,
+                                print_type_t i_print_type)
+{
+    uint8_t i_text_length;
+    uint8_t *p_text = desc4e_get_text(p_desc, &i_text_length);
+
+    char *psz_text = dvb_string_get(p_text, i_text_length,
+                                    pf_iconv, iconv_opaque);
+
+    switch (i_print_type) {
+    case PRINT_XML:
+        psz_text = dvb_string_xml_escape(psz_text);
+        pf_print(print_opaque, "<EXTENDED_EVENT_DESC desc_number=\"%u\" last_desc_number=\"%u\" lang=\"%3.3s\" text=\"%s\">",
+                 desc4e_get_desc_number(p_desc),
+                 desc4e_get_last_desc_number(p_desc),
+                 (char *)desc4e_get_code(p_desc),
+                 psz_text
+                );
+        break;
+    default:
+        pf_print(print_opaque,"    - desc 4e extended_event desc_number=%u last_desc_number=%u lang=%3.3s text=\"%s\"",
+                 desc4e_get_desc_number(p_desc),
+                 desc4e_get_last_desc_number(p_desc),
+                 (char *)desc4e_get_code(p_desc),
+                 psz_text
+                );
+    }
+    free( psz_text );
+
+    uint8_t j = 0;
+    const uint8_t *p_desc_n;
+    while ((p_desc_n = desc4e_get_item(p_desc, j++)) != NULL) {
+        uint8_t i_desc_length, i_item_length;
+        const uint8_t *p_desc = desc4en_get_item_description(p_desc_n, &i_desc_length);
+        const uint8_t *p_item = desc4en_get_item_text(p_desc_n, &i_item_length);
+        char *psz_desc = dvb_string_get(p_desc, i_desc_length, pf_iconv, iconv_opaque);
+        char *psz_item = dvb_string_get(p_item, i_item_length, pf_iconv, iconv_opaque);
+
+        switch (i_print_type) {
+        case PRINT_XML:
+            psz_desc = dvb_string_xml_escape(psz_desc);
+            psz_item = dvb_string_xml_escape(psz_item);
+            pf_print(print_opaque, "<EXTENDED_EVENT_ITEM description=\"%s\" text=\"%s\"/>",
+                     psz_desc, psz_item);
+            break;
+        default:
+            pf_print(print_opaque,"       - extended_event_item description=\"%s\" text=\"%s\"",
+                     psz_desc, psz_item);
+        }
+
+        free(psz_desc);
+        free(psz_item);
+    }
+
+    if (i_print_type == PRINT_XML)
+        pf_print(print_opaque, "</EXTENED_EVENT_DESC>");
+}
+
+/*****************************************************************************
  * Descriptor 0x52: Stream identifier descriptor
  *****************************************************************************/
 #define DESC52_HEADER_SIZE      (DESC_HEADER_SIZE + 1)
diff --git a/dvb/si_print.h b/dvb/si_print.h
index 9dd3dd0..9476ce0 100644
--- a/dvb/si_print.h
+++ b/dvb/si_print.h
@@ -113,6 +113,7 @@ static inline void descs_print(uint8_t *p_descs,
         CASE_DESC_ICONV(48)
         CASE_DESC(4a)
         CASE_DESC_ICONV(4d)
+        CASE_DESC_ICONV(4e)
         CASE_DESC(52)
         CASE_DESC(54)
         CASE_DESC(55)
-- 
1.7.5.1



More information about the dvblast-devel mailing list