Commit a1028692 authored by Andrew John Hughes's avatar Andrew John Hughes Committed by Christophe Massiot

* src/descriptor: Descriptor 0x52 decoding and generation

* examples/decode_pmt.c: More verbose output
parent 0ad4a56c
......@@ -21,6 +21,11 @@ D: subtables decoder
D: SDT decoder
D: most DVB descriptors
N: Andrew John Hughes
E: gnu_andrew@member.fsf.org
D: descriptor 0x52
D: decode_pmt verbose output
N: Tristan Leteurtre
E: tristan.leteurtre@anevia.com
C: tooney
......
......@@ -6,7 +6,7 @@ decode_pat_SOURCES = decode_pat.c
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
......
......@@ -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@via.ecp.fr>
*
......
......@@ -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@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 @@ int ReadPacket(int i_fd, uint8_t* p_dst)
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 @@ void DumpPMT(void* p_zero, dvbpsi_pmt_t* p_pmt)
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;
}
......
......@@ -32,6 +32,7 @@ pkginclude_HEADERS = dvbpsi.h psi.h descriptor.h demux.h \
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_src = descriptors/dr_02.c \
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
......
......@@ -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"
......
/*****************************************************************************
* dr_52.c
* (c)2005 Andrew John Hughes
*
* Authors: Andrew John Hughes <gnu_andrew@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;
}
/*****************************************************************************
* dr_52.h
* (c)2005 Andrew John Hughes
*
* Authors: Andrew John Hughes <gnu_andrew@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@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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment