Commit 94f6a279 authored by Damien Lucas's avatar Damien Lucas

. 0x59 (dvb subtitles) descriptor decoder

  Work of Tristan Leteurtre <tristan.leteurtre@anevia.com>
parent a620ded0
......@@ -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_59.h \
descriptors/dr.h
descriptors_src = descriptors/dr_02.c \
......@@ -50,7 +51,8 @@ descriptors_src = descriptors/dr_02.c \
descriptors/dr_0f.c \
descriptors/dr_42.c \
descriptors/dr_47.c \
descriptors/dr_48.c
descriptors/dr_48.c \
descriptors/dr_59.c
tables_src = tables/pat.c tables/pat_private.h \
tables/pmt.c tables/pmt_private.h \
......
/*****************************************************************************
* dr.h
* (c)2001-2002 VideoLAN
* $Id: dr.h,v 1.4 2002/12/12 10:19:32 jobi Exp $
* $Id: dr.h,v 1.5 2003/11/06 16:20:30 nitrox Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
*
......@@ -49,6 +49,7 @@
#include "dr_42.h"
#include "dr_47.h"
#include "dr_48.h"
#include "dr_59.h"
#else
#error "Multiple inclusions of dr.h"
......
/*****************************************************************************
* dr_48.c
* (c)2001-2002 VideoLAN
* $Id: dr_59.c,v 1.1 2003/11/06 16:20:30 nitrox Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* Tristan Leteurtre <tristan.leteurtre@anevia.com>
*
* 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_59.h"
/*****************************************************************************
* dvbpsi_DecodeSubtitlingDr
*****************************************************************************/
dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr(
dvbpsi_descriptor_t * p_descriptor)
{
int i_subtitles_number, i;
dvbpsi_subtitling_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x59)
{
DVBPSI_ERROR_ARG("dr_59 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_subtitling_dr_t*)malloc(sizeof(dvbpsi_subtitling_dr_t));
if(!p_decoded)
{
DVBPSI_ERROR("dr_59 decoder", "out of memory");
return NULL;
}
/* Decode data and check the length */
if(p_descriptor->i_length < 3)
{
DVBPSI_ERROR_ARG("dr_59 decoder", "bad length (%d)",
p_descriptor->i_length);
free(p_decoded);
}
if(p_descriptor->i_length % 8)
{
DVBPSI_ERROR_ARG("dr_59 decoder", "length not multiple of 8 (%d)",
p_descriptor->i_length);
free(p_decoded);
}
i_subtitles_number = p_descriptor->i_length / 8;
p_decoded->i_subtitles_number = i_subtitles_number;
for (i=0; i < i_subtitles_number; i++)
{
memcpy(p_decoded->p_subtitle[i].i_iso6392_language_code,
p_descriptor->p_data + 8 * i, 3);
p_decoded->p_subtitle[i].i_subtitling_type =
p_descriptor->p_data[8 * i + 3];
p_decoded->p_subtitle[i].i_composition_page_id =
((uint16_t)(p_descriptor->p_data[8 * i + 4]) << 8)
| p_descriptor->p_data[8 * i + 5];
p_decoded->p_subtitle[i].i_ancillary_page_id =
((uint16_t)(p_descriptor->p_data[8 * i + 6]) << 8)
| p_descriptor->p_data[8 * i + 7];
}
p_descriptor->p_decoded = (void*)p_decoded;
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenSubtitlingDr
*****************************************************************************/
dvbpsi_descriptor_t * dvbpsi_GenSubtitlingDr(
dvbpsi_subtitling_dr_t * p_decoded,
int b_duplicate)
{
int i;
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x59, 2 + p_decoded->i_subtitles_number * 8 , NULL);
if(p_descriptor)
{
/* Encode data */
for (i=0; i < p_decoded->i_subtitles_number; i++ )
{
memcpy( p_descriptor->p_data + 8 * i,
p_decoded->p_subtitle[i].i_iso6392_language_code,
3);
p_descriptor->p_data[8 * i + 3] =
p_decoded->p_subtitle[i].i_subtitling_type;
p_descriptor->p_data[8 * i + 4] =
p_decoded->p_subtitle[i].i_composition_page_id >> 8;
p_descriptor->p_data[8 * i + 5] =
p_decoded->p_subtitle[i].i_composition_page_id % 0xFF;
p_descriptor->p_data[8 * i + 6] =
p_decoded->p_subtitle[i].i_ancillary_page_id >> 8;
p_descriptor->p_data[8 * i + 7] =
p_decoded->p_subtitle[i].i_ancillary_page_id % 0xFF;
}
if(b_duplicate)
{
/* Duplicate decoded data */
dvbpsi_subtitling_dr_t * p_dup_decoded =
(dvbpsi_subtitling_dr_t*)malloc(sizeof(dvbpsi_subtitling_dr_t));
if(p_dup_decoded)
memcpy(p_dup_decoded, p_decoded, sizeof(dvbpsi_subtitling_dr_t));
p_descriptor->p_decoded = (void*)p_dup_decoded;
}
}
return p_descriptor;
}
/*****************************************************************************
* dr_59.h
* (c)2001-2002 VideoLAN
* $Id: dr_59.h,v 1.1 2003/11/06 16:20:30 nitrox Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* Tristan Leteurtre <tristan.leteurtre@anevia.com>
*
* 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_59.h>
* \author Tristan Leteurtre <tristan.leteurtre@anevia.com>
* \brief DVB subtitling descriptor parsing.
*
* DVB subtitling descriptor parsing, according to ETSI EN 300 468
* section 6.2.36.
*/
#ifndef _DVBPSI_DR_59_H_
#define _DVBPSI_DR_59_H_
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
* dvbpsi_subtitle_t
*****************************************************************************/
/*!
* \struct dvbpsi_subtitle_dr_s
* \brief one subtitle structure.
*
* This structure is used since subtitling_descriptor will contain several
* subtitles
*/
/*!
* \typedef struct dvbpsi_subtitle_s dvbpsi_subtitle_t
* \brief dvbpsi_subtitle_t type definition.
*/
typedef struct dvbpsi_subtitle_s
{
uint8_t i_iso6392_language_code[3];
uint8_t i_subtitling_type;
uint16_t i_composition_page_id;
uint16_t i_ancillary_page_id;
} dvbpsi_subtitle_t;
/*****************************************************************************
* dvbpsi_subtitling_dr_t
*****************************************************************************/
/*!
* \struct dvbpsi_subtitling_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_subtitling_dr_s dvbpsi_subtitling_dr_t
* \brief dvbpsi_subtitling_dr_t type definition.
*/
typedef struct dvbpsi_subtitling_dr_s
{
uint8_t i_subtitles_number;
dvbpsi_subtitle_t p_subtitle[20];
} dvbpsi_subtitling_dr_t;
/*****************************************************************************
* dvbpsi_DecodeSubtitlingDataDr
*****************************************************************************/
/*!
* \fn dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr(
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_subtitling_dr_t* dvbpsi_DecodeSubtitlingDr(
dvbpsi_descriptor_t * p_descriptor);
/*****************************************************************************
* dvbpsi_GenSubtitlingDataDr
*****************************************************************************/
/*!
* \fn dvbpsi_descriptor_t * dvbpsi_GenSubtitlingDr(
dvbpsi_subtitling_dr_t * p_decoded, int b_duplicate)
* \brief "subtitling" descriptor generator.
* \param p_decoded pointer to a decoded "subtitling" 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_GenSubtitlingDr(
dvbpsi_subtitling_dr_t * p_decoded,
int b_duplicate);
#ifdef __cplusplus
};
#endif
#else
#error "Multiple inclusions of dr_59.h"
#endif
......@@ -2,7 +2,7 @@
* pmt.c: PMT decoder/generator
*----------------------------------------------------------------------------
* (c)2001-2002 VideoLAN
* $Id: pmt.c,v 1.9 2003/07/25 21:08:45 fenrir Exp $
* $Id: pmt.c,v 1.10 2003/11/06 16:20:30 nitrox Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
*
......@@ -295,7 +295,7 @@ void dvbpsi_GatherPMTSections(dvbpsi_decoder_t* p_decoder,
if(b_append && (p_pmt_decoder->i_program_number != p_section->i_extension))
{
/* Invalid program_number */
DVBPSI_ERROR("PMT decoder",
//DVBPSI_ERROR("PMT decoder", \
"'program_number' don't match");
b_append = 0;
}
......
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