Commit 4cd53b56 authored by Jean-Paul Saman's avatar Jean-Paul Saman

ATSC: descriptors refactor

- refactor descriptor structs allocations
parent c2587e30
......@@ -33,6 +33,20 @@ Decode Carousel Id Descriptor.
#include "dr_13.h"
static dvbpsi_carousel_id_dr_t *NewCarouselDr(const size_t i_private)
{
dvbpsi_carousel_id_dr_t *p_carousel;
if (i_private <= 0)
return NULL;
p_carousel = (dvbpsi_carousel_id_dr_t *)
calloc(1, sizeof(dvbpsi_carousel_id_dr_t) + i_private);
if (p_carousel)
{
p_carousel->p_private_data = p_carousel + sizeof(dvbpsi_carousel_id_dr_t);
p_carousel->i_private_data_len = i_private;
}
return p_carousel;
}
/*****************************************************************************
* dvbpsi_DecodeCarouselIdDr
......@@ -53,18 +67,10 @@ dvbpsi_carousel_id_dr_t *dvbpsi_DecodeCarouselIdDr(dvbpsi_descriptor_t *p_descri
if (p_descriptor->i_length < 4)
return NULL;
p_decoded = (dvbpsi_carousel_id_dr_t*)malloc(sizeof(dvbpsi_carousel_id_dr_t));
p_decoded = NewCarouselDr(p_descriptor->i_length - 4);
if (!p_decoded)
return NULL;
p_decoded->p_private_data = malloc(p_descriptor->i_length - 4);
if (!p_decoded->s_private_data)
{
free(p_decoded);
return NULL;
}
p_decoded->i_private_data_len = p_descriptor->i_length - 4;
p_decoded->i_carousel_id = ((p_descriptor->p_data[0] & 0xff) << 24) | ((p_descriptor->p_data[1] & 0xff) << 16)|
((p_descriptor->p_data[2] & 0xff) << 8) | (p_descriptor->p_data[3] & 0xff);
......
......@@ -38,10 +38,12 @@ Decode Carousel id Descriptor.
*/
typedef struct dvbpsi_carousel_id_dr_s
{
uint32_t i_carousel_id;
uint8_t i_private_data_len;
uint8_t *p_private_data; /*< allocated memory must be released */
}dvbpsi_carousel_id_dr_t;
uint32_t i_carousel_id; /*< carousel identifier */
uint8_t i_private_data_len; /*< length of private data pointer in bytes */
uint8_t *p_private_data; /*< memory is allocated right after sizeof struct,
when freeing this struct the private data is
freed at the same time. */
} dvbpsi_carousel_id_dr_t;
/*****************************************************************************
* dvbpsi_DecodeCarouselIdDr
......@@ -57,7 +59,3 @@ typedef struct dvbpsi_carousel_id_dr_s
dvbpsi_carousel_id_dr_t *dvbpsi_DecodeCarouselIdDr(dvbpsi_descriptor_t *p_descriptor);
#endif
......@@ -33,6 +33,25 @@ Decode Assocation Tag Descriptor.
#include "dr_14.h"
static dvbpsi_association_tag_dr_t *NewAssociationTagDr(const size_t i_selector, const size_t i_private)
{
dvbpsi_association_tag_dr_t *p_tag;
if ((i_selector <= 0) || (i_private <= 0))
return NULL;
size_t i_size = sizeof(dvbpsi_association_tag_dr_t) + i_selector + i_private;
p_tag = (dvbpsi_association_tag_dr_t*) calloc(1, i_size);
if (p_tag)
{
p_tag->p_selector = p_tag + sizeof(dvbpsi_association_tag_dr_t);
p_tag->i_selector_len = i_selector;
p_tag->p_private_data = p_tag->p_selector + i_selector;
p_tag->i_private_data_len = i_private;
}
return p_tag;
}
/*****************************************************************************
* dvbpsi_DecodeAssociationTagDr
......@@ -56,41 +75,23 @@ dvbpsi_association_tag_dr_t *dvbpsi_DecodeAssociationTagDr(dvbpsi_descriptor_t *
return NULL;
selector_len = p_descriptor->p_data[4];
private_data_len = p_descriptor->i_length - (5 + selector_len);
/* Invalid selector length */
if (selector_len + 5 > p_descriptor->i_length)
return NULL;
private_data_len= p_descriptor->i_length - (5 + selector_len);
p_decoded = (dvbpsi_association_tag_dr_t*)malloc(sizeof(dvbpsi_association_tag_dr_t));
p_decoded = NewAssociationTagDr(selector_len, private_data_len);
if (!p_decoded)
return NULL;
p_decoded->p_selector = malloc(selector_len);
if (!p_decoded->p_selector)
{
free(p_decoder);
return NULL;
}
p_decoded->p_private_data = malloc(private_data_len);
if (!p_decoded->p_private_data)
{
free(p_decoded->p_selector);
free(p_decoder);
return NULL;
}
p_decoded->i_tag = ((p_descriptor->p_data[0] & 0xff) << 8) | (p_descriptor->p_data[1] & 0xff);
p_decoded->i_use = ((p_descriptor->p_data[2] & 0xff) << 8) | (p_descriptor->p_data[3] & 0xff);
p_decoded->i_selector_len = selector_len;
p_decoded->i_private_data_len= private_data_len;
p_decoded->p_selector = ((void*)p_decoded) + sizeof(dvbpsi_association_tag_dr_t);
p_decoded->p_private_data = p_decoded->p_selector + selector_len;
memcpy(p_decoded->p_selector, &p_descriptor->p_data[5], selector_len);
memcpy(p_decoded->p_private_data, &p_descriptor->p_data[5 + selector_len], private_data_len);
p_descriptor->p_decoded = (void*)p_decoded;
return p_decoded;
}
......@@ -38,12 +38,16 @@ Decode Association Tag Descriptor.
*/
typedef struct dvbpsi_association_tag_dr_s
{
uint16_t i_tag;
uint16_t i_use;
uint8_t i_selector_len;
uint8_t *p_selector;
uint8_t i_private_data_len;
uint8_t *p_private_data; /*< release allocated memory */
uint16_t i_tag; /*< association tag identifier */
uint16_t i_use; /*< indicator if association tag identifier is in use */
uint8_t i_selector_len; /*< length of selector data in bytes */
uint8_t *p_selector; /*< pointer to selector. Memory is allocated
right after sizeof struct, when freeing this
struct the private data is freed at the same time. */
uint8_t i_private_data_len; /*< length of private data segment in bytes */
uint8_t *p_private_data; /*< pointer to private data. Memory is allocated
right after sizeof struct, when freeing this
struct the private data is freed at the same time. */
} dvbpsi_association_tag_dr_t;
/*****************************************************************************
......@@ -60,8 +64,3 @@ typedef struct dvbpsi_association_tag_dr_s
dvbpsi_association_tag_dr_t *dvbpsi_DecodeAssociationTagDr(dvbpsi_descriptor_t *p_descriptor);
#endif
......@@ -77,5 +77,3 @@ uint32_t dvbpsi_Bcd8ToUint32(uint32_t bcd);
#endif
#endif
......@@ -33,6 +33,22 @@ Decode Data Broadcast Id Descriptor.
#include "dr_66.h"
static dvbpsi_data_broadcast_id_dr_t *NewDataBroadcastDr(const size_t i_private)
{
dvbpsi_data_broadcast_id_dr_t *p_bcast;
if (i_private <= 0)
return NULL;
p_bcast = (dvbpsi_data_broadcast_id_dr_t *)
calloc(1, sizeof(dvbpsi_data_broadcast_id_dr_t) + i_private);
if (p_bcast)
{
p_bcast->p_id_selector = p_bcast + sizeof(dvbpsi_data_broadcast_id_dr_t);
p_bcast->i_id_selector_len = i_private;
}
return p_bcast;
}
/*****************************************************************************
* dvbpsi_DecodeDataBroadcastIdDr
......@@ -53,18 +69,11 @@ dvbpsi_data_broadcast_id_dr_t *dvbpsi_DecodeDataBroadcastIdDr(dvbpsi_descriptor_
if (p_descriptor->i_length < 2)
return NULL;
p_decoded = (dvbpsi_data_broadcast_id_dr_t*)malloc(sizeof(dvbpsi_data_broadcast_id_dr_t));
p_decoded = NewDataBroadcastDr(p_descriptor->i_length - 2);
if (!p_decoded)
return NULL;
p_decoded->p_id_selector = malloc(p_descriptor->i_length - 2);
if (!p_decoded->p_id_selector)
{
free(p_decoded);
return NULL;
}
p_decoded->i_data_broadcast_id = ((p_descriptor->p_data[0] & 0xff) << 8) | (p_descriptor->p_data[1] & 0xff);
p_decoded->i_id_selector_len = p_descriptor->i_length - 2;
memcpy(p_decoded->p_id_selector, &p_descriptor->p_data[2], p_decoded->i_id_selector_len);
p_descriptor->p_decoded = (void*)p_decoded;
......
......@@ -38,10 +38,12 @@ Decode Data Broadcast id Descriptor.
*/
typedef struct dvbpsi_data_broadcast_id_dr_s
{
uint16_t i_data_broadcast_id;
uint8_t i_id_selector_len;
uint8_t *p_id_selector; /*< release allocated memory */
}dvbpsi_data_broadcast_id_dr_t;
uint16_t i_data_broadcast_id; /*< broadcast identifier */
uint8_t i_id_selector_len; /*< length of selector data in bytes */
uint8_t *p_id_selector; /*< pointer to selector data. Memory is allocated
right after sizeof struct, when freeing this
struct the private data is freed at the same time. */
} dvbpsi_data_broadcast_id_dr_t;
/*****************************************************************************
* dvbpsi_DecodeDataBroadcastIdDr
......
......@@ -43,8 +43,8 @@ extern "C" {
*/
typedef struct dvbpsi_default_authority_dr_s
{
uint8_t authority[255];
}dvbpsi_default_authority_dr_t;
uint8_t authority[255]; /*< default authorizty descriptor */
} dvbpsi_default_authority_dr_t;
/*****************************************************************************
* dvbpsi_DecodeLCNDr
......@@ -63,6 +63,3 @@ dvbpsi_default_authority_dr_t *dvbpsi_DecodeDefaultAuthorityDr(dvbpsi_descriptor
#endif
#endif
......@@ -45,8 +45,8 @@ typedef struct dvbpsi_lcn_entry_s
{
uint16_t i_service_id; /*!< Service ID this logical channel number refers to */
int b_visible_service_flag; /*!< Whether this LCN should be visible to the user. */
uint16_t i_logical_channel_number; /*!<The logical channel number for this service. */
}dvbpsi_lcn_entry_t;
uint16_t i_logical_channel_number; /*!< The logical channel number for this service. */
} dvbpsi_lcn_entry_t;
/*****************************************************************************
* dvbpsi_lcn_dr_s
......
......@@ -29,6 +29,8 @@
#include <stdarg.h>
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
extern uint32_t dvbpsi_crc32_table[];
/*****************************************************************************
......
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