Commit 62a24ea6 authored by Derk-Jan Hartman's avatar Derk-Jan Hartman

* New 0x56 EBU System B Teletext descriptor decoder.

  Currently untested
parent d578fa4c
......@@ -5,6 +5,7 @@ Changes between 0.1.4 and 0.1.5:
* src/tables/eit*: EIT decoder (no generator yet)
* 0x55 (dvb parental rating) descriptor decoder
* 0x56 (EBU teletext) descriptor decoder
* fixed a segfault in the subtitles descriptor decoder
* correctly handle duplicate packets
......
......@@ -33,6 +33,7 @@ pkginclude_HEADERS = dvbpsi.h psi.h descriptor.h demux.h \
descriptors/dr_47.h \
descriptors/dr_48.h \
descriptors/dr_55.h \
descriptors/dr_56.h \
descriptors/dr_59.h \
descriptors/dr.h
......@@ -54,6 +55,7 @@ descriptors_src = descriptors/dr_02.c \
descriptors/dr_47.c \
descriptors/dr_48.c \
descriptors/dr_55.c \
descriptors/dr_56.c \
descriptors/dr_59.c
tables_src = tables/pat.c tables/pat_private.h \
......
......@@ -50,6 +50,7 @@
#include "dr_47.h"
#include "dr_48.h"
#include "dr_55.h"
#include "dr_56.h"
#include "dr_59.h"
#else
......
/*****************************************************************************
* dr_56.c
* (c)2004 VideoLAN
* $Id: dr_56.c 93 2004-10-19 19:17:49Z massiot $
*
* Authors: Derk-Jan Hartman <hartman at videolan dot 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_56.h"
/*****************************************************************************
* dvbpsi_DecodeTeletextDr
*****************************************************************************/
dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr(
dvbpsi_descriptor_t * p_descriptor)
{
int i_pages_number, i;
dvbpsi_teletext_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x56)
{
DVBPSI_ERROR_ARG("dr_56 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_56 decoder", "bad length (%d)",
p_descriptor->i_length);
return NULL;
}
if(p_descriptor->i_length % 5)
{
DVBPSI_ERROR_ARG("dr_56 decoder", "length not multiple of 5(%d)",
p_descriptor->i_length);
return NULL;
}
i_pages_number = p_descriptor->i_length / 5;
/* Allocate memory */
p_decoded =
(dvbpsi_teletext_dr_t*)malloc(sizeof(dvbpsi_teletext_dr_t));
if(!p_decoded)
{
DVBPSI_ERROR("dr_56 decoder", "out of memory");
return NULL;
}
p_decoded->i_pages_number = i_pages_number;
for(i=0; i < i_pages_number; i++)
{
memcpy(p_decoded->p_pages[i].i_iso6392_language_code,
p_descriptor->p_data + 5 * i, 3);
p_decoded->p_pages[i].i_teletext_type =
((uint8_t)(p_descriptor->p_data[5 * i + 3]) >> 3)
p_decoded->p_pages[i].i_teletext_magazin_number =
((uint16_t)(p_descriptor->p_data[5 * i + 3]) & 0x07)
| p_descriptor->p_data[5 * i + 5];
p_decoded->p_pages[i].i_teletext_page_number = p_descriptor->p_data[4 * i + 4];
}
p_descriptor->p_decoded = (void*)p_decoded;
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenTeletextDr
*****************************************************************************/
dvbpsi_descriptor_t * dvbpsi_GenSubtitlingDr(
dvbpsi_teletext_dr_t * p_decoded,
int b_duplicate)
{
int i;
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x56, p_decoded->i_pages_number * 8 , NULL);
if(p_descriptor)
{
/* Encode data */
for (i=0; i < p_decoded->i_pages_number; i++ )
{
memcpy( p_descriptor->p_data + 8 * i,
p_decoded->p_pages[i].i_iso6392_language_code,
3);
p_descriptor->p_data[8 * i + 3] =
(uint8_t) ( (uint8_t)( p_decoded->p_pages[i].i_teletext_type << 3 ) |
( (uint8_t) p_decoded->p_pages[i].i_teletext_magazine_number & 0x07 );
p_descriptor->p_data[8 * i + 4] =
p_decoded->p_pages[i].i_teletext_page_number;
}
if(b_duplicate)
{
/* Duplicate decoded data */
dvbpsi_teletext_dr_t * p_dup_decoded =
(dvbpsi_teletext_dr_t*)malloc(sizeof(dvbpsi_teletext_dr_t));
if(p_dup_decoded)
memcpy(p_dup_decoded, p_decoded, sizeof(dvbpsi_teletext_dr_t));
p_descriptor->p_decoded = (void*)p_dup_decoded;
}
}
return p_descriptor;
}
/*****************************************************************************
* dr_56.h
* (c)2004 VideoLAN
* $Id: dr_56.h 93 2004-10-19 19:17:49Z massiot $
*
* Authors: Derk-Jan Hartman <hartman at videolan dot 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_56.h>
* \author Derk-Jan Hartman <hartman at videolan dot org>
* \brief EBU Teletext descriptor parsing.
*
* DVB EBU Teletext descriptor parsing, according to ETSI EN 300 468
* section 6.2.41.
*/
#ifndef _DVBPSI_DR_56_H_
#define _DVBPSI_DR_56_H_
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
* dvbpsi_teletext_t
*****************************************************************************/
/*!
* \struct dvbpsi_teletextpage_t
* \brief one teletext page structure.
*
* This structure is used since teletext_descriptor will contain several
* pages
*/
/*!
* \typedef struct dvbpsi_teletextpage_s dvbpsi_teletextpage_t
* \brief dvbpsi_teletextpage_t type definition.
*/
typedef struct dvbpsi_teletextpage_s
{
uint8_t i_iso6392_language_code[3]; /* 24 bits */
uint8_t i_teletext_type; /* 5 bits */
uint8_t i_teletext_magazine_number; /* 3 bits */
uint8_t i_teletext_page_number; /* 8 bits */
} dvbpsi_teletextpage_t;
/*****************************************************************************
* dvbpsi_teletext_dr_t
*****************************************************************************/
/*!
* \struct dvbpsi_teletext_dr_s
* \brief "subtitling" descriptor structure.
*
* This structure is used to store a decoded "subtitling"
* descriptor. (ETSI EN 300 468 section 6.2.30).
*/
/*!
* \typedef struct dvbpsi_teletext_dr_s dvbpsi_teletext_dr_t
* \brief dvbpsi_teletext_dr_t type definition.
*/
typedef struct dvbpsi_teletext_dr_s
{
uint8_t i_pages_number;
dvbpsi_teletextpage_t p_pages[64];
} dvbpsi_teletext_dr_t;
/*****************************************************************************
* dvbpsi_DecodeTeletextDataDr
*****************************************************************************/
/*!
* \fn dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDataDr(
dvbpsi_descriptor_t * p_descriptor)
* \brief "subtitling" descriptor decoder.
* \param p_descriptor pointer to the descriptor structure
* \return a pointer to a new "subtitling" descriptor structure
* which contains the decoded data.
*/
dvbpsi_teletext_dr_t* dvbpsi_DecodeTeletextDataDr(
dvbpsi_descriptor_t * p_descriptor);
/*****************************************************************************
* dvbpsi_GenTeletextDr
*****************************************************************************/
/*!
* \fn dvbpsi_descriptor_t * dvbpsi_GenTeletextDr(
dvbpsi_teletext_dr_t * p_decoded, int b_duplicate)
* \brief "teletext" descriptor generator.
* \param p_decoded pointer to a decoded "teletext" 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_GenTeletextDr(
dvbpsi_teletext_dr_t * p_decoded,
int b_duplicate);
#ifdef __cplusplus
};
#endif
#else
#error "Multiple inclusions of dr_56.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