Patch to add descriptor 52 and improve the output of the PMT example.

Andrew John Hughes gnu_andrew at member.fsf.org
Mon Mar 21 13:20:08 CET 2005


Attached is a patch which adds support for descriptor 52, and also
gives more detailed output from the PMT example (specifically, it
prints out information from the descriptors, which is where the need
for descriptor 52 comes from).  The patch is against current HEAD,
and I'd like to contribute this back to the tree if possible.

Thanks,
-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

No software patents in Europe -- http://nosoftwarepatents.com

"Value your freedom, or you will lose it, teaches history. 
`Don't bother us with politics' respond those who don't want to learn." 
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }

-------------- next part --------------
Index: src/descriptors/dr_52.c
===================================================================
--- src/descriptors/dr_52.c	(revision 0)
+++ src/descriptors/dr_52.c	(revision 0)
@@ -0,0 +1,118 @@
+/*****************************************************************************
+ * dr_52.c
+ * (c)2005 Andrew John Hughes
+ *
+ * Authors: Andrew John Hughes <gnu_andrew at member.fsf.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ *****************************************************************************/
+
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(HAVE_INTTYPES_H)
+#include <inttypes.h>
+#elif defined(HAVE_STDINT_H)
+#include <stdint.h>
+#endif
+
+#include "../dvbpsi.h"
+#include "../dvbpsi_private.h"
+#include "../descriptor.h"
+
+#include "dr_52.h"
+
+
+/*****************************************************************************
+ * dvbpsi_DecodeStreamIdentifierDr
+ *****************************************************************************/
+dvbpsi_stream_identifier_dr_t * dvbpsi_DecodeStreamIdentifierDr(
+                                        dvbpsi_descriptor_t * p_descriptor)
+{
+  dvbpsi_stream_identifier_dr_t * p_decoded;
+
+  /* Check the tag */
+  if(p_descriptor->i_tag != 0x52)
+  {
+    DVBPSI_ERROR_ARG("dr_52 decoder", "bad tag (0x%x)", p_descriptor->i_tag);
+    return NULL;
+  }
+
+  /* Don't decode twice */
+  if(p_descriptor->p_decoded)
+    return p_descriptor->p_decoded;
+
+  /* Allocate memory */
+  p_decoded =
+        (dvbpsi_stream_identifier_dr_t*)malloc(sizeof(dvbpsi_stream_identifier_dr_t));
+  if(!p_decoded)
+  {
+    DVBPSI_ERROR("dr_52 decoder", "out of memory");
+    return NULL;
+  }
+
+  /* Decode data and check the length */
+  if(p_descriptor->i_length < 1)
+  {
+    DVBPSI_ERROR_ARG("dr_52 decoder", "bad length (%d)",
+                     p_descriptor->i_length);
+    free(p_decoded);
+    return NULL;
+  }
+
+  p_decoded->i_component_tag = p_descriptor->p_data[0];
+
+  p_descriptor->p_decoded = (void*)p_decoded;
+
+  return p_decoded;
+}
+
+
+/*****************************************************************************
+ * dvbpsi_GenStreamIdentifierDr
+ *****************************************************************************/
+dvbpsi_descriptor_t * dvbpsi_GenStreamIdentifierDr(
+                                        dvbpsi_stream_identifier_dr_t * p_decoded,
+                                        int b_duplicate)
+{
+  /* Create the descriptor */
+  dvbpsi_descriptor_t * p_descriptor =
+        dvbpsi_NewDescriptor(0x52, 1, NULL);
+
+  if(p_descriptor)
+  {
+    /* Encode data */
+    p_descriptor->p_data[0] = p_decoded->i_component_tag;
+
+    if(b_duplicate)
+    {
+      /* Duplicate decoded data */
+      dvbpsi_stream_identifier_dr_t * p_dup_decoded =
+        (dvbpsi_stream_identifier_dr_t*)malloc(sizeof(dvbpsi_stream_identifier_dr_t));
+      if(p_dup_decoded)
+        memcpy(p_dup_decoded, p_decoded, sizeof(dvbpsi_stream_identifier_dr_t));
+
+      p_descriptor->p_decoded = (void*)p_dup_decoded;
+    }
+  }
+
+  return p_descriptor;
+}
+
Index: src/descriptors/dr_52.h
===================================================================
--- src/descriptors/dr_52.h	(revision 0)
+++ src/descriptors/dr_52.h	(revision 0)
@@ -0,0 +1,102 @@
+/*****************************************************************************
+ * dr_52.h
+ * (c)2005 Andrew John Hughes
+ *
+ * Authors: Andrew John Hughes <gnu_andrew at member.fsf.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ *****************************************************************************/
+
+/*!
+ * \file <dr_52.h>
+ * \author Andrew John Hughes <gnu_andrew at member.fsf.org>
+ * \brief Application interface for the DVB "stream identifier"
+ * descriptor decoder and generator.
+ *
+ * Application interface for the DVB "stream identifier" descriptor
+ * decoder and generator. This descriptor's definition can be found in
+ * ETSI EN 300 468 section 6.2.37.
+ */
+
+#ifndef _DVBPSI_DR_52_H_
+#define _DVBPSI_DR_52_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*****************************************************************************
+ * dvbpsi_service_dr_t
+ *****************************************************************************/
+/*!
+ * \struct dvbpsi_service_dr_s
+ * \brief "stream identifier" descriptor structure.
+ *
+ * This structure is used to store a decoded "stream identifier"
+ * descriptor. (ETSI EN 300 468 section 6.2.37).
+ */
+/*!
+ * \typedef struct dvbpsi_service_dr_s dvbpsi_stream_identifier_dr_t
+ * \brief dvbpsi_stream_identifier_dr_t type definition.
+ */
+typedef struct dvbpsi_stream_identifier_dr_s
+{
+  uint8_t      i_component_tag;             /*!< component tag*/
+} dvbpsi_stream_identifier_dr_t;
+
+
+/*****************************************************************************
+ * dvbpsi_DecodeStreamIdentifierDr
+ *****************************************************************************/
+/*!
+ * \fn dvbpsi_stream_identifier_dr_t * dvbpsi_DecodeStreamIdentifierDr(
+                                        dvbpsi_descriptor_t * p_descriptor)
+ * \brief "stream identifier" descriptor decoder.
+ * \param p_descriptor pointer to the descriptor structure
+ * \return a pointer to a new "stream identifier" descriptor structure
+ * which contains the decoded data.
+ */
+dvbpsi_stream_identifier_dr_t* dvbpsi_DecodeStreamIdentifierDr(
+						      dvbpsi_descriptor_t * p_descriptor);
+
+
+/*****************************************************************************
+ * dvbpsi_GenStreamIdentifierDr
+ *****************************************************************************/
+/*!
+ * \fn dvbpsi_descriptor_t * dvbpsi_GenStreamIdentifierDr(
+                        dvbpsi_service_dr_t * p_decoded, int b_duplicate)
+ * \brief "stream identifier" descriptor generator.
+ * \param p_decoded pointer to a decoded "stream identifier" descriptor
+ * structure
+ * \param b_duplicate if non zero then duplicate the p_decoded structure into
+ * the descriptor
+ * \return a pointer to a new descriptor structure which contains encoded data.
+ */
+dvbpsi_descriptor_t * dvbpsi_GenStreamIdentifierDr(
+                                        dvbpsi_stream_identifier_dr_t * p_decoded,
+                                        int b_duplicate);
+
+
+#ifdef __cplusplus
+};
+#endif
+
+#else
+#error "Multiple inclusions of dr_52.h"
+#endif
+
Index: src/descriptors/dr.h
===================================================================
--- src/descriptors/dr.h	(revision 103)
+++ src/descriptors/dr.h	(working copy)
@@ -49,6 +49,7 @@
 #include "dr_42.h"
 #include "dr_47.h"
 #include "dr_48.h"
+#include "dr_52.h"
 #include "dr_55.h"
 #include "dr_56.h"
 #include "dr_59.h"
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 103)
+++ src/Makefile.am	(working copy)
@@ -32,6 +32,7 @@
                      descriptors/dr_42.h \
                      descriptors/dr_47.h \
                      descriptors/dr_48.h \
+		     descriptors/dr_52.h \
                      descriptors/dr_55.h \
                      descriptors/dr_56.h \
                      descriptors/dr_59.h \
@@ -54,6 +55,7 @@
                   descriptors/dr_42.c \
                   descriptors/dr_47.c \
                   descriptors/dr_48.c \
+		  descriptors/dr_52.c \
                   descriptors/dr_55.c \
                   descriptors/dr_56.c \
                   descriptors/dr_59.c
Index: examples/decode_pmt.c
===================================================================
--- examples/decode_pmt.c	(revision 103)
+++ examples/decode_pmt.c	(working copy)
@@ -2,7 +2,7 @@
  * decode_pmt.c: PAT decoder example
  *----------------------------------------------------------------------------
  * (c)2001-2002 VideoLAN
- * $Id: decode_pmt.c,v 1.3 2002/10/07 14:15:14 sam Exp $
+ * $Id$
  *
  * Authors: Arnaud de Bossoreille de Ribou <bozo at via.ecp.fr>
  *
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <math.h>
 
 #if defined(HAVE_INTTYPES_H)
 #include <inttypes.h>
@@ -44,13 +45,19 @@
 #include "../src/psi.h"
 #include "../src/descriptor.h"
 #include "../src/tables/pmt.h"
+#include "../src/descriptors/dr.h"
 #else
 #include <dvbpsi/dvbpsi.h>
 #include <dvbpsi/psi.h>
 #include <dvbpsi/descriptor.h>
 #include <dvbpsi/pmt.h>
+#include <dvbpsi/dr.h>
 #endif
 
+#define SYSTEM_CLOCK_DR 0x0B
+#define MAX_BITRATE_DR 0x0E
+#define STREAM_IDENTIFIER_DR 0x52
+#define SUBTITLING_DR 0x59
 
 /*****************************************************************************
  * ReadPacket
@@ -77,19 +84,129 @@
   return (i == 0) ? 1 : 0;
 }
 
+/*****************************************************************************
+ * GetTypeName
+ *****************************************************************************/
+char* GetTypeName(uint8_t type)
+{
+  switch (type)
+    {
+    case 0x00:
+      return "Reserved";
+    case 0x01:
+      return "ISO/IEC 11172 Video";
+    case 0x02:
+      return "ISO/IEC 13818-2 Video";
+    case 0x03:
+      return "ISO/IEC 11172 Audio";
+    case 0x04:
+      return "ISO/IEC 13818-3 Audio";
+    case 0x05:
+      return "ISO/IEC 13818-1 Private Section";
+    case 0x06:
+      return "ISO/IEC 13818-1 Private PES data packets";
+    case 0x07:
+      return "ISO/IEC 13522 MHEG";
+    case 0x08:
+      return "ISO/IEC 13818-1 Annex A DSM CC";
+    case 0x09:
+      return "H222.1";
+    case 0x0A:
+      return "ISO/IEC 13818-6 type A";
+    case 0x0B:
+      return "ISO/IEC 13818-6 type B";
+    case 0x0C:
+      return "ISO/IEC 13818-6 type C";
+    case 0x0D:
+      return "ISO/IEC 13818-6 type D";
+    case 0x0E:
+      return "ISO/IEC 13818-1 auxillary";
+    default:
+      if (type < 0x80)
+	return "ISO/IEC 13818-1 reserved";
+      else
+	return "User Private";
+    }
+}
 
 /*****************************************************************************
+ * DumpMaxBitrateDescriptor
+ *****************************************************************************/
+void DumpMaxBitrateDescriptor(dvbpsi_max_bitrate_dr_t* bitrate_descriptor)
+{
+  printf("Bitrate: %d\n", bitrate_descriptor->i_max_bitrate);
+}
+
+/*****************************************************************************
+ * DumpSystemClockDescriptor
+ *****************************************************************************/
+void DumpSystemClockDescriptor(dvbpsi_system_clock_dr_t* p_clock_descriptor)
+{
+  printf("External clock: %s, Accuracy: %E\n",
+	 p_clock_descriptor->b_external_clock_ref ? "Yes" : "No",
+	 p_clock_descriptor->i_clock_accuracy_integer *
+	 pow(10, p_clock_descriptor->i_clock_accuracy_exponent));
+}
+
+/*****************************************************************************
+ * DumpStreamIdentifierDescriptor
+ *****************************************************************************/
+void DumpStreamIdentifierDescriptor(dvbpsi_stream_identifier_dr_t* p_si_descriptor)
+{
+  printf("Component tag: %d\n",
+	 p_si_descriptor->i_component_tag);
+}
+
+/*****************************************************************************
+ * DumpSubtitleDescriptor
+ *****************************************************************************/
+void DumpSubtitleDescriptor(dvbpsi_subtitling_dr_t* p_subtitle_descriptor)
+{
+  int a;
+
+  printf("%d subtitles,\n", p_subtitle_descriptor->i_subtitles_number);
+  for (a = 0; a < p_subtitle_descriptor->i_subtitles_number; ++a)
+    {
+      printf("       | %d - lang: %c%c%c, type: %d, cpid: %d, apid: %d\n", a,
+	     p_subtitle_descriptor->p_subtitle[a].i_iso6392_language_code[0],
+	     p_subtitle_descriptor->p_subtitle[a].i_iso6392_language_code[1],
+	     p_subtitle_descriptor->p_subtitle[a].i_iso6392_language_code[2],
+	     p_subtitle_descriptor->p_subtitle[a].i_subtitling_type,
+	     p_subtitle_descriptor->p_subtitle[a].i_composition_page_id,
+	     p_subtitle_descriptor->p_subtitle[a].i_ancillary_page_id);
+    }
+}
+
+/*****************************************************************************
  * DumpDescriptors
  *****************************************************************************/
 void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descriptor)
 {
+  int i;
+
   while(p_descriptor)
   {
-    int i;
-    printf("%s 0x%02x : \"", str, p_descriptor->i_tag);
-    for(i = 0; i < p_descriptor->i_length; i++)
-      printf("%c", p_descriptor->p_data[i]);
-    printf("\"\n");
+    printf("%s 0x%02x : ", str, p_descriptor->i_tag);
+    switch (p_descriptor->i_tag)
+      {
+      case SYSTEM_CLOCK_DR:
+	DumpSystemClockDescriptor(dvbpsi_DecodeSystemClockDr(p_descriptor));
+	break;
+      case MAX_BITRATE_DR:
+	DumpMaxBitrateDescriptor(dvbpsi_DecodeMaxBitrateDr(p_descriptor));
+	break;
+      case STREAM_IDENTIFIER_DR:
+	DumpStreamIdentifierDescriptor(dvbpsi_DecodeStreamIdentifierDr(p_descriptor));
+	break;
+      case SUBTITLING_DR:
+	DumpSubtitleDescriptor(dvbpsi_DecodeSubtitlingDr(p_descriptor));
+	break;
+      default:
+	printf("\"");
+	for(i = 0; i < p_descriptor->i_length; i++)
+	  printf("%c", p_descriptor->p_data[i]);
+	printf("\"\n");
+      }
     p_descriptor = p_descriptor->p_next;
   }
 };
@@ -113,8 +230,9 @@
   printf(  "    | type @ elementary_PID\n");
   while(p_es)
   {
-    printf("    | 0x%02x @ 0x%x (%d)\n",
-           p_es->i_type, p_es->i_pid, p_es->i_pid);
+    printf("    | 0x%02x (%s) @ 0x%x (%d)\n",
+           p_es->i_type, GetTypeName(p_es->i_type),
+	   p_es->i_pid, p_es->i_pid);
     DumpDescriptors("    |  ]", p_es->p_first_descriptor);
     p_es = p_es->p_next;
   }
Index: examples/decode_pat.c
===================================================================
--- examples/decode_pat.c	(revision 103)
+++ examples/decode_pat.c	(working copy)
@@ -2,7 +2,7 @@
  * decode_pat.c: PAT decoder example
  *----------------------------------------------------------------------------
  * (c)2001-2002 VideoLAN
- * $Id: decode_pat.c,v 1.3 2002/10/07 14:15:14 sam Exp $
+ * $Id$
  *
  * Authors: Arnaud de Bossoreille de Ribou <bozo at via.ecp.fr>
  *
Index: examples/Makefile.am
===================================================================
--- examples/Makefile.am	(revision 103)
+++ examples/Makefile.am	(working copy)
@@ -6,7 +6,7 @@
 decode_pat_LDFLAGS = -L../src -ldvbpsi
 
 decode_pmt_SOURCES = decode_pmt.c
-decode_pmt_LDFLAGS = -L../src -ldvbpsi
+decode_pmt_LDFLAGS = -L../src -ldvbpsi -lm
 
 decode_sdt_SOURCES = decode_sdt.c
 decode_sdt_LDFLAGS = -L../src -ldvbpsi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.videolan.org/pipermail/libdvbpsi-devel/attachments/20050321/a18b23e6/attachment.pgp 


More information about the libdvbpsi-devel mailing list