[PATCH] new description table (0x69 - Program Delivery Control)
Pinky <[email protected]>
| Newsgroups | gmane.comp.video.videolan.libdvbpsi.devel |
|---|---|
| Message-ID | <20070526184954.3f87b72c__33420.5982428559$1180198232$gmane$org@storage_kolej.vscht.cz> |
Hi, I implement for my self new table into libdvbpsi(descriptor 0x69) Program Delivery Control. ( http://en.wikipedia.org/wiki/Programme_Delivery_Control ) I mean, this might be useful for others and not only for my. I attach patch against latest, CVS/SVN version of library (but it is "version independent"). I does not try generate PDC descriptor, only decoding is tested. Jiří Pinkava.
libdvbpsi_td_0x69.patch
(text/x-patch, 8.5 KB)
diff -ruN -x'.*' libdvbpsi.orig/src/descriptors/dr_69.c libdvbpsi/src/descriptors/dr_69.c --- libdvbpsi.orig/src/descriptors/dr_69.c 1970-01-01 01:00:00.000000000 +0100 +++ libdvbpsi/src/descriptors/dr_69.c 2007-05-26 17:43:23.000000000 +0200 @@ -0,0 +1,124 @@ +/***************************************************************************** + * dr_69.c + * (c)2007 VideoLAN + * $Id: dr_69.c 88 2007-26-05 14:31:18Z sam $ + * + * Authors: Jiri Pinkava <[email protected]> + * + * 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_69.h" + + +/***************************************************************************** + * dvbpsi_DecodePDCDr + *****************************************************************************/ +dvbpsi_PDC_dr_t * dvbpsi_DecodePDCDr(dvbpsi_descriptor_t * p_descriptor) +{ + dvbpsi_PDC_dr_t * p_decoded; + + /* Check the tag */ + if(p_descriptor->i_tag != 0x69) + { + DVBPSI_ERROR_ARG("dr_69 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; + + /* Decode data and check the length */ + if( p_descriptor->i_length != 3) + { + DVBPSI_ERROR_ARG("dr_69 decoder", "bad length (%d)", + p_descriptor->i_length); + return NULL; + } + + /* Allocate memory */ + p_decoded = (dvbpsi_PDC_dr_t*)malloc(sizeof(dvbpsi_PDC_dr_t)); + if(!p_decoded) + { + DVBPSI_ERROR("dr_69 decoder", "out of memory"); + return NULL; + } + + p_decoded->i_PDC[0] = ((p_descriptor->p_data[0] & 0x0f) << 1) | + (p_descriptor->p_data[1] >> 7); + p_decoded->i_PDC[1] = ((p_descriptor->p_data[1] >> 3) & 0x0f); + p_decoded->i_PDC[2] = ((p_descriptor->p_data[1] << 2) & 0x1c) | + (p_descriptor->p_data[2] >> 6); + p_decoded->i_PDC[3] = p_descriptor->p_data[2] & 0x3f; + + p_descriptor->p_decoded = (void*)p_decoded; + + return p_decoded; +} + + +/***************************************************************************** + * dvbpsi_GenPDCDr + *****************************************************************************/ +dvbpsi_descriptor_t * dvbpsi_GenPDCDr(dvbpsi_PDC_dr_t * p_decoded, + int b_duplicate) +{ + /* Create the descriptor */ + dvbpsi_descriptor_t * p_descriptor = + dvbpsi_NewDescriptor(0x69, 3, NULL); + + if(p_descriptor) + { + /* Encode data */ + p_descriptor->p_data[0] = 0xf0 | (p_decoded->i_PDC[0] >> 1); + p_descriptor->p_data[1] = (p_decoded->i_PDC[0] << 7) | + (p_decoded->i_PDC[1] << 3) | (p_decoded->i_PDC[2] >> 2); + p_descriptor->p_data[2] = (p_decoded->i_PDC[2] << 6 ) | + p_decoded->i_PDC[3]; + + if(b_duplicate) + { + /* Duplicate decoded data */ + dvbpsi_PDC_dr_t * p_dup_decoded = + (dvbpsi_PDC_dr_t*)malloc(sizeof(dvbpsi_PDC_dr_t)); + if(p_dup_decoded) + memcpy(p_dup_decoded, p_decoded, sizeof(dvbpsi_PDC_dr_t)); + + p_descriptor->p_decoded = (void*)p_dup_decoded; + } + } + + return p_descriptor; +} + diff -ruN -x'.*' libdvbpsi.orig/src/descriptors/dr_69.h libdvbpsi/src/descriptors/dr_69.h --- libdvbpsi.orig/src/descriptors/dr_69.h 1970-01-01 01:00:00.000000000 +0100 +++ libdvbpsi/src/descriptors/dr_69.h 2007-05-26 17:45:28.000000000 +0200 @@ -0,0 +1,100 @@ +/***************************************************************************** + * dr_69.h + * (c)2007 VideoLAN + * $Id: dr_69.h 88 2007-05-26 14:31:18Z sam $ + * + * Authors: Pinkava Jiri <[email protected]> + * + * 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_69.h> + * \author Jiri Pinkava <[email protected]> + * \brief Application interface for the PDC (Programme Delivery Control) + * descriptor decoder and generator. + * + * Application interface for the MPEG 2 TS PDC descriptor decoder and generator + * This descriptor's definition can be found in ETSC EN 300 231 + */ + +#ifndef _DVBPSI_DR_69_H_ +#define _DVBPSI_DR_69_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +/***************************************************************************** + * dvbpsi_PDC_dr_t + *****************************************************************************/ +/*! + * \struct dvbpsi_PDC_dr_s + * \brief PDC descriptor structure. + * + * This structure is used to store a decoded PDC descriptor. + * (ETSI EN 300 231). + */ +/*! + * \typedef struct dvbpsi_PDC_dr_s dvbpsi_PDC_dr_t + * \brief dvbpsi_PDC_dr_t type definition. + */ +typedef struct dvbpsi_PDC_dr_s +{ + /* pdc[0] ~= day; PDC[1] ~= month; PDC[2] ~= hour; PDC[3] ~= min; */ + uint8_t i_PDC[4]; /*!< PDC */ +} dvbpsi_PDC_dr_t; + + +/***************************************************************************** + * dvbpsi_DecodePDCDr + *****************************************************************************/ +/*! + * \fn dvbpsi_PDC_dr_t * dvbpsi_DecodePDCDr( + dvbpsi_descriptor_t * p_descriptor) + * \brief PDC descriptor decoder. + * \param p_descriptor pointer to the descriptor structure + * \return a pointer to a new "video stream" descriptor structure which + * contains the decoded data. + */ +dvbpsi_PDC_dr_t* dvbpsi_DecodePDCDr(dvbpsi_descriptor_t * p_descriptor); + + +/***************************************************************************** + * dvbpsi_GenPDCDr + *****************************************************************************/ +/*! + * \fn dvbpsi_descriptor_t * dvbpsi_GenVStreamDr( + dvbpsi_PDC_dr_t * p_decoded, int b_duplicate) + * \brief PDC descriptor generator. + * \param p_decoded pointer to a decoded PDC 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_GenPDCDr(dvbpsi_PDC_dr_t * p_decoded, + int b_duplicate); + + +#ifdef __cplusplus +}; +#endif + +#else +#error "Multiple inclusions of dr_69.h" +#endif + diff -ruN -x'.*' libdvbpsi.orig/src/Makefile.am libdvbpsi/src/Makefile.am --- libdvbpsi.orig/src/Makefile.am 2007-05-26 18:42:02.000000000 +0200 +++ libdvbpsi/src/Makefile.am 2007-05-26 13:33:26.000000000 +0200 @@ -38,6 +38,7 @@ descriptors/dr_55.h \ descriptors/dr_56.h \ descriptors/dr_59.h \ + descriptors/dr_69.h \ descriptors/dr.h descriptors_src = descriptors/dr_02.c \ @@ -62,7 +63,8 @@ descriptors/dr_52.c \ descriptors/dr_55.c \ descriptors/dr_56.c \ - descriptors/dr_59.c + descriptors/dr_59.c \ + descriptors/dr_69.c tables_src = tables/pat.c tables/pat_private.h \ tables/pmt.c tables/pmt_private.h \