[dvblast-devel] [PATCH 07/17] mpeg/psi: Add support for descriptor 0x02 (Video stream).

Georgi Chorbadzhiyski gf at unixsol.org
Fri Sep 9 23:28:29 CEST 2011


---
 dvb/si_print.h |    1 +
 mpeg/psi.h     |  120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)

diff --git a/dvb/si_print.h b/dvb/si_print.h
index fab2608..9989f54 100644
--- a/dvb/si_print.h
+++ b/dvb/si_print.h
@@ -91,6 +91,7 @@ static inline void descs_print(uint8_t *p_descs,
                                  i_print_type);                             \
             break;
 
+        CASE_DESC(02)
         CASE_DESC(05)
         CASE_DESC(09)
         CASE_DESC(0a)
diff --git a/mpeg/psi.h b/mpeg/psi.h
index 4e18a2c..410d98a 100644
--- a/mpeg/psi.h
+++ b/mpeg/psi.h
@@ -114,6 +114,126 @@ static inline void desc_print(const uint8_t *p_desc, f_print pf_print,
 }
 
 /*****************************************************************************
+ * Descriptor 0x02: Video stream descriptor
+ *****************************************************************************/
+#define DESC02_HEADER_SIZE      (DESC_HEADER_SIZE + 1)
+
+static inline bool desc02_is_mpeg1_only_flag(const uint8_t *p_desc) {
+    return (p_desc[2] & 0x04) == 0x04;
+}
+
+static inline bool desc02_validate(const uint8_t *p_desc)
+{
+    if (desc02_is_mpeg1_only_flag(p_desc)) {
+        return desc_get_length(p_desc) >= DESC02_HEADER_SIZE - DESC_HEADER_SIZE;
+    } else {
+        return desc_get_length(p_desc) >= (DESC02_HEADER_SIZE + 2) - DESC_HEADER_SIZE;
+    }
+}
+
+static inline const char *desc02_get_frame_rate_txt(const uint8_t frame_rate_code) {
+    return frame_rate_code == 0 ? "forbidden" :
+           frame_rate_code == 1 ? "23.976" :
+           frame_rate_code == 2 ? "24.00" :
+           frame_rate_code == 3 ? "25.00" :
+           frame_rate_code == 4 ? "29.97" :
+           frame_rate_code == 5 ? "30.00" :
+           frame_rate_code == 6 ? "50.00" :
+           frame_rate_code == 7 ? "59.94" :
+           frame_rate_code == 8 ? "60.00" : "reserved";
+}
+
+static inline const char *desc02_get_profile_txt(const uint8_t profile) {
+    return profile == 1 ? "High"               :
+           profile == 2 ? "Spatially Scalable" :
+           profile == 3 ? "SNR Scalable"       :
+           profile == 4 ? "Main"               :
+           profile == 5 ? "Simple"             : "Reserved";
+}
+
+static inline const char *desc02_get_level_txt(const uint8_t level) {
+    return level == 4  ? "High"      :
+           level == 6  ? "High 1440" :
+           level == 8  ? "Main"      :
+           level == 10 ? "Low"       : "Reserved";
+}
+
+static inline const char *desc02_get_chroma_format_txt(const uint8_t chroma_format) {
+    return chroma_format == 0 ? "reserved" :
+           chroma_format == 1 ? "4:2:0" :
+           chroma_format == 2 ? "4:2:2" :
+           chroma_format == 3 ? "4:4:4" : "unknown";
+}
+
+static inline void desc02_print(const uint8_t *p_desc, f_print pf_print,
+                                void *opaque, print_type_t i_print_type)
+{
+    uint8_t chroma_format, frame_rate_extension, profile, level;
+
+    uint8_t multiple_frame_rate  = (p_desc[2] & 0x80) == 0x80; // bit_8
+    uint8_t frame_rate_code      = (p_desc[2] &~ 0x80) >> 3; // 1xxxx111
+    uint8_t mpeg1_only           = (p_desc[2] & 0x04) == 0x04; // bit_3
+    uint8_t constraint_parameter = (p_desc[2] & 0x02) == 0x02; // bit_2
+    uint8_t still_picture        = (p_desc[2] & 0x01) == 0x01; // bit_1
+    if (mpeg1_only == 0) {
+        profile              = (p_desc[3] &~ 0x8f) >> 4;    // x111xxxx
+        level                = p_desc[3] &~ 0xf0;           // xxxx1111
+        chroma_format        = p_desc[4] >> 6;              // xx111111
+        frame_rate_extension = (p_desc[4] & 0x20) == 0x20;  // bit 6
+    }
+
+    switch (i_print_type) {
+    case PRINT_XML:
+        if (desc02_is_mpeg1_only_flag(p_desc)) {
+            pf_print(opaque,
+                "<VIDEO_STREAM_DESC multiple_frame_rate=\"%u\" frame_rate_code=\"%u\" frame_rate=\"%s\""
+                " mpeg1_only=\"%u\" constraint_parameter=\"%u\" still_picture=\"%u\"/>",
+                     multiple_frame_rate, frame_rate_code, desc02_get_frame_rate_txt(frame_rate_code),
+                     mpeg1_only, constraint_parameter, still_picture
+            );
+        } else {
+            pf_print(opaque,
+                "<VIDEO_STREAM_DESC multiple_frame_rate=\"%u\" frame_rate_code=\"%u\" frame_rate=\"%s\""
+                " mpeg1_only=\"%u\" constraint_parameter=\"%u\" still_picture=\"%u\""
+                " profile=\"%u\" profile_txt=\"%s\" level=\"%u\" level_txt=\"%s\""
+                " chroma_format=\"%u\" chroma_format_txt=\"%s\""
+                " frame_rate_extension=\"%u\"/>",
+                     multiple_frame_rate, frame_rate_code, desc02_get_frame_rate_txt(frame_rate_code),
+                     mpeg1_only, constraint_parameter, still_picture,
+                     profile, desc02_get_profile_txt(profile),
+                     level, desc02_get_level_txt(level),
+                     chroma_format, desc02_get_chroma_format_txt(chroma_format),
+                     frame_rate_extension
+            );
+        }
+        break;
+    default:
+        if (desc02_is_mpeg1_only_flag(p_desc)) {
+            pf_print(opaque,
+                "    - desc 02 multiple_frame_rate=%u frame_rate_code=%u frame_rate=%s"
+                " mpeg1_only=%u constraint_parameter=%u still_picture=%u",
+                     multiple_frame_rate, frame_rate_code, desc02_get_frame_rate_txt(frame_rate_code),
+                     mpeg1_only, constraint_parameter, still_picture
+            );
+        } else {
+            pf_print(opaque,
+                "    - desc 02 multiple_frame_rate=%u frame_rate_code=%u frame_rate=%s"
+                " mpeg1_only=%u constraint_parameter=%u still_picture=%u"
+                " profile=%u profile_txt=%s level=%u level_txt=%s"
+                " chroma_format=%u chroma_format_txt=%s"
+                " frame_rate_extension=%u",
+                     multiple_frame_rate, frame_rate_code, desc02_get_frame_rate_txt(frame_rate_code),
+                     mpeg1_only, constraint_parameter, still_picture,
+                     profile, desc02_get_profile_txt(profile),
+                     level, desc02_get_level_txt(level),
+                     chroma_format, desc02_get_chroma_format_txt(chroma_format),
+                     frame_rate_extension
+            );
+        }
+    }
+}
+
+/*****************************************************************************
  * Descriptor 0x05: Registration descriptor
  *****************************************************************************/
 #define DESC05_HEADER_SIZE      (DESC_HEADER_SIZE + 4)
-- 
1.7.5.1



More information about the dvblast-devel mailing list