[dvblast-devel] [PATCH 4/5] dvb/si: Add support for descriptor 0x55 (Parential rating descriptor).

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


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

diff --git a/dvb/si.h b/dvb/si.h
index 6f8a530..619f64d 100644
--- a/dvb/si.h
+++ b/dvb/si.h
@@ -1110,6 +1110,77 @@ static inline void desc54_print(uint8_t *p_desc, f_print pf_print,
 }
 
 /*****************************************************************************
+ * Descriptor 0x55: Parential rating descriptor
+ *****************************************************************************/
+#define DESC55_HEADER_SIZE      DESC_HEADER_SIZE
+#define DESC55_RATING_SIZE      4
+
+static inline void desc55_init(uint8_t *p_desc)
+{
+    desc_set_tag(p_desc, 0x55);
+}
+
+#define desc55n_get_country_code desc0an_get_code
+#define desc55n_set_country_code desc0an_set_code
+
+static inline uint8_t *desc55_get_rating(uint8_t *p_desc, uint8_t n)
+{
+    uint8_t *p_desc_n = p_desc + DESC55_HEADER_SIZE + n * DESC55_RATING_SIZE;
+    if (p_desc_n + DESC55_RATING_SIZE - p_desc
+         > desc_get_length(p_desc) + DESC55_HEADER_SIZE)
+        return NULL;
+    return p_desc_n;
+}
+
+static inline uint8_t desc55n_get_rating(uint8_t *p_desc_n)
+{
+    return p_desc_n[3];
+}
+
+static inline void desc55n_set_rating(uint8_t *p_desc_n, uint8_t i_rating)
+{
+    p_desc_n[3] = i_rating;
+}
+
+static inline bool desc55_validate(const uint8_t *p_desc)
+{
+    return !(desc_get_length(p_desc) % DESC55_RATING_SIZE);
+}
+
+static inline void desc55_print(uint8_t *p_desc, f_print pf_print,
+                                void *opaque, print_type_t i_print_type)
+{
+    uint8_t j = 0;
+    uint8_t *p_desc_n;
+
+    while ((p_desc_n = desc55_get_rating(p_desc, j++)) != NULL) {
+        char rating_txt[16];
+        uint8_t rating = desc55n_get_rating(p_desc_n);
+        if (rating == 0)
+            sprintf(rating_txt, "%s", "undefined");
+        else if (rating >= 0x01 || rating <= 0x0f)
+            sprintf(rating_txt, "min %d years", rating + 3);
+        else
+            sprintf(rating_txt, "%s", "unknown");
+        switch (i_print_type) {
+        case PRINT_XML:
+            pf_print(opaque, "<PARENTIAL_RATING_DESC country_code=\"%3.3s\" rating=\"%u\" rating_txt=\"%s\"/>",
+                     (char *)desc55n_get_country_code(p_desc_n),
+                     desc55n_get_rating(p_desc_n),
+                     rating_txt
+                    );
+            break;
+        default:
+            pf_print(opaque,"    - desc 55 parential_rating country_code=%3.3s rating=%u rating_txt=\"%s\"",
+                     (char *)desc55n_get_country_code(p_desc_n),
+                     desc55n_get_rating(p_desc_n),
+                     rating_txt
+                    );
+        }
+    }
+}
+
+/*****************************************************************************
  * Descriptor 0x56: Teletext descriptor
  *****************************************************************************/
 #define DESC56_HEADER_SIZE      DESC46_HEADER_SIZE
diff --git a/dvb/si_print.h b/dvb/si_print.h
index e45a3a6..9dd3dd0 100644
--- a/dvb/si_print.h
+++ b/dvb/si_print.h
@@ -115,6 +115,7 @@ static inline void descs_print(uint8_t *p_descs,
         CASE_DESC_ICONV(4d)
         CASE_DESC(52)
         CASE_DESC(54)
+        CASE_DESC(55)
         CASE_DESC(56)
         CASE_DESC(59)
         CASE_DESC(5a)
-- 
1.7.5.1



More information about the dvblast-devel mailing list