dr_69.c | dr_69.c | |||
---|---|---|---|---|
/************************************************************************** *** | /************************************************************************** *** | |||
* dr_69.c | * dr_69.c | |||
* Copyright (C) 2007-2010 VideoLAN | * Copyright (C) 2007-2011 VideoLAN | |||
* $Id$ | * $Id$ | |||
* | * | |||
* Authors: Jiri Pinkava <master_up@post.cz> | * Authors: Jiri Pinkava <master_up@post.cz> | |||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
skipping to change at line 28 | skipping to change at line 28 | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1 USA | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1 USA | |||
* | * | |||
************************************************************************** ***/ | ************************************************************************** ***/ | |||
#include "config.h" | #include "config.h" | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <stdbool.h> | ||||
#include <string.h> | #include <string.h> | |||
#if defined(HAVE_INTTYPES_H) | #if defined(HAVE_INTTYPES_H) | |||
#include <inttypes.h> | #include <inttypes.h> | |||
#elif defined(HAVE_STDINT_H) | #elif defined(HAVE_STDINT_H) | |||
#include <stdint.h> | #include <stdint.h> | |||
#endif | #endif | |||
#include "../dvbpsi.h" | #include "../dvbpsi.h" | |||
#include "../dvbpsi_private.h" | #include "../dvbpsi_private.h" | |||
#include "../descriptor.h" | #include "../descriptor.h" | |||
#include "dr_69.h" | #include "dr_69.h" | |||
/************************************************************************** *** | /************************************************************************** *** | |||
* dvbpsi_DecodePDCDr | * dvbpsi_DecodePDCDr | |||
************************************************************************** ***/ | ************************************************************************** ***/ | |||
dvbpsi_PDC_dr_t * dvbpsi_DecodePDCDr(dvbpsi_descriptor_t * p_descriptor) | dvbpsi_PDC_dr_t * dvbpsi_DecodePDCDr(dvbpsi_descriptor_t * p_descriptor) | |||
{ | { | |||
dvbpsi_PDC_dr_t * p_decoded; | dvbpsi_PDC_dr_t * p_decoded; | |||
/* Check the tag */ | /* Check the tag */ | |||
if(p_descriptor->i_tag != 0x69) | if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x69)) | |||
{ | return NULL; | |||
DVBPSI_ERROR_ARG("dr_69 decoder", "bad tag (0x%x)", p_descriptor->i_tag | ||||
); | /* Don't decode twice */ | |||
return NULL; | if (dvbpsi_IsDescriptorDecoded(p_descriptor)) | |||
} | return p_descriptor->p_decoded; | |||
/* Don't decode twice */ | /* Check the length */ | |||
if(p_descriptor->p_decoded) | if (p_descriptor->i_length != 3) | |||
return p_descriptor->p_decoded; | return NULL; | |||
/* Decode data and check the length */ | /* Allocate memory */ | |||
if( p_descriptor->i_length != 3) | p_decoded = (dvbpsi_PDC_dr_t*)malloc(sizeof(dvbpsi_PDC_dr_t)); | |||
{ | if (!p_decoded) | |||
DVBPSI_ERROR_ARG("dr_69 decoder", "bad length (%d)", | return NULL; | |||
p_descriptor->i_length); | ||||
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); | ||||
/* Allocate memory */ | p_decoded->i_PDC[2] = ((p_descriptor->p_data[1] << 2) & 0x1c) | | |||
p_decoded = (dvbpsi_PDC_dr_t*)malloc(sizeof(dvbpsi_PDC_dr_t)); | (p_descriptor->p_data[2] >> 6); | |||
if(!p_decoded) | p_decoded->i_PDC[3] = p_descriptor->p_data[2] & 0x3f; | |||
{ | ||||
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; | p_descriptor->p_decoded = (void*)p_decoded; | |||
return p_decoded; | return p_decoded; | |||
} | } | |||
/************************************************************************** *** | /************************************************************************** *** | |||
* dvbpsi_GenPDCDr | * dvbpsi_GenPDCDr | |||
************************************************************************** ***/ | ************************************************************************** ***/ | |||
dvbpsi_descriptor_t * dvbpsi_GenPDCDr(dvbpsi_PDC_dr_t * p_decoded, | dvbpsi_descriptor_t * dvbpsi_GenPDCDr(dvbpsi_PDC_dr_t * p_decoded, | |||
int b_duplicate) | bool b_duplicate) | |||
{ | { | |||
/* Create the descriptor */ | /* Create the descriptor */ | |||
dvbpsi_descriptor_t * p_descriptor = | dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x69, 3, NULL | |||
dvbpsi_NewDescriptor(0x69, 3, NULL); | ); | |||
if (!p_descriptor) | ||||
return NULL; | ||||
if(p_descriptor) | ||||
{ | ||||
/* Encode data */ | /* Encode data */ | |||
p_descriptor->p_data[0] = 0xf0 | (p_decoded->i_PDC[0] >> 1); | p_descriptor->p_data[0] = 0xf0 | (p_decoded->i_PDC[0] >> 1); | |||
p_descriptor->p_data[1] = (p_decoded->i_PDC[0] << 7) | | p_descriptor->p_data[1] = (p_decoded->i_PDC[0] << 7) | | |||
(p_decoded->i_PDC[1] << 3) | (p_decoded->i_PDC[2] >> 2); | (p_decoded->i_PDC[1] << 3) | | |||
(p_decoded->i_PDC[2] >> 2); | ||||
p_descriptor->p_data[2] = (p_decoded->i_PDC[2] << 6 ) | | p_descriptor->p_data[2] = (p_decoded->i_PDC[2] << 6 ) | | |||
p_decoded->i_PDC[3]; | p_decoded->i_PDC[3]; | |||
if(b_duplicate) | if (b_duplicate) | |||
{ | { | |||
/* Duplicate decoded data */ | /* Duplicate decoded data */ | |||
dvbpsi_PDC_dr_t * p_dup_decoded = | p_descriptor->p_decoded = | |||
(dvbpsi_PDC_dr_t*)malloc(sizeof(dvbpsi_PDC_dr_t)); | dvbpsi_DuplicateDecodedDescriptor(p_decoded, | |||
if(p_dup_decoded) | sizeof(dvbpsi_PDC_dr_t)); | |||
memcpy(p_dup_decoded, p_decoded, sizeof(dvbpsi_PDC_dr_t)); | ||||
p_descriptor->p_decoded = (void*)p_dup_decoded; | ||||
} | } | |||
} | ||||
return p_descriptor; | return p_descriptor; | |||
} | } | |||
End of changes. 15 change blocks. | ||||
56 lines changed or deleted | 43 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |