[libdvbpsi-devel] descriptors/dr_a1: Add support for generation of Service Location descriptor

mbenoit git at videolan.org
Wed Dec 24 12:51:57 CET 2014


libdvbpsi | branch: master | mbenoit <mbenoit at anevia.com> | Mon Dec 15 22:07:07 2014 +0100| [16257a3a88b904679e1baf96f32fff1fb6ef4c9d] | committer: Jean-Paul Saman

descriptors/dr_a1: Add support for generation of Service Location descriptor

Signed-off-by: Jean-Paul Saman <jpsaman at videolan.org>

> http://git.videolan.org/gitweb.cgi/libdvbpsi.git/?a=commit;h=16257a3a88b904679e1baf96f32fff1fb6ef4c9d
---

 src/descriptors/dr_a1.c |   70 ++++++++++++++++++++++-------------------------
 src/descriptors/dr_a1.h |    8 ++----
 2 files changed, 35 insertions(+), 43 deletions(-)

diff --git a/src/descriptors/dr_a1.c b/src/descriptors/dr_a1.c
index faeb8a2..796f3c0 100644
--- a/src/descriptors/dr_a1.c
+++ b/src/descriptors/dr_a1.c
@@ -91,49 +91,43 @@ dvbpsi_DecodeServiceLocationDr (dvbpsi_descriptor_t * p_descriptor)
     return p_decoded;
 }
 
-#if 0
+
 /*****************************************************************************
- * dvbpsi_GenServiceDr
+ * dvbpsi_GenServiceLocationDr
  *****************************************************************************/
-dvbpsi_descriptor_t *
-dvbpsi_GenServiceDr (dvbpsi_service_location_dr_t * p_decoded,
-		     bool b_duplicate)
+dvbpsi_descriptor_t* dvbpsi_GenServiceLocationDr(
+                                        dvbpsi_service_location_dr_t* p_decoded,
+                                        bool b_duplicate)
 {
-    /* Create the descriptor */
-    dvbpsi_descriptor_t *p_descriptor =
-            dvbpsi_NewDescriptor (0x48,
-                                  3 + p_decoded->i_service_location_name_length +
-                                  p_decoded->i_service_location_provider_name_length,
-                                  NULL);
-
-    if (p_descriptor)
+    uint8_t i_desc_length = 3 + p_decoded->i_number_elements * 6;
+    dvbpsi_descriptor_t* p_descriptor = dvbpsi_NewDescriptor(0xa1, i_desc_length, NULL);
+    if (!p_descriptor)
+        return NULL;
+
+    uint8_t* p_data = p_descriptor->p_data;
+    p_data[0] = p_decoded->i_pcr_pid >> 8;
+    p_data[1] = p_decoded->i_pcr_pid;
+    p_data[2] = p_decoded->i_number_elements;
+
+    p_data += 3;
+    for (uint8_t i = 0; i < p_decoded->i_number_elements; ++i) {
+      dvbpsi_service_location_element_t p_es = p_decoded->elements[i];
+      uint8_t* p_es_data = p_data;
+      p_es_data[0] = p_es.i_stream_type;
+      p_es_data[1] = p_es.i_elementary_pid >> 8;
+      p_es_data[2] = p_es.i_elementary_pid;
+      p_es_data[3] = p_es.i_iso_639_code[0];
+      p_es_data[4] = p_es.i_iso_639_code[1];
+      p_es_data[5] = p_es.i_iso_639_code[2];
+
+      p_data += 6;
+    }
+
+    if (b_duplicate)
     {
-        /* Encode data */
-        p_descriptor->p_data[0] = p_decoded->i_service_type;
-        p_descriptor->p_data[1] = p_decoded->i_service_provider_name_length;
-        if (p_decoded->i_service_provider_name_length)
-            memcpy (p_descriptor->p_data + 2,
-                    p_decoded->i_service_provider_name,
-                    p_decoded->i_service_provider_name_length);
-        p_descriptor->p_data[2 + p_decoded->i_service_provider_name_length] =
-                p_decoded->i_service_name_length;
-        if (p_decoded->i_service_name_length)
-            memcpy (p_descriptor->p_data + 3 +
-                    p_decoded->i_service_provider_name_length,
-                    p_decoded->i_service_name, p_decoded->i_service_name_length);
-
-        if (b_duplicate)
-        {
-            /* Duplicate decoded data */
-            dvbpsi_service_dr_t *p_dup_decoded =
-                    (dvbpsi_service_dr_t *) malloc (sizeof (dvbpsi_service_dr_t));
-            if (p_dup_decoded)
-                memcpy (p_dup_decoded, p_decoded, sizeof (dvbpsi_service_dr_t));
-
-            p_descriptor->p_decoded = (void *) p_dup_decoded;
-        }
+      p_descriptor->p_decoded = dvbpsi_DuplicateDecodedDescriptor(p_decoded,
+        sizeof(dvbpsi_service_location_dr_t));
     }
 
     return p_descriptor;
 }
-#endif
diff --git a/src/descriptors/dr_a1.h b/src/descriptors/dr_a1.h
index 5130168..b2072e4 100644
--- a/src/descriptors/dr_a1.h
+++ b/src/descriptors/dr_a1.h
@@ -81,7 +81,6 @@ typedef struct dvbpsi_service_location_dr_s
 dvbpsi_service_location_dr_t
     *dvbpsi_DecodeServiceLocationDr (dvbpsi_descriptor_t * p_descriptor);
 
-#if 0
 /*****************************************************************************
  * dvbpsi_GenServiceDataDr
  *****************************************************************************/
@@ -95,10 +94,9 @@ dvbpsi_service_location_dr_t
  * the descriptor
  * \return a pointer to a new descriptor structure which contains encoded data.
  */
-dvbpsi_descriptor_t *dvbpsi_GenServiceLocationDr (dvbpsi_service_dr_t *
-						    p_decoded,
-						    bool b_duplicate);
-#endif
+dvbpsi_descriptor_t* dvbpsi_GenServiceLocationDr(
+                                        dvbpsi_service_location_dr_t* p_decoded,
+                                        bool b_duplicate);
 
 
 #ifdef __cplusplus



More information about the libdvbpsi-devel mailing list