aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libucsi
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libucsi')
-rw-r--r--lib/libucsi/Makefile34
-rw-r--r--lib/libucsi/atsc/Makefile55
-rw-r--r--lib/libucsi/atsc/ac3_descriptor.h112
-rw-r--r--lib/libucsi/atsc/atsc_text.c743
-rw-r--r--lib/libucsi/atsc/caption_service_descriptor.h137
-rw-r--r--lib/libucsi/atsc/component_name_descriptor.h92
-rw-r--r--lib/libucsi/atsc/content_advisory_descriptor.h235
-rw-r--r--lib/libucsi/atsc/cvct_section.c77
-rw-r--r--lib/libucsi/atsc/cvct_section.h228
-rw-r--r--lib/libucsi/atsc/dcc_arriving_request_descriptor.h107
-rw-r--r--lib/libucsi/atsc/dcc_departing_request_descriptor.h108
-rw-r--r--lib/libucsi/atsc/dccsct_section.c109
-rw-r--r--lib/libucsi/atsc/dccsct_section.h327
-rw-r--r--lib/libucsi/atsc/dcct_section.c96
-rw-r--r--lib/libucsi/atsc/dcct_section.h380
-rw-r--r--lib/libucsi/atsc/descriptor.h68
-rw-r--r--lib/libucsi/atsc/eit_section.c71
-rw-r--r--lib/libucsi/atsc/eit_section.h191
-rw-r--r--lib/libucsi/atsc/ett_section.c42
-rw-r--r--lib/libucsi/atsc/ett_section.h91
-rw-r--r--lib/libucsi/atsc/extended_channel_name_descriptor.h92
-rw-r--r--lib/libucsi/atsc/genre_descriptor.h82
-rw-r--r--lib/libucsi/atsc/mgt_section.c76
-rw-r--r--lib/libucsi/atsc/mgt_section.h215
-rw-r--r--lib/libucsi/atsc/rc_descriptor.h83
-rw-r--r--lib/libucsi/atsc/rrt_section.c108
-rw-r--r--lib/libucsi/atsc/rrt_section.h379
-rw-r--r--lib/libucsi/atsc/section.h84
-rw-r--r--lib/libucsi/atsc/service_location_descriptor.h141
-rw-r--r--lib/libucsi/atsc/stt_section.c42
-rw-r--r--lib/libucsi/atsc/stt_section.h105
-rw-r--r--lib/libucsi/atsc/stuffing_descriptor.h82
-rw-r--r--lib/libucsi/atsc/time_shifted_service_descriptor.h136
-rw-r--r--lib/libucsi/atsc/tvct_section.c81
-rw-r--r--lib/libucsi/atsc/tvct_section.h227
-rw-r--r--lib/libucsi/atsc/types.c71
-rw-r--r--lib/libucsi/atsc/types.h227
-rw-r--r--lib/libucsi/crc32.c89
-rw-r--r--lib/libucsi/crc32.h58
-rw-r--r--lib/libucsi/descriptor.h129
-rw-r--r--lib/libucsi/dvb/Makefile121
-rw-r--r--lib/libucsi/dvb/ac3_descriptor.h88
-rw-r--r--lib/libucsi/dvb/adaptation_field_data_descriptor.h62
-rw-r--r--lib/libucsi/dvb/ait_application_descriptor.h204
-rw-r--r--lib/libucsi/dvb/ait_application_icons_descriptor.h157
-rw-r--r--lib/libucsi/dvb/ait_application_name_descriptor.h145
-rw-r--r--lib/libucsi/dvb/ait_external_application_authorisation_descriptor.h125
-rw-r--r--lib/libucsi/dvb/ancillary_data_descriptor.h67
-rw-r--r--lib/libucsi/dvb/announcement_support_descriptor.h219
-rw-r--r--lib/libucsi/dvb/application_signalling_descriptor.h124
-rw-r--r--lib/libucsi/dvb/bat_section.c77
-rw-r--r--lib/libucsi/dvb/bat_section.h211
-rw-r--r--lib/libucsi/dvb/bouquet_name_descriptor.h82
-rw-r--r--lib/libucsi/dvb/ca_identifier_descriptor.h94
-rw-r--r--lib/libucsi/dvb/cable_delivery_descriptor.h70
-rw-r--r--lib/libucsi/dvb/cell_frequency_link_descriptor.h190
-rw-r--r--lib/libucsi/dvb/cell_list_descriptor.h201
-rw-r--r--lib/libucsi/dvb/component_descriptor.h147
-rw-r--r--lib/libucsi/dvb/content_descriptor.h116
-rw-r--r--lib/libucsi/dvb/content_identifier_descriptor.h233
-rw-r--r--lib/libucsi/dvb/country_availability_descriptor.h120
-rw-r--r--lib/libucsi/dvb/data_broadcast_descriptor.h139
-rw-r--r--lib/libucsi/dvb/data_broadcast_id_descriptor.h221
-rw-r--r--lib/libucsi/dvb/default_authority_descriptor.h82
-rw-r--r--lib/libucsi/dvb/descriptor.h229
-rw-r--r--lib/libucsi/dvb/dit_section.c32
-rw-r--r--lib/libucsi/dvb/dit_section.h54
-rw-r--r--lib/libucsi/dvb/dsng_descriptor.h80
-rw-r--r--lib/libucsi/dvb/eit_section.c63
-rw-r--r--lib/libucsi/dvb/eit_section.h160
-rw-r--r--lib/libucsi/dvb/extended_event_descriptor.h232
-rw-r--r--lib/libucsi/dvb/frequency_list_descriptor.h107
-rw-r--r--lib/libucsi/dvb/int_section.c79
-rw-r--r--lib/libucsi/dvb/int_section.h245
-rw-r--r--lib/libucsi/dvb/ip_mac_platform_name_descriptor.h87
-rw-r--r--lib/libucsi/dvb/ip_mac_platform_provider_name_descriptor.h87
-rw-r--r--lib/libucsi/dvb/ip_mac_stream_location_descriptor.h73
-rw-r--r--lib/libucsi/dvb/linkage_descriptor.h480
-rw-r--r--lib/libucsi/dvb/local_time_offset_descriptor.h127
-rw-r--r--lib/libucsi/dvb/mhp_data_broadcast_id_descriptor.h110
-rw-r--r--lib/libucsi/dvb/mosaic_descriptor.h324
-rw-r--r--lib/libucsi/dvb/multilingual_bouquet_name_descriptor.h145
-rw-r--r--lib/libucsi/dvb/multilingual_component_descriptor.h149
-rw-r--r--lib/libucsi/dvb/multilingual_network_name_descriptor.h145
-rw-r--r--lib/libucsi/dvb/multilingual_service_name_descriptor.h197
-rw-r--r--lib/libucsi/dvb/network_name_descriptor.h82
-rw-r--r--lib/libucsi/dvb/nit_section.c78
-rw-r--r--lib/libucsi/dvb/nit_section.h207
-rw-r--r--lib/libucsi/dvb/nvod_reference_descriptor.h125
-rw-r--r--lib/libucsi/dvb/parental_rating_descriptor.h135
-rw-r--r--lib/libucsi/dvb/partial_transport_stream_descriptor.h68
-rw-r--r--lib/libucsi/dvb/pdc_descriptor.h64
-rw-r--r--lib/libucsi/dvb/private_data_specifier_descriptor.h63
-rw-r--r--lib/libucsi/dvb/related_content_descriptor.h56
-rw-r--r--lib/libucsi/dvb/rnt_rar_over_dvb_stream_descriptor.h110
-rw-r--r--lib/libucsi/dvb/rnt_rar_over_ip_descriptor.h87
-rw-r--r--lib/libucsi/dvb/rnt_rnt_scan_descriptor.h125
-rw-r--r--lib/libucsi/dvb/rst_section.c47
-rw-r--r--lib/libucsi/dvb/rst_section.h110
-rw-r--r--lib/libucsi/dvb/s2_satellite_delivery_descriptor.h116
-rw-r--r--lib/libucsi/dvb/satellite_delivery_descriptor.h73
-rw-r--r--lib/libucsi/dvb/scrambling_descriptor.h61
-rw-r--r--lib/libucsi/dvb/sdt_section.c60
-rw-r--r--lib/libucsi/dvb/sdt_section.h157
-rw-r--r--lib/libucsi/dvb/section.h107
-rw-r--r--lib/libucsi/dvb/service_availability_descriptor.h98
-rw-r--r--lib/libucsi/dvb/service_descriptor.h163
-rw-r--r--lib/libucsi/dvb/service_identifier_descriptor.h82
-rw-r--r--lib/libucsi/dvb/service_list_descriptor.h122
-rw-r--r--lib/libucsi/dvb/service_move_descriptor.h67
-rw-r--r--lib/libucsi/dvb/short_event_descriptor.h135
-rw-r--r--lib/libucsi/dvb/short_smoothing_buffer_descriptor.h87
-rw-r--r--lib/libucsi/dvb/sit_section.c69
-rw-r--r--lib/libucsi/dvb/sit_section.h173
-rw-r--r--lib/libucsi/dvb/st_section.c29
-rw-r--r--lib/libucsi/dvb/st_section.h77
-rw-r--r--lib/libucsi/dvb/stream_identifier_descriptor.h61
-rw-r--r--lib/libucsi/dvb/stuffing_descriptor.h82
-rw-r--r--lib/libucsi/dvb/subtitling_descriptor.h126
-rw-r--r--lib/libucsi/dvb/target_ip_address_descriptor.h116
-rw-r--r--lib/libucsi/dvb/target_ip_slash_descriptor.h116
-rw-r--r--lib/libucsi/dvb/target_ip_source_slash_descriptor.h118
-rw-r--r--lib/libucsi/dvb/target_ipv6_address_descriptor.h116
-rw-r--r--lib/libucsi/dvb/target_ipv6_slash_descriptor.h116
-rw-r--r--lib/libucsi/dvb/target_ipv6_source_slash_descriptor.h118
-rw-r--r--lib/libucsi/dvb/tdt_section.c33
-rw-r--r--lib/libucsi/dvb/tdt_section.h54
-rw-r--r--lib/libucsi/dvb/telephone_descriptor.h150
-rw-r--r--lib/libucsi/dvb/teletext_descriptor.h127
-rw-r--r--lib/libucsi/dvb/terrestrial_delivery_descriptor.h77
-rw-r--r--lib/libucsi/dvb/time_shifted_event_descriptor.h65
-rw-r--r--lib/libucsi/dvb/time_shifted_service_descriptor.h63
-rw-r--r--lib/libucsi/dvb/tot_section.c50
-rw-r--r--lib/libucsi/dvb/tot_section.h97
-rw-r--r--lib/libucsi/dvb/transport_stream_descriptor.h82
-rw-r--r--lib/libucsi/dvb/tva_container_section.c33
-rw-r--r--lib/libucsi/dvb/tva_container_section.h90
-rw-r--r--lib/libucsi/dvb/tva_id_descriptor.h124
-rw-r--r--lib/libucsi/dvb/types.c270
-rw-r--r--lib/libucsi/dvb/types.h127
-rw-r--r--lib/libucsi/dvb/vbi_data_descriptor.h186
-rw-r--r--lib/libucsi/dvb/vbi_teletext_descriptor.h116
-rw-r--r--lib/libucsi/endianops.h128
-rw-r--r--lib/libucsi/mpeg/Makefile65
-rw-r--r--lib/libucsi/mpeg/audio_stream_descriptor.h65
-rw-r--r--lib/libucsi/mpeg/ca_descriptor.h91
-rw-r--r--lib/libucsi/mpeg/cat_section.c34
-rw-r--r--lib/libucsi/mpeg/cat_section.h94
-rw-r--r--lib/libucsi/mpeg/content_labelling_descriptor.h356
-rw-r--r--lib/libucsi/mpeg/copyright_descriptor.h89
-rw-r--r--lib/libucsi/mpeg/data_stream_alignment_descriptor.h73
-rw-r--r--lib/libucsi/mpeg/descriptor.h102
-rw-r--r--lib/libucsi/mpeg/external_es_id_descriptor.h63
-rw-r--r--lib/libucsi/mpeg/fmc_descriptor.h122
-rw-r--r--lib/libucsi/mpeg/fmxbuffer_size_descriptor.h83
-rw-r--r--lib/libucsi/mpeg/hierarchy_descriptor.h83
-rw-r--r--lib/libucsi/mpeg/ibp_descriptor.h65
-rw-r--r--lib/libucsi/mpeg/iod_descriptor.h87
-rw-r--r--lib/libucsi/mpeg/iso_639_language_descriptor.h124
-rw-r--r--lib/libucsi/mpeg/maximum_bitrate_descriptor.h64
-rw-r--r--lib/libucsi/mpeg/metadata_descriptor.h472
-rw-r--r--lib/libucsi/mpeg/metadata_pointer_descriptor.h360
-rw-r--r--lib/libucsi/mpeg/metadata_section.c27
-rw-r--r--lib/libucsi/mpeg/metadata_section.h122
-rw-r--r--lib/libucsi/mpeg/metadata_std_descriptor.h72
-rw-r--r--lib/libucsi/mpeg/mpeg4_audio_descriptor.h61
-rw-r--r--lib/libucsi/mpeg/mpeg4_video_descriptor.h61
-rw-r--r--lib/libucsi/mpeg/multiplex_buffer_descriptor.h65
-rw-r--r--lib/libucsi/mpeg/multiplex_buffer_utilization_descriptor.h67
-rw-r--r--lib/libucsi/mpeg/muxcode_descriptor.h82
-rw-r--r--lib/libucsi/mpeg/odsmt_section.c80
-rw-r--r--lib/libucsi/mpeg/odsmt_section.h224
-rw-r--r--lib/libucsi/mpeg/pat_section.c46
-rw-r--r--lib/libucsi/mpeg/pat_section.h118
-rw-r--r--lib/libucsi/mpeg/pmt_section.c71
-rw-r--r--lib/libucsi/mpeg/pmt_section.h188
-rw-r--r--lib/libucsi/mpeg/private_data_indicator_descriptor.h63
-rw-r--r--lib/libucsi/mpeg/registration_descriptor.h91
-rw-r--r--lib/libucsi/mpeg/section.h58
-rw-r--r--lib/libucsi/mpeg/sl_descriptor.h63
-rw-r--r--lib/libucsi/mpeg/smoothing_buffer_descriptor.h66
-rw-r--r--lib/libucsi/mpeg/std_descriptor.h62
-rw-r--r--lib/libucsi/mpeg/system_clock_descriptor.h65
-rw-r--r--lib/libucsi/mpeg/target_background_grid_descriptor.h66
-rw-r--r--lib/libucsi/mpeg/tsdt_section.c34
-rw-r--r--lib/libucsi/mpeg/tsdt_section.h94
-rw-r--r--lib/libucsi/mpeg/types.h127
-rw-r--r--lib/libucsi/mpeg/video_stream_descriptor.h101
-rw-r--r--lib/libucsi/mpeg/video_window_descriptor.h64
-rw-r--r--lib/libucsi/section.h253
-rw-r--r--lib/libucsi/section_buf.c173
-rw-r--r--lib/libucsi/section_buf.h124
-rw-r--r--lib/libucsi/testrecord.txt146
-rw-r--r--lib/libucsi/transport_packet.c256
-rw-r--r--lib/libucsi/transport_packet.h195
-rw-r--r--lib/libucsi/types.h36
196 files changed, 24097 insertions, 0 deletions
diff --git a/lib/libucsi/Makefile b/lib/libucsi/Makefile
new file mode 100644
index 0000000..19ab268
--- /dev/null
+++ b/lib/libucsi/Makefile
@@ -0,0 +1,34 @@
+# Makefile for linuxtv.org dvb-apps/lib/libucsi
+
+includes = crc32.h \
+ descriptor.h \
+ endianops.h \
+ section.h \
+ section_buf.h \
+ transport_packet.h \
+ types.h
+
+objects = crc32.o \
+ section_buf.o \
+ transport_packet.o
+
+lib_name = libucsi
+
+CPPFLAGS += -I../../lib
+
+.PHONY: all
+
+all: library
+
+include atsc/Makefile
+include dvb/Makefile
+include mpeg/Makefile
+
+.PHONY: $(sub-install)
+
+install:: $(sub-install)
+
+$(sub-install):
+ $(MAKE) -C $@ install
+
+include ../../Make.rules
diff --git a/lib/libucsi/atsc/Makefile b/lib/libucsi/atsc/Makefile
new file mode 100644
index 0000000..c3d8e6b
--- /dev/null
+++ b/lib/libucsi/atsc/Makefile
@@ -0,0 +1,55 @@
+# Makefile for linuxtv.org dvb-apps/lib/libucsi/atsc
+
+.PHONY: sub-error-atsc
+
+sub-error-atsc:
+ $(error You can't use this makefile directly.)
+
+ifneq ($(lib_name),)
+
+objects += atsc/atsc_text.o \
+ atsc/cvct_section.o \
+ atsc/dccsct_section.o \
+ atsc/dcct_section.o \
+ atsc/eit_section.o \
+ atsc/ett_section.o \
+ atsc/mgt_section.o \
+ atsc/rrt_section.o \
+ atsc/stt_section.o \
+ atsc/tvct_section.o \
+ atsc/types.o
+
+sub-install += atsc
+
+else
+
+includes = ac3_descriptor.h \
+ caption_service_descriptor.h \
+ component_name_descriptor.h \
+ content_advisory_descriptor.h \
+ cvct_section.h \
+ dcc_arriving_request_descriptor.h \
+ dcc_departing_request_descriptor.h \
+ dccsct_section.h \
+ dcct_section.h \
+ descriptor.h \
+ eit_section.h \
+ ett_section.h \
+ extended_channel_name_descriptor.h \
+ genre_descriptor.h \
+ mgt_section.h \
+ rc_descriptor.h \
+ rrt_section.h \
+ section.h \
+ service_location_descriptor.h \
+ stt_section.h \
+ stuffing_descriptor.h \
+ time_shifted_service_descriptor.h \
+ tvct_section.h \
+ types.h
+
+include ../../../Make.rules
+
+lib_name = libucsi/atsc
+
+endif
diff --git a/lib/libucsi/atsc/ac3_descriptor.h b/lib/libucsi/atsc/ac3_descriptor.h
new file mode 100644
index 0000000..489695b
--- /dev/null
+++ b/lib/libucsi/atsc/ac3_descriptor.h
@@ -0,0 +1,112 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_atsc@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_AC3_DESCRIPTOR
+#define _UCSI_ATSC_AC3_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+enum atsc_ac3_channels {
+ ATSC_AC3_CHANNELS_1_PLUS_1 = 0x0,
+ ATSC_AC3_CHANNELS_1_0 = 0x1,
+ ATSC_AC3_CHANNELS_2_0 = 0x2,
+ ATSC_AC3_CHANNELS_3_0 = 0x3,
+ ATSC_AC3_CHANNELS_2_1 = 0x4,
+ ATSC_AC3_CHANNELS_3_1 = 0x5,
+ ATSC_AC3_CHANNELS_2_2 = 0x6,
+ ATSC_AC3_CHANNELS_3_2 = 0x7,
+ ATSC_AC3_CHANNELS_1 = 0x8,
+ ATSC_AC3_CHANNELS_LTEQ_2 = 0x9,
+ ATSC_AC3_CHANNELS_LTEQ_3 = 0xa,
+ ATSC_AC3_CHANNELS_LTEQ_4 = 0xb,
+ ATSC_AC3_CHANNELS_LTEQ_5 = 0xc,
+ ATSC_AC3_CHANNELS_LTEQ_6 = 0xd,
+};
+
+/**
+ * atsc_ac3_descriptor structure.
+ */
+struct atsc_ac3_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t sample_rate_code : 3; ,
+ uint8_t bsid : 5; );
+ EBIT2(uint8_t bit_rate_code : 6; ,
+ uint8_t surround_mode : 2; );
+ EBIT3(uint8_t bsmod : 3; ,
+ uint8_t num_channels : 4; ,
+ uint8_t full_svc : 1; );
+ /* uint8_t additional_info[] */
+} __ucsi_packed;
+
+/**
+ * Process an atsc_ac3_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return atsc_ac3_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_ac3_descriptor*
+ atsc_ac3_descriptor_codec(struct descriptor* d)
+{
+ int pos = 0;
+
+ if (d->len < (pos+4))
+ return NULL;
+ pos += 4;
+
+ return (struct atsc_ac3_descriptor*) d;
+}
+
+/**
+ * Retrieve pointer to additional_info field of a atsc_ac3_descriptor.
+ *
+ * @param d atsc_ac3_descriptor pointer.
+ * @return Pointer to additional_info field.
+ */
+static inline uint8_t *atsc_ac3_descriptor_additional_info(struct atsc_ac3_descriptor *d)
+{
+ int pos = sizeof(struct atsc_ac3_descriptor);
+
+ return ((uint8_t *) d) + pos;
+}
+
+/**
+ * Determine length of additional_info field of a atsc_ac3_descriptor.
+ *
+ * @param d atsc_ac3_descriptor pointer.
+ * @return Length of field in bytes.
+ */
+static inline int atsc_ac3_descriptor_additional_info_length(struct atsc_ac3_descriptor* d)
+{
+ return d->d.len - 3;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/atsc_text.c b/lib/libucsi/atsc/atsc_text.c
new file mode 100644
index 0000000..d79c83f
--- /dev/null
+++ b/lib/libucsi/atsc/atsc_text.c
@@ -0,0 +1,743 @@
+/*
+* section and descriptor parser
+*
+* Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* 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,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "libucsi/endianops.h"
+#include "libucsi/atsc/types.h"
+
+#define HUFFTREE_LITERAL_MASK 0x80
+#define HUFFSTRING_END 0x00
+#define HUFFSTRING_ESCAPE 0x1b
+
+#define DEST_ALLOC_DELTA 20
+
+struct hufftree_entry {
+ uint8_t left_idx;
+ uint8_t right_idx;
+} __ucsi_packed;
+
+struct huffbuff {
+ uint8_t *buf;
+ uint32_t buf_len;
+
+ uint32_t cur_byte;
+ uint8_t cur_bit;
+};
+
+
+static struct hufftree_entry program_description_hufftree[][128] = {
+ { {0x14, 0x15}, {0x9b, 0xd6}, {0xc9, 0xcf}, {0xd7, 0xc7}, {0x01, 0xa2},
+ {0xce, 0xcb}, {0x02, 0x03}, {0xc5, 0xcc}, {0xc6, 0xc8}, {0x04, 0xc4},
+ {0x05, 0xc2}, {0x06, 0xc3}, {0xd2, 0x07}, {0xd3, 0x08}, {0xca, 0xd4},
+ {0x09, 0xcd}, {0xd0, 0x0a}, {0xc1, 0x0b}, {0x0c, 0x0d}, {0x0e, 0x0f},
+ {0x10, 0x11}, {0x12, 0x13}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x38, 0x39}, {0xad, 0xaf}, {0xb7, 0xda}, {0xa8, 0xb3}, {0xb5, 0x01},
+ {0x02, 0x9b}, {0xb4, 0xf1}, {0xa2, 0xd5}, {0xd6, 0xd9}, {0x03, 0x04},
+ {0x05, 0xcf}, {0x06, 0xc9}, {0xf9, 0xea}, {0xeb, 0xf5}, {0xf6, 0x07},
+ {0x08, 0x09}, {0xb2, 0xc5}, {0xc6, 0xb1}, {0x0a, 0xee}, {0xcb, 0x0b},
+ {0xd4, 0x0c}, {0xc4, 0xc8}, {0xd2, 0x0d}, {0x0e, 0x0f}, {0xc7, 0xca},
+ {0xce, 0xd0}, {0xd7, 0x10}, {0xc2, 0x11}, {0xcc, 0xec}, {0xe5, 0xe7},
+ {0x12, 0xcd}, {0x13, 0x14}, {0xc3, 0x15}, {0x16, 0x17}, {0xed, 0x18},
+ {0x19, 0xf2}, {0x1a, 0xd3}, {0x1b, 0x1c}, {0xe4, 0x1d}, {0xc1, 0xe3},
+ {0x1e, 0xe9}, {0xf0, 0xe2}, {0xf7, 0x1f}, {0xf3, 0xe6}, {0x20, 0x21},
+ {0x22, 0xe8}, {0xef, 0x23}, {0x24, 0x25}, {0x26, 0x27}, {0x28, 0x29},
+ {0x2a, 0xf4}, {0x2b, 0x2c}, {0x2d, 0x2e}, {0x2f, 0xe1}, {0x30, 0x31},
+ {0x32, 0x33}, {0x34, 0x35}, {0x36, 0x37}, },
+ { {0x9b, 0x9b}, },
+ { {0x03, 0x04}, {0x80, 0xae}, {0xc8, 0xd4}, {0x01, 0x02}, {0x9b, 0xa0}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x02, 0xf3}, {0xa0, 0xf4}, {0x9b, 0x01}, },
+ { {0x9b, 0x9b}, },
+ { {0xac, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x01, 0xa0}, {0x9b, 0xa2}, },
+ { {0x07, 0x08}, {0xe2, 0xe4}, {0xe5, 0xe6}, {0xa0, 0xf2}, {0xe1, 0x01},
+ {0x02, 0xf3}, {0xe3, 0x03}, {0x04, 0x05}, {0x9b, 0x06}, },
+ { {0x04, 0x80}, {0xca, 0xd3}, {0xa2, 0x01}, {0x9b, 0x02}, {0x03, 0xa0}, },
+ { {0x9b, 0xa0}, },
+ { {0x03, 0x04}, {0x9b, 0xb7}, {0xf4, 0xa0}, {0xb0, 0xf3}, {0x01, 0x02}, },
+ { {0xb9, 0x02}, {0xb8, 0x9b}, {0xa0, 0x01}, },
+ { {0xae, 0x02}, {0xb6, 0x9b}, {0x01, 0xa0}, },
+ { {0xa0, 0x01}, {0x9b, 0xb0}, },
+ { {0xae, 0x01}, {0x9b, 0xa0}, },
+ { {0xae, 0x01}, {0xa0, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x01}, {0xac, 0xae}, },
+ { {0x9b, 0x9b}, },
+ { {0x02, 0x03}, {0x9b, 0xa0}, {0xb5, 0xb6}, {0xb8, 0x01}, },
+ { {0x9b, 0xa0}, },
+ { {0x9b, 0xa0}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0xa0}, },
+ { {0x9b, 0x9b}, },
+ { {0x08, 0x09}, {0xe6, 0xf5}, {0xf3, 0xf4}, {0x9b, 0xe4}, {0x01, 0xed},
+ {0x02, 0x03}, {0x04, 0xf2}, {0x05, 0x06}, {0xec, 0xee}, {0x07, 0xa0}, },
+ { {0x05, 0x06}, {0x9b, 0xec}, {0xf5, 0x01}, {0x02, 0xe1}, {0xef, 0xe5},
+ {0xe9, 0xf2}, {0x03, 0x04}, },
+ { {0x06, 0x07}, {0x9b, 0xe9}, {0xf9, 0xf2}, {0xf5, 0x01}, {0x02, 0x03},
+ {0xec, 0xef}, {0xe1, 0x04}, {0xe8, 0x05}, },
+ { {0x05, 0x06}, {0xf9, 0xf2}, {0xf5, 0x9b}, {0xe5, 0xef}, {0x01, 0x02},
+ {0xe9, 0xe1}, {0x03, 0x04}, },
+ { {0x06, 0x07}, {0xe1, 0xe9}, {0xee, 0xf6}, {0xe4, 0xec}, {0xf3, 0x01},
+ {0x02, 0xf2}, {0x03, 0x04}, {0x9b, 0x05}, },
+ { {0x02, 0x03}, {0xe5, 0xec}, {0x9b, 0xef}, {0x01, 0xf2}, },
+ { {0x05, 0x06}, {0xf5, 0xef}, {0x9b, 0xec}, {0xe9, 0x01}, {0xe1, 0xf2},
+ {0x02, 0xe5}, {0x03, 0x04}, },
+ { {0x03, 0x04}, {0x9b, 0xe5}, {0xe9, 0xf5}, {0xe1, 0x01}, {0xef, 0x02}, },
+ { {0x04, 0x05}, {0xa0, 0xc9}, {0xf3, 0x9b}, {0xae, 0xf2}, {0x01, 0x02},
+ {0x03, 0xee}, },
+ { {0xef, 0x05}, {0x9b, 0xae}, {0xe9, 0xe5}, {0x01, 0xf5}, {0x02, 0xe1},
+ {0x03, 0x04}, },
+ { {0xe5, 0x03}, {0xe1, 0xe9}, {0xf2, 0x9b}, {0x01, 0x02}, },
+ { {0x03, 0x04}, {0x9b, 0xe9}, {0xf5, 0x01}, {0xe5, 0x02}, {0xef, 0xe1}, },
+ { {0xe1, 0x05}, {0x9b, 0xe3}, {0xef, 0x01}, {0xf5, 0xe5}, {0x02, 0x03},
+ {0xe9, 0x04}, },
+ { {0xe5, 0x03}, {0x9b, 0xe9}, {0x01, 0xe1}, {0xef, 0x02}, },
+ { {0x03, 0x04}, {0xa7, 0xee}, {0xec, 0xf2}, {0xf3, 0x01}, {0x9b, 0x02}, },
+ { {0xe1, 0x06}, {0x9b, 0xe8}, {0xe9, 0x01}, {0xf2, 0xec}, {0x02, 0xef},
+ {0x03, 0xe5}, {0x04, 0x05}, },
+ { {0x9b, 0x9b}, },
+ { {0x03, 0x04}, {0x9b, 0xae}, {0x01, 0xe9}, {0x02, 0xe1}, {0xe5, 0xef}, },
+ { {0x09, 0x0a}, {0xf6, 0xf9}, {0x01, 0xae}, {0xe3, 0xe9}, {0xf5, 0x9b},
+ {0xe5, 0xef}, {0x02, 0x03}, {0xe1, 0x04}, {0xe8, 0x05}, {0x06, 0xf4},
+ {0x07, 0x08}, },
+ { {0xe8, 0x07}, {0xe5, 0xf7}, {0xd6, 0xe1}, {0x9b, 0xe9}, {0xf2, 0x01},
+ {0x02, 0x03}, {0x04, 0xef}, {0x05, 0x06}, },
+ { {0xae, 0x01}, {0x9b, 0xee}, },
+ { {0xe9, 0x02}, {0xe5, 0x9b}, {0xa0, 0x01}, },
+ { {0x03, 0x04}, {0x9b, 0xe8}, {0xe5, 0xe1}, {0xef, 0x01}, {0xe9, 0x02}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0xef}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x18, 0x19}, {0xe8, 0xef}, {0xf8, 0x9b}, {0xa7, 0xf7}, {0xfa, 0x01},
+ {0x02, 0x03}, {0x04, 0xe5}, {0xae, 0x05}, {0xe6, 0xe2}, {0x06, 0xf6},
+ {0xeb, 0xf5}, {0xe9, 0x07}, {0xf0, 0xf9}, {0xe7, 0x08}, {0x09, 0xe4},
+ {0x0a, 0xe3}, {0x0b, 0xed}, {0x0c, 0xf3}, {0x0d, 0x0e}, {0x0f, 0xec},
+ {0x10, 0xf4}, {0x11, 0x12}, {0xf2, 0xa0}, {0x13, 0x14}, {0x15, 0xee},
+ {0x16, 0x17}, },
+ { {0x0b, 0x0c}, {0xe4, 0xf3}, {0x9b, 0xae}, {0xe2, 0x01}, {0x02, 0x03},
+ {0xec, 0xa0}, {0x04, 0xe9}, {0xf2, 0xf5}, {0x05, 0xf9}, {0xe1, 0x06},
+ {0xef, 0x07}, {0xe5, 0x08}, {0x09, 0x0a}, },
+ { {0x0f, 0x10}, {0xf1, 0xae}, {0xc4, 0xf9}, {0xac, 0x01}, {0xe3, 0x02},
+ {0x9b, 0xf2}, {0x03, 0x04}, {0xa0, 0xec}, {0xf5, 0x05}, {0x06, 0xe9},
+ {0x07, 0xeb}, {0x08, 0xf4}, {0x09, 0xe5}, {0x0a, 0xef}, {0xe1, 0xe8},
+ {0x0b, 0x0c}, {0x0d, 0x0e}, },
+ { {0x13, 0x14}, {0xa7, 0xbb}, {0xe6, 0xed}, {0xf7, 0xe7}, {0xf6, 0x01},
+ {0x02, 0x9b}, {0xee, 0x03}, {0x04, 0xec}, {0x05, 0xf5}, {0x06, 0xac},
+ {0xe4, 0xf9}, {0xf2, 0x07}, {0x08, 0x09}, {0xae, 0x0a}, {0xef, 0x0b},
+ {0xe1, 0xf3}, {0x0c, 0xe9}, {0x0d, 0x0e}, {0x0f, 0x10}, {0xe5, 0x11},
+ {0x12, 0xa0}, },
+ { {0x1d, 0x1e}, {0xa9, 0xe8}, {0xf5, 0x9b}, {0x01, 0xad}, {0xbb, 0xeb},
+ {0xfa, 0x02}, {0xa7, 0xe6}, {0xe2, 0xe7}, {0x03, 0x04}, {0x05, 0x06},
+ {0xe9, 0xf8}, {0x07, 0xac}, {0xef, 0xf0}, {0x08, 0xed}, {0xf6, 0xf9},
+ {0x09, 0xf7}, {0x0a, 0x0b}, {0xae, 0x0c}, {0xe3, 0x0d}, {0xe5, 0xf4},
+ {0x0e, 0x0f}, {0xe4, 0x10}, {0xec, 0x11}, {0xe1, 0x12}, {0x13, 0x14},
+ {0x15, 0x16}, {0xee, 0xf3}, {0x17, 0x18}, {0xf2, 0xa0}, {0x19, 0x1a},
+ {0x1b, 0x1c}, },
+ { {0x09, 0x0a}, {0xae, 0x9b}, {0xec, 0x01}, {0xf5, 0x02}, {0xf4, 0xe6},
+ {0x03, 0xe1}, {0xe5, 0xe9}, {0x04, 0xf2}, {0xef, 0x05}, {0x06, 0x07},
+ {0xa0, 0x08}, },
+ { {0x0e, 0x0f}, {0xad, 0xe7}, {0x9b, 0xa7}, {0xf9, 0x01}, {0xec, 0x02},
+ {0xac, 0xf2}, {0x03, 0xae}, {0xf3, 0xf5}, {0x04, 0x05}, {0xef, 0x06},
+ {0x07, 0xe9}, {0xe1, 0x08}, {0x09, 0xe8}, {0x0a, 0x0b}, {0xe5, 0x0c},
+ {0xa0, 0x0d}, },
+ { {0x0d, 0x0e}, {0xa7, 0xac}, {0xf3, 0xad}, {0x01, 0x02}, {0x9b, 0xf9},
+ {0xf5, 0xae}, {0x03, 0xee}, {0x04, 0xf2}, {0x05, 0x06}, {0xf4, 0x07},
+ {0x08, 0x09}, {0xef, 0xe1}, {0xa0, 0x0a}, {0xe9, 0x0b}, {0x0c, 0xe5}, },
+ { {0x14, 0x15}, {0xac, 0xe2}, {0xf8, 0x9b}, {0xae, 0xfa}, {0x01, 0xeb},
+ {0x02, 0xa0}, {0x03, 0x04}, {0xf0, 0x05}, {0x06, 0xe6}, {0xf6, 0x07},
+ {0xe4, 0xed}, {0xe7, 0x08}, {0xe1, 0xef}, {0xf2, 0x09}, {0x0a, 0x0b},
+ {0xec, 0x0c}, {0xe5, 0xe3}, {0x0d, 0xf4}, {0x0e, 0xf3}, {0x0f, 0x10},
+ {0x11, 0xee}, {0x12, 0x13}, },
+ { {0x03, 0xef}, {0x9b, 0xe1}, {0xe5, 0xf5}, {0x01, 0x02}, },
+ { {0x08, 0x09}, {0xec, 0xf9}, {0xa7, 0xee}, {0x01, 0xac}, {0x9b, 0xae},
+ {0x02, 0x03}, {0x04, 0xf3}, {0x05, 0xe9}, {0x06, 0xa0}, {0x07, 0xe5}, },
+ { {0x16, 0x17}, {0xa7, 0xad}, {0xee, 0xe3}, {0xeb, 0xf2}, {0x9b, 0xe2},
+ {0x01, 0x02}, {0xf5, 0x03}, {0xf4, 0xac}, {0x04, 0x05}, {0xe6, 0xed},
+ {0xf6, 0x06}, {0xae, 0xf0}, {0x07, 0x08}, {0xf3, 0x09}, {0x0a, 0xe4},
+ {0x0b, 0x0c}, {0xf9, 0x0d}, {0xef, 0x0e}, {0xe1, 0x0f}, {0x10, 0xe9},
+ {0xec, 0x11}, {0xa0, 0xe5}, {0x12, 0x13}, {0x14, 0x15}, },
+ { {0x0c, 0x0d}, {0xa7, 0xbb}, {0x9b, 0x01}, {0xf9, 0xae}, {0xe2, 0x02},
+ {0xed, 0xf3}, {0x03, 0xf5}, {0xef, 0xf0}, {0x04, 0x05}, {0xe9, 0x06},
+ {0x07, 0x08}, {0x09, 0xa0}, {0xe1, 0xe5}, {0x0a, 0x0b}, },
+ { {0x19, 0x1a}, {0xad, 0xbb}, {0xe2, 0xea}, {0xed, 0xf2}, {0xfa, 0xe6},
+ {0xec, 0x01}, {0x02, 0x03}, {0x9b, 0xf5}, {0x04, 0xa7}, {0xf6, 0xf9},
+ {0x05, 0x06}, {0xeb, 0xef}, {0x07, 0x08}, {0x09, 0x0a}, {0xac, 0x0b},
+ {0x0c, 0xe3}, {0xae, 0x0d}, {0xee, 0xe9}, {0x0e, 0xe1}, {0x0f, 0xf3},
+ {0x10, 0x11}, {0xf4, 0x12}, {0xe7, 0xe5}, {0x13, 0x14}, {0xe4, 0x15},
+ {0x16, 0x17}, {0xa0, 0x18}, },
+ { {0x1a, 0x1b}, {0xc2, 0x9b}, {0xad, 0xac}, {0xf8, 0x01}, {0xae, 0x02},
+ {0x03, 0xe5}, {0xe7, 0xe8}, {0xf9, 0xe9}, {0xeb, 0x04}, {0xe3, 0xe1},
+ {0x05, 0xf6}, {0x06, 0xe4}, {0x07, 0xe2}, {0xf0, 0x08}, {0x09, 0xf3},
+ {0xf4, 0xf7}, {0xef, 0x0a}, {0x0b, 0x0c}, {0x0d, 0xec}, {0x0e, 0x0f},
+ {0x10, 0xf5}, {0xed, 0x11}, {0xe6, 0xa0}, {0x12, 0xf2}, {0x13, 0x14},
+ {0x15, 0xee}, {0x16, 0x17}, {0x18, 0x19}, },
+ { {0x0e, 0x0f}, {0xad, 0xed}, {0xf9, 0x9b}, {0xae, 0x01}, {0xf3, 0x02},
+ {0x03, 0xf5}, {0xf4, 0xf0}, {0x04, 0xef}, {0x05, 0xe9}, {0x06, 0xe8},
+ {0xa0, 0xe1}, {0xec, 0x07}, {0xf2, 0x08}, {0xe5, 0x09}, {0x0a, 0x0b},
+ {0x0c, 0x0d}, },
+ { {0x9b, 0xf5}, },
+ { {0x19, 0x1a}, {0xa9, 0xbb}, {0xf6, 0xe6}, {0x01, 0x9b}, {0xad, 0xe2},
+ {0xf0, 0x02}, {0xa7, 0x03}, {0x04, 0x05}, {0xf5, 0xe3}, {0xac, 0xe7},
+ {0xf2, 0x06}, {0xeb, 0x07}, {0xec, 0xed}, {0xee, 0xf9}, {0x08, 0xae},
+ {0x09, 0x0a}, {0xe4, 0x0b}, {0x0c, 0xf4}, {0x0d, 0xf3}, {0x0e, 0x0f},
+ {0x10, 0xe1}, {0xef, 0x11}, {0xe9, 0x12}, {0x13, 0xe5}, {0x14, 0xa0},
+ {0x15, 0x16}, {0x17, 0x18}, },
+ { {0xa0, 0x16}, {0xa2, 0xa7}, {0xe2, 0xeb}, {0xed, 0xee}, {0x9b, 0xf7},
+ {0x01, 0x02}, {0x03, 0xbb}, {0xf9, 0xf0}, {0x04, 0x05}, {0xec, 0x06},
+ {0x07, 0x08}, {0xf5, 0xe1}, {0x09, 0xac}, {0xe3, 0x0a}, {0xe8, 0x0b},
+ {0xe9, 0x0c}, {0xef, 0xf3}, {0xae, 0x0d}, {0x0e, 0xe5}, {0x0f, 0x10},
+ {0x11, 0xf4}, {0x12, 0x13}, {0x14, 0x15}, },
+ { {0x14, 0x15}, {0xbb, 0xe2}, {0xad, 0xed}, {0x01, 0x9b}, {0xa7, 0xe3},
+ {0xac, 0xec}, {0xee, 0x02}, {0xf7, 0x03}, {0x04, 0xf9}, {0x05, 0x06},
+ {0x07, 0x08}, {0xf4, 0xae}, {0xf5, 0x09}, {0x0a, 0xf2}, {0xe1, 0xf3},
+ {0x0b, 0x0c}, {0x0d, 0xe9}, {0x0e, 0x0f}, {0xef, 0xe5}, {0x10, 0xa0},
+ {0xe8, 0x11}, {0x12, 0x13}, },
+ { {0x11, 0x12}, {0xef, 0xf6}, {0x9b, 0xeb}, {0xf9, 0x01}, {0xa0, 0xe2},
+ {0x02, 0xe1}, {0x03, 0xed}, {0x04, 0xe3}, {0xe9, 0x05}, {0xe4, 0xe5},
+ {0xe7, 0x06}, {0xec, 0xf0}, {0x07, 0x08}, {0x09, 0x0a}, {0x0b, 0xf3},
+ {0x0c, 0xf4}, {0xee, 0x0d}, {0xf2, 0x0e}, {0x0f, 0x10}, },
+ { {0x05, 0xe5}, {0xf3, 0xf9}, {0x9b, 0x01}, {0xef, 0x02}, {0x03, 0xe1},
+ {0x04, 0xe9}, },
+ { {0x0a, 0x0b}, {0xae, 0x9b}, {0xec, 0xed}, {0x01, 0x02}, {0xf3, 0xee},
+ {0xf2, 0x03}, {0xe5, 0x04}, {0xe8, 0xa0}, {0xe1, 0x05}, {0xef, 0x06},
+ {0x07, 0x08}, {0xe9, 0x09}, },
+ { {0x05, 0x06}, {0xa0, 0xac}, {0xad, 0xf4}, {0xe9, 0x01}, {0x02, 0xe1},
+ {0xe5, 0x03}, {0x9b, 0x04}, },
+ { {0x11, 0xa0}, {0xbf, 0xe1}, {0xe2, 0xe6}, {0xed, 0xe4}, {0xe9, 0xf7},
+ {0xa7, 0x01}, {0x02, 0xbb}, {0x03, 0x04}, {0xec, 0x05}, {0x9b, 0xee},
+ {0x06, 0xef}, {0x07, 0xac}, {0xe5, 0xf3}, {0x08, 0x09}, {0x0a, 0xae},
+ {0x0b, 0x0c}, {0x0d, 0x0e}, {0x0f, 0x10}, },
+ { {0x06, 0x07}, {0xa0, 0xae}, {0xe1, 0xe5}, {0xec, 0xfa}, {0x9b, 0xef},
+ {0xe9, 0x01}, {0x02, 0x03}, {0x04, 0x05}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+};
+
+static struct hufftree_entry program_title_hufftree[][128] = {
+ { {0x1b, 0x1c}, {0xb4, 0xa4}, {0xb2, 0xb7}, {0xda, 0x01}, {0xd1, 0x02},
+ {0x03, 0x9b}, {0x04, 0xd5}, {0xd9, 0x05}, {0xcb, 0xd6}, {0x06, 0xcf},
+ {0x07, 0x08}, {0xca, 0x09}, {0xc9, 0xc5}, {0xc6, 0x0a}, {0xd2, 0xc4},
+ {0xc7, 0xcc}, {0xd0, 0xc8}, {0xd7, 0xce}, {0x0b, 0xc1}, {0x0c, 0xc2},
+ {0xcd, 0xc3}, {0x0d, 0x0e}, {0x0f, 0x10}, {0xd3, 0x11}, {0xd4, 0x12},
+ {0x13, 0x14}, {0x15, 0x16}, {0x17, 0x18}, {0x19, 0x1a}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x29, 0x2a}, {0xd8, 0xe5}, {0xb9, 0x01}, {0xa7, 0xb1}, {0xec, 0xd1},
+ {0x02, 0xad}, {0xb2, 0xda}, {0xe3, 0xb3}, {0x03, 0xe4}, {0xe6, 0x04},
+ {0x9b, 0xe2}, {0x05, 0x06}, {0x07, 0x08}, {0x09, 0xd5}, {0x0a, 0xd6},
+ {0x0b, 0xd9}, {0x0c, 0xa6}, {0xe9, 0xcb}, {0xc5, 0xcf}, {0x0d, 0x0e},
+ {0xca, 0xc9}, {0x0f, 0xc7}, {0x10, 0x11}, {0xe1, 0x12}, {0x13, 0xc6},
+ {0xd2, 0xc8}, {0xce, 0xc1}, {0xc4, 0xd0}, {0xcc, 0x14}, {0x15, 0xef},
+ {0xc2, 0xd7}, {0x16, 0xcd}, {0x17, 0xf4}, {0xd4, 0x18}, {0x19, 0x1a},
+ {0xc3, 0xd3}, {0x1b, 0x1c}, {0x1d, 0x1e}, {0x1f, 0x20}, {0x21, 0x22},
+ {0x23, 0x24}, {0x25, 0x26}, {0x27, 0x28}, },
+ { {0x01, 0x80}, {0xa0, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0xb1, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0xa0}, },
+ { {0x04, 0xf3}, {0xe4, 0xb9}, {0x01, 0xf4}, {0xa0, 0x9b}, {0x02, 0x03}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x01, 0x02}, {0x9b, 0xc1}, {0xc8, 0xd3}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0xa0}, },
+ { {0x07, 0x08}, {0xb1, 0xd2}, {0xd3, 0xd4}, {0xd5, 0xad}, {0xcd, 0xc1},
+ {0x01, 0x02}, {0x03, 0xa0}, {0x04, 0x9b}, {0x05, 0x06}, },
+ { {0xa0, 0x05}, {0xc9, 0xd7}, {0xd3, 0x01}, {0x02, 0x9b}, {0xae, 0x80},
+ {0x03, 0x04}, },
+ { {0x9b, 0x9b}, },
+ { {0x02, 0x03}, {0xad, 0x9b}, {0x01, 0x80}, {0xa0, 0xb0}, },
+ { {0x04, 0x05}, {0x80, 0x9b}, {0xb1, 0xb2}, {0xa0, 0xb0}, {0xb9, 0x01},
+ {0x02, 0x03}, },
+ { {0x02, 0x03}, {0xb1, 0xba}, {0x01, 0xb0}, {0x9b, 0x80}, },
+ { {0x80, 0x01}, {0xb0, 0x9b}, },
+ { {0x9b, 0xb8}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0xb0}, },
+ { {0x9b, 0xa0}, },
+ { {0x02, 0x03}, {0xb1, 0xb3}, {0xb9, 0xb0}, {0x01, 0x9b}, },
+ { {0x9b, 0xa0}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x80}, },
+ { {0x9b, 0x9b}, },
+ { {0x13, 0x14}, {0xaa, 0xad}, {0xae, 0xf6}, {0xe7, 0xf4}, {0xe2, 0xe9},
+ {0x01, 0x02}, {0xc2, 0xf0}, {0x9b, 0xf3}, {0xe3, 0xe6}, {0xf7, 0x03},
+ {0xf5, 0x04}, {0x05, 0x06}, {0xf2, 0x07}, {0x08, 0x09}, {0x0a, 0x0b},
+ {0x0c, 0xe4}, {0xa0, 0x0d}, {0xec, 0xee}, {0x0e, 0xed}, {0x0f, 0x10},
+ {0x11, 0x12}, },
+ { {0x08, 0x09}, {0xc1, 0xd3}, {0x9b, 0x01}, {0xc3, 0x02}, {0xe9, 0xec},
+ {0x03, 0xf2}, {0xf5, 0x04}, {0xef, 0xe1}, {0x05, 0xe5}, {0x06, 0x07}, },
+ { {0x0b, 0x0c}, {0xc1, 0xf9}, {0x01, 0xc2}, {0xcf, 0xe5}, {0xf5, 0x9b},
+ {0xe9, 0x02}, {0xa0, 0x03}, {0x04, 0x05}, {0xf2, 0x06}, {0xec, 0x07},
+ {0xe1, 0x08}, {0x09, 0xe8}, {0x0a, 0xef}, },
+ { {0x05, 0x06}, {0xf9, 0x9b}, {0x01, 0xf5}, {0x02, 0xf2}, {0xe9, 0xe5},
+ {0xef, 0x03}, {0xe1, 0x04}, },
+ { {0x0a, 0x0b}, {0xf1, 0xf5}, {0xf3, 0x01}, {0xed, 0xf9}, {0xc3, 0x02},
+ {0xec, 0xee}, {0xe4, 0xf8}, {0x03, 0x9b}, {0xf6, 0x04}, {0x05, 0xe1},
+ {0x06, 0x07}, {0x08, 0x09}, },
+ { {0x07, 0x08}, {0xa0, 0x9b}, {0xcc, 0x01}, {0xe5, 0x02}, {0xec, 0xf5},
+ {0xef, 0x03}, {0xe9, 0xf2}, {0x04, 0x05}, {0xe1, 0x06}, },
+ { {0x09, 0x0a}, {0xae, 0xec}, {0xf9, 0xc1}, {0xe8, 0x01}, {0x9b, 0x02},
+ {0x03, 0x04}, {0xe1, 0xf5}, {0xe9, 0x05}, {0xe5, 0x06}, {0xf2, 0xef},
+ {0x07, 0x08}, },
+ { {0xef, 0x05}, {0x80, 0x9b}, {0xf5, 0x01}, {0x02, 0xe9}, {0xe1, 0x03},
+ {0xe5, 0x04}, },
+ { {0xee, 0x0b}, {0xba, 0xd4}, {0xae, 0xf2}, {0xe3, 0x01}, {0xa0, 0x02},
+ {0x80, 0x9b}, {0xed, 0x03}, {0xc9, 0xf3}, {0xf4, 0x04}, {0x05, 0x06},
+ {0x07, 0x08}, {0x09, 0x0a}, },
+ { {0x02, 0x03}, {0x9b, 0xf5}, {0x01, 0xe1}, {0xef, 0xe5}, },
+ { {0x05, 0xe9}, {0xe1, 0xef}, {0xf5, 0xee}, {0x9b, 0xe5}, {0x01, 0x02},
+ {0x03, 0x04}, },
+ { {0x04, 0x05}, {0xa0, 0x9b}, {0x01, 0xf5}, {0x02, 0xe5}, {0xef, 0x03},
+ {0xe1, 0xe9}, },
+ { {0x08, 0x09}, {0xaa, 0xd4}, {0x01, 0x9b}, {0xe3, 0x02}, {0xf2, 0x03},
+ {0xe5, 0x04}, {0xf5, 0xf9}, {0xe9, 0x05}, {0xef, 0x06}, {0x07, 0xe1}, },
+ { {0xe5, 0x08}, {0xce, 0xa0}, {0xc6, 0xf5}, {0x01, 0x02}, {0x9b, 0xc2},
+ {0x03, 0xe1}, {0x04, 0xef}, {0x05, 0xe9}, {0x06, 0x07}, },
+ { {0x09, 0x0a}, {0xe4, 0xf3}, {0xe6, 0xf6}, {0xf7, 0xf0}, {0xf2, 0x01},
+ {0xec, 0x02}, {0x03, 0xa0}, {0x9b, 0x04}, {0x05, 0xf5}, {0x06, 0x07},
+ {0xee, 0x08}, },
+ { {0x0b, 0x0c}, {0xa0, 0xf3}, {0xf9, 0xae}, {0xd2, 0xc7}, {0x01, 0x9b},
+ {0x02, 0xf5}, {0x03, 0x04}, {0x05, 0xe9}, {0xec, 0x06}, {0xe5, 0x07},
+ {0xef, 0x08}, {0xe1, 0x09}, {0xf2, 0x0a}, },
+ { {0x01, 0xf5}, {0x9b, 0xd6}, },
+ { {0x04, 0x05}, {0xe8, 0x9b}, {0x01, 0xf5}, {0x02, 0xe1}, {0xe9, 0xef},
+ {0x03, 0xe5}, },
+ { {0x10, 0x11}, {0xaa, 0xec}, {0xf1, 0xae}, {0xa0, 0xf7}, {0xed, 0xee},
+ {0x01, 0x02}, {0x9b, 0xeb}, {0x03, 0x04}, {0x05, 0x06}, {0xe3, 0x07},
+ {0xef, 0x08}, {0xe9, 0xf5}, {0x09, 0xe1}, {0xe5, 0xf0}, {0xe8, 0x0a},
+ {0x0b, 0x0c}, {0x0d, 0xf4}, {0x0e, 0x0f}, },
+ { {0xe8, 0x0a}, {0xad, 0xce}, {0x9b, 0x01}, {0xd6, 0x02}, {0xf5, 0xf7},
+ {0x03, 0x04}, {0xe1, 0xe5}, {0xe9, 0x05}, {0xf2, 0x06}, {0xef, 0x07},
+ {0x08, 0x09}, },
+ { {0xee, 0x03}, {0xec, 0xae}, {0x01, 0x9b}, {0x02, 0xf0}, },
+ { {0x06, 0xe9}, {0xa0, 0xc3}, {0xef, 0x9b}, {0xe5, 0x01}, {0x80, 0x02},
+ {0x03, 0xe1}, {0x04, 0x05}, },
+ { {0x06, 0x07}, {0xc6, 0xd7}, {0x01, 0x9b}, {0xf2, 0x02}, {0x03, 0xe8},
+ {0xe5, 0xe1}, {0x04, 0xe9}, {0xef, 0x05}, },
+ { {0x9b, 0x9b}, },
+ { {0x02, 0xef}, {0xe1, 0x9b}, {0x01, 0xe5}, },
+ { {0x01, 0xef}, {0x9b, 0xe1}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x19, 0x1a}, {0x9b, 0xba}, {0xe5, 0xea}, {0xf8, 0x01}, {0x02, 0xe6},
+ {0xa7, 0x03}, {0xfa, 0xe8}, {0x04, 0xf7}, {0x05, 0xf5}, {0xe2, 0x06},
+ {0xeb, 0x07}, {0xf0, 0x08}, {0x80, 0xf6}, {0xe7, 0x09}, {0xe4, 0x0a},
+ {0xa0, 0xe9}, {0x0b, 0xe3}, {0xf9, 0x0c}, {0x0d, 0xed}, {0x0e, 0x0f},
+ {0xf3, 0x10}, {0x11, 0xec}, {0x12, 0xf4}, {0xf2, 0x13}, {0xee, 0x14},
+ {0x15, 0x16}, {0x17, 0x18}, },
+ { {0x0a, 0x0b}, {0xf3, 0x9b}, {0xf5, 0xe2}, {0x01, 0x80}, {0xa0, 0x02},
+ {0xe5, 0xf2}, {0xe9, 0x03}, {0xec, 0x04}, {0xf9, 0x05}, {0xef, 0x06},
+ {0xe1, 0x07}, {0x08, 0x09}, },
+ { {0x10, 0x11}, {0xc3, 0xcc}, {0xc7, 0x9b}, {0xe3, 0x01}, {0x80, 0xec},
+ {0xf9, 0x02}, {0xf3, 0x03}, {0xf5, 0x04}, {0x05, 0xf2}, {0x06, 0xe9},
+ {0xa0, 0x07}, {0x08, 0xef}, {0xf4, 0x09}, {0x0a, 0xe1}, {0x0b, 0xe8},
+ {0xeb, 0xe5}, {0x0c, 0x0d}, {0x0e, 0x0f}, },
+ { {0x0e, 0x0f}, {0xae, 0xf5}, {0xf7, 0x01}, {0xec, 0x02}, {0xe4, 0xe7},
+ {0xf2, 0x03}, {0x9b, 0xef}, {0x04, 0xf6}, {0x05, 0x06}, {0xf9, 0xf3},
+ {0x07, 0xe9}, {0xe1, 0x08}, {0x09, 0x80}, {0x0a, 0x0b}, {0xe5, 0x0c},
+ {0x0d, 0xa0}, },
+ { {0x1e, 0x1f}, {0x9b, 0xa1}, {0xad, 0xe8}, {0xea, 0xf1}, {0xf5, 0xfa},
+ {0x01, 0x02}, {0x03, 0x04}, {0xba, 0xf8}, {0xa7, 0xe2}, {0xe9, 0x05},
+ {0x06, 0x07}, {0xe6, 0xed}, {0xe7, 0xeb}, {0x08, 0x09}, {0xf6, 0xf0},
+ {0x0a, 0xef}, {0x0b, 0xe3}, {0x0c, 0x0d}, {0x0e, 0xf9}, {0x0f, 0xe4},
+ {0xec, 0x10}, {0xe5, 0x11}, {0xf4, 0xf7}, {0x12, 0x13}, {0xe1, 0x14},
+ {0x15, 0x16}, {0xee, 0xf3}, {0x17, 0x80}, {0x18, 0x19}, {0xf2, 0x1a},
+ {0x1b, 0xa0}, {0x1c, 0x1d}, },
+ { {0xa0, 0x0b}, {0xf5, 0x9b}, {0x01, 0xec}, {0xf3, 0xf2}, {0x80, 0xe1},
+ {0x02, 0x03}, {0xf4, 0xe9}, {0xef, 0xe6}, {0x04, 0x05}, {0x06, 0x07},
+ {0xe5, 0x08}, {0x09, 0x0a}, },
+ { {0x0f, 0x10}, {0xba, 0xf9}, {0xa7, 0xf4}, {0x9b, 0x01}, {0xe7, 0xec},
+ {0x02, 0xee}, {0x03, 0xef}, {0xf5, 0x04}, {0xf2, 0x05}, {0x06, 0xe9},
+ {0x07, 0xf3}, {0xe1, 0x08}, {0x09, 0x0a}, {0x0b, 0xe5}, {0x80, 0x0c},
+ {0xe8, 0xa0}, {0x0d, 0x0e}, },
+ { {0xe5, 0x0d}, {0xe2, 0xf5}, {0xf7, 0x9b}, {0xec, 0x01}, {0xf9, 0xee},
+ {0x02, 0x03}, {0x04, 0xf2}, {0x05, 0x80}, {0x06, 0xa0}, {0xe1, 0xef},
+ {0x07, 0xf4}, {0xe9, 0x08}, {0x09, 0x0a}, {0x0b, 0x0c}, },
+ { {0x15, 0x16}, {0xa1, 0xf8}, {0xe9, 0xeb}, {0x01, 0x80}, {0x9b, 0xfa},
+ {0xe2, 0x02}, {0x03, 0x04}, {0xa0, 0xf0}, {0x05, 0x06}, {0x07, 0xe1},
+ {0x08, 0xe6}, {0xf2, 0xed}, {0xf6, 0x09}, {0xe4, 0x0a}, {0xef, 0xf4},
+ {0xec, 0xf3}, {0xe7, 0xe5}, {0x0b, 0xe3}, {0x0c, 0x0d}, {0x0e, 0x0f},
+ {0x10, 0x11}, {0x12, 0x13}, {0xee, 0x14}, },
+ { {0xef, 0x01}, {0x9b, 0xe1}, },
+ { {0x0b, 0x0c}, {0xd4, 0xef}, {0xe6, 0xec}, {0xf7, 0xe1}, {0x01, 0xba},
+ {0x02, 0x9b}, {0xf9, 0x03}, {0x04, 0x05}, {0xf3, 0x06}, {0x07, 0x08},
+ {0xe9, 0xa0}, {0x09, 0x80}, {0xe5, 0x0a}, },
+ { {0x15, 0x16}, {0xa7, 0xba}, {0xe3, 0xf7}, {0xf2, 0xad}, {0xe2, 0x01},
+ {0x02, 0x9b}, {0xe6, 0x03}, {0xed, 0xf6}, {0x04, 0xeb}, {0x05, 0xf4},
+ {0x06, 0x07}, {0x08, 0xf3}, {0x09, 0xf5}, {0x0a, 0xef}, {0x0b, 0x0c},
+ {0x80, 0xf9}, {0xe1, 0x0d}, {0xe4, 0xe9}, {0xa0, 0x0e}, {0x0f, 0xec},
+ {0xe5, 0x10}, {0x11, 0x12}, {0x13, 0x14}, },
+ { {0x0a, 0x0b}, {0xf9, 0x9b}, {0xf5, 0xf3}, {0x01, 0x02}, {0xe2, 0xed},
+ {0x80, 0x03}, {0xf0, 0xef}, {0x04, 0xa0}, {0x05, 0xe9}, {0x06, 0xe1},
+ {0x07, 0x08}, {0x09, 0xe5}, },
+ { {0x18, 0x19}, {0xe2, 0xea}, {0xf2, 0xe8}, {0xec, 0xed}, {0xfa, 0x9b},
+ {0x01, 0xf5}, {0x02, 0x03}, {0xf6, 0x04}, {0xba, 0xe6}, {0x05, 0x06},
+ {0xeb, 0xef}, {0x07, 0xa7}, {0xf9, 0x08}, {0x09, 0x0a}, {0x0b, 0xe3},
+ {0x0c, 0xee}, {0xe1, 0x0d}, {0xf3, 0x0e}, {0xe9, 0x0f}, {0x10, 0xf4},
+ {0x80, 0xe4}, {0xe5, 0x11}, {0x12, 0xe7}, {0xa0, 0x13}, {0x14, 0x15},
+ {0x16, 0x17}, },
+ { {0x1b, 0x1c}, {0xae, 0xfa}, {0xbf, 0x01}, {0xa7, 0x9b}, {0x02, 0xe9},
+ {0xf8, 0xf9}, {0x03, 0xe5}, {0xe8, 0x04}, {0xe1, 0xeb}, {0x05, 0xe2},
+ {0x06, 0x07}, {0xe3, 0x08}, {0xe7, 0xf4}, {0x09, 0x80}, {0xf6, 0xf0},
+ {0x0a, 0xe4}, {0x0b, 0xf3}, {0xf7, 0x0c}, {0x0d, 0xef}, {0xec, 0xa0},
+ {0x0e, 0x0f}, {0xed, 0xe6}, {0x10, 0xf5}, {0x11, 0x12}, {0x13, 0x14},
+ {0x15, 0xf2}, {0x16, 0xee}, {0x17, 0x18}, {0x19, 0x1a}, },
+ { {0x0e, 0x0f}, {0xed, 0xa7}, {0x9b, 0xe4}, {0x01, 0xf9}, {0xf3, 0xf2},
+ {0xf4, 0x02}, {0xe8, 0x03}, {0xec, 0xf0}, {0x04, 0xe1}, {0xe9, 0x05},
+ {0x06, 0x80}, {0xa0, 0x07}, {0x08, 0x09}, {0x0a, 0xe5}, {0xef, 0x0b},
+ {0x0c, 0x0d}, },
+ { {0x9b, 0xf5}, },
+ { {0x18, 0x19}, {0xba, 0xac}, {0xf6, 0x9b}, {0xf0, 0xe2}, {0x01, 0xe6},
+ {0x02, 0xa7}, {0xae, 0xe7}, {0x03, 0xe3}, {0xf5, 0x04}, {0xed, 0x05},
+ {0x06, 0x07}, {0xeb, 0x08}, {0x09, 0xee}, {0xf2, 0x0a}, {0xe4, 0x0b},
+ {0xf9, 0xec}, {0x0c, 0x0d}, {0xf4, 0x80}, {0x0e, 0xef}, {0xf3, 0xa0},
+ {0xe1, 0x0f}, {0xe9, 0x10}, {0x11, 0xe5}, {0x12, 0x13}, {0x14, 0x15},
+ {0x16, 0x17}, },
+ { {0x19, 0x1a}, {0xa7, 0xac}, {0xbf, 0xc3}, {0xc8, 0xe4}, {0xe6, 0xed},
+ {0xf2, 0xae}, {0xec, 0xee}, {0xf9, 0x01}, {0x02, 0x03}, {0x04, 0xba},
+ {0x05, 0x9b}, {0xf5, 0x06}, {0x07, 0x08}, {0x09, 0xeb}, {0xf0, 0x0a},
+ {0x0b, 0x0c}, {0xe1, 0xe3}, {0x0d, 0xe8}, {0x0e, 0x0f}, {0xef, 0x10},
+ {0x11, 0xf3}, {0x12, 0xe9}, {0x13, 0xe5}, {0x14, 0x15}, {0xf4, 0x16},
+ {0x17, 0xa0}, {0x18, 0x80}, },
+ { {0x14, 0x15}, {0xba, 0xbf}, {0xe4, 0xf7}, {0x9b, 0xa7}, {0x01, 0xee},
+ {0x02, 0x03}, {0x04, 0xe3}, {0xe2, 0xed}, {0x05, 0xf9}, {0x06, 0xf4},
+ {0x07, 0xec}, {0x08, 0xf5}, {0xf2, 0x09}, {0xe1, 0xf3}, {0x0a, 0xef},
+ {0x0b, 0x0c}, {0x0d, 0xe9}, {0x80, 0xe5}, {0x0e, 0xa0}, {0x0f, 0xe8},
+ {0x10, 0x11}, {0x12, 0x13}, },
+ { {0x11, 0x12}, {0xeb, 0xfa}, {0x80, 0xe6}, {0x9b, 0x01}, {0xa0, 0x02},
+ {0x03, 0xe9}, {0xe1, 0x04}, {0xe4, 0xf0}, {0xed, 0xe2}, {0xe3, 0xe7},
+ {0xec, 0x05}, {0xe5, 0x06}, {0x07, 0x08}, {0x09, 0xf4}, {0x0a, 0x0b},
+ {0x0c, 0xf3}, {0xee, 0x0d}, {0x0e, 0xf2}, {0x0f, 0x10}, },
+ { {0x04, 0xe5}, {0xf3, 0xef}, {0x9b, 0x01}, {0xe1, 0x02}, {0x03, 0xe9}, },
+ { {0x0b, 0x0c}, {0xa7, 0xe2}, {0xec, 0xe3}, {0xf2, 0x01}, {0x9b, 0x02},
+ {0x03, 0x04}, {0xe9, 0xef}, {0xee, 0xe5}, {0xe1, 0x80}, {0x05, 0xa0},
+ {0x06, 0x07}, {0x08, 0x09}, {0xf3, 0x0a}, },
+ { {0x05, 0x06}, {0x9b, 0xa0}, {0xe1, 0xe5}, {0xe9, 0x01}, {0x80, 0xf0},
+ {0x02, 0xf4}, {0x03, 0x04}, },
+ { {0xa0, 0x13}, {0xe3, 0xad}, {0xe4, 0xe9}, {0xee, 0xef}, {0xf0, 0xf4},
+ {0xf6, 0xa1}, {0xe1, 0xed}, {0x01, 0xe2}, {0x02, 0x03}, {0x04, 0xa7},
+ {0x05, 0x06}, {0xf7, 0x07}, {0x9b, 0xec}, {0x08, 0xe5}, {0x09, 0x0a},
+ {0x0b, 0x0c}, {0x0d, 0x0e}, {0xf3, 0x0f}, {0x10, 0x11}, {0x80, 0x12}, },
+ { {0x05, 0x06}, {0xe5, 0xfa}, {0xa0, 0xf9}, {0x9b, 0x01}, {0x80, 0xe9},
+ {0x02, 0xe1}, {0x03, 0x04}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+ { {0x9b, 0x9b}, },
+};
+
+
+
+static inline void huffbuff_init(struct huffbuff *hbuf, uint8_t *buf, uint32_t buf_len)
+{
+ memset(hbuf, 0, sizeof(struct huffbuff));
+ hbuf->buf = buf;
+ hbuf->buf_len = buf_len;
+}
+
+static inline int huffbuff_bits(struct huffbuff *hbuf, uint8_t nbits)
+{
+ uint8_t result = 0;
+
+ if (nbits > 8)
+ return -1;
+
+ while(nbits--) {
+ if (hbuf->cur_byte >= hbuf->buf_len) {
+ return -1;
+ }
+
+ result <<= 1;
+ if (hbuf->buf[hbuf->cur_byte] & (0x80 >> hbuf->cur_bit))
+ result |= 1;
+
+ if (++hbuf->cur_bit > 7) {
+ hbuf->cur_byte++;
+ hbuf->cur_bit = 0;
+ }
+ }
+
+ return result;
+}
+
+static inline int append_unicode_char(uint8_t **destbuf, size_t *destbuflen, size_t *destbufpos,
+ uint32_t c)
+{
+ uint8_t tmp[3];
+ int tmplen = 0;
+
+ // encode the unicode character first of all
+ if (c < 0x80) {
+ tmp[0] = c;
+ tmplen = 1;
+ } else if (c < 0x800) {
+ tmp[0] = 0xc0 | ((c >> 6) & 0x1f);
+ tmp[1] = 0x80 | (c & 0x3f);
+ tmplen = 2;
+ } else if (c < 0x10000) {
+ tmp[0] = 0xe0 | ((c >> 12) & 0x0f);
+ tmp[1] = 0x80 | ((c >> 6) & 0x3f);
+ tmp[2] = 0x80 | (c & 0x3f);
+ tmplen = 3;
+ } else {
+ return -1;
+ }
+
+ // do we have enough buffer space?
+ if ((*destbufpos + tmplen) >= *destbuflen) {
+ uint8_t *new_dest = realloc(*destbuf, *destbuflen + DEST_ALLOC_DELTA);
+ if (new_dest == NULL)
+ return -ENOMEM;
+ *destbuf = new_dest;
+ *destbuflen += DEST_ALLOC_DELTA;
+ }
+
+ // copy it into position
+ memcpy(*destbuf + *destbufpos, tmp, tmplen);
+ *destbufpos += tmplen;
+
+ return 0;
+}
+
+static inline int unicode_decode(uint8_t *srcbuf, size_t srcbuflen, int mode,
+ uint8_t **destbuf, size_t *destbuflen, size_t *destbufpos)
+{
+ size_t i;
+ uint32_t msb = mode << 8;
+
+ for(i=0; i< srcbuflen; i++) {
+ if (append_unicode_char(destbuf, destbuflen, destbufpos, msb + srcbuf[i]))
+ return -1;
+ }
+
+ return *destbufpos;
+}
+
+static int huffman_decode_uncompressed(struct huffbuff *hbuf,
+ uint8_t **destbuf, size_t *destbuflen, size_t *destbufpos)
+{
+ int c;
+
+ while(hbuf->cur_byte < hbuf->buf_len) {
+ // get next byte
+ if ((c = huffbuff_bits(hbuf, 8)) < 0)
+ return -1;
+
+ switch(c) {
+ case HUFFSTRING_END:
+ return 0;
+
+ case HUFFSTRING_ESCAPE:
+ return HUFFSTRING_ESCAPE;
+
+ default:
+ if (append_unicode_char(destbuf, destbuflen, destbufpos, c))
+ return -1;
+
+ // if it is 7 bit, we swap back to the compressed context
+ if ((c & 0x80) == 0)
+ return c;
+
+ // characters following an 8 bit uncompressed char are uncompressed as well
+ break;
+ }
+ }
+
+ // ran out of string; pretend we saw an end of string char
+ return HUFFSTRING_END;
+}
+
+static int huffman_decode(uint8_t *src, size_t srclen,
+ uint8_t **destbuf, size_t *destbuflen, size_t *destbufpos,
+ struct hufftree_entry hufftree[][128])
+{
+ struct huffbuff hbuf;
+ int bit;
+ struct hufftree_entry *tree = hufftree[0];
+ uint8_t treeidx = 0;
+ uint8_t treeval;
+ int tmp;
+
+ huffbuff_init(&hbuf, src, srclen);
+
+ while(hbuf.cur_byte < hbuf.buf_len) {
+ // get the next bit
+ if ((bit = huffbuff_bits(&hbuf, 1)) < 0)
+ return *destbufpos;
+
+ if (!bit) {
+ treeval = tree[treeidx].left_idx;
+ } else {
+ treeval = tree[treeidx].right_idx;
+ }
+
+ if (treeval & HUFFTREE_LITERAL_MASK) {
+ switch(treeval & ~HUFFTREE_LITERAL_MASK) {
+ case HUFFSTRING_END:
+ return 0;
+
+ case HUFFSTRING_ESCAPE:
+ if ((tmp =
+ huffman_decode_uncompressed(&hbuf,
+ destbuf, destbuflen, destbufpos)) < 0)
+ return tmp;
+ if (tmp == 0)
+ return *destbufpos;
+
+ tree = hufftree[tmp];
+ treeidx = 0;
+ break;
+
+ default:
+ // stash it
+ if (append_unicode_char(destbuf, destbuflen, destbufpos,
+ treeval & ~HUFFTREE_LITERAL_MASK))
+ return -1;
+ tree = hufftree[treeval & ~HUFFTREE_LITERAL_MASK];
+ treeidx = 0;
+ break;
+ }
+ } else {
+ treeidx = treeval;
+ }
+ }
+
+ return *destbufpos;
+}
+
+int atsc_text_segment_decode(struct atsc_text_string_segment *segment,
+ uint8_t **destbuf, size_t *destbufsize, size_t *destbufpos)
+{
+ if (segment->mode > ATSC_TEXT_SEGMENT_MODE_UNICODE_RANGE_MAX)
+ return -1;
+
+ // mode==0 MUST be used for compressed text
+ if ((segment->mode) && (segment->compression_type))
+ return -1;
+
+ uint8_t *buf = atsc_text_string_segment_bytes(segment);
+
+ switch(segment->compression_type) {
+ case ATSC_TEXT_COMPRESS_NONE:
+ return unicode_decode(buf, segment->number_bytes, segment->mode,
+ destbuf, destbufsize, destbufpos);
+
+ case ATSC_TEXT_COMPRESS_PROGRAM_TITLE:
+ return huffman_decode(buf, segment->number_bytes,
+ destbuf, destbufsize, destbufpos,
+ program_title_hufftree);
+
+ case ATSC_TEXT_COMPRESS_PROGRAM_DESCRIPTION:
+ return huffman_decode(buf, segment->number_bytes,
+ destbuf, destbufsize, destbufpos,
+ program_description_hufftree);
+ }
+
+ return -1;
+}
diff --git a/lib/libucsi/atsc/caption_service_descriptor.h b/lib/libucsi/atsc/caption_service_descriptor.h
new file mode 100644
index 0000000..29d1794
--- /dev/null
+++ b/lib/libucsi/atsc/caption_service_descriptor.h
@@ -0,0 +1,137 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_CAPTION_SERVICE_DESCRIPTOR
+#define _UCSI_ATSC_CAPTION_SERVICE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * atsc_caption_service_descriptor structure.
+ */
+struct atsc_caption_service_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t reserved : 3; ,
+ uint8_t number_of_services : 5; );
+ /* struct atsc_caption_service_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the entries field of a atsc_caption_service_descriptor.
+ */
+struct atsc_caption_service_entry {
+ iso639lang_t language_code;
+ EBIT3(uint8_t digital_cc : 1; ,
+ uint8_t reserved : 1; ,
+ uint8_t value : 6; );
+ EBIT3(uint16_t easy_reader : 1; ,
+ uint16_t wide_aspect_ratio : 1; ,
+ uint16_t reserved1 :14; );
+} __ucsi_packed;
+
+/**
+ * Process an atsc_caption_service_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_caption_service_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_caption_service_descriptor*
+ atsc_caption_service_descriptor_codec(struct descriptor* d)
+{
+ struct atsc_caption_service_descriptor *ret =
+ (struct atsc_caption_service_descriptor *) d;
+ uint8_t *buf = (uint8_t*) d + 2;
+ int pos = 0;
+ int idx;
+
+ if (d->len < 1)
+ return NULL;
+ pos++;
+
+ for(idx = 0; idx < ret->number_of_services; idx++) {
+ if (d->len < (pos + sizeof(struct atsc_caption_service_entry)))
+ return NULL;
+
+ bswap16(buf+pos+4);
+
+ pos += sizeof(struct atsc_caption_service_entry);
+ }
+
+ return (struct atsc_caption_service_descriptor*) d;
+}
+
+/**
+ * Iterator for entries field of a atsc_caption_service_descriptor.
+ *
+ * @param d atsc_caption_service_descriptor pointer.
+ * @param pos Variable holding a pointer to the current atsc_caption_service_entry.
+ * @param idx Field iterator integer.
+ */
+#define atsc_caption_service_descriptor_entries_for_each(d, pos, idx) \
+ for ((pos) = atsc_caption_service_descriptor_entries_first(d), idx=0; \
+ (pos); \
+ (pos) = atsc_caption_service_descriptor_entries_next(d, pos, ++idx))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_caption_service_entry*
+ atsc_caption_service_descriptor_entries_first(struct atsc_caption_service_descriptor *d)
+{
+ if (d->number_of_services == 0)
+ return NULL;
+
+ return (struct atsc_caption_service_entry *)
+ ((uint8_t*) d + sizeof(struct atsc_caption_service_descriptor));
+}
+
+static inline struct atsc_caption_service_entry*
+ atsc_caption_service_descriptor_entries_next(struct atsc_caption_service_descriptor *d,
+ struct atsc_caption_service_entry *pos,
+ int idx)
+{
+ if (idx >= d->number_of_services)
+ return NULL;
+
+ return (struct atsc_caption_service_entry *)
+ ((uint8_t *) pos + sizeof(struct atsc_caption_service_entry));
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/component_name_descriptor.h b/lib/libucsi/atsc/component_name_descriptor.h
new file mode 100644
index 0000000..3b9cab7
--- /dev/null
+++ b/lib/libucsi/atsc/component_name_descriptor.h
@@ -0,0 +1,92 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_COMPONENT_NAME_DESCRIPTOR
+#define _UCSI_ATSC_COMPONENT_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+#include <libucsi/atsc/types.h>
+
+/**
+ * atsc_component_name_descriptor structure.
+ */
+struct atsc_component_name_descriptor {
+ struct descriptor d;
+
+ /* struct atsc_text text[] */
+} __ucsi_packed;
+
+/**
+ * Process an atsc_component_name_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_component_name_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_component_name_descriptor*
+ atsc_component_name_descriptor_codec(struct descriptor* d)
+{
+ uint8_t *txt = ((uint8_t*) d) + sizeof(struct atsc_component_name_descriptor);
+
+ if (atsc_text_validate(txt, d->len))
+ return NULL;
+
+ return (struct atsc_component_name_descriptor*) d;
+}
+
+/**
+ * Accessor for the text field of an atsc_component_name_descriptor.
+ *
+ * @param d atsc_component_name_descriptor pointer.
+ * @return Pointer to the atsc_text data, or NULL on error.
+ */
+static inline struct atsc_text*
+ atsc_component_name_descriptor_text(struct atsc_component_name_descriptor *d)
+{
+ uint8_t *txt = ((uint8_t*) d) + sizeof(struct atsc_component_name_descriptor);
+
+ return (struct atsc_text*) txt;
+}
+
+/**
+ * Accessor for the length of the text field of an atsc_component_name_descriptor_text.
+ *
+ * @param d atsc_component_name_descriptor pointer.
+ * @return The length in bytes.
+ */
+static inline int
+ atsc_component_name_descriptor_text_length(struct atsc_component_name_descriptor *d)
+{
+ return d->d.len;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/content_advisory_descriptor.h b/lib/libucsi/atsc/content_advisory_descriptor.h
new file mode 100644
index 0000000..da19813
--- /dev/null
+++ b/lib/libucsi/atsc/content_advisory_descriptor.h
@@ -0,0 +1,235 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_CONTENT_ADVISORY_DESCRIPTOR
+#define _UCSI_ATSC_CONTENT_ADVISORY_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * atsc_content_advisory_descriptor structure.
+ */
+struct atsc_content_advisory_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t reserved : 2; ,
+ uint8_t rating_region_count : 6; );
+ /* struct atsc_content_advisory_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the entries field of a atsc_content_advisory_descriptor.
+ */
+struct atsc_content_advisory_entry {
+ uint8_t rating_region;
+ uint8_t rated_dimensions;
+ /* struct atsc_content_advisory_entry_dimension dimensions[] */
+ /* struct atsc_content_advisory_entry_part2 part2 */
+} __ucsi_packed;
+
+/**
+ * An entry in the entries field of a atsc_content_advisory_descriptor.
+ */
+struct atsc_content_advisory_entry_dimension {
+ uint8_t rating_dimension_j;
+ EBIT2(uint8_t reserved : 4; ,
+ uint8_t rating_value : 4; );
+} __ucsi_packed;
+
+/**
+ * Part2 of an atsc_content_advisory_entry.
+ */
+struct atsc_content_advisory_entry_part2 {
+ uint8_t rating_description_length;
+ /* struct atsc_text description */
+} __ucsi_packed;
+
+/**
+ * Process an atsc_content_advisory_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_content_advisory_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_content_advisory_descriptor*
+ atsc_content_advisory_descriptor_codec(struct descriptor* d)
+{
+ struct atsc_content_advisory_descriptor *ret =
+ (struct atsc_content_advisory_descriptor *) d;
+ uint8_t *buf = (uint8_t*) d + 2;
+ int pos = 0;
+ int idx;
+
+ if (d->len < 1)
+ return NULL;
+ pos++;
+
+ for(idx = 0; idx < ret->rating_region_count; idx++) {
+ if (d->len < (pos + sizeof(struct atsc_content_advisory_entry)))
+ return NULL;
+ struct atsc_content_advisory_entry *entry =
+ (struct atsc_content_advisory_entry *) (buf + pos);
+ pos += sizeof(struct atsc_content_advisory_entry);
+
+ if (d->len < (pos + (sizeof(struct atsc_content_advisory_entry_dimension) *
+ entry->rated_dimensions)))
+ return NULL;
+ pos += sizeof(struct atsc_content_advisory_entry_dimension) * entry->rated_dimensions;
+
+ if (d->len < (pos + sizeof(struct atsc_content_advisory_entry_part2)))
+ return NULL;
+ struct atsc_content_advisory_entry_part2 *part2 =
+ (struct atsc_content_advisory_entry_part2 *) (buf + pos);
+ pos += sizeof(struct atsc_content_advisory_entry_part2);
+
+ if (d->len < (pos + part2->rating_description_length))
+ return NULL;
+
+ if (atsc_text_validate(buf+pos, part2->rating_description_length))
+ return NULL;
+
+ pos += part2->rating_description_length;
+ }
+
+ return (struct atsc_content_advisory_descriptor*) d;
+}
+
+/**
+ * Iterator for entries field of a atsc_content_advisory_descriptor.
+ *
+ * @param d atsc_content_advisory_descriptor pointer.
+ * @param pos Variable holding a pointer to the current atsc_content_advisory_entry.
+ * @param idx Integer used to count which entry we are in.
+ */
+#define atsc_content_advisory_descriptor_entries_for_each(d, pos, idx) \
+ for ((pos) = atsc_content_advisory_descriptor_entries_first(d), idx=0; \
+ (pos); \
+ (pos) = atsc_content_advisory_descriptor_entries_next(d, pos, ++idx))
+
+/**
+ * Iterator for dimensions field of a atsc_content_advisory_entry.
+ *
+ * @param d atsc_content_advisory_entry pointer.
+ * @param pos Variable holding a pointer to the current atsc_content_advisory_entry_dimension.
+ * @param idx Integer used to count which dimension we are in.
+ */
+#define atsc_content_advisory_entry_dimensions_for_each(d, pos, idx) \
+ for ((pos) = atsc_content_advisory_entry_dimensions_first(d), idx=0; \
+ (pos); \
+ (pos) = atsc_content_advisory_entry_dimensions_next(d, pos, ++idx))
+
+/**
+ * Accessor for the part2 field of an atsc_content_advisory_entry.
+ *
+ * @param entry atsc_content_advisory_entry pointer.
+ * @return struct atsc_content_advisory_entry_part2 pointer.
+ */
+static inline struct atsc_content_advisory_entry_part2 *
+ atsc_content_advisory_entry_part2(struct atsc_content_advisory_entry *entry)
+{
+ int pos = sizeof(struct atsc_content_advisory_entry);
+ pos += entry->rated_dimensions * sizeof(struct atsc_content_advisory_entry_dimension);
+
+ return (struct atsc_content_advisory_entry_part2 *) (((uint8_t*) entry) + pos);
+}
+
+
+/**
+ * Accessor for the description field of an atsc_content_advisory_entry_part2.
+ *
+ * @param part2 atsc_content_advisory_entry_part2 pointer.
+ * @return Pointer to the atsc_text data, or NULL on error.
+ */
+static inline struct atsc_text*
+ atsc_content_advisory_entry_part2_description(struct atsc_content_advisory_entry_part2 *part2)
+{
+ uint8_t *txt = ((uint8_t*) part2) + sizeof(struct atsc_content_advisory_entry_part2);
+
+ return (struct atsc_text *) txt;
+}
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_content_advisory_entry*
+ atsc_content_advisory_descriptor_entries_first(struct atsc_content_advisory_descriptor *d)
+{
+ if (d->rating_region_count == 0)
+ return NULL;
+
+ return (struct atsc_content_advisory_entry *)
+ ((uint8_t*) d + sizeof(struct atsc_content_advisory_descriptor));
+}
+
+static inline struct atsc_content_advisory_entry*
+ atsc_content_advisory_descriptor_entries_next(struct atsc_content_advisory_descriptor *d,
+ struct atsc_content_advisory_entry *pos,
+ int idx)
+{
+ if (idx >= d->rating_region_count)
+ return NULL;
+ struct atsc_content_advisory_entry_part2 *part2 =
+ atsc_content_advisory_entry_part2(pos);
+
+ return (struct atsc_content_advisory_entry *)
+ ((uint8_t *) part2 +
+ sizeof(struct atsc_content_advisory_entry_part2) +
+ part2->rating_description_length);
+}
+
+static inline struct atsc_content_advisory_entry_dimension*
+ atsc_content_advisory_entry_dimensions_first(struct atsc_content_advisory_entry *e)
+{
+ if (e->rated_dimensions == 0)
+ return NULL;
+
+ return (struct atsc_content_advisory_entry_dimension *)
+ ((uint8_t*) e + sizeof(struct atsc_content_advisory_entry));
+}
+
+static inline struct atsc_content_advisory_entry_dimension*
+ atsc_content_advisory_entry_dimensions_next(struct atsc_content_advisory_entry *e,
+ struct atsc_content_advisory_entry_dimension *pos,
+ int idx)
+{
+ uint8_t *next = (uint8_t *) pos + sizeof(struct atsc_content_advisory_entry_dimension);
+
+ if (idx >= e->rated_dimensions)
+ return NULL;
+ return (struct atsc_content_advisory_entry_dimension *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/cvct_section.c b/lib/libucsi/atsc/cvct_section.c
new file mode 100644
index 0000000..6edbc03
--- /dev/null
+++ b/lib/libucsi/atsc/cvct_section.c
@@ -0,0 +1,77 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/atsc/cvct_section.h>
+
+struct atsc_cvct_section *atsc_cvct_section_codec(struct atsc_section_psip *psip)
+{
+ uint8_t * buf = (uint8_t *) psip;
+ size_t pos = sizeof(struct atsc_section_psip);
+ size_t len = section_ext_length(&(psip->ext_head));
+ int idx;
+
+ if (len < sizeof(struct atsc_cvct_section))
+ return NULL;
+ struct atsc_cvct_section *cvct = (struct atsc_cvct_section *) psip;
+
+ pos++;
+ for(idx =0; idx < cvct->num_channels_in_section; idx++) {
+ if ((pos + sizeof(struct atsc_cvct_channel)) > len)
+ return NULL;
+ struct atsc_cvct_channel *channel = (struct atsc_cvct_channel *) (buf+pos);
+
+ pos += 7*2;
+
+ bswap32(buf+pos);
+ bswap32(buf+pos+4);
+ bswap16(buf+pos+8);
+ bswap16(buf+pos+10);
+ bswap16(buf+pos+12);
+ bswap16(buf+pos+14);
+ bswap16(buf+pos+16);
+ pos+=18;
+
+ if ((pos + channel->descriptors_length) > len)
+ return NULL;
+ if (verify_descriptors(buf + pos, channel->descriptors_length))
+ return NULL;
+
+ pos += channel->descriptors_length;
+ }
+
+ if ((pos + sizeof(struct atsc_cvct_section_part2)) > len)
+ return NULL;
+ struct atsc_cvct_section_part2 *part2 = (struct atsc_cvct_section_part2 *) (buf+pos);
+
+ bswap16(buf+pos);
+ pos+=2;
+
+ if ((pos + part2->descriptors_length) > len)
+ return NULL;
+ if (verify_descriptors(buf + pos, part2->descriptors_length))
+ return NULL;
+
+ pos += part2->descriptors_length;
+ if (pos != len)
+ return NULL;
+
+ return (struct atsc_cvct_section *) psip;
+}
diff --git a/lib/libucsi/atsc/cvct_section.h b/lib/libucsi/atsc/cvct_section.h
new file mode 100644
index 0000000..c3d418a
--- /dev/null
+++ b/lib/libucsi/atsc/cvct_section.h
@@ -0,0 +1,228 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_CVCT_SECTION_H
+#define _UCSI_ATSC_CVCT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/atsc/section.h>
+
+/**
+ * atsc_cvct_section structure.
+ */
+struct atsc_cvct_section {
+ struct atsc_section_psip head;
+
+ uint8_t num_channels_in_section;
+ /* struct atsc_cvct_channel channels[] */
+ /* struct atsc_cvct_channel_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_cvct_channel {
+ uint16_t short_name[7]; // UTF-16 network ordered
+ EBIT4(uint32_t reserved : 4; ,
+ uint32_t major_channel_number :10; ,
+ uint32_t minor_channel_number :10; ,
+ uint32_t modulation_mode : 8; );
+ uint32_t carrier_frequency;
+ uint16_t channel_TSID;
+ uint16_t program_number;
+ EBIT8(uint16_t ETM_location : 2; ,
+ uint16_t access_controlled : 1; ,
+ uint16_t hidden : 1; ,
+ uint16_t path_select : 1; ,
+ uint16_t out_of_band : 1; ,
+ uint16_t hide_guide : 1; ,
+ uint16_t reserved2 : 3; ,
+ uint16_t service_type : 6; );
+ uint16_t source_id;
+ EBIT2(uint16_t reserved3 : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+struct atsc_cvct_section_part2 {
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+static inline struct atsc_cvct_channel *atsc_cvct_section_channels_first(struct atsc_cvct_section *cvct);
+static inline struct atsc_cvct_channel *
+ atsc_cvct_section_channels_next(struct atsc_cvct_section *cvct, struct atsc_cvct_channel *pos, int idx);
+
+/**
+ * Process a atsc_cvct_section.
+ *
+ * @param section Pointer to anj atsc_section_psip structure.
+ * @return atsc_cvct_section pointer, or NULL on error.
+ */
+struct atsc_cvct_section *atsc_cvct_section_codec(struct atsc_section_psip *section);
+
+/**
+ * Accessor for the transport_stream_id field of a CVCT.
+ *
+ * @param cvdt CVDT pointer.
+ * @return The transport_stream_id.
+ */
+static inline uint16_t atsc_cvct_section_transport_stream_id(struct atsc_cvct_section *cvct)
+{
+ return cvct->head.ext_head.table_id_ext;
+}
+
+/**
+ * Iterator for the tables field in an atsc_cvct_section.
+ *
+ * @param mgt atsc_cvct_section pointer.
+ * @param pos Variable containing a pointer to the current atsc_cvct_channel.
+ * @param idx Integer used to count which table we in.
+ */
+#define atsc_cvct_section_channels_for_each(mgt, pos, idx) \
+ for ((pos) = atsc_cvct_section_channels_first(mgt), idx=0; \
+ (pos); \
+ (pos) = atsc_cvct_section_channels_next(mgt, pos, ++idx))
+
+/**
+ * Iterator for the descriptors field in a atsc_cvct_channel structure.
+ *
+ * @param table atsc_cvct_channel pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_cvct_channel_descriptors_for_each(table, pos) \
+ for ((pos) = atsc_cvct_channel_descriptors_first(table); \
+ (pos); \
+ (pos) = atsc_cvct_channel_descriptors_next(table, pos))
+
+/**
+ * Accessor for the second part of an atsc_cvct_section.
+ *
+ * @param mgt atsc_cvct_section pointer.
+ * @return atsc_cvct_section_part2 pointer.
+ */
+static inline struct atsc_cvct_section_part2 *
+ atsc_cvct_section_part2(struct atsc_cvct_section *mgt)
+{
+ int pos = sizeof(struct atsc_cvct_section);
+
+ struct atsc_cvct_channel *cur_table;
+ int idx;
+ atsc_cvct_section_channels_for_each(mgt, cur_table, idx) {
+ pos += sizeof(struct atsc_cvct_channel);
+ pos += cur_table->descriptors_length;
+ }
+
+ return (struct atsc_cvct_section_part2 *) (((uint8_t*) mgt) + pos);
+}
+
+/**
+ * Iterator for the descriptors field in a atsc_cvct_section structure.
+ *
+ * @param part2 atsc_cvct_section_part2 pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_cvct_section_part2_descriptors_for_each(part2, pos) \
+ for ((pos) = atsc_cvct_section_part2_descriptors_first(part2); \
+ (pos); \
+ (pos) = atsc_cvct_section_part2_descriptors_next(part2, pos))
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_cvct_channel *
+ atsc_cvct_section_channels_first(struct atsc_cvct_section *cvct)
+{
+ size_t pos = sizeof(struct atsc_cvct_section);
+
+ if (cvct->num_channels_in_section == 0)
+ return NULL;
+
+ return (struct atsc_cvct_channel*) (((uint8_t *) cvct) + pos);
+}
+
+static inline struct atsc_cvct_channel *
+ atsc_cvct_section_channels_next(struct atsc_cvct_section *cvct,
+ struct atsc_cvct_channel *pos,
+ int idx)
+{
+ if (idx >= cvct->num_channels_in_section)
+ return NULL;
+
+ return (struct atsc_cvct_channel *)
+ (((uint8_t*) pos) + sizeof(struct atsc_cvct_channel) + pos->descriptors_length);
+}
+
+static inline struct descriptor *
+ atsc_cvct_channel_descriptors_first(struct atsc_cvct_channel *table)
+{
+ size_t pos = sizeof(struct atsc_cvct_channel);
+
+ if (table->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) table) + pos);
+}
+
+static inline struct descriptor *
+ atsc_cvct_channel_descriptors_next(struct atsc_cvct_channel *table,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) table + sizeof(struct atsc_cvct_channel),
+ table->descriptors_length,
+ pos);
+}
+
+static inline struct descriptor *
+ atsc_cvct_section_part2_descriptors_first(struct atsc_cvct_section_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_cvct_section_part2);
+
+ if (part2->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct descriptor *
+ atsc_cvct_section_part2_descriptors_next(struct atsc_cvct_section_part2 *part2,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_cvct_section_part2),
+ part2->descriptors_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/dcc_arriving_request_descriptor.h b/lib/libucsi/atsc/dcc_arriving_request_descriptor.h
new file mode 100644
index 0000000..af76eac
--- /dev/null
+++ b/lib/libucsi/atsc/dcc_arriving_request_descriptor.h
@@ -0,0 +1,107 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_DCC_ARRIVING_REQUEST_DESCRIPTOR
+#define _UCSI_ATSC_DCC_ARRIVING_REQUEST_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+enum atsc_dcc_arriving_request_type {
+ DCC_ARRIVAL_TYPE_DEFER_10SEC = 0x01,
+ DCC_ARRIVAL_TYPE_DEFER = 0x02,
+};
+
+/**
+ * atsc_dcc_arriving_request_descriptor structure.
+ */
+struct atsc_dcc_arriving_request_descriptor {
+ struct descriptor d;
+
+ uint8_t dcc_arriving_request_type;
+ uint8_t dcc_arriving_request_text_length;
+ /* struct atsc_text text[] */
+} __ucsi_packed;
+
+/**
+ * Process an atsc_dcc_arriving_request_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_dcc_arriving_request_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_dcc_arriving_request_descriptor*
+ atsc_dcc_arriving_request_descriptor_codec(struct descriptor* d)
+{
+ struct atsc_dcc_arriving_request_descriptor *ret =
+ (struct atsc_dcc_arriving_request_descriptor *) d;
+
+ if (d->len < 2)
+ return NULL;
+
+ if (d->len != 2 + ret->dcc_arriving_request_text_length)
+ return NULL;
+
+ if (atsc_text_validate((uint8_t*) d + sizeof(struct atsc_dcc_arriving_request_descriptor),
+ ret->dcc_arriving_request_text_length))
+ return NULL;
+
+ return (struct atsc_dcc_arriving_request_descriptor*) d;
+}
+
+/**
+ * Accessor for the text field of an atsc_dcc_arriving_request_descriptor.
+ *
+ * @param d atsc_dcc_arriving_request_descriptor pointer.
+ * @return Pointer to the atsc_text data, or NULL on error.
+ */
+static inline struct atsc_text*
+ atsc_dcc_arriving_request_descriptor_text(struct atsc_dcc_arriving_request_descriptor *d)
+{
+ uint8_t *txt = ((uint8_t*) d) + sizeof(struct atsc_dcc_arriving_request_descriptor);
+
+ return (struct atsc_text*) txt;
+}
+
+/**
+ * Accessor for the length of the text field of an atsc_dcc_arriving_request_descriptor.
+ *
+ * @param d atsc_dcc_arriving_request_descriptor pointer.
+ * @return The length in bytes.
+ */
+static inline int
+ atsc_dcc_arriving_request_descriptor_text_length(struct
+ atsc_dcc_arriving_request_descriptor *d)
+{
+ return d->d.len - 2;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/dcc_departing_request_descriptor.h b/lib/libucsi/atsc/dcc_departing_request_descriptor.h
new file mode 100644
index 0000000..851f0cc
--- /dev/null
+++ b/lib/libucsi/atsc/dcc_departing_request_descriptor.h
@@ -0,0 +1,108 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_DCC_DEPARTING_REQUEST_DESCRIPTOR
+#define _UCSI_ATSC_DCC_DEPARTING_REQUEST_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+enum atsc_dcc_departing_request_type {
+ DCC_DEPART_TYPE_IMMEDIATE = 0x01,
+ DCC_DEPART_TYPE_DEFER_10SEC = 0x02,
+ DCC_DEPART_TYPE_DEFER = 0x03,
+};
+
+/**
+ * atsc_dcc_departing_request_descriptor structure.
+ */
+struct atsc_dcc_departing_request_descriptor {
+ struct descriptor d;
+
+ uint8_t dcc_departing_request_type;
+ uint8_t dcc_departing_request_text_length;
+ /* struct atsc_text text[] */
+} __ucsi_packed;
+
+/**
+ * Process an atsc_dcc_departing_request_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_dcc_departing_request_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_dcc_departing_request_descriptor*
+ atsc_dcc_departing_request_descriptor_codec(struct descriptor* d)
+{
+ struct atsc_dcc_departing_request_descriptor *ret =
+ (struct atsc_dcc_departing_request_descriptor *) d;
+
+ if (d->len < 2)
+ return NULL;
+
+ if (d->len != 2 + ret->dcc_departing_request_text_length)
+ return NULL;
+
+ if (atsc_text_validate(((uint8_t*) d) + sizeof(struct atsc_dcc_departing_request_descriptor),
+ ret->dcc_departing_request_text_length))
+ return NULL;
+
+ return (struct atsc_dcc_departing_request_descriptor*) d;
+}
+
+/**
+ * Accessor for the text field of an atsc_dcc_departing_request_descriptor.
+ *
+ * @param d atsc_dcc_departing_request_descriptor pointer.
+ * @return Pointer to the atsc_text data, or NULL on error.
+ */
+static inline struct atsc_text*
+ atsc_dcc_departing_request_descriptor_text(struct atsc_dcc_departing_request_descriptor *d)
+{
+ uint8_t *txt = ((uint8_t*) d) + sizeof(struct atsc_dcc_departing_request_descriptor);
+
+ return (struct atsc_text*) txt;
+}
+
+/**
+ * Accessor for the length of the text field of an atsc_dcc_departing_request_descriptor.
+ *
+ * @param d atsc_dcc_departing_request_descriptor pointer.
+ * @return The length in bytes.
+ */
+static inline int
+ atsc_dcc_departing_request_descriptor_text_length(struct
+ atsc_dcc_departing_request_descriptor *d)
+{
+ return d->d.len - 2;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/dccsct_section.c b/lib/libucsi/atsc/dccsct_section.c
new file mode 100644
index 0000000..59ad069
--- /dev/null
+++ b/lib/libucsi/atsc/dccsct_section.c
@@ -0,0 +1,109 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/atsc/dccsct_section.h>
+
+struct atsc_dccsct_section *atsc_dccsct_section_codec(struct atsc_section_psip *psip)
+{
+ uint8_t * buf = (uint8_t *) psip;
+ size_t pos = 0;
+ size_t len = section_ext_length(&(psip->ext_head));
+ int idx;
+
+ if (len < sizeof(struct atsc_dccsct_section))
+ return NULL;
+ struct atsc_dccsct_section *dccsct = (struct atsc_dccsct_section *) psip;
+
+ pos += sizeof(struct atsc_dccsct_section);
+ for(idx =0; idx < dccsct->updates_defined; idx++) {
+ if (len < (pos + sizeof(struct atsc_dccsct_update)))
+ return NULL;
+ struct atsc_dccsct_update *update = (struct atsc_dccsct_update *) (buf+pos);
+
+ pos += sizeof(struct atsc_dccsct_update);
+ if (len < (pos + update->update_data_length))
+ return NULL;
+
+ switch(update->update_type) {
+ case ATSC_DCCST_UPDATE_NEW_GENRE: {
+ int sublen = sizeof(struct atsc_dccsct_update_new_genre);
+ if (update->update_data_length < sublen)
+ return NULL;
+
+ if (atsc_text_validate(buf+pos+sublen, update->update_data_length - sublen))
+ return NULL;
+ break;
+ }
+ case ATSC_DCCST_UPDATE_NEW_STATE: {
+ int sublen = sizeof(struct atsc_dccsct_update_new_state);
+ if (update->update_data_length < sublen)
+ return NULL;
+
+ if (atsc_text_validate(buf+pos+sublen, update->update_data_length - sublen))
+ return NULL;
+ break;
+ }
+ case ATSC_DCCST_UPDATE_NEW_COUNTY: {
+ int sublen = sizeof(struct atsc_dccsct_update_new_county);
+ if (update->update_data_length < sublen)
+ return NULL;
+ bswap16(buf+pos+1);
+
+ if (atsc_text_validate(buf+pos+sublen, update->update_data_length - sublen))
+ return NULL;
+ break;
+ }
+ }
+
+ pos += update->update_data_length;
+ if (len < (pos + sizeof(struct atsc_dccsct_update_part2)))
+ return NULL;
+ struct atsc_dccsct_update_part2 *part2 = (struct atsc_dccsct_update_part2 *) buf + pos;
+
+ bswap16(buf+pos);
+
+ pos += sizeof(struct atsc_dccsct_update_part2);
+ if (len < (pos + part2->descriptors_length))
+ return NULL;
+ if (verify_descriptors(buf + pos, part2->descriptors_length))
+ return NULL;
+
+ pos += part2->descriptors_length;
+ }
+
+ if (len < (pos + sizeof(struct atsc_dccsct_section_part2)))
+ return NULL;
+ struct atsc_dccsct_section_part2 *part2 = (struct atsc_dccsct_section_part2 *) (buf+pos);
+
+ bswap16(buf+pos);
+
+ pos += sizeof(struct atsc_dccsct_section_part2);
+ if (len < (pos + part2->descriptors_length))
+ return NULL;
+ if (verify_descriptors(buf + pos, part2->descriptors_length))
+ return NULL;
+
+ pos += part2->descriptors_length;
+ if (pos != len)
+ return NULL;
+
+ return (struct atsc_dccsct_section *) psip;
+}
diff --git a/lib/libucsi/atsc/dccsct_section.h b/lib/libucsi/atsc/dccsct_section.h
new file mode 100644
index 0000000..f9f3522
--- /dev/null
+++ b/lib/libucsi/atsc/dccsct_section.h
@@ -0,0 +1,327 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_DCCSCT_SECTION_H
+#define _UCSI_ATSC_DCCSCT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/atsc/section.h>
+#include <libucsi/atsc/types.h>
+
+enum atsc_dccst_update_types {
+ ATSC_DCCST_UPDATE_NEW_GENRE = 0x01,
+ ATSC_DCCST_UPDATE_NEW_STATE = 0x02,
+ ATSC_DCCST_UPDATE_NEW_COUNTY = 0x03,
+};
+
+/**
+ * atsc_dccsct_section structure.
+ */
+struct atsc_dccsct_section {
+ struct atsc_section_psip head;
+
+ uint8_t updates_defined;
+ /* struct atsc_dccsct_update updates */
+ /* struct atsc_dccsct_section_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_dccsct_update {
+ uint8_t update_type;
+ uint8_t update_data_length;
+ /* struct atsc_dccsct_update_XXX data -- depends on update_type */
+ /* struct atsc_dccsct_update_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_dccsct_update_new_genre {
+ uint8_t genre_category_code;
+ /* atsc_text name */
+} __ucsi_packed;
+
+struct atsc_dccsct_update_new_state {
+ uint8_t dcc_state_location_code;
+ /* atsc_text name */
+} __ucsi_packed;
+
+struct atsc_dccsct_update_new_county {
+ uint8_t state_code;
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t dcc_county_location_code :10; );
+ /* atsc_text name */
+} __ucsi_packed;
+
+struct atsc_dccsct_update_part2 {
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+struct atsc_dccsct_section_part2 {
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process an atsc_dccsct_section.
+ *
+ * @param section Pointer to an atsc_section_psip structure.
+ * @return atsc_dccsct_section pointer, or NULL on error.
+ */
+struct atsc_dccsct_section *atsc_dccsct_section_codec(struct atsc_section_psip *section);
+
+/**
+ * Accessor for the dccsct_type field of a dccsct.
+ *
+ * @param dccsct dccsct pointer.
+ * @return The dccsct_type.
+ */
+static inline uint16_t atsc_dccsct_section_dccsct_type(struct atsc_dccsct_section *dccsct)
+{
+ return dccsct->head.ext_head.table_id_ext;
+}
+
+/**
+ * Iterator for the updates field in an atsc_dccsct_section.
+ *
+ * @param dccsct atsc_dccsct_section pointer.
+ * @param pos Variable containing a pointer to the current atsc_dccsct_update.
+ * @param idx Integer used to count which test we are in.
+ */
+#define atsc_dccsct_section_updates_for_each(dccsct, pos, idx) \
+ for ((pos) = atsc_dccsct_section_updates_first(dccsct), idx=0; \
+ (pos); \
+ (pos) = atsc_dccsct_section_updates_next(dccsct, pos, ++idx))
+
+/**
+ * Accessor for the data field of a new genre atsc_dccsct_update.
+ *
+ * @param update atsc_dccsct_update pointer.
+ * @return struct atsc_dccsct_update_new_genre pointer.
+ */
+static inline struct atsc_dccsct_update_new_genre *atsc_dccsct_update_new_genre(struct atsc_dccsct_update *update)
+{
+ if (update->update_type != ATSC_DCCST_UPDATE_NEW_GENRE)
+ return NULL;
+
+ return (struct atsc_dccsct_update_new_genre *)
+ (((uint8_t*) update) + sizeof(struct atsc_dccsct_update));
+}
+
+/**
+ * Accessor for the name field of an atsc_dccsct_update_new_genre.
+ *
+ * @param update atsc_dccsct_update_new_genre pointer.
+ * @return text pointer.
+ */
+static inline struct atsc_text *atsc_dccsct_update_new_genre_name(struct atsc_dccsct_update *update)
+{
+ if ((update->update_data_length - 1) == 0)
+ return NULL;
+
+ return (struct atsc_text *)
+ (((uint8_t*) update) + sizeof(struct atsc_dccsct_update_new_genre));
+}
+
+/**
+ * Accessor for the data field of a new state atsc_dccsct_update.
+ *
+ * @param update atsc_dccsct_update pointer.
+ * @return struct atsc_dccsct_update_new_state pointer.
+ */
+static inline struct atsc_dccsct_update_new_state *
+ atsc_dccsct_update_new_state(struct atsc_dccsct_update *update)
+{
+ if (update->update_type != ATSC_DCCST_UPDATE_NEW_STATE)
+ return NULL;
+
+ return (struct atsc_dccsct_update_new_state *)
+ (((uint8_t*) update) + sizeof(struct atsc_dccsct_update));
+}
+
+/**
+ * Accessor for the name field of an atsc_dccsct_update_new_state.
+ *
+ * @param update atsc_dccsct_update_new_state pointer.
+ * @return text pointer.
+ */
+static inline struct atsc_text *atsc_dccsct_update_new_state_name(struct atsc_dccsct_update *update)
+{
+ if ((update->update_data_length - 1) == 0)
+ return NULL;
+
+ return (struct atsc_text *)
+ (((uint8_t*) update) + sizeof(struct atsc_dccsct_update_new_state));
+}
+
+/**
+ * Accessor for the data field of a new county atsc_dccsct_update.
+ *
+ * @param update atsc_dccsct_update pointer.
+ * @return struct atsc_dccsct_update_new_county pointer.
+ */
+static inline struct atsc_dccsct_update_new_county *
+ atsc_dccsct_update_new_county(struct atsc_dccsct_update *update)
+{
+ if (update->update_type != ATSC_DCCST_UPDATE_NEW_COUNTY)
+ return NULL;
+
+ return (struct atsc_dccsct_update_new_county *)
+ (((uint8_t*) update) + sizeof(struct atsc_dccsct_update));
+}
+
+/**
+ * Accessor for the name field of an atsc_dccsct_update_new_county.
+ *
+ * @param update atsc_dccsct_update_new_county pointer.
+ * @return text pointer.
+ */
+static inline struct atsc_text *atsc_dccsct_update_new_county_name(struct atsc_dccsct_update *update)
+{
+ if ((update->update_data_length - 3) == 0)
+ return NULL;
+
+ return (struct atsc_text*)
+ (((uint8_t*) update) + sizeof(struct atsc_dccsct_update_new_county));
+}
+
+/**
+ * Accessor for the part2 field of an atsc_dccsct_update.
+ *
+ * @param update atsc_dccsct_update pointer.
+ * @return struct atsc_dccsct_test_part2 pointer.
+ */
+static inline struct atsc_dccsct_update_part2 *atsc_dccsct_update_part2(struct atsc_dccsct_update *update)
+{
+ int pos = sizeof(struct atsc_dccsct_update);
+ pos += update->update_data_length;
+
+ return (struct atsc_dccsct_update_part2 *) (((uint8_t*) update) + pos);
+}
+
+/**
+ * Iterator for the descriptors field in an atsc_dccsct_update_part2 structure.
+ *
+ * @param part2 atsc_dccsct_update_part2 pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_dccsct_update_part2_descriptors_for_each(part2, pos) \
+ for ((pos) = atsc_dccsct_update_part2_descriptors_first(part2); \
+ (pos); \
+ (pos) = atsc_dccsct_update_part2_descriptors_next(part2, pos))
+
+/**
+ * Iterator for the descriptors field in a atsc_dccsct_section_part2 structure.
+ *
+ * @param part2 atsc_dccsct_section_part2 pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_dccsct_section_part2_descriptors_for_each(part2, pos) \
+ for ((pos) = atsc_dccsct_section_part2_descriptors_first(part2); \
+ (pos); \
+ (pos) = atsc_dccsct_section_part2_descriptors_next(part2, pos))
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_dccsct_update *
+ atsc_dccsct_section_updates_first(struct atsc_dccsct_section *dccsct)
+{
+ size_t pos = sizeof(struct atsc_dccsct_section);
+
+ if (dccsct->updates_defined == 0)
+ return NULL;
+
+ return (struct atsc_dccsct_update*) (((uint8_t *) dccsct) + pos);
+}
+
+static inline struct atsc_dccsct_update*
+ atsc_dccsct_section_updates_next(struct atsc_dccsct_section *dccsct,
+ struct atsc_dccsct_update *pos,
+ int idx)
+{
+ if (idx >= dccsct->updates_defined)
+ return NULL;
+
+ struct atsc_dccsct_update_part2 *part2 = atsc_dccsct_update_part2(pos);
+ int len = sizeof(struct atsc_dccsct_update_part2);
+ len += part2->descriptors_length;
+
+ return (struct atsc_dccsct_update *) (((uint8_t*) part2) + len);
+}
+
+static inline struct descriptor *
+ atsc_dccsct_update_part2_descriptors_first(struct atsc_dccsct_update_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_dccsct_update_part2);
+
+ if (part2->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct descriptor *
+ atsc_dccsct_update_part2_descriptors_next(struct atsc_dccsct_update_part2 *part2,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_dccsct_update_part2),
+ part2->descriptors_length,
+ pos);
+}
+
+static inline struct descriptor *
+ atsc_dccsct_section_part2_descriptors_first(struct atsc_dccsct_section_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_dccsct_section_part2);
+
+ if (part2->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct descriptor *
+ atsc_dccsct_section_part2_descriptors_next(struct atsc_dccsct_section_part2 *part2,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_dccsct_section_part2),
+ part2->descriptors_length,
+ pos);
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/dcct_section.c b/lib/libucsi/atsc/dcct_section.c
new file mode 100644
index 0000000..7d0b83b
--- /dev/null
+++ b/lib/libucsi/atsc/dcct_section.c
@@ -0,0 +1,96 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/atsc/dcct_section.h>
+
+struct atsc_dcct_section *atsc_dcct_section_codec(struct atsc_section_psip *psip)
+{
+ uint8_t * buf = (uint8_t *) psip;
+ size_t pos = 0;
+ size_t len = section_ext_length(&(psip->ext_head));
+ int testidx;
+ int termidx;
+
+ if (len < sizeof(struct atsc_dcct_section))
+ return NULL;
+ struct atsc_dcct_section *dcct = (struct atsc_dcct_section *) psip;
+
+ pos += sizeof(struct atsc_dcct_section);
+ for(testidx =0; testidx < dcct->dcc_test_count; testidx++) {
+ if (len < (pos + sizeof(struct atsc_dcct_test)))
+ return NULL;
+ struct atsc_dcct_test *test = (struct atsc_dcct_test *) (buf+pos);
+
+ bswap24(buf+pos);
+ bswap24(buf+pos+3);
+ bswap32(buf+pos+6);
+ bswap32(buf+pos+10);
+
+ pos += sizeof(struct atsc_dcct_test);
+ for(termidx =0; termidx < test->dcc_term_count; termidx++) {
+ if (len < (pos + sizeof(struct atsc_dcct_term)))
+ return NULL;
+ struct atsc_dcct_term *term = (struct atsc_dcct_term *) (buf+pos);
+
+ bswap64(buf+pos+1);
+ bswap16(buf+pos+9);
+
+ pos += sizeof(struct atsc_dcct_term);
+ if (len < (pos + term->descriptors_length))
+ return NULL;
+ if (verify_descriptors(buf + pos, term->descriptors_length))
+ return NULL;
+
+ pos += term->descriptors_length;
+ }
+
+ if (len < (pos + sizeof(struct atsc_dcct_test_part2)))
+ return NULL;
+ struct atsc_dcct_test_part2 *part2 = (struct atsc_dcct_test_part2 *) (buf+pos);
+
+ bswap16(buf+pos);
+
+ pos += sizeof(struct atsc_dcct_test_part2);
+ if (len < (pos + part2->descriptors_length))
+ return NULL;
+ if (verify_descriptors(buf + pos, part2->descriptors_length))
+ return NULL;
+ pos += part2->descriptors_length;
+ }
+
+ if (len < (pos + sizeof(struct atsc_dcct_section_part2)))
+ return NULL;
+ struct atsc_dcct_section_part2 *part2 = (struct atsc_dcct_section_part2 *) (buf+pos);
+
+ bswap16(buf+pos);
+
+ pos += sizeof(struct atsc_dcct_section_part2);
+ if (len < (pos + part2->descriptors_length))
+ return NULL;
+ if (verify_descriptors(buf + pos, part2->descriptors_length))
+ return NULL;
+
+ pos += part2->descriptors_length;
+ if (pos != len)
+ return NULL;
+
+ return (struct atsc_dcct_section *) psip;
+}
diff --git a/lib/libucsi/atsc/dcct_section.h b/lib/libucsi/atsc/dcct_section.h
new file mode 100644
index 0000000..647bd4b
--- /dev/null
+++ b/lib/libucsi/atsc/dcct_section.h
@@ -0,0 +1,380 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_DCCT_SECTION_H
+#define _UCSI_ATSC_DCCT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/atsc/section.h>
+#include <libucsi/atsc/types.h>
+
+enum atsc_dcc_context {
+ ATSC_DCC_CONTEXT_TEMPORARY_RETUNE = 0,
+ ATSC_DCC_CONTEXT_CHANNEL_REDIRECT = 1,
+};
+
+enum atsc_dcc_selection_type {
+ ATSC_DCC_SELECTION_UNCONDITIONAL_CHANNEL_CHANGE = 0x00,
+ ATSC_DCC_SELECTION_NUMERIC_POSTAL_CODE_INCLUSION = 0x01,
+ ATSC_DCC_SELECTION_ALPHANUMERIC_POSTAL_CODE_INCLUSION = 0x02,
+ ATSC_DCC_SELECTION_DEMOGRAPHIC_CATEGORY_ONE_OR_MORE = 0x05,
+ ATSC_DCC_SELECTION_DEMOGRAPHIC_CATEGORY_ALL = 0x06,
+ ATSC_DCC_SELECTION_GENRE_CATEGORY_ONE_OR_MORE = 0x07,
+ ATSC_DCC_SELECTION_GENRE_CATEGORY_ALL = 0x08,
+ ATSC_DCC_SELECTION_CANNOT_BE_AUTHORIZED = 0x09,
+ ATSC_DCC_SELECTION_GEOGRAPHIC_LOCATION_INCLUSION = 0x0c,
+ ATSC_DCC_SELECTION_RATING_BLOCKED = 0x0d,
+ ATSC_DCC_SELECTION_RETURN_TO_ORIGINAL_CHANNEL = 0x0f,
+ ATSC_DCC_SELECTION_NUMERIC_POSTAL_CODE_EXCLUSION = 0x11,
+ ATSC_DCC_SELECTION_ALPHANUMERIC_POSTAL_CODE_EXCLUSION = 0x12,
+ ATSC_DCC_SELECTION_DEMOGRAPHIC_CATEGORY_NOT_ONE_OR_MORE = 0x15,
+ ATSC_DCC_SELECTION_DEMOGRAPHIC_CATEGORY_NOT_ALL = 0x16,
+ ATSC_DCC_SELECTION_GENRE_CATEGORY_NOT_ONE_OR_MORE = 0x17,
+ ATSC_DCC_SELECTION_GENRE_CATEGORY_NOT_ALL = 0x18,
+ ATSC_DCC_SELECTION_GEOGRAPHIC_LOCATION_EXCLUSION = 0x1c,
+ ATSC_DCC_SELECTION_VIEWER_DIRECT_SELECT_A = 0x20,
+ ATSC_DCC_SELECTION_VIEWER_DIRECT_SELECT_B = 0x21,
+ ATSC_DCC_SELECTION_VIEWER_DIRECT_SELECT_C = 0x22,
+ ATSC_DCC_SELECTION_VIEWER_DIRECT_SELECT_D = 0x23,
+};
+
+/**
+ * atsc_dcct_section structure.
+ */
+struct atsc_dcct_section {
+ struct atsc_section_psip head;
+
+ uint8_t dcc_test_count;
+ /* struct atsc_dcct_test tests */
+ /* struct atsc_dcct_section_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_dcct_test {
+ EBIT4(uint32_t dcc_context : 1; ,
+ uint32_t reserved : 3; ,
+ uint32_t dcc_from_major_channel_number :10; ,
+ uint32_t dcc_from_minor_channel_number :10; );
+ EBIT3(uint32_t reserved1 : 4; ,
+ uint32_t dcc_to_major_channel_number :10; ,
+ uint32_t dcc_to_minor_channel_number :10; );
+ atsctime_t start_time;
+ atsctime_t end_time;
+ uint8_t dcc_term_count;
+ /* struct atsc_dcct_term terms */
+ /* struct atsc_dcct_test_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_dcct_term {
+ uint8_t dcc_selection_type;
+ uint64_t dcc_selection_id;
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+struct atsc_dcct_test_part2 {
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+struct atsc_dcct_section_part2 {
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+static inline struct atsc_dcct_test *
+ atsc_dcct_section_tests_first(struct atsc_dcct_section *dcct);
+static inline struct atsc_dcct_test *
+ atsc_dcct_section_tests_next(struct atsc_dcct_section *dcct,
+ struct atsc_dcct_test *pos,
+ int idx);
+static inline struct atsc_dcct_term *
+ atsc_dcct_test_terms_first(struct atsc_dcct_test *test);
+static inline struct atsc_dcct_term *
+ atsc_dcct_test_terms_next(struct atsc_dcct_test *test,
+ struct atsc_dcct_term *pos,
+ int idx);
+
+
+/**
+ * Process an atsc_dcct_section.
+ *
+ * @param section Pointer to an atsc_section_psip structure.
+ * @return atsc_dcct_section pointer, or NULL on error.
+ */
+struct atsc_dcct_section *atsc_dcct_section_codec(struct atsc_section_psip *section);
+
+/**
+ * Accessor for the dcc_subtype field of a dcct.
+ *
+ * @param dcct dcct pointer.
+ * @return The dcc_subtype.
+ */
+static inline uint8_t atsc_dcct_section_dcc_subtype(struct atsc_dcct_section *dcct)
+{
+ return dcct->head.ext_head.table_id_ext >> 8;
+}
+
+/**
+ * Accessor for the dcc_id field of a dcct.
+ *
+ * @param dcct dcct pointer.
+ * @return The dcc_id.
+ */
+static inline uint8_t atsc_dcct_section_dcc_id(struct atsc_dcct_section *dcct)
+{
+ return dcct->head.ext_head.table_id_ext & 0xff;
+}
+
+/**
+ * Iterator for the tests field in an atsc_dcct_section.
+ *
+ * @param dcct atsc_dcct_section pointer.
+ * @param pos Variable containing a pointer to the current atsc_dcct_test.
+ * @param idx Integer used to count which test we are in.
+ */
+#define atsc_dcct_section_tests_for_each(dcct, pos, idx) \
+ for ((pos) = atsc_dcct_section_tests_first(dcct), idx=0; \
+ (pos); \
+ (pos) = atsc_dcct_section_tests_next(dcct, pos, ++idx))
+
+/**
+ * Iterator for the terms field in an atsc_dcct_test.
+ *
+ * @param test atsc_dcct_test pointer.
+ * @param pos Variable containing a pointer to the current atsc_dcct_term.
+ * @param idx Integer used to count which test we are in.
+ */
+#define atsc_dcct_test_terms_for_each(test, pos, idx) \
+ for ((pos) = atsc_dcct_test_terms_first(test), idx=0; \
+ (pos); \
+ (pos) = atsc_dcct_test_terms_next(test, pos, ++idx))
+
+/**
+ * Iterator for the descriptors field in a atsc_dcct_term structure.
+ *
+ * @param term atsc_dcct_term pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_dcct_term_descriptors_for_each(term, pos) \
+ for ((pos) = atsc_dcct_term_descriptors_first(term); \
+ (pos); \
+ (pos) = atsc_dcct_term_descriptors_next(term, pos))
+
+/**
+ * Accessor for the part2 field of an atsc_dcct_test.
+ *
+ * @param test atsc_dcct_test pointer.
+ * @return struct atsc_dcct_test_part2 pointer.
+ */
+static inline struct atsc_dcct_test_part2 *atsc_dcct_test_part2(struct atsc_dcct_test *test)
+{
+ int pos = sizeof(struct atsc_dcct_test);
+
+ struct atsc_dcct_term *cur_term;
+ int idx;
+ atsc_dcct_test_terms_for_each(test, cur_term, idx) {
+ pos += sizeof(struct atsc_dcct_term);
+ pos += cur_term->descriptors_length;
+ }
+
+ return (struct atsc_dcct_test_part2 *) (((uint8_t*) test) + pos);
+}
+
+/**
+ * Iterator for the descriptors field in a atsc_dcct_test_part2 structure.
+ *
+ * @param term atsc_dcct_test_part2 pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_dcct_test_part2_descriptors_for_each(part2, pos) \
+ for ((pos) = atsc_dcct_test_part2_descriptors_first(part2); \
+ (pos); \
+ (pos) = atsc_dcct_test_part2_descriptors_next(part2, pos))
+
+/**
+ * Accessor for the part2 field of an atsc_dcct_section.
+ *
+ * @param dcct atsc_dcct_section pointer.
+ * @return struct atsc_dcct_section_part2 pointer.
+ */
+static inline struct atsc_dcct_section_part2 *atsc_dcct_section_part2(struct atsc_dcct_section *dcct)
+{
+ int pos = sizeof(struct atsc_dcct_section);
+
+ struct atsc_dcct_test *cur_test;
+ int testidx;
+ atsc_dcct_section_tests_for_each(dcct, cur_test, testidx) {
+ struct atsc_dcct_test_part2 *part2 = atsc_dcct_test_part2(cur_test);
+ pos += ((uint8_t*) part2 - (uint8_t*) cur_test);
+
+ pos += sizeof(struct atsc_dcct_test_part2);
+ pos += part2->descriptors_length;
+ }
+
+ return (struct atsc_dcct_section_part2 *) (((uint8_t*) dcct) + pos);
+}
+
+/**
+ * Iterator for the descriptors field in a atsc_dcct_section_part2 structure.
+ *
+ * @param part2 atsc_dcct_section_part2 pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_dcct_section_part2_descriptors_for_each(part2, pos) \
+ for ((pos) = atsc_dcct_section_part2_descriptors_first(part2); \
+ (pos); \
+ (pos) = atsc_dcct_section_part2_descriptors_next(part2, pos))
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_dcct_test *
+ atsc_dcct_section_tests_first(struct atsc_dcct_section *dcct)
+{
+ size_t pos = sizeof(struct atsc_dcct_section);
+
+ if (dcct->dcc_test_count == 0)
+ return NULL;
+
+ return (struct atsc_dcct_test*) (((uint8_t *) dcct) + pos);
+}
+
+static inline struct atsc_dcct_test *
+ atsc_dcct_section_tests_next(struct atsc_dcct_section *dcct,
+ struct atsc_dcct_test *pos,
+ int idx)
+{
+ if (idx >= dcct->dcc_test_count)
+ return NULL;
+
+ struct atsc_dcct_test_part2 *part2 = atsc_dcct_test_part2(pos);
+ int len = sizeof(struct atsc_dcct_test_part2);
+ len += part2->descriptors_length;
+
+ return (struct atsc_dcct_test *) (((uint8_t*) part2) + len);
+}
+
+static inline struct atsc_dcct_term *
+ atsc_dcct_test_terms_first(struct atsc_dcct_test *test)
+{
+ size_t pos = sizeof(struct atsc_dcct_test);
+
+ if (test->dcc_term_count == 0)
+ return NULL;
+
+ return (struct atsc_dcct_term*) (((uint8_t *) test) + pos);
+}
+
+static inline struct atsc_dcct_term *
+ atsc_dcct_test_terms_next(struct atsc_dcct_test *test,
+ struct atsc_dcct_term *pos,
+ int idx)
+{
+ if (idx >= test->dcc_term_count)
+ return NULL;
+
+ int len = sizeof(struct atsc_dcct_term);
+ len += pos->descriptors_length;
+
+ return (struct atsc_dcct_term *) (((uint8_t*) pos) + len);
+}
+
+static inline struct descriptor *
+ atsc_dcct_term_descriptors_first(struct atsc_dcct_term *term)
+{
+ size_t pos = sizeof(struct atsc_dcct_term);
+
+ if (term->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) term) + pos);
+}
+
+static inline struct descriptor *
+ atsc_dcct_term_descriptors_next(struct atsc_dcct_term *term,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) term + sizeof(struct atsc_dcct_term),
+ term->descriptors_length,
+ pos);
+}
+
+static inline struct descriptor *
+ atsc_dcct_test_part2_descriptors_first(struct atsc_dcct_test_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_dcct_test_part2);
+
+ if (part2->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct descriptor *
+ atsc_dcct_test_part2_descriptors_next(struct atsc_dcct_test_part2 *part2,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_dcct_test_part2),
+ part2->descriptors_length,
+ pos);
+}
+
+static inline struct descriptor *
+ atsc_dcct_section_part2_descriptors_first(struct atsc_dcct_section_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_dcct_section_part2);
+
+ if (part2->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct descriptor *
+ atsc_dcct_section_part2_descriptors_next(struct atsc_dcct_section_part2 *part2,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_dcct_section_part2),
+ part2->descriptors_length,
+ pos);
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/descriptor.h b/lib/libucsi/atsc/descriptor.h
new file mode 100644
index 0000000..a57176a
--- /dev/null
+++ b/lib/libucsi/atsc/descriptor.h
@@ -0,0 +1,68 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_DESCRIPTOR_H
+#define _UCSI_ATSC_DESCRIPTOR_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/endianops.h>
+#include <libucsi/atsc/stuffing_descriptor.h>
+#include <libucsi/atsc/ac3_descriptor.h>
+#include <libucsi/atsc/caption_service_descriptor.h>
+#include <libucsi/atsc/component_name_descriptor.h>
+#include <libucsi/atsc/content_advisory_descriptor.h>
+#include <libucsi/atsc/dcc_arriving_request_descriptor.h>
+#include <libucsi/atsc/dcc_departing_request_descriptor.h>
+#include <libucsi/atsc/extended_channel_name_descriptor.h>
+#include <libucsi/atsc/genre_descriptor.h>
+#include <libucsi/atsc/rc_descriptor.h>
+#include <libucsi/atsc/service_location_descriptor.h>
+#include <libucsi/atsc/time_shifted_service_descriptor.h>
+
+/**
+ * Enumeration of ATSC descriptor tags.
+ */
+enum atsc_descriptor_tag {
+ dtag_atsc_stuffing = 0x80,
+ dtag_atsc_ac3_audio = 0x81,
+ dtag_atsc_caption_service = 0x86,
+ dtag_atsc_content_advisory = 0x87,
+ dtag_atsc_extended_channel_name = 0xa0,
+ dtag_atsc_service_location = 0xa1,
+ dtag_atsc_time_shifted_service = 0xa2,
+ dtag_atsc_component_name = 0xa3,
+ dtag_atsc_dcc_departing_request = 0xa8,
+ dtag_atsc_dcc_arriving_request = 0xa9,
+ dtag_atsc_redistribution_control = 0xaa,
+ dtag_atsc_private_information = 0xad,
+ dtag_atsc_content_identifier = 0xb6,
+ dtag_atsc_genre = 0xab,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/eit_section.c b/lib/libucsi/atsc/eit_section.c
new file mode 100644
index 0000000..48cdda6
--- /dev/null
+++ b/lib/libucsi/atsc/eit_section.c
@@ -0,0 +1,71 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/atsc/eit_section.h>
+
+struct atsc_eit_section *atsc_eit_section_codec(struct atsc_section_psip *psip)
+{
+ uint8_t * buf = (uint8_t *) psip;
+ size_t pos = 0;
+ size_t len = section_ext_length(&(psip->ext_head));
+ int idx;
+
+ if (len < sizeof(struct atsc_eit_section))
+ return NULL;
+ struct atsc_eit_section *eit = (struct atsc_eit_section *) psip;
+
+ pos += sizeof(struct atsc_eit_section);
+ for(idx =0; idx < eit->num_events_in_section; idx++) {
+ if (len < (pos + sizeof(struct atsc_eit_event)))
+ return NULL;
+ struct atsc_eit_event *event = (struct atsc_eit_event *) (buf+pos);
+
+ bswap16(buf+pos);
+ bswap32(buf+pos+2);
+ bswap32(buf+pos+6);
+
+ pos += sizeof(struct atsc_eit_event);
+ if (len < (pos + event->title_length))
+ return NULL;
+ if (atsc_text_validate(buf+pos, event->title_length))
+ return NULL;
+
+ pos += event->title_length;
+ if (len < (pos + sizeof(struct atsc_eit_event_part2)))
+ return NULL;
+ struct atsc_eit_event_part2 *part2 = (struct atsc_eit_event_part2 *) (buf+pos);
+
+ bswap16(buf+pos);
+
+ pos += sizeof(struct atsc_eit_event_part2);
+ if (len < (pos + part2->descriptors_length))
+ return NULL;
+
+ if (verify_descriptors(buf + pos, part2->descriptors_length))
+ return NULL;
+ pos += part2->descriptors_length;
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return (struct atsc_eit_section *) psip;
+}
diff --git a/lib/libucsi/atsc/eit_section.h b/lib/libucsi/atsc/eit_section.h
new file mode 100644
index 0000000..84bef16
--- /dev/null
+++ b/lib/libucsi/atsc/eit_section.h
@@ -0,0 +1,191 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_EIT_SECTION_H
+#define _UCSI_ATSC_EIT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/atsc/section.h>
+#include <libucsi/atsc/types.h>
+
+/**
+ * atsc_eit_section structure.
+ */
+struct atsc_eit_section {
+ struct atsc_section_psip head;
+
+ uint8_t num_events_in_section;
+ /* struct atsc_eit_event events[] */
+} __ucsi_packed;
+
+struct atsc_eit_event {
+ EBIT2(uint16_t reserved : 2; ,
+ uint16_t event_id :14; );
+ atsctime_t start_time;
+ EBIT4(uint32_t reserved1 : 2; ,
+ uint32_t ETM_location : 2; ,
+ uint32_t length_in_seconds :20; ,
+ uint32_t title_length : 8; );
+ /* struct atsc_text title_text */
+ /* struct atsc_eit_event_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_eit_event_part2 {
+ EBIT2(uint16_t reserved : 4; ,
+ uint16_t descriptors_length :12; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+
+/**
+ * Process a atsc_eit_section.
+ *
+ * @param section Pointer to an atsc_section_psip structure.
+ * @return atsc_eit_section pointer, or NULL on error.
+ */
+struct atsc_eit_section *atsc_eit_section_codec(struct atsc_section_psip *section);
+
+/**
+ * Accessor for the source_id field of an EIT.
+ *
+ * @param eit EIT pointer.
+ * @return The source_id .
+ */
+static inline uint16_t atsc_eit_section_source_id(struct atsc_eit_section *eit)
+{
+ return eit->head.ext_head.table_id_ext;
+}
+
+/**
+ * Iterator for the events field in an atsc_eit_section.
+ *
+ * @param eit atsc_eit_section pointer.
+ * @param pos Variable containing a pointer to the current atsc_eit_event.
+ * @param idx Integer used to count which event we are in.
+ */
+#define atsc_eit_section_events_for_each(eit, pos, idx) \
+ for ((pos) = atsc_eit_section_events_first(eit), idx=0; \
+ (pos); \
+ (pos) = atsc_eit_section_events_next(eit, pos, ++idx))
+
+/**
+ * Accessor for the title_text field of an atsc_eit_event.
+ *
+ * @param event atsc_eit_event pointer.
+ * @return struct atsc_text pointer, or NULL on error.
+ */
+static inline struct atsc_text *atsc_eit_event_name_title_text(struct atsc_eit_event *event)
+{
+ if (event->title_length == 0)
+ return NULL;
+
+ return (struct atsc_text*)(((uint8_t*) event) + sizeof(struct atsc_eit_event));
+}
+
+/**
+ * Accessor for the part2 field of an atsc_eit_event.
+ *
+ * @param event atsc_eit_event pointer.
+ * @return struct atsc_eit_event_part2 pointer.
+ */
+static inline struct atsc_eit_event_part2 *atsc_eit_event_part2(struct atsc_eit_event *event)
+{
+ return (struct atsc_eit_event_part2 *)
+ (((uint8_t*) event) + sizeof(struct atsc_eit_event) + event->title_length);
+}
+
+/**
+ * Iterator for the descriptors field in a atsc_eit_section structure.
+ *
+ * @param part2 atsc_eit_event_part2 pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_eit_event_part2_descriptors_for_each(part2, pos) \
+ for ((pos) = atsc_eit_event_part2_descriptors_first(part2); \
+ (pos); \
+ (pos) = atsc_eit_event_part2_descriptors_next(part2, pos))
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_eit_event *
+ atsc_eit_section_events_first(struct atsc_eit_section *eit)
+{
+ size_t pos = sizeof(struct atsc_eit_section);
+
+ if (eit->num_events_in_section == 0)
+ return NULL;
+
+ return (struct atsc_eit_event*) (((uint8_t *) eit) + pos);
+}
+
+static inline struct atsc_eit_event *
+ atsc_eit_section_events_next(struct atsc_eit_section *eit,
+ struct atsc_eit_event *pos,
+ int idx)
+{
+ if (idx >= eit->num_events_in_section)
+ return NULL;
+
+ struct atsc_eit_event_part2 *part2 = atsc_eit_event_part2(pos);
+ int len = sizeof(struct atsc_eit_event_part2);
+ len += part2->descriptors_length;
+
+ return (struct atsc_eit_event *) (((uint8_t*) part2) + len);
+}
+
+static inline struct descriptor *
+ atsc_eit_event_part2_descriptors_first(struct atsc_eit_event_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_eit_event_part2);
+
+ if (part2->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct descriptor *
+ atsc_eit_event_part2_descriptors_next(struct atsc_eit_event_part2 *part2,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_eit_event_part2),
+ part2->descriptors_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/ett_section.c b/lib/libucsi/atsc/ett_section.c
new file mode 100644
index 0000000..ab2ff9c
--- /dev/null
+++ b/lib/libucsi/atsc/ett_section.c
@@ -0,0 +1,42 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/atsc/ett_section.h>
+#include <libucsi/atsc/types.h>
+
+struct atsc_ett_section *atsc_ett_section_codec(struct atsc_section_psip *psip)
+{
+ uint8_t * buf = (uint8_t *) psip;
+ size_t pos = sizeof(struct atsc_section_psip);
+ size_t len = section_ext_length(&(psip->ext_head));
+
+ if (len < sizeof(struct atsc_ett_section))
+ return NULL;
+
+ bswap32(buf + pos);
+ pos += 4;
+
+ if (atsc_text_validate(buf + pos,
+ section_ext_length(&psip->ext_head) - sizeof(struct atsc_ett_section)))
+ return NULL;
+
+ return (struct atsc_ett_section *) psip;
+}
diff --git a/lib/libucsi/atsc/ett_section.h b/lib/libucsi/atsc/ett_section.h
new file mode 100644
index 0000000..e2bb510
--- /dev/null
+++ b/lib/libucsi/atsc/ett_section.h
@@ -0,0 +1,91 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_ETT_SECTION_H
+#define _UCSI_ATSC_ETT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/atsc/section.h>
+
+enum atsc_etm_type {
+ ATSC_ETM_CHANNEL = 0x00,
+ ATSC_ETM_EVENT = 0x02,
+};
+
+/**
+ * atsc_ett_section structure.
+ */
+struct atsc_ett_section {
+ struct atsc_section_psip head;
+
+ EBIT3(uint32_t ETM_source_id :16; ,
+ uint32_t ETM_sub_id :14; ,
+ uint32_t ETM_type : 2; );
+ /* struct atsc_text extended_text_message */
+} __ucsi_packed;
+
+/**
+ * Process a atsc_ett_section.
+ *
+ * @param section Pointer to an atsc_section_psip structure.
+ * @return atsc_ett_section pointer, or NULL on error.
+ */
+struct atsc_ett_section *atsc_ett_section_codec(struct atsc_section_psip *section);
+
+/**
+ * Accessor for the extended_text_message part of an atsc_ett_section.
+ *
+ * @param ett atsc_ett_section pointer.
+ * @return atsc_text pointer, or NULL on error.
+ */
+static inline struct atsc_text*
+ atsc_ett_section_extended_text_message(struct atsc_ett_section *ett)
+{
+ int pos = sizeof(struct atsc_ett_section);
+ int len = section_ext_length(&ett->head.ext_head) - sizeof(struct atsc_ett_section);
+
+ if (len == 0)
+ return NULL;
+
+ return (struct atsc_text*)(((uint8_t*) ett) + pos);
+}
+
+/**
+ * Accessor for the extended_text_message part of an atsc_ett_section.
+ *
+ * @param ett atsc_ett_section pointer.
+ * @return The length.
+ */
+static inline int
+ atsc_ett_section_extended_text_message_length(struct atsc_ett_section *ett)
+{
+ return section_ext_length(&ett->head.ext_head) - sizeof(struct atsc_ett_section);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/extended_channel_name_descriptor.h b/lib/libucsi/atsc/extended_channel_name_descriptor.h
new file mode 100644
index 0000000..d0b714b
--- /dev/null
+++ b/lib/libucsi/atsc/extended_channel_name_descriptor.h
@@ -0,0 +1,92 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_EXTENDED_CHANNEL_NAME_DESCRIPTOR
+#define _UCSI_ATSC_EXTENDED_CHANNEL_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+#include <libucsi/atsc/types.h>
+
+/**
+ * atsc_extended_channel_name_descriptor structure.
+ */
+struct atsc_extended_channel_name_descriptor {
+ struct descriptor d;
+
+ /* struct atsc_text text[] */
+} __ucsi_packed;
+
+/**
+ * Process an atsc_extended_channel_name_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_extended_channel_name_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_extended_channel_name_descriptor*
+ atsc_extended_channel_name_descriptor_codec(struct descriptor* d)
+{
+ if (atsc_text_validate(((uint8_t*) d) + sizeof(struct atsc_extended_channel_name_descriptor),
+ d->len))
+ return NULL;
+
+ return (struct atsc_extended_channel_name_descriptor*) d;
+}
+
+/**
+ * Accessor for the text field of an atsc_extended_channel_name_descriptor.
+ *
+ * @param d atsc_extended_channel_name_descriptor pointer.
+ * @return Pointer to the atsc_text data, or NULL on error.
+ */
+static inline struct atsc_text*
+ atsc_extended_channel_name_descriptor_text(struct atsc_extended_channel_name_descriptor *d)
+{
+ uint8_t *txt = ((uint8_t*) d) + sizeof(struct atsc_extended_channel_name_descriptor);
+
+ return (struct atsc_text*) txt;
+}
+
+/**
+ * Accessor for the length of the text field of an atsc_extended_channel_name_descriptor.
+ *
+ * @param d atsc_extended_channel_name_descriptor pointer.
+ * @return The length in bytes.
+ */
+static inline int
+ atsc_extended_channel_name_descriptor_text_length(struct
+ atsc_extended_channel_name_descriptor *d)
+{
+ return d->d.len;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/genre_descriptor.h b/lib/libucsi/atsc/genre_descriptor.h
new file mode 100644
index 0000000..a6fc542
--- /dev/null
+++ b/lib/libucsi/atsc/genre_descriptor.h
@@ -0,0 +1,82 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_GENRE_DESCRIPTOR
+#define _UCSI_ATSC_GENRE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * atsc_genre_descriptor structure.
+ */
+struct atsc_genre_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t reserved : 3; ,
+ uint8_t attribute_count : 5; );
+ /* uint8_t attributes[] */
+} __ucsi_packed;
+
+/**
+ * Process an atsc_genre_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_genre_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_genre_descriptor*
+ atsc_genre_descriptor_codec(struct descriptor* d)
+{
+ struct atsc_genre_descriptor *ret =
+ (struct atsc_genre_descriptor *) d;
+
+ if (d->len < 1)
+ return NULL;
+
+ if (d->len != (1 + ret->attribute_count))
+ return NULL;
+
+ return (struct atsc_genre_descriptor*) d;
+}
+
+/**
+ * Accessor for the attributes field of an atsc_genre_descriptor.
+ *
+ * @param d atsc_genre_descriptor pointer.
+ * @return Pointer to the attributes.
+ */
+static inline uint8_t*
+ atsc_genre_descriptor_attributes(struct atsc_genre_descriptor *d)
+{
+ return ((uint8_t*) d) + sizeof(struct atsc_genre_descriptor);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/mgt_section.c b/lib/libucsi/atsc/mgt_section.c
new file mode 100644
index 0000000..bc6b3f2
--- /dev/null
+++ b/lib/libucsi/atsc/mgt_section.c
@@ -0,0 +1,76 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/atsc/mgt_section.h>
+
+struct atsc_mgt_section *atsc_mgt_section_codec(struct atsc_section_psip *psip)
+{
+ uint8_t * buf = (uint8_t *) psip;
+ size_t pos = sizeof(struct atsc_section_psip);
+ size_t len = section_ext_length(&(psip->ext_head));
+ struct atsc_mgt_section *mgt = (struct atsc_mgt_section *) psip;
+ int i;
+
+ if (len < sizeof(struct atsc_mgt_section))
+ return NULL;
+
+ bswap16(buf + pos);
+ pos += 2;
+
+ // we cannot use the tables_defined value here because of the braindead ATSC spec!
+ for(i=0; i < mgt->tables_defined; i++) {
+ // we think we're still in the tables - process as normal
+ if ((pos + sizeof(struct atsc_mgt_table)) > len)
+ return NULL;
+ struct atsc_mgt_table *table = (struct atsc_mgt_table *) (buf+pos);
+
+ bswap16(buf+pos);
+ bswap16(buf+pos+2);
+ bswap32(buf+pos+5);
+ bswap16(buf+pos+9);
+
+ pos += sizeof(struct atsc_mgt_table);
+ if ((pos + table->table_type_descriptors_length) > len)
+ return NULL;
+ if (verify_descriptors(buf + pos, table->table_type_descriptors_length))
+ return NULL;
+
+ pos += table->table_type_descriptors_length;
+ }
+
+ if ((pos + sizeof(struct atsc_mgt_section_part2)) > len)
+ return NULL;
+ struct atsc_mgt_section_part2 *part2 = (struct atsc_mgt_section_part2 *) (buf+pos);
+
+ bswap16(buf+pos);
+
+ pos += sizeof(struct atsc_mgt_section_part2);
+ if ((pos + part2->descriptors_length) > len)
+ return NULL;
+ if (verify_descriptors(buf + pos, part2->descriptors_length))
+ return NULL;
+ pos += part2->descriptors_length;
+
+ if (pos != len)
+ return NULL;
+
+ return (struct atsc_mgt_section *) psip;
+}
diff --git a/lib/libucsi/atsc/mgt_section.h b/lib/libucsi/atsc/mgt_section.h
new file mode 100644
index 0000000..3102a54
--- /dev/null
+++ b/lib/libucsi/atsc/mgt_section.h
@@ -0,0 +1,215 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_MGT_SECTION_H
+#define _UCSI_ATSC_MGT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/atsc/section.h>
+
+enum atsc_mgt_section_table_type {
+ ATSC_MGT_TABLE_TYPE_TVCT_CURRENT = 0,
+ ATSC_MGT_TABLE_TYPE_TVCT_NEXT = 1,
+ ATSC_MGT_TABLE_TYPE_CVCT_CURRENT = 2,
+ ATSC_MGT_TABLE_TYPE_CVCT_NEXT = 3,
+ ATSC_MGT_TABLE_TYPE_CHANNEL_ETT = 4,
+ ATSC_MGT_TABLE_TYPE_DCCSCT = 5,
+};
+
+/**
+ * atsc_mgt_section structure.
+ */
+struct atsc_mgt_section {
+ struct atsc_section_psip head;
+
+ uint16_t tables_defined;
+ /* struct atsc_mgt_table tables[] */
+ /* struct atsc_mgt_section_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_mgt_table {
+ uint16_t table_type;
+ EBIT2(uint16_t reserved : 3; ,
+ uint16_t table_type_PID :13; );
+ EBIT2(uint8_t reserved1 : 3; ,
+ uint8_t table_type_version_number : 5; );
+ uint32_t number_bytes;
+ EBIT2(uint16_t reserved2 : 4; ,
+ uint16_t table_type_descriptors_length :12; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+struct atsc_mgt_section_part2 {
+ EBIT2(uint16_t reserved : 4; ,
+ uint16_t descriptors_length :12; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+static inline struct atsc_mgt_table * atsc_mgt_section_tables_first(struct atsc_mgt_section *mgt);
+static inline struct atsc_mgt_table *
+ atsc_mgt_section_tables_next(struct atsc_mgt_section *mgt, struct atsc_mgt_table *pos, int idx);
+
+/**
+ * Process a atsc_mgt_section.
+ *
+ * @param section Pointer to an atsc_section_psip structure.
+ * @return atsc_mgt_section pointer, or NULL on error.
+ */
+struct atsc_mgt_section *atsc_mgt_section_codec(struct atsc_section_psip *section);
+
+/**
+ * Iterator for the tables field in an atsc_mgt_section.
+ *
+ * @param mgt atsc_mgt_section pointer.
+ * @param pos Variable containing a pointer to the current atsc_mgt_table.
+ * @param idx Integer used to count which table we in.
+ */
+#define atsc_mgt_section_tables_for_each(mgt, pos, idx) \
+ for ((pos) = atsc_mgt_section_tables_first(mgt), idx=0; \
+ (pos); \
+ (pos) = atsc_mgt_section_tables_next(mgt, pos, ++idx))
+
+/**
+ * Iterator for the descriptors field in a atsc_mgt_table structure.
+ *
+ * @param table atsc_mgt_table pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_mgt_table_descriptors_for_each(table, pos) \
+ for ((pos) = atsc_mgt_table_descriptors_first(table); \
+ (pos); \
+ (pos) = atsc_mgt_table_descriptors_next(table, pos))
+
+/**
+ * Accessor for the second part of an atsc_mgt_section.
+ *
+ * @param mgt atsc_mgt_section pointer.
+ * @return atsc_mgt_section_part2 pointer.
+ */
+static inline struct atsc_mgt_section_part2 *
+ atsc_mgt_section_part2(struct atsc_mgt_section *mgt)
+{
+ int pos = sizeof(struct atsc_mgt_section);
+
+ struct atsc_mgt_table *cur_table;
+ int idx;
+ atsc_mgt_section_tables_for_each(mgt, cur_table, idx) {
+ pos += sizeof(struct atsc_mgt_table);
+ pos += cur_table->table_type_descriptors_length;
+ }
+
+ return (struct atsc_mgt_section_part2 *) (((uint8_t*) mgt) + pos);
+}
+
+/**
+ * Iterator for the descriptors field in a atsc_mgt_section structure.
+ *
+ * @param part2 atsc_mgt_section_part2 pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_mgt_section_part2_descriptors_for_each(part2, pos) \
+ for ((pos) = atsc_mgt_section_part2_descriptors_first(part2); \
+ (pos); \
+ (pos) = atsc_mgt_section_part2_descriptors_next(part2, pos))
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_mgt_table *
+ atsc_mgt_section_tables_first(struct atsc_mgt_section *mgt)
+{
+ size_t pos = sizeof(struct atsc_mgt_section);
+
+ if (mgt->tables_defined == 0)
+ return NULL;
+
+ return (struct atsc_mgt_table*) (((uint8_t *) mgt) + pos);
+}
+
+static inline struct atsc_mgt_table *
+ atsc_mgt_section_tables_next(struct atsc_mgt_section *mgt,
+ struct atsc_mgt_table *pos,
+ int idx)
+{
+ if (idx >= mgt->tables_defined)
+ return NULL;
+
+ return (struct atsc_mgt_table *)
+ (((uint8_t*) pos) + sizeof(struct atsc_mgt_table) + pos->table_type_descriptors_length);
+}
+
+static inline struct descriptor *
+ atsc_mgt_table_descriptors_first(struct atsc_mgt_table *table)
+{
+ size_t pos = sizeof(struct atsc_mgt_table);
+
+ if (table->table_type_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) table) + pos);
+}
+
+static inline struct descriptor *
+ atsc_mgt_table_descriptors_next(struct atsc_mgt_table *table,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) table + sizeof(struct atsc_mgt_table),
+ table->table_type_descriptors_length,
+ pos);
+}
+
+static inline struct descriptor *
+ atsc_mgt_section_part2_descriptors_first(struct atsc_mgt_section_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_mgt_section_part2);
+
+ if (part2->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct descriptor *
+ atsc_mgt_section_part2_descriptors_next(struct atsc_mgt_section_part2 *part2,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_mgt_section_part2),
+ part2->descriptors_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/rc_descriptor.h b/lib/libucsi/atsc/rc_descriptor.h
new file mode 100644
index 0000000..4fb0e8e
--- /dev/null
+++ b/lib/libucsi/atsc/rc_descriptor.h
@@ -0,0 +1,83 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_RC_DESCRIPTOR
+#define _UCSI_ATSC_RC_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * atsc_rc_descriptor structure.
+ */
+struct atsc_rc_descriptor {
+ struct descriptor d;
+
+ /* uint8_t info[] */
+} __ucsi_packed;
+
+/**
+ * Process an atsc_rc_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_rc_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_rc_descriptor*
+ atsc_rc_descriptor_codec(struct descriptor* d)
+{
+ return (struct atsc_rc_descriptor*) d;
+}
+
+/**
+ * Accessor for the info field of an atsc_rc_descriptor.
+ *
+ * @param d atsc_rc_descriptor pointer.
+ * @return Pointer to the atsc_text data.
+ */
+static inline uint8_t*
+ atsc_rc_descriptor_info(struct atsc_rc_descriptor *d)
+{
+ return ((uint8_t*) d) + sizeof(struct atsc_rc_descriptor);
+}
+
+/**
+ * Accessor for the length of the info field of an atsc_rc_descriptor.
+ *
+ * @param d atsc_rc_descriptor pointer.
+ * @return The length
+ */
+static inline int
+ atsc_rc_descriptor_info_length(struct atsc_rc_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/rrt_section.c b/lib/libucsi/atsc/rrt_section.c
new file mode 100644
index 0000000..6e96c3a
--- /dev/null
+++ b/lib/libucsi/atsc/rrt_section.c
@@ -0,0 +1,108 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/atsc/rrt_section.h>
+
+struct atsc_rrt_section *atsc_rrt_section_codec(struct atsc_section_psip *psip)
+{
+ uint8_t * buf = (uint8_t *) psip;
+ size_t pos = 0;
+ size_t len = section_ext_length(&(psip->ext_head));
+ int idx;
+ int vidx;
+ struct atsc_rrt_section *rrt = (struct atsc_rrt_section *) psip;
+
+ if (len < sizeof(struct atsc_rrt_section))
+ return NULL;
+ pos += sizeof(struct atsc_rrt_section);
+
+ if (len < (pos + rrt->rating_region_name_length))
+ return NULL;
+ if (atsc_text_validate(buf+pos, rrt->rating_region_name_length))
+ return NULL;
+
+ pos += rrt->rating_region_name_length;
+ if (len < (pos + sizeof(struct atsc_rrt_section_part2)))
+ return NULL;
+ struct atsc_rrt_section_part2 *rrtpart2 = (struct atsc_rrt_section_part2 *) (buf+pos);
+
+ pos += sizeof(struct atsc_rrt_section_part2);
+ for(idx =0; idx < rrtpart2->dimensions_defined; idx++) {
+ if (len < (pos + sizeof(struct atsc_rrt_dimension)))
+ return NULL;
+ struct atsc_rrt_dimension *dimension = (struct atsc_rrt_dimension *) (buf+pos);
+
+ pos += sizeof(struct atsc_rrt_dimension);
+ if (len < (pos + dimension->dimension_name_length))
+ return NULL;
+ if (atsc_text_validate(buf+pos, dimension->dimension_name_length))
+ return NULL;
+
+ pos += dimension->dimension_name_length;
+ if (len < (pos + sizeof(struct atsc_rrt_dimension_part2)))
+ return NULL;
+ struct atsc_rrt_dimension_part2 *dpart2 = (struct atsc_rrt_dimension_part2 *) (buf+pos);
+
+ pos += sizeof(struct atsc_rrt_dimension_part2);
+ for(vidx =0; vidx < dpart2->values_defined; vidx++) {
+ if (len < (pos + sizeof(struct atsc_rrt_dimension_value)))
+ return NULL;
+ struct atsc_rrt_dimension_value *value = (struct atsc_rrt_dimension_value *) (buf+pos);
+
+ pos += sizeof(struct atsc_rrt_dimension_value);
+ if (len < (pos + value->abbrev_rating_value_length))
+ return NULL;
+ if (atsc_text_validate(buf+pos, value->abbrev_rating_value_length))
+ return NULL;
+
+ pos += value->abbrev_rating_value_length;
+ if (len < (pos + sizeof(struct atsc_rrt_dimension_value_part2)))
+ return NULL;
+ struct atsc_rrt_dimension_value_part2 *vpart2 =
+ (struct atsc_rrt_dimension_value_part2 *) (buf+pos);
+
+ pos += sizeof(struct atsc_rrt_dimension_value_part2);
+ if (len < (pos + vpart2->rating_value_length))
+ return NULL;
+ if (atsc_text_validate(buf+pos, vpart2->rating_value_length))
+ return NULL;
+
+ pos+= vpart2->rating_value_length;
+ }
+ }
+
+ if (len < (pos + sizeof(struct atsc_rrt_section_part3)))
+ return NULL;
+ struct atsc_rrt_section_part3 *part3 = (struct atsc_rrt_section_part3 *) (buf+pos);
+
+ pos += sizeof(struct atsc_rrt_section_part3);
+ if (len < (pos + part3->descriptors_length))
+ return NULL;
+
+ if (verify_descriptors(buf + pos, part3->descriptors_length))
+ return NULL;
+
+ pos += part3->descriptors_length;
+ if (pos != len)
+ return NULL;
+
+ return (struct atsc_rrt_section *) psip;
+}
diff --git a/lib/libucsi/atsc/rrt_section.h b/lib/libucsi/atsc/rrt_section.h
new file mode 100644
index 0000000..fba4596
--- /dev/null
+++ b/lib/libucsi/atsc/rrt_section.h
@@ -0,0 +1,379 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_RRT_SECTION_H
+#define _UCSI_ATSC_RRT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/atsc/section.h>
+#include <libucsi/atsc/types.h>
+
+/**
+ * atsc_rrt_section structure.
+ */
+struct atsc_rrt_section {
+ struct atsc_section_psip head;
+
+ uint8_t rating_region_name_length;
+ /* struct atsc_text rating_region_name_text */
+ /* struct atsc_rrt_section_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_rrt_section_part2 {
+ uint8_t dimensions_defined;
+ /* struct atsc_rrt_dimension dimensions[] */
+ /* struct atsc_rrt_section_part3 part3 */
+} __ucsi_packed;
+
+struct atsc_rrt_dimension {
+ uint8_t dimension_name_length;
+ /* struct atsc_text dimension_name_text */
+ /* struct atsc_rrt_dimension_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_rrt_dimension_part2 {
+ EBIT3(uint8_t reserved : 3; ,
+ uint8_t graduated_scale : 1; ,
+ uint8_t values_defined : 4; );
+ /* struct atsc_rrt_dimension_value values[] */
+} __ucsi_packed;
+
+struct atsc_rrt_dimension_value {
+ uint8_t abbrev_rating_value_length;
+ /* struct atsc_text abbrev_rating_value_text */
+ /* struct atsc_rrt_dimension_value_part2 */
+} __ucsi_packed;
+
+struct atsc_rrt_dimension_value_part2 {
+ uint8_t rating_value_length;
+ /* struct atsc_text rating_value_text */
+} __ucsi_packed;
+
+struct atsc_rrt_section_part3 {
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+
+static inline struct atsc_rrt_dimension *
+ atsc_rrt_section_dimensions_first(struct atsc_rrt_section_part2 *part2);
+static inline struct atsc_rrt_dimension *
+ atsc_rrt_section_dimensions_next(struct atsc_rrt_section_part2 *part2,
+ struct atsc_rrt_dimension *pos,
+ int idx);
+static inline struct atsc_rrt_dimension_value *
+ atsc_rrt_dimension_part2_values_first(struct atsc_rrt_dimension_part2 *part2);
+static inline struct atsc_rrt_dimension_value *
+ atsc_rrt_dimension_part2_values_next(struct atsc_rrt_dimension_part2 *part2,
+ struct atsc_rrt_dimension_value *pos,
+ int idx);
+
+/**
+ * Process a atsc_rrt_section.
+ *
+ * @param section Pointer to anj atsc_section_psip structure.
+ * @return atsc_rrt_section pointer, or NULL on error.
+ */
+struct atsc_rrt_section *atsc_rrt_section_codec(struct atsc_section_psip *section);
+
+/**
+ * Accessor for the rating_region field of an RRT.
+ *
+ * @param rrt RRT pointer.
+ * @return The transport_stream_id.
+ */
+static inline uint8_t atsc_rrt_section_rating_region(struct atsc_rrt_section *rrt)
+{
+ return rrt->head.ext_head.table_id_ext & 0xff;
+}
+
+/**
+ * Accessor for the rating_region_name_text field of an RRT.
+ *
+ * @param rrt RRT pointer.
+ * @return struct atsc_text pointer, or NULL.
+ */
+static inline struct atsc_text *atsc_rrt_section_rating_region_name_text(struct atsc_rrt_section *rrt)
+{
+ if (rrt->rating_region_name_length == 0)
+ return NULL;
+
+ return (struct atsc_text*)(((uint8_t*) rrt) + sizeof(struct atsc_rrt_section));
+}
+
+/**
+ * Accessor for the part2 field of an RRT.
+ *
+ * @param rrt RRT pointer.
+ * @return struct atsc_rrt_section_part2 pointer.
+ */
+static inline struct atsc_rrt_section_part2 *atsc_rrt_section_part2(struct atsc_rrt_section *rrt)
+{
+ return (struct atsc_rrt_section_part2 *)
+ (((uint8_t*) rrt) + sizeof(struct atsc_rrt_section) +
+ rrt->rating_region_name_length);
+}
+
+/**
+ * Iterator for the dimensions field in an atsc_rrt_section_part2.
+ *
+ * @param rrt atsc_rrt_section pointer.
+ * @param pos Variable containing a pointer to the current atsc_rrt_dimension.
+ * @param idx Integer used to count which dimension we are in.
+ */
+#define atsc_rrt_section_dimensions_for_each(rrt, pos, idx) \
+ for ((pos) = atsc_rrt_section_dimensions_first(rrt), idx=0; \
+ (pos); \
+ (pos) = atsc_rrt_section_dimensions_next(rrt, pos, ++idx))
+
+/**
+ * Accessor for the dimension_name_text field of an atsc_rrt_dimension.
+ *
+ * @param dimension atsc_rrt_dimension pointer.
+ * @return struct atsc_text pointer, or NULL on error.
+ */
+static inline struct atsc_text *atsc_rrt_dimension_name_text(struct atsc_rrt_dimension *dimension)
+{
+ if (dimension->dimension_name_length == 0)
+ return NULL;
+
+ return (struct atsc_text*)(((uint8_t*) dimension) + sizeof(struct atsc_rrt_dimension));
+}
+
+/**
+ * Accessor for the part2 field of an atsc_rrt_dimension.
+ *
+ * @param dimension atsc_rrt_dimension pointer.
+ * @return struct atsc_rrt_dimension_part2 pointer.
+ */
+static inline struct atsc_rrt_dimension_part2 *atsc_rrt_dimension_part2(struct atsc_rrt_dimension *dimension)
+{
+ return (struct atsc_rrt_dimension_part2 *)
+ (((uint8_t*) dimension) +
+ sizeof(struct atsc_rrt_dimension) +
+ dimension->dimension_name_length);
+}
+
+/**
+ * Iterator for the values field in a atsc_rrt_dimension_part2 structure.
+ *
+ * @param part2 atsc_rrt_dimension_part2 pointer.
+ * @param pos Variable containing a pointer to the current value.
+ * @param idx Integer used to count which value we are in
+ */
+#define atsc_rrt_dimension_part2_values_for_each(part2, pos, idx) \
+ for ((pos) = atsc_rrt_dimension_part2_values_first(part2), idx=0; \
+ (pos); \
+ (pos) = atsc_rrt_dimension_part2_values_next(part2, pos, ++idx))
+
+/**
+ * Accessor for the dimension_name_text field of an atsc_rrt_dimension.
+ *
+ * @param dimension atsc_rrt_dimension pointer.
+ * @return struct atsc_text pointer.
+ */
+static inline struct atsc_text *
+ atsc_rrt_dimension_value_abbrev_rating_value_text(struct atsc_rrt_dimension_value *value)
+{
+ if (value->abbrev_rating_value_length == 0)
+ return NULL;
+
+ return (struct atsc_text*)(((uint8_t*) value) + sizeof(struct atsc_rrt_dimension_value));
+}
+
+/**
+ * Accessor for the part2 field of an atsc_rrt_dimension_value.
+ *
+ * @param value atsc_rrt_dimension_value pointer.
+ * @return struct atsc_rrt_dimension_value_part2 pointer.
+ */
+static inline struct atsc_rrt_dimension_value_part2 *atsc_rrt_dimension_value_part2(struct atsc_rrt_dimension_value *value)
+{
+ return (struct atsc_rrt_dimension_value_part2 *)
+ (((uint8_t*) value) +
+ sizeof(struct atsc_rrt_dimension_value) +
+ value->abbrev_rating_value_length);
+}
+
+/**
+ * Accessor for the rating_value_text field of an atsc_rrt_dimension_value_part2.
+ *
+ * @param part2 atsc_rrt_dimension_value_part2 pointer.
+ * @return struct atsc_text pointer.
+ */
+static inline struct atsc_text *atsc_rrt_dimension_value_part2_rating_value_text(struct atsc_rrt_dimension_value_part2 *part2)
+{
+ if (part2->rating_value_length == 0)
+ return NULL;
+
+ return (struct atsc_text*)(((uint8_t*) part2) + sizeof(struct atsc_rrt_dimension_value_part2));
+}
+
+/**
+ * Accessor for the third part of an atsc_rrt_section.
+ *
+ * @param part2 atsc_rrt_section_part2 pointer.
+ * @return atsc_rrt_section_part3 pointer.
+ */
+static inline struct atsc_rrt_section_part3 *
+ atsc_rrt_section_part3(struct atsc_rrt_section_part2 *part2)
+{
+ int pos = sizeof(struct atsc_rrt_section_part2);
+
+ struct atsc_rrt_dimension *cur_dimension;
+ int idx;
+ atsc_rrt_section_dimensions_for_each(part2, cur_dimension, idx) {
+ pos += sizeof(struct atsc_rrt_dimension);
+ pos += cur_dimension->dimension_name_length;
+ pos += sizeof(struct atsc_rrt_dimension_part2);
+
+ // now we need to iterate over the values. yuck
+ struct atsc_rrt_dimension_part2 *dpart2 = atsc_rrt_dimension_part2(cur_dimension);
+ struct atsc_rrt_dimension_value *cur_value;
+ int vidx;
+ atsc_rrt_dimension_part2_values_for_each(dpart2, cur_value, vidx) {
+ pos += sizeof(struct atsc_rrt_dimension_value);
+ pos += cur_value->abbrev_rating_value_length;
+
+ struct atsc_rrt_dimension_value_part2 *vpart2 = atsc_rrt_dimension_value_part2(cur_value);
+ pos += sizeof(struct atsc_rrt_dimension_value_part2);
+ pos += vpart2->rating_value_length;
+ }
+ }
+
+ return (struct atsc_rrt_section_part3 *) (((uint8_t*) part2) + pos);
+}
+
+/**
+ * Iterator for the descriptors field in a atsc_rrt_section structure.
+ *
+ * @param part3 atsc_rrt_section_part3 pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_rrt_section_part3_descriptors_for_each(part3, pos) \
+ for ((pos) = atsc_rrt_section_part3_descriptors_first(part3); \
+ (pos); \
+ (pos) = atsc_rrt_section_part3_descriptors_next(part3, pos))
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_rrt_dimension *
+ atsc_rrt_section_dimensions_first(struct atsc_rrt_section_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_rrt_section_part2);
+
+ if (part2->dimensions_defined == 0)
+ return NULL;
+
+ return (struct atsc_rrt_dimension*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct atsc_rrt_dimension *
+ atsc_rrt_section_dimensions_next(struct atsc_rrt_section_part2 *part2,
+ struct atsc_rrt_dimension *pos,
+ int idx)
+{
+ if (idx >= part2->dimensions_defined)
+ return NULL;
+
+ struct atsc_rrt_dimension_part2 *dpart2 = atsc_rrt_dimension_part2(pos);
+ int len = sizeof(struct atsc_rrt_dimension_part2);
+
+ // now we need to iterate over the values. yuck
+ struct atsc_rrt_dimension_value *cur_value;
+ int vidx;
+ atsc_rrt_dimension_part2_values_for_each(dpart2, cur_value, vidx) {
+ len += sizeof(struct atsc_rrt_dimension_value);
+ len += cur_value->abbrev_rating_value_length;
+
+ struct atsc_rrt_dimension_value_part2 *vpart2 = atsc_rrt_dimension_value_part2(cur_value);
+ len += sizeof(struct atsc_rrt_dimension_value_part2);
+ len += vpart2->rating_value_length;
+ }
+
+ return (struct atsc_rrt_dimension *) (((uint8_t*) dpart2) + len);
+}
+
+static inline struct atsc_rrt_dimension_value *
+ atsc_rrt_dimension_part2_values_first(struct atsc_rrt_dimension_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_rrt_dimension_part2);
+
+ if (part2->values_defined == 0)
+ return NULL;
+
+ return (struct atsc_rrt_dimension_value*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct atsc_rrt_dimension_value *
+ atsc_rrt_dimension_part2_values_next(struct atsc_rrt_dimension_part2 *part2,
+ struct atsc_rrt_dimension_value *pos,
+ int idx)
+{
+ if (idx >= part2->values_defined)
+ return NULL;
+
+ struct atsc_rrt_dimension_value_part2 *vpart2 = atsc_rrt_dimension_value_part2(pos);
+ int len = sizeof(struct atsc_rrt_dimension_value_part2);
+ len += vpart2->rating_value_length;
+
+ return (struct atsc_rrt_dimension_value *) (((uint8_t*) vpart2) + len);
+}
+
+static inline struct descriptor *
+ atsc_rrt_section_part3_descriptors_first(struct atsc_rrt_section_part3 *part3)
+{
+ size_t pos = sizeof(struct atsc_rrt_section_part3);
+
+ if (part3->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) part3) + pos);
+}
+
+static inline struct descriptor *
+ atsc_rrt_section_part3_descriptors_next(struct atsc_rrt_section_part3 *part3,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) part3 + sizeof(struct atsc_rrt_section_part3),
+ part3->descriptors_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/section.h b/lib/libucsi/atsc/section.h
new file mode 100644
index 0000000..23d59ea
--- /dev/null
+++ b/lib/libucsi/atsc/section.h
@@ -0,0 +1,84 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/section.h>
+#include <libucsi/atsc/mgt_section.h>
+#include <libucsi/atsc/tvct_section.h>
+#include <libucsi/atsc/cvct_section.h>
+#include <libucsi/atsc/rrt_section.h>
+#include <libucsi/atsc/eit_section.h>
+#include <libucsi/atsc/ett_section.h>
+#include <libucsi/atsc/stt_section.h>
+#include <libucsi/atsc/dcct_section.h>
+#include <libucsi/atsc/dccsct_section.h>
+
+#ifndef _UCSI_ATSC_SECTION_H
+#define _UCSI_ATSC_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define ATSC_BASE_PID 0x1ffb
+
+/**
+ * Enumeration of ATSC section tags.
+ */
+enum atsc_section_tag {
+ stag_atsc_master_guide = 0xc7,
+ stag_atsc_terrestrial_virtual_channel = 0xc8,
+ stag_atsc_cable_virtual_channel = 0xc9,
+ stag_atsc_rating_region = 0xca,
+ stag_atsc_event_information = 0xcb,
+ stag_atsc_extended_text = 0xcc,
+ stag_atsc_system_time = 0xcd,
+};
+
+/**
+ * ATSC specific PSIP section structure.
+ */
+struct atsc_section_psip {
+ struct section_ext ext_head;
+ uint8_t protocol_version;
+} __ucsi_packed;
+
+/**
+ * Decode a PSIP section structure.
+ *
+ * @param section_ext Pointer to the processed section_ext structure.
+ * @return Pointer to the parsed section_psip structure, or NULL if invalid.
+ */
+static inline struct atsc_section_psip *atsc_section_psip_decode(struct section_ext *section_ext)
+{
+ size_t len = section_ext_length(section_ext);
+ if (len < sizeof(struct atsc_section_psip)) {
+ return NULL;
+ }
+
+ return (struct atsc_section_psip *) section_ext;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/service_location_descriptor.h b/lib/libucsi/atsc/service_location_descriptor.h
new file mode 100644
index 0000000..aad5b4a
--- /dev/null
+++ b/lib/libucsi/atsc/service_location_descriptor.h
@@ -0,0 +1,141 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_SERVICE_LOCATION_DESCRIPTOR
+#define _UCSI_ATSC_SERVICE_LOCATION_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+enum atsc_stream_types {
+ ATSC_STREAM_TYPE_VIDEO = 0x02,
+ ATSC_STREAM_TYPE_AUDIO = 0x81,
+};
+
+/**
+ * atsc_service_location_descriptor structure.
+ */
+struct atsc_service_location_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint16_t reserved : 3; ,
+ uint16_t PCR_PID :13; );
+ uint8_t number_elements;
+ /* struct atsc_service_location_element elements[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the elements field of an atsc_service_location_descriptor.
+ */
+struct atsc_caption_service_location_element {
+ uint8_t stream_type;
+ EBIT2(uint16_t reserved : 3; ,
+ uint16_t elementary_PID :13; );
+ iso639lang_t language_code;
+} __ucsi_packed;
+
+/**
+ * Process an atsc_service_location_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_service_location_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_service_location_descriptor*
+ atsc_service_location_descriptor_codec(struct descriptor* d)
+{
+ struct atsc_service_location_descriptor *ret =
+ (struct atsc_service_location_descriptor *) d;
+ uint8_t *buf = (uint8_t*) d + 2;
+ int pos = 0;
+ int idx;
+
+ if (d->len < 3)
+ return NULL;
+ bswap16(buf + pos);
+ pos+=3;
+
+ for(idx = 0; idx < ret->number_elements; idx++) {
+ if (d->len < (pos + sizeof(struct atsc_caption_service_entry)))
+ return NULL;
+
+ bswap16(buf+pos+1);
+
+ pos += sizeof(struct atsc_caption_service_entry);
+ }
+
+ return (struct atsc_service_location_descriptor*) d;
+}
+
+/**
+ * Iterator for elements field of a atsc_service_location_descriptor.
+ *
+ * @param d atsc_service_location_descriptor pointer.
+ * @param pos Variable holding a pointer to the current atsc_service_location_element.
+ * @param idx Integer used to count which dimension we are in.
+ */
+#define atsc_service_location_descriptor_elements_for_each(d, pos, idx) \
+ for ((pos) = atsc_service_location_descriptor_elements_first(d), idx=0; \
+ (pos); \
+ (pos) = atsc_service_location_descriptor_elements_next(d, pos, ++idx))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_caption_service_location_element*
+ atsc_service_location_descriptor_elements_first(struct atsc_service_location_descriptor *d)
+{
+ if (d->number_elements == 0)
+ return NULL;
+
+ return (struct atsc_caption_service_location_element *)
+ ((uint8_t*) d + sizeof(struct atsc_service_location_descriptor));
+}
+
+static inline struct atsc_caption_service_location_element*
+ atsc_service_location_descriptor_elements_next(struct atsc_service_location_descriptor *d,
+ struct atsc_caption_service_location_element *pos,
+ int idx)
+{
+ uint8_t *next = (uint8_t *) pos + sizeof(struct atsc_caption_service_location_element);
+
+ if (idx >= d->number_elements)
+ return NULL;
+ return (struct atsc_caption_service_location_element *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/stt_section.c b/lib/libucsi/atsc/stt_section.c
new file mode 100644
index 0000000..23ddd76
--- /dev/null
+++ b/lib/libucsi/atsc/stt_section.c
@@ -0,0 +1,42 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/atsc/stt_section.h>
+
+struct atsc_stt_section *atsc_stt_section_codec(struct atsc_section_psip *psip)
+{
+ uint8_t *buf = (uint8_t *) psip;
+ size_t pos = sizeof(struct atsc_section_psip);
+ size_t len = section_ext_length(&(psip->ext_head));
+
+ if (len < sizeof(struct atsc_stt_section))
+ return NULL;
+
+ bswap32(buf + pos);
+ pos += 5;
+ bswap16(buf + pos);
+ pos += 2;
+
+ if (verify_descriptors(buf + pos, len - sizeof(struct atsc_stt_section)))
+ return NULL;
+
+ return (struct atsc_stt_section *) psip;
+}
diff --git a/lib/libucsi/atsc/stt_section.h b/lib/libucsi/atsc/stt_section.h
new file mode 100644
index 0000000..79db5a1
--- /dev/null
+++ b/lib/libucsi/atsc/stt_section.h
@@ -0,0 +1,105 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_STT_SECTION_H
+#define _UCSI_ATSC_STT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/atsc/section.h>
+#include <libucsi/atsc/types.h>
+
+/**
+ * atsc_stt_section structure.
+ */
+struct atsc_stt_section {
+ struct atsc_section_psip head;
+
+ atsctime_t system_time;
+ uint8_t gps_utc_offset;
+ EBIT4(uint16_t DS_status : 1; ,
+ uint16_t reserved : 2; ,
+ uint16_t DS_day_of_month : 5; ,
+ uint16_t DS_hour : 8; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process a atsc_stt_section.
+ *
+ * @param section Pointer to an atsc_section_psip structure.
+ * @return atsc_stt_section pointer, or NULL on error.
+ */
+struct atsc_stt_section *atsc_stt_section_codec(struct atsc_section_psip *section);
+
+/**
+ * Iterator for the services field in a atsc_stt_section.
+ *
+ * @param stt atsc_stt_section pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_stt_section_descriptors_for_each(stt, pos) \
+ for ((pos) = atsc_stt_section_descriptors_first(stt); \
+ (pos); \
+ (pos) = atsc_stt_section_descriptors_next(stt, pos))
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ atsc_stt_section_descriptors_first(struct atsc_stt_section *stt)
+{
+ size_t pos = sizeof(struct atsc_stt_section);
+
+ if (pos >= section_ext_length(&stt->head.ext_head))
+ return NULL;
+
+ return (struct descriptor*) ((uint8_t *) stt + pos);
+}
+
+static inline struct descriptor *
+ atsc_stt_section_descriptors_next(struct atsc_stt_section *stt,
+ struct descriptor *pos)
+{
+ int len = section_ext_length(&stt->head.ext_head);
+ len -= sizeof(struct atsc_stt_section);
+
+ return next_descriptor((uint8_t*) stt + sizeof(struct atsc_stt_section),
+ len,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/stuffing_descriptor.h b/lib/libucsi/atsc/stuffing_descriptor.h
new file mode 100644
index 0000000..777c282
--- /dev/null
+++ b/lib/libucsi/atsc/stuffing_descriptor.h
@@ -0,0 +1,82 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_atsc@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_STUFFING_DESCRIPTOR
+#define _UCSI_ATSC_STUFFING_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * atsc_stuffing_descriptor.
+ */
+struct atsc_stuffing_descriptor {
+ struct descriptor d;
+
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Process a atsc_stuffing_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return atsc_stuffing_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_stuffing_descriptor*
+ atsc_stuffing_descriptor_codec(struct descriptor* d)
+{
+ return (struct atsc_stuffing_descriptor*) d;
+}
+
+/**
+ * Retrieve a pointer to the data field of a atsc_stuffing_descriptor.
+ *
+ * @param d atsc_stuffing_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ atsc_stuffing_descriptor_data(struct atsc_stuffing_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct atsc_stuffing_descriptor);
+}
+
+/**
+ * Calculate length of the data field of a atsc_stuffing_descriptor.
+ *
+ * @param d atsc_stuffing_descriptor pointer.
+ * @return The length in bytes.
+ */
+static inline int
+ atsc_stuffing_descriptor_data_length(struct atsc_stuffing_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/time_shifted_service_descriptor.h b/lib/libucsi/atsc/time_shifted_service_descriptor.h
new file mode 100644
index 0000000..599e66d
--- /dev/null
+++ b/lib/libucsi/atsc/time_shifted_service_descriptor.h
@@ -0,0 +1,136 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_TIME_SHIFTED_SERVICE_DESCRIPTOR
+#define _UCSI_ATSC_TIME_SHIFTED_SERVICE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * atsc_time_shifted_service_descriptor structure.
+ */
+struct atsc_time_shifted_service_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t reserved : 3; ,
+ uint8_t number_of_services : 5; );
+ /* struct atsc_time_shifted_service services[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the services field of an atsc_time_shifted_service_descriptor.
+ */
+struct atsc_time_shifted_service {
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t time_shift :10; );
+ EBIT3(uint32_t reserved2 : 4; ,
+ uint32_t major_channel_number :10; ,
+ uint32_t minor_channel_number :10; );
+} __ucsi_packed;
+
+/**
+ * Process an atsc_time_shifted_service_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return atsc_time_shifted_service_descriptor pointer, or NULL on error.
+ */
+static inline struct atsc_time_shifted_service_descriptor*
+ atsc_time_shifted_service_descriptor_codec(struct descriptor* d)
+{
+ struct atsc_time_shifted_service_descriptor *ret =
+ (struct atsc_time_shifted_service_descriptor *) d;
+ uint8_t *buf = (uint8_t*) d + 2;
+ int pos = 0;
+ int idx;
+
+ if (d->len < 1)
+ return NULL;
+ pos++;
+
+ for(idx = 0; idx < ret->number_of_services; idx++) {
+ if (d->len < (pos + sizeof(struct atsc_time_shifted_service)))
+ return NULL;
+
+ bswap16(buf+pos);
+ bswap24(buf+pos+2);
+
+ pos += sizeof(struct atsc_time_shifted_service);
+ }
+
+ return (struct atsc_time_shifted_service_descriptor*) d;
+}
+
+/**
+ * Iterator for services field of a atsc_time_shifted_service_descriptor.
+ *
+ * @param d atsc_time_shifted_service_descriptor pointer.
+ * @param pos Variable holding a pointer to the current atsc_service_location_element.
+ * @param idx Integer used to count which service we are in.
+ */
+#define atsc_time_shifted_service_descriptor_services_for_each(d, pos, idx) \
+ for ((pos) = atsc_time_shifted_service_descriptor_services_first(d), idx=0; \
+ (pos); \
+ (pos) = atsc_time_shifted_service_descriptor_services_next(d, pos, ++idx))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_time_shifted_service*
+ atsc_time_shifted_service_descriptor_services_first(struct atsc_time_shifted_service_descriptor *d)
+{
+ if (d->number_of_services == 0)
+ return NULL;
+
+ return (struct atsc_time_shifted_service *)
+ ((uint8_t*) d + sizeof(struct atsc_time_shifted_service_descriptor));
+}
+
+static inline struct atsc_time_shifted_service*
+ atsc_time_shifted_service_descriptor_services_next(struct atsc_time_shifted_service_descriptor *d,
+ struct atsc_time_shifted_service *pos,
+ int idx)
+{
+ uint8_t *next = (uint8_t *) pos + sizeof(struct atsc_time_shifted_service);
+
+ if (idx >= d->number_of_services)
+ return NULL;
+ return (struct atsc_time_shifted_service *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/tvct_section.c b/lib/libucsi/atsc/tvct_section.c
new file mode 100644
index 0000000..d187414
--- /dev/null
+++ b/lib/libucsi/atsc/tvct_section.c
@@ -0,0 +1,81 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/atsc/tvct_section.h>
+
+struct atsc_tvct_section *atsc_tvct_section_codec(struct atsc_section_psip *psip)
+{
+ uint8_t * buf = (uint8_t *) psip;
+ size_t pos = sizeof(struct atsc_section_psip);
+ size_t len = section_ext_length(&(psip->ext_head));
+ int idx;
+ struct atsc_tvct_section *tvct = (struct atsc_tvct_section *) psip;
+
+ if (len < sizeof(struct atsc_tvct_section))
+ return NULL;
+
+ pos++;
+
+ for(idx =0; idx < tvct->num_channels_in_section; idx++) {
+
+ if ((pos + sizeof(struct atsc_tvct_channel)) > len)
+ return NULL;
+ struct atsc_tvct_channel *channel = (struct atsc_tvct_channel *) (buf+pos);
+
+ pos += 7*2;
+
+ bswap32(buf+pos);
+ bswap32(buf+pos+4);
+ bswap16(buf+pos+8);
+ bswap16(buf+pos+10);
+ bswap16(buf+pos+12);
+ bswap16(buf+pos+14);
+ bswap16(buf+pos+16);
+ pos+=18;
+
+ if ((pos + channel->descriptors_length) > len)
+ return NULL;
+ if (verify_descriptors(buf + pos, channel->descriptors_length))
+ return NULL;
+
+ pos += channel->descriptors_length;
+ }
+
+ if ((pos + sizeof(struct atsc_tvct_section_part2)) > len)
+ return NULL;
+ struct atsc_tvct_section_part2 *part2 = (struct atsc_tvct_section_part2 *) (buf+pos);
+
+ bswap16(buf+pos);
+ pos+=2;
+
+ if ((pos + part2->descriptors_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, part2->descriptors_length))
+ return NULL;
+
+ pos += part2->descriptors_length;
+
+ if (pos != len)
+ return NULL;
+
+ return (struct atsc_tvct_section *) psip;
+}
diff --git a/lib/libucsi/atsc/tvct_section.h b/lib/libucsi/atsc/tvct_section.h
new file mode 100644
index 0000000..77bc5f4
--- /dev/null
+++ b/lib/libucsi/atsc/tvct_section.h
@@ -0,0 +1,227 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_TVCT_SECTION_H
+#define _UCSI_ATSC_TVCT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/atsc/section.h>
+
+/**
+ * atsc_tvct_section structure.
+ */
+struct atsc_tvct_section {
+ struct atsc_section_psip head;
+
+ uint8_t num_channels_in_section;
+ /* struct atsc_tvct_channel channels[] */
+ /* struct atsc_tvct_channel_part2 part2 */
+} __ucsi_packed;
+
+struct atsc_tvct_channel {
+ uint16_t short_name[7]; // UTF-16 network ordered
+ EBIT4(uint32_t reserved : 4; ,
+ uint32_t major_channel_number :10; ,
+ uint32_t minor_channel_number :10; ,
+ uint32_t modulation_mode : 8; );
+ uint32_t carrier_frequency;
+ uint16_t channel_TSID;
+ uint16_t program_number;
+ EBIT7(uint16_t ETM_location : 2; ,
+ uint16_t access_controlled : 1; ,
+ uint16_t hidden : 1; ,
+ uint16_t reserved1 : 2; ,
+ uint16_t hide_guide : 1; ,
+ uint16_t reserved2 : 3; ,
+ uint16_t service_type : 6; );
+ uint16_t source_id;
+ EBIT2(uint16_t reserved3 : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+struct atsc_tvct_section_part2 {
+ EBIT2(uint16_t reserved : 6; ,
+ uint16_t descriptors_length :10; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+static inline struct atsc_tvct_channel *atsc_tvct_section_channels_first(struct atsc_tvct_section *tvct);
+static inline struct atsc_tvct_channel *
+ atsc_tvct_section_channels_next(struct atsc_tvct_section *tvct, struct atsc_tvct_channel *pos, int idx);
+
+/**
+ * Process a atsc_tvct_section.
+ *
+ * @param section Pointer to an atsc_section_psip structure.
+ * @return atsc_tvct_section pointer, or NULL on error.
+ */
+struct atsc_tvct_section *atsc_tvct_section_codec(struct atsc_section_psip *section);
+
+/**
+ * Accessor for the transport_stream_id field of a TVCT.
+ *
+ * @param tvct TVCT pointer.
+ * @return The transport_stream_id.
+ */
+static inline uint16_t atsc_tvct_section_transport_stream_id(struct atsc_tvct_section *tvct)
+{
+ return tvct->head.ext_head.table_id_ext;
+}
+
+/**
+ * Iterator for the channels field in an atsc_tvct_section.
+ *
+ * @param mgt atsc_tvct_section pointer.
+ * @param pos Variable containing a pointer to the current atsc_tvct_channel.
+ * @param idx Integer used to count which channel we in.
+ */
+#define atsc_tvct_section_channels_for_each(mgt, pos, idx) \
+ for ((pos) = atsc_tvct_section_channels_first(mgt), idx=0; \
+ (pos); \
+ (pos) = atsc_tvct_section_channels_next(mgt, pos, ++idx))
+
+/**
+ * Iterator for the descriptors field in a atsc_tvct_channel structure.
+ *
+ * @param channel atsc_tvct_channel pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_tvct_channel_descriptors_for_each(channel, pos) \
+ for ((pos) = atsc_tvct_channel_descriptors_first(channel); \
+ (pos); \
+ (pos) = atsc_tvct_channel_descriptors_next(channel, pos))
+
+/**
+ * Accessor for the second part of an atsc_tvct_section.
+ *
+ * @param mgt atsc_tvct_section pointer.
+ * @return atsc_tvct_section_part2 pointer.
+ */
+static inline struct atsc_tvct_section_part2 *
+ atsc_tvct_section_part2(struct atsc_tvct_section *mgt)
+{
+ int pos = sizeof(struct atsc_tvct_section);
+
+ struct atsc_tvct_channel *cur_channel;
+ int idx;
+ atsc_tvct_section_channels_for_each(mgt, cur_channel, idx) {
+ pos += sizeof(struct atsc_tvct_channel);
+ pos += cur_channel->descriptors_length;
+ }
+
+ return (struct atsc_tvct_section_part2 *) (((uint8_t*) mgt) + pos);
+}
+
+/**
+ * Iterator for the descriptors field in a atsc_tvct_section structure.
+ *
+ * @param part2 atsc_tvct_section_part2 pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define atsc_tvct_section_part2_descriptors_for_each(part2, pos) \
+ for ((pos) = atsc_tvct_section_part2_descriptors_first(part2); \
+ (pos); \
+ (pos) = atsc_tvct_section_part2_descriptors_next(part2, pos))
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_tvct_channel *
+ atsc_tvct_section_channels_first(struct atsc_tvct_section *tvct)
+{
+ size_t pos = sizeof(struct atsc_tvct_section);
+
+ if (tvct->num_channels_in_section == 0)
+ return NULL;
+
+ return (struct atsc_tvct_channel*) (((uint8_t *) tvct) + pos);
+}
+
+static inline struct atsc_tvct_channel *
+ atsc_tvct_section_channels_next(struct atsc_tvct_section *tvct,
+ struct atsc_tvct_channel *pos,
+ int idx)
+{
+ if (idx >= tvct->num_channels_in_section)
+ return NULL;
+
+ return (struct atsc_tvct_channel *)
+ (((uint8_t*) pos) + sizeof(struct atsc_tvct_channel) + pos->descriptors_length);
+}
+
+static inline struct descriptor *
+ atsc_tvct_channel_descriptors_first(struct atsc_tvct_channel *channel)
+{
+ size_t pos = sizeof(struct atsc_tvct_channel);
+
+ if (channel->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) channel) + pos);
+}
+
+static inline struct descriptor *
+ atsc_tvct_channel_descriptors_next(struct atsc_tvct_channel *channel,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) channel + sizeof(struct atsc_tvct_channel),
+ channel->descriptors_length,
+ pos);
+}
+
+static inline struct descriptor *
+ atsc_tvct_section_part2_descriptors_first(struct atsc_tvct_section_part2 *part2)
+{
+ size_t pos = sizeof(struct atsc_tvct_section_part2);
+
+ if (part2->descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor*) (((uint8_t *) part2) + pos);
+}
+
+static inline struct descriptor *
+ atsc_tvct_section_part2_descriptors_next(struct atsc_tvct_section_part2 *part2,
+ struct descriptor *pos)
+{
+ return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_tvct_section_part2),
+ part2->descriptors_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/atsc/types.c b/lib/libucsi/atsc/types.c
new file mode 100644
index 0000000..8f4b7ea
--- /dev/null
+++ b/lib/libucsi/atsc/types.c
@@ -0,0 +1,71 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <string.h>
+#include "libucsi/atsc/types.h"
+
+/* GPS epoch == unix time_t at 06/Jan/1980 */
+#define GPS_EPOCH 315964800
+
+
+int atsc_text_validate(uint8_t *buf, int len)
+{
+ int i;
+ int j;
+ int number_strings;
+ int number_segments;
+ int number_bytes;
+ int pos = 0;
+
+ if (len == 0)
+ return 0;
+ number_strings = buf[pos];
+ pos++;
+
+ for(i=0; i< number_strings; i++) {
+ if (len < (pos+4))
+ return -1;
+ number_segments = buf[pos+3];
+ pos+=4;
+
+ for(j=0; j < number_segments; j++) {
+ if (len < (pos+3))
+ return -1;
+ number_bytes = buf[pos+2];
+ pos+=3;
+
+ if (len < (pos + number_bytes))
+ return -1;
+ pos += number_bytes;
+ }
+ }
+
+ return 0;
+}
+
+time_t atsctime_to_unixtime(atsctime_t atsc)
+{
+ return atsc + GPS_EPOCH;
+}
+
+atsctime_t unixtime_to_atsctime(time_t t)
+{
+ return t - GPS_EPOCH;
+}
diff --git a/lib/libucsi/atsc/types.h b/lib/libucsi/atsc/types.h
new file mode 100644
index 0000000..4d4b802
--- /dev/null
+++ b/lib/libucsi/atsc/types.h
@@ -0,0 +1,227 @@
+ /*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_ATSC_TYPES_H
+#define _UCSI_ATSC_TYPES_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+#include <time.h>
+#include <libucsi/types.h>
+
+enum atsc_vct_modulation {
+ ATSC_VCT_MODULATION_ANALOG = 0x01,
+ ATSC_VCT_MODULATION_SCTE_MODE1 = 0x02,
+ ATSC_VCT_MODULATION_SCTE_MODE2 = 0x03,
+ ATSC_VCT_MODULATION_8VSB = 0x04,
+ ATSC_VCT_MODULATION_16VSB = 0x05,
+};
+
+enum atsc_vct_service_type {
+ ATSC_VCT_SERVICE_TYPE_ANALOG = 0x01,
+ ATSC_VCT_SERVICE_TYPE_TV = 0x02,
+ ATSC_VCT_SERVICE_TYPE_AUDIO = 0x03,
+ ATSC_VCT_SERVICE_TYPE_DATA = 0x04,
+};
+
+enum atsc_etm_location {
+ ATSC_VCT_ETM_NONE = 0x00,
+ ATSC_VCT_ETM_IN_THIS_PTC = 0x01,
+ ATSC_VCT_ETM_IN_CHANNEL_TSID = 0x02,
+};
+
+enum atsc_text_compress_type {
+ ATSC_TEXT_COMPRESS_NONE = 0x00,
+ ATSC_TEXT_COMPRESS_PROGRAM_TITLE = 0x01,
+ ATSC_TEXT_COMPRESS_PROGRAM_DESCRIPTION = 0x02,
+};
+
+enum atsc_text_segment_mode {
+ ATSC_TEXT_SEGMENT_MODE_UNICODE_RANGE_MIN = 0x00,
+ ATSC_TEXT_SEGMENT_MODE_UNICODE_RANGE_MAX = 0x33,
+ ATSC_TEXT_SEGMENT_MODE_SCSU = 0x3e,
+ ATSC_TEXT_SEGMENT_MODE_UTF16 = 0x3f,
+ ATSC_TEXT_SEGMENT_MODE_TAIWAN_BITMAP = 0x40,
+ ATSC_TEXT_SEGMENT_MODE_TAIWAN_CODEWORD_BITMAP = 0x41,
+};
+
+typedef uint32_t atsctime_t;
+
+struct atsc_text {
+ uint8_t number_strings;
+ /* struct atsc_text_string strings[] */
+};
+
+struct atsc_text_string {
+ iso639lang_t language_code;
+ uint8_t number_segments;
+ /* struct atsc_text_string_segment segments[] */
+};
+
+struct atsc_text_string_segment {
+ uint8_t compression_type;
+ uint8_t mode;
+ uint8_t number_bytes;
+ /* uint8_t bytes[] */
+};
+
+/**
+ * Iterator for strings field of an atsc_text structure.
+ *
+ * @param txt atsc_text pointer.
+ * @param pos Variable holding a pointer to the current atsc_text_string.
+ * @param idx Iterator variable.
+ */
+#define atsc_text_strings_for_each(txt, pos, idx) \
+ for ((pos) = atsc_text_strings_first(txt), idx=0; \
+ (pos); \
+ (pos) = atsc_text_strings_next(txt, pos, ++idx))
+
+/**
+ * Iterator for segments field of an atsc_text_string structure.
+ *
+ * @param str atsc_text_string pointer.
+ * @param pos Variable holding a pointer to the current atsc_text_string_segment.
+ * @param idx Iterator variable.
+ */
+#define atsc_text_string_segments_for_each(str, pos, idx) \
+ for ((pos) = atsc_text_string_segments_first(str), idx=0; \
+ (pos); \
+ (pos) = atsc_text_string_segments_next(str, pos, ++idx))
+
+/**
+ * Accessor for the bytes field of an atsc_text_string_segment.
+ *
+ * @param seg atsc_text_string_segment pointer.
+ * @return Pointer to the bytes.
+ */
+static inline uint8_t*
+ atsc_text_string_segment_bytes(struct atsc_text_string_segment *d)
+{
+ return ((uint8_t*) d) + sizeof(struct atsc_text_string_segment);
+}
+
+/**
+ * Validate a buffer containing an atsc_text structure.
+ *
+ * @param buf Start of the atsc_text structure.
+ * @param len Length in bytes of the buffer.
+ * @return 0 if valid, nonzero if not.
+ */
+extern int atsc_text_validate(uint8_t *buf, int len);
+
+/**
+ * Decodes an atsc_text_segment with mode < 0x3e. Decompression of the ATSC text encoding IS
+ * supported. The output text will be in the UTF-8 encoding.
+ *
+ * @param segment Pointer to the segment to decode.
+ * @param destbuf Pointer to the malloc()ed buffer to append text to (pass NULL if none).
+ * @param destbufsize Size of destbuf in bytes.
+ * @param destbufpos Position within destbuf. This will be updated to point after the end of the
+ * string on exit.
+ * @return New value of destbufpos, or < 0 on error.
+ */
+extern int atsc_text_segment_decode(struct atsc_text_string_segment *segment,
+ uint8_t **destbuf, size_t *destbufsize, size_t *destbufpos);
+
+/**
+ * Convert from ATSC time to unix time_t.
+ *
+ * @param atsc ATSC time.
+ * @return The time value.
+ */
+extern time_t atsctime_to_unixtime(atsctime_t atsc);
+
+/**
+ * Convert from unix time_t to atsc time.
+ *
+ * @param t unix time_t.
+ * @return The atsc time value.
+ */
+extern atsctime_t unixtime_to_atsctime(time_t t);
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct atsc_text_string*
+ atsc_text_strings_first(struct atsc_text *txt)
+{
+ if (txt->number_strings == 0)
+ return NULL;
+
+ return (struct atsc_text_string *)
+ ((uint8_t*) txt + sizeof(struct atsc_text));
+}
+
+static inline struct atsc_text_string*
+ atsc_text_strings_next(struct atsc_text *txt, struct atsc_text_string *pos, int idx)
+{
+ int i;
+ uint8_t *buf;
+
+ if (idx >= txt->number_strings)
+ return NULL;
+
+ buf = ((uint8_t*) pos) + sizeof(struct atsc_text_string);
+ for(i=0; i < pos->number_segments; i++) {
+ struct atsc_text_string_segment *seg =
+ (struct atsc_text_string_segment *) buf;
+
+ buf += sizeof(struct atsc_text_string_segment);
+ buf += seg->number_bytes;
+ }
+
+ return (struct atsc_text_string *) buf;
+}
+
+static inline struct atsc_text_string_segment*
+ atsc_text_string_segments_first(struct atsc_text_string *str)
+{
+ if (str->number_segments == 0)
+ return NULL;
+
+ return (struct atsc_text_string_segment *)
+ ((uint8_t*) str + sizeof(struct atsc_text_string));
+}
+
+static inline struct atsc_text_string_segment*
+ atsc_text_string_segments_next(struct atsc_text_string *str,
+ struct atsc_text_string_segment *pos, int idx)
+{
+ if (idx >= str->number_segments)
+ return NULL;
+
+ return (struct atsc_text_string_segment *)
+ (((uint8_t*) pos) + sizeof(struct atsc_text_string_segment) + pos->number_bytes);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/crc32.c b/lib/libucsi/crc32.c
new file mode 100644
index 0000000..dc1de5c
--- /dev/null
+++ b/lib/libucsi/crc32.c
@@ -0,0 +1,89 @@
+/**
+ * crc32 calculation routines.
+ *
+ * Copyright (c) 2005 by Andrew de Quincey <adq_dvb@lidskialf.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdint.h>
+
+uint32_t crc32tbl[] =
+{
+ 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
+ 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
+ 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
+ 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
+ 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,
+ 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
+ 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011,
+ 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
+ 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
+ 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,
+ 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,
+ 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
+ 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49,
+ 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
+ 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
+ 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,
+ 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,
+ 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
+ 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
+ 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,
+ 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
+ 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,
+ 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,
+ 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
+ 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e,
+ 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,
+ 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
+ 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,
+ 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
+ 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
+ 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686,
+ 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,
+ 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
+ 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
+ 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,
+ 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
+ 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47,
+ 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,
+ 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
+ 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,
+ 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,
+ 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
+ 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f,
+ 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
+ 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
+ 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,
+ 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,
+ 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
+ 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
+ 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,
+ 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
+ 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,
+ 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,
+ 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
+ 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088,
+ 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,
+ 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
+ 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,
+ 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
+ 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
+ 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0,
+ 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
+ 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
+ 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
+};
diff --git a/lib/libucsi/crc32.h b/lib/libucsi/crc32.h
new file mode 100644
index 0000000..7d781ce
--- /dev/null
+++ b/lib/libucsi/crc32.h
@@ -0,0 +1,58 @@
+/**
+ * crc32 calculation routines.
+ *
+ * Copyright (c) 2005 by Andrew de Quincey <adq_dvb@lidskialf.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_CRC32_H
+#define _UCSI_CRC32_H 1
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define CRC32_INIT (~0)
+
+extern uint32_t crc32tbl[];
+
+/**
+ * Calculate a CRC32 over a piece of data.
+ *
+ * @param crc Current CRC value (use CRC32_INIT for first call).
+ * @param buf Buffer to calculate over.
+ * @param len Number of bytes.
+ * @return Calculated CRC.
+ */
+static inline uint32_t crc32(uint32_t crc, uint8_t* buf, size_t len)
+{
+ size_t i;
+
+ for (i=0; i< len; i++) {
+ crc = (crc << 8) ^ crc32tbl[((crc >> 24) ^ buf[i]) & 0xff];
+ }
+
+ return crc;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/descriptor.h b/lib/libucsi/descriptor.h
new file mode 100644
index 0000000..606e45d
--- /dev/null
+++ b/lib/libucsi/descriptor.h
@@ -0,0 +1,129 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DESCRIPTOR_H
+#define _UCSI_DESCRIPTOR_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/endianops.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/**
+ * Generic descriptor header.
+ */
+struct descriptor {
+ uint8_t tag;
+ uint8_t len;
+} __ucsi_packed;
+
+/**
+ * Retreive pointer to the next descriptor structure.
+ *
+ * @param buf The buffer of descriptors.
+ * @param len Size of the buffer.
+ * @param pos Current descriptor.
+ * @return Pointer to next descriptor, or NULL if there are none.
+ */
+static inline struct descriptor *
+ next_descriptor(uint8_t * buf, size_t len, struct descriptor * pos)
+{
+ uint8_t* next;
+
+ if (pos == NULL)
+ return NULL;
+
+ next = (uint8_t*) pos + 2 + pos->len;
+ if (next >= buf + len)
+ return NULL;
+
+ return (struct descriptor *) next;
+}
+
+
+/**
+ * The unknown descriptor.
+ */
+struct unknown_descriptor {
+ struct descriptor d;
+
+ /* uint8_t data [] */
+} __ucsi_packed;
+
+/**
+ * Retrieve pointer to the unknown descriptor's data field.
+ *
+ * @param d The descriptor.
+ * @return Pointer to the data field.
+ */
+static inline uint8_t *
+ unknown_descriptor_data(struct unknown_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct unknown_descriptor);
+}
+
+/**
+ * Retrieve size of unknown descriptor's data field.
+ *
+ * @param d The descriptor.
+ * @return Size of data field in bytes.
+ */
+static inline int
+ unknown_descriptor_data_size(struct unknown_descriptor *d)
+{
+ return d->d.len;
+}
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline int verify_descriptors(uint8_t * buf, size_t len)
+{
+ size_t pos = 0;
+
+ while (pos < len) {
+ if ((pos + 2) > len)
+ return -1;
+
+ pos += 2 + buf[pos+1];
+ }
+
+ if (pos != len)
+ return -1;
+
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/Makefile b/lib/libucsi/dvb/Makefile
new file mode 100644
index 0000000..78876dc
--- /dev/null
+++ b/lib/libucsi/dvb/Makefile
@@ -0,0 +1,121 @@
+# Makefile for linuxtv.org dvb-apps/lib/libucsi/dvb
+
+.PHONY: sub-error-dvb
+
+sub-error-dvb:
+ $(error You can't use this makefile directly.)
+
+ifneq ($(lib_name),)
+
+objects += dvb/bat_section.o \
+ dvb/dit_section.o \
+ dvb/eit_section.o \
+ dvb/int_section.o \
+ dvb/nit_section.o \
+ dvb/rst_section.o \
+ dvb/sdt_section.o \
+ dvb/sit_section.o \
+ dvb/st_section.o \
+ dvb/tdt_section.o \
+ dvb/tot_section.o \
+ dvb/tva_container_section.o \
+ dvb/types.o
+
+sub-install += dvb
+
+else
+
+includes = ac3_descriptor.h \
+ adaptation_field_data_descriptor.h \
+ ait_application_descriptor.h \
+ ait_application_icons_descriptor.h \
+ ait_application_name_descriptor.h \
+ ait_external_application_authorisation_descriptor.h \
+ ancillary_data_descriptor.h \
+ announcement_support_descriptor.h \
+ application_signalling_descriptor.h \
+ bat_section.h \
+ bouquet_name_descriptor.h \
+ ca_identifier_descriptor.h \
+ cable_delivery_descriptor.h \
+ cell_frequency_link_descriptor.h \
+ cell_list_descriptor.h \
+ component_descriptor.h \
+ content_descriptor.h \
+ content_identifier_descriptor.h \
+ country_availability_descriptor.h \
+ data_broadcast_descriptor.h \
+ data_broadcast_id_descriptor.h \
+ default_authority_descriptor.h \
+ descriptor.h \
+ dit_section.h \
+ dsng_descriptor.h \
+ eit_section.h \
+ extended_event_descriptor.h \
+ frequency_list_descriptor.h \
+ int_section.h \
+ ip_mac_platform_name_descriptor.h \
+ ip_mac_platform_provider_name_descriptor.h \
+ ip_mac_stream_location_descriptor.h \
+ linkage_descriptor.h \
+ local_time_offset_descriptor.h \
+ mhp_data_broadcast_id_descriptor.h \
+ mosaic_descriptor.h \
+ multilingual_bouquet_name_descriptor.h \
+ multilingual_component_descriptor.h \
+ multilingual_network_name_descriptor.h \
+ multilingual_service_name_descriptor.h \
+ network_name_descriptor.h \
+ nit_section.h \
+ nvod_reference_descriptor.h \
+ parental_rating_descriptor.h \
+ partial_transport_stream_descriptor.h \
+ pdc_descriptor.h \
+ private_data_specifier_descriptor.h \
+ related_content_descriptor.h \
+ rnt_rar_over_dvb_stream_descriptor.h \
+ rnt_rar_over_ip_descriptor.h \
+ rnt_rnt_scan_descriptor.h \
+ rst_section.h \
+ s2_satellite_delivery_descriptor.h \
+ satellite_delivery_descriptor.h \
+ scrambling_descriptor.h \
+ sdt_section.h \
+ section.h \
+ service_availability_descriptor.h \
+ service_descriptor.h \
+ service_identifier_descriptor.h \
+ service_list_descriptor.h \
+ service_move_descriptor.h \
+ short_event_descriptor.h \
+ short_smoothing_buffer_descriptor.h \
+ sit_section.h \
+ st_section.h \
+ stream_identifier_descriptor.h \
+ stuffing_descriptor.h \
+ subtitling_descriptor.h \
+ target_ip_address_descriptor.h \
+ target_ipv6_address_descriptor.h \
+ target_ip_slash_descriptor.h \
+ target_ip_source_slash_descriptor.h \
+ target_ipv6_slash_descriptor.h \
+ target_ipv6_source_slash_descriptor.h \
+ tdt_section.h \
+ telephone_descriptor.h \
+ teletext_descriptor.h \
+ terrestrial_delivery_descriptor.h \
+ time_shifted_event_descriptor.h \
+ time_shifted_service_descriptor.h \
+ tot_section.h \
+ transport_stream_descriptor.h \
+ tva_container_section.h \
+ tva_id_descriptor.h \
+ types.h \
+ vbi_data_descriptor.h \
+ vbi_teletext_descriptor.h
+
+include ../../../Make.rules
+
+lib_name = libucsi/dvb
+
+endif
diff --git a/lib/libucsi/dvb/ac3_descriptor.h b/lib/libucsi/dvb/ac3_descriptor.h
new file mode 100644
index 0000000..0a2a5cd
--- /dev/null
+++ b/lib/libucsi/dvb/ac3_descriptor.h
@@ -0,0 +1,88 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_AC3_DESCRIPTOR
+#define _UCSI_DVB_AC3_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_ac3_descriptor structure.
+ */
+struct dvb_ac3_descriptor {
+ struct descriptor d;
+
+ EBIT5(uint8_t ac3_type_flag : 1; ,
+ uint8_t bsid_flag : 1; ,
+ uint8_t mainid_flag : 1; ,
+ uint8_t asvc_flag : 1; ,
+ uint8_t reserved : 4; );
+ /* uint8_t additional_info[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ac3_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_ac3_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ac3_descriptor*
+ dvb_ac3_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct dvb_ac3_descriptor) - 2))
+ return NULL;
+
+ return (struct dvb_ac3_descriptor*) d;
+}
+
+/**
+ * Retrieve pointer to additional_info field of a dvb_ac3_descriptor.
+ *
+ * @param d dvb_ac3_descriptor pointer.
+ * @return Pointer to additional_info field.
+ */
+static inline uint8_t *dvb_ac3_descriptor_additional_info(struct dvb_ac3_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_ac3_descriptor);
+}
+
+/**
+ * Determine length of additional_info field of a dvb_ac3_descriptor.
+ *
+ * @param d dvb_ac3_descriptor pointer.
+ * @return Length of field in bytes.
+ */
+static inline int dvb_ac3_descriptor_additional_info_length(struct dvb_ac3_descriptor *d)
+{
+ return d->d.len - 1;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/adaptation_field_data_descriptor.h b/lib/libucsi/dvb/adaptation_field_data_descriptor.h
new file mode 100644
index 0000000..b207054
--- /dev/null
+++ b/lib/libucsi/dvb/adaptation_field_data_descriptor.h
@@ -0,0 +1,62 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_ADAPTATION_FIELD_DATA_DESCRIPTOR
+#define _UCSI_DVB_ADAPTATION_FIELD_DATA_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_adaptation_field_data_descriptor structure.
+ */
+struct dvb_adaptation_field_data_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t reserved : 7; ,
+ uint8_t announcement_switching_data : 1; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_adaptation_field_data_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to dvb_adaptation_field_data_descriptor, or NULL on error.
+ */
+static inline struct dvb_adaptation_field_data_descriptor*
+ dvb_adaptation_field_data_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_adaptation_field_data_descriptor) - 2))
+ return NULL;
+
+ return (struct dvb_adaptation_field_data_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/ait_application_descriptor.h b/lib/libucsi/dvb/ait_application_descriptor.h
new file mode 100644
index 0000000..95fb7e3
--- /dev/null
+++ b/lib/libucsi/dvb/ait_application_descriptor.h
@@ -0,0 +1,204 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_AIT_APPLICATION_DESCRIPTOR
+#define _UCSI_DVB_AIT_APPLICATION_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Possible values for the visibility field.
+ */
+enum {
+ AVB_AIT_APPLICATION_VISIBILITY_HIDDEN = 0x00,
+ AVB_AIT_APPLICATION_VISIBILITY_APPSONLY = 0x01,
+ AVB_AIT_APPLICATION_VISIBILITY_VISIBLE = 0x03,
+};
+
+/**
+ * dvb_ait_application_descriptor structure.
+ */
+struct dvb_ait_application_descriptor {
+ struct descriptor d;
+
+ uint8_t application_profiles_length;
+ /* struct dvb_ait_application_profile profiles [] */
+ /* struct dvb_ait_application_descriptor_part2 part2 */
+} __ucsi_packed;
+
+/**
+ * An entry in the profiles field of a dvb_ait_application_descriptor.
+ */
+struct dvb_ait_application_profile {
+ uint16_t application_profile;
+ uint8_t version_major;
+ uint8_t version_minor;
+ uint8_t version_micro;
+} __ucsi_packed;
+
+/**
+ * Second part of a dvb_ait_application_descriptor structure.
+ */
+struct dvb_ait_application_descriptor_part2 {
+ EBIT3(uint8_t service_bound_flag : 1; ,
+ uint8_t visibility : 2; ,
+ uint8_t reserved : 5; );
+ uint8_t application_priority;
+ /* uint8_t transport_protocol_label[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ait_application_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_ait_application_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ait_application_descriptor*
+ dvb_ait_application_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint32_t pos2 = 0;
+ uint32_t len = d->len + 2;
+ uint8_t* buf = (uint8_t*) d;
+ struct dvb_ait_application_descriptor *ret =
+ (struct dvb_ait_application_descriptor*) d;
+
+ if (len < sizeof(struct dvb_ait_application_descriptor))
+ return NULL;
+
+ if (len < (sizeof(struct dvb_ait_application_descriptor) + ret->application_profiles_length))
+ return NULL;
+
+ if (ret->application_profiles_length % sizeof(struct dvb_ait_application_profile))
+ return NULL;
+
+ pos += sizeof(struct dvb_ait_application_descriptor);
+ pos2 = 0;
+ while(pos2 < ret->application_profiles_length) {
+ bswap16(buf + pos + pos2);
+ pos2 += sizeof(struct dvb_ait_application_descriptor);
+ }
+ pos += pos2;
+
+ if (len < (pos + sizeof(struct dvb_ait_application_descriptor_part2)))
+ return NULL;
+
+ return ret;
+}
+
+/**
+ * Iterator for the profiles field of a dvb_ait_application_descriptor.
+ *
+ * @param d dvb_ait_application_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_ait_application_profile.
+ */
+#define dvb_ait_application_descriptor_profiles_for_each(d, pos) \
+ for ((pos) = dvb_ait_application_descriptor_profiles_first(d); \
+ (pos); \
+ (pos) = dvb_ait_application_descriptor_profiles_next(d, pos))
+
+/**
+ * Accessor for the part2 field of a dvb_ait_application_descriptor.
+ *
+ * @param d dvb_ait_application_descriptor pointer.
+ * @return dvb_ait_application_descriptor_part2 pointer.
+ */
+static inline struct dvb_ait_application_descriptor_part2*
+ dvb_ait_application_descriptor_part2(struct dvb_ait_application_descriptor* d)
+{
+ return (struct dvb_ait_application_descriptor_part2*)
+ ((uint8_t*) d +
+ sizeof(struct dvb_ait_application_descriptor) +
+ d->application_profiles_length);
+}
+
+/**
+ * Accessor for the transport_protocol_label field of a dvb_ait_application_descriptor_part2.
+ *
+ * @param d dvb_ait_application_descriptor_part2 pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ dvb_ait_application_descriptor_part2_transport_protocol_label(struct dvb_ait_application_descriptor_part2* d)
+{
+ return (uint8_t*) d +
+ sizeof(struct dvb_ait_application_descriptor_part2);
+}
+
+/**
+ * Calculate the number of bytes in the transport_protocol_label field of a dvb_ait_application_descriptor_part2.
+ *
+ * @param d dvb_ait_application_descriptor pointer.
+ * @param part2 dvb_ait_application_descriptor_part2 pointer.
+ * @return Number of bytes.
+ */
+static inline int
+ dvb_ait_application_descriptor_part2_transport_protocol_label_length(struct dvb_ait_application_descriptor *d,
+ struct dvb_ait_application_descriptor_part2* part2)
+{
+ uint8_t *ptr = (uint8_t*) part2 + sizeof(struct dvb_ait_application_descriptor_part2);
+ uint8_t *end = (uint8_t*) d + d->d.len + 2;
+
+ return (int) (end - ptr);
+}
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ait_application_profile*
+ dvb_ait_application_descriptor_profiles_first(struct dvb_ait_application_descriptor *d)
+{
+ if (d->application_profiles_length == 0)
+ return NULL;
+
+ return (struct dvb_ait_application_profile *)
+ ((uint8_t*) d + sizeof(struct dvb_ait_application_descriptor));
+}
+
+static inline struct dvb_ait_application_profile*
+ dvb_ait_application_descriptor_profiles_next(struct dvb_ait_application_descriptor *d,
+ struct dvb_ait_application_profile *pos)
+{
+ uint8_t *end = (uint8_t*) d +
+ sizeof(struct dvb_ait_application_descriptor) +
+ d->application_profiles_length;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ait_application_profile);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_ait_application_profile *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/ait_application_icons_descriptor.h b/lib/libucsi/dvb/ait_application_icons_descriptor.h
new file mode 100644
index 0000000..431cd6c
--- /dev/null
+++ b/lib/libucsi/dvb/ait_application_icons_descriptor.h
@@ -0,0 +1,157 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_AIT_APPLICATION_ICONS_DESCRIPTOR
+#define _UCSI_DVB_AIT_APPLICATION_ICONS_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * Possible values for the icon_flags field.
+ */
+enum {
+ AIT_APPLICATION_ICON_FLAG_32_32 = 0x001,
+ AIT_APPLICATION_ICON_FLAG_32_32_43 = 0x002,
+ AIT_APPLICATION_ICON_FLAG_24_32_169 = 0x004,
+
+ AIT_APPLICATION_ICON_FLAG_64_64 = 0x008,
+ AIT_APPLICATION_ICON_FLAG_64_64_43 = 0x010,
+ AIT_APPLICATION_ICON_FLAG_48_64_169 = 0x020,
+
+ AIT_APPLICATION_ICON_FLAG_128_128 = 0x040,
+ AIT_APPLICATION_ICON_FLAG_128_128_43 = 0x080,
+ AIT_APPLICATION_ICON_FLAG_96_128_169 = 0x100,
+};
+
+/**
+ * dvb_ait_application_icons_descriptor structure.
+ */
+struct dvb_ait_application_icons_descriptor {
+ struct descriptor d;
+
+ uint8_t icon_locator_length;
+ /* uint8_t icon_locator[] */
+ /* struct dvb_ait_application_icons_descriptor_part2 */
+} __ucsi_packed;
+
+/**
+ * Second part of a dvb_ait_application_icons_descriptor.
+ */
+struct dvb_ait_application_icons_descriptor_part2 {
+ uint16_t icon_flags;
+ /* uint8_t reserved[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ait_application_icons_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_ait_application_icons_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ait_application_icons_descriptor*
+ dvb_ait_application_icons_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d;
+ uint32_t pos = 0;
+ uint32_t len = d->len + 2;
+ struct dvb_ait_application_icons_descriptor *ret =
+ (struct dvb_ait_application_icons_descriptor *) d;
+
+ if (len < sizeof(struct dvb_ait_application_icons_descriptor))
+ return NULL;
+ if (len < (sizeof(struct dvb_ait_application_icons_descriptor) + ret->icon_locator_length))
+ return NULL;
+
+ pos += sizeof(struct dvb_ait_application_icons_descriptor) + ret->icon_locator_length;
+
+ if ((len - pos) < sizeof(struct dvb_ait_application_icons_descriptor_part2))
+ return NULL;
+ bswap16(buf + pos);
+
+ return ret;
+}
+/**
+ * Accessor for the icon_locator field of a dvb_ait_application_icons_descriptor.
+ *
+ * @param e dvb_ait_application_icons_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_ait_application_icons_descriptor_icon_locator(struct dvb_ait_application_icons_descriptor *e)
+{
+ return (uint8_t *) e + sizeof(struct dvb_ait_application_icons_descriptor);
+}
+
+/**
+ * Accessor for the part2 field of a dvb_ait_application_icons_descriptor.
+ *
+ * @param e dvb_ait_application_icons_descriptor Pointer.
+ * @return dvb_ait_application_icons_descriptor_part2 pointer.
+ */
+static inline struct dvb_ait_application_icons_descriptor_part2 *
+ dvb_ait_application_icons_descriptor_part2(struct dvb_ait_application_icons_descriptor *e)
+{
+ return (struct dvb_ait_application_icons_descriptor_part2 *)
+ ((uint8_t *) e + sizeof(struct dvb_ait_application_icons_descriptor) +
+ e->icon_locator_length);
+}
+
+/**
+ * Accessor for the reserved field of a dvb_ait_application_icons_descriptor_part2.
+ *
+ * @param e dvb_ait_application_icons_part2 pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_ait_application_icons_descriptor_part2_reserved(struct dvb_ait_application_icons_descriptor_part2 *e)
+{
+ return (uint8_t *) e + sizeof(struct dvb_ait_application_icons_descriptor_part2);
+}
+
+/**
+ * Calculate the number of bytes in the reserved field of a dvb_ait_application_icons_descriptor_part2.
+ *
+ * @param d dvb_ait_application_icons_descriptorpointer.
+ * @param part2 dvb_ait_application_icons_descriptor_part2 pointer.
+ * @return Number of bytes.
+ */
+static inline int
+ dvb_ait_application_icons_descriptor_part2_reserved_length(struct dvb_ait_application_icons_descriptor *d,
+ struct dvb_ait_application_icons_descriptor_part2* part2)
+{
+ uint8_t *ptr = (uint8_t*) part2 + sizeof(struct dvb_ait_application_icons_descriptor_part2);
+ uint8_t *end = (uint8_t*) d + d->d.len + 2;
+
+ return (int) (end - ptr);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/ait_application_name_descriptor.h b/lib/libucsi/dvb/ait_application_name_descriptor.h
new file mode 100644
index 0000000..a4b719e
--- /dev/null
+++ b/lib/libucsi/dvb/ait_application_name_descriptor.h
@@ -0,0 +1,145 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_AIT_APPLICATION_NAME_DESCRIPTOR
+#define _UCSI_DVB_AIT_APPLICATION_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_ait_application_name_descriptor structure.
+ */
+struct dvb_ait_application_name_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_ait_application_name names[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the names field of a dvb_ait_application_name_descriptor.
+ */
+struct dvb_ait_application_name {
+ iso639lang_t language_code;
+ uint8_t application_name_length;
+ /* uint8_t name[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ait_application_name_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_ait_application_name_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ait_application_name_descriptor*
+ dvb_ait_application_name_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+
+ while(pos < len) {
+ struct dvb_ait_application_name *e =
+ (struct dvb_ait_application_name*) (buf + pos);
+
+ pos += sizeof(struct dvb_ait_application_name);
+
+ if (pos > len)
+ return NULL;
+
+ pos += e->application_name_length;
+
+ if (pos > len)
+ return NULL;
+ }
+
+ return (struct dvb_ait_application_name_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the names field of a dvb_ait_application_name_descriptor.
+ *
+ * @param d dvb_ait_application_name_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_ait_application_name.
+ */
+#define dvb_ait_application_name_descriptor_names_for_each(d, pos) \
+ for ((pos) = dvb_ait_application_name_descriptor_names_first(d); \
+ (pos); \
+ (pos) = dvb_ait_application_name_descriptor_names_next(d, pos))
+
+/**
+ * Accessor for the name field of a dvb_ait_application_name.
+ *
+ * @param e dvb_ait_application_name pointer.
+ * @return Pointer to the name field.
+ */
+static inline uint8_t *
+ dvb_ait_application_name_name(struct dvb_ait_application_name *e)
+{
+ return (uint8_t *) e + sizeof(struct dvb_ait_application_name);
+}
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ait_application_name*
+ dvb_ait_application_name_descriptor_names_first(struct dvb_ait_application_name_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_ait_application_name *)
+ ((uint8_t*) d + sizeof(struct dvb_ait_application_name_descriptor));
+}
+
+static inline struct dvb_ait_application_name*
+ dvb_ait_application_name_descriptor_names_next(struct dvb_ait_application_name_descriptor *d,
+ struct dvb_ait_application_name *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_ait_application_name) +
+ pos->application_name_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_ait_application_name *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/ait_external_application_authorisation_descriptor.h b/lib/libucsi/dvb/ait_external_application_authorisation_descriptor.h
new file mode 100644
index 0000000..34f584a
--- /dev/null
+++ b/lib/libucsi/dvb/ait_external_application_authorisation_descriptor.h
@@ -0,0 +1,125 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_AIT_EXTERNAL_APPLICATION_AUTHORISATION_DESCRIPTOR
+#define _UCSI_DVB_AIT_EXTERNAL_APPLICATION_AUTHORISATION_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_ait_external_application_authorisation_descriptor structure.
+ */
+struct dvb_ait_external_application_authorisation_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_ait_external_application_authorisation auths[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the auths field of a dvb_ait_external_application_authorisation_descriptor.
+ */
+struct dvb_ait_external_application_authorisation {
+ uint32_t organization_id;
+ uint16_t application_id;
+ uint8_t application_priority;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ait_external_application_authorisation_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_ait_external_application_authorisation_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ait_external_application_authorisation_descriptor*
+ dvb_ait_external_application_authorisation_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+
+ if (len % sizeof(struct dvb_ait_external_application_authorisation))
+ return NULL;
+
+ while(pos < len) {
+ bswap32(buf + pos);
+ bswap32(buf + pos + 4);
+ pos += sizeof(struct dvb_ait_external_application_authorisation);
+ }
+
+ return (struct dvb_ait_external_application_authorisation_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the auths field of a dvb_ait_external_application_authorisation_descriptor.
+ *
+ * @param d dvb_ait_external_application_authorisation_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_ait_external_application_authorisation.
+ */
+#define dvb_ait_external_application_authorisation_descriptor_auths_for_each(d, pos) \
+ for ((pos) = dvb_ait_external_application_authorisation_descriptor_auths_first(d); \
+ (pos); \
+ (pos) = dvb_ait_external_application_authorisation_descriptor_auths_next(d, pos))
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ait_external_application_authorisation*
+ dvb_ait_external_application_authorisation_descriptor_auths_first(struct dvb_ait_external_application_authorisation_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_ait_external_application_authorisation *)
+ ((uint8_t*) d + sizeof(struct dvb_ait_external_application_authorisation_descriptor));
+}
+
+static inline struct dvb_ait_external_application_authorisation*
+ dvb_ait_external_application_authorisation_descriptor_auths_next(struct dvb_ait_external_application_authorisation_descriptor *d,
+ struct dvb_ait_external_application_authorisation *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_ait_external_application_authorisation);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_ait_external_application_authorisation *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/ancillary_data_descriptor.h b/lib/libucsi/dvb/ancillary_data_descriptor.h
new file mode 100644
index 0000000..04b2f59
--- /dev/null
+++ b/lib/libucsi/dvb/ancillary_data_descriptor.h
@@ -0,0 +1,67 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_ANCILLARY_DATA_DESCRIPTOR
+#define _UCSI_DVB_ANCILLARY_DATA_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_ancillary_data_descriptor structure.
+ */
+struct dvb_ancillary_data_descriptor {
+ struct descriptor d;
+ EBIT8(uint8_t reserved : 1; ,
+ uint8_t rds_via_udcp : 1; ,
+ uint8_t mpeg4_ancillary_data : 1; ,
+ uint8_t scale_factor_error_check : 1; ,
+ uint8_t dab_ancillary_data : 1; ,
+ uint8_t announcement_switching_data : 1; ,
+ uint8_t extended_ancillary_data : 1; ,
+ uint8_t dvd_video_ancillary_data : 1; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ancillary_data_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_ancillary_data_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ancillary_data_descriptor*
+ dvb_ancillary_data_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_ancillary_data_descriptor) - 2))
+ return NULL;
+
+ return (struct dvb_ancillary_data_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/announcement_support_descriptor.h b/lib/libucsi/dvb/announcement_support_descriptor.h
new file mode 100644
index 0000000..9eb20c4
--- /dev/null
+++ b/lib/libucsi/dvb/announcement_support_descriptor.h
@@ -0,0 +1,219 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_ANNOUNCEMENT_SUPPORT_DESCRIPTOR
+#define _UCSI_DVB_ANNOUNCEMENT_SUPPORT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Possible values for announcement_support_indicator.
+ */
+enum {
+ DVB_ANNOUNCEMENT_SUPPORT_EMERGENCY = 0x01,
+ DVB_ANNOUNCEMENT_SUPPORT_ROAD_TRAFFIC_FLASH = 0x02,
+ DVB_ANNOUNCEMENT_SUPPORT_PUBLIC_TRANSPORT_FLASH = 0x04,
+ DVB_ANNOUNCEMENT_SUPPORT_WARNING_MESSAGE = 0x08,
+ DVB_ANNOUNCEMENT_SUPPORT_NEWS_FLASH = 0x10,
+ DVB_ANNOUNCEMENT_SUPPORT_WEATHER_FLASH = 0x20,
+ DVB_ANNOUNCEMENT_SUPPORT_EVENT_ANNOUNCEMENT = 0x40,
+ DVB_ANNOUNCEMENT_SUPPORT_PERSONAL_CALL = 0x80,
+};
+
+/**
+ * Possible values for announcement_type.
+ */
+enum {
+ DVB_ANNOUNCEMENT_TYPE_EMERGENCY = 0x00,
+ DVB_ANNOUNCEMENT_TYPE_ROAD_TRAFFIC_FLASH = 0x01,
+ DVB_ANNOUNCEMENT_TYPE_PUBLIC_TRANSPORT_FLASH = 0x02,
+ DVB_ANNOUNCEMENT_TYPE_WARNING_MESSAGE = 0x03,
+ DVB_ANNOUNCEMENT_TYPE_NEWS_FLASH = 0x04,
+ DVB_ANNOUNCEMENT_TYPE_WEATHER_FLASH = 0x05,
+ DVB_ANNOUNCEMENT_TYPE_EVENT_ANNOUNCEMENT = 0x06,
+ DVB_ANNOUNCEMENT_TYPE_PERSONAL_CALL = 0x07,
+};
+
+/**
+ * Possible values for reference_type.
+ */
+enum {
+ DVB_REFERENCE_TYPE_AUDIO = 0x00,
+ DVB_REFERENCE_TYPE_OTHER_AUDIO = 0x01,
+ DVB_REFERENCE_TYPE_OTHER_SERVICE = 0x02,
+ DVB_REFERENCE_TYPE_OTHER_TS = 0x03,
+};
+
+/**
+ * dvb_announcement_support_descriptor structure.
+ */
+struct dvb_announcement_support_descriptor {
+ struct descriptor d;
+ uint16_t announcement_support_indicator;
+ /* struct dvb_announcement_support_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the entries field of a dvb_announcement_support_descriptor.
+ */
+struct dvb_announcement_support_entry {
+ EBIT3(uint8_t announcement_type : 4; ,
+ uint8_t reserved : 1; ,
+ uint8_t reference_type : 3; );
+ /* Only if reference_type == 1, 2 or 3:
+ * struct dvb_announcement_support_reference reference */
+} __ucsi_packed;
+
+/**
+ * The optional reference field only present in a dvb_announcement_support_descriptor if
+ * its reference_type field is 1,2 or 3.
+ */
+struct dvb_announcement_support_reference {
+ uint16_t original_network_id;
+ uint16_t transport_stream_id;
+ uint16_t service_id;
+ uint8_t component_tag;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_announcement_support_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_announcement_support_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_announcement_support_descriptor*
+ dvb_announcement_support_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t len = d->len;
+
+ if (len < (sizeof(struct dvb_announcement_support_descriptor) - 2))
+ return NULL;
+
+ bswap16(buf+pos);
+
+ pos += 2;
+
+ while(pos < len) {
+ struct dvb_announcement_support_entry *e =
+ (struct dvb_announcement_support_entry*) (buf+pos);
+
+ pos += sizeof(struct dvb_announcement_support_entry);
+
+ if (pos > len)
+ return NULL;
+
+ if ((e->reference_type == 1) ||
+ (e->reference_type == 2) ||
+ (e->reference_type == 3)) {
+ if ((pos + sizeof(struct dvb_announcement_support_reference)) > len)
+ return NULL;
+
+ bswap16(buf+pos);
+ bswap16(buf+pos+2);
+ bswap16(buf+pos+4);
+
+ pos += sizeof(struct dvb_announcement_support_reference);
+ }
+ }
+
+ return (struct dvb_announcement_support_descriptor*) d;
+}
+
+/**
+ * Iterator for the entries field of a dvb_announcement_support_descriptor.
+ *
+ * @param d dvb_announcement_support_descriptor pointer.
+ * @param pod Variable holding a pointer to the current dvb_announcement_support_entry.
+ */
+#define dvb_announcement_support_descriptor_entries_for_each(d, pos) \
+ for ((pos) = dvb_announcement_support_descriptor_entries_first(d); \
+ (pos); \
+ (pos) = dvb_announcement_support_descriptor_entries_next(d, pos))
+
+/**
+ * Accessor for the reference field of a dvb_announcement_support_entry if present.
+ *
+ * @param entry dvb_announcement_support_entry pointer.
+ * @return dvb_announcement_support_reference pointer, or NULL on error.
+ */
+static inline struct dvb_announcement_support_reference*
+ dvb_announcement_support_entry_reference(struct dvb_announcement_support_entry* entry)
+{
+ if ((entry->reference_type != 0x01) &&
+ (entry->reference_type != 0x02) &&
+ (entry->reference_type != 0x03))
+ return NULL;
+
+ return (struct dvb_announcement_support_reference*)
+ ((uint8_t*) entry + sizeof(struct dvb_announcement_support_entry));
+}
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_announcement_support_entry*
+ dvb_announcement_support_descriptor_entries_first(struct dvb_announcement_support_descriptor *d)
+{
+ if (d->d.len == 2)
+ return NULL;
+
+ return (struct dvb_announcement_support_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_announcement_support_descriptor));
+}
+
+static inline struct dvb_announcement_support_entry*
+ dvb_announcement_support_descriptor_entries_next(struct dvb_announcement_support_descriptor *d,
+ struct dvb_announcement_support_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t* next = (uint8_t*) pos + sizeof(struct dvb_announcement_support_entry);
+ struct dvb_announcement_support_reference* reference =
+ dvb_announcement_support_entry_reference(pos);
+
+ if (reference)
+ next += sizeof(struct dvb_announcement_support_reference);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_announcement_support_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/application_signalling_descriptor.h b/lib/libucsi/dvb/application_signalling_descriptor.h
new file mode 100644
index 0000000..78211cf
--- /dev/null
+++ b/lib/libucsi/dvb/application_signalling_descriptor.h
@@ -0,0 +1,124 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_APPLICATION_SIGNALLING_DESCRIPTOR
+#define _UCSI_DVB_APPLICATION_SIGNALLING_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_application_signalling_descriptor structure.
+ */
+struct dvb_application_signalling_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_application_signalling_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the entries field of a dvb_application_signalling_descriptor.
+ */
+struct dvb_application_signalling_entry {
+ uint16_t application_type;
+ EBIT2(uint8_t reserved : 3; ,
+ uint8_t AIT_version_number : 5; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_application_signalling_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_application_signalling_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_application_signalling_descriptor*
+ dvb_application_signalling_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+ uint8_t* buf = (uint8_t*) d + 2;
+
+ pos += sizeof(struct dvb_application_signalling_descriptor) - 2;
+ if (len % sizeof(struct dvb_application_signalling_entry))
+ return NULL;
+
+ while(pos < len) {
+ bswap16(buf+pos);
+ pos+=3;
+ }
+
+ return (struct dvb_application_signalling_descriptor*) d;
+}
+
+/**
+ * Iterator for the entries field of a dvb_application_signalling_descriptor.
+ *
+ * @param d dvb_application_signalling_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_application_signalling_entry.
+ */
+#define dvb_application_signalling_descriptor_entries_for_each(d, pos) \
+ for ((pos) = dvb_application_signalling_descriptor_entries_first(d); \
+ (pos); \
+ (pos) = dvb_application_signalling_descriptor_entries_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_application_signalling_entry*
+ dvb_application_signalling_descriptor_entries_first(struct dvb_application_signalling_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_application_signalling_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_application_signalling_descriptor));
+}
+
+static inline struct dvb_application_signalling_entry*
+ dvb_application_signalling_descriptor_entries_next(struct dvb_application_signalling_descriptor *d,
+ struct dvb_application_signalling_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_application_signalling_entry);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_application_signalling_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/bat_section.c b/lib/libucsi/dvb/bat_section.c
new file mode 100644
index 0000000..99e5cf6
--- /dev/null
+++ b/lib/libucsi/dvb/bat_section.c
@@ -0,0 +1,77 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/bat_section.h>
+
+struct dvb_bat_section * dvb_bat_section_codec(struct section_ext * ext)
+{
+ uint8_t * buf = (uint8_t *) ext;
+ size_t pos = sizeof(struct section_ext);
+ size_t len = section_ext_length(ext);
+ struct dvb_bat_section * ret = (struct dvb_bat_section *) ext;
+
+ if (len < sizeof(struct dvb_bat_section))
+ return NULL;
+
+ bswap16(buf + pos);
+ pos += 2;
+
+ if ((pos + ret->bouquet_descriptors_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, ret->bouquet_descriptors_length))
+ return NULL;
+ pos += ret->bouquet_descriptors_length;
+
+ if ((pos + sizeof(struct dvb_bat_section_part2)) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+ pos += sizeof(struct dvb_bat_section_part2);
+
+ while (pos < len) {
+ struct dvb_bat_transport * transport =
+ (struct dvb_bat_transport *) (buf + pos);
+
+ if ((pos + sizeof(struct dvb_bat_transport)) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+ bswap16(buf + pos + 2);
+ bswap16(buf + pos + 4);
+
+ pos += sizeof(struct dvb_bat_transport);
+
+ if ((pos + transport->transport_descriptors_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos,
+ transport->transport_descriptors_length))
+ return NULL;
+
+ pos += transport->transport_descriptors_length;
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return ret;
+}
diff --git a/lib/libucsi/dvb/bat_section.h b/lib/libucsi/dvb/bat_section.h
new file mode 100644
index 0000000..94ed8a4
--- /dev/null
+++ b/lib/libucsi/dvb/bat_section.h
@@ -0,0 +1,211 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_BAT_SECTION_H
+#define _UCSI_DVB_BAT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * dvb_bat_section structure.
+ */
+struct dvb_bat_section {
+ struct section_ext head;
+
+ EBIT2(uint16_t reserved_1 : 4; ,
+ uint16_t bouquet_descriptors_length :12; );
+ /* struct descriptor descriptors[] */
+ /* struct dvb_bat_section_part2 part2 */
+};
+
+/**
+ * Second part of a dvb_bat_section, following the variable length descriptors field.
+ */
+struct dvb_bat_section_part2 {
+ EBIT2(uint16_t reserved_2 : 4; ,
+ uint16_t transport_stream_loop_length :12; );
+ /* struct dvb_bat_transport transports[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the transports field of a dvb_bat_section_part2.
+ */
+struct dvb_bat_transport {
+ uint16_t transport_stream_id;
+ uint16_t original_network_id;
+ EBIT2(uint16_t reserved : 4; ,
+ uint16_t transport_descriptors_length :12; );
+ /* struct descriptor descriptors[] */
+};
+
+/**
+ * Process a dvb_bat_section.
+ *
+ * @param section Generic section pointer.
+ * @return dvb_bat_section pointer, or NULL on error.
+ */
+struct dvb_bat_section *dvb_bat_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for the bouquet_id field of a BAT.
+ *
+ * @param bat BAT pointer.
+ * @return The bouquet_id.
+ */
+static inline uint16_t dvb_bat_section_bouquet_id(struct dvb_bat_section *bat)
+{
+ return bat->head.table_id_ext;
+}
+
+/**
+ * Iterator for the descriptors field in a dvb_bat_section.
+ *
+ * @param bat dvb_bat_section pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define dvb_bat_section_descriptors_for_each(bat, pos) \
+ for ((pos) = dvb_bat_section_descriptors_first(bat); \
+ (pos); \
+ (pos) = dvb_bat_section_descriptors_next(bat, pos))
+
+/**
+ * Accessor for the second part of a dvb_bat_section.
+ *
+ * @param bat dvb_bat_section pointer.
+ * @return dvb_bat_section_part2 pointer.
+ */
+static inline struct dvb_bat_section_part2 *
+ dvb_bat_section_part2(struct dvb_bat_section *bat)
+{
+ return (struct dvb_bat_section_part2 *)
+ ((uint8_t*) bat +
+ sizeof(struct dvb_bat_section) +
+ bat->bouquet_descriptors_length);
+
+}
+
+/**
+ * Iterator for the transports field of a dvb_bat_section_part2.
+ *
+ * @param part2 dvb_bat_section_part2 pointer.
+ * @param pos Variable containing a pointer to the current dvb_bat_transport.
+ */
+#define dvb_bat_section_transports_for_each(part2, pos) \
+ for ((pos) = dvb_bat_section_transports_first(part2); \
+ (pos); \
+ (pos) = dvb_bat_section_transports_next(part2, pos))
+
+/**
+ * Iterator for the descriptors field of a dvb_bat_transport.
+ *
+ * @param transport dvb_bat_transport pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define dvb_bat_transport_descriptors_for_each(transport, pos) \
+ for ((pos) = dvb_bat_transport_descriptors_first(transport); \
+ (pos); \
+ (pos) = dvb_bat_transport_descriptors_next(transport, pos))
+
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ dvb_bat_section_descriptors_first(struct dvb_bat_section *bat)
+{
+ if (bat->bouquet_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) bat + sizeof(struct dvb_bat_section));
+}
+
+static inline struct descriptor *
+ dvb_bat_section_descriptors_next(struct dvb_bat_section *bat,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) bat + sizeof(struct dvb_bat_section),
+ bat->bouquet_descriptors_length,
+ pos);
+}
+
+static inline struct dvb_bat_transport *
+ dvb_bat_section_transports_first(struct dvb_bat_section_part2 *part2)
+{
+ if (part2->transport_stream_loop_length == 0)
+ return NULL;
+
+ return (struct dvb_bat_transport *)
+ ((uint8_t *) part2 + sizeof(struct dvb_bat_section_part2));
+}
+
+static inline struct dvb_bat_transport *
+ dvb_bat_section_transports_next(struct dvb_bat_section_part2 *part2,
+ struct dvb_bat_transport *pos)
+{
+ uint8_t *end = (uint8_t*) part2 + sizeof(struct dvb_bat_section_part2) +
+ part2->transport_stream_loop_length;
+ uint8_t *next = (uint8_t*) pos + sizeof(struct dvb_bat_transport) +
+ pos->transport_descriptors_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_bat_transport *) next;
+}
+
+static inline struct descriptor *
+ dvb_bat_transport_descriptors_first(struct dvb_bat_transport *t)
+{
+ if (t->transport_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t*)t + sizeof(struct dvb_bat_transport));
+}
+
+static inline struct descriptor *
+ dvb_bat_transport_descriptors_next(struct dvb_bat_transport *t,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) t + sizeof(struct dvb_bat_transport),
+ t->transport_descriptors_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/bouquet_name_descriptor.h b/lib/libucsi/dvb/bouquet_name_descriptor.h
new file mode 100644
index 0000000..a298849
--- /dev/null
+++ b/lib/libucsi/dvb/bouquet_name_descriptor.h
@@ -0,0 +1,82 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_BOUQUET_NAME_DESCRIPTOR
+#define _UCSI_DVB_BOUQUET_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_bouquet_name_descriptor structure.
+ */
+struct dvb_bouquet_name_descriptor {
+ struct descriptor d;
+
+ /* uint8_t name[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_bouquet_name_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_bouquet_name_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_bouquet_name_descriptor*
+ dvb_bouquet_name_descriptor_codec(struct descriptor* d)
+{
+ return (struct dvb_bouquet_name_descriptor*) d;
+}
+
+/**
+ * Accessor for the name field of a dvb_bouquet_name_descriptor.
+ *
+ * @param d dvb_bouquet_name_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_bouquet_name_descriptor_name(struct dvb_bouquet_name_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_bouquet_name_descriptor);
+}
+
+/**
+ * Determine the length of the name field of a dvb_bouquet_name_descriptor in bytes.
+ *
+ * @param d dvb_bouquet_name_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_bouquet_name_descriptor_name_length(struct dvb_bouquet_name_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/ca_identifier_descriptor.h b/lib/libucsi/dvb/ca_identifier_descriptor.h
new file mode 100644
index 0000000..ac670a9
--- /dev/null
+++ b/lib/libucsi/dvb/ca_identifier_descriptor.h
@@ -0,0 +1,94 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_CA_IDENTIFIER_DESCRIPTOR
+#define _UCSI_DVB_CA_IDENTIFIER_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_ca_identifier_descriptor structure.
+ */
+struct dvb_ca_identifier_descriptor {
+ struct descriptor d;
+
+ /* uint16_t ca_system_ids[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ca_identifier_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_ca_identifier_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ca_identifier_descriptor*
+ dvb_ca_identifier_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len;
+ uint8_t *buf = (uint8_t*) d + 2;
+ uint32_t pos = 0;
+
+ if (len % 2)
+ return NULL;
+
+ while(pos < len) {
+ bswap16(buf+pos);
+ pos+=2;
+ }
+
+ return (struct dvb_ca_identifier_descriptor*) d;
+}
+
+/**
+ * Accessor for the ca_system_ids field of a dvb_ca_identifier_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint16_t *
+ dvb_ca_identifier_descriptor_ca_system_ids(struct dvb_ca_identifier_descriptor *d)
+{
+ return (uint16_t *) ((uint8_t *) d + sizeof(struct dvb_ca_identifier_descriptor));
+}
+
+/**
+ * Calculate the number of entries in the ca_system_ids field of a dvb_ca_identifier_descriptor.
+ *
+ * @param d dvb_ca_identifier_descriptor pointer.
+ * @return Number of entries.
+ */
+static inline int
+ dvb_ca_identifier_descriptor_ca_system_ids_count(struct dvb_ca_identifier_descriptor *d)
+{
+ return d->d.len >> 1;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/cable_delivery_descriptor.h b/lib/libucsi/dvb/cable_delivery_descriptor.h
new file mode 100644
index 0000000..f0f92f3
--- /dev/null
+++ b/lib/libucsi/dvb/cable_delivery_descriptor.h
@@ -0,0 +1,70 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_CABLE_DELIVERY_DESCRIPTOR
+#define _UCSI_DVB_CABLE_DELIVERY_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_cable_delivery_descriptor structure.
+ */
+struct dvb_cable_delivery_descriptor {
+ struct descriptor d;
+
+ uint32_t frequency; // BCD, units 100Hz
+ EBIT2(uint16_t reserved : 12; ,
+ uint16_t fec_outer : 4; );
+ uint8_t modulation;
+ EBIT2(uint32_t symbol_rate : 28; , // BCD, units 100Hz
+ uint32_t fec_inner : 4; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_cable_delivery_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_cable_delivery_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_cable_delivery_descriptor*
+ dvb_cable_delivery_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_cable_delivery_descriptor) - 2))
+ return NULL;
+
+ bswap32((uint8_t*) d + 2);
+ bswap16((uint8_t*) d + 6);
+ bswap32((uint8_t*) d + 9);
+
+ return (struct dvb_cable_delivery_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/cell_frequency_link_descriptor.h b/lib/libucsi/dvb/cell_frequency_link_descriptor.h
new file mode 100644
index 0000000..63f7fd2
--- /dev/null
+++ b/lib/libucsi/dvb/cell_frequency_link_descriptor.h
@@ -0,0 +1,190 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_CELL_FREQUENCY_LINK_DESCRIPTOR
+#define _UCSI_DVB_CELL_FREQUENCY_LINK_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_cell_frequency_link_descriptor structure.
+ */
+struct dvb_cell_frequency_link_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_cell_frequency_link_cell cells[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the cells field of a dvb_cell_frequency_link_descriptor.
+ */
+struct dvb_cell_frequency_link_cell {
+ uint16_t cell_id;
+ uint32_t frequency;
+ uint8_t subcell_loop_info_length;
+ /* struct dvb_cell_frequency_link_subcell subcells[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the subcells field of a dvb_cell_frequency_link_cell.
+ */
+struct dvb_cell_frequency_link_cell_subcell {
+ uint8_t cell_id_extension;
+ uint32_t transposer_frequency;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_cell_frequency_link_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_cell_frequency_link_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_cell_frequency_link_descriptor*
+ dvb_cell_frequency_link_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint32_t pos2 = 0;
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t len = d->len;
+
+ while(pos < len) {
+ struct dvb_cell_frequency_link_cell *e =
+ (struct dvb_cell_frequency_link_cell*) (buf+pos);
+
+ if ((pos + sizeof(struct dvb_cell_frequency_link_cell)) > len)
+ return NULL;
+
+ bswap16(buf+pos);
+ bswap32(buf+pos+2);
+
+ pos += sizeof(struct dvb_cell_frequency_link_cell);
+
+ if ((pos + e->subcell_loop_info_length) > len)
+ return NULL;
+
+ if (e->subcell_loop_info_length % sizeof(struct dvb_cell_frequency_link_cell_subcell))
+ return NULL;
+
+ pos2 = 0;
+ while(pos2 < e->subcell_loop_info_length) {
+ bswap32(buf+pos+pos2+1);
+
+ pos2 += sizeof(struct dvb_cell_frequency_link_cell_subcell);
+ }
+
+ pos += e->subcell_loop_info_length;
+ }
+
+ return (struct dvb_cell_frequency_link_descriptor*) d;
+}
+
+/**
+ * Iterator for the cells field of a dvb_cell_frequency_link_descriptor.
+ *
+ * @param d dvb_cell_frequency_link_descriptor pointer.
+ * @param pos Variable holding a pointer to the current dvb_cell_frequency_link_cell.
+ */
+#define dvb_cell_frequency_link_descriptor_cells_for_each(d, pos) \
+ for ((pos) = dvb_cell_frequency_link_descriptor_cells_first(d); \
+ (pos); \
+ (pos) = dvb_cell_frequency_link_descriptor_cells_next(d, pos))
+
+/**
+ * Iterator for the subcells field of a dvb_cell_frequency_link_cell.
+ *
+ * @param cell dvb_cell_frequency_link_cell pointer.
+ * @param pos Variable holding a pointer to the current dvb_cell_frequency_link_cell_subcell.
+ */
+#define dvb_cell_frequency_link_cell_subcells_for_each(cell, pos) \
+ for ((pos) = dvb_cell_frequency_link_cell_subcells_first(cell); \
+ (pos); \
+ (pos) = dvb_cell_frequency_link_cell_subcells_next(cell, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_cell_frequency_link_cell*
+ dvb_cell_frequency_link_descriptor_cells_first(struct dvb_cell_frequency_link_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_cell_frequency_link_cell *)
+ ((uint8_t*) d + sizeof(struct dvb_cell_frequency_link_descriptor));
+}
+
+static inline struct dvb_cell_frequency_link_cell*
+ dvb_cell_frequency_link_descriptor_cells_next(struct dvb_cell_frequency_link_descriptor *d,
+ struct dvb_cell_frequency_link_cell *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_cell_frequency_link_cell) +
+ pos->subcell_loop_info_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_cell_frequency_link_cell *) next;
+}
+
+static inline struct dvb_cell_frequency_link_cell_subcell*
+ dvb_cell_frequency_link_cell_subcells_first(struct dvb_cell_frequency_link_cell *d)
+{
+ if (d->subcell_loop_info_length == 0)
+ return NULL;
+
+ return (struct dvb_cell_frequency_link_cell_subcell*)
+ ((uint8_t*) d + sizeof(struct dvb_cell_frequency_link_cell));
+}
+
+static inline struct dvb_cell_frequency_link_cell_subcell*
+ dvb_cell_frequency_link_cell_subcells_next(struct dvb_cell_frequency_link_cell *cell,
+ struct dvb_cell_frequency_link_cell_subcell *pos)
+{
+ uint8_t *end = (uint8_t*) cell + cell->subcell_loop_info_length;
+ uint8_t *next = (uint8_t*) pos +
+ sizeof(struct dvb_cell_frequency_link_cell_subcell);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_cell_frequency_link_cell_subcell *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/cell_list_descriptor.h b/lib/libucsi/dvb/cell_list_descriptor.h
new file mode 100644
index 0000000..ddbaf2c
--- /dev/null
+++ b/lib/libucsi/dvb/cell_list_descriptor.h
@@ -0,0 +1,201 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_CELL_LIST_DESCRIPTOR
+#define _UCSI_DVB_CELL_LIST_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_cell_list_descriptor structure.
+ */
+struct dvb_cell_list_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_cell_list_entry cells[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the cells field of a dvb_cell_list_descriptor.
+ */
+struct dvb_cell_list_entry {
+ uint16_t cell_id;
+ uint16_t cell_latitude;
+ uint16_t cell_longitude;
+ EBIT3(uint32_t cell_extend_of_latitude :12; ,
+ uint32_t cell_extend_of_longitude :12; ,
+ uint32_t subcell_info_loop_length : 8; );
+ /* struct dvb_subcell_list_entry subcells[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the subcells field of a dvb_cell_list_entry.
+ */
+struct dvb_subcell_list_entry {
+ uint8_t cell_id_extension;
+ uint16_t subcell_latitude;
+ uint16_t subcell_longitude;
+ EBIT2(uint32_t subcell_extend_of_latitude :12; ,
+ uint32_t subcell_extend_of_longitude :12; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_cell_list_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_cell_list_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_cell_list_descriptor*
+ dvb_cell_list_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint32_t pos2 = 0;
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t len = d->len;
+
+ while(pos < len) {
+ struct dvb_cell_list_entry *e =
+ (struct dvb_cell_list_entry*) (buf+pos);
+
+ if ((pos + sizeof(struct dvb_cell_list_entry)) > len)
+ return NULL;
+
+ bswap16(buf+pos);
+ bswap16(buf+pos+2);
+ bswap16(buf+pos+4);
+ bswap32(buf+pos+6);
+
+ pos += sizeof(struct dvb_cell_list_entry);
+
+ if ((pos + e->subcell_info_loop_length) > len)
+ return NULL;
+
+ if (e->subcell_info_loop_length % sizeof(struct dvb_subcell_list_entry))
+ return NULL;
+
+ pos2 = 0;
+ while(pos2 < e->subcell_info_loop_length) {
+ bswap16(buf+pos+pos2+1);
+ bswap16(buf+pos+pos2+3);
+ bswap24(buf+pos+pos2+5);
+
+ pos2 += sizeof(struct dvb_subcell_list_entry);
+ }
+
+ pos += e->subcell_info_loop_length;
+ }
+
+ return (struct dvb_cell_list_descriptor*) d;
+}
+
+/**
+ * Iterator for the cells field of a dvb_cell_list_descriptor.
+ *
+ * @param d dvb_cell_list_descriptor pointer.
+ * @param pos Variable holding a pointer to the current dvb_cell_list_entry.
+ */
+#define dvb_cell_list_descriptor_cells_for_each(d, pos) \
+ for ((pos) = dvb_cell_list_descriptor_cells_first(d); \
+ (pos); \
+ (pos) = dvb_cell_list_descriptor_cells_next(d, pos))
+
+/**
+ * Iterator for the subcells field of a dvb_cell_list_entry.
+ *
+ * @param cell dvb_cell_list_entry pointer.
+ * @param pos Variable holding a pointer to the current dvb_subcell_list_entry.
+ */
+#define dvb_cell_list_entry_subcells_for_each(cell, pos) \
+ for ((pos) = dvb_cell_list_entry_subcells_first(cell); \
+ (pos); \
+ (pos) = dvb_cell_list_entry_subcells_next(cell, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_cell_list_entry*
+ dvb_cell_list_descriptor_cells_first(struct dvb_cell_list_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_cell_list_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_cell_list_descriptor));
+}
+
+static inline struct dvb_cell_list_entry*
+ dvb_cell_list_descriptor_cells_next(struct dvb_cell_list_descriptor *d,
+ struct dvb_cell_list_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_cell_list_entry) +
+ pos->subcell_info_loop_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_cell_list_entry *) next;
+}
+
+static inline struct dvb_subcell_list_entry*
+ dvb_cell_list_entry_subcells_first(struct dvb_cell_list_entry *d)
+{
+ if (d->subcell_info_loop_length == 0)
+ return NULL;
+
+ return (struct dvb_subcell_list_entry*)
+ ((uint8_t*) d + sizeof(struct dvb_cell_list_entry));
+}
+
+static inline struct dvb_subcell_list_entry*
+ dvb_cell_list_entry_subcells_next(struct dvb_cell_list_entry *d,
+ struct dvb_subcell_list_entry *pos)
+{
+ uint8_t *next = (uint8_t*) pos + sizeof(struct dvb_subcell_list_entry);
+ uint8_t *end = (uint8_t*) d +
+ sizeof(struct dvb_cell_list_entry) +
+ d->subcell_info_loop_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_subcell_list_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/component_descriptor.h b/lib/libucsi/dvb/component_descriptor.h
new file mode 100644
index 0000000..31d38e1
--- /dev/null
+++ b/lib/libucsi/dvb/component_descriptor.h
@@ -0,0 +1,147 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_COMPONENT_DESCRIPTOR
+#define _UCSI_DVB_COMPONENT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * Possible values for stream_content.
+ */
+enum {
+ DVB_STREAM_CONTENT_VIDEO = 0x01,
+ DVB_STREAM_CONTENT_AUDIO = 0x02,
+ DVB_STREAM_CONTENT_SUBTITLE = 0x03,
+ DVB_STREAM_CONTENT_AC3 = 0x04,
+};
+
+/**
+ * Possible values for component_type.
+ */
+enum {
+ DVB_COMPONENT_TYPE_VIDEO_43_25Hz = 0x01,
+ DVB_COMPONENT_TYPE_VIDEO_169_PAN_25Hz = 0x02,
+ DVB_COMPONENT_TYPE_VIDEO_169_NOPAN_25Hz = 0x03,
+ DVB_COMPONENT_TYPE_VIDEO_GT169_25Hz = 0x04,
+
+ DVB_COMPONENT_TYPE_VIDEO_43_30Hz = 0x05,
+ DVB_COMPONENT_TYPE_VIDEO_169_PAN_30Hz = 0x06,
+ DVB_COMPONENT_TYPE_VIDEO_169_NOPAN_30Hz = 0x07,
+ DVB_COMPONENT_TYPE_VIDEO_GT169_30Hz = 0x08,
+
+ DVB_COMPONENT_TYPE_HDVIDEO_43_25Hz = 0x09,
+ DVB_COMPONENT_TYPE_HDVIDEO_169_PAN_25Hz = 0x0a,
+ DVB_COMPONENT_TYPE_HDVIDEO_169_NOPAN_25Hz = 0x0b,
+ DVB_COMPONENT_TYPE_HDVIDEO_GT169_25Hz = 0x0c,
+
+ DVB_COMPONENT_TYPE_HDVIDEO_43_30Hz = 0x0d,
+ DVB_COMPONENT_TYPE_HDVIDEO_169_PAN_30Hz = 0x0e,
+ DVB_COMPONENT_TYPE_HDVIDEO_169_NOPAN_30Hz = 0x0f,
+ DVB_COMPONENT_TYPE_HDVIDEO_GT169_30Hz = 0x10,
+
+ DVB_COMPONENT_TYPE_AUDIO_SINGLE_MONO = 0x01,
+ DVB_COMPONENT_TYPE_AUDIO_DUAL_MONO = 0x02,
+ DVB_COMPONENT_TYPE_AUDIO_STEREO = 0x03,
+ DVB_COMPONENT_TYPE_AUDIO_MULTI_LINGUAL_MULTI_CHAN= 0x04,
+ DVB_COMPONENT_TYPE_AUDIO_SURROUND = 0x05,
+ DVB_COMPONENT_TYPE_AUDIO_VISUAL_IMPAIRED = 0x40,
+ DVB_COMPONENT_TYPE_AUDIO_HARDHEAR = 0x41,
+ DVB_COMPONENT_TYPE_AUDIO_SUPPLEMENTARY = 0x42,
+
+ DVB_COMPONENT_TYPE_SUBTITLE_TELETEXT = 0x01,
+ DVB_COMPONENT_TYPE_SUBTITLE_ASSOC_TELETEXT = 0x02,
+ DVB_COMPONENT_TYPE_SUBTITLE_VBI = 0x03,
+ DVB_COMPONENT_TYPE_SUBTITLE_DVB = 0x10,
+ DVB_COMPONENT_TYPE_SUBTITLE_DVB_43 = 0x11,
+ DVB_COMPONENT_TYPE_SUBTITLE_DVB_169 = 0x12,
+ DVB_COMPONENT_TYPE_SUBTITLE_DVB_2211 = 0x13,
+ DVB_COMPONENT_TYPE_SUBTITLE_DVB_HARDHEAR = 0x20,
+ DVB_COMPONENT_TYPE_SUBTITLE_DVB_HARDHEAR_43 = 0x21,
+ DVB_COMPONENT_TYPE_SUBTITLE_DVB_HARDHEAR_169 = 0x22,
+ DVB_COMPONENT_TYPE_SUBTITLE_DVB_HARDHEAR_2211 = 0x23,
+};
+
+/**
+ * dvb_component_descriptor structure.
+ */
+struct dvb_component_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t reserved : 4; ,
+ uint8_t stream_content : 4; );
+ uint8_t component_type;
+ uint8_t component_tag;
+ iso639lang_t language_code;
+ /* uint8_t text[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_component_descriptor.
+ *
+ * @param d Pointer to a generic descriptor.
+ * @return dvb_component_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_component_descriptor*
+ dvb_component_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct dvb_component_descriptor) - 2))
+ return NULL;
+
+ return (struct dvb_component_descriptor*) d;
+}
+
+/**
+ * Accessor for the text field of a dvb_component_descriptor.
+ *
+ * @param d dvb_component_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_component_descriptor_text(struct dvb_component_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_component_descriptor);
+}
+
+/**
+ * Determine the length of the text field of a dvb_component_descriptor.
+ *
+ * @param d dvb_component_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_component_descriptor_text_length(struct dvb_component_descriptor *d)
+{
+ return d->d.len - 6;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/content_descriptor.h b/lib/libucsi/dvb/content_descriptor.h
new file mode 100644
index 0000000..d2a63a0
--- /dev/null
+++ b/lib/libucsi/dvb/content_descriptor.h
@@ -0,0 +1,116 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_CONTENT_DESCRIPTOR
+#define _UCSI_DVB_CONTENT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+// FIXME: the nibbles
+
+/**
+ * dvb_content_descriptor structure.
+ */
+struct dvb_content_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_content_nibble nibbles[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the nibbles field of a dvb_content_descriptor.
+ */
+struct dvb_content_nibble {
+ EBIT2(uint8_t content_nibble_level_1 : 4; ,
+ uint8_t content_nibble_level_2 : 4; );
+ EBIT2(uint8_t user_nibble_1 : 4; ,
+ uint8_t user_nibble_2 : 4; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_content_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_content_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_content_descriptor*
+ dvb_content_descriptor_codec(struct descriptor* d)
+{
+ if (d->len % sizeof(struct dvb_content_nibble))
+ return NULL;
+
+ return (struct dvb_content_descriptor*) d;
+}
+
+/**
+ * Iterator for the nibbles field of a dvb_content_descriptor.
+ *
+ * @param d dvb_content_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_content_nibble.
+ */
+#define dvb_content_descriptor_nibbles_for_each(d, pos) \
+ for ((pos) = dvb_content_descriptor_nibbles_first(d); \
+ (pos); \
+ (pos) = dvb_content_descriptor_nibbles_next(d, pos))
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_content_nibble*
+ dvb_content_descriptor_nibbles_first(struct dvb_content_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_content_nibble *)
+ ((uint8_t*) d + sizeof(struct dvb_content_descriptor));
+}
+
+static inline struct dvb_content_nibble*
+ dvb_content_descriptor_nibbles_next(struct dvb_content_descriptor *d,
+ struct dvb_content_nibble *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_content_nibble);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_content_nibble *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/content_identifier_descriptor.h b/lib/libucsi/dvb/content_identifier_descriptor.h
new file mode 100644
index 0000000..c2cf9ea
--- /dev/null
+++ b/lib/libucsi/dvb/content_identifier_descriptor.h
@@ -0,0 +1,233 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_CONTENT_IDENTIFIER_DESCRIPTOR
+#define _UCSI_DVB_CONTENT_IDENTIFIER_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+
+/**
+ * Possible values for the crid_type.
+ */
+enum {
+ DVB_CRID_TYPE_NONE = 0x00,
+ DVB_CRID_TYPE_ITEM = 0x01,
+ DVB_CRID_TYPE_SERIES = 0x02,
+ DVB_CRID_TYPE_RECOMMENDATION = 0x03,
+};
+
+/**
+ * Possible values for the crid_location.
+ */
+enum {
+ DVB_CRID_LOCATION_THIS_DESCRIPTOR = 0x00,
+ DVB_CRID_LOCATION_CIT = 0x01,
+};
+
+/**
+ * dvb_content_identifier_descriptor structure.
+ */
+struct dvb_content_identifier_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_content_identifier_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the entries field of a dvb_content_identifier_descriptor.
+ */
+struct dvb_content_identifier_entry {
+ EBIT2(uint8_t crid_type : 6; ,
+ uint8_t crid_location : 2; );
+ /* struct dvb_content_identifier_data_00 data0 */
+ /* struct dvb_content_identifier_data_01 data1 */
+} __ucsi_packed;
+
+/**
+ * The data if crid_location == 0
+ */
+struct dvb_content_identifier_entry_data_0 {
+ uint8_t crid_length;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * The data if crid_location == 1
+ */
+struct dvb_content_identifier_entry_data_1 {
+ uint16_t crid_ref;
+} __ucsi_packed;
+
+
+/**
+ * Process a dvb_content_identifier_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return dvb_content_identifier_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_content_identifier_descriptor*
+ dvb_content_identifier_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len + 2;
+ uint32_t pos = 2;
+ uint8_t *buf = (uint8_t*) d;
+
+ while(pos < len) {
+ struct dvb_content_identifier_entry *e =
+ (struct dvb_content_identifier_entry*) (buf + pos);
+
+ if (len < (pos+1))
+ return NULL;
+ pos++;
+
+ switch(e->crid_location) {
+ case 0:
+ if (len < (pos + 1))
+ return NULL;
+ if (len < (pos + 1 + buf[pos]))
+ return NULL;
+ pos += 1 + buf[pos];
+ break;
+
+ case 1:
+ if (len < (pos+2))
+ return NULL;
+ bswap16(buf+pos);
+ break;
+ }
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return (struct dvb_content_identifier_descriptor*) d;
+}
+
+/**
+ * Iterator for entries field of a dvb_content_identifier_descriptor.
+ *
+ * @param d dvb_content_identifier_descriptor pointer.
+ * @param pos Variable holding a pointer to the current dvb_content_identifier_entry.
+ */
+#define dvb_content_identifier_descriptor_entries_for_each(d, pos) \
+ for ((pos) = dvb_content_identifier_descriptor_entries_first(d); \
+ (pos); \
+ (pos) = dvb_content_identifier_descriptor_entries_next(d, pos))
+
+/**
+ * Accessor for the data0 field of a dvb_content_identifier_entry.
+ *
+ * @param d dvb_content_identifier_entry pointer.
+ * @return Pointer, or NULL on error.
+ */
+static inline struct dvb_content_identifier_entry_data_0*
+ dvb_content_identifier_entry_data_0(struct dvb_content_identifier_entry *d)
+{
+ if (d->crid_location != 0)
+ return NULL;
+ return (struct dvb_content_identifier_entry_data_0*)
+ ((uint8_t*) d + sizeof(struct dvb_content_identifier_entry));
+}
+/**
+ * Accessor for the data field of a dvb_content_identifier_entry_data_0.
+ *
+ * @param d dvb_content_identifier_entry_data_0 pointer.
+ * @return Pointer, or NULL on error.
+ */
+static inline uint8_t*
+ dvb_content_identifier_entry_data_0_data(struct dvb_content_identifier_entry_data_0 *d)
+{
+ return ((uint8_t*) d + sizeof(struct dvb_content_identifier_entry_data_0));
+}
+
+/**
+ * Accessor for the data1 field of a dvb_content_identifier_entry.
+ *
+ * @param d dvb_content_identifier_entry pointer.
+ * @return Pointer, or NULL on error.
+ */
+static inline struct dvb_content_identifier_entry_data_1*
+ dvb_content_identifier_entry_data_1(struct dvb_content_identifier_entry *d)
+{
+ if (d->crid_location != 1)
+ return NULL;
+ return (struct dvb_content_identifier_entry_data_1*)
+ ((uint8_t*) d + sizeof(struct dvb_content_identifier_entry));
+}
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_content_identifier_entry*
+ dvb_content_identifier_descriptor_entries_first(struct dvb_content_identifier_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_content_identifier_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_content_identifier_descriptor));
+}
+
+static inline struct dvb_content_identifier_entry*
+ dvb_content_identifier_descriptor_entries_next(struct dvb_content_identifier_descriptor *d,
+ struct dvb_content_identifier_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_content_identifier_entry);
+
+ if (next >= end)
+ return NULL;
+
+ switch(pos->crid_location) {
+ case 0:
+ if ((next+2) >= end)
+ return NULL;
+ if ((next+2+next[1]) >= end)
+ return NULL;
+ break;
+
+ case 1:
+ if ((next+3) >= end)
+ return NULL;
+ break;
+ }
+
+ return (struct dvb_content_identifier_entry*) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/country_availability_descriptor.h b/lib/libucsi/dvb/country_availability_descriptor.h
new file mode 100644
index 0000000..65b1661
--- /dev/null
+++ b/lib/libucsi/dvb/country_availability_descriptor.h
@@ -0,0 +1,120 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_COUNTRY_AVAILABILITY_DESCRIPTOR
+#define _UCSI_DVB_COUNTRY_AVAILABILITY_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_country_availability_descriptor structure.
+ */
+struct dvb_country_availability_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t country_availability_flag : 1; ,
+ uint8_t reserved : 7; );
+ /* struct dvb_country_availability_entry countries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the countries field of a dvb_country_availability_descriptor.
+ */
+struct dvb_country_availability_entry {
+ iso639country_t country_code;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_country_availability_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_country_availability_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_country_availability_descriptor*
+ dvb_country_availability_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len;
+
+ if (len < (sizeof(struct dvb_country_availability_descriptor) - 2))
+ return NULL;
+
+ if ((len - 1) % sizeof(struct dvb_country_availability_entry))
+ return NULL;
+
+ return (struct dvb_country_availability_descriptor*) d;
+}
+
+/**
+ * Iterator for the countries field of a dvb_country_availability_descriptor.
+ *
+ * @param d dvb_country_availability_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_country_availability_entry.
+ */
+#define dvb_country_availability_descriptor_countries_for_each(d, pos) \
+ for ((pos) = dvb_country_availability_descriptor_countries_first(d); \
+ (pos); \
+ (pos) = dvb_country_availability_descriptor_countries_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_country_availability_entry*
+ dvb_country_availability_descriptor_countries_first(struct dvb_country_availability_descriptor *d)
+{
+ if (d->d.len == 1)
+ return NULL;
+
+ return (struct dvb_country_availability_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_country_availability_descriptor));
+}
+
+static inline struct dvb_country_availability_entry*
+ dvb_country_availability_descriptor_countries_next(struct dvb_country_availability_descriptor *d,
+ struct dvb_country_availability_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_country_availability_entry);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_country_availability_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/data_broadcast_descriptor.h b/lib/libucsi/dvb/data_broadcast_descriptor.h
new file mode 100644
index 0000000..069e1db
--- /dev/null
+++ b/lib/libucsi/dvb/data_broadcast_descriptor.h
@@ -0,0 +1,139 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_DATA_BROADCAST_DESCRIPTOR
+#define _UCSI_DVB_DATA_BROADCAST_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_data_broadcast_descriptor structure.
+ */
+struct dvb_data_broadcast_descriptor {
+ struct descriptor d;
+
+ uint16_t data_broadcast_id;
+ uint8_t component_tag;
+ uint8_t selector_length;
+ /* uint8_t selector[] */
+ /* struct dvb_data_broadcast_descriptor_part2 part2 */
+} __ucsi_packed;
+
+/**
+ * Second part of a dvb_data_broadcast_descriptor following the variable length selector field.
+ */
+struct dvb_data_broadcast_descriptor_part2 {
+ iso639lang_t language_code;
+ uint8_t text_length;
+ /* uint8_t text[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_data_broadcast_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_data_broadcast_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_data_broadcast_descriptor*
+ dvb_data_broadcast_descriptor_codec(struct descriptor* d)
+{
+ struct dvb_data_broadcast_descriptor *p =
+ (struct dvb_data_broadcast_descriptor *) d;
+ struct dvb_data_broadcast_descriptor_part2 *p2;
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t pos = sizeof(struct dvb_data_broadcast_descriptor) - 2;
+ uint32_t len = d->len;
+
+ if (pos > len)
+ return NULL;
+
+ bswap16(buf + 2);
+
+ pos += p->selector_length;
+
+ if (pos > len)
+ return NULL;
+
+ p2 = (struct dvb_data_broadcast_descriptor_part2*) (buf + 2 + pos);
+
+ pos += sizeof(struct dvb_data_broadcast_descriptor_part2);
+
+ if (pos > len)
+ return NULL;
+
+ pos += p2->text_length;
+
+ if (pos != len)
+ return NULL;
+
+ return p;
+}
+
+/**
+ * Accessor for the selector field of a dvb_data_broadcast_descriptor.
+ *
+ * @param d dvb_data_broadcast_descriptor pointer.
+ * @return pointer to the field.
+ */
+static inline uint8_t *
+ dvb_data_broadcast_descriptor_selector(struct dvb_data_broadcast_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_data_broadcast_descriptor);
+}
+
+/**
+ * Accessor for the second part of a dvb_data_broadcast_descriptor.
+ *
+ * @param d dvb_data_broadcast_descriptor pointer.
+ * @return dvb_data_broadcast_descriptor_part2 pointer.
+ */
+static inline struct dvb_data_broadcast_descriptor_part2 *
+ dvb_data_broadcast_descriptor_part2(struct dvb_data_broadcast_descriptor *d)
+{
+ return (struct dvb_data_broadcast_descriptor_part2*)
+ ((uint8_t*) d + sizeof(struct dvb_data_broadcast_descriptor) +
+ d->selector_length);
+}
+
+/**
+ * Accessor for the text field in a dvb_data_broadcast_descriptor_part2.
+ *
+ * @param d dvb_data_broadcast_descriptor_part2 pointer.
+ * @return pointer to the field.
+ */
+static inline uint8_t *
+ dvb_data_broadcast_descriptor_part2_text(struct dvb_data_broadcast_descriptor_part2 *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_data_broadcast_descriptor_part2);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/data_broadcast_id_descriptor.h b/lib/libucsi/dvb/data_broadcast_id_descriptor.h
new file mode 100644
index 0000000..446927c
--- /dev/null
+++ b/lib/libucsi/dvb/data_broadcast_id_descriptor.h
@@ -0,0 +1,221 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_DATA_BROADCAST_ID_DESCRIPTOR
+#define _UCSI_DVB_DATA_BROADCAST_ID_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Possible values for data_broadcast_id.
+ */
+enum {
+ DVB_BROADCAST_ID_DATA_PIPE = 0X0001,
+ DVB_BROADCAST_ID_ASYNCHRONOUS_DATA_STREAM = 0X0002,
+ DVB_BROADCAST_ID_SYNCHRONOUS_DATA_STREAM = 0X0003,
+ DVB_BROADCAST_ID_SYNCHRONISED_DATA_STREAM = 0X0004,
+ DVB_BROADCAST_ID_MULTI_PROTOCOL_ENCAPSULATION = 0X0005,
+ DVB_BROADCAST_ID_DATA_CAROUSEL = 0X0006,
+ DVB_BROADCAST_ID_OBJECT_CAROUSEL = 0X0007,
+ DVB_BROADCAST_ID_DVB_ATM_STREAMS = 0X0008,
+ DVB_BROADCAST_ID_HIGHER_PROTOCOLS = 0X0009,
+ DVB_BROADCAST_ID_SOFTWARE_UPDATE = 0x000A,
+ DVB_BROADCAST_ID_IP_MAC_NOTIFICATION_TABLE = 0x000B,
+};
+
+/**
+ * dvb_data_broadcast_id_descriptor structure.
+ */
+struct dvb_data_broadcast_id_descriptor {
+ struct descriptor d;
+
+ uint16_t data_broadcast_id;
+ /* uint8_t id_selector_byte[] */
+} __ucsi_packed;
+
+/**
+ * id_selector_byte for 0x000b data_broadcast_id (IP/MAC Notification Table).
+ */
+struct dvb_id_selector_byte_000b {
+ uint8_t platform_id_data_length;
+ /* struct dvb_ip_mac_notification_info infos[] */
+ /* uint8_t private_data[] */
+} __ucsi_packed;
+
+/**
+ * Entries in the infos field of a dvb_id_selector_byte_0b.
+ */
+struct dvb_ip_mac_notification_info {
+ EBIT2(uint32_t platform_id : 24; ,
+ uint8_t action_type : 8; );
+ EBIT3(uint8_t reserved : 2; ,
+ uint8_t INT_versioning_flag : 1; ,
+ uint8_t INT_version : 5; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_data_broadcast_id_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_data_broadcast_id_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_data_broadcast_id_descriptor*
+ dvb_data_broadcast_id_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct dvb_data_broadcast_id_descriptor) - 2))
+ return NULL;
+
+ bswap16((uint8_t*) d + 2);
+
+ return (struct dvb_data_broadcast_id_descriptor*) d;
+}
+
+/**
+ * Accessor for the selector_byte field of a dvb_data_broadcast_id_descriptor.
+ *
+ * @param d dvb_data_broadcast_id_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_data_broadcast_id_descriptor_id_selector_byte(struct dvb_data_broadcast_id_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_data_broadcast_id_descriptor);
+}
+
+/**
+ * Determine the length of the selector_byte field of a dvb_data_broadcast_id_descriptor.
+ *
+ * @param d dvb_data_broadcast_id_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_data_broadcast_id_descriptor_id_selector_byte_length(struct dvb_data_broadcast_id_descriptor *d)
+{
+ return d->d.len - 2;
+}
+
+/**
+ * Accessor for a dvb_id_selector_byte_000b pointer.
+ *
+ * @param d dvb_data_broadcast_id_descriptor pointer.
+ * @return Pointer to the data field.
+ */
+static inline struct dvb_id_selector_byte_000b *
+ dvb_id_selector_byte_000b(struct dvb_data_broadcast_id_descriptor *d)
+{
+ if (d->data_broadcast_id != DVB_BROADCAST_ID_IP_MAC_NOTIFICATION_TABLE)
+ return NULL;
+ return (struct dvb_id_selector_byte_000b *) dvb_data_broadcast_id_descriptor_id_selector_byte(d);
+}
+
+/**
+ * Iterator for the dvb_ip_mac_notification_info field of a dvb_id_selector_byte_000b.
+ *
+ * @param id_selector_byte dvb_id_selector_byte_000b pointer.
+ * @param pos Variable containing a pointer to the current dvb_ip_mac_notification_info.
+ */
+#define dvb_id_selector_byte_000b_ip_mac_notification_info_for_each(id_selector_byte, pos) \
+ for ((pos) = dvb_ip_mac_notification_info_first(id_selector_byte); \
+ (pos); \
+ (pos) = dvb_ip_mac_notification_info_next(id_selector_byte, pos))
+
+/**
+ * Length of the private_data field of a dvb_id_selector_byte_000b.
+ *
+ * @param d descriptor pointer.
+ * @param i dvb_id_selector_byte_000b pointer.
+ * @return Length of the field.
+ */
+static inline uint8_t
+ dvb_id_selector_byte_000b_private_data_length(struct descriptor *d,
+ struct dvb_id_selector_byte_000b *i)
+{
+ return (uint8_t) (d->len -
+ sizeof(struct descriptor) -
+ i->platform_id_data_length -
+ sizeof(struct dvb_id_selector_byte_000b));
+}
+
+/**
+ * Accessor for the private_data field of a dvb_id_selector_byte_000b.
+ *
+ * @param d descriptor pointer.
+ * @param i dvb_id_selector_byte_000b pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_id_selector_byte_000b_private_data(struct descriptor *d,
+ struct dvb_id_selector_byte_000b *i)
+{
+ if (dvb_id_selector_byte_000b_private_data_length(d, i) <= 0)
+ return NULL;
+
+ return (uint8_t *) i + i->platform_id_data_length + sizeof(struct dvb_id_selector_byte_000b);
+}
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ip_mac_notification_info *
+ dvb_ip_mac_notification_info_first(struct dvb_id_selector_byte_000b *d)
+{
+ if (d->platform_id_data_length == 0)
+ return NULL;
+
+ bswap32((uint8_t *) d + sizeof(struct dvb_id_selector_byte_000b));
+
+ return (struct dvb_ip_mac_notification_info *) ((uint8_t *) d + sizeof(struct dvb_id_selector_byte_000b));
+}
+
+static inline struct dvb_ip_mac_notification_info *
+ dvb_ip_mac_notification_info_next(struct dvb_id_selector_byte_000b *d,
+ struct dvb_ip_mac_notification_info *pos)
+{
+ uint8_t *end = (uint8_t *) d + d->platform_id_data_length;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_id_selector_byte_000b) +
+ sizeof(struct dvb_ip_mac_notification_info);
+
+ if (next >= end)
+ return NULL;
+
+ bswap32(next);
+
+ return (struct dvb_ip_mac_notification_info *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#include <libucsi/dvb/mhp_data_broadcast_id_descriptor.h>
diff --git a/lib/libucsi/dvb/default_authority_descriptor.h b/lib/libucsi/dvb/default_authority_descriptor.h
new file mode 100644
index 0000000..0b0ba73
--- /dev/null
+++ b/lib/libucsi/dvb/default_authority_descriptor.h
@@ -0,0 +1,82 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_DEFAULT_AUTHORITY_DESCRIPTOR
+#define _UCSI_DVB_DEFAULT_AUTHORITY_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_default_authority_descriptor structure.
+ */
+struct dvb_default_authority_descriptor {
+ struct descriptor d;
+
+ /* char name[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_default_authority_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_default_authority_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_default_authority_descriptor*
+ dvb_default_authority_descriptor_codec(struct descriptor* d)
+{
+ return (struct dvb_default_authority_descriptor*) d;
+}
+
+/**
+ * Accessor for the name field in a dvb_default_authority_descriptor.
+ *
+ * @param d dvb_default_authority_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_default_authority_descriptor_name(struct dvb_default_authority_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_default_authority_descriptor);
+}
+
+/**
+ * Calculate the length of the name field in a dvb_default_authority_descriptor.
+ *
+ * @param d dvb_default_authority_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_default_authority_descriptor_name_length(struct dvb_default_authority_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/descriptor.h b/lib/libucsi/dvb/descriptor.h
new file mode 100644
index 0000000..303e17a
--- /dev/null
+++ b/lib/libucsi/dvb/descriptor.h
@@ -0,0 +1,229 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_DESCRIPTOR_H
+#define _UCSI_DVB_DESCRIPTOR_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/dvb/ac3_descriptor.h>
+#include <libucsi/dvb/adaptation_field_data_descriptor.h>
+#include <libucsi/dvb/ancillary_data_descriptor.h>
+#include <libucsi/dvb/announcement_support_descriptor.h>
+#include <libucsi/dvb/application_signalling_descriptor.h>
+#include <libucsi/dvb/bouquet_name_descriptor.h>
+#include <libucsi/dvb/ca_identifier_descriptor.h>
+#include <libucsi/dvb/cable_delivery_descriptor.h>
+#include <libucsi/dvb/cell_frequency_link_descriptor.h>
+#include <libucsi/dvb/cell_list_descriptor.h>
+#include <libucsi/dvb/component_descriptor.h>
+#include <libucsi/dvb/content_descriptor.h>
+#include <libucsi/dvb/content_identifier_descriptor.h>
+#include <libucsi/dvb/country_availability_descriptor.h>
+#include <libucsi/dvb/data_broadcast_descriptor.h>
+#include <libucsi/dvb/data_broadcast_id_descriptor.h>
+#include <libucsi/dvb/default_authority_descriptor.h>
+#include <libucsi/dvb/dsng_descriptor.h>
+#include <libucsi/dvb/extended_event_descriptor.h>
+#include <libucsi/dvb/frequency_list_descriptor.h>
+#include <libucsi/dvb/ip_mac_platform_name_descriptor.h>
+#include <libucsi/dvb/ip_mac_platform_provider_name_descriptor.h>
+#include <libucsi/dvb/ip_mac_stream_location_descriptor.h>
+#include <libucsi/dvb/linkage_descriptor.h>
+#include <libucsi/dvb/local_time_offset_descriptor.h>
+#include <libucsi/dvb/mosaic_descriptor.h>
+#include <libucsi/dvb/multilingual_bouquet_name_descriptor.h>
+#include <libucsi/dvb/multilingual_component_descriptor.h>
+#include <libucsi/dvb/multilingual_network_name_descriptor.h>
+#include <libucsi/dvb/multilingual_service_name_descriptor.h>
+#include <libucsi/dvb/network_name_descriptor.h>
+#include <libucsi/dvb/nvod_reference_descriptor.h>
+#include <libucsi/dvb/parental_rating_descriptor.h>
+#include <libucsi/dvb/partial_transport_stream_descriptor.h>
+#include <libucsi/dvb/pdc_descriptor.h>
+#include <libucsi/dvb/private_data_specifier_descriptor.h>
+#include <libucsi/dvb/related_content_descriptor.h>
+#include <libucsi/dvb/satellite_delivery_descriptor.h>
+#include <libucsi/dvb/s2_satellite_delivery_descriptor.h>
+#include <libucsi/dvb/scrambling_descriptor.h>
+#include <libucsi/dvb/service_availability_descriptor.h>
+#include <libucsi/dvb/service_descriptor.h>
+#include <libucsi/dvb/service_identifier_descriptor.h>
+#include <libucsi/dvb/service_list_descriptor.h>
+#include <libucsi/dvb/service_move_descriptor.h>
+#include <libucsi/dvb/short_event_descriptor.h>
+#include <libucsi/dvb/short_smoothing_buffer_descriptor.h>
+#include <libucsi/dvb/stream_identifier_descriptor.h>
+#include <libucsi/dvb/stuffing_descriptor.h>
+#include <libucsi/dvb/subtitling_descriptor.h>
+#include <libucsi/dvb/target_ip_address_descriptor.h>
+#include <libucsi/dvb/target_ipv6_address_descriptor.h>
+#include <libucsi/dvb/target_ip_slash_descriptor.h>
+#include <libucsi/dvb/target_ip_source_slash_descriptor.h>
+#include <libucsi/dvb/target_ipv6_slash_descriptor.h>
+#include <libucsi/dvb/target_ipv6_source_slash_descriptor.h>
+#include <libucsi/dvb/telephone_descriptor.h>
+#include <libucsi/dvb/teletext_descriptor.h>
+#include <libucsi/dvb/terrestrial_delivery_descriptor.h>
+#include <libucsi/dvb/time_shifted_event_descriptor.h>
+#include <libucsi/dvb/time_shifted_service_descriptor.h>
+#include <libucsi/dvb/transport_stream_descriptor.h>
+#include <libucsi/dvb/tva_id_descriptor.h>
+#include <libucsi/dvb/vbi_data_descriptor.h>
+#include <libucsi/dvb/vbi_teletext_descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * The following are disabled because support is incomplete just now.
+ */
+/*
+#include <libucsi/dvb/rnt_rar_over_dvb_stream_descriptor.h>
+#include <libucsi/dvb/rnt_rar_over_ip_descriptor.h>
+#include <libucsi/dvb/rnt_rnt_scan_descriptor.h>
+#include <libucsi/dvb/ait_application_descriptor.h>
+#include <libucsi/dvb/ait_application_name_descriptor.h>
+#include <libucsi/dvb/ait_external_application_authorisation_descriptor.h>
+#include <libucsi/dvb/ait_application_icons_descriptor.h>
+*/
+
+/**
+ * The following are not implemented just now
+ */
+/*
+#include <libucsi/dvb/ait_transport_protocol_descriptor.h>
+#include <libucsi/dvb/ait_dvb_j_application_descriptor.h>
+#include <libucsi/dvb/ait_dvb_j_application_location_descriptor.h>
+#include <libucsi/dvb/ait_dvb_html_application_descriptor.h>
+#include <libucsi/dvb/ait_dvb_html_application_location_descriptor.h>
+#include <libucsi/dvb/ait_dvb_html_application_boundary_descriptor.h>
+#include <libucsi/dvb/ait_prefetch_descriptor.h>
+#include <libucsi/dvb/ait_dii_location_descriptor.h>
+#include <libucsi/dvb/ait_ip_signalling_descriptor.h>
+*/
+
+/**
+ * Enumeration of DVB descriptor tags.
+ */
+enum dvb_descriptor_tag {
+ dtag_dvb_network_name = 0x40,
+ dtag_dvb_service_list = 0x41,
+ dtag_dvb_stuffing = 0x42,
+ dtag_dvb_satellite_delivery_system = 0x43,
+ dtag_dvb_cable_delivery_system = 0x44,
+ dtag_dvb_vbi_data = 0x45,
+ dtag_dvb_vbi_teletext = 0x46,
+ dtag_dvb_bouquet_name = 0x47,
+ dtag_dvb_service = 0x48,
+ dtag_dvb_country_availability = 0x49,
+ dtag_dvb_linkage = 0x4a,
+ dtag_dvb_nvod_reference = 0x4b,
+ dtag_dvb_time_shifted_service = 0x4c,
+ dtag_dvb_short_event = 0x4d,
+ dtag_dvb_extended_event = 0x4e,
+ dtag_dvb_time_shifted_event = 0x4f,
+ dtag_dvb_component = 0x50,
+ dtag_dvb_mosaic = 0x51,
+ dtag_dvb_stream_identifier = 0x52,
+ dtag_dvb_ca_identifier = 0x53,
+ dtag_dvb_content = 0x54,
+ dtag_dvb_parental_rating = 0x55,
+ dtag_dvb_teletext = 0x56,
+ dtag_dvb_telephone = 0x57,
+ dtag_dvb_local_time_offset = 0x58,
+ dtag_dvb_subtitling = 0x59,
+ dtag_dvb_terrestial_delivery_system = 0x5a,
+ dtag_dvb_multilingual_network_name = 0x5b,
+ dtag_dvb_multilingual_bouquet_name = 0x5c,
+ dtag_dvb_multilingual_service_name = 0x5d,
+ dtag_dvb_multilingual_component = 0x5e,
+ dtag_dvb_private_data_specifier = 0x5f,
+ dtag_dvb_service_move = 0x60,
+ dtag_dvb_short_smoothing_buffer = 0x61,
+ dtag_dvb_frequency_list = 0x62,
+ dtag_dvb_partial_transport_stream = 0x63,
+ dtag_dvb_data_broadcast = 0x64,
+ dtag_dvb_scrambling = 0x65,
+ dtag_dvb_data_broadcast_id = 0x66,
+ dtag_dvb_transport_stream = 0x67,
+ dtag_dvb_dsng = 0x68,
+ dtag_dvb_pdc = 0x69,
+ dtag_dvb_ac3 = 0x6a,
+ dtag_dvb_ancillary_data = 0x6b,
+ dtag_dvb_cell_list = 0x6c,
+ dtag_dvb_cell_frequency_link = 0x6d,
+ dtag_dvb_announcement_support = 0x6e,
+ dtag_dvb_application_signalling = 0x6f,
+ dtag_dvb_adaptation_field_data = 0x70,
+ dtag_dvb_service_identifier = 0x71,
+ dtag_dvb_service_availability = 0x72,
+ dtag_dvb_default_authority = 0x73,
+ dtag_dvb_related_content = 0x74,
+ dtag_dvb_tva_id = 0x75,
+ dtag_dvb_content_identifier = 0x76,
+ dtag_dvb_time_slice_fec_identifier = 0x77,
+ dtag_dvb_ecm_repetition_rate = 0x78,
+ dtag_dvb_s2_satellite_delivery_descriptor= 0x79,
+ dtag_dvb_enhanced_ac3_descriptor = 0x7a,
+ dtag_dvb_dts_descriptor = 0x7b,
+ dtag_dvb_aac_descriptor = 0x7c,
+ dtag_dvb_extension_descriptor = 0x7f,
+
+ /* descriptors which may only appear in an RNT */
+ dtag_dvb_rnt_rar_over_dvb_stream = 0x40,
+ dtag_dvb_rnt_rar_over_ip = 0x41,
+ dtag_dvb_rnt_rnt_scan = 0x42,
+
+ /* descriptors which may only appear in an AIT */
+ dtag_dvb_ait_application = 0x00,
+ dtag_dvb_ait_application_name = 0x01,
+ dtag_dvb_ait_transport_protocol = 0x02,
+ dtag_dvb_ait_dvb_j_application = 0x03,
+ dtag_dvb_ait_dvb_j_application_location = 0x04,
+ dtag_dvb_ait_external_application_authorisation = 0x05,
+ dtag_dvb_ait_dvb_html_application = 0x08,
+ dtag_dvb_ait_dvb_html_application_location = 0x09,
+ dtab_dvb_ait_dvb_html_application_boundary = 0x0a,
+ dtag_dvb_ait_application_icons = 0x0b,
+ dtag_dvb_ait_prefetch = 0x0c,
+ dtag_dvb_ait_dii_location = 0x0d,
+ dtag_dvb_ait_ip_signalling = 0x11,
+
+ /* descriptors which may only appear in INT */
+ dtag_dvb_target_ip_address = 0x09,
+ dtag_dvb_target_ipv6_address = 0x0a,
+ dtag_dvb_ip_mac_platform_name = 0x0c,
+ dtag_dvb_ip_mac_platform_provider_name = 0x0d,
+ dtag_dvb_target_ip_slash = 0x0f,
+ dtag_dvb_target_ip_source_slash = 0x10,
+ dtag_dvb_target_ipv6_slash = 0x11,
+ dtag_dvb_target_ipv6_source_slash = 0x12,
+ dtag_dvb_ip_mac_stream_location = 0x13,
+
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/dit_section.c b/lib/libucsi/dvb/dit_section.c
new file mode 100644
index 0000000..4f69d4e
--- /dev/null
+++ b/lib/libucsi/dvb/dit_section.c
@@ -0,0 +1,32 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/dit_section.h>
+
+struct dvb_dit_section * dvb_dit_section_codec(struct section * section)
+{
+ struct dvb_dit_section * ret = (struct dvb_dit_section *)section;
+
+ if (section->length < 1)
+ return NULL;
+
+ return ret;
+}
diff --git a/lib/libucsi/dvb/dit_section.h b/lib/libucsi/dvb/dit_section.h
new file mode 100644
index 0000000..69fce4f
--- /dev/null
+++ b/lib/libucsi/dvb/dit_section.h
@@ -0,0 +1,54 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_DIT_SECTION_H
+#define _UCSI_DVB_DIT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * dvb_dit_section structure.
+ */
+struct dvb_dit_section {
+ struct section head;
+
+ EBIT2(uint8_t transition_flag : 1; ,
+ uint8_t reserved : 7; );
+};
+
+/**
+ * Process a dvb_dit_section.
+ *
+ * @param section Pointer to a generic section header.
+ * @return Pointer to a dvb_dit_section, or NULL on error.
+ */
+struct dvb_dit_section * dvb_dit_section_codec(struct section *section);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/dsng_descriptor.h b/lib/libucsi/dvb/dsng_descriptor.h
new file mode 100644
index 0000000..6fd369b
--- /dev/null
+++ b/lib/libucsi/dvb/dsng_descriptor.h
@@ -0,0 +1,80 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_DSNG_DESCRIPTOR
+#define _UCSI_DVB_DSNG_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_dsng_descriptor structure.
+ */
+struct dvb_dsng_descriptor {
+ struct descriptor d;
+
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_dsng_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to a dvb_dsng_descriptor, or NULL on error.
+ */
+static inline struct dvb_dsng_descriptor*
+ dvb_dsng_descriptor_codec(struct descriptor* d)
+{
+ return (struct dvb_dsng_descriptor*) d;
+}
+
+/**
+ * Accessor for the data field in a dvb_dsng_descriptor.
+ *
+ * @param d dvb_dsng_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *dvb_dsng_descriptor_data(struct dvb_dsng_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_dsng_descriptor);
+}
+
+/**
+ * Determine the length of the data field in a dvb_dsng_descriptor.
+ *
+ * @param d dvb_dsng_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int dvb_dsng_descriptor_data_length(struct dvb_dsng_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/eit_section.c b/lib/libucsi/dvb/eit_section.c
new file mode 100644
index 0000000..97b0261
--- /dev/null
+++ b/lib/libucsi/dvb/eit_section.c
@@ -0,0 +1,63 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/eit_section.h>
+
+struct dvb_eit_section *dvb_eit_section_codec(struct section_ext * ext)
+{
+ uint8_t * buf = (uint8_t *) ext;
+ size_t pos = sizeof(struct section_ext);
+ size_t len = section_ext_length(ext);
+
+ if (len < sizeof(struct dvb_eit_section))
+ return NULL;
+
+ bswap16(buf + pos);
+ pos += 2;
+ bswap16(buf + pos);
+ pos += 4;
+
+ while (pos < len) {
+ struct dvb_eit_event * event =
+ (struct dvb_eit_event *) (buf + pos);
+
+ if ((pos + sizeof(struct dvb_eit_event)) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+ bswap16(buf + pos + 10);
+
+ pos += sizeof(struct dvb_eit_event);
+
+ if ((pos + event->descriptors_loop_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, event->descriptors_loop_length))
+ return NULL;
+
+ pos += event->descriptors_loop_length;
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return (struct dvb_eit_section *) ext;
+}
diff --git a/lib/libucsi/dvb/eit_section.h b/lib/libucsi/dvb/eit_section.h
new file mode 100644
index 0000000..a2f3e4f
--- /dev/null
+++ b/lib/libucsi/dvb/eit_section.h
@@ -0,0 +1,160 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_EIT_SECTION_H
+#define _UCSI_DVB_EIT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+#include <libucsi/dvb/types.h>
+
+
+/**
+ * dvb_eit_section structure.
+ */
+struct dvb_eit_section {
+ struct section_ext head;
+
+ uint16_t transport_stream_id;
+ uint16_t original_network_id;
+ uint8_t segment_last_section_number;
+ uint8_t last_table_id;
+ /* struct eit_event events[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the events field of a dvb_eit_section.
+ */
+struct dvb_eit_event {
+ uint16_t event_id;
+ dvbdate_t start_time;
+ dvbduration_t duration;
+ EBIT3(uint16_t running_status : 3; ,
+ uint16_t free_ca_mode : 1; ,
+ uint16_t descriptors_loop_length:12; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_eit_section.
+ *
+ * @param section Pointer to a generic section_ext structure.
+ * @return Pointer to a dvb_eit_section, or NULL on error.
+ */
+struct dvb_eit_section *dvb_eit_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for the service_id field of an EIT.
+ *
+ * @param eit EIT pointer.
+ * @return The service_id.
+ */
+static inline uint16_t dvb_eit_section_service_id(struct dvb_eit_section *eit)
+{
+ return eit->head.table_id_ext;
+}
+
+/**
+ * Iterator for the events field of a dvb_eit_section.
+ *
+ * @param eit dvb_eit_section pointer.
+ * @param pos Variable containing a pointer to the current dvb_eit_event.
+ */
+#define dvb_eit_section_events_for_each(eit, pos) \
+ for ((pos) = dvb_eit_section_events_first(eit); \
+ (pos); \
+ (pos) = dvb_eit_section_events_next(eit, pos))
+
+/**
+ * Iterator for the descriptors field of a dvb_eit_event.
+ *
+ * @param eit dvb_eit_event pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define dvb_eit_event_descriptors_for_each(event, pos) \
+ for ((pos) = dvb_eit_event_descriptors_first(event); \
+ (pos); \
+ (pos) = dvb_eit_event_descriptors_next(event, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_eit_event *
+ dvb_eit_section_events_first(struct dvb_eit_section *eit)
+{
+ size_t pos = sizeof(struct dvb_eit_section);
+
+ if (pos >= section_ext_length(&eit->head))
+ return NULL;
+
+ return (struct dvb_eit_event*) ((uint8_t *) eit + pos);
+}
+
+static inline struct dvb_eit_event *
+ dvb_eit_section_events_next(struct dvb_eit_section *eit,
+ struct dvb_eit_event *pos)
+{
+ uint8_t *end = (uint8_t*) eit + section_ext_length(&eit->head);
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_eit_event) +
+ pos->descriptors_loop_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_eit_event *) next;
+}
+
+static inline struct descriptor *
+ dvb_eit_event_descriptors_first(struct dvb_eit_event * t)
+{
+ if (t->descriptors_loop_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) t + sizeof(struct dvb_eit_event));
+}
+
+static inline struct descriptor *
+ dvb_eit_event_descriptors_next(struct dvb_eit_event * t,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) t + sizeof(struct dvb_eit_event),
+ t->descriptors_loop_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/extended_event_descriptor.h b/lib/libucsi/dvb/extended_event_descriptor.h
new file mode 100644
index 0000000..bba04b0
--- /dev/null
+++ b/lib/libucsi/dvb/extended_event_descriptor.h
@@ -0,0 +1,232 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_EXTENDED_EVENT_DESCRIPTOR
+#define _UCSI_DVB_EXTENDED_EVENT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_extended_event_descriptor structure.
+ */
+struct dvb_extended_event_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t descriptor_number : 4; ,
+ uint8_t last_descriptor_number : 4; );
+ iso639lang_t language_code;
+ uint8_t length_of_items;
+ /* struct dvb_extended_event_item items[] */
+ /* struct dvb_extended_event_descriptor_part2 part2 */
+} __ucsi_packed;
+
+/**
+ * An entry in the items field of a dvb_extended_event_descriptor.
+ */
+struct dvb_extended_event_item {
+ uint8_t item_description_length;
+ /* uint8_t item_description[] */
+ /* struct dvb_extended_event_item_part2 part2 */
+} __ucsi_packed;
+
+/**
+ * The second part of a dvb_extended_event_item, following the variable length
+ * description field.
+ */
+struct dvb_extended_event_item_part2 {
+ uint8_t item_length;
+ /* uint8_t item[] */
+} __ucsi_packed;
+
+/**
+ * The second part of a dvb_extended_event_descriptor, following the variable
+ * length items field.
+ */
+struct dvb_extended_event_descriptor_part2 {
+ uint8_t text_length;
+ /* uint8_t text[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_extended_event_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_extended_event_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_extended_event_descriptor*
+ dvb_extended_event_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+ struct dvb_extended_event_descriptor * p =
+ (struct dvb_extended_event_descriptor *) d;
+ struct dvb_extended_event_descriptor_part2 *p2;
+
+ pos += sizeof(struct dvb_extended_event_descriptor) - 2;
+
+ if (pos > len)
+ return NULL;
+
+ pos += p->length_of_items;
+
+ if (pos > len)
+ return NULL;
+
+ p2 = (struct dvb_extended_event_descriptor_part2*) (buf+pos);
+
+ pos += sizeof(struct dvb_extended_event_descriptor_part2);
+
+ if (pos > len)
+ return NULL;
+
+ pos += p2->text_length;
+
+ if (pos != len)
+ return NULL;
+
+ return p;
+}
+
+/**
+ * Iterator for the items field of a dvb_extended_event_descriptor.
+ *
+ * @param d dvb_extended_event_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_extended_event_item.
+ */
+#define dvb_extended_event_descriptor_items_for_each(d, pos) \
+ for ((pos) = dvb_extended_event_descriptor_items_first(d); \
+ (pos); \
+ (pos) = dvb_extended_event_descriptor_items_next(d, pos))
+
+/**
+ * Accessor for the description field of a dvb_extended_event_item.
+ *
+ * @param d dvb_extended_event_item pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ dvb_extended_event_item_description(struct dvb_extended_event_item *d)
+{
+ return (uint8_t*) d + sizeof(struct dvb_extended_event_item);
+}
+
+/**
+ * Accessor for the second part of a dvb_extended_event_item.
+ *
+ * @param dvb_extended_event_item pointer.
+ * @return dvb_extended_event_item_part2 pointer.
+ */
+static inline struct dvb_extended_event_item_part2*
+ dvb_extended_event_item_part2(struct dvb_extended_event_item *d)
+{
+ return (struct dvb_extended_event_item_part2*)
+ ((uint8_t*) d + sizeof(struct dvb_extended_event_item) +
+ d->item_description_length);
+}
+
+/**
+ * Accessor for the item field of a dvb_extended_event_item_part2.
+ *
+ * @param d dvb_extended_event_item_part2 pointer.
+ * @return Pointer to the item field.
+ */
+static inline uint8_t*
+ dvb_extended_event_item_part2_item(struct dvb_extended_event_item_part2 *d)
+{
+ return (uint8_t*) d + sizeof(struct dvb_extended_event_item_part2);
+}
+
+/**
+ * Accessor for the second part of a dvb_extended_event_descriptor.
+ *
+ * @param d dvb_extended_event_descriptor pointer.
+ * @return dvb_extended_event_descriptor_part2 pointer.
+ */
+static inline struct dvb_extended_event_descriptor_part2*
+ dvb_extended_event_descriptor_part2(struct dvb_extended_event_descriptor *d)
+{
+ return (struct dvb_extended_event_descriptor_part2*)
+ ((uint8_t*) d + sizeof(struct dvb_extended_event_descriptor) +
+ d->length_of_items);
+}
+
+/**
+ * Accessor for the text field of an dvb_extended_event_descriptor_part2.
+ *
+ * @param d dvb_extended_event_descriptor_part2 pointer.
+ * @return Pointer to the text field.
+ */
+static inline uint8_t*
+ dvb_extended_event_descriptor_part2_text(struct dvb_extended_event_descriptor_part2 *d)
+{
+ return (uint8_t*)
+ ((uint8_t*) d + sizeof(struct dvb_extended_event_descriptor_part2));
+}
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_extended_event_item*
+ dvb_extended_event_descriptor_items_first(struct dvb_extended_event_descriptor *d)
+{
+ if (d->length_of_items == 0)
+ return NULL;
+
+ return (struct dvb_extended_event_item *)
+ ((uint8_t*) d + sizeof(struct dvb_extended_event_descriptor));
+}
+
+static inline struct dvb_extended_event_item*
+ dvb_extended_event_descriptor_items_next(struct dvb_extended_event_descriptor *d,
+ struct dvb_extended_event_item *pos)
+{
+ struct dvb_extended_event_item_part2* part2 =
+ dvb_extended_event_item_part2(pos);
+ uint8_t *end = (uint8_t*) d + sizeof(struct dvb_extended_event_descriptor) + d->length_of_items;
+ uint8_t *next = (uint8_t *) part2 +
+ sizeof(struct dvb_extended_event_item_part2) +
+ part2->item_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_extended_event_item *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/frequency_list_descriptor.h b/lib/libucsi/dvb/frequency_list_descriptor.h
new file mode 100644
index 0000000..4c18cec
--- /dev/null
+++ b/lib/libucsi/dvb/frequency_list_descriptor.h
@@ -0,0 +1,107 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_FREQUENCY_LIST_DESCRIPTOR
+#define _UCSI_DVB_FREQUENCY_LIST_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Possible values for coding_type.
+ */
+enum {
+ DVB_CODING_TYPE_SATELLITE = 0x01,
+ DVB_CODING_TYPE_CABLE = 0x02,
+ DVB_CODING_TYPE_TERRESTRIAL = 0x03,
+};
+
+/**
+ * dvb_frequency_list_descriptor structure.
+ */
+struct dvb_frequency_list_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t reserved : 6; ,
+ uint8_t coding_type : 2; );
+ /* uint32_t centre_frequencies [] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_frequency_list_descriptor.
+ *
+ * @param d Pointer to a generic descriptor structure.
+ * @return dvb_frequency_list_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_frequency_list_descriptor*
+ dvb_frequency_list_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t len = d->len;
+
+ pos += sizeof(struct dvb_frequency_list_descriptor) - 2;
+
+ if ((len - pos) % 4)
+ return NULL;
+
+ while(pos < len) {
+ bswap32(buf+pos);
+ pos += 4;
+ }
+
+ return (struct dvb_frequency_list_descriptor*) d;
+}
+
+/**
+ * Accessor for the centre_frequencies field of a dvb_frequency_list_descriptor.
+ *
+ * @param d dvb_frequency_list_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint32_t *
+ dvb_frequency_list_descriptor_centre_frequencies(struct dvb_frequency_list_descriptor *d)
+{
+ return (uint32_t *) ((uint8_t *) d + sizeof(struct dvb_frequency_list_descriptor));
+}
+
+/**
+ * Determine the number of entries in the centre_frequencies field of a dvb_frequency_list_descriptor.
+ *
+ * @param d dvb_frequency_list_descriptor pointer.
+ * @return The number of entries.
+ */
+static inline int
+ dvb_frequency_list_descriptor_centre_frequencies_count(struct dvb_frequency_list_descriptor *d)
+{
+ return (d->d.len - 1) >> 2;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/int_section.c b/lib/libucsi/dvb/int_section.c
new file mode 100644
index 0000000..c2bb15f
--- /dev/null
+++ b/lib/libucsi/dvb/int_section.c
@@ -0,0 +1,79 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2005 Patrick Boettcher (pb@linuxtv.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/int_section.h>
+
+struct dvb_int_section * dvb_int_section_codec(struct section_ext *ext)
+{
+ uint8_t *buf = (uint8_t *) ext;
+ struct dvb_int_section *in = (struct dvb_int_section *) ext;
+ size_t pos = sizeof(struct section_ext);
+ size_t len = section_ext_length(ext);
+
+ if (len < sizeof(struct dvb_int_section))
+ return NULL;
+
+ bswap32(buf+8);
+ bswap16(buf+12);
+ pos += 6;
+
+ if (len - pos < in->platform_descriptors_length)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, in->platform_descriptors_length))
+ return NULL;
+
+ pos += in->platform_descriptors_length;
+
+ while (pos < len) {
+ struct dvb_int_target *s2 = (struct dvb_int_target *) (buf + pos);
+ struct dvb_int_operational_loop *s3;
+
+ bswap16(buf + pos); /* target_descriptor_loop_length swap */
+
+ if (len - pos < s2->target_descriptors_length)
+ return NULL;
+
+ pos += sizeof(struct dvb_int_target);
+
+ if (verify_descriptors(buf + pos, s2->target_descriptors_length))
+ return NULL;
+
+ pos += s2->target_descriptors_length;
+
+ s3 = (struct dvb_int_operational_loop *) (buf + pos);
+
+ bswap16(buf + pos); /* operational_descriptor_loop_length swap */
+
+ if (len - pos < s3->operational_descriptors_length)
+ return NULL;
+
+ pos += sizeof(struct dvb_int_operational_loop);
+
+ if (verify_descriptors(buf + pos, s3->operational_descriptors_length))
+ return NULL;
+
+ pos += s3->operational_descriptors_length;
+ }
+
+ return (struct dvb_int_section *) ext;
+}
diff --git a/lib/libucsi/dvb/int_section.h b/lib/libucsi/dvb/int_section.h
new file mode 100644
index 0000000..932c0e8
--- /dev/null
+++ b/lib/libucsi/dvb/int_section.h
@@ -0,0 +1,245 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2005 Patrick Boettcher (pb@linuxtv.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#ifndef _UCSI_DVB_INT_SECTION_H
+#define _UCSI_DVB_INT_SECTION_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * dvb_int_section structure - IP/MAC notification section.
+ */
+struct dvb_int_section {
+ struct section_ext head;
+
+ EBIT2(uint32_t platform_id :24; ,
+ uint32_t processing_order : 8; );
+ EBIT2(uint16_t reserved2 : 4; ,
+ uint16_t platform_descriptors_length :12; );
+ /* struct descriptor platform_descriptors[] */
+ /* struct dvb_int_target target_loop[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the target_loop field of a dvb_int_section.
+ */
+struct dvb_int_target {
+ EBIT2(uint16_t reserved3 : 4; ,
+ uint16_t target_descriptors_length :12; );
+ /* struct descriptor target_descriptors[] */
+ /* struct dvb_int_operational_loop operational_loop */
+} __ucsi_packed;
+
+/**
+ * The operational_loop field in a dvb_int_target.
+ */
+struct dvb_int_operational_loop {
+ EBIT2(uint16_t reserved4 : 4; ,
+ uint16_t operational_descriptors_length :12; );
+ /* struct descriptor operational_descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_int_section.
+ *
+ * @param section Generic section_ext pointer.
+ * @return dvb_int_section pointer, or NULL on error.
+ */
+extern struct dvb_int_section * dvb_int_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for the action_type field of an INT.
+ *
+ * @param intp INT pointer.
+ * @return The action_type.
+ */
+static inline uint8_t dvb_int_section_action_type(struct dvb_int_section *intp)
+{
+ return intp->head.table_id_ext >> 8;
+}
+
+/**
+ * Accessor for the platform_id_hash field of an INT.
+ *
+ * @param intp INT pointer.
+ * @return The platform_id_hash.
+ */
+static inline uint8_t dvb_int_section_platform_id_hash(struct dvb_int_section *intp)
+{
+ return intp->head.table_id_ext & 0xff;
+}
+
+/**
+ * Iterator for platform_descriptors field in a dvb_int_section.
+ *
+ * @param intp dvb_int_section pointer.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define dvb_int_section_platform_descriptors_for_each(intp, pos) \
+ for ((pos) = dvb_int_section_platform_descriptors_first(intp); \
+ (pos); \
+ (pos) = dvb_int_section_platform_descriptors_next(intp, pos))
+
+/**
+ * Iterator for the target_loop field in a dvb_int_section.
+ *
+ * @param intp dvb_int_section pointer.
+ * @param pos Variable holding a pointer to the current dvb_int_target.
+ */
+#define dvb_int_section_target_loop_for_each(intp,pos) \
+ for ((pos) = dvb_int_section_target_loop_first(intp); \
+ (pos); \
+ (pos) = dvb_int_section_target_loop_next(intp, pos))
+
+/**
+ * Iterator for the target_descriptors field in a dvb_int_target.
+ *
+ * @param target dvb_int_target pointer.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define dvb_int_target_target_descriptors_for_each(target, pos) \
+ for ((pos) = dvb_int_target_target_descriptors_first(target); \
+ (pos); \
+ (pos) = dvb_int_target_target_descriptors_next(target, pos))
+
+/**
+ * Accessor for the operational_loop field of a dvb_int_target.
+ *
+ * @param target dvb_int_target pointer.
+ * @return Pointer to a dvb_int_operational_loop.
+ */
+static inline struct dvb_int_operational_loop *
+ dvb_int_target_operational_loop(struct dvb_int_target *target)
+{
+ return (struct dvb_int_operational_loop *)
+ ((uint8_t *) target + sizeof(struct dvb_int_target) + target->target_descriptors_length);
+}
+
+/**
+ * Iterator for the operational_descriptors field in a dvb_int_operational_loop.
+ *
+ * @param oploop dvb_int_operational_loop pointer.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define dvb_int_operational_loop_operational_descriptors_for_each(oploop, pos) \
+ for ((pos) = dvb_int_operational_loop_operational_descriptors_first(oploop); \
+ (pos); \
+ (pos) = dvb_int_operational_loop_operational_descriptors_next(oploop, pos))
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ dvb_int_section_platform_descriptors_first(struct dvb_int_section *in)
+{
+ if (in->platform_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) in + sizeof(struct dvb_int_section));
+}
+
+static inline struct descriptor *
+ dvb_int_section_platform_descriptors_next(struct dvb_int_section *in,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) in + sizeof(struct dvb_int_section),
+ in->platform_descriptors_length,
+ pos);
+}
+
+static inline struct dvb_int_target *
+ dvb_int_section_target_loop_first(struct dvb_int_section *in)
+{
+ if (sizeof(struct dvb_int_section) + in->platform_descriptors_length >= (uint32_t) section_ext_length((struct section_ext *) in))
+ return NULL;
+
+ return (struct dvb_int_target *)
+ ((uint8_t *) in + sizeof(struct dvb_int_section) + in->platform_descriptors_length);
+}
+
+static inline struct dvb_int_target *
+ dvb_int_section_target_loop_next(struct dvb_int_section *in,
+ struct dvb_int_target *pos)
+{
+ struct dvb_int_operational_loop *ol = dvb_int_target_operational_loop(pos);
+ struct dvb_int_target *next =
+ (struct dvb_int_target *) ( (uint8_t *) pos +
+ sizeof(struct dvb_int_target) + pos->target_descriptors_length +
+ sizeof(struct dvb_int_operational_loop) + ol->operational_descriptors_length);
+ struct dvb_int_target *end =
+ (struct dvb_int_target *) ((uint8_t *) in + section_ext_length((struct section_ext *) in) );
+
+ if (next >= end)
+ return 0;
+ return next;
+}
+
+static inline struct descriptor *
+ dvb_int_target_target_descriptors_first(struct dvb_int_target *tl)
+{
+ if (tl->target_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) tl + sizeof(struct dvb_int_target));
+}
+
+static inline struct descriptor *
+ dvb_int_target_target_descriptors_next(struct dvb_int_target *tl,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) tl + sizeof(struct dvb_int_target),
+ tl->target_descriptors_length,
+ pos);
+}
+
+static inline struct descriptor *
+ dvb_int_operational_loop_operational_descriptors_first(struct dvb_int_operational_loop *ol)
+{
+ if (ol->operational_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) ol + sizeof(struct dvb_int_operational_loop));
+}
+
+static inline struct descriptor *
+ dvb_int_operational_loop_operational_descriptors_next(struct dvb_int_operational_loop *ol,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) ol + sizeof(struct dvb_int_operational_loop),
+ ol->operational_descriptors_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/ip_mac_platform_name_descriptor.h b/lib/libucsi/dvb/ip_mac_platform_name_descriptor.h
new file mode 100644
index 0000000..c470e89
--- /dev/null
+++ b/lib/libucsi/dvb/ip_mac_platform_name_descriptor.h
@@ -0,0 +1,87 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_IP_MAC_PLATFORM_NAME_DESCRIPTOR
+#define _UCSI_DVB_IP_MAC_PLATFORM_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_ip_platform_name_descriptor structure.
+ */
+struct dvb_ip_platform_name_descriptor {
+ struct descriptor d;
+
+ iso639lang_t language_code;
+ /* uint8_t text[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ip_platform_name_descriptor.
+ *
+ * @param d Pointer to a generic descriptor.
+ * @return dvb_ip_platform_name_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ip_platform_name_descriptor*
+ dvb_ip_platform_name_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct dvb_ip_platform_name_descriptor) - 2))
+ return NULL;
+
+ return (struct dvb_ip_platform_name_descriptor*) d;
+}
+
+/**
+ * Accessor for the text field of a dvb_ip_platform_name_descriptor.
+ *
+ * @param d dvb_ip_platform_name_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_ip_platform_name_descriptor_text(struct dvb_ip_platform_name_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_ip_platform_name_descriptor);
+}
+
+/**
+ * Determine the length of the text field of a dvb_ip_platform_name_descriptor.
+ *
+ * @param d dvb_ip_platform_name_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_ip_platform_name_descriptor_text_length(struct dvb_ip_platform_name_descriptor *d)
+{
+ return d->d.len - 3;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/ip_mac_platform_provider_name_descriptor.h b/lib/libucsi/dvb/ip_mac_platform_provider_name_descriptor.h
new file mode 100644
index 0000000..ba95b8f
--- /dev/null
+++ b/lib/libucsi/dvb/ip_mac_platform_provider_name_descriptor.h
@@ -0,0 +1,87 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_IP_MAC_PLATFORM_PROVIDER_NAME_DESCRIPTOR
+#define _UCSI_DVB_IP_MAC_PLATFORM_PROVIDER_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_ip_platform_provider_name_descriptor structure.
+ */
+struct dvb_ip_platform_provider_name_descriptor {
+ struct descriptor d;
+
+ iso639lang_t language_code;
+ /* uint8_t text[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ip_platform_provider_name_descriptor.
+ *
+ * @param d Pointer to a generic descriptor.
+ * @return dvb_ip_platform_provider_name_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ip_platform_provider_name_descriptor*
+ dvb_ip_platform_provider_name_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct dvb_ip_platform_provider_name_descriptor) - 2))
+ return NULL;
+
+ return (struct dvb_ip_platform_provider_name_descriptor*) d;
+}
+
+/**
+ * Accessor for the text field of a dvb_ip_platform_provider_name_descriptor.
+ *
+ * @param d dvb_ip_platform_provider_name_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_ip_platform_provider_name_descriptor_text(struct dvb_ip_platform_provider_name_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_ip_platform_provider_name_descriptor);
+}
+
+/**
+ * Determine the length of the text field of a dvb_ip_platform_provider_name_descriptor.
+ *
+ * @param d dvb_ip_platform_provider_name_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_ip_platform_provider_name_descriptor_text_length(struct dvb_ip_platform_provider_name_descriptor *d)
+{
+ return d->d.len - 3;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/ip_mac_stream_location_descriptor.h b/lib/libucsi/dvb/ip_mac_stream_location_descriptor.h
new file mode 100644
index 0000000..36216d6
--- /dev/null
+++ b/lib/libucsi/dvb/ip_mac_stream_location_descriptor.h
@@ -0,0 +1,73 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_IP_MAC_STREAM_LOCATION_DESCRIPTOR
+#define _UCSI_DVB_IP_MAC_PLATFORM_PROVIDER_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_ip_mac_stream_location_descriptor structure.
+ */
+struct dvb_ip_mac_stream_location_descriptor {
+ struct descriptor d;
+
+ uint16_t network_id;
+ uint16_t original_network_id;
+ uint16_t transport_stream_id;
+ uint16_t service_id;
+ uint8_t component_tag;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_ip_mac_stream_location_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_ip_mac_stream_location_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_ip_mac_stream_location_descriptor*
+ dvb_ip_mac_stream_location_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+
+ if (d->len != (sizeof(struct dvb_ip_mac_stream_location_descriptor) - 2))
+ return NULL;
+
+ bswap16(buf);
+ bswap16(buf+2);
+ bswap16(buf+4);
+ bswap16(buf+6);
+
+ return (struct dvb_ip_mac_stream_location_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/linkage_descriptor.h b/lib/libucsi/dvb/linkage_descriptor.h
new file mode 100644
index 0000000..d2be789
--- /dev/null
+++ b/lib/libucsi/dvb/linkage_descriptor.h
@@ -0,0 +1,480 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_LINKAGE_DESCRIPTOR
+#define _UCSI_DVB_LINKAGE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * Possible values for linkage_type.
+ */
+enum {
+ DVB_LINKAGE_TYPE_INFORMATION = 0x01,
+ DVB_LINKAGE_TYPE_EPG = 0x02,
+ DVB_LINKAGE_TYPE_CA_REPLACEMENT = 0x03,
+ DVB_LINKAGE_TYPE_TS_WITH_BAT_NIT = 0x04,
+ DVB_LINKAGE_TYPE_SERVICE_REPLACMENT = 0x05,
+ DVB_LINKAGE_TYPE_DATA_BCAST = 0x06,
+ DVB_LINKAGE_TYPE_RCS_MAP = 0x07,
+ DVB_LINKAGE_TYPE_MOBILE_HANDOVER = 0x08,
+ DVB_LINKAGE_TYPE_SOFTWARE_UPDATE = 0x09,
+ DVB_LINKAGE_TYPE_TS_WITH_SSU_BAT_NIT = 0x0a,
+ DVB_LINKAGE_TYPE_IP_MAC_NOTIFICATION = 0x0b,
+ DVB_LINKAGE_TYPE_TS_WITH_INT_BAT_NIT = 0x0c,
+};
+
+/**
+ * Possible values for hand_over_type.
+ */
+enum {
+ DVB_HAND_OVER_TYPE_IDENTICAL_NEIGHBOURING_COUNTRY = 0x01,
+ DVB_HAND_OVER_TYPE_LOCAL_VARIATION = 0x02,
+ DVB_HAND_OVER_TYPE_ASSOCIATED_SERVICE = 0x03,
+};
+
+/**
+ * Possible values for origin_type.
+ */
+enum {
+ DVB_ORIGIN_TYPE_NIT = 0x00,
+ DVB_ORIGIN_TYPE_SDT = 0x01,
+};
+
+/**
+ * dvb_linkage_descriptor structure.
+ */
+struct dvb_linkage_descriptor {
+ struct descriptor d;
+
+ uint16_t transport_stream_id;
+ uint16_t original_network_id;
+ uint16_t service_id;
+ uint8_t linkage_type;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Data for a linkage_type of 0x08.
+ */
+struct dvb_linkage_data_08 {
+ EBIT3(uint8_t hand_over_type : 4; ,
+ uint8_t reserved : 3; ,
+ uint8_t origin_type : 1; );
+ /* uint16_t network_id if hand_over_type == 1,2,3 */
+ /* uint16_t initial_service_id if origin_type = 0 */
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Data for an linkage_type of 0x0b (IP/MAC Notification Table).
+ */
+struct dvb_linkage_data_0b {
+ uint8_t platform_id_data_length;
+ /* struct platform_id ids[] */
+} __ucsi_packed;
+
+/**
+ * Entries in the ids field of a dvb_linkage_data_0b.
+ */
+struct dvb_platform_id {
+ EBIT2(uint32_t platform_id : 24; ,
+ uint8_t platform_name_loop_length : 8; );
+ /* struct platform_name names[] */
+} __ucsi_packed;
+
+/**
+ * Entries in the names field of a dvb_platform_id.
+ */
+struct dvb_platform_name {
+ iso639lang_t language_code;
+ uint8_t platform_name_length;
+ /* uint8_t text[] */
+} __ucsi_packed;
+
+/**
+ * Data for a linkage_type of 0x0c (IP/MAC Notification Table).
+ */
+struct dvb_linkage_data_0c {
+ uint8_t table_type;
+ /* uint16_t bouquet_id if table_type == 0x02 */
+} __ucsi_packed;
+
+
+/**
+ * Process a dvb_linkage_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_linkage_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_linkage_descriptor*
+ dvb_linkage_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t len = d->len;
+ struct dvb_linkage_descriptor *p =
+ (struct dvb_linkage_descriptor*) d;
+
+ if (len < (sizeof(struct dvb_linkage_descriptor) - 2))
+ return NULL;
+
+ bswap16(buf);
+ bswap16(buf+2);
+ bswap16(buf+4);
+
+ pos += sizeof(struct dvb_linkage_descriptor) - 2;
+
+ if (p->linkage_type == 0x08) {
+ struct dvb_linkage_data_08 *d08;
+
+ if ((len - pos) < sizeof(struct dvb_linkage_data_08))
+ return NULL;
+ d08 = (struct dvb_linkage_data_08 *) (buf+pos);
+ pos += sizeof(struct dvb_linkage_data_08);
+
+ switch(d08->hand_over_type) {
+ case 1:
+ case 2:
+ case 3:
+ if ((len - pos) < 2)
+ return NULL;
+ bswap16(buf+pos);
+ pos += 2;
+ break;
+ }
+ if (d08->origin_type == 0) {
+ if ((len - pos) < 2)
+ return NULL;
+ bswap16(buf+pos);
+ pos+=2;
+ }
+
+ } else if (p->linkage_type == 0x0b) {
+ uint32_t pos2=0;
+ struct dvb_linkage_data_0b *l_0b = (struct dvb_linkage_data_0b *) (buf + pos);
+
+ if ((len - pos) < sizeof(struct dvb_linkage_data_0b))
+ return NULL;
+
+ pos += sizeof(struct dvb_linkage_data_0b);
+ if ((len - pos) < l_0b->platform_id_data_length)
+ return NULL;
+
+ while (pos2 < l_0b->platform_id_data_length) {
+ bswap32(buf + pos + pos2);
+
+ struct dvb_platform_id *p_id = (struct dvb_platform_id *) (buf + pos + pos2);
+ if ((len - pos - pos2) < p_id->platform_name_loop_length)
+ return NULL;
+
+ pos2 += sizeof(struct dvb_platform_id) + p_id->platform_name_loop_length;
+ }
+
+ pos += pos2;
+ } else if (p->linkage_type == 0x0c) {
+ struct dvb_linkage_data_0c *l_0c = (struct dvb_linkage_data_0c *) (buf + pos);
+
+ if ((len - pos) < sizeof(struct dvb_linkage_data_0c))
+ return NULL;
+ pos += sizeof(struct dvb_linkage_data_0c);
+
+ if (l_0c->table_type == 0x02) {
+ if ((len - pos) < 2)
+ return NULL;
+ bswap16(buf+pos);
+ }
+ }
+
+ return (struct dvb_linkage_descriptor*) d;
+}
+
+/**
+ * Accessor for the data field of a dvb_linkage_descriptor.
+ *
+ * @param d dvb_linkage_descriptor pointer.
+ * @return Pointer to the data field.
+ */
+static inline uint8_t *
+ dvb_linkage_descriptor_data(struct dvb_linkage_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_linkage_descriptor);
+}
+
+/**
+ * Determine the length of the data field of a dvb_linkage_descriptor.
+ *
+ * @param d dvb_linkage_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_linkage_descriptor_data_length(struct dvb_linkage_descriptor *d)
+{
+ return d->d.len - 7;
+}
+
+/**
+ * Accessor for a dvb_linkage_data_08 pointer.
+ *
+ * @param d dvb_linkage_descriptor pointer.
+ * @return Pointer to the data field.
+ */
+static inline struct dvb_linkage_data_08 *
+ dvb_linkage_data_08(struct dvb_linkage_descriptor *d)
+{
+ if (d->linkage_type != 0x08)
+ return NULL;
+ return (struct dvb_linkage_data_08 *) dvb_linkage_descriptor_data(d);
+}
+
+/**
+ * Accessor for the network_id field of a dvb_linkage_data_08.
+ *
+ * @param d dvb_linkage_descriptor pointer
+ * @param d08 dvb_linkage_data_08 pointer.
+ * @return network_id, or -1 if not present
+ */
+static inline int
+ dvb_linkage_data_08_network_id(struct dvb_linkage_descriptor *d, struct dvb_linkage_data_08 *d08)
+{
+ if (d->linkage_type != 0x08)
+ return -1;
+
+ switch(d08->hand_over_type) {
+ case 1:
+ case 2:
+ case 3:
+ return *((uint16_t*) ((uint8_t*) d08 + sizeof(struct dvb_linkage_data_08)));
+ }
+
+ return -1;
+}
+
+/**
+ * Accessor for the initial_service_id field of a dvb_linkage_data_08.
+ *
+ * @param d dvb_linkage_descriptor pointer
+ * @param d08 dvb_linkage_data_08 pointer.
+ * @return initial_service_id, or -1 if not present
+ */
+static inline int
+ dvb_linkage_data_08_initial_service_id(struct dvb_linkage_descriptor *d, struct dvb_linkage_data_08 *d08)
+{
+ uint8_t *pos;
+
+ if (d->linkage_type != 0x08)
+ return -1;
+ if (d08->origin_type != 0)
+ return -1;
+
+ pos = ((uint8_t*) d08) + sizeof(struct dvb_linkage_data_08);
+ switch(d08->hand_over_type) {
+ case 1:
+ case 2:
+ case 3:
+ pos +=2;
+ break;
+ }
+
+ return *((uint16_t*) pos);
+}
+
+/**
+ * Accessor for the data field of a dvb_linkage_data_08.
+ *
+ * @param d dvb_linkage_descriptor pointer
+ * @param d08 dvb_linkage_data_08 pointer.
+ * @param length Pointer to int destination for data length.
+ * @return Pointer to the data field, or NULL if invalid
+ */
+static inline uint8_t *
+ dvb_linkage_data_08_data(struct dvb_linkage_descriptor *d, struct dvb_linkage_data_08 *d08, int *length)
+{
+ uint8_t *pos;
+ int used = 0;
+
+ if (d->linkage_type != 0x08) {
+ *length = 0;
+ return NULL;
+ }
+
+ pos = ((uint8_t*) d08) + sizeof(struct dvb_linkage_data_08);
+ switch(d08->hand_over_type) {
+ case 1:
+ case 2:
+ case 3:
+ pos += 2;
+ used += 2;
+ break;
+ }
+ if (d08->origin_type == 0) {
+ pos+=2;
+ used+=2;
+ }
+
+ *length = dvb_linkage_descriptor_data_length(d) - (sizeof(struct dvb_linkage_data_08) + used);
+ return pos;
+}
+
+/**
+ * Accessor for a dvb_linkage_data_0b pointer.
+ *
+ * @param d dvb_linkage_descriptor pointer.
+ * @return Pointer to the data field.
+ */
+static inline struct dvb_linkage_data_0b *
+ dvb_linkage_data_0b(struct dvb_linkage_descriptor *d)
+{
+ if (d->linkage_type != 0x0b)
+ return NULL;
+ return (struct dvb_linkage_data_0b *) dvb_linkage_descriptor_data(d);
+}
+
+/**
+ * Iterator for the platform_id field of a dvb_linkage_data_0b.
+ *
+ * @param linkage dvb_linkage_data_0b pointer.
+ * @param pos Variable containing a pointer to the current dvb_platform_id.
+ */
+#define dvb_linkage_data_0b_platform_id_for_each(linkage, pos) \
+ for ((pos) = dvb_platform_id_first(linkage); \
+ (pos); \
+ (pos) = dvb_platform_id_next(linkage, pos))
+
+/**
+ * Iterator for the platform_name field of a dvb_platform_id.
+ *
+ * @param platid dvb_platform_id pointer.
+ * @param pos Variable containing a pointer to the current dvb_platform_name.
+ */
+#define dvb_platform_id_platform_name_for_each(platid, pos) \
+ for ((pos) = dvb_platform_name_first(platid); \
+ (pos); \
+ (pos) = dvb_platform_name_next(platid, pos))
+
+/**
+ * Accessor for the text field of a dvb_platform_name.
+ *
+ * @param p dvb_platform_name pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_platform_name_text(struct dvb_platform_name *p)
+{
+ return (uint8_t *) p + sizeof(struct dvb_platform_name);
+}
+
+/**
+ * Accessor for a dvb_linkage_data_0c pointer.
+ *
+ * @param d dvb_linkage_descriptor pointer.
+ * @return Pointer to the data field.
+ */
+static inline struct dvb_linkage_data_0c *
+ dvb_linkage_data_0c(struct dvb_linkage_descriptor *d)
+{
+ if (d->linkage_type != 0x0c)
+ return NULL;
+ return (struct dvb_linkage_data_0c *) dvb_linkage_descriptor_data(d);
+}
+
+/**
+ * Accessor for the bouquet_id field of a dvb_linkage_data_0c if table_id == 0x02.
+ *
+ * @param l_0c dvb_linkage_data_0c pointer.
+ * @return The bouquet field, or -1 on error.
+ */
+static inline int
+ dvb_linkage_data_0c_bouquet_id(struct dvb_linkage_data_0c *l_0c)
+{
+ if (l_0c->table_type != 0x02)
+ return -1;
+
+ return *((uint16_t *) ((uint8_t*) l_0c + 1));
+}
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_platform_id *
+ dvb_platform_id_first(struct dvb_linkage_data_0b *d)
+{
+ if (d->platform_id_data_length == 0)
+ return NULL;
+
+ return (struct dvb_platform_id *) ((uint8_t *) d + sizeof(struct dvb_linkage_data_0b));
+}
+
+static inline struct dvb_platform_id *
+ dvb_platform_id_next(struct dvb_linkage_data_0b *d,
+ struct dvb_platform_id *pos)
+{
+ uint8_t *end = (uint8_t *) d + d->platform_id_data_length;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_platform_id) +
+ pos->platform_name_loop_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_platform_id *) next;
+}
+
+static inline struct dvb_platform_name *
+ dvb_platform_name_first(struct dvb_platform_id *p)
+{
+ if (p->platform_name_loop_length == 0)
+ return NULL;
+
+ return (struct dvb_platform_name *) ((uint8_t *) p + sizeof(struct dvb_platform_id));
+}
+
+static inline struct dvb_platform_name *
+ dvb_platform_name_next(struct dvb_platform_id *p,
+ struct dvb_platform_name *pos)
+{
+ uint8_t *end = (uint8_t *) p + p->platform_name_loop_length;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_platform_name) +
+ pos->platform_name_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_platform_name *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/local_time_offset_descriptor.h b/lib/libucsi/dvb/local_time_offset_descriptor.h
new file mode 100644
index 0000000..d0eebb3
--- /dev/null
+++ b/lib/libucsi/dvb/local_time_offset_descriptor.h
@@ -0,0 +1,127 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_LOCAL_TIME_OFFSET_DESCRIPTOR
+#define _UCSI_DVB_LOCAL_TIME_OFFSET_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+#include <libucsi/dvb/types.h>
+
+/**
+ * dvb_local_time_offset_descriptor parameter.
+ */
+struct dvb_local_time_offset_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_local_time_offset offsets[] */
+} __ucsi_packed;
+
+/**
+ * Entry in the offsets field of dvb_local_time_offset_descriptor.
+ */
+struct dvb_local_time_offset {
+ iso639country_t country_code;
+ EBIT3(uint8_t country_region_id : 6; ,
+ uint8_t reserved : 1; ,
+ uint8_t local_time_offset_polarity : 1; );
+ dvbhhmm_t local_time_offset;
+ dvbdate_t time_of_change;
+ dvbhhmm_t next_time_offset;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_local_time_offset_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_local_time_offset_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_local_time_offset_descriptor*
+ dvb_local_time_offset_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len;
+ uint32_t pos = 0;
+
+ if (len % sizeof(struct dvb_local_time_offset))
+ return NULL;
+
+ while(pos < len) {
+ pos += sizeof(struct dvb_local_time_offset);
+ }
+
+ return (struct dvb_local_time_offset_descriptor*) d;
+}
+
+/**
+ * Iterator for the offsets field of a dvb_local_time_offset_descriptor.
+ *
+ * @param d dvb_local_time_offset_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_local_time_offset.
+ */
+#define dvb_local_time_offset_descriptor_offsets_for_each(d, pos) \
+ for ((pos) = dvb_local_time_offset_descriptor_offsets_first(d); \
+ (pos); \
+ (pos) = dvb_local_time_offset_descriptor_offsets_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_local_time_offset*
+ dvb_local_time_offset_descriptor_offsets_first(struct dvb_local_time_offset_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_local_time_offset *)
+ ((uint8_t*) d + sizeof(struct dvb_local_time_offset_descriptor));
+}
+
+static inline struct dvb_local_time_offset*
+ dvb_local_time_offset_descriptor_offsets_next(struct dvb_local_time_offset_descriptor *d,
+ struct dvb_local_time_offset *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_local_time_offset);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_local_time_offset *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/mhp_data_broadcast_id_descriptor.h b/lib/libucsi/dvb/mhp_data_broadcast_id_descriptor.h
new file mode 100644
index 0000000..d79b48c
--- /dev/null
+++ b/lib/libucsi/dvb/mhp_data_broadcast_id_descriptor.h
@@ -0,0 +1,110 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_MHP_DATA_BROADCAST_ID_DESCRIPTOR
+#define _UCSI_DVB_MHP_DATA_BROADCAST_ID_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifndef _UCSI_DVB_DATA_BROADCAST_ID_DESCRIPTOR
+#error Must include dvb/data_broadcast_id_descriptor.h first
+#endif
+
+/**
+ * Broadcast IDs for MHP.
+ */
+enum {
+ DVB_BROADCAST_ID_MHP_OBJECT_CAROUSEL = 0x00f0,
+ DVB_BROADCAST_ID_MHP_MPE = 0x00f1,
+};
+
+/**
+ * dvb_mhp_data_broadcast_id_descriptor structure.
+ */
+struct dvb_mhp_data_broadcast_id_descriptor {
+ struct dvb_data_broadcast_id_descriptor d;
+ /* uint16_t application_type[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_mhp_data_broadcast_id_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_mhp_data_broadcast_id_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_mhp_data_broadcast_id_descriptor*
+ dvb_mhp_data_broadcast_id_descriptor_codec(struct dvb_data_broadcast_id_descriptor* d)
+{
+ uint8_t * buf;
+ int len;
+ int pos = 0;
+ struct dvb_mhp_data_broadcast_id_descriptor *res =
+ (struct dvb_mhp_data_broadcast_id_descriptor *) d;
+
+ if ((res->d.data_broadcast_id < 0xf0) || (res->d.data_broadcast_id > 0xfe))
+ return NULL;
+
+ buf = dvb_data_broadcast_id_descriptor_id_selector_byte(d);
+ len = dvb_data_broadcast_id_descriptor_id_selector_byte_length(d);
+
+ if (len % 2)
+ return NULL;
+
+ while(pos < len) {
+ bswap16(buf+pos);
+ pos+=2;
+ }
+
+ return res;
+}
+
+/**
+ * Accessor for the application_type field of a dvb_mhp_data_broadcast_id_descriptor.
+ *
+ * @param d dvb_mhp_data_broadcast_id_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint16_t *
+ dvb_mhp_data_broadcast_id_descriptor_id_application_type(struct dvb_mhp_data_broadcast_id_descriptor *d)
+{
+ return (uint16_t *) dvb_data_broadcast_id_descriptor_id_selector_byte((struct dvb_data_broadcast_id_descriptor*) d);
+}
+
+/**
+ * Determine the number of entries in the application_type field of a dvb_mhp_data_broadcast_id_descriptor.
+ *
+ * @param d dvb_data_broadcast_id_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_mhp_data_broadcast_id_descriptor_id_application_type_count(struct dvb_mhp_data_broadcast_id_descriptor *d)
+{
+ return dvb_data_broadcast_id_descriptor_id_selector_byte_length((struct dvb_data_broadcast_id_descriptor*) d) >> 1;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/mosaic_descriptor.h b/lib/libucsi/dvb/mosaic_descriptor.h
new file mode 100644
index 0000000..6da1e95
--- /dev/null
+++ b/lib/libucsi/dvb/mosaic_descriptor.h
@@ -0,0 +1,324 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_MOSAIC_DESCRIPTOR
+#define _UCSI_DVB_MOSAIC_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_mosaic_descriptor structure.
+ */
+struct dvb_mosaic_descriptor {
+ struct descriptor d;
+
+ EBIT4(uint8_t mosaic_entry_point : 1; ,
+ uint8_t number_of_horiz_elementary_cells: 3; ,
+ uint8_t reserved : 1; ,
+ uint8_t number_of_vert_elementary_cells : 3; );
+ /* struct dvb_mosaic_info infos[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the infos field of a dvb_mosaic_descriptor.
+ */
+struct dvb_mosaic_info {
+ EBIT3(uint16_t logical_cell_id : 6; ,
+ uint16_t reserved : 7; ,
+ uint16_t logical_cell_presentation_info : 3; );
+ uint8_t elementary_cell_field_length;
+ /* struct dvb_mosaic_elementary_cell_field fields[] */
+ /* struct dvb_mosaic_info_part2 part2 */
+ /* struct dvb_mosaic_linkage linkage */
+} __ucsi_packed;
+
+/**
+ * An entry in the fields field of a dvb_mosaic_info.
+ */
+struct dvb_mosaic_elementary_cell_field {
+ EBIT2(uint8_t reserved : 2; ,
+ uint8_t elementary_cell_id : 6; );
+} __ucsi_packed;
+
+/**
+ * Part2 of dvb_mosaic_info, following the variable length fields field.
+ */
+struct dvb_mosaic_info_part2 {
+ uint8_t cell_linkage_info;
+} __ucsi_packed;
+
+struct dvb_mosaic_linkage_01 {
+ uint16_t bouquet_id;
+} __ucsi_packed;
+
+struct dvb_mosaic_linkage_02 {
+ uint16_t original_network_id;
+ uint16_t transport_stream_id;
+ uint16_t service_id;
+} __ucsi_packed;
+
+struct dvb_mosaic_linkage_03 {
+ uint16_t original_network_id;
+ uint16_t transport_stream_id;
+ uint16_t service_id;
+} __ucsi_packed;
+
+struct dvb_mosaic_linkage_04 {
+ uint16_t original_network_id;
+ uint16_t transport_stream_id;
+ uint16_t service_id;
+ uint16_t event_id;
+} __ucsi_packed;
+
+/**
+ * Structure describing the linkage field of a dvb_mosaic_info
+ */
+struct dvb_mosaic_linkage {
+ union {
+ struct dvb_mosaic_linkage_01 linkage_01;
+ struct dvb_mosaic_linkage_02 linkage_02;
+ struct dvb_mosaic_linkage_03 linkage_03;
+ struct dvb_mosaic_linkage_04 linkage_04;
+ } u;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_mosaic_descriptor.
+ *
+ * @param d Pointer to a generic descriptor structure.
+ */
+static inline struct dvb_mosaic_descriptor*
+ dvb_mosaic_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+ struct dvb_mosaic_descriptor * p =
+ (struct dvb_mosaic_descriptor *) d;
+
+ pos += (sizeof(struct dvb_mosaic_descriptor) - 2);
+
+ if (pos > len)
+ return NULL;
+
+ while(pos < len) {
+ struct dvb_mosaic_info *e =
+ (struct dvb_mosaic_info*) (buf+pos);
+ struct dvb_mosaic_info_part2 *e2;
+ struct dvb_mosaic_linkage *linkage;
+
+ if ((pos + sizeof(struct dvb_mosaic_info)) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+
+ pos += sizeof(struct dvb_mosaic_info) +
+ e->elementary_cell_field_length;
+
+ if (pos > len)
+ return NULL;
+
+ e2 = (struct dvb_mosaic_info_part2*) (buf+pos);
+
+ pos += sizeof(struct dvb_mosaic_info_part2);
+
+ if (pos > len)
+ return NULL;
+
+ linkage = (struct dvb_mosaic_linkage*) (buf+pos);
+
+ switch(e2->cell_linkage_info) {
+ case 0x01:
+ if ((pos + sizeof(struct dvb_mosaic_linkage_01)) > len)
+ return NULL;
+ bswap16(buf+pos);
+ pos += sizeof(struct dvb_mosaic_linkage_01);
+ break;
+
+ case 0x02:
+ if ((pos + sizeof(struct dvb_mosaic_linkage_02)) > len)
+ return NULL;
+ bswap16(buf+pos);
+ bswap16(buf+pos+2);
+ bswap16(buf+pos+4);
+ pos += sizeof(struct dvb_mosaic_linkage_02);
+ break;
+
+ case 0x03:
+ if ((pos + sizeof(struct dvb_mosaic_linkage_03)) > len)
+ return NULL;
+ bswap16(buf+pos);
+ bswap16(buf+pos+2);
+ bswap16(buf+pos+4);
+ pos += sizeof(struct dvb_mosaic_linkage_03);
+ break;
+
+ case 0x04:
+ if ((pos + sizeof(struct dvb_mosaic_linkage_04)) > len)
+ return NULL;
+ bswap16(buf+pos);
+ bswap16(buf+pos+2);
+ bswap16(buf+pos+4);
+ bswap16(buf+pos+6);
+ pos += sizeof(struct dvb_mosaic_linkage_04);
+ break;
+ }
+ }
+
+ return p;
+}
+
+/**
+ * Iterator over the infos field of a dvb_mosaic_descriptor.
+ *
+ * @param d dvb_mosaic_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_mosaic_info.
+ */
+#define dvb_mosaic_descriptor_infos_for_each(d, pos) \
+ for ((pos) = dvb_mosaic_descriptor_infos_first(d); \
+ (pos); \
+ (pos) = dvb_mosaic_descriptor_infos_next(d, pos))
+
+/**
+ * Iterator over the fields field of a dvb_mosaic_info.
+ *
+ * @param info dvb_mosaic_info pointer.
+ * @param pos Variable containing a pointer to the current dvb_mosaic_elementary_cell_field.
+ */
+#define dvb_mosaic_info_fields_for_each(info, pos) \
+ for ((pos) = dvb_mosaic_info_fields_first(info); \
+ (pos); \
+ (pos) = dvb_mosaic_info_fields_next(info, pos))
+
+/**
+ * Accessor for the second part of the dvb_mosaic_info structure.
+ *
+ * @param entry dvb_mosaic_info pointer.
+ * @return dvb_mosaic_info_part2 pointer.
+ */
+static inline struct dvb_mosaic_info_part2*
+ dvb_mosaic_info_part2(struct dvb_mosaic_info* entry)
+{
+ return (struct dvb_mosaic_info_part2*)
+ ((uint8_t*) entry + sizeof(struct dvb_mosaic_info) +
+ entry->elementary_cell_field_length);
+}
+
+/**
+ * Accessor for the linkage field a dvb_mosaic_info structure.
+ *
+ * @param entry dvb_mosaic_info_part2 pointer.
+ * @return dvb_mosaic_linkage pointer, or NULL on error.
+ */
+static inline struct dvb_mosaic_linkage*
+ dvb_mosaic_linkage(struct dvb_mosaic_info_part2* entry)
+{
+ if ((entry->cell_linkage_info != 0x01) &&
+ (entry->cell_linkage_info != 0x02) &&
+ (entry->cell_linkage_info != 0x03) &&
+ (entry->cell_linkage_info != 0x04))
+ return NULL;
+
+ return (struct dvb_mosaic_linkage*)
+ ((uint8_t*) entry + sizeof(struct dvb_mosaic_info_part2));
+}
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_mosaic_info*
+ dvb_mosaic_descriptor_infos_first(struct dvb_mosaic_descriptor *d)
+{
+ if (d->d.len == 1)
+ return NULL;
+
+ return (struct dvb_mosaic_info *)
+ ((uint8_t*) d + sizeof(struct dvb_mosaic_descriptor));
+}
+
+static inline struct dvb_mosaic_info*
+ dvb_mosaic_descriptor_infos_next(struct dvb_mosaic_descriptor *d,
+ struct dvb_mosaic_info *pos)
+{
+ struct dvb_mosaic_info_part2* part2 = dvb_mosaic_info_part2(pos);
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_mosaic_info) +
+ pos->elementary_cell_field_length +
+ sizeof(struct dvb_mosaic_info_part2);
+
+ if (part2->cell_linkage_info == 0x01)
+ next += sizeof(struct dvb_mosaic_linkage_01);
+ else if (part2->cell_linkage_info == 0x02)
+ next += sizeof(struct dvb_mosaic_linkage_02);
+ else if (part2->cell_linkage_info == 0x03)
+ next += sizeof(struct dvb_mosaic_linkage_03);
+ else if (part2->cell_linkage_info == 0x04)
+ next += sizeof(struct dvb_mosaic_linkage_04);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_mosaic_info *) next;
+}
+
+static inline struct dvb_mosaic_elementary_cell_field*
+ dvb_mosaic_info_fields_first(struct dvb_mosaic_info *d)
+{
+ if (d->elementary_cell_field_length == 0)
+ return NULL;
+
+ return (struct dvb_mosaic_elementary_cell_field*)
+ ((uint8_t*) d + sizeof(struct dvb_mosaic_info));
+}
+
+static inline struct dvb_mosaic_elementary_cell_field*
+ dvb_mosaic_info_fields_next(struct dvb_mosaic_info *d,
+ struct dvb_mosaic_elementary_cell_field* pos)
+{
+ uint8_t *end = (uint8_t*) d + sizeof(struct dvb_mosaic_info) +
+ d->elementary_cell_field_length;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_mosaic_elementary_cell_field);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_mosaic_elementary_cell_field *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/multilingual_bouquet_name_descriptor.h b/lib/libucsi/dvb/multilingual_bouquet_name_descriptor.h
new file mode 100644
index 0000000..0d8deb1
--- /dev/null
+++ b/lib/libucsi/dvb/multilingual_bouquet_name_descriptor.h
@@ -0,0 +1,145 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_MULTILINGUAL_BOUQUET_NAME_DESCRIPTOR
+#define _UCSI_DVB_MULTILINGUAL_BOUQUET_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_multilingual_bouquet_name_descriptor structure.
+ */
+struct dvb_multilingual_bouquet_name_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_multilingual_bouquet_name names[]*/
+} __ucsi_packed;
+
+/**
+ * An entry in the names field of a dvb_multilingual_bouquet_name_descriptor.
+ */
+struct dvb_multilingual_bouquet_name {
+ iso639lang_t language_code;
+ uint8_t bouquet_name_length;
+ /* uint8_t name[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_multilingual_bouquet_name_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_multilingual_bouquet_name_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_multilingual_bouquet_name_descriptor*
+ dvb_multilingual_bouquet_name_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+
+ while(pos < len) {
+ struct dvb_multilingual_bouquet_name *e =
+ (struct dvb_multilingual_bouquet_name*) (buf+pos);
+
+ pos += sizeof(struct dvb_multilingual_bouquet_name);
+
+ if (pos > len)
+ return NULL;
+
+ pos += e->bouquet_name_length;
+
+ if (pos > len)
+ return NULL;
+ }
+
+ return (struct dvb_multilingual_bouquet_name_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the names field of a dvb_multilingual_bouquet_name_descriptor.
+ *
+ * @param d dvb_multilingual_bouquet_name_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_multilingual_bouquet_name.
+ */
+#define dvb_multilingual_bouquet_name_descriptor_names_for_each(d, pos) \
+ for ((pos) = dvb_multilingual_bouquet_name_descriptor_names_first(d); \
+ (pos); \
+ (pos) = dvb_multilingual_bouquet_name_descriptor_names_next(d, pos))
+
+/**
+ * Accessor for the name field of a dvb_multilingual_bouquet_name.
+ *
+ * @param e dvb_multilingual_bouquet_name pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_multilingual_bouquet_name_name(struct dvb_multilingual_bouquet_name *e)
+{
+ return (uint8_t *) e + sizeof(struct dvb_multilingual_bouquet_name);
+}
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_multilingual_bouquet_name*
+ dvb_multilingual_bouquet_name_descriptor_names_first(struct dvb_multilingual_bouquet_name_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_multilingual_bouquet_name *)
+ ((uint8_t*) d + sizeof(struct dvb_multilingual_bouquet_name_descriptor));
+}
+
+static inline struct dvb_multilingual_bouquet_name*
+ dvb_multilingual_bouquet_name_descriptor_names_next(struct dvb_multilingual_bouquet_name_descriptor *d,
+ struct dvb_multilingual_bouquet_name *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_multilingual_bouquet_name) +
+ pos->bouquet_name_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_multilingual_bouquet_name *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/multilingual_component_descriptor.h b/lib/libucsi/dvb/multilingual_component_descriptor.h
new file mode 100644
index 0000000..ab156af
--- /dev/null
+++ b/lib/libucsi/dvb/multilingual_component_descriptor.h
@@ -0,0 +1,149 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_MULTILINGUAL_COMPONENT_DESCRIPTOR
+#define _UCSI_DVB_MULTILINGUAL_COMPONENT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_multilingual_component_descriptor structure.
+ */
+struct dvb_multilingual_component_descriptor {
+ struct descriptor d;
+
+ uint8_t component_tag;
+ /* struct dvb_multilingual_component components[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the components field of a dvb_multilingual_component_descriptor.
+ */
+struct dvb_multilingual_component {
+ iso639lang_t language_code;
+ uint8_t text_description_length;
+ /* uint8_t text_char[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_multilingual_component_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_multilingual_component_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_multilingual_component_descriptor*
+ dvb_multilingual_component_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t pos = sizeof(struct dvb_multilingual_component_descriptor) - 2;
+ uint32_t len = d->len;
+
+ if (pos > len)
+ return NULL;
+
+ while(pos < len) {
+ struct dvb_multilingual_component *e =
+ (struct dvb_multilingual_component*) (buf+pos);
+
+ pos += sizeof(struct dvb_multilingual_component);
+
+ if (pos > len)
+ return NULL;
+
+ pos += e->text_description_length;
+
+ if (pos > len)
+ return NULL;
+ }
+
+ return (struct dvb_multilingual_component_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the components field of a dvb_multilingual_component_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_multilingual_component.
+ */
+#define dvb_multilingual_component_descriptor_components_for_each(d, pos) \
+ for ((pos) = dvb_multilingual_component_descriptor_components_first(d); \
+ (pos); \
+ (pos) = dvb_multilingual_component_descriptor_components_next(d, pos))
+
+/**
+ * Accessor for the text_char field in a dvb_multilingual_component.
+ *
+ * @param e dvb_multilingual_component pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_multilingual_component_text_char(struct dvb_multilingual_component *e)
+{
+ return (uint8_t *) e + sizeof(struct dvb_multilingual_component);
+}
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_multilingual_component*
+ dvb_multilingual_component_descriptor_components_first(struct dvb_multilingual_component_descriptor *d)
+{
+ if (d->d.len == 1)
+ return NULL;
+
+ return (struct dvb_multilingual_component *)
+ ((uint8_t*) d + sizeof(struct dvb_multilingual_component_descriptor));
+}
+
+static inline struct dvb_multilingual_component*
+ dvb_multilingual_component_descriptor_components_next(struct dvb_multilingual_component_descriptor *d,
+ struct dvb_multilingual_component *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_multilingual_component) +
+ pos->text_description_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_multilingual_component *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/multilingual_network_name_descriptor.h b/lib/libucsi/dvb/multilingual_network_name_descriptor.h
new file mode 100644
index 0000000..1a7b8c4
--- /dev/null
+++ b/lib/libucsi/dvb/multilingual_network_name_descriptor.h
@@ -0,0 +1,145 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_MULTILINGUAL_NETWORK_NAME_DESCRIPTOR
+#define _UCSI_DVB_MULTILINGUAL_NETWORK_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_multilingual_network_name_descriptor structure.
+ */
+struct dvb_multilingual_network_name_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_multilingual_network_name names[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the names field of a dvb_multilingual_network_name_descriptor.
+ */
+struct dvb_multilingual_network_name {
+ iso639lang_t language_code;
+ uint8_t network_name_length;
+ /* uint8_t name[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_multilingual_network_name_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_multilingual_network_name_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_multilingual_network_name_descriptor*
+ dvb_multilingual_network_name_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+
+ while(pos < len) {
+ struct dvb_multilingual_network_name *e =
+ (struct dvb_multilingual_network_name*) (buf + pos);
+
+ pos += sizeof(struct dvb_multilingual_network_name);
+
+ if (pos > len)
+ return NULL;
+
+ pos += e->network_name_length;
+
+ if (pos > len)
+ return NULL;
+ }
+
+ return (struct dvb_multilingual_network_name_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the names field of a dvb_multilingual_network_name_descriptor.
+ *
+ * @param d dvb_multilingual_network_name_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_multilingual_network_name.
+ */
+#define dvb_multilingual_network_name_descriptor_names_for_each(d, pos) \
+ for ((pos) = dvb_multilingual_network_name_descriptor_names_first(d); \
+ (pos); \
+ (pos) = dvb_multilingual_network_name_descriptor_names_next(d, pos))
+
+/**
+ * Accessor for the name field of a dvb_multilingual_network_name.
+ *
+ * @param e dvb_multilingual_network_name pointer.
+ * @return Pointer to the name field.
+ */
+static inline uint8_t *
+ dvb_multilingual_network_name_name(struct dvb_multilingual_network_name *e)
+{
+ return (uint8_t *) e + sizeof(struct dvb_multilingual_network_name);
+}
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_multilingual_network_name*
+ dvb_multilingual_network_name_descriptor_names_first(struct dvb_multilingual_network_name_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_multilingual_network_name *)
+ ((uint8_t*) d + sizeof(struct dvb_multilingual_network_name_descriptor));
+}
+
+static inline struct dvb_multilingual_network_name*
+ dvb_multilingual_network_name_descriptor_names_next(struct dvb_multilingual_network_name_descriptor *d,
+ struct dvb_multilingual_network_name *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos +
+ sizeof(struct dvb_multilingual_network_name) +
+ pos->network_name_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_multilingual_network_name *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/multilingual_service_name_descriptor.h b/lib/libucsi/dvb/multilingual_service_name_descriptor.h
new file mode 100644
index 0000000..31bb9c3
--- /dev/null
+++ b/lib/libucsi/dvb/multilingual_service_name_descriptor.h
@@ -0,0 +1,197 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_MULTILINGUAL_SERVICE_NAME_DESCRIPTOR
+#define _UCSI_DVB_MULTILINGUAL_SERVICE_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_multilingual_service_name_descriptor structure.
+ */
+struct dvb_multilingual_service_name_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_multilingual_service_name names[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the service_names field of a dvb_multilingual_service_name_descriptor.
+ */
+struct dvb_multilingual_service_name {
+ iso639lang_t language_code;
+ uint8_t service_provider_name_length;
+ /* uint8_t service_provider_name[] */
+ /* struct dvb_multilingual_service_name_part2 part2 */
+} __ucsi_packed;
+
+/**
+ * Second part of a dvb_multilingual_service_name following the variable length
+ * service_provider_name.
+ */
+struct dvb_multilingual_service_name_part2 {
+ uint8_t service_name_length;
+ /* uint8_t service_name[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_multilingual_service_name_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_multilingual_service_name_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_multilingual_service_name_descriptor*
+ dvb_multilingual_service_name_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+
+ while(pos < len) {
+ struct dvb_multilingual_service_name *e =
+ (struct dvb_multilingual_service_name*) (buf+pos);
+ struct dvb_multilingual_service_name_part2 *e2;
+
+ pos += sizeof(struct dvb_multilingual_service_name);
+
+ if (pos > len)
+ return NULL;
+
+ pos += e->service_provider_name_length;
+
+ if (pos > len)
+ return NULL;
+
+ e2 = (struct dvb_multilingual_service_name_part2*) (buf+pos);
+
+ pos += sizeof(struct dvb_multilingual_service_name_part2);
+
+ if (pos > len)
+ return NULL;
+
+ pos += e2->service_name_length;
+
+ if (pos > len)
+ return NULL;
+ }
+
+ return (struct dvb_multilingual_service_name_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the service_name field of a dvb_multilingual_service_name_descriptor.
+ *
+ * @param d dvb_multilingual_service_name_descriptor pointer,
+ * @param pos Variable containing pointer to the current dvb_multilingual_service_name.
+ */
+#define dvb_multilingual_service_name_descriptor_names_for_each(d, pos) \
+ for ((pos) = dvb_multilingual_service_name_descriptor_names_first(d); \
+ (pos); \
+ (pos) = dvb_multilingual_service_name_descriptor_names_next(d, pos))
+
+/**
+ * Accessor for the service_provider_name field of a dvb_multilingual_service_name.
+ *
+ * @param e dvb_multilingual_service_name pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_multilingual_service_name_service_provider_name(struct dvb_multilingual_service_name *e)
+{
+ return (uint8_t *) e + sizeof(struct dvb_multilingual_service_name);
+}
+
+/**
+ * Accessor for the dvb_multilingual_service_name_part2 - second part of a
+ * dvb_multilingual_service_name following the service_name field.
+ *
+ * @param e dvb_multilingual_service_name Pointer.
+ * @return dvb_multilingual_service_name_part2 pointer.
+ */
+static inline struct dvb_multilingual_service_name_part2 *
+ dvb_multilingual_service_name_part2(struct dvb_multilingual_service_name *e)
+{
+ return (struct dvb_multilingual_service_name_part2 *)
+ ((uint8_t *) e + sizeof(struct dvb_multilingual_service_name) +
+ e->service_provider_name_length);
+}
+
+/**
+ * Accessor for the service_name field of a dvb_multilingual_service_name_part2.
+ *
+ * @param e dvb_multilingual_service_name_part2 pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_multilingual_service_name_service_name(struct dvb_multilingual_service_name_part2 *e)
+{
+ return (uint8_t *) e + sizeof(struct dvb_multilingual_service_name_part2);
+}
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_multilingual_service_name*
+ dvb_multilingual_service_name_descriptor_names_first(struct dvb_multilingual_service_name_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_multilingual_service_name *)
+ ((uint8_t*) d + sizeof(struct dvb_multilingual_service_name_descriptor));
+}
+
+static inline struct dvb_multilingual_service_name*
+ dvb_multilingual_service_name_descriptor_names_next(struct dvb_multilingual_service_name_descriptor *d,
+ struct dvb_multilingual_service_name *pos)
+{
+ struct dvb_multilingual_service_name_part2 * part2 =
+ dvb_multilingual_service_name_part2(pos);
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) part2+
+ sizeof(struct dvb_multilingual_service_name_part2) +
+ part2->service_name_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_multilingual_service_name *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/network_name_descriptor.h b/lib/libucsi/dvb/network_name_descriptor.h
new file mode 100644
index 0000000..0754597
--- /dev/null
+++ b/lib/libucsi/dvb/network_name_descriptor.h
@@ -0,0 +1,82 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_NETWORK_NAME_DESCRIPTOR
+#define _UCSI_DVB_NETWORK_NAME_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_network_name_descriptor structure.
+ */
+struct dvb_network_name_descriptor {
+ struct descriptor d;
+
+ /* char name[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_network_name_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_network_name_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_network_name_descriptor*
+ dvb_network_name_descriptor_codec(struct descriptor* d)
+{
+ return (struct dvb_network_name_descriptor*) d;
+}
+
+/**
+ * Accessor for the name field in a dvb_network_name_descriptor.
+ *
+ * @param d dvb_network_name_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_network_name_descriptor_name(struct dvb_network_name_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_network_name_descriptor);
+}
+
+/**
+ * Calculate the length of the name field in a dvb_network_name_descriptor.
+ *
+ * @param d dvb_network_name_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_network_name_descriptor_name_length(struct dvb_network_name_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/nit_section.c b/lib/libucsi/dvb/nit_section.c
new file mode 100644
index 0000000..664a0cb
--- /dev/null
+++ b/lib/libucsi/dvb/nit_section.c
@@ -0,0 +1,78 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/nit_section.h>
+
+struct dvb_nit_section *dvb_nit_section_codec(struct section_ext * ext)
+{
+ uint8_t * buf = (uint8_t *) ext;
+ struct dvb_nit_section * ret = (struct dvb_nit_section *) ext;
+ size_t pos = sizeof(struct section_ext);
+ size_t len = section_ext_length(ext);
+
+ if (len < sizeof(struct dvb_nit_section))
+ return NULL;
+
+ bswap16(buf + pos);
+ pos += 2;
+
+ if ((pos + ret->network_descriptors_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, ret->network_descriptors_length))
+ return NULL;
+
+ pos += ret->network_descriptors_length;
+
+ if ((pos + sizeof(struct dvb_nit_section_part2)) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+ pos += 2;
+
+ while (pos < len) {
+ struct dvb_nit_transport *transport =
+ (struct dvb_nit_transport *)(buf + pos);
+
+ if ((pos + sizeof(struct dvb_nit_transport)) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+ bswap16(buf + pos + 2);
+ bswap16(buf + pos + 4);
+
+ pos += sizeof(struct dvb_nit_transport);
+
+ if ((pos + transport->transport_descriptors_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos,
+ transport->transport_descriptors_length))
+ return NULL;
+
+ pos += transport->transport_descriptors_length;
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return ret;
+}
diff --git a/lib/libucsi/dvb/nit_section.h b/lib/libucsi/dvb/nit_section.h
new file mode 100644
index 0000000..77ab1a0
--- /dev/null
+++ b/lib/libucsi/dvb/nit_section.h
@@ -0,0 +1,207 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_NIT_SECTION_H
+#define _UCSI_DVB_NIT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * dvb_nit_section structure.
+ */
+struct dvb_nit_section {
+ struct section_ext head;
+
+ EBIT2(uint16_t reserved_1 : 4; ,
+ uint16_t network_descriptors_length :12; );
+ /* struct descriptor descriptors[] */
+ /* struct dvb_nit_section_part2 part2 */
+};
+
+/**
+ * Second part of a dvb_nit_section, following the variable length descriptors field.
+ */
+struct dvb_nit_section_part2 {
+ EBIT2(uint16_t reserved_2 : 4; ,
+ uint16_t transport_stream_loop_length :12; );
+ /* struct dvb_nit_transport transports[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the transports field of a dvb_nit_section_part2
+ */
+struct dvb_nit_transport {
+ uint16_t transport_stream_id;
+ uint16_t original_network_id;
+ EBIT2(uint16_t reserved : 4; ,
+ uint16_t transport_descriptors_length :12; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_nit_section.
+ *
+ * @param section Generic section_ext pointer.
+ * @return dvb_nit_section pointer, or NULL on error.
+ */
+struct dvb_nit_section * dvb_nit_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for the network_id field of a NIT.
+ *
+ * @param nit NIT pointer.
+ * @return The network_id.
+ */
+static inline uint16_t dvb_nit_section_network_id(struct dvb_nit_section *nit)
+{
+ return nit->head.table_id_ext;
+}
+
+/**
+ * Iterator over the descriptors field in a dvb_nit_section.
+ *
+ * @param nit dvb_nit_section pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define dvb_nit_section_descriptors_for_each(nit, pos) \
+ for ((pos) = dvb_nit_section_descriptors_first(nit); \
+ (pos); \
+ (pos) = dvb_nit_section_descriptors_next(nit, pos))
+
+/**
+ * Accessor for a pointer to the dvb_nit_section_part2 structure.
+ *
+ * @param nit dvb_nit_section pointer.
+ * @return dvb_nit_section_part2 pointer.
+ */
+static inline struct dvb_nit_section_part2 *dvb_nit_section_part2(struct dvb_nit_section * nit)
+{
+ return (struct dvb_nit_section_part2 *)
+ ((uint8_t*) nit + sizeof(struct dvb_nit_section) +
+ nit->network_descriptors_length);
+}
+
+/**
+ * Iterator over the transports field in a dvb_nit_section_part2.
+ *
+ * @param nit dvb_nit_section pointer.
+ * @param part2 dvb_nit_section_part2 pointer.
+ * @param pos Pointer to the current dvb_nit_transport.
+ */
+#define dvb_nit_section_transports_for_each(nit, part2, pos) \
+ for ((pos) = dvb_nit_section_transports_first(part2); \
+ (pos); \
+ (pos) = dvb_nit_section_transports_next(part2, pos))
+
+/**
+ * Iterator over the descriptors field in a dvb_nit_transport.
+ *
+ * @param transport dvb_nit_transport pointer.
+ * @param pos Pointer to the current descriptor.
+ */
+#define dvb_nit_transport_descriptors_for_each(transport, pos) \
+ for ((pos) = dvb_nit_transport_descriptors_first(transport); \
+ (pos); \
+ (pos) = dvb_nit_transport_descriptors_next(transport, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ dvb_nit_section_descriptors_first(struct dvb_nit_section * nit)
+{
+ if (nit->network_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) nit + sizeof(struct dvb_nit_section));
+}
+
+static inline struct descriptor *
+ dvb_nit_section_descriptors_next(struct dvb_nit_section * nit,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) nit + sizeof(struct dvb_nit_section),
+ nit->network_descriptors_length,
+ pos);
+}
+
+static inline struct dvb_nit_transport *
+ dvb_nit_section_transports_first(struct dvb_nit_section_part2 *part2)
+{
+ if (part2->transport_stream_loop_length == 0)
+ return NULL;
+
+ return (struct dvb_nit_transport *)
+ ((uint8_t *)part2 + sizeof(struct dvb_nit_section_part2));
+}
+
+static inline struct dvb_nit_transport *
+ dvb_nit_section_transports_next(struct dvb_nit_section_part2 *part2,
+ struct dvb_nit_transport *pos)
+{
+ uint8_t *end = (uint8_t*) part2 + sizeof(struct dvb_nit_section_part2) +
+ part2->transport_stream_loop_length;
+ uint8_t *next = (uint8_t*) pos + sizeof(struct dvb_nit_transport) +
+ pos->transport_descriptors_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_nit_transport *) next;
+}
+
+static inline struct descriptor *
+ dvb_nit_transport_descriptors_first(struct dvb_nit_transport *t)
+{
+ if (t->transport_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t*) t + sizeof(struct dvb_nit_transport));
+}
+
+static inline struct descriptor *
+ dvb_nit_transport_descriptors_next(struct dvb_nit_transport *t,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) t + sizeof(struct dvb_nit_transport),
+ t->transport_descriptors_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/nvod_reference_descriptor.h b/lib/libucsi/dvb/nvod_reference_descriptor.h
new file mode 100644
index 0000000..6180514
--- /dev/null
+++ b/lib/libucsi/dvb/nvod_reference_descriptor.h
@@ -0,0 +1,125 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_NVOD_REFERENCE_DESCRIPTOR
+#define _UCSI_DVB_NVOD_REFERENCE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_nvod_reference_descriptor structure.
+ */
+struct dvb_nvod_reference_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_nvod_reference references[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the references field of a dvb_nvod_reference_descriptor.
+ */
+struct dvb_nvod_reference {
+ uint16_t transport_stream_id;
+ uint16_t original_network_id;
+ uint16_t service_id;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_nvod_reference_descriptor.
+ *
+ * @param d Pointer to a generic descriptor structure pointer.
+ * @return dvb_nvod_reference_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_nvod_reference_descriptor*
+ dvb_nvod_reference_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t len = d->len;
+
+ if (len % sizeof(struct dvb_nvod_reference))
+ return NULL;
+
+ while(pos < len) {
+ bswap16(buf+pos);
+ bswap16(buf+pos+2);
+ bswap16(buf+pos+4);
+ pos += sizeof(struct dvb_nvod_reference);
+ }
+
+ return (struct dvb_nvod_reference_descriptor*) d;
+}
+
+/**
+ * Iterator over the references field in a dvb_nvod_reference_descriptor.
+ *
+ * @param d dvb_nvod_reference_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_nvod_reference.
+ */
+#define dvb_nvod_reference_descriptor_references_for_each(d, pos) \
+ for ((pos) = dvb_nvod_reference_descriptor_references_first(d); \
+ (pos); \
+ (pos) = dvb_nvod_reference_descriptor_references_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_nvod_reference*
+ dvb_nvod_reference_descriptor_references_first(struct dvb_nvod_reference_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_nvod_reference *)
+ ((uint8_t*) d + sizeof(struct dvb_nvod_reference_descriptor));
+}
+
+static inline struct dvb_nvod_reference*
+ dvb_nvod_reference_descriptor_references_next(struct dvb_nvod_reference_descriptor *d,
+ struct dvb_nvod_reference *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_nvod_reference);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_nvod_reference *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/parental_rating_descriptor.h b/lib/libucsi/dvb/parental_rating_descriptor.h
new file mode 100644
index 0000000..72ecd0a
--- /dev/null
+++ b/lib/libucsi/dvb/parental_rating_descriptor.h
@@ -0,0 +1,135 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_PARENTAL_RATING_DESCRIPTOR
+#define _UCSI_DVB_PARENTAL_RATING_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * Defined values for the rating field.
+ */
+enum {
+ DVB_PARENTAL_RATING_MIN_3YEARS = 0x01,
+ DVB_PARENTAL_RATING_MIN_4YEARS = 0x02,
+ DVB_PARENTAL_RATING_MIN_5YEARS = 0x03,
+ DVB_PARENTAL_RATING_MIN_6YEARS = 0x04,
+ DVB_PARENTAL_RATING_MIN_7YEARS = 0x05,
+ DVB_PARENTAL_RATING_MIN_8YEARS = 0x06,
+ DVB_PARENTAL_RATING_MIN_9YEARS = 0x07,
+ DVB_PARENTAL_RATING_MIN_10YEARS = 0x08,
+ DVB_PARENTAL_RATING_MIN_11YEARS = 0x09,
+ DVB_PARENTAL_RATING_MIN_12YEARS = 0x0a,
+ DVB_PARENTAL_RATING_MIN_13YEARS = 0x0b,
+ DVB_PARENTAL_RATING_MIN_14YEARS = 0x0c,
+ DVB_PARENTAL_RATING_MIN_15YEARS = 0x0d,
+ DVB_PARENTAL_RATING_MIN_16YEARS = 0x0e,
+ DVB_PARENTAL_RATING_MIN_17YEARS = 0x0f,
+};
+
+/**
+ * dvb_parental_rating_descriptor structure.
+ */
+struct dvb_parental_rating_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_parental_rating ratings[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the ratings field of a dvb_parental_rating_descriptor.
+ */
+struct dvb_parental_rating {
+ iso639country_t country_code;
+ uint8_t rating;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_parental_rating_descriptor.
+ *
+ * @param d Generic descriptor structure pointer.
+ * @return dvb_parental_rating_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_parental_rating_descriptor*
+ dvb_parental_rating_descriptor_codec(struct descriptor* d)
+{
+ if (d->len % sizeof(struct dvb_parental_rating))
+ return NULL;
+
+ return (struct dvb_parental_rating_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the ratings field of a dvb_parental_rating_descriptor.
+ *
+ * @param d dvb_parental_rating_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_parental_rating.
+ */
+#define dvb_parental_rating_descriptor_ratings_for_each(d, pos) \
+ for ((pos) = dvb_parental_rating_descriptor_ratings_first(d); \
+ (pos); \
+ (pos) = dvb_parental_rating_descriptor_ratings_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_parental_rating*
+ dvb_parental_rating_descriptor_ratings_first(struct dvb_parental_rating_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_parental_rating *)
+ ((uint8_t*) d + sizeof(struct dvb_parental_rating_descriptor));
+}
+
+static inline struct dvb_parental_rating*
+ dvb_parental_rating_descriptor_ratings_next(struct dvb_parental_rating_descriptor *d,
+ struct dvb_parental_rating *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_parental_rating);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_parental_rating *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/partial_transport_stream_descriptor.h b/lib/libucsi/dvb/partial_transport_stream_descriptor.h
new file mode 100644
index 0000000..6e3aa96
--- /dev/null
+++ b/lib/libucsi/dvb/partial_transport_stream_descriptor.h
@@ -0,0 +1,68 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_PARTIAL_TRANSPORT_STREAM_DESCRIPTOR
+#define _UCSI_DVB_PARTIAL_TRANSPORT_STREAM_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_partial_transport_stream_descriptor structure.
+ */
+struct dvb_partial_transport_stream_descriptor {
+ struct descriptor d;
+
+ EBIT6(uint64_t reserved : 2; ,
+ uint64_t peak_rate :22; ,
+ uint64_t reserved_2 : 2; ,
+ uint64_t minimum_overall_smoothing_rate :22; ,
+ uint64_t reserved_3 : 2; ,
+ uint64_t maximum_overall_smoothing_rate :14; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_partial_transport_stream_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_partial_transport_stream_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_partial_transport_stream_descriptor*
+ dvb_partial_transport_stream_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_partial_transport_stream_descriptor) - 2))
+ return NULL;
+
+ bswap64((uint8_t*) d + 2);
+
+ return (struct dvb_partial_transport_stream_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/pdc_descriptor.h b/lib/libucsi/dvb/pdc_descriptor.h
new file mode 100644
index 0000000..68190be
--- /dev/null
+++ b/lib/libucsi/dvb/pdc_descriptor.h
@@ -0,0 +1,64 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_PDC_DESCRIPTOR
+#define _UCSI_DVB_PDC_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_pdc_descriptor structure.
+ */
+struct dvb_pdc_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint32_t reserved : 4; ,
+ uint32_t programme_id_label :20; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_pdc_descriptor.
+ *
+ * @param d Pointer to a generic descriptor structure.
+ * @return dvb_pdc_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_pdc_descriptor*
+ dvb_pdc_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_pdc_descriptor) - 2))
+ return NULL;
+
+ bswap24((uint8_t*) d + 2);
+
+ return (struct dvb_pdc_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/private_data_specifier_descriptor.h b/lib/libucsi/dvb/private_data_specifier_descriptor.h
new file mode 100644
index 0000000..f4cc03c
--- /dev/null
+++ b/lib/libucsi/dvb/private_data_specifier_descriptor.h
@@ -0,0 +1,63 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_PRIVATE_DATA_SPECIFIER_DESCRIPTOR
+#define _UCSI_DVB_PRIVATE_DATA_SPECIFIER_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_private_data_specifier_descriptor structure.
+ */
+struct dvb_private_data_specifier_descriptor {
+ struct descriptor d;
+
+ uint32_t private_data_specifier;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_private_data_specifier_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_private_data_specifier_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_private_data_specifier_descriptor*
+ dvb_private_data_specifier_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_private_data_specifier_descriptor) - 2))
+ return NULL;
+
+ bswap32((uint8_t*) d + 2);
+
+ return (struct dvb_private_data_specifier_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/related_content_descriptor.h b/lib/libucsi/dvb/related_content_descriptor.h
new file mode 100644
index 0000000..fd6a358
--- /dev/null
+++ b/lib/libucsi/dvb/related_content_descriptor.h
@@ -0,0 +1,56 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_RELATED_CONTENT_DESCRIPTOR
+#define _UCSI_DVB_RELATED_CONTENT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_related_content_descriptor structure.
+ */
+struct dvb_related_content_descriptor {
+ struct descriptor d;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_related_content_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_related_content_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_related_content_descriptor*
+ dvb_related_content_descriptor_codec(struct descriptor* d)
+{
+ return (struct dvb_related_content_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/rnt_rar_over_dvb_stream_descriptor.h b/lib/libucsi/dvb/rnt_rar_over_dvb_stream_descriptor.h
new file mode 100644
index 0000000..ba42d12
--- /dev/null
+++ b/lib/libucsi/dvb/rnt_rar_over_dvb_stream_descriptor.h
@@ -0,0 +1,110 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_RNT_RAR_OVER_DVB_STREAM_DESCRIPTOR
+#define _UCSI_DVB_RNT_RAR_OVER_DVB_STREAM_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_rnt_rar_over_dvb_stream_descriptor structure.
+ */
+struct dvb_rnt_rar_over_dvb_stream_descriptor {
+ struct descriptor d;
+
+ dvbdate_t first_valid_date;
+ dvbdate_t last_valid_date;
+ EBIT3(uint8_t weighting : 6; ,
+ uint8_t complete_flag : 1; ,
+ uint8_t scheduled_flag : 1; );
+ uint16_t transport_stream_id;
+ uint16_t original_network_id;
+ uint16_t service_id;
+ uint8_t component_tag;
+ /* struct dvb_rnt_rar_over_dvb_stream_descriptor_scheduled_info scheduled_info */
+} __ucsi_packed;
+
+/**
+ * The scheduled_info field of a dvb_rnt_rar_over_dvb_stream_descriptor (only appears
+ * if scheduled_flag = 1).
+ */
+struct dvb_rnt_rar_over_dvb_stream_descriptor_scheduled_info {
+ dvbdate_t download_start_time;
+ uint8_t download_period_duration;
+ uint8_t download_cycle_time;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_rnt_rar_over_dvb_stream_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_rnt_rar_over_dvb_stream_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_rnt_rar_over_dvb_stream_descriptor*
+ dvb_rnt_rar_over_dvb_stream_descriptor_codec(struct descriptor* d)
+{
+ uint8_t *buf = (uint8_t*) d;
+ uint32_t len = d->len + 2;
+ struct dvb_rnt_rar_over_dvb_stream_descriptor *ret =
+ (struct dvb_rnt_rar_over_dvb_stream_descriptor *) buf;
+
+ if (len < sizeof(struct dvb_rnt_rar_over_dvb_stream_descriptor))
+ return NULL;
+
+ bswap16(buf + 13);
+ bswap16(buf + 15);
+ bswap16(buf + 17);
+
+ if (ret->scheduled_flag == 1) {
+ if (len < (sizeof(struct dvb_rnt_rar_over_dvb_stream_descriptor)+
+ sizeof(struct dvb_rnt_rar_over_dvb_stream_descriptor_scheduled_info)))
+ return NULL;
+ }
+
+ return ret;
+}
+
+/**
+ * Accessor for the scheduled_info field of a dvb_rnt_rar_over_dvb_stream_descriptor.
+ *
+ * @param d dvb_rnt_rar_over_dvb_stream_descriptor pointer.
+ * @return Pointer, or NULL on error.
+ */
+static inline struct dvb_rnt_rar_over_dvb_stream_descriptor_scheduled_info*
+ dvb_rnt_rar_over_dvb_stream_descriptor_scheduled_info(struct dvb_rnt_rar_over_dvb_stream_descriptor *d)
+{
+ if (d->scheduled_flag != 1)
+ return NULL;
+ return (struct dvb_rnt_rar_over_dvb_stream_descriptor_scheduled_info*)
+ ((uint8_t*) d + sizeof(struct dvb_rnt_rar_over_dvb_stream_descriptor));
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/rnt_rar_over_ip_descriptor.h b/lib/libucsi/dvb/rnt_rar_over_ip_descriptor.h
new file mode 100644
index 0000000..b1f2da4
--- /dev/null
+++ b/lib/libucsi/dvb/rnt_rar_over_ip_descriptor.h
@@ -0,0 +1,87 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_RNT_RAR_OVER_IP_DESCRIPTOR
+#define _UCSI_DVB_RNT_RAR_OVER_IP_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_rnt_rar_over_ip_descriptor structure.
+ */
+struct dvb_rnt_rar_over_ip_descriptor {
+ struct descriptor d;
+
+ dvbdate_t first_valid_date;
+ dvbdate_t last_valid_date;
+ EBIT3(uint8_t weighting : 6; ,
+ uint8_t complete_flag : 1; ,
+ uint8_t reserved : 1; );
+ uint8_t url_length;
+ /* uint8_t url[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_rnt_rar_over_ip_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_rnt_rar_over_ip_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_rnt_rar_over_ip_descriptor*
+ dvb_rnt_rar_over_ip_descriptor_codec(struct descriptor* d)
+{
+ uint8_t *buf = (uint8_t*) d;
+ uint32_t len = d->len + 2;
+ struct dvb_rnt_rar_over_ip_descriptor *ret =
+ (struct dvb_rnt_rar_over_ip_descriptor *) buf;
+
+ if (len < sizeof(struct dvb_rnt_rar_over_ip_descriptor))
+ return NULL;
+ if (len < (sizeof(struct dvb_rnt_rar_over_ip_descriptor) + buf[13]))
+ return NULL;
+
+ return ret;
+}
+
+/**
+ * Accessor for the url field of a dvb_rnt_rar_over_ip_descriptor.
+ *
+ * @param d dvb_rnt_rar_over_ip_descriptor pointer.
+ * @return Pointer.
+ */
+static inline uint8_t*
+ dvb_rnt_rar_over_ip_descriptor_url(struct dvb_rnt_rar_over_ip_descriptor *d)
+{
+ return (uint8_t*)
+ ((uint8_t*) d + sizeof(struct dvb_rnt_rar_over_ip_descriptor));
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/rnt_rnt_scan_descriptor.h b/lib/libucsi/dvb/rnt_rnt_scan_descriptor.h
new file mode 100644
index 0000000..cb74f75
--- /dev/null
+++ b/lib/libucsi/dvb/rnt_rnt_scan_descriptor.h
@@ -0,0 +1,125 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_RNT_RNT_SCAN_DESCRIPTOR
+#define _UCSI_DVB_RNT_RNT_SCAN_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_rnt_rnt_scan_descriptor structure.
+ */
+struct dvb_rnt_rnt_scan_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_rnt_rnt_scan_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the entries field of a dvb_rnt_rnt_scan_descriptor.
+ */
+struct dvb_rnt_rnt_scan_entry {
+ uint16_t transport_stream_id;
+ uint16_t original_network_id;
+ uint8_t scan_weighting;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_rnt_rnt_scan_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return dvb_rnt_rnt_scan_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_rnt_rnt_scan_descriptor*
+ dvb_rnt_rnt_scan_descriptor_codec(struct descriptor* d)
+{
+ uint8_t *buf = (uint8_t*) d;
+ uint32_t len = d->len +2;
+ uint32_t pos = 2;
+
+ if ((len-2) % sizeof(struct dvb_rnt_rnt_scan_entry))
+ return NULL;
+
+ while(pos < len) {
+ bswap16(buf+pos);
+ bswap16(buf+pos+2);
+ pos += sizeof(struct dvb_rnt_rnt_scan_entry);
+ }
+
+ return (struct dvb_rnt_rnt_scan_descriptor*) d;
+}
+
+/**
+ * Iterator for entries field of a dvb_rnt_rnt_scan_descriptor.
+ *
+ * @param d dvb_rnt_rnt_scan_descriptor pointer.
+ * @param pos Variable holding a pointer to the current dvb_rnt_rnt_scan_entry.
+ */
+#define dvb_rnt_rnt_scan_descriptor_entries_for_each(d, pos) \
+ for ((pos) = dvb_rnt_rnt_scan_descriptor_entries_first(d); \
+ (pos); \
+ (pos) = dvb_rnt_rnt_scan_descriptor_entries_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_rnt_rnt_scan_entry*
+ dvb_rnt_rnt_scan_descriptor_entries_first(struct dvb_rnt_rnt_scan_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_rnt_rnt_scan_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_rnt_rnt_scan_descriptor));
+}
+
+static inline struct dvb_rnt_rnt_scan_entry*
+ dvb_rnt_rnt_scan_descriptor_entries_next(struct dvb_rnt_rnt_scan_descriptor *d,
+ struct dvb_rnt_rnt_scan_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_rnt_rnt_scan_entry);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_rnt_rnt_scan_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/rst_section.c b/lib/libucsi/dvb/rst_section.c
new file mode 100644
index 0000000..259d2b0
--- /dev/null
+++ b/lib/libucsi/dvb/rst_section.c
@@ -0,0 +1,47 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/rst_section.h>
+
+struct dvb_rst_section * dvb_rst_section_codec(struct section *section)
+{
+ uint8_t * buf = (uint8_t *) section;
+ size_t pos = sizeof(struct section);
+ size_t len = section_length(section);
+ struct dvb_rst_section * ret = (struct dvb_rst_section *) section;
+
+ while (pos < len) {
+ if ((pos + sizeof(struct dvb_rst_status)) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+ bswap16(buf + pos + 2);
+ bswap16(buf + pos + 4);
+ bswap16(buf + pos + 6);
+
+ pos += sizeof(struct dvb_rst_status);
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return ret;
+}
diff --git a/lib/libucsi/dvb/rst_section.h b/lib/libucsi/dvb/rst_section.h
new file mode 100644
index 0000000..4b3360b
--- /dev/null
+++ b/lib/libucsi/dvb/rst_section.h
@@ -0,0 +1,110 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_RST_SECTION_H
+#define _UCSI_DVB_RST_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * dvb_rst_section structure.
+ */
+struct dvb_rst_section {
+ struct section head;
+
+ /* struct dvb_rst_status statuses[] */
+};
+
+/**
+ * An entry in the statuses field of a dvb_rst_section structure.
+ */
+struct dvb_rst_status {
+ uint16_t transport_stream_id;
+ uint16_t original_network_id;
+ uint16_t service_id;
+ uint16_t event_id;
+ EBIT2(uint8_t reserved : 5; ,
+ uint8_t running_status : 3; );
+};
+
+/**
+ * Process a dvb_rst_section.
+ *
+ * @param section Pointer to a generic section strcuture.
+ * @return dvb_rst_section pointer, or NULL on error.
+ */
+struct dvb_rst_section *dvb_rst_section_codec(struct section *section);
+
+/**
+ * Iterator for entries in the statuses field of a dvb_rst_section.
+ *
+ * @param rst dvb_rst_section pointer.
+ * @param pos Variable containing a pointer to the current dvb_rst_status.
+ */
+#define dvb_rst_section_statuses_for_each(rst, pos) \
+ for ((pos) = dvb_rst_section_statuses_first(rst); \
+ (pos); \
+ (pos) = dvb_rst_section_statuses_next(rst, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_rst_status *
+ dvb_rst_section_statuses_first(struct dvb_rst_section *rst)
+{
+ size_t pos = sizeof(struct dvb_rst_section);
+
+ if (pos >= section_length(&rst->head))
+ return NULL;
+
+ return (struct dvb_rst_status*) ((uint8_t *) rst + pos);
+}
+
+static inline struct dvb_rst_status *
+ dvb_rst_section_statuses_next(struct dvb_rst_section * rst,
+ struct dvb_rst_status * pos)
+{
+ uint8_t *end = (uint8_t*) rst + section_length(&rst->head);
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_rst_status);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_rst_status *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/s2_satellite_delivery_descriptor.h b/lib/libucsi/dvb/s2_satellite_delivery_descriptor.h
new file mode 100644
index 0000000..8f9fea8
--- /dev/null
+++ b/lib/libucsi/dvb/s2_satellite_delivery_descriptor.h
@@ -0,0 +1,116 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_S2_SATELLITE_DELIVERY_DESCRIPTOR
+#define _UCSI_DVB_S2_SATELLITE_DELIVERY_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_s2_satellite_delivery_descriptor structure.
+ */
+struct dvb_s2_satellite_delivery_descriptor {
+ struct descriptor d;
+
+ EBIT4(uint8_t scrambling_sequence_selector : 1; ,
+ uint8_t multiple_input_stream : 1; ,
+ uint8_t backwards_compatability : 1; ,
+ uint8_t reserved : 5; );
+ /* uint32_t scrambling_sequence_index if scrambling_sequence_selector = 1 */
+ /* uint8_t input_stream_id if multiple_input_stream = 1 */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_s2_satellite_delivery_descriptor.
+ *
+ * @param d Pointer to a generic descriptor structure.
+ * @return dvb_s2_satellite_delivery_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_s2_satellite_delivery_descriptor*
+ dvb_s2_satellite_delivery_descriptor_codec(struct descriptor* d)
+{
+ struct dvb_s2_satellite_delivery_descriptor *s2 =
+ (struct dvb_s2_satellite_delivery_descriptor*) d;
+
+ if (d->len < (sizeof(struct dvb_s2_satellite_delivery_descriptor) - 2))
+ return NULL;
+
+ int len = sizeof(struct dvb_s2_satellite_delivery_descriptor);
+ if (s2->scrambling_sequence_selector) {
+ len += 3;
+ }
+ if (s2->multiple_input_stream) {
+ len += 1;
+ }
+
+ if (d->len < len)
+ return NULL;
+
+ return s2;
+}
+
+/**
+ * Accessor for the scrambling_sequence_index field of a dvb_s2_satellite_delivery_descriptor.
+ *
+ * @param s2 dvb_s2_satellite_delivery_descriptor pointer.
+ * @return The scrambling_sequence_index.
+ */
+static inline uint32_t dvb_s2_satellite_delivery_descriptor_scrambling_sequence_index(struct dvb_s2_satellite_delivery_descriptor *s2)
+{
+ uint8_t *tmp = (uint8_t*) s2;
+
+ if (s2->scrambling_sequence_selector) {
+ return ((tmp[4] & 0x03) << 16) | (tmp[5] << 8) | tmp[6];
+ }
+ return 0;
+}
+
+/**
+ * Accessor for the input_stream_id field of a dvb_s2_satellite_delivery_descriptor.
+ *
+ * @param s2 dvb_s2_satellite_delivery_descriptor pointer.
+ * @return The input_stream_id.
+ */
+static inline uint8_t dvb_s2_satellite_delivery_descriptor_input_stream_id(struct dvb_s2_satellite_delivery_descriptor *s2)
+{
+ uint8_t *tmp = (uint8_t*) s2;
+
+ if (!s2->multiple_input_stream)
+ return 0;
+
+ int off = 3;
+ if (s2->scrambling_sequence_selector) {
+ off += 3;
+ }
+ return tmp[off];
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/satellite_delivery_descriptor.h b/lib/libucsi/dvb/satellite_delivery_descriptor.h
new file mode 100644
index 0000000..b93d052
--- /dev/null
+++ b/lib/libucsi/dvb/satellite_delivery_descriptor.h
@@ -0,0 +1,73 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SATELLITE_DELIVERY_DESCRIPTOR
+#define _UCSI_DVB_SATELLITE_DELIVERY_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_satellite_delivery_descriptor structure.
+ */
+struct dvb_satellite_delivery_descriptor {
+ struct descriptor d;
+
+ uint32_t frequency; // BCD, units 10kHz
+ uint16_t orbital_position;
+ EBIT5(uint8_t west_east_flag : 1; ,
+ uint8_t polarization : 2; ,
+ uint8_t roll_off : 2; ,
+ uint8_t modulation_system : 1; ,
+ uint8_t modulation_type : 2; );
+ EBIT2(uint32_t symbol_rate : 28; , // BCD, units 100Hz
+ uint32_t fec_inner : 4; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_satellite_delivery_descriptor.
+ *
+ * @param d Pointer to a generic descriptor structure.
+ * @return dvb_satellite_delivery_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_satellite_delivery_descriptor*
+ dvb_satellite_delivery_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct dvb_satellite_delivery_descriptor) - 2))
+ return NULL;
+
+ bswap32((uint8_t*) d + 2);
+ bswap16((uint8_t*) d + 6);
+ bswap32((uint8_t*) d + 9);
+
+ return (struct dvb_satellite_delivery_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/scrambling_descriptor.h b/lib/libucsi/dvb/scrambling_descriptor.h
new file mode 100644
index 0000000..4669bc8
--- /dev/null
+++ b/lib/libucsi/dvb/scrambling_descriptor.h
@@ -0,0 +1,61 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SCRAMBLING_DESCRIPTOR
+#define _UCSI_DVB_SCRAMBLING_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_scrambling_descriptor structure.
+ */
+struct dvb_scrambling_descriptor {
+ struct descriptor d;
+
+ uint8_t scrambling_mode;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_scrambling_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to dvb_scrambling_descriptor, or NULL on error.
+ */
+static inline struct dvb_scrambling_descriptor*
+ dvb_scrambling_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_scrambling_descriptor) - 2))
+ return NULL;
+
+ return (struct dvb_scrambling_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/sdt_section.c b/lib/libucsi/dvb/sdt_section.c
new file mode 100644
index 0000000..4c7824c
--- /dev/null
+++ b/lib/libucsi/dvb/sdt_section.c
@@ -0,0 +1,60 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/sdt_section.h>
+
+struct dvb_sdt_section * dvb_sdt_section_codec(struct section_ext * ext)
+{
+ uint8_t * buf = (uint8_t *) ext;
+ size_t pos = sizeof(struct section_ext);
+ size_t len = section_ext_length(ext);
+
+ if (len < sizeof(struct dvb_sdt_section))
+ return NULL;
+
+ bswap16(buf + pos);
+ pos += 3;
+
+ while (pos < len) {
+ struct dvb_sdt_service * service =
+ (struct dvb_sdt_service *)(buf + pos);
+
+ if ((pos + sizeof(struct dvb_sdt_service)) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+ bswap16(buf + pos + 3);
+ pos += sizeof(struct dvb_sdt_service);
+
+ if ((pos + service->descriptors_loop_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, service->descriptors_loop_length))
+ return NULL;
+
+ pos += service->descriptors_loop_length;
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return (struct dvb_sdt_section *) ext;
+}
diff --git a/lib/libucsi/dvb/sdt_section.h b/lib/libucsi/dvb/sdt_section.h
new file mode 100644
index 0000000..03a8569
--- /dev/null
+++ b/lib/libucsi/dvb/sdt_section.h
@@ -0,0 +1,157 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SDT_SECTION_H
+#define _UCSI_DVB_SDT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * dvb_sdt_section structure.
+ */
+struct dvb_sdt_section {
+ struct section_ext head;
+
+ uint16_t original_network_id;
+ uint8_t reserved;
+ /* struct dvb_sdt_service services[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the services field of a dvb_sdt_section.
+ */
+struct dvb_sdt_service {
+ uint16_t service_id;
+ EBIT3(uint8_t reserved : 6; ,
+ uint8_t eit_schedule_flag : 1; ,
+ uint8_t eit_present_following_flag : 1; );
+ EBIT3(uint16_t running_status : 3; ,
+ uint16_t free_ca_mode : 1; ,
+ uint16_t descriptors_loop_length :12; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_sdt_section.
+ *
+ * @param section Pointer to a generic section_ext structure.
+ * @return dvb_sdt_section pointer, or NULL on error.
+ */
+struct dvb_sdt_section * dvb_sdt_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for the transport_stream_id field of an SDT.
+ *
+ * @param sdt SDT pointer.
+ * @return The transport_stream_id.
+ */
+static inline uint16_t dvb_sdt_section_transport_stream_id(struct dvb_sdt_section *sdt)
+{
+ return sdt->head.table_id_ext;
+}
+
+/**
+ * Iterator for the services field in a dvb_sdt_section.
+ *
+ * @param sdt dvb_sdt_section pointer.
+ * @param pos Variable containing a pointer to the current dvb_sdt_service.
+ */
+#define dvb_sdt_section_services_for_each(sdt, pos) \
+ for ((pos) = dvb_sdt_section_services_first(sdt); \
+ (pos); \
+ (pos) = dvb_sdt_section_services_next(sdt, pos))
+
+/**
+ * Iterator for the descriptors field in a dvb_sdt_service.
+ *
+ * @param service dvb_sdt_service pointer.
+ * @param pos Variable containing a pointer to the current descriptor.
+ */
+#define dvb_sdt_service_descriptors_for_each(service, pos) \
+ for ((pos) = dvb_sdt_service_descriptors_first(service); \
+ (pos); \
+ (pos) = dvb_sdt_service_descriptors_next(service, pos))
+
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_sdt_service *
+ dvb_sdt_section_services_first(struct dvb_sdt_section * sdt)
+{
+ size_t pos = sizeof(struct dvb_sdt_section);
+
+ if (pos >= section_ext_length(&sdt->head))
+ return NULL;
+
+ return (struct dvb_sdt_service*) ((uint8_t *) sdt + pos);
+}
+
+static inline struct dvb_sdt_service *
+ dvb_sdt_section_services_next(struct dvb_sdt_section * sdt,
+ struct dvb_sdt_service * pos)
+{
+ uint8_t *end = (uint8_t*) sdt + section_ext_length(&sdt->head);
+ uint8_t *next = (uint8_t*) pos + sizeof(struct dvb_sdt_service) +
+ pos->descriptors_loop_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_sdt_service *) next;
+}
+
+static inline struct descriptor *
+ dvb_sdt_service_descriptors_first(struct dvb_sdt_service *svc)
+{
+ if (svc->descriptors_loop_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t*) svc + sizeof(struct dvb_sdt_service));
+}
+
+static inline struct descriptor *
+ dvb_sdt_service_descriptors_next(struct dvb_sdt_service *svc,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) svc + sizeof(struct dvb_sdt_service),
+ svc->descriptors_loop_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/section.h b/lib/libucsi/dvb/section.h
new file mode 100644
index 0000000..8488d71
--- /dev/null
+++ b/lib/libucsi/dvb/section.h
@@ -0,0 +1,107 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SECTION_H
+#define _UCSI_DVB_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/dvb/bat_section.h>
+#include <libucsi/dvb/dit_section.h>
+#include <libucsi/dvb/eit_section.h>
+#include <libucsi/dvb/nit_section.h>
+#include <libucsi/dvb/rst_section.h>
+#include <libucsi/dvb/sdt_section.h>
+#include <libucsi/dvb/sit_section.h>
+#include <libucsi/dvb/st_section.h>
+#include <libucsi/dvb/tdt_section.h>
+#include <libucsi/dvb/tot_section.h>
+#include <libucsi/dvb/tva_container_section.h>
+#include <libucsi/dvb/int_section.h>
+
+/**
+ * The following are not implemented just now.
+ */
+/*
+#include <libucsi/dvb/tva_related_content_section.h>
+#include <libucsi/dvb/tva_content_identifier_section.h>
+#include <libucsi/dvb/tva_resolution_provider_notification_section.h>
+#include <libucsi/dvb/ait_section.h>
+#include <libucsi/dvb/cit_section.h>
+#include <libucsi/dvb/rct_section.h>
+#include <libucsi/dvb/rnt_section.h>
+*/
+
+#define TRANSPORT_NIT_PID 0x10
+#define TRANSPORT_SDT_PID 0x11
+#define TRANSPORT_BAT_PID 0x11
+#define TRANSPORT_EIT_PID 0x12
+#define TRANSPORT_CIT_PID 0x12
+#define TRANSPORT_RST_PID 0x13
+#define TRANSPORT_TDT_PID 0x14
+#define TRANSPORT_TOT_PID 0x14
+#define TRANSPORT_RNT_PID 0x16
+#define TRANSPORT_DIT_PID 0x1e
+#define TRANSPORT_SIT_PID 0x1f
+
+/**
+ * Enumeration of DVB section tags.
+ */
+enum dvb_section_tag {
+ stag_dvb_network_information_actual = 0x40,
+ stag_dvb_network_information_other = 0x41,
+
+ stag_dvb_service_description_actual = 0x42,
+ stag_dvb_service_description_other = 0x46,
+
+ stag_dvb_bouquet_association = 0x4a,
+ stag_dvb_update_notification = 0x4b, /* same syntax as IP_MAC */
+ stag_dvb_ip_mac_notification = 0x4c,
+
+ stag_dvb_event_information_nownext_actual = 0x4e,
+ stag_dvb_event_information_nownext_other = 0x4f,
+ stag_dvb_event_information_schedule_actual = 0x50, /* 0x50->0x5f */
+ stag_dvb_event_information_schedule_other = 0x60, /* 0x60->0x6f */
+
+ stag_dvb_time_date = 0x70,
+ stag_dvb_running_status = 0x71,
+ stag_dvb_stuffing = 0x72,
+ stag_dvb_time_offset = 0x73,
+ stag_dvb_application_information = 0x74,
+ stag_dvb_tva_container = 0x75,
+ stag_dvb_tva_related_content = 0x76,
+ stag_dvb_tva_content_identifier = 0x77,
+ stag_dvb_mpe_fec = 0x78,
+ stag_dvb_tva_resolution_provider_notification = 0x79,
+
+ stag_dvb_discontinuity_information = 0x7e,
+ stag_dvb_selection_information = 0x7f,
+
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/service_availability_descriptor.h b/lib/libucsi/dvb/service_availability_descriptor.h
new file mode 100644
index 0000000..64def75
--- /dev/null
+++ b/lib/libucsi/dvb/service_availability_descriptor.h
@@ -0,0 +1,98 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SERVICE_AVAILABILITY_DESCRIPTOR
+#define _UCSI_DVB_SERVICE_AVAILABILITY_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_service_availability_descriptor structure.
+ */
+struct dvb_service_availability_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t availability_flag : 1; ,
+ uint8_t reserved : 7; );
+ /* uint16_t cell_ids[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_service_availability_descriptor.
+ *
+ * @param d Pointer to a generic descriptor structure.
+ * @return dvb_service_availability_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_service_availability_descriptor*
+ dvb_service_availability_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint8_t* buf = (uint8_t*) d + 2;
+ uint32_t len = d->len;
+
+ pos += sizeof(struct dvb_service_availability_descriptor) - 2;
+
+ if ((len - pos) % 2)
+ return NULL;
+
+ while(pos < len) {
+ bswap16(buf+pos);
+ pos += 2;
+ }
+
+ return (struct dvb_service_availability_descriptor*) d;
+}
+
+/**
+ * Accessor for the cell_ids field of a dvb_service_availability_descriptor.
+ *
+ * @param d dvb_service_availability_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint16_t *
+ dvb_service_availability_descriptor_cell_ids(struct dvb_service_availability_descriptor *d)
+{
+ return (uint16_t *) ((uint8_t *) d + sizeof(struct dvb_service_availability_descriptor));
+}
+
+/**
+ * Determine the number of entries in the cell_ids field of a dvb_service_availability_descriptor.
+ *
+ * @param d dvb_service_availability_descriptor pointer.
+ * @return The number of entries.
+ */
+static inline int
+ dvb_service_availability_descriptor_cell_ids_count(struct dvb_service_availability_descriptor *d)
+{
+ return (d->d.len - 1) >> 1;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/service_descriptor.h b/lib/libucsi/dvb/service_descriptor.h
new file mode 100644
index 0000000..dd0f0ec
--- /dev/null
+++ b/lib/libucsi/dvb/service_descriptor.h
@@ -0,0 +1,163 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SERVICE_DESCRIPTOR
+#define _UCSI_DVB_SERVICE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Possible values for service_type.
+ */
+enum {
+ DVB_SERVICE_TYPE_DIGITAL_TV = 0x01,
+ DVB_SERVICE_TYPE_DIGITAL_RADIO = 0x02,
+ DVB_SERVICE_TYPE_TELETEXT = 0x03,
+ DVB_SERVICE_TYPE_NVOD_REF = 0x04,
+ DVB_SERVICE_TYPE_NVOD_TIMESHIFT = 0x05,
+ DVB_SERVICE_TYPE_MOSAIC = 0x06,
+ DVB_SERVICE_TYPE_PAL = 0x07,
+ DVB_SERVICE_TYPE_SECAM = 0x08,
+ DVB_SERVICE_TYPE_D_D2_MAC = 0x09,
+ DVB_SERVICE_TYPE_FM_RADIO = 0x0a,
+ DVB_SERVICE_TYPE_NTSC = 0x0b,
+ DVB_SERVICE_TYPE_DATA_BCAST = 0x0c,
+ DVB_SERVICE_TYPE_EN50221 = 0x0d,
+ DVB_SERVICE_TYPE_RCS_MAP = 0x0e,
+ DVB_SERVICE_TYPE_RCS_FLS = 0x0f,
+ DVB_SERVICE_TYPE_MHP = 0x10,
+ DVB_SERVICE_TYPE_MPEG2_HD_DIGITAL_TV = 0x11,
+ DVB_SERVICE_TYPE_ADVANCED_CODEC_SD_DIGITAL_TV = 0x16,
+ DVB_SERVICE_TYPE_ADVANCED_CODEC_SD_NVOD_TIMESHIFT = 0x17,
+ DVB_SERVICE_TYPE_ADVANCED_CODEC_SD_NVOD_REF = 0x18,
+ DVB_SERVICE_TYPE_ADVANCED_CODEC_HD_DIGITAL_TV = 0x19,
+ DVB_SERVICE_TYPE_ADVANCED_CODEC_HD_NVOD_TIMESHIFT = 0x1a,
+ DVB_SERVICE_TYPE_ADVANCED_CODEC_HD_NVOD_REF = 0x1b,
+};
+
+/**
+ * dvb_service_descriptor structure.
+ */
+struct dvb_service_descriptor {
+ struct descriptor d;
+
+ uint8_t service_type;
+ uint8_t service_provider_name_length;
+ /* uint8_t service_provider_name[] */
+ /* struct dvb_service_descriptor_part2 part2 */
+} __ucsi_packed;
+
+/**
+ * Second part of a dvb_service_descriptor following the variable length
+ * service_provider_name field.
+ */
+struct dvb_service_descriptor_part2 {
+ uint8_t service_name_length;
+ /* uint8_t service_name[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_service_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_service_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_service_descriptor*
+ dvb_service_descriptor_codec(struct descriptor* d)
+{
+ struct dvb_service_descriptor *p =
+ (struct dvb_service_descriptor *) d;
+ struct dvb_service_descriptor_part2 *p2;
+ uint32_t pos = sizeof(struct dvb_service_descriptor) - 2;
+ uint32_t len = d->len;
+
+ if (pos > len)
+ return NULL;
+
+ pos += p->service_provider_name_length;
+
+ if (pos > len)
+ return NULL;
+
+ p2 = (struct dvb_service_descriptor_part2*) ((uint8_t*) d + 2 + pos);
+
+ pos += sizeof(struct dvb_service_descriptor_part2);
+
+ if (pos > len)
+ return NULL;
+
+ pos += p2->service_name_length;
+
+ if (pos != len)
+ return NULL;
+
+ return p;
+}
+
+/**
+ * Accessor for the service_provider_name field of a dvb_service_descriptor.
+ *
+ * @param d dvb_service_descriptor pointer.
+ * @return Pointer to the service_provider_name field.
+ */
+static inline uint8_t *
+ dvb_service_descriptor_service_provider_name(struct dvb_service_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_service_descriptor);
+}
+
+/**
+ * Accessor for the second part of a dvb_service_descriptor.
+ *
+ * @param d dvb_service_descriptor pointer.
+ * @return dvb_service_descriptor_part2 pointer.
+ */
+static inline struct dvb_service_descriptor_part2 *
+ dvb_service_descriptor_part2(struct dvb_service_descriptor *d)
+{
+ return (struct dvb_service_descriptor_part2 *)
+ ((uint8_t*) d + sizeof(struct dvb_service_descriptor) +
+ d->service_provider_name_length);
+}
+
+/**
+ * Accessor for the service_name field of a dvb_service_descriptor_part2.
+ *
+ * @param d dvb_service_descriptor_part2 pointer.
+ * @return Pointer to the service_name field.
+ */
+static inline uint8_t *
+ dvb_service_descriptor_service_name(struct dvb_service_descriptor_part2 *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_service_descriptor_part2);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/service_identifier_descriptor.h b/lib/libucsi/dvb/service_identifier_descriptor.h
new file mode 100644
index 0000000..2037a05
--- /dev/null
+++ b/lib/libucsi/dvb/service_identifier_descriptor.h
@@ -0,0 +1,82 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SERVICE_IDENTIFIER_DESCRIPTOR
+#define _UCSI_DVB_SERVICE_IDENTIFIER_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_service_identifier_descriptor.
+ */
+struct dvb_service_identifier_descriptor {
+ struct descriptor d;
+
+ /* uint8_t identifier[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_service_identifier_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_service_identifier_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_service_identifier_descriptor*
+ dvb_service_identifier_descriptor_codec(struct descriptor* d)
+{
+ return (struct dvb_service_identifier_descriptor*) d;
+}
+
+/**
+ * Retrieve a pointer to the identifier field of a dvb_service_identifier_descriptor.
+ *
+ * @param d dvb_service_identifier_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_service_identifier_descriptor_identifier(struct dvb_service_identifier_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_service_identifier_descriptor);
+}
+
+/**
+ * Calculate length of the identifier field of a dvb_service_identifier_descriptor.
+ *
+ * @param d dvb_service_identifier_descriptor pointer.
+ * @return The length in bytes.
+ */
+static inline int
+ dvb_service_identifier_descriptor_identifier_length(struct dvb_service_identifier_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/service_list_descriptor.h b/lib/libucsi/dvb/service_list_descriptor.h
new file mode 100644
index 0000000..0086b25
--- /dev/null
+++ b/lib/libucsi/dvb/service_list_descriptor.h
@@ -0,0 +1,122 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SERVICE_LIST_DESCRIPTOR
+#define _UCSI_DVB_SERVICE_LIST_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_service_list_descriptor structure.
+ */
+struct dvb_service_list_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_service_list_service services[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the services field of a dvb_service_list_descriptor.
+ */
+struct dvb_service_list_service {
+ uint16_t service_id;
+ uint8_t service_type;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_service_list_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_service_list_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_service_list_descriptor*
+ dvb_service_list_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+ uint8_t *p = (uint8_t*) d + 2;
+
+ if (len % sizeof(struct dvb_service_list_service))
+ return NULL;
+
+ while(pos < len) {
+ bswap16(p+pos);
+ pos += sizeof(struct dvb_service_list_service);
+ }
+
+ return (struct dvb_service_list_descriptor*) d;
+}
+
+/**
+ * Iterator for services field in a dvb_service_list_descriptor.
+ *
+ * @param d dvb_service_list_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_service_list_service.
+ */
+#define dvb_service_list_descriptor_services_for_each(d, pos) \
+ for ((pos) = dvb_service_list_descriptor_services_first(d); \
+ (pos); \
+ (pos) = dvb_service_list_descriptor_services_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_service_list_service*
+ dvb_service_list_descriptor_services_first(struct dvb_service_list_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_service_list_service *)
+ ((uint8_t*) d + sizeof(struct dvb_service_list_descriptor));
+}
+
+static inline struct dvb_service_list_service*
+ dvb_service_list_descriptor_services_next(struct dvb_service_list_descriptor *d,
+ struct dvb_service_list_service *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_service_list_service);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_service_list_service *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/service_move_descriptor.h b/lib/libucsi/dvb/service_move_descriptor.h
new file mode 100644
index 0000000..7685e65
--- /dev/null
+++ b/lib/libucsi/dvb/service_move_descriptor.h
@@ -0,0 +1,67 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SERVICE_MOVE_DESCRIPTOR
+#define _UCSI_DVB_SERVICE_MOVE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_service_move_descriptor structure.
+ */
+struct dvb_service_move_descriptor {
+ struct descriptor d;
+
+ uint16_t new_original_network_id;
+ uint16_t new_transport_stream_id;
+ uint16_t new_service_id;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_service_move_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to dvb_service_move_descriptor, or NULL on error.
+ */
+static inline struct dvb_service_move_descriptor*
+ dvb_service_move_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_service_move_descriptor) - 2))
+ return NULL;
+
+ bswap16((uint8_t*) d + 2);
+ bswap16((uint8_t*) d + 4);
+ bswap16((uint8_t*) d + 6);
+
+ return (struct dvb_service_move_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/short_event_descriptor.h b/lib/libucsi/dvb/short_event_descriptor.h
new file mode 100644
index 0000000..449c6f0
--- /dev/null
+++ b/lib/libucsi/dvb/short_event_descriptor.h
@@ -0,0 +1,135 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SHORT_EVENT_DESCRIPTOR
+#define _UCSI_DVB_SHORT_EVENT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_short_event_descriptor structure.
+ */
+struct dvb_short_event_descriptor {
+ struct descriptor d;
+
+ iso639lang_t language_code;
+ uint8_t event_name_length;
+ /* uint8_t event_name[] */
+ /* struct dvb_short_event_descriptor_part2 part2 */
+} __ucsi_packed;
+
+/**
+ * Second part of a dvb_short_event_descriptor, following the variable length
+ * name field.
+ */
+struct dvb_short_event_descriptor_part2 {
+ uint8_t text_length;
+ /* uint8_t text[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_short_event_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_short_event_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_short_event_descriptor*
+ dvb_short_event_descriptor_codec(struct descriptor* d)
+{
+ struct dvb_short_event_descriptor *p =
+ (struct dvb_short_event_descriptor*) d;
+ struct dvb_short_event_descriptor_part2 *p2;
+ uint32_t pos = sizeof(struct dvb_short_event_descriptor) - 2;
+ uint32_t len = d->len;
+
+ if (pos > len)
+ return NULL;
+
+ pos += p->event_name_length;
+
+ if (pos > len)
+ return NULL;
+
+ p2 = (struct dvb_short_event_descriptor_part2*) ((uint8_t*) d + 2 + pos);
+
+ pos += sizeof(struct dvb_short_event_descriptor_part2);
+
+ if (pos > len)
+ return NULL;
+
+ pos += p2->text_length;
+
+ if (pos != len)
+ return NULL;
+
+ return p;
+}
+
+/**
+ * Accessor for name field in a dvb_short_event_descriptor.
+ *
+ * @param d dvb_short_event_descriptor pointer.
+ * @return Pointer to name field.
+ */
+static inline uint8_t *
+ dvb_short_event_descriptor_event_name(struct dvb_short_event_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_short_event_descriptor);
+}
+
+/**
+ * Accessor for second part of a dvb_short_event_descriptor.
+ *
+ * @param d dvb_short_event_descriptor pointer.
+ * @return dvb_short_event_descriptor_part2 pointer.
+ */
+static inline struct dvb_short_event_descriptor_part2 *
+ dvb_short_event_descriptor_part2(struct dvb_short_event_descriptor *d)
+{
+ return (struct dvb_short_event_descriptor_part2 *)
+ ((uint8_t*) d + sizeof(struct dvb_short_event_descriptor) +
+ d->event_name_length);
+}
+
+/**
+ * Accessor for text field in a dvb_short_event_descriptor_part2.
+ *
+ * @param d dvb_short_event_descriptor_part2 pointer.
+ * @return Pointer to text field.
+ */
+static inline uint8_t *
+ dvb_short_event_descriptor_text(struct dvb_short_event_descriptor_part2 *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_short_event_descriptor_part2);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/short_smoothing_buffer_descriptor.h b/lib/libucsi/dvb/short_smoothing_buffer_descriptor.h
new file mode 100644
index 0000000..e52d20a
--- /dev/null
+++ b/lib/libucsi/dvb/short_smoothing_buffer_descriptor.h
@@ -0,0 +1,87 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SHORT_SMOOTHING_BUFFER_DESCRIPTOR
+#define _UCSI_DVB_SHORT_SMOOTHING_BUFFER_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_short_smoothing_buffer_descriptor structure.
+ */
+struct dvb_short_smoothing_buffer_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t sb_size : 2; ,
+ uint8_t sb_leak_rate : 6; );
+ /* uint8_t reserved [] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_short_smoothing_buffer_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_short_smoothing_buffer_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_short_smoothing_buffer_descriptor*
+ dvb_short_smoothing_buffer_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct dvb_short_smoothing_buffer_descriptor) - 2))
+ return NULL;
+
+ return (struct dvb_short_smoothing_buffer_descriptor*) d;
+}
+
+/**
+ * Accessor for reserved field in a dvb_short_smoothing_buffer_descriptor.
+ *
+ * @param d dvb_short_smoothing_buffer_descriptor pointer.
+ * @return Pointer to reserved field.
+ */
+static inline uint8_t *
+ dvb_short_smoothing_buffer_descriptor_reserved(struct dvb_short_smoothing_buffer_descriptor *d)
+{
+ return (uint8_t*) d + sizeof(struct dvb_short_smoothing_buffer_descriptor);
+}
+
+/**
+ * Calculate length of reserved field in a dvb_short_smoothing_buffer_descriptor.
+ *
+ * @param d dvb_short_smoothing_buffer_descriptor pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ dvb_short_smoothing_buffer_descriptor_reserved_length(struct dvb_short_smoothing_buffer_descriptor *d)
+{
+ return d->d.len - 1;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/sit_section.c b/lib/libucsi/dvb/sit_section.c
new file mode 100644
index 0000000..06c228c
--- /dev/null
+++ b/lib/libucsi/dvb/sit_section.c
@@ -0,0 +1,69 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/sit_section.h>
+
+struct dvb_sit_section * dvb_sit_section_codec(struct section_ext * ext)
+{
+ uint8_t * buf = (uint8_t *) ext;
+ struct dvb_sit_section * ret = (struct dvb_sit_section *) ext;
+ size_t pos = sizeof(struct section_ext);
+ size_t len = section_ext_length(ext);
+
+ if (len < sizeof(struct dvb_sit_section))
+ return NULL;
+
+ bswap16(buf + pos);
+ pos += 2;
+
+ if ((pos + ret->transmission_info_loop_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, ret->transmission_info_loop_length))
+ return NULL;
+
+ pos += ret->transmission_info_loop_length;
+
+ while (pos < len) {
+ struct dvb_sit_service * service = (void*)(buf + pos);
+
+ if ((pos + sizeof(struct dvb_sit_service)) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+ bswap16(buf + pos + 2);
+ bswap16(buf + pos + 4);
+ pos += sizeof(struct dvb_sit_service);
+
+ if ((pos + service->service_loop_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, service->service_loop_length))
+ return NULL;
+
+ pos += service->service_loop_length;
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return ret;
+}
diff --git a/lib/libucsi/dvb/sit_section.h b/lib/libucsi/dvb/sit_section.h
new file mode 100644
index 0000000..e06d596
--- /dev/null
+++ b/lib/libucsi/dvb/sit_section.h
@@ -0,0 +1,173 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SIT_SECTION_H
+#define _UCSI_DVB_SIT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * dvb_sit_section structure.
+ */
+struct dvb_sit_section {
+ struct section_ext head;
+
+ EBIT2(uint16_t reserved : 4; ,
+ uint16_t transmission_info_loop_length :12; );
+ /* struct descriptor descriptors[] */
+ /* struct dvb_sit_service services[] */
+};
+
+/**
+ * An entry in the services field of a dvb_sit_section.
+ */
+struct dvb_sit_service {
+ uint16_t service_id;
+ EBIT3(uint16_t reserved : 1; ,
+ uint16_t running_status : 3; ,
+ uint16_t service_loop_length :12; );
+ /* struct descriptor descriptors[] */
+};
+
+/**
+ * Process a dvb_sit_section.
+ *
+ * @param section Generic section_ext structure.
+ * @return dvb_sit_section pointer, or NULL on error.
+ */
+struct dvb_sit_section * dvb_sit_section_codec(struct section_ext *section);
+
+/**
+ * Iterator for descriptors field in a dvb_sit_section.
+ *
+ * @param sit dvb_sit_section Pointer.
+ * @param pos Variable holding pointer to current descriptor.
+ */
+#define dvb_sit_section_descriptors_for_each(sit, pos) \
+ for ((pos) = dvb_sit_section_descriptors_first(sit); \
+ (pos); \
+ (pos) = dvb_sit_section_descriptors_first(sit))
+
+/**
+ * Iterator for services field in a dvb_sit_section.
+ *
+ * @param sit dvb_sit_section Pointer.
+ * @param pos Variable holding pointer to current dvb_sit_service.
+ */
+#define dvb_sit_section_services_for_each(sit, pos) \
+ for ((pos) = dvb_sit_section_services_first(sit); \
+ (pos); \
+ (pos) = dvb_sit_section_services_next(sit, pos))
+
+/**
+ * Iterator for descriptors field in a dvb_sit_service.
+ *
+ * @param service dvb_sit_service Pointer.
+ * @param pos Variable holding pointer to current descriptor.
+ */
+#define dvb_sit_service_descriptors_for_each(service, pos) \
+ for ((pos) = dvb_sit_service_descriptors_first(service); \
+ (pos); \
+ (pos) = dvb_sit_service_descriptors_next(service, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ dvb_sit_section_descriptors_first(struct dvb_sit_section *sit)
+{
+ if (sit->transmission_info_loop_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) sit + sizeof(struct dvb_sit_section));
+}
+
+static inline struct descriptor *
+ dvb_sit_section_descriptors_next(struct dvb_sit_section *sit,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) sit + sizeof(struct dvb_sit_section),
+ sit->transmission_info_loop_length,
+ pos);
+}
+
+static inline struct dvb_sit_service *
+ dvb_sit_section_services_first(struct dvb_sit_section *sit)
+{
+ size_t pos = sizeof(struct dvb_sit_section) + sit->transmission_info_loop_length;
+
+ if (pos >= section_ext_length(&sit->head))
+ return NULL;
+
+ return (struct dvb_sit_service*) ((uint8_t *) sit + pos);
+}
+
+static inline struct dvb_sit_service *
+ dvb_sit_section_services_next(struct dvb_sit_section *sit,
+ struct dvb_sit_service *pos)
+{
+ uint8_t *end = (uint8_t*) sit + section_ext_length(&sit->head);
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_sit_service) +
+ pos->service_loop_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_sit_service *) next;
+}
+
+static inline struct descriptor *
+ dvb_sit_service_descriptors_first(struct dvb_sit_service * t)
+{
+ if (t->service_loop_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) t + sizeof(struct dvb_sit_service));
+}
+
+static inline struct descriptor *
+ dvb_sit_service_descriptors_next(struct dvb_sit_service *t,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) t + sizeof(struct dvb_sit_service),
+ t->service_loop_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/st_section.c b/lib/libucsi/dvb/st_section.c
new file mode 100644
index 0000000..0e60aa1
--- /dev/null
+++ b/lib/libucsi/dvb/st_section.c
@@ -0,0 +1,29 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/st_section.h>
+
+struct dvb_st_section * dvb_st_section_codec(struct section * section)
+{
+ struct dvb_st_section * ret = (struct dvb_st_section *)section;
+
+ return ret;
+}
diff --git a/lib/libucsi/dvb/st_section.h b/lib/libucsi/dvb/st_section.h
new file mode 100644
index 0000000..52ba888
--- /dev/null
+++ b/lib/libucsi/dvb/st_section.h
@@ -0,0 +1,77 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_ST_SECTION_H
+#define _UCSI_DVB_ST_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * dvb_st_section structure.
+ */
+struct dvb_st_section {
+ struct section head;
+
+ /* uint8_t data[] */
+};
+
+/**
+ * Process a dvb_st_section.
+ *
+ * @param section Generic section header.
+ * @return dvb_st_section pointer, or NULL on error.
+ */
+struct dvb_st_section *dvb_st_section_codec(struct section *section);
+
+/**
+ * Accessor for data field of dvb_st_section.
+ *
+ * @param st dvb_st_section Pointer.
+ * @return Pointer to field.
+ */
+static inline uint8_t*
+ dvb_st_section_data(struct dvb_st_section* st)
+{
+ return (uint8_t*) st + sizeof(struct dvb_st_section);
+}
+
+/**
+ * Calculate length of data field of dvb_st_section.
+ *
+ * @param st dvb_st_section Pointer.
+ * @return Length in bytes.
+ */
+static inline int
+ dvb_st_section_data_length(struct dvb_st_section* st)
+{
+ return st->head.length;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/stream_identifier_descriptor.h b/lib/libucsi/dvb/stream_identifier_descriptor.h
new file mode 100644
index 0000000..262c7e2
--- /dev/null
+++ b/lib/libucsi/dvb/stream_identifier_descriptor.h
@@ -0,0 +1,61 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_STREAM_IDENTIFIER_DESCRIPTOR
+#define _UCSI_DVB_STREAM_IDENTIFIER_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_stream_identifier_descriptor structure.
+ */
+struct dvb_stream_identifier_descriptor {
+ struct descriptor d;
+
+ uint8_t component_tag;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_stream_identifier_descriptor.
+ *
+ * @param d Pointer to generic descriptor structure.
+ * @return dvb_stream_identifier_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_stream_identifier_descriptor*
+ dvb_stream_identifier_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_stream_identifier_descriptor) - 2))
+ return NULL;
+
+ return (struct dvb_stream_identifier_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/stuffing_descriptor.h b/lib/libucsi/dvb/stuffing_descriptor.h
new file mode 100644
index 0000000..48e415d
--- /dev/null
+++ b/lib/libucsi/dvb/stuffing_descriptor.h
@@ -0,0 +1,82 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_STUFFING_DESCRIPTOR
+#define _UCSI_DVB_STUFFING_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_stuffing_descriptor.
+ */
+struct dvb_stuffing_descriptor {
+ struct descriptor d;
+
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_stuffing_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_stuffing_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_stuffing_descriptor*
+ dvb_stuffing_descriptor_codec(struct descriptor* d)
+{
+ return (struct dvb_stuffing_descriptor*) d;
+}
+
+/**
+ * Retrieve a pointer to the data field of a dvb_stuffing_descriptor.
+ *
+ * @param d dvb_stuffing_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ dvb_stuffing_descriptor_data(struct dvb_stuffing_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_stuffing_descriptor);
+}
+
+/**
+ * Calculate length of the data field of a dvb_stuffing_descriptor.
+ *
+ * @param d dvb_stuffing_descriptor pointer.
+ * @return The length in bytes.
+ */
+static inline int
+ dvb_stuffing_descriptor_data_length(struct dvb_stuffing_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/subtitling_descriptor.h b/lib/libucsi/dvb/subtitling_descriptor.h
new file mode 100644
index 0000000..74fc25a
--- /dev/null
+++ b/lib/libucsi/dvb/subtitling_descriptor.h
@@ -0,0 +1,126 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_SUBTITLING_DESCRIPTOR
+#define _UCSI_DVB_SUBTITLING_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_subtitling_descriptor structure.
+ */
+struct dvb_subtitling_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_subtitling_entry subtitles[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the subtitles field of the a dvb_subtitling_descriptor.
+ */
+struct dvb_subtitling_entry {
+ iso639lang_t language_code;
+ uint8_t subtitling_type;
+ uint16_t composition_page_id;
+ uint16_t ancillary_page_id;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_subtitling_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return dvb_subtitling_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_subtitling_descriptor*
+ dvb_subtitling_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint8_t* ptr = (uint8_t*) d + 2;
+ uint32_t len = d->len;
+
+ if (len % sizeof(struct dvb_subtitling_entry))
+ return NULL;
+
+ while(pos < len) {
+ bswap16(ptr+pos+4);
+ bswap16(ptr+pos+6);
+ pos += sizeof(struct dvb_subtitling_entry);
+ }
+
+ return (struct dvb_subtitling_descriptor*) d;
+}
+
+/**
+ * Iterator for subtitles field in dvb_subtitling_descriptor.
+ *
+ * @param d dvb_subtitling_descriptor pointer.
+ * @param pos Variable containing a pointer to current dvb_subtitling_entry.
+ */
+#define dvb_subtitling_descriptor_subtitles_for_each(d, pos) \
+ for ((pos) = dvb_subtitling_descriptor_subtitles_first(d); \
+ (pos); \
+ (pos) = dvb_subtitling_descriptor_subtitles_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_subtitling_entry*
+ dvb_subtitling_descriptor_subtitles_first(struct dvb_subtitling_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_subtitling_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_subtitling_descriptor));
+}
+
+static inline struct dvb_subtitling_entry*
+ dvb_subtitling_descriptor_subtitles_next(struct dvb_subtitling_descriptor *d,
+ struct dvb_subtitling_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_subtitling_entry);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_subtitling_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/target_ip_address_descriptor.h b/lib/libucsi/dvb/target_ip_address_descriptor.h
new file mode 100644
index 0000000..c08b60e
--- /dev/null
+++ b/lib/libucsi/dvb/target_ip_address_descriptor.h
@@ -0,0 +1,116 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TARGET_IP_ADDRESS_DESCRIPTOR
+#define _UCSI_DVB_TARGET_IP_ADDRESS_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_target_ip_address_descriptor structure.
+ */
+struct dvb_target_ip_address_descriptor {
+ struct descriptor d;
+
+ uint8_t ipv4_addr_mask[4];
+ /* struct dvb_ipv4_addr ipv4_addr[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the ipv4_addr field of a dvb_target_ip_address_descriptor.
+ */
+struct dvb_ipv4_addr {
+ uint8_t ipv4_addr[4];
+} __ucsi_packed;
+
+/**
+ * Process a dvb_target_ip_address_descriptor.
+ *
+ * @param d Generic descriptor structure pointer.
+ * @return dvb_target_ip_address_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_target_ip_address_descriptor*
+ dvb_target_ip_address_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len - 4;
+
+ if (len % sizeof(struct dvb_ipv4_addr))
+ return NULL;
+
+ return (struct dvb_target_ip_address_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the ipv4_addr field of a dvb_target_ip_address_descriptor.
+ *
+ * @param d dvb_target_ip_address_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_ipv4_addr.
+ */
+#define dvb_target_ip_address_descriptor_ipv4_addr_for_each(d, pos) \
+ for ((pos) = dvb_target_ip_address_descriptor_ipv4_addr_first(d); \
+ (pos); \
+ (pos) = dvb_target_ip_address_descriptor_ipv4_addr_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ipv4_addr*
+ dvb_target_ip_address_descriptor_ipv4_addr_first(struct dvb_target_ip_address_descriptor *d)
+{
+ if (d->d.len == 4)
+ return NULL;
+
+ return (struct dvb_ipv4_addr *)
+ ((uint8_t*) d + sizeof(struct dvb_target_ip_address_descriptor));
+}
+
+static inline struct dvb_ipv4_addr*
+ dvb_target_ip_address_descriptor_ipv4_addr_next(struct dvb_target_ip_address_descriptor *d,
+ struct dvb_ipv4_addr *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len - 4;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ipv4_addr);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_ipv4_addr *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/target_ip_slash_descriptor.h b/lib/libucsi/dvb/target_ip_slash_descriptor.h
new file mode 100644
index 0000000..e5bc76a
--- /dev/null
+++ b/lib/libucsi/dvb/target_ip_slash_descriptor.h
@@ -0,0 +1,116 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TARGET_IP_SLASH_DESCRIPTOR
+#define _UCSI_DVB_TARGET_IP_SLASH_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_target_ip_slash_descriptor structure.
+ */
+struct dvb_target_ip_slash_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_ipv4_slash ipv4_slash[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the ipv4_slash field of a dvb_target_ip_slash_descriptor.
+ */
+struct dvb_ipv4_slash {
+ uint8_t ipv4_addr[4];
+ uint8_t ipv4_slash;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_target_ip_slash_descriptor.
+ *
+ * @param d Generic descriptor structure pointer.
+ * @return dvb_target_ip_slash_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_target_ip_slash_descriptor*
+ dvb_target_ip_slash_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len;
+
+ if (len % sizeof(struct dvb_ipv4_slash))
+ return NULL;
+
+ return (struct dvb_target_ip_slash_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the ipv4_slash field of a dvb_target_ip_slash_descriptor.
+ *
+ * @param d dvb_target_ip_slash_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_ipv4_slash.
+ */
+#define dvb_target_ip_slash_descriptor_ipv4_slash_for_each(d, pos) \
+ for ((pos) = dvb_target_ip_slash_descriptor_ipv4_slash_first(d); \
+ (pos); \
+ (pos) = dvb_target_ip_slash_descriptor_ipv4_slash_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ipv4_slash*
+ dvb_target_ip_slash_descriptor_ipv4_slash_first(struct dvb_target_ip_slash_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_ipv4_slash *)
+ ((uint8_t*) d + sizeof(struct dvb_target_ip_slash_descriptor));
+}
+
+static inline struct dvb_ipv4_slash*
+ dvb_target_ip_slash_descriptor_ipv4_slash_next(struct dvb_target_ip_slash_descriptor *d,
+ struct dvb_ipv4_slash *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ipv4_slash);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_ipv4_slash *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/target_ip_source_slash_descriptor.h b/lib/libucsi/dvb/target_ip_source_slash_descriptor.h
new file mode 100644
index 0000000..8cade48
--- /dev/null
+++ b/lib/libucsi/dvb/target_ip_source_slash_descriptor.h
@@ -0,0 +1,118 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TARGET_IP_SOURCE_SLASH_DESCRIPTOR
+#define _UCSI_DVB_TARGET_IP_SOURCE_SLASH_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_target_ip_source_slash_descriptor structure.
+ */
+struct dvb_target_ip_source_slash_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_ipv4_source_slash ipv4_source_slash[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the ipv4_source_slash field of a dvb_target_ip_source_slash_descriptor.
+ */
+struct dvb_ipv4_source_slash {
+ uint8_t ipv4_source_addr[4];
+ uint8_t ipv4_source_slash;
+ uint8_t ipv4_dest_addr[4];
+ uint8_t ipv4_dest_slash;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_target_ip_source_slash_descriptor.
+ *
+ * @param d Generic descriptor structure pointer.
+ * @return dvb_target_ip_source_slash_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_target_ip_source_slash_descriptor*
+ dvb_target_ip_source_slash_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len;
+
+ if (len % sizeof(struct dvb_ipv4_source_slash))
+ return NULL;
+
+ return (struct dvb_target_ip_source_slash_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the ipv4_source_slash field of a dvb_target_ip_source_slash_descriptor.
+ *
+ * @param d dvb_target_ip_source_slash_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_ipv4_source_slash.
+ */
+#define dvb_target_ip_source_slash_descriptor_ipv4_source_slash_for_each(d, pos) \
+ for ((pos) = dvb_target_ip_source_slash_descriptor_ipv4_source_slash_first(d); \
+ (pos); \
+ (pos) = dvb_target_ip_source_slash_descriptor_ipv4_source_slash_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ipv4_source_slash*
+ dvb_target_ip_source_slash_descriptor_ipv4_source_slash_first(struct dvb_target_ip_source_slash_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_ipv4_source_slash *)
+ ((uint8_t*) d + sizeof(struct dvb_target_ip_source_slash_descriptor));
+}
+
+static inline struct dvb_ipv4_source_slash*
+ dvb_target_ip_source_slash_descriptor_ipv4_source_slash_next(struct dvb_target_ip_source_slash_descriptor *d,
+ struct dvb_ipv4_source_slash *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ipv4_source_slash);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_ipv4_source_slash *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/target_ipv6_address_descriptor.h b/lib/libucsi/dvb/target_ipv6_address_descriptor.h
new file mode 100644
index 0000000..1b28b48
--- /dev/null
+++ b/lib/libucsi/dvb/target_ipv6_address_descriptor.h
@@ -0,0 +1,116 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TARGET_IPV6_ADDRESS_DESCRIPTOR
+#define _UCSI_DVB_TARGET_IPV6_ADDRESS_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_target_ipv6_address_descriptor structure.
+ */
+struct dvb_target_ipv6_address_descriptor {
+ struct descriptor d;
+
+ uint8_t ipv6_addr_mask[16];
+ /* struct dvb_ipv6_addr ipv6_addr[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the ipv6_addr field of a dvb_target_ipv6_address_descriptor.
+ */
+struct dvb_ipv6_addr {
+ uint8_t ipv6_addr[16];
+} __ucsi_packed;
+
+/**
+ * Process a dvb_target_ipv6_address_descriptor.
+ *
+ * @param d Generic descriptor structure pointer.
+ * @return dvb_target_ipv6_address_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_target_ipv6_address_descriptor*
+ dvb_target_ipv6_address_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len - 16;
+
+ if (len % sizeof(struct dvb_ipv6_addr))
+ return NULL;
+
+ return (struct dvb_target_ipv6_address_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the ipv6_addr field of a dvb_target_ipv6_address_descriptor.
+ *
+ * @param d dvb_target_ipv6_address_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_ipv6_addr.
+ */
+#define dvb_target_ipv6_address_descriptor_ipv6_addr_for_each(d, pos) \
+ for ((pos) = dvb_target_ipv6_address_descriptor_ipv6_addr_first(d); \
+ (pos); \
+ (pos) = dvb_target_ipv6_address_descriptor_ipv6_addr_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ipv6_addr*
+ dvb_target_ipv6_address_descriptor_ipv6_addr_first(struct dvb_target_ipv6_address_descriptor *d)
+{
+ if (d->d.len == 16)
+ return NULL;
+
+ return (struct dvb_ipv6_addr *)
+ ((uint8_t*) d + sizeof(struct dvb_target_ipv6_address_descriptor));
+}
+
+static inline struct dvb_ipv6_addr*
+ dvb_target_ipv6_address_descriptor_ipv6_addr_next(struct dvb_target_ipv6_address_descriptor *d,
+ struct dvb_ipv6_addr *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len - 16;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ipv6_addr);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_ipv6_addr *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/target_ipv6_slash_descriptor.h b/lib/libucsi/dvb/target_ipv6_slash_descriptor.h
new file mode 100644
index 0000000..3dc6d75
--- /dev/null
+++ b/lib/libucsi/dvb/target_ipv6_slash_descriptor.h
@@ -0,0 +1,116 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TARGET_IPV6_SLASH_DESCRIPTOR
+#define _UCSI_DVB_TARGET_IPV6_SLASH_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_target_ipv6_slash_descriptor structure.
+ */
+struct dvb_target_ipv6_slash_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_ipv6_slash ipv6_slash[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the ipv6_slash field of a dvb_target_ipv6_slash_descriptor.
+ */
+struct dvb_ipv6_slash {
+ uint8_t ipv6_addr[16];
+ uint8_t ipv6_slash;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_target_ipv6_slash_descriptor.
+ *
+ * @param d Generic descriptor structure pointer.
+ * @return dvb_target_ipv6_slash_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_target_ipv6_slash_descriptor*
+ dvb_target_ipv6_slash_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len;
+
+ if (len % sizeof(struct dvb_ipv6_slash))
+ return NULL;
+
+ return (struct dvb_target_ipv6_slash_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the ipv6_slash field of a dvb_target_ipv6_slash_descriptor.
+ *
+ * @param d dvb_target_ipv6_slash_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_ipv6_slash.
+ */
+#define dvb_target_ipv6_slash_descriptor_ipv6_slash_for_each(d, pos) \
+ for ((pos) = dvb_target_ipv6_slash_descriptor_ipv6_slash_first(d); \
+ (pos); \
+ (pos) = dvb_target_ipv6_slash_descriptor_ipv6_slash_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ipv6_slash*
+ dvb_target_ipv6_slash_descriptor_ipv6_slash_first(struct dvb_target_ipv6_slash_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_ipv6_slash *)
+ ((uint8_t*) d + sizeof(struct dvb_target_ipv6_slash_descriptor));
+}
+
+static inline struct dvb_ipv6_slash*
+ dvb_target_ipv6_slash_descriptor_ipv6_slash_next(struct dvb_target_ipv6_slash_descriptor *d,
+ struct dvb_ipv6_slash *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ipv6_slash);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_ipv6_slash *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/target_ipv6_source_slash_descriptor.h b/lib/libucsi/dvb/target_ipv6_source_slash_descriptor.h
new file mode 100644
index 0000000..3a4b38e
--- /dev/null
+++ b/lib/libucsi/dvb/target_ipv6_source_slash_descriptor.h
@@ -0,0 +1,118 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TARGET_IPV6_SOURCE_SLASH_DESCRIPTOR
+#define _UCSI_DVB_TARGET_IPV6_SOURCE_SLASH_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_target_ipv6_source_slash_descriptor structure.
+ */
+struct dvb_target_ipv6_source_slash_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_ipv6_source_slash ipv6_source_slash[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the ipv6_source_slash field of a dvb_target_ipv6_source_slash_descriptor.
+ */
+struct dvb_ipv6_source_slash {
+ uint8_t ipv6_source_addr[16];
+ uint8_t ipv6_source_slash;
+ uint8_t ipv6_dest_addr[16];
+ uint8_t ipv6_dest_slash;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_target_ipv6_source_slash_descriptor.
+ *
+ * @param d Generic descriptor structure pointer.
+ * @return dvb_target_ipv6_source_slash_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_target_ipv6_source_slash_descriptor*
+ dvb_target_ipv6_source_slash_descriptor_codec(struct descriptor* d)
+{
+ uint32_t len = d->len;
+
+ if (len % sizeof(struct dvb_ipv6_source_slash))
+ return NULL;
+
+ return (struct dvb_target_ipv6_source_slash_descriptor*) d;
+}
+
+/**
+ * Iterator for entries in the ipv6_source_slash field of a dvb_target_ipv6_source_slash_descriptor.
+ *
+ * @param d dvb_target_ipv6_source_slash_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_ipv6_source_slash.
+ */
+#define dvb_target_ipv6_source_slash_descriptor_ipv6_source_slash_for_each(d, pos) \
+ for ((pos) = dvb_target_ipv6_source_slash_descriptor_ipv6_source_slash_first(d); \
+ (pos); \
+ (pos) = dvb_target_ipv6_source_slash_descriptor_ipv6_source_slash_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_ipv6_source_slash*
+ dvb_target_ipv6_source_slash_descriptor_ipv6_source_slash_first(struct dvb_target_ipv6_source_slash_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_ipv6_source_slash *)
+ ((uint8_t*) d + sizeof(struct dvb_target_ipv6_source_slash_descriptor));
+}
+
+static inline struct dvb_ipv6_source_slash*
+ dvb_target_ipv6_source_slash_descriptor_ipv6_source_slash_next(struct dvb_target_ipv6_source_slash_descriptor *d,
+ struct dvb_ipv6_source_slash *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ipv6_source_slash);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_ipv6_source_slash *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/tdt_section.c b/lib/libucsi/dvb/tdt_section.c
new file mode 100644
index 0000000..ba64fe9
--- /dev/null
+++ b/lib/libucsi/dvb/tdt_section.c
@@ -0,0 +1,33 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/tdt_section.h>
+
+struct dvb_tdt_section * dvb_tdt_section_codec(struct section * section)
+{
+ size_t len = section_length(section);
+ struct dvb_tdt_section * ret = (struct dvb_tdt_section *) section;
+
+ if (len != sizeof(struct dvb_tdt_section))
+ return NULL;
+
+ return ret;
+}
diff --git a/lib/libucsi/dvb/tdt_section.h b/lib/libucsi/dvb/tdt_section.h
new file mode 100644
index 0000000..fc2bcb8
--- /dev/null
+++ b/lib/libucsi/dvb/tdt_section.h
@@ -0,0 +1,54 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TDT_SECTION_H
+#define _UCSI_DVB_TDT_SECTION_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+#include <libucsi/dvb/types.h>
+
+/**
+ * dvb_tdt_section structure.
+ */
+struct dvb_tdt_section {
+ struct section head;
+
+ dvbdate_t utc_time;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_tdt_section.
+ *
+ * @param section Generic section header.
+ * @return dvb_tdt_section pointer, or NULL on error.
+ */
+struct dvb_tdt_section *dvb_tdt_section_codec(struct section *section);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/telephone_descriptor.h b/lib/libucsi/dvb/telephone_descriptor.h
new file mode 100644
index 0000000..3dc43a1
--- /dev/null
+++ b/lib/libucsi/dvb/telephone_descriptor.h
@@ -0,0 +1,150 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TELEPHONE_DESCRIPTOR
+#define _UCSI_DVB_TELEPHONE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_telephone_descriptor stucture.
+ */
+struct dvb_telephone_descriptor {
+ struct descriptor d;
+
+ EBIT3(uint8_t reserved_1 : 2; ,
+ uint8_t foreign_availability : 1; ,
+ uint8_t connection_type : 5; );
+ EBIT4(uint8_t reserved_2 : 1; ,
+ uint8_t country_prefix_length : 2; ,
+ uint8_t international_area_code_length : 3; ,
+ uint8_t operator_code_length : 2; );
+ EBIT3(uint8_t reserved_3 : 1; ,
+ uint8_t national_area_code_length : 3; ,
+ uint8_t core_number_length : 4; );
+ /* uint8_t country_prefix[] */
+ /* uint8_t international_area_code[] */
+ /* uint8_t operator_code[] */
+ /* uint8_t national_area_code[] */
+ /* uint8_t core_number[] */
+} __ucsi_packed;
+
+
+/**
+ * Process a dvb_telephone_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return dvb_telephone_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_telephone_descriptor*
+ dvb_telephone_descriptor_codec(struct descriptor* d)
+{
+ struct dvb_telephone_descriptor* p =
+ (struct dvb_telephone_descriptor*) d;
+ uint32_t pos = sizeof(struct dvb_telephone_descriptor) - 2;
+ uint32_t len = d->len;
+
+ if (pos > len)
+ return NULL;
+
+ pos += p->country_prefix_length +
+ p->international_area_code_length +
+ p->operator_code_length +
+ p->national_area_code_length +
+ p->core_number_length;
+
+ if (pos != len)
+ return NULL;
+
+ return p;
+}
+
+/**
+ * Retrieve pointer to country_prefix field of a dvb_telephone_descriptor.
+ *
+ * @param d dvb_telephone_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ dvb_telephone_descriptor_country_prefix(struct dvb_telephone_descriptor* d)
+{
+ return (uint8_t*) d + sizeof(struct dvb_telephone_descriptor);
+}
+
+/**
+ * Retrieve pointer to international_area_code field of a dvb_telephone_descriptor.
+ *
+ * @param d dvb_telephone_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ dvb_telephone_descriptor_international_area_code(struct dvb_telephone_descriptor* d)
+{
+ return dvb_telephone_descriptor_country_prefix(d) + d->country_prefix_length;
+}
+
+/**
+ * Retrieve pointer to operator_code field of a dvb_telephone_descriptor.
+ *
+ * @param d dvb_telephone_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ dvb_telephone_descriptor_operator_code(struct dvb_telephone_descriptor* d)
+{
+ return dvb_telephone_descriptor_international_area_code(d) + d->international_area_code_length;
+}
+
+/**
+ * Retrieve pointer to national_area_code field of a dvb_telephone_descriptor.
+ *
+ * @param d dvb_telephone_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ dvb_telephone_descriptor_national_area_code(struct dvb_telephone_descriptor* d)
+{
+ return dvb_telephone_descriptor_operator_code(d) + d->operator_code_length;
+}
+
+/**
+ * Retrieve pointer to core_number field of a dvb_telephone_descriptor.
+ *
+ * @param d dvb_telephone_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ dvb_telephone_descriptor_core_number(struct dvb_telephone_descriptor* d)
+{
+ return dvb_telephone_descriptor_national_area_code(d) + d->national_area_code_length;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/teletext_descriptor.h b/lib/libucsi/dvb/teletext_descriptor.h
new file mode 100644
index 0000000..424c1cb
--- /dev/null
+++ b/lib/libucsi/dvb/teletext_descriptor.h
@@ -0,0 +1,127 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TELETEXT_DESCRIPTOR
+#define _UCSI_DVB_TELETEXT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * Possible values for the type field.
+ */
+enum {
+ DVB_TELETEXT_TYPE_INITIAL = 0x01,
+ DVB_TELETEXT_TYPE_SUBTITLE = 0x02,
+ DVB_TELETEXT_TYPE_ADDITIONAL = 0x03,
+ DVB_TELETEXT_TYPE_SCHEDULE = 0x04,
+ DVB_TELETEXT_TYPE_SUBTITLE_HEARING_IMPAIRED= 0x05,
+};
+
+/**
+ * dvb_teletext_descriptor structure.
+ */
+struct dvb_teletext_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_teletext_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the entries field of a dvb_teletext_descriptor.
+ */
+struct dvb_teletext_entry {
+ iso639lang_t language_code;
+ EBIT2(uint8_t type : 5; ,
+ uint8_t magazine_number: 3; );
+ uint8_t page_number;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_teletext_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return dvb_teletext_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_teletext_descriptor*
+ dvb_teletext_descriptor_codec(struct descriptor* d)
+{
+ if (d->len % sizeof(struct dvb_teletext_entry))
+ return NULL;
+
+ return (struct dvb_teletext_descriptor*) d;
+}
+
+/**
+ * Iterator for entries field of a dvb_teletext_descriptor.
+ *
+ * @param d dvb_teletext_descriptor pointer.
+ * @param pos Variable holding a pointer to the current dvb_teletext_entry.
+ */
+#define dvb_teletext_descriptor_entries_for_each(d, pos) \
+ for ((pos) = dvb_teletext_descriptor_entries_first(d); \
+ (pos); \
+ (pos) = dvb_teletext_descriptor_entries_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_teletext_entry*
+ dvb_teletext_descriptor_entries_first(struct dvb_teletext_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_teletext_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_teletext_descriptor));
+}
+
+static inline struct dvb_teletext_entry*
+ dvb_teletext_descriptor_entries_next(struct dvb_teletext_descriptor *d,
+ struct dvb_teletext_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_teletext_entry);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_teletext_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/terrestrial_delivery_descriptor.h b/lib/libucsi/dvb/terrestrial_delivery_descriptor.h
new file mode 100644
index 0000000..c624dab
--- /dev/null
+++ b/lib/libucsi/dvb/terrestrial_delivery_descriptor.h
@@ -0,0 +1,77 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TERRESTRIAL_DELIVERY_DESCRIPTOR
+#define _UCSI_DVB_TERRESTRIAL_DELIVERY_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_terrestrial_delivery_descriptor structure.
+ */
+struct dvb_terrestrial_delivery_descriptor {
+ struct descriptor d;
+
+ uint32_t centre_frequency; // Normal integer, units 10Hz
+ EBIT5(uint8_t bandwidth : 3; ,
+ uint8_t priority : 1; ,
+ uint8_t time_slicing_indicator : 1; ,
+ uint8_t mpe_fec_indicator : 1; ,
+ uint8_t reserved_1 : 2; );
+ EBIT3(uint8_t constellation : 2; ,
+ uint8_t hierarchy_information : 3; ,
+ uint8_t code_rate_hp_stream : 3; );
+ EBIT4(uint8_t code_rate_lp_stream : 3; ,
+ uint8_t guard_interval : 2; ,
+ uint8_t transmission_mode : 2; ,
+ uint8_t other_frequency_flag : 1; );
+ uint32_t reserved_2;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_terrestrial_delivery_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_terrestrial_delivery_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_terrestrial_delivery_descriptor*
+ dvb_terrestrial_delivery_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_terrestrial_delivery_descriptor) - 2))
+ return NULL;
+
+ bswap32((uint8_t*) d + 2);
+ bswap32((uint8_t*) d + 9);
+
+ return (struct dvb_terrestrial_delivery_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/time_shifted_event_descriptor.h b/lib/libucsi/dvb/time_shifted_event_descriptor.h
new file mode 100644
index 0000000..6b4a9f6
--- /dev/null
+++ b/lib/libucsi/dvb/time_shifted_event_descriptor.h
@@ -0,0 +1,65 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TIME_SHIFTED_EVENT_DESCRIPTOR
+#define _UCSI_DVB_TIME_SHIFTED_EVENT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_time_shifted_event_descriptor structure.
+ */
+struct dvb_time_shifted_event_descriptor {
+ struct descriptor d;
+
+ uint16_t reference_service_id;
+ uint16_t reference_event_id;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_time_shifted_event_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return dvb_time_shifted_event_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_time_shifted_event_descriptor*
+ dvb_time_shifted_event_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_time_shifted_event_descriptor) - 2))
+ return NULL;
+
+ bswap16((uint8_t*) d + 2);
+ bswap16((uint8_t*) d + 4);
+
+ return (struct dvb_time_shifted_event_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/time_shifted_service_descriptor.h b/lib/libucsi/dvb/time_shifted_service_descriptor.h
new file mode 100644
index 0000000..c8dcc0e
--- /dev/null
+++ b/lib/libucsi/dvb/time_shifted_service_descriptor.h
@@ -0,0 +1,63 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TIME_SHIFTED_SERVICE_DESCRIPTOR
+#define _UCSI_DVB_TIME_SHIFTED_SERVICE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_time_shifted_service_descriptor structure.
+ */
+struct dvb_time_shifted_service_descriptor {
+ struct descriptor d;
+
+ uint16_t reference_service_id;
+} __ucsi_packed;
+
+/**
+ * Process a dvb_time_shifted_service_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return Pointer to dvb_time_shifted_service_descriptor, or NULL on error.
+ */
+static inline struct dvb_time_shifted_service_descriptor*
+ dvb_time_shifted_service_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct dvb_time_shifted_service_descriptor) - 2))
+ return NULL;
+
+ bswap16((uint8_t*) d + 2);
+
+ return (struct dvb_time_shifted_service_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/tot_section.c b/lib/libucsi/dvb/tot_section.c
new file mode 100644
index 0000000..5dc7890
--- /dev/null
+++ b/lib/libucsi/dvb/tot_section.c
@@ -0,0 +1,50 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/tot_section.h>
+
+struct dvb_tot_section *dvb_tot_section_codec(struct section *section)
+{
+ uint8_t * buf = (uint8_t *)section;
+ size_t pos = sizeof(struct section);
+ size_t len = section_length(section) - CRC_SIZE;
+ struct dvb_tot_section * ret = (struct dvb_tot_section *)section;
+
+ if (len < sizeof(struct dvb_tot_section))
+ return NULL;
+
+ pos += 5;
+ bswap16(buf + pos);
+ pos += 2;
+
+ if ((pos + ret->descriptors_loop_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, ret->descriptors_loop_length))
+ return NULL;
+
+ pos += ret->descriptors_loop_length;
+
+ if (pos != len)
+ return NULL;
+
+ return ret;
+}
diff --git a/lib/libucsi/dvb/tot_section.h b/lib/libucsi/dvb/tot_section.h
new file mode 100644
index 0000000..3474da1
--- /dev/null
+++ b/lib/libucsi/dvb/tot_section.h
@@ -0,0 +1,97 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TOT_SECTION_H
+#define _UCSI_DVB_TOT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+#include <libucsi/dvb/types.h>
+
+/**
+ * dvb_tot_section structure.
+ */
+struct dvb_tot_section {
+ struct section head;
+
+ dvbdate_t utc_time;
+ EBIT2(uint16_t reserved : 4; ,
+ uint16_t descriptors_loop_length:12; );
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_tot_section.
+ *
+ * @param section Pointer to generic section structure.
+ * @return dvb_tot_section pointer, or NULL on error.
+ */
+struct dvb_tot_section * dvb_tot_section_codec(struct section *section);
+
+/**
+ * Iterator for descriptors field of dvb_tot_section.
+ *
+ * @param tot dvb_tot_section pointer.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define dvb_tot_section_descriptors_for_each(tot, pos) \
+ for ((pos) = dvb_tot_section_descriptors_first(tot); \
+ (pos); \
+ (pos) = dvb_tot_section_descriptors_next(tot, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ dvb_tot_section_descriptors_first(struct dvb_tot_section * tot)
+{
+ if (tot->descriptors_loop_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) tot + sizeof(struct dvb_tot_section));
+}
+
+static inline struct descriptor *
+ dvb_tot_section_descriptors_next(struct dvb_tot_section *tot,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t *) tot + sizeof(struct dvb_tot_section),
+ tot->descriptors_loop_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/transport_stream_descriptor.h b/lib/libucsi/dvb/transport_stream_descriptor.h
new file mode 100644
index 0000000..1797ec5
--- /dev/null
+++ b/lib/libucsi/dvb/transport_stream_descriptor.h
@@ -0,0 +1,82 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TRANSPORT_STREAM_DESCRIPTOR
+#define _UCSI_DVB_TRANSPORT_STREAM_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_transport_stream_descriptor structure.
+ */
+struct dvb_transport_stream_descriptor {
+ struct descriptor d;
+
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Process dvb_transport_stream_descriptor structure.
+ *
+ * @param d Pointer to generic descriptor.
+ * @return dvb_transport_stream_descriptor structure or NULL on error.
+ */
+static inline struct dvb_transport_stream_descriptor*
+ dvb_transport_stream_descriptor_codec(struct descriptor* d)
+{
+ return (struct dvb_transport_stream_descriptor*) d;
+}
+
+/**
+ * Retrieve a pointer to the data field of a dvb_transport_stream_descriptor.
+ *
+ * @param d dvb_transport_stream_descriptor structure.
+ * @return Pointer to data field.
+ */
+static inline uint8_t *
+ dvb_transport_stream_descriptor_data(struct dvb_transport_stream_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_transport_stream_descriptor);
+}
+
+/**
+ * Calculate the length of the data field of a dvb_transport_stream_descriptor.
+ *
+ * @param d dvb_transport_stream_descriptor structure.
+ * @return length of data field in bytes.
+ */
+static inline int
+ dvb_transport_stream_descriptor_data_length(struct dvb_transport_stream_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/tva_container_section.c b/lib/libucsi/dvb/tva_container_section.c
new file mode 100644
index 0000000..f526efc
--- /dev/null
+++ b/lib/libucsi/dvb/tva_container_section.c
@@ -0,0 +1,33 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/dvb/tva_container_section.h>
+
+struct dvb_tva_container_section *dvb_tva_container_section_codec(struct section_ext *ext)
+{
+ size_t len = section_ext_length(ext);
+ struct dvb_tva_container_section* ret = (struct dvb_tva_container_section*) ext;
+
+ if (len < sizeof(struct dvb_tva_container_section))
+ return NULL;
+
+ return ret;
+}
diff --git a/lib/libucsi/dvb/tva_container_section.h b/lib/libucsi/dvb/tva_container_section.h
new file mode 100644
index 0000000..7d0abb1
--- /dev/null
+++ b/lib/libucsi/dvb/tva_container_section.h
@@ -0,0 +1,90 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TVA_CONTAINER_SECTION_H
+#define _UCSI_DVB_TVA_CONTAINER_SECTION_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+#include <libucsi/dvb/types.h>
+
+/**
+ * dvb_tva_container_section structure.
+ */
+struct dvb_tva_container_section {
+ struct section_ext head;
+
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_tva_container_section.
+ *
+ * @param section Generic section header.
+ * @return dvb_tdt_section pointer, or NULL on error.
+ */
+struct dvb_tva_container_section *dvb_tva_container_section_codec(struct section_ext *ext);
+
+/**
+ * Accessor for the container_id field of a tva container section.
+ *
+ * @param container dvb_tva_container_section pointer.
+ * @return The container_id.
+ */
+static inline uint16_t dvb_tva_container_section_container_id(struct dvb_tva_container_section *container)
+{
+ return container->head.table_id_ext;
+}
+
+/**
+ * Accessor for the data field of a dvb_data_broadcast_id_descriptor.
+ *
+ * @param d dvb_data_broadcast_id_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+dvb_tva_container_section_data(struct dvb_tva_container_section *s)
+{
+ return (uint8_t *) s + sizeof(struct dvb_tva_container_section);
+}
+
+/**
+ * Determine the number of bytes in the data field of a dvb_tva_container_section.
+ *
+ * @param d dvb_tva_container_section pointer.
+ * @return Length of the field in bytes.
+ */
+static inline int
+dvb_tva_container_section_data_length(struct dvb_tva_container_section *s)
+{
+ return section_ext_length(&s->head) - sizeof(struct dvb_tva_container_section);
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/tva_id_descriptor.h b/lib/libucsi/dvb/tva_id_descriptor.h
new file mode 100644
index 0000000..3b4f3e8
--- /dev/null
+++ b/lib/libucsi/dvb/tva_id_descriptor.h
@@ -0,0 +1,124 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TVA_ID_DESCRIPTOR
+#define _UCSI_DVB_TVA_ID_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * dvb_tva_id_descriptor structure.
+ */
+struct dvb_tva_id_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_tva_id_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the entries field of a dvb_tva_id_descriptor.
+ */
+struct dvb_tva_id_entry {
+ uint16_t tva_id;
+ EBIT2(uint8_t reserved : 5; ,
+ uint8_t running_status : 3; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_tva_id_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return dvb_tva_id_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_tva_id_descriptor*
+ dvb_tva_id_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+ uint8_t* buf = (uint8_t*) d + 2;
+
+ pos += sizeof(struct dvb_tva_id_descriptor) - 2;
+ if (len % sizeof(struct dvb_tva_id_entry))
+ return NULL;
+
+ while(pos < len) {
+ bswap16(buf+pos);
+ pos+=3;
+ }
+
+ return (struct dvb_tva_id_descriptor*) d;
+}
+
+/**
+ * Iterator for the entries field of a dvb_tva_id_descriptor.
+ *
+ * @param d dvb_tva_id_descriptor pointer.
+ * @param pos Variable containing a pointer to the current dvb_tva_id_entry.
+ */
+#define dvb_tva_id_descriptor_entries_for_each(d, pos) \
+ for ((pos) = dvb_tva_id_descriptor_entries_first(d); \
+ (pos); \
+ (pos) = dvb_tva_id_descriptor_entries_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_tva_id_entry*
+ dvb_tva_id_descriptor_entries_first(struct dvb_tva_id_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_tva_id_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_tva_id_descriptor));
+}
+
+static inline struct dvb_tva_id_entry*
+ dvb_tva_id_descriptor_entries_next(struct dvb_tva_id_descriptor *d,
+ struct dvb_tva_id_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_tva_id_entry);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_tva_id_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/types.c b/lib/libucsi/dvb/types.c
new file mode 100644
index 0000000..c1cf583
--- /dev/null
+++ b/lib/libucsi/dvb/types.c
@@ -0,0 +1,270 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <string.h>
+#include "types.h"
+
+time_t dvbdate_to_unixtime(dvbdate_t dvbdate)
+{
+ int k = 0;
+ struct tm tm;
+ double mjd;
+
+ /* check for the undefined value */
+ if ((dvbdate[0] == 0xff) &&
+ (dvbdate[1] == 0xff) &&
+ (dvbdate[2] == 0xff) &&
+ (dvbdate[3] == 0xff) &&
+ (dvbdate[4] == 0xff)) {
+ return -1;
+ }
+
+ memset(&tm, 0, sizeof(tm));
+ mjd = (dvbdate[0] << 8) | dvbdate[1];
+
+ tm.tm_year = (int) ((mjd - 15078.2) / 365.25);
+ tm.tm_mon = (int) (((mjd - 14956.1) - (int) (tm.tm_year * 365.25)) / 30.6001);
+ tm.tm_mday = (int) mjd - 14956 - (int) (tm.tm_year * 365.25) - (int) (tm.tm_mon * 30.6001);
+ if ((tm.tm_mon == 14) || (tm.tm_mon == 15)) k = 1;
+ tm.tm_year += k;
+ tm.tm_mon = tm.tm_mon - 2 - k * 12;
+ tm.tm_sec = bcd_to_integer(dvbdate[4]);
+ tm.tm_min = bcd_to_integer(dvbdate[3]);
+ tm.tm_hour = bcd_to_integer(dvbdate[2]);
+
+ return mktime(&tm);
+}
+
+void unixtime_to_dvbdate(time_t unixtime, dvbdate_t dvbdate)
+{
+ struct tm tm;
+ double l = 0;
+ int mjd;
+
+ /* the undefined value */
+ if (unixtime == -1) {
+ memset(dvbdate, 0xff, 5);
+ return;
+ }
+
+ gmtime_r(&unixtime, &tm);
+ tm.tm_mon++;
+ if ((tm.tm_mon == 1) || (tm.tm_mon == 2)) l = 1;
+ mjd = 14956 + tm.tm_mday + (int) ((tm.tm_year - l) * 365.25) + (int) ((tm.tm_mon + 1 + l * 12) * 30.6001);
+
+ dvbdate[0] = (mjd & 0xff00) >> 8;
+ dvbdate[1] = mjd & 0xff;
+ dvbdate[2] = integer_to_bcd(tm.tm_hour);
+ dvbdate[3] = integer_to_bcd(tm.tm_min);
+ dvbdate[4] = integer_to_bcd(tm.tm_sec);
+}
+
+int dvbduration_to_seconds(dvbduration_t dvbduration)
+{
+ int seconds = 0;
+
+ seconds += (bcd_to_integer(dvbduration[0]) * 60 * 60);
+ seconds += (bcd_to_integer(dvbduration[1]) * 60);
+ seconds += bcd_to_integer(dvbduration[2]);
+
+ return seconds;
+}
+
+void seconds_to_dvbduration(int seconds, dvbduration_t dvbduration)
+{
+ int hours, mins;
+
+ hours = seconds / (60*60);
+ seconds -= (hours * 60 * 60);
+ mins = seconds / 60;
+ seconds -= (mins * 60);
+
+ dvbduration[0] = integer_to_bcd(hours);
+ dvbduration[1] = integer_to_bcd(mins);
+ dvbduration[2] = integer_to_bcd(seconds);
+}
+
+int dvbhhmm_to_seconds(dvbhhmm_t dvbhhmm)
+{
+ int seconds = 0;
+
+ seconds += (bcd_to_integer(dvbhhmm[0]) * 60 * 60);
+ seconds += (bcd_to_integer(dvbhhmm[1]) * 60);
+
+ return seconds;
+}
+
+void seconds_to_dvbhhmm(int seconds, dvbhhmm_t dvbhhmm)
+{
+ int hours, mins;
+
+ hours = seconds / (60*60);
+ seconds -= (hours * 60 * 60);
+ mins = seconds / 60;
+
+ dvbhhmm[0] = integer_to_bcd(hours);
+ dvbhhmm[1] = integer_to_bcd(mins);
+}
+
+uint32_t integer_to_bcd(uint32_t intval)
+{
+ uint32_t val = 0;
+
+ int i;
+ for(i=0; i<=28;i+=4) {
+ val |= ((intval % 10) << i);
+ intval /= 10;
+ }
+
+ return val;
+}
+
+uint32_t bcd_to_integer(uint32_t bcdval)
+{
+ uint32_t val = 0;
+
+ int i;
+ for(i=28; i>=0;i-=4) {
+ val += ((bcdval >> i) & 0x0f);
+ if (i != 0) val *= 10;
+ }
+
+ return val;
+}
+
+const char *dvb_charset(char *dvb_text, int dvb_text_length, int *consumed)
+{
+ char *charset = "ISO6937";
+ int used = 0;
+
+ if (dvb_text_length == 0)
+ goto exit;
+ if (dvb_text[0] >= 32)
+ goto exit;
+ if (dvb_text[0] == 0x10) {
+ if (dvb_text_length < 3)
+ goto exit;
+
+ used = 3;
+ uint16_t ext = (dvb_text[1] << 8) | dvb_text[2];
+ switch(ext) {
+ case 0x01:
+ charset = "ISO8859-1";
+ break;
+ case 0x02:
+ charset = "ISO8859-2";
+ break;
+ case 0x03:
+ charset = "ISO8859-3";
+ break;
+ case 0x04:
+ charset = "ISO8859-4";
+ break;
+ case 0x05:
+ charset = "ISO8859-5";
+ break;
+ case 0x06:
+ charset = "ISO8859-6";
+ break;
+ case 0x07:
+ charset = "ISO8859-7";
+ break;
+ case 0x08:
+ charset = "ISO8859-8";
+ break;
+ case 0x09:
+ charset = "ISO8859-9";
+ break;
+ case 0x0a:
+ charset = "ISO8859-10";
+ break;
+ case 0x0b:
+ charset = "ISO8859-11";
+ break;
+ case 0x0d:
+ charset = "ISO8859-13";
+ break;
+ case 0x0e:
+ charset = "ISO8859-14";
+ break;
+ case 0x0f:
+ charset = "ISO8859-15";
+ break;
+ default:
+ used = 0;
+ break;
+ }
+ } else {
+ used = 1;
+ switch(dvb_text[0]) {
+ case 0x01:
+ charset = "ISO8859-5";
+ break;
+ case 0x02:
+ charset = "ISO8859-6";
+ break;
+ case 0x03:
+ charset = "ISO8859-7";
+ break;
+ case 0x04:
+ charset = "ISO8859-8";
+ break;
+ case 0x05:
+ charset = "ISO8859-9";
+ break;
+ case 0x06:
+ charset = "ISO8859-10";
+ break;
+ case 0x07:
+ charset = "ISO8859-11";
+ break;
+ case 0x09:
+ charset = "ISO8859-13";
+ break;
+ case 0x0a:
+ charset = "ISO8859-14";
+ break;
+ case 0x0b:
+ charset = "ISO8859-15";
+ break;
+ case 0x11:
+ charset = "UTF16";
+ break;
+ case 0x12:
+ charset = "EUC-KR";
+ break;
+ case 0x13:
+ charset = "GB2312";
+ break;
+ case 0x14:
+ charset = "GBK";
+ break;
+ case 0x15:
+ charset = "UTF8";
+ break;
+ default:
+ used = 0;
+ break;
+ }
+ }
+exit:
+ *consumed = used;
+ return charset;
+}
diff --git a/lib/libucsi/dvb/types.h b/lib/libucsi/dvb/types.h
new file mode 100644
index 0000000..437c7c3
--- /dev/null
+++ b/lib/libucsi/dvb/types.h
@@ -0,0 +1,127 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_TYPES_H
+#define _UCSI_DVB_TYPES_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+#include <time.h>
+
+typedef uint8_t dvbdate_t[5];
+typedef uint8_t dvbduration_t[3];
+typedef uint8_t dvbhhmm_t[2];
+
+/**
+ * Running status values.
+ */
+enum {
+ DVB_RUNNING_STATUS_NOT_RUNNING = 0x01,
+ DVB_RUNNING_STATUS_FEW_SECONDS = 0x02,
+ DVB_RUNNING_STATUS_PAUSING = 0x03,
+ DVB_RUNNING_STATUS_RUNNING = 0x04,
+};
+
+/**
+ * Convert from a 5 byte DVB UTC date to unix time.
+ * Note: this functions expects the DVB date in network byte order.
+ *
+ * @param d Pointer to DVB date.
+ * @return The unix timestamp, or -1 if the dvbdate was set to the 'undefined' value
+ */
+extern time_t dvbdate_to_unixtime(dvbdate_t dvbdate);
+
+/**
+ * Convert from a unix timestemp to a 5 byte DVB UTC date.
+ * Note: this function will always output the DVB date in
+ * network byte order.
+ *
+ * @param unixtime The unix timestamp, or -1 for the 'undefined' value.
+ * @param utc Pointer to 5 byte DVB date.
+ */
+extern void unixtime_to_dvbdate(time_t unixtime, dvbdate_t dvbdate);
+
+/**
+ * Convert from a DVB BCD duration to a number of seconds.
+ *
+ * @param dvbduration Pointer to 3 byte DVB duration.
+ * @return Number of seconds.
+ */
+extern int dvbduration_to_seconds(dvbduration_t dvbduration);
+
+/**
+ * Convert from a number of seconds to a DVB 3 byte BCD duration.
+ *
+ * @param seconds The number of seconds.
+ * @param dvbduration Pointer to 3 byte DVB duration.
+ */
+extern void seconds_to_dvbduration(int seconds, dvbduration_t dvbduration);
+
+/**
+ * Convert from a DVB BCD HHMM to a number of seconds.
+ *
+ * @param dvbduration Pointer to 2 byte DVB HHMM.
+ * @return Number of seconds.
+ */
+extern int dvbhhmm_to_seconds(dvbhhmm_t dvbhhmm);
+
+/**
+ * Convert from a number of seconds to a DVB 2 byte BCD HHMM.
+ *
+ * @param seconds The number of seconds.
+ * @param dvbduration Pointer to 2 byte DVB HHMM.
+ */
+extern void seconds_to_dvbhhmm(int seconds, dvbhhmm_t dvbhhmm);
+
+/**
+ * Convert a __ucsi_packed BCD value into a normal integer.
+ *
+ * @param bcd The value to convert.
+ * @return The value.
+ */
+extern uint32_t bcd_to_integer(uint32_t bcd);
+
+/**
+ * Convert a normal integer into a __ucsi_packed BCD value.
+ *
+ * @param integer The value to convert.
+ * @return The value.
+ */
+extern uint32_t integer_to_bcd(uint32_t integer);
+
+/**
+ * Determine the (iconv compatable) character set of a dvb string.
+ *
+ * @param dvb_text DVB text concerned.
+ * @param dvb_text_length Length of text.
+ * @param consumed Out parameter of number of bytes used to encode the character set.
+ * @return Name of the character set.
+ */
+extern const char *dvb_charset(char *dvb_text, int dvb_text_length, int *consumed);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/vbi_data_descriptor.h b/lib/libucsi/dvb/vbi_data_descriptor.h
new file mode 100644
index 0000000..b1d8703
--- /dev/null
+++ b/lib/libucsi/dvb/vbi_data_descriptor.h
@@ -0,0 +1,186 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_VBI_DATA_DESCRIPTOR
+#define _UCSI_DVB_VBI_DATA_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Possible values for the data_service_id field.
+ */
+enum {
+ DVB_VBI_DATA_SERVICE_ID_EBU = 0x01,
+ DVB_VBI_DATA_SERVICE_ID_INVERTED = 0x02,
+ DVB_VBI_DATA_SERVICE_ID_VPS = 0x04,
+ DVB_VBI_DATA_SERVICE_ID_WSS = 0x05,
+ DVB_VBI_DATA_SERVICE_ID_CC = 0x06,
+ DVB_VBI_DATA_SERVICE_ID_MONO_422 = 0x07,
+};
+
+/**
+ * dvb_vbi_data_descriptor structure
+ */
+struct dvb_vbi_data_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_vbi_data_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the dvb_vbi_data_descriptor entries field.
+ */
+struct dvb_vbi_data_entry {
+ uint8_t data_service_id;
+ uint8_t data_length;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Format of the dvb_vbi_data_entry data field, if data_service_id == 1,2,4,5,6,7.
+ */
+struct dvb_vbi_data_x {
+ EBIT3(uint8_t reserved : 2; ,
+ uint8_t field_parity : 1; ,
+ uint8_t line_offset : 5; );
+} __ucsi_packed;
+
+/**
+ * Process a dvb_vbi_data_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return dvb_vbi_data_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_vbi_data_descriptor*
+ dvb_vbi_data_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* p = (uint8_t*) d + 2;
+ uint32_t pos = 0;
+ uint32_t len = d->len;
+
+ while(pos < len) {
+ struct dvb_vbi_data_entry *e =
+ (struct dvb_vbi_data_entry*) (p+pos);
+
+ pos += sizeof(struct dvb_vbi_data_entry);
+
+ if (pos > len)
+ return NULL;
+
+ pos += e->data_length;
+
+ if (pos > len)
+ return NULL;
+ }
+
+ return (struct dvb_vbi_data_descriptor*) d;
+}
+
+/**
+ * Iterator for entries field in a dvb_vbi_data_descriptor structure.
+ *
+ * @param d Pointer to dvb_vbi_data_descriptor structure.
+ * @param pos Variable holding pointer to the current dvb_vbi_data_entry structure.
+ */
+#define dvb_vbi_data_descriptor_entries_for_each(d, pos) \
+ for ((pos) = dvb_vbi_data_descriptor_entries_first(d); \
+ (pos); \
+ (pos) = dvb_vbi_data_descriptor_entries_next(d, pos))
+
+/**
+ * Get a pointer to the data field of a dvb_vbi_data_entry.
+ *
+ * @param d dvb_vbi_data_entry structure.
+ * @return Pointer to the data field.
+ */
+static inline uint8_t *
+ dvb_vbi_data_entry_data(struct dvb_vbi_data_entry *d)
+{
+ return (uint8_t *) d + sizeof(struct dvb_vbi_data_entry);
+}
+
+/**
+ * Get a pointer to the data field of a dvb_vbi_data_x for id 1,2,4,5,6,7.
+ *
+ * @param d dvb_vbi_data_entry structure.
+ * @return Pointer to the data field, or NULL if invalid
+ */
+static inline struct dvb_vbi_data_x*
+ dvb_vbi_data_entry_data_x(struct dvb_vbi_data_entry *d)
+{
+ switch(d->data_service_id) {
+ case 1:
+ case 2:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ return (struct dvb_vbi_data_x*) ((uint8_t *) d + sizeof(struct dvb_vbi_data_entry));
+ }
+
+ return NULL;
+}
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_vbi_data_entry*
+ dvb_vbi_data_descriptor_entries_first(struct dvb_vbi_data_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_vbi_data_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_vbi_data_descriptor));
+}
+
+static inline struct dvb_vbi_data_entry*
+ dvb_vbi_data_descriptor_entries_next(struct dvb_vbi_data_descriptor *d,
+ struct dvb_vbi_data_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_vbi_data_entry) +
+ pos->data_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_vbi_data_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/dvb/vbi_teletext_descriptor.h b/lib/libucsi/dvb/vbi_teletext_descriptor.h
new file mode 100644
index 0000000..fd779d7
--- /dev/null
+++ b/lib/libucsi/dvb/vbi_teletext_descriptor.h
@@ -0,0 +1,116 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_DVB_VBI_TELETEXT_DESCRIPTOR
+#define _UCSI_DVB_VBI_TELETEXT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * dvb_vbi_teletext_descriptor structure
+ */
+struct dvb_vbi_teletext_descriptor {
+ struct descriptor d;
+
+ /* struct dvb_vbi_teletext_entry entries[] */
+} __ucsi_packed;
+
+/**
+ * An entry in a dvb_vbi_teletext_descriptor structure.
+ */
+struct dvb_vbi_teletext_entry {
+ iso639lang_t language_code;
+ EBIT2(uint8_t type : 5; ,
+ uint8_t magazine_number: 3; );
+ uint8_t page_number;
+} __ucsi_packed;
+
+/**
+ * Process an dvb_vbi_teletext_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return dvb_vbi_teletext_descriptor pointer, or NULL on error.
+ */
+static inline struct dvb_vbi_teletext_descriptor*
+ dvb_vbi_teletext_descriptor_codec(struct descriptor* d)
+{
+ if (d->len % sizeof(struct dvb_vbi_teletext_entry))
+ return NULL;
+
+ return (struct dvb_vbi_teletext_descriptor*) d;
+}
+
+/**
+ * Iterator for entries field of a dvb_vbi_teletext_descriptor.
+ *
+ * @param d Pointer to dvb_vbi_teletext_descriptor.
+ * @param pos Variable holding a pointer to the current dvb_vbi_teletext_entry.
+ */
+#define dvb_vbi_teletext_descriptor_entries_for_each(d, pos) \
+ for ((pos) = dvb_vbi_teletext_descriptor_entries_first(d); \
+ (pos); \
+ (pos) = dvb_vbi_teletext_descriptor_entries_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct dvb_vbi_teletext_entry*
+ dvb_vbi_teletext_descriptor_entries_first(struct dvb_vbi_teletext_descriptor *d)
+{
+ if (d->d.len == 0)
+ return NULL;
+
+ return (struct dvb_vbi_teletext_entry *)
+ ((uint8_t*) d + sizeof(struct dvb_vbi_teletext_descriptor));
+}
+
+static inline struct dvb_vbi_teletext_entry*
+ dvb_vbi_teletext_descriptor_entries_next(struct dvb_vbi_teletext_descriptor *d,
+ struct dvb_vbi_teletext_entry *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_vbi_teletext_entry);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct dvb_vbi_teletext_entry *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/endianops.h b/lib/libucsi/endianops.h
new file mode 100644
index 0000000..23b418b
--- /dev/null
+++ b/lib/libucsi/endianops.h
@@ -0,0 +1,128 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_COMMON_H
+#define _UCSI_COMMON_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+#include <byteswap.h>
+#include <endian.h>
+
+#define __ucsi_packed __attribute__((packed))
+
+
+
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define EBIT2(x1,x2) x1 x2
+#define EBIT3(x1,x2,x3) x1 x2 x3
+#define EBIT4(x1,x2,x3,x4) x1 x2 x3 x4
+#define EBIT5(x1,x2,x3,x4,x5) x1 x2 x3 x4 x5
+#define EBIT6(x1,x2,x3,x4,x5,x6) x1 x2 x3 x4 x5 x6
+#define EBIT7(x1,x2,x3,x4,x5,x6,x7) x1 x2 x3 x4 x5 x6 x7
+#define EBIT8(x1,x2,x3,x4,x5,x6,x7,x8) x1 x2 x3 x4 x5 x6 x7 x8
+
+static inline void bswap16(uint8_t *buf) {
+ (void) buf;
+}
+
+static inline void bswap32(uint8_t *buf) {
+ (void) buf;
+}
+
+static inline void bswap64(uint8_t *buf) {
+ (void) buf;
+}
+
+static inline void bswap24(uint8_t *buf) {
+ (void) buf;
+}
+
+static inline void bswap40(uint8_t *buf) {
+ (void) buf;
+}
+
+static inline void bswap48(uint8_t *buf) {
+ (void) buf;
+}
+
+#else
+#define EBIT2(x1,x2) x2 x1
+#define EBIT3(x1,x2,x3) x3 x2 x1
+#define EBIT4(x1,x2,x3,x4) x4 x3 x2 x1
+#define EBIT5(x1,x2,x3,x4,x5) x5 x4 x3 x2 x1
+#define EBIT6(x1,x2,x3,x4,x5,x6) x6 x5 x4 x3 x2 x1
+#define EBIT7(x1,x2,x3,x4,x5,x6,x7) x7 x6 x5 x4 x3 x2 x1
+#define EBIT8(x1,x2,x3,x4,x5,x6,x7,x8) x8 x7 x6 x5 x4 x3 x2 x1
+
+static inline void bswap16(uint8_t * buf) {
+ *((uint16_t*)buf) = bswap_16((*(uint16_t*)buf));
+}
+
+static inline void bswap32(uint8_t * buf) {
+ *((uint32_t*)buf) = bswap_32((*(uint32_t*)buf));
+}
+
+static inline void bswap64(uint8_t * buf) {
+ *((uint64_t*)buf) = bswap_64((*(uint64_t*)buf));
+}
+
+static inline void bswap24(uint8_t * buf) {
+ uint8_t tmp0 = buf[0];
+
+ buf[0] = buf[2];
+ buf[2] = tmp0;
+}
+
+static inline void bswap40(uint8_t * buf) {
+ uint8_t tmp0 = buf[0];
+ uint8_t tmp1 = buf[1];
+
+ buf[0] = buf[4];
+ buf[1] = buf[3];
+ buf[3] = tmp1;
+ buf[4] = tmp0;
+}
+
+static inline void bswap48(uint8_t * buf) {
+ uint8_t tmp0 = buf[0];
+ uint8_t tmp1 = buf[1];
+ uint8_t tmp2 = buf[2];
+
+ buf[0] = buf[5];
+ buf[1] = buf[4];
+ buf[2] = buf[3];
+ buf[3] = tmp2;
+ buf[4] = tmp1;
+ buf[5] = tmp0;
+}
+
+#endif // __BYTE_ORDER
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/Makefile b/lib/libucsi/mpeg/Makefile
new file mode 100644
index 0000000..ace8808
--- /dev/null
+++ b/lib/libucsi/mpeg/Makefile
@@ -0,0 +1,65 @@
+# Makefile for linuxtv.org dvb-apps/lib/libucsi/mpeg
+
+.PHONY: sub-error-mpeg
+
+sub-error-mpeg:
+ $(error You can't use this makefile directly.)
+
+ifneq ($(lib_name),)
+
+objects += mpeg/cat_section.o \
+ mpeg/metadata_section.o \
+ mpeg/odsmt_section.o \
+ mpeg/pat_section.o \
+ mpeg/pmt_section.o \
+ mpeg/tsdt_section.o
+
+sub-install += mpeg
+
+else
+
+includes = audio_stream_descriptor.h \
+ ca_descriptor.h \
+ cat_section.h \
+ content_labelling_descriptor.h \
+ copyright_descriptor.h \
+ data_stream_alignment_descriptor.h \
+ descriptor.h \
+ external_es_id_descriptor.h \
+ fmc_descriptor.h \
+ fmxbuffer_size_descriptor.h \
+ hierarchy_descriptor.h \
+ ibp_descriptor.h \
+ iod_descriptor.h \
+ iso_639_language_descriptor.h \
+ maximum_bitrate_descriptor.h \
+ metadata_descriptor.h \
+ metadata_pointer_descriptor.h \
+ metadata_section.h \
+ metadata_std_descriptor.h \
+ mpeg4_audio_descriptor.h \
+ mpeg4_video_descriptor.h \
+ multiplex_buffer_descriptor.h \
+ multiplex_buffer_utilization_descriptor.h \
+ muxcode_descriptor.h \
+ odsmt_section.h \
+ pat_section.h \
+ pmt_section.h \
+ private_data_indicator_descriptor.h \
+ registration_descriptor.h \
+ section.h \
+ sl_descriptor.h \
+ smoothing_buffer_descriptor.h \
+ std_descriptor.h \
+ system_clock_descriptor.h \
+ target_background_grid_descriptor.h \
+ tsdt_section.h \
+ types.h \
+ video_stream_descriptor.h \
+ video_window_descriptor.h
+
+include ../../../Make.rules
+
+lib_name = libucsi/mpeg
+
+endif
diff --git a/lib/libucsi/mpeg/audio_stream_descriptor.h b/lib/libucsi/mpeg/audio_stream_descriptor.h
new file mode 100644
index 0000000..7e6ea07
--- /dev/null
+++ b/lib/libucsi/mpeg/audio_stream_descriptor.h
@@ -0,0 +1,65 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_AUDIO_STREAM_DESCRIPTOR
+#define _UCSI_MPEG_AUDIO_STREAM_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_audio_stream_descriptor structure
+ */
+struct mpeg_audio_stream_descriptor {
+ struct descriptor d;
+
+ EBIT5(uint8_t free_format_flag : 1; ,
+ uint8_t id : 1; ,
+ uint8_t layer : 2; ,
+ uint8_t variable_rate_audio_indicator : 1; ,
+ uint8_t reserved : 3; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_audio_stream_descriptor.
+ *
+ * @param d Pointer to the generic descriptor structure.
+ * @return Pointer to the mpeg_audio_stream_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_audio_stream_descriptor*
+ mpeg_audio_stream_descriptor_codec(struct descriptor *d)
+{
+ if (d->len != (sizeof(struct mpeg_audio_stream_descriptor) - 2))
+ return NULL;
+
+ return (struct mpeg_audio_stream_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/ca_descriptor.h b/lib/libucsi/mpeg/ca_descriptor.h
new file mode 100644
index 0000000..88a65dd
--- /dev/null
+++ b/lib/libucsi/mpeg/ca_descriptor.h
@@ -0,0 +1,91 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_CA_DESCRIPTOR
+#define _UCSI_MPEG_CA_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_ca_descriptor structure
+ */
+struct mpeg_ca_descriptor {
+ struct descriptor d;
+
+ uint16_t ca_system_id;
+ EBIT2(uint16_t reserved : 3; ,
+ uint16_t ca_pid : 13; );
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_ca_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return Pointer to an mpeg_ca_descriptor, or NULL on error.
+ */
+static inline struct mpeg_ca_descriptor*
+ mpeg_ca_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct mpeg_ca_descriptor) - 2))
+ return NULL;
+
+ bswap16((uint8_t*) d + 2);
+ bswap16((uint8_t*) d + 4);
+
+ return (struct mpeg_ca_descriptor*) d;
+}
+
+/**
+ * Accessor for pointer to data field of an mpeg_ca_descriptor.
+ *
+ * @param d The mpeg_ca_descriptor structure.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ mpeg_ca_descriptor_data(struct mpeg_ca_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct mpeg_ca_descriptor);
+}
+
+/**
+ * Determine length of data field of an mpeg_ca_descriptor.
+ *
+ * @param d The mpeg_ca_descriptor structure.
+ * @return Length of the field in bytes.
+ */
+static inline int
+ mpeg_ca_descriptor_data_length(struct mpeg_ca_descriptor *d)
+{
+ return d->d.len - 4;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/cat_section.c b/lib/libucsi/mpeg/cat_section.c
new file mode 100644
index 0000000..8c974b8
--- /dev/null
+++ b/lib/libucsi/mpeg/cat_section.c
@@ -0,0 +1,34 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/mpeg/cat_section.h>
+
+struct mpeg_cat_section * mpeg_cat_section_codec(struct section_ext * ext)
+{
+ uint8_t * buf = (uint8_t *)ext;
+ size_t pos = sizeof(struct section_ext);
+
+ if (verify_descriptors(buf + pos,
+ section_ext_length(ext) - sizeof(struct mpeg_cat_section)))
+ return NULL;
+
+ return (struct mpeg_cat_section *)ext;
+}
diff --git a/lib/libucsi/mpeg/cat_section.h b/lib/libucsi/mpeg/cat_section.h
new file mode 100644
index 0000000..7ed34a3
--- /dev/null
+++ b/lib/libucsi/mpeg/cat_section.h
@@ -0,0 +1,94 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_CAT_SECTION_H
+#define _UCSI_MPEG_CAT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * mpeg_cat_section structure.
+ */
+struct mpeg_cat_section {
+ struct section_ext head;
+
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_cat_section.
+ *
+ * @param section The generic section_ext structure.
+ * @return Pointer to an mpeg_cat_section structure, or NULL on error.
+ */
+extern struct mpeg_cat_section *mpeg_cat_section_codec(struct section_ext *section);
+
+/**
+ * Convenience iterator for descriptors field of an mpeg_cat_section.
+ *
+ * @param cat The mpeg_cat_section pointer.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define mpeg_cat_section_descriptors_for_each(cat, pos) \
+ for ((pos) = mpeg_cat_section_descriptors_first(cat); \
+ (pos); \
+ (pos) = mpeg_cat_section_descriptors_next(cat, pos))
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ mpeg_cat_section_descriptors_first(struct mpeg_cat_section *cat)
+{
+ size_t pos = sizeof(struct mpeg_cat_section);
+
+ if (pos >= section_ext_length(&cat->head))
+ return NULL;
+
+ return (struct descriptor*)((uint8_t *) cat + pos);
+}
+
+
+static inline struct descriptor *
+ mpeg_cat_section_descriptors_next(struct mpeg_cat_section *cat,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t *) cat + sizeof(struct mpeg_cat_section),
+ section_ext_length(&cat->head) - sizeof(struct mpeg_cat_section),
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/content_labelling_descriptor.h b/lib/libucsi/mpeg/content_labelling_descriptor.h
new file mode 100644
index 0000000..06738ab
--- /dev/null
+++ b/lib/libucsi/mpeg/content_labelling_descriptor.h
@@ -0,0 +1,356 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_CONTENT_LABELLING_DESCRIPTOR
+#define _UCSI_MPEG_CONTENT_LABELLING_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Possible values for content_time_base_indicator.
+ */
+enum {
+ MPEG_CONTENT_TIME_BASE_STC = 0x01,
+ MPEG_CONTENT_TIME_BASE_NPT = 0x02,
+};
+
+/**
+ * mpeg_content_labelling_descriptor structure.
+ */
+struct mpeg_content_labelling_descriptor {
+ struct descriptor d;
+
+ uint16_t metadata_application_format;
+ /* struct mpeg_content_labelling_descriptor_application_format_identifier id */
+ /* struct mpeg_content_labelling_descriptor_flags flags */
+ /* struct mpeg_content_labelling_descriptor_reference_id reference_id */
+ /* struct mpeg_content_labelling_descriptor_time_base time_base */
+ /* struct mpeg_content_labelling_descriptor_content_id content_id */
+ /* struct mpeg_content_labelling_descriptor_time_base_association time_base_assoc */
+ /* uint8_t private_data[] */
+} __ucsi_packed;
+
+/**
+ * id field of a content_labelling_descriptor.
+ */
+struct mpeg_content_labelling_descriptor_application_format_identifier {
+ uint32_t id;
+} __ucsi_packed;
+
+/**
+ * Flags field of a content_labelling_descriptor
+ */
+struct mpeg_content_labelling_descriptor_flags {
+ EBIT3(uint8_t content_reference_id_record_flag : 1; ,
+ uint8_t content_time_base_indicator : 4; ,
+ uint8_t reserved : 3; );
+} __ucsi_packed;
+
+/**
+ * Reference_id field of a content_labelling_descriptor.
+ */
+struct mpeg_content_labelling_descriptor_reference_id {
+ uint8_t content_reference_id_record_length;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * time_base field of a content_labelling_descriptor.
+ */
+struct mpeg_content_labelling_descriptor_time_base {
+ EBIT2(uint64_t reserved_1 : 7; ,
+ uint64_t content_time_base_value :33; );
+ EBIT2(uint64_t reserved_2 : 7; ,
+ uint64_t metadata_time_base_value :33; );
+} __ucsi_packed;
+
+/**
+ * content_id field of a content_labelling_descriptor.
+ */
+struct mpeg_content_labelling_descriptor_content_id {
+ EBIT2(uint8_t reserved : 1; ,
+ uint8_t contentId : 7; );
+} __ucsi_packed;
+
+/**
+ * time_base_assoc field of a content_labelling_descriptor.
+ */
+struct mpeg_content_labelling_descriptor_time_base_association {
+ uint8_t time_base_association_data_length;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+
+
+/**
+ * Process an mpeg_content_labelling_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return Pointer to an mpeg_content_labelling_descriptor, or NULL on error.
+ */
+static inline struct mpeg_content_labelling_descriptor*
+ mpeg_content_labelling_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 2;
+ uint8_t *buf = (uint8_t*) d;
+ uint32_t len = d->len + 2;
+ struct mpeg_content_labelling_descriptor_flags *flags;
+ int id;
+
+ if (len < sizeof(struct mpeg_content_labelling_descriptor))
+ return NULL;
+
+ bswap16(buf + pos);
+ id = *((uint16_t*) (buf+pos));
+ pos += 2;
+
+ if (id == 0xffff) {
+ if (len < (pos+4))
+ return NULL;
+ bswap32(buf+pos);
+ pos += 4;
+ }
+
+ if (len < (pos + sizeof(struct mpeg_content_labelling_descriptor_flags)))
+ return NULL;
+ flags = (struct mpeg_content_labelling_descriptor_flags*) (buf+pos);
+ pos += sizeof(struct mpeg_content_labelling_descriptor_flags);
+
+ if (flags->content_reference_id_record_flag == 1) {
+ if (len < (pos+1))
+ return NULL;
+ if (len < (pos+1+buf[pos]))
+ return NULL;
+ pos += 1 + buf[pos];
+ }
+
+ if ((flags->content_time_base_indicator == 1) ||
+ (flags->content_time_base_indicator == 2)) {
+ if (len < (pos + sizeof(struct mpeg_content_labelling_descriptor_time_base)))
+ return NULL;
+ bswap40(buf+pos);
+ bswap40(buf+pos+5);
+ pos += sizeof(struct mpeg_content_labelling_descriptor_time_base);
+ }
+
+ if (flags->content_time_base_indicator == 2) {
+ if (len < (pos + sizeof(struct mpeg_content_labelling_descriptor_content_id)))
+ return NULL;
+ pos += sizeof(struct mpeg_content_labelling_descriptor_content_id);
+ }
+
+ if (flags->content_time_base_indicator > 2) {
+ if (len < (pos+1))
+ return NULL;
+ if (len < (pos+1+buf[pos]))
+ return NULL;
+ pos += 1 + buf[pos];
+ }
+
+ if (len < pos)
+ return NULL;
+
+ return (struct mpeg_content_labelling_descriptor*) d;
+}
+
+/**
+ * Accessor for pointer to id field of an mpeg_content_labelling_descriptor.
+ *
+ * @param d The mpeg_content_labelling_descriptor structure.
+ * @return The pointer, or NULL on error.
+ */
+static inline struct mpeg_content_labelling_descriptor_application_format_identifier*
+ mpeg_content_labelling_descriptor_id(struct mpeg_content_labelling_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d;
+
+ if (d->metadata_application_format != 0xffff)
+ return NULL;
+ return (struct mpeg_content_labelling_descriptor_application_format_identifier*)
+ (buf + sizeof(struct mpeg_content_labelling_descriptor));
+}
+
+/**
+ * Accessor for pointer to flags field of an mpeg_content_labelling_descriptor.
+ *
+ * @param d The mpeg_content_labelling_descriptor structure.
+ * @return The pointer, or NULL on error.
+ */
+static inline struct mpeg_content_labelling_descriptor_flags*
+ mpeg_content_labelling_descriptor_flags(struct mpeg_content_labelling_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d + sizeof(struct mpeg_content_labelling_descriptor);
+
+ if (d->metadata_application_format != 0xffff)
+ buf += 4;
+
+ return (struct mpeg_content_labelling_descriptor_flags *) buf;
+}
+
+/**
+ * Accessor for reference_id field of an mpeg_content_labelling_descriptor.
+ *
+ * @param flags Pointer to the mpeg_content_labelling_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_content_labelling_descriptor_reference_id*
+ mpeg_content_labelling_descriptor_reference_id(struct mpeg_content_labelling_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_content_labelling_descriptor_flags);
+
+ if (flags->content_reference_id_record_flag != 1)
+ return NULL;
+
+ return (struct mpeg_content_labelling_descriptor_reference_id *) buf;
+}
+
+/**
+ * Accessor for data field of an mpeg_content_reference_id.
+ *
+ * @param d The mpeg_content_reference_id structure.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_content_reference_id_data(struct mpeg_content_labelling_descriptor_reference_id *d)
+{
+ return (uint8_t*) d + sizeof(struct mpeg_content_labelling_descriptor_reference_id);
+}
+
+/**
+ * Accessor for time_base field of an mpeg_content_labelling_descriptor.
+ *
+ * @param flags Pointer to the mpeg_content_labelling_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_content_labelling_descriptor_time_base*
+ mpeg_content_labelling_descriptor_time_base(struct mpeg_content_labelling_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_content_labelling_descriptor_flags);
+
+ if ((flags->content_time_base_indicator!=1) && (flags->content_time_base_indicator!=2))
+ return NULL;
+
+ if (flags->content_reference_id_record_flag == 1)
+ buf += 1 + buf[1];
+
+ return (struct mpeg_content_labelling_descriptor_time_base *) buf;
+}
+
+/**
+ * Accessor for content_id field of an mpeg_content_labelling_descriptor.
+ *
+ * @param flags Pointer to the mpeg_content_labelling_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_content_labelling_descriptor_content_id*
+ mpeg_content_labelling_descriptor_content_id(struct mpeg_content_labelling_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_content_labelling_descriptor_flags);
+
+ if (flags->content_time_base_indicator!=2)
+ return NULL;
+
+ if (flags->content_reference_id_record_flag == 1)
+ buf += 1 + buf[1];
+ if ((flags->content_time_base_indicator==1) || (flags->content_time_base_indicator==2))
+ buf += sizeof(struct mpeg_content_labelling_descriptor_time_base);
+
+ return (struct mpeg_content_labelling_descriptor_content_id *) buf;
+}
+
+/**
+ * Accessor for time_base_association field of an mpeg_content_labelling_descriptor.
+ *
+ * @param flags Pointer to the mpeg_content_labelling_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_content_labelling_descriptor_time_base_association*
+ mpeg_content_labelling_descriptor_time_base_assoc(struct mpeg_content_labelling_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_content_labelling_descriptor_flags);
+
+ if (flags->content_time_base_indicator<3)
+ return NULL;
+
+ if (flags->content_reference_id_record_flag == 1)
+ buf += 1 + buf[1];
+ if ((flags->content_time_base_indicator==1) || (flags->content_time_base_indicator==2))
+ buf += sizeof(struct mpeg_content_labelling_descriptor_time_base);
+ if (flags->content_time_base_indicator==2)
+ buf += sizeof(struct mpeg_content_labelling_descriptor_content_id);
+
+ return (struct mpeg_content_labelling_descriptor_time_base_association *) buf;
+}
+
+/**
+ * Accessor for data field of an mpeg_time_base_association.
+ *
+ * @param d The mpeg_time_base_association structure.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_time_base_association_data(struct mpeg_content_labelling_descriptor_time_base_association *d)
+{
+ return (uint8_t*) d + sizeof(struct mpeg_content_labelling_descriptor_time_base_association);
+}
+
+
+/**
+ * Accessor for private_data field of an mpeg_content_labelling_descriptor.
+ *
+ * @param d The mpeg_content_labelling_descriptor structure.
+ * @param flags Pointer to the mpeg_content_labelling_descriptor_flags.
+ * @param length Where the number of bytes in the field should be stored.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_content_labelling_descriptor_data(struct mpeg_content_labelling_descriptor *d,
+ struct mpeg_content_labelling_descriptor_flags *flags,
+ int *length)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_content_labelling_descriptor_flags);
+ uint8_t *end = (uint8_t*) d + d->d.len + 2;
+
+ if (flags->content_reference_id_record_flag == 1)
+ buf += 1 + buf[1];
+ if ((flags->content_time_base_indicator==1) || (flags->content_time_base_indicator==2))
+ buf += sizeof(struct mpeg_content_labelling_descriptor_time_base);
+ if (flags->content_time_base_indicator==2)
+ buf += sizeof(struct mpeg_content_labelling_descriptor_content_id);
+ if (flags->content_time_base_indicator<3)
+ buf += 1 + buf[1];
+
+ *length = end - buf;
+
+ return buf;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/copyright_descriptor.h b/lib/libucsi/mpeg/copyright_descriptor.h
new file mode 100644
index 0000000..5991fe9
--- /dev/null
+++ b/lib/libucsi/mpeg/copyright_descriptor.h
@@ -0,0 +1,89 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_COPYRIGHT_DESCRIPTOR
+#define _UCSI_MPEG_COPYRIGHT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_copyright_descriptor structure.
+ */
+struct mpeg_copyright_descriptor {
+ struct descriptor d;
+
+ uint32_t copyright_identifier;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_copyright_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return mpeg_copyright_descriptor pointer, or NULL on error.
+ */
+static inline struct mpeg_copyright_descriptor*
+ mpeg_copyright_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct mpeg_copyright_descriptor) - 2))
+ return NULL;
+
+ bswap32((uint8_t*) d + 2);
+
+ return (struct mpeg_copyright_descriptor*) d;
+}
+
+/**
+ * Retrieve pointer to data field of an mpeg_copyright_descriptor.
+ *
+ * @param d mpeg_copyright_descriptor pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ mpeg_copyright_descriptor_data(struct mpeg_copyright_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct mpeg_copyright_descriptor);
+}
+
+
+/**
+ * Determine length of the data field of an mpeg_copyright_descriptor.
+ *
+ * @param d mpeg_copyright_descriptor pointer.
+ * @return Length of field in bytes.
+ */
+static inline int
+ mpeg_copyright_descriptor_data_length(struct mpeg_copyright_descriptor *d)
+{
+ return d->d.len - 4;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/data_stream_alignment_descriptor.h b/lib/libucsi/mpeg/data_stream_alignment_descriptor.h
new file mode 100644
index 0000000..887495f
--- /dev/null
+++ b/lib/libucsi/mpeg/data_stream_alignment_descriptor.h
@@ -0,0 +1,73 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_DATA_STREAM_ALIGNMENT_DESCRIPTOR
+#define _UCSI_MPEG_DATA_STREAM_ALIGNMENT_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Possible values for alignment_type.
+ */
+enum {
+ MPEG_DATA_STREAM_ALIGNMENT_VIDEO_SLICE_OR_AU = 0x01,
+ MPEG_DATA_STREAM_ALIGNMENT_VIDEO_AU = 0x02,
+ MPEG_DATA_STREAM_ALIGNMENT_VIDEO_GOP_OR_SEQ = 0x03,
+ MPEG_DATA_STREAM_ALIGNMENT_VIDEO_SEQ = 0x04,
+
+ MPEG_DATA_STREAM_ALIGNMENT_AUDIO_SYNC_WORD = 0x01,
+};
+
+/**
+ * mpeg_data_stream_alignment_descriptor structure.
+ */
+struct mpeg_data_stream_alignment_descriptor {
+ struct descriptor d;
+
+ uint8_t alignment_type;
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_data_stream_alignment_descriptor.
+ *
+ * @param d Pointer to generic descriptor structure.
+ * @return Pointer to mpeg_data_stream_alignment_descriptor, or NULL on error.
+ */
+static inline struct mpeg_data_stream_alignment_descriptor*
+ mpeg_data_stream_alignment_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_data_stream_alignment_descriptor) - 2))
+ return NULL;
+
+ return (struct mpeg_data_stream_alignment_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/descriptor.h b/lib/libucsi/mpeg/descriptor.h
new file mode 100644
index 0000000..c32775f
--- /dev/null
+++ b/lib/libucsi/mpeg/descriptor.h
@@ -0,0 +1,102 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_DESCRIPTOR_H
+#define _UCSI_MPEG_DESCRIPTOR_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/mpeg/mpeg4_audio_descriptor.h>
+#include <libucsi/mpeg/mpeg4_video_descriptor.h>
+#include <libucsi/mpeg/audio_stream_descriptor.h>
+#include <libucsi/mpeg/ca_descriptor.h>
+#include <libucsi/mpeg/content_labelling_descriptor.h>
+#include <libucsi/mpeg/copyright_descriptor.h>
+#include <libucsi/mpeg/data_stream_alignment_descriptor.h>
+#include <libucsi/mpeg/external_es_id_descriptor.h>
+#include <libucsi/mpeg/fmc_descriptor.h>
+#include <libucsi/mpeg/fmxbuffer_size_descriptor.h>
+#include <libucsi/mpeg/hierarchy_descriptor.h>
+#include <libucsi/mpeg/ibp_descriptor.h>
+#include <libucsi/mpeg/iod_descriptor.h>
+#include <libucsi/mpeg/iso_639_language_descriptor.h>
+#include <libucsi/mpeg/maximum_bitrate_descriptor.h>
+#include <libucsi/mpeg/metadata_descriptor.h>
+#include <libucsi/mpeg/metadata_pointer_descriptor.h>
+#include <libucsi/mpeg/metadata_std_descriptor.h>
+#include <libucsi/mpeg/multiplex_buffer_descriptor.h>
+#include <libucsi/mpeg/multiplex_buffer_utilization_descriptor.h>
+#include <libucsi/mpeg/muxcode_descriptor.h>
+#include <libucsi/mpeg/private_data_indicator_descriptor.h>
+#include <libucsi/mpeg/registration_descriptor.h>
+#include <libucsi/mpeg/sl_descriptor.h>
+#include <libucsi/mpeg/smoothing_buffer_descriptor.h>
+#include <libucsi/mpeg/std_descriptor.h>
+#include <libucsi/mpeg/system_clock_descriptor.h>
+#include <libucsi/mpeg/target_background_grid_descriptor.h>
+#include <libucsi/mpeg/video_stream_descriptor.h>
+#include <libucsi/mpeg/video_window_descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Enumeration of MPEG descriptor tags.
+ */
+enum mpeg_descriptor_tag {
+ dtag_mpeg_video_stream = 0x02,
+ dtag_mpeg_audio_stream = 0x03,
+ dtag_mpeg_hierarchy = 0x04,
+ dtag_mpeg_registration = 0x05,
+ dtag_mpeg_data_stream_alignment = 0x06,
+ dtag_mpeg_target_background_grid = 0x07,
+ dtag_mpeg_video_window = 0x08,
+ dtag_mpeg_ca = 0x09,
+ dtag_mpeg_iso_639_language = 0x0a,
+ dtag_mpeg_system_clock = 0x0b,
+ dtag_mpeg_multiplex_buffer_utilization = 0x0c,
+ dtag_mpeg_copyright = 0x0d,
+ dtag_mpeg_maximum_bitrate = 0x0e,
+ dtag_mpeg_private_data_indicator = 0x0f,
+ dtag_mpeg_smoothing_buffer = 0x10,
+ dtag_mpeg_std = 0x11,
+ dtag_mpeg_ibp = 0x12,
+ dtag_mpeg_4_video = 0x1b,
+ dtag_mpeg_4_audio = 0x1c,
+ dtag_mpeg_iod = 0x1d,
+ dtag_mpeg_sl = 0x1e,
+ dtag_mpeg_fmc = 0x1f,
+ dtag_mpeg_external_es_id = 0x20,
+ dtag_mpeg_muxcode = 0x21,
+ dtag_mpeg_fmxbuffer_size = 0x22,
+ dtag_mpeg_multiplex_buffer = 0x23,
+ dtag_mpeg_content_labelling = 0x24,
+ dtag_mpeg_metadata_pointer = 0x25,
+ dtag_mpeg_metadata = 0x26,
+ dtag_mpeg_metadata_std = 0x27,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/external_es_id_descriptor.h b/lib/libucsi/mpeg/external_es_id_descriptor.h
new file mode 100644
index 0000000..3aa3237
--- /dev/null
+++ b/lib/libucsi/mpeg/external_es_id_descriptor.h
@@ -0,0 +1,63 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_EXTERNAL_ES_ID_DESCRIPTOR
+#define _UCSI_MPEG_EXTERNAL_ES_ID_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_external_es_id_descriptor structure.
+ */
+struct mpeg_external_es_id_descriptor {
+ struct descriptor d;
+
+ uint16_t external_es_id;
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_external_es_id_descriptor structure.
+ *
+ * @param d Generic descriptor structure.
+ * @return mpeg_external_es_id_descriptor pointer, or NULL on error.
+ */
+static inline struct mpeg_external_es_id_descriptor*
+ mpeg_external_es_id_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_external_es_id_descriptor) - 2))
+ return NULL;
+
+ bswap16((uint8_t*) d + 2);
+
+ return (struct mpeg_external_es_id_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/fmc_descriptor.h b/lib/libucsi/mpeg/fmc_descriptor.h
new file mode 100644
index 0000000..5a5bed2
--- /dev/null
+++ b/lib/libucsi/mpeg/fmc_descriptor.h
@@ -0,0 +1,122 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_FMC_DESCRIPTOR
+#define _UCSI_MPEG_FMC_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_fmc_descriptor structure.
+ */
+struct mpeg_fmc_descriptor {
+ struct descriptor d;
+
+ /* struct mpeg_flex_mux muxes[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the muxes field of an mpeg_fmc_descriptor structure.
+ */
+struct mpeg_flex_mux {
+ uint16_t es_id;
+ uint8_t flex_mux_channel;
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_fmc_descriptor structure.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to an mpeg_fmc_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_fmc_descriptor*
+ mpeg_fmc_descriptor_codec(struct descriptor* d)
+{
+ uint8_t* buf = (uint8_t*) d + 2;
+ int pos = 0;
+ int len = d->len;
+
+ if (len % sizeof(struct mpeg_flex_mux))
+ return NULL;
+
+ while(pos < len) {
+ bswap16(buf+pos);
+ pos += sizeof(struct mpeg_flex_mux);
+ }
+
+ return (struct mpeg_fmc_descriptor*) d;
+}
+
+/**
+ * Convenience iterator for the muxes field of an mpeg_fmc_descriptor structure.
+ *
+ * @param d Generic descriptor structure.
+ * @param pos Variable holding a pointer to the the current entry within the muxes field.
+ */
+#define mpeg_fmc_descriptor_muxes_for_each(d, pos) \
+ for ((pos) = mpeg_fmc_descriptor_muxes_first(d); \
+ (pos); \
+ (pos) = mpeg_fmc_descriptor_muxes_next(d, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct mpeg_flex_mux*
+ mpeg_fmc_descriptor_muxes_first(struct mpeg_fmc_descriptor *d)
+{
+ if (d->d.len < sizeof(struct mpeg_flex_mux))
+ return NULL;
+
+ return (struct mpeg_flex_mux *)
+ ((uint8_t*) d + sizeof(struct mpeg_fmc_descriptor));
+}
+
+static inline struct mpeg_flex_mux*
+ mpeg_fmc_descriptor_muxes_next(struct mpeg_fmc_descriptor *d,
+ struct mpeg_flex_mux *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct mpeg_flex_mux);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct mpeg_flex_mux *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/fmxbuffer_size_descriptor.h b/lib/libucsi/mpeg/fmxbuffer_size_descriptor.h
new file mode 100644
index 0000000..74f643c
--- /dev/null
+++ b/lib/libucsi/mpeg/fmxbuffer_size_descriptor.h
@@ -0,0 +1,83 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_FMXBUFFER_SIZE_DESCRIPTOR
+#define _UCSI_MPEG_FMXBUFFER_SIZE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+
+/**
+ * mpeg_fmxbuffer_size_descriptor structure.
+ */
+struct mpeg_fmxbuffer_size_descriptor {
+ struct descriptor d;
+
+ /* uint8_t descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_fmxbuffer_size_descriptor structure.
+ *
+ * @param d Pointer to a generic descriptor structure.
+ * @return Pointer to an mpeg_fmxbuffer_size_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_fmxbuffer_size_descriptor*
+ mpeg_fmxbuffer_size_descriptor_codec(struct descriptor* d)
+{
+ return (struct mpeg_fmxbuffer_size_descriptor*) d;
+}
+
+/**
+ * Retrieve pointer to descriptors field of mpeg_fmxbuffer_size_descriptor structure.
+ *
+ * @param d mpeg_fmxbuffer_size_descriptor structure pointer.
+ * @return Pointer to the descriptors.
+ */
+static inline uint8_t *
+ mpeg_fmxbuffer_size_descriptor_descriptors(struct mpeg_fmxbuffer_size_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct mpeg_fmxbuffer_size_descriptor);
+}
+
+/**
+ * Calculate the length of the descriptors field of an mpeg_fmxbuffer_size_descriptor structure.
+ *
+ * @param d mpeg_fmxbuffer_size_descriptor structure pointer.
+ * @return Length of descriptors in bytes.
+ */
+static inline int
+ mpeg_fmxbuffer_size_descriptor_descriptors_length(struct mpeg_fmxbuffer_size_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/hierarchy_descriptor.h b/lib/libucsi/mpeg/hierarchy_descriptor.h
new file mode 100644
index 0000000..a38539d
--- /dev/null
+++ b/lib/libucsi/mpeg/hierarchy_descriptor.h
@@ -0,0 +1,83 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_HIERARCHY_DESCRIPTOR
+#define _UCSI_MPEG_HIERARCHY_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Hierarchy type values.
+ */
+enum {
+ MPEG_HIERARCHY_TYPE_ISO13818_2_SPATIAL_SCALABILITY = 0x01,
+ MPEG_HIERARCHY_TYPE_ISO13818_2_SNR_SCALABILITY = 0x02,
+ MPEG_HIERARCHY_TYPE_ISO13818_2_TEMPORAL_SCALABILITY = 0x03,
+ MPEG_HIERARCHY_TYPE_ISO13818_2_DATA_PARTITIONING = 0x04,
+ MPEG_HIERARCHY_TYPE_ISO13818_3_EXTENSION_BITSTREAM = 0x05,
+ MPEG_HIERARCHY_TYPE_ISO13818_1_PRIVATE_BITSTREAM = 0x06,
+ MPEG_HIERARCHY_TYPE_ISO13818_2_MULTI_VIEW_PROFILE = 0x07,
+ MPEG_HIERARCHY_TYPE_BASE_LAYER = 0x0f,
+};
+
+
+/**
+ * mpeg_hierarchy_descriptor structure.
+ */
+struct mpeg_hierarchy_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t reserved_1 : 4; ,
+ uint8_t hierarchy_type : 4; );
+ EBIT2(uint8_t reserved_2 : 2; ,
+ uint8_t hierarchy_layer_index : 6; );
+ EBIT2(uint8_t reserved_3 : 2; ,
+ uint8_t hierarchy_embedded_layer_index : 6; );
+ EBIT2(uint8_t reserved_4 : 2; ,
+ uint8_t hierarchy_channel : 6; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_hierarchy_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to mpeg_hierarchy_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_hierarchy_descriptor*
+ mpeg_hierarchy_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_hierarchy_descriptor) - 2))
+ return NULL;
+
+ return (struct mpeg_hierarchy_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/ibp_descriptor.h b/lib/libucsi/mpeg/ibp_descriptor.h
new file mode 100644
index 0000000..e82780a
--- /dev/null
+++ b/lib/libucsi/mpeg/ibp_descriptor.h
@@ -0,0 +1,65 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_IBP_DESCRIPTOR
+#define _UCSI_MPEG_IBP_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_ibp_descriptor structure.
+ */
+struct mpeg_ibp_descriptor {
+ struct descriptor d;
+
+ EBIT3(uint16_t closed_gop_flag : 1; ,
+ uint16_t identical_gop_flag : 1; ,
+ uint16_t max_gop_length : 14; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_ibp_descriptor structure.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to the mpeg_ibp_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_ibp_descriptor*
+ mpeg_ibp_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_ibp_descriptor) - 2))
+ return NULL;
+
+ bswap16((uint8_t*) d + 2);
+
+ return (struct mpeg_ibp_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/iod_descriptor.h b/lib/libucsi/mpeg/iod_descriptor.h
new file mode 100644
index 0000000..61de153
--- /dev/null
+++ b/lib/libucsi/mpeg/iod_descriptor.h
@@ -0,0 +1,87 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_IOD_DESCRIPTOR
+#define _UCSI_MPEG_IOD_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_iod_descriptor structure.
+ */
+struct mpeg_iod_descriptor {
+ struct descriptor d;
+
+ uint8_t scope_of_iod_label;
+ uint8_t iod_label;
+ /* uint8_t iod[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_iod_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to an mpeg_iod_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_iod_descriptor*
+ mpeg_iod_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct mpeg_iod_descriptor) - 2))
+ return NULL;
+
+ return (struct mpeg_iod_descriptor*) d;
+}
+
+/**
+ * Retrieve pointer to iod field of an mpeg_iod_descriptor structure.
+ *
+ * @param d Pointer to mpeg_iod_descriptor structure.
+ * @return Pointer to the iod field.
+ */
+static inline uint8_t *
+ mpeg_iod_descriptor_iod(struct mpeg_iod_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct mpeg_iod_descriptor);
+}
+
+/**
+ * Calculate the length of the iod field of an mpeg_iod_descriptor structure.
+ *
+ * @param d Pointer to mpeg_iod_descriptor structure.
+ * @return The number of bytes.
+ */
+static inline int
+ mpeg_iod_descriptor_iod_length(struct mpeg_iod_descriptor *d)
+{
+ return d->d.len - 2;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/iso_639_language_descriptor.h b/lib/libucsi/mpeg/iso_639_language_descriptor.h
new file mode 100644
index 0000000..5b5aac0
--- /dev/null
+++ b/lib/libucsi/mpeg/iso_639_language_descriptor.h
@@ -0,0 +1,124 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_ISO_639_LANGUAGE_DESCRIPTOR
+#define _UCSI_MPEG_ISO_639_LANGUAGE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+#include <libucsi/types.h>
+
+/**
+ * Possible values for audio_type.
+ */
+enum {
+ MPEG_AUDIO_TYPE_CLEAN_EFFECTS = 0x01,
+ MPEG_AUDIO_TYPE_HEARING_IMPAIRED = 0x02,
+ MPEG_AUDIO_TYPE_VISUAL_IMPAIRED_COMMENTARY = 0x03,
+};
+
+/**
+ * mpeg_iso_639_language_descriptor structure.
+ */
+struct mpeg_iso_639_language_descriptor {
+ struct descriptor d;
+
+ /* struct mpeg_iso_639_language_code languages[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the mpeg_iso_639_language_descriptor languages field.
+ */
+struct mpeg_iso_639_language_code {
+ iso639lang_t language_code;
+ uint8_t audio_type;
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_iso_639_language_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to an mpeg_iso_639_language_descriptor structure, or NULL
+ * on error.
+ */
+static inline struct mpeg_iso_639_language_descriptor*
+ mpeg_iso_639_language_descriptor_codec(struct descriptor* d)
+{
+ if (d->len % sizeof(struct mpeg_iso_639_language_code))
+ return NULL;
+
+ return (struct mpeg_iso_639_language_descriptor*) d;
+}
+
+/**
+ * Convenience iterator for the languages field of an mpeg_iso_639_language_descriptor
+ *
+ * @param d Pointer to the mpeg_iso_639_language_descriptor structure.
+ * @param pos Variable holding a pointer to the current entry.
+ */
+#define mpeg_iso_639_language_descriptor_languages_for_each(_d, _pos) \
+ for ((_pos) = mpeg_iso_639_language_descriptor_languages_first(_d); \
+ (_pos); \
+ (_pos) = mpeg_iso_639_language_descriptor_languages_next(_d, _pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct mpeg_iso_639_language_code*
+ mpeg_iso_639_language_descriptor_languages_first(struct mpeg_iso_639_language_descriptor *d)
+{
+ if (d->d.len < sizeof(struct mpeg_iso_639_language_code))
+ return NULL;
+
+ return (struct mpeg_iso_639_language_code *)
+ ((uint8_t*) d + sizeof(struct mpeg_iso_639_language_descriptor));
+}
+
+static inline struct mpeg_iso_639_language_code*
+ mpeg_iso_639_language_descriptor_languages_next(struct mpeg_iso_639_language_descriptor *d,
+ struct mpeg_iso_639_language_code *pos)
+{
+ uint8_t *end = (uint8_t*) d + 2 + d->d.len;
+ uint8_t *next = (uint8_t *) pos + sizeof(struct mpeg_iso_639_language_code);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct mpeg_iso_639_language_code *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/maximum_bitrate_descriptor.h b/lib/libucsi/mpeg/maximum_bitrate_descriptor.h
new file mode 100644
index 0000000..e0bcddb
--- /dev/null
+++ b/lib/libucsi/mpeg/maximum_bitrate_descriptor.h
@@ -0,0 +1,64 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_MAXIMUM_BITRATE_DESCRIPTOR
+#define _UCSI_MPEG_MAXIMUM_BITRATE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_maximum_bitrate_descriptor structure.
+ */
+struct mpeg_maximum_bitrate_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint32_t reserved : 2; ,
+ uint32_t maximum_bitrate : 22; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_maximum_bitrate_descriptor.
+ *
+ * @param d Pointer to generic descriptor structure.
+ * @return Pointer to mpeg_maximum_bitrate_descriptor, or NULL on error.
+ */
+static inline struct mpeg_maximum_bitrate_descriptor*
+ mpeg_maximum_bitrate_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_maximum_bitrate_descriptor) - 2))
+ return NULL;
+
+ bswap24((uint8_t*) d + 2);
+
+ return (struct mpeg_maximum_bitrate_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/metadata_descriptor.h b/lib/libucsi/mpeg/metadata_descriptor.h
new file mode 100644
index 0000000..5b91e05
--- /dev/null
+++ b/lib/libucsi/mpeg/metadata_descriptor.h
@@ -0,0 +1,472 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_METADATA_DESCRIPTOR
+#define _UCSI_MPEG_METADATA_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Values for the decoder_config_flags field.
+ */
+enum {
+ MPEG_DECODER_CONFIG_NONE = 0x00,
+ MPEG_DECODER_CONFIG_IN_DECODER_CONFIG = 0x01,
+ MPEG_DECODER_CONFIG_SAME_METADATA_SERVICE = 0x02,
+ MPEG_DECODER_CONFIG_DSMCC = 0x03,
+ MPEG_DECODER_CONFIG_SAME_PROGRAM = 0x04,
+};
+
+/**
+ * mpeg_metadata_descriptor structure.
+ */
+struct mpeg_metadata_descriptor {
+ struct descriptor d;
+
+ uint16_t metadata_application_format;
+ /* struct mpeg_metadata_descriptor_application_format_identifier appid */
+ /* uint8_t metadata_format */
+ /* struct mpeg_metadata_descriptor_format_identifier formid */
+ /* struct mpeg_metadata_descriptor_flags flags */
+ /* struct mpeg_metadata_descriptor_service_identifier service_identifier */
+ /* struct mpeg_metadata_descriptor_decoder_config decoder_config */
+ /* struct mpeg_metadata_descriptor_decoder_config_id_record decoder_config_id_record */
+ /* struct mpeg_metadata_descriptor_decoder_config_service_id decoder_config_service_id */
+ /* struct mpeg_metadata_descriptor_decoder_config_reserved decoder_config_reserved */
+ /* uint8_t private_data[] */
+} __ucsi_packed;
+
+/**
+ * appid field of a metadata_descriptor.
+ */
+struct mpeg_metadata_descriptor_application_format_identifier {
+ uint32_t id;
+} __ucsi_packed;
+
+/**
+ * formid field of a metadata_descriptor.
+ */
+struct mpeg_metadata_descriptor_format_identifier {
+ uint32_t id;
+} __ucsi_packed;
+
+/**
+ * Flags field of a metadata_descriptor
+ */
+struct mpeg_metadata_descriptor_flags {
+ uint8_t metadata_service_id;
+ EBIT3(uint8_t decoder_config_flags : 3; ,
+ uint8_t dsm_cc_flag : 1; ,
+ uint8_t reserved : 4; );
+} __ucsi_packed;
+
+/**
+ * service_identifier field of a metadata_descriptor.
+ */
+struct mpeg_metadata_descriptor_service_identifier {
+ uint8_t service_identification_length;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * decoder_config field of a metadata_descriptor.
+ */
+struct mpeg_metadata_descriptor_decoder_config {
+ uint8_t decoder_config_length;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * decoder_config_id_record field of a metadata_descriptor.
+ */
+struct mpeg_metadata_descriptor_decoder_config_id_record {
+ uint8_t decoder_config_id_record_length;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * decoder_config_service_id field of a metadata_descriptor.
+ */
+struct mpeg_metadata_descriptor_decoder_config_service_id {
+ uint8_t decoder_config_metadata_service_id;
+} __ucsi_packed;
+
+/**
+ * decoder_config_reserved field of a metadata_descriptor.
+ */
+struct mpeg_metadata_descriptor_decoder_config_reserved {
+ uint8_t reserved_data_length;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+
+
+
+/**
+ * Process an mpeg_metadata_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return Pointer to an mpeg_metadata_descriptor, or NULL on error.
+ */
+static inline struct mpeg_metadata_descriptor*
+ mpeg_metadata_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 2;
+ uint8_t *buf = (uint8_t*) d;
+ uint32_t len = d->len + 2;
+ struct mpeg_metadata_descriptor_flags *flags;
+ int id;
+
+ if (len < sizeof(struct mpeg_metadata_descriptor))
+ return NULL;
+
+ bswap16(buf + pos);
+ id = *((uint16_t*) (buf+pos));
+ pos += 2;
+
+ if (id == 0xffff) {
+ if (len < (pos+4))
+ return NULL;
+ bswap32(buf+pos);
+ pos += 4;
+ }
+
+ if (len < (pos+1))
+ return NULL;
+
+ id = buf[pos];
+ pos++;
+ if (id == 0xff) {
+ if (len < (pos+4))
+ return NULL;
+ bswap32(buf+pos);
+ pos += 4;
+ }
+
+ if (len < (pos + sizeof(struct mpeg_metadata_descriptor_flags)))
+ return NULL;
+ flags = (struct mpeg_metadata_descriptor_flags*) (buf+pos);
+ pos += sizeof(struct mpeg_metadata_descriptor_flags);
+
+ if (flags->dsm_cc_flag == 1) {
+ if (len < (pos+1))
+ return NULL;
+ if (len < (pos+1+buf[pos]))
+ return NULL;
+ pos += 1 + buf[pos];
+ }
+
+ if (flags->decoder_config_flags == 1) {
+ if (len < (pos+1))
+ return NULL;
+ if (len < (pos+1+buf[pos]))
+ return NULL;
+ pos += 1 + buf[pos];
+ }
+
+ if (flags->decoder_config_flags == 3) {
+ if (len < (pos+1))
+ return NULL;
+ if (len < (pos+1+buf[pos]))
+ return NULL;
+ pos += 1 + buf[pos];
+ }
+
+ if (flags->decoder_config_flags == 4) {
+ if (len < (pos+1))
+ return NULL;
+ pos++;
+ }
+
+ if ((flags->decoder_config_flags == 5) ||
+ (flags->decoder_config_flags == 6)) {
+ if (len < (pos+1))
+ return NULL;
+ if (len < (pos+1+buf[pos]))
+ return NULL;
+ pos += 1 + buf[pos];
+ }
+
+ if (len < pos)
+ return NULL;
+
+ return (struct mpeg_metadata_descriptor*) d;
+}
+
+/**
+ * Accessor for pointer to appid field of an mpeg_metadata_descriptor.
+ *
+ * @param d The mpeg_metadata_descriptor structure.
+ * @return The pointer, or NULL on error.
+ */
+static inline struct mpeg_metadata_descriptor_application_format_identifier*
+ mpeg_metadata_descriptor_appid(struct mpeg_metadata_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d + sizeof(struct mpeg_metadata_descriptor);
+
+ if (d->metadata_application_format != 0xffff)
+ return NULL;
+ return (struct mpeg_metadata_descriptor_application_format_identifier*) buf;
+}
+
+/**
+ * Accessor for metadata_format field of an mpeg_metadata_descriptor.
+ *
+ * @param d The mpeg_metadata_descriptor structure.
+ * @return The pointer, or NULL on error.
+ */
+static inline uint8_t
+ mpeg_metadata_descriptor_metadata_format(struct mpeg_metadata_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d + sizeof(struct mpeg_metadata_descriptor);
+
+ if (d->metadata_application_format == 0xffff)
+ buf+=4;
+ return *buf;
+}
+
+/**
+ * Accessor for pointer to formid field of an mpeg_metadata_descriptor.
+ *
+ * @param d The mpeg_metadata_descriptor structure.
+ * @return The pointer, or NULL on error.
+ */
+static inline struct mpeg_metadata_descriptor_format_identifier*
+ mpeg_metadata_descriptor_formid(struct mpeg_metadata_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d + sizeof(struct mpeg_metadata_descriptor);
+
+ if (d->metadata_application_format == 0xffff)
+ buf+=4;
+ if (*buf != 0xff)
+ return NULL;
+
+ return (struct mpeg_metadata_descriptor_format_identifier*) (buf+1);
+}
+
+/**
+ * Accessor for flags field of an mpeg_metadata_descriptor.
+ *
+ * @param d The mpeg_metadata_descriptor structure.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_descriptor_flags*
+ mpeg_metadata_descriptor_flags(struct mpeg_metadata_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d + sizeof(struct mpeg_metadata_descriptor);
+
+ if (d->metadata_application_format == 0xffff)
+ buf+=4;
+ if (*buf == 0xff)
+ buf+=4;
+
+ return (struct mpeg_metadata_descriptor_flags*) buf;
+}
+
+
+/**
+ * Accessor for service_identifier field of an mpeg_metadata_descriptor.
+ *
+ * @param flags Pointer to the mpeg_metadata_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_descriptor_service_identifier*
+ mpeg_metadata_descriptor_sevice_identifier(struct mpeg_metadata_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_descriptor_flags);
+
+ if (flags->dsm_cc_flag!=1)
+ return NULL;
+
+ return (struct mpeg_metadata_descriptor_service_identifier *) buf;
+}
+
+/**
+ * Accessor for data field of an mpeg_metadata_descriptor_service_identifier.
+ *
+ * @param d The mpeg_metadata_descriptor_service_identifier structure.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_metadata_descriptor_service_identifier_data(struct mpeg_metadata_descriptor_service_identifier *d)
+{
+ return (uint8_t*) d + sizeof(struct mpeg_metadata_descriptor_service_identifier);
+}
+
+/**
+ * Accessor for decoder_config field of an mpeg_metadata_descriptor.
+ *
+ * @param flags Pointer to the mpeg_metadata_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_descriptor_decoder_config*
+ mpeg_metadata_descriptor_decoder_config(struct mpeg_metadata_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_descriptor_flags);
+
+ if (flags->decoder_config_flags != 1)
+ return NULL;
+
+ if (flags->dsm_cc_flag==1)
+ buf += 1 + buf[1];
+
+ return (struct mpeg_metadata_descriptor_decoder_config*) buf;
+}
+
+/**
+ * Accessor for data field of an mpeg_metadata_descriptor_service_identifier.
+ *
+ * @param d The mpeg_metadata_descriptor_service_identifier structure.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_metadata_descriptor_decoder_config_data(struct mpeg_metadata_descriptor_decoder_config *d)
+{
+ return (uint8_t*) d + sizeof(struct mpeg_metadata_descriptor_decoder_config);
+}
+
+/**
+ * Accessor for decoder_config_id_record field of an mpeg_metadata_descriptor.
+ *
+ * @param flags Pointer to the mpeg_metadata_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_descriptor_decoder_config_id_record*
+ mpeg_metadata_descriptor_decoder_config_id_record(struct mpeg_metadata_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_descriptor_flags);
+
+ if (flags->decoder_config_flags != 3)
+ return NULL;
+
+ if (flags->dsm_cc_flag==1)
+ buf += 1 + buf[1];
+
+ return (struct mpeg_metadata_descriptor_decoder_config_id_record *) buf;
+}
+
+/**
+ * Accessor for data field of an mpeg_metadata_descriptor_decoder_config_id_record.
+ *
+ * @param d The mpeg_metadata_descriptor_decoder_config_id_record structure.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_metadata_descriptor_decoder_config_id_record_data(struct mpeg_metadata_descriptor_decoder_config_id_record *d)
+{
+ return (uint8_t*) d + sizeof(struct mpeg_metadata_descriptor_decoder_config_id_record);
+}
+
+/**
+ * Accessor for decoder_config_service_id field of an mpeg_metadata_descriptor.
+ *
+ * @param flags Pointer to the mpeg_metadata_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_descriptor_decoder_config_service_id*
+ mpeg_metadata_descriptor_decoder_config_service_id(struct mpeg_metadata_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_descriptor_flags);
+
+ if (flags->decoder_config_flags != 4)
+ return NULL;
+
+ if (flags->dsm_cc_flag==1)
+ buf += 1 + buf[1];
+
+ return (struct mpeg_metadata_descriptor_decoder_config_service_id *) buf;
+}
+
+/**
+ * Accessor for decoder_config_reserved field of an mpeg_metadata_descriptor.
+ *
+ * @param flags Pointer to the mpeg_metadata_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_descriptor_decoder_config_reserved*
+ mpeg_metadata_descriptor_decoder_config_reserved(struct mpeg_metadata_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_descriptor_flags);
+
+ if ((flags->decoder_config_flags != 5) && (flags->decoder_config_flags != 6))
+ return NULL;
+
+ if (flags->dsm_cc_flag==1)
+ buf += 1 + buf[1];
+
+ return (struct mpeg_metadata_descriptor_decoder_config_reserved *) buf;
+}
+
+/**
+ * Accessor for data field of an mpeg_metadata_descriptor_decoder_config_reserved.
+ *
+ * @param d The mpeg_metadata_descriptor_decoder_config_reserved structure.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_metadata_descriptor_decoder_config_reserved_data(struct mpeg_metadata_descriptor_decoder_config_reserved *d)
+{
+ return (uint8_t*) d + sizeof(struct mpeg_metadata_descriptor_decoder_config_reserved);
+}
+
+/**
+ * Accessor for private_data field of an mpeg_metadata_descriptor.
+ *
+ * @param d The mpeg_metadata_descriptor structure.
+ * @param flags Pointer to the mpeg_metadata_descriptor_flags.
+ * @param length Where the number of bytes in the field should be stored.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_metadata_descriptor_private_data(struct mpeg_metadata_descriptor *d,
+ struct mpeg_metadata_descriptor_flags *flags,
+ int *length)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_descriptor_flags);
+ uint8_t *end = (uint8_t*) d + d->d.len + 2;
+
+
+ if (flags->dsm_cc_flag==1)
+ buf += 1 + buf[1];
+ if (flags->decoder_config_flags==1)
+ buf += 1 + buf[1];
+ if (flags->decoder_config_flags==3)
+ buf += 1 + buf[1];
+ if (flags->decoder_config_flags==4)
+ buf++;
+ if ((flags->decoder_config_flags==5)||(flags->decoder_config_flags==6))
+ buf += 1 + buf[1];
+
+ *length = end - buf;
+ return buf;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/metadata_pointer_descriptor.h b/lib/libucsi/mpeg/metadata_pointer_descriptor.h
new file mode 100644
index 0000000..e4d7503
--- /dev/null
+++ b/lib/libucsi/mpeg/metadata_pointer_descriptor.h
@@ -0,0 +1,360 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_METADATA_POINTER_DESCRIPTOR
+#define _UCSI_MPEG_METADATA_POINTER_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * Possible values for the mpeg_carriage_flags field.
+ */
+enum {
+ MPEG_CARRIAGE_SAME_TS = 0x00,
+ MPEG_CARRIAGE_DIFFERENT_TS = 0x01,
+ MPEG_CARRIAGE_PS = 0x02,
+ MPEG_CARRIAGE_OTHER = 0x03,
+};
+
+/**
+ * mpeg_metadata_pointer_descriptor structure.
+ */
+struct mpeg_metadata_pointer_descriptor {
+ struct descriptor d;
+
+ uint16_t metadata_application_format;
+ /* struct mpeg_metadata_pointer_descriptor_application_format_identifier appid */
+ /* uint8_t metadata_format */
+ /* struct mpeg_metadata_pointer_descriptor_format_identifier formid */
+ /* struct mpeg_metadata_pointer_descriptor_flags flags */
+ /* struct mpeg_metadata_pointer_descriptor_locator locator */
+ /* struct mpeg_metadata_pointer_descriptor_program_number program_number */
+ /* struct mpeg_metadata_pointer_descriptor_carriage carriage */
+ /* uint8_t private_data[] */
+} __ucsi_packed;
+
+/**
+ * appid field of a metadata_pointer_descriptor.
+ */
+struct mpeg_metadata_pointer_descriptor_application_format_identifier {
+ uint32_t id;
+} __ucsi_packed;
+
+/**
+ * formid field of a metadata_pointer_descriptor.
+ */
+struct mpeg_metadata_pointer_descriptor_format_identifier {
+ uint32_t id;
+} __ucsi_packed;
+
+/**
+ * Flags field of a metadata_pointer_descriptor
+ */
+struct mpeg_metadata_pointer_descriptor_flags {
+ uint8_t metadata_service_id;
+ EBIT3(uint8_t metadata_locator_record_flag : 1; ,
+ uint8_t mpeg_carriage_flags : 2; ,
+ uint8_t reserved : 5; );
+} __ucsi_packed;
+
+/**
+ * Reference_id field of a metadata_pointer_descriptor.
+ */
+struct mpeg_metadata_pointer_descriptor_locator {
+ uint8_t metadata_locator_record_length;
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * program_number field of a metadata_pointer_descriptor.
+ */
+struct mpeg_metadata_pointer_descriptor_program_number {
+ uint16_t number;
+} __ucsi_packed;
+
+/**
+ * carriage field of a metadata_pointer_descriptor.
+ */
+struct mpeg_metadata_pointer_descriptor_carriage {
+ uint16_t transport_stream_location;
+ uint16_t transport_stream_id;
+} __ucsi_packed;
+
+
+
+
+/**
+ * Process an mpeg_metadata_pointer_descriptor.
+ *
+ * @param d Generic descriptor.
+ * @return Pointer to an mpeg_metadata_pointer_descriptor, or NULL on error.
+ */
+static inline struct mpeg_metadata_pointer_descriptor*
+ mpeg_metadata_pointer_descriptor_codec(struct descriptor* d)
+{
+ uint32_t pos = 2;
+ uint8_t *buf = (uint8_t*) d;
+ uint32_t len = d->len + 2;
+ struct mpeg_metadata_pointer_descriptor_flags *flags;
+ int id;
+
+ if (len < sizeof(struct mpeg_metadata_pointer_descriptor))
+ return NULL;
+
+ bswap16(buf + pos);
+ id = *((uint16_t*) (buf+pos));
+ pos += 2;
+
+ if (id == 0xffff) {
+ if (len < (pos+4))
+ return NULL;
+ bswap32(buf+pos);
+ pos += 4;
+ }
+
+ if (len < (pos+1))
+ return NULL;
+
+ id = buf[pos];
+ pos++;
+ if (id == 0xff) {
+ if (len < (pos+4))
+ return NULL;
+ bswap32(buf+pos);
+ pos += 4;
+ }
+
+ if (len < (pos + sizeof(struct mpeg_metadata_pointer_descriptor_flags)))
+ return NULL;
+ flags = (struct mpeg_metadata_pointer_descriptor_flags*) (buf+pos);
+ pos += sizeof(struct mpeg_metadata_pointer_descriptor_flags);
+
+ if (flags->metadata_locator_record_flag == 1) {
+ if (len < (pos+1))
+ return NULL;
+ if (len < (pos+1+buf[pos]))
+ return NULL;
+ pos += 1 + buf[pos];
+ }
+
+ if (flags->mpeg_carriage_flags < 3) {
+ if (len < (pos + 2))
+ return NULL;
+ bswap16(buf+pos);
+ pos += 2;
+ }
+
+ if (flags->mpeg_carriage_flags == 1) {
+ if (len < (pos + 4))
+ return NULL;
+ bswap16(buf+pos);
+ bswap16(buf+pos+2);
+ pos += 4;
+ }
+
+ if (len < pos)
+ return NULL;
+
+ return (struct mpeg_metadata_pointer_descriptor*) d;
+}
+
+/**
+ * Accessor for pointer to appid field of an mpeg_metadata_pointer_descriptor.
+ *
+ * @param d The mpeg_metadata_pointer_descriptor structure.
+ * @return The pointer, or NULL on error.
+ */
+static inline struct mpeg_metadata_pointer_descriptor_application_format_identifier*
+ mpeg_metadata_pointer_descriptor_appid(struct mpeg_metadata_pointer_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d + sizeof(struct mpeg_metadata_pointer_descriptor);
+
+ if (d->metadata_application_format != 0xffff)
+ return NULL;
+ return (struct mpeg_metadata_pointer_descriptor_application_format_identifier*) buf;
+}
+
+/**
+ * Accessor for metadata_format field of an mpeg_metadata_pointer_descriptor.
+ *
+ * @param d The mpeg_metadata_pointer_descriptor structure.
+ * @return The pointer, or NULL on error.
+ */
+static inline uint8_t
+ mpeg_metadata_pointer_descriptor_metadata_format(struct mpeg_metadata_pointer_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d + sizeof(struct mpeg_metadata_pointer_descriptor);
+
+ if (d->metadata_application_format == 0xffff)
+ buf+=4;
+ return *buf;
+}
+
+/**
+ * Accessor for pointer to formid field of an mpeg_metadata_pointer_descriptor.
+ *
+ * @param d The mpeg_metadata_pointer_descriptor structure.
+ * @return The pointer, or NULL on error.
+ */
+static inline struct mpeg_metadata_pointer_descriptor_format_identifier*
+ mpeg_metadata_pointer_descriptor_formid(struct mpeg_metadata_pointer_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d + sizeof(struct mpeg_metadata_pointer_descriptor);
+
+ if (d->metadata_application_format == 0xffff)
+ buf+=4;
+ if (*buf != 0xff)
+ return NULL;
+
+ return (struct mpeg_metadata_pointer_descriptor_format_identifier*) (buf+1);
+}
+
+/**
+ * Accessor for flags field of an mpeg_metadata_pointer_descriptor.
+ *
+ * @param d The mpeg_metadata_pointer_descriptor structure.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_pointer_descriptor_flags*
+ mpeg_metadata_pointer_descriptor_flags(struct mpeg_metadata_pointer_descriptor *d)
+{
+ uint8_t *buf = (uint8_t*) d + sizeof(struct mpeg_metadata_pointer_descriptor);
+
+ if (d->metadata_application_format == 0xffff)
+ buf+=4;
+ if (*buf == 0xff)
+ buf+=4;
+
+ return (struct mpeg_metadata_pointer_descriptor_flags*) buf;
+}
+
+
+/**
+ * Accessor for locator field of an mpeg_metadata_pointer_descriptor.
+ *
+ * @param flags Pointer to the mpeg_metadata_pointer_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_pointer_descriptor_locator*
+ mpeg_metadata_pointer_descriptor_locator(struct mpeg_metadata_pointer_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_pointer_descriptor_flags);
+
+ if (flags->metadata_locator_record_flag!=1)
+ return NULL;
+
+ return (struct mpeg_metadata_pointer_descriptor_locator *) buf;
+}
+
+/**
+ * Accessor for data field of an mpeg_metadata_pointer_descriptor_locator.
+ *
+ * @param d The mpeg_metadata_pointer_descriptor_locator structure.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_metadata_pointer_descriptor_locator_data(struct mpeg_metadata_pointer_descriptor_locator *d)
+{
+ return (uint8_t*) d + sizeof(struct mpeg_metadata_pointer_descriptor_locator);
+}
+
+
+/**
+ * Accessor for program_number field of an mpeg_metadata_pointer_descriptor.
+ *
+ * @param flags Pointer to the mpeg_metadata_pointer_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_pointer_descriptor_program_number*
+ mpeg_metadata_pointer_descriptor_program_number(struct mpeg_metadata_pointer_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_pointer_descriptor_flags);
+
+ if (flags->mpeg_carriage_flags < 3)
+ return NULL;
+
+ if (flags->metadata_locator_record_flag==1)
+ buf += 1 + buf[1];
+
+ return (struct mpeg_metadata_pointer_descriptor_program_number*) buf;
+}
+
+/**
+ * Accessor for carriage field of an mpeg_metadata_pointer_descriptor.
+ *
+ * @param flags Pointer to the mpeg_metadata_pointer_descriptor_flags.
+ * @return Pointer to the field, or NULL on error.
+ */
+static inline struct mpeg_metadata_pointer_descriptor_carriage*
+ mpeg_metadata_pointer_descriptor_carriage(struct mpeg_metadata_pointer_descriptor_flags *flags)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_pointer_descriptor_flags);
+
+ if (flags->mpeg_carriage_flags != 1)
+ return NULL;
+
+ if (flags->metadata_locator_record_flag==1)
+ buf += 1 + buf[1];
+ if (flags->mpeg_carriage_flags < 3)
+ buf += sizeof(struct mpeg_metadata_pointer_descriptor_program_number);
+
+ return (struct mpeg_metadata_pointer_descriptor_carriage *) buf;
+}
+
+/**
+ * Accessor for private_data field of an mpeg_metadata_pointer_descriptor.
+ *
+ * @param d The mpeg_metadata_pointer_descriptor structure.
+ * @param flags Pointer to the mpeg_metadata_pointer_descriptor_flags.
+ * @param length Where the number of bytes in the field should be stored.
+ * @return Pointer to the field.
+ */
+static inline uint8_t*
+ mpeg_metadata_pointer_descriptor_private_data(struct mpeg_metadata_pointer_descriptor *d,
+ struct mpeg_metadata_pointer_descriptor_flags *flags,
+ int *length)
+{
+ uint8_t *buf = (uint8_t*) flags + sizeof(struct mpeg_metadata_pointer_descriptor_flags);
+ uint8_t *end = (uint8_t*) d + d->d.len + 2;
+
+
+ if (flags->metadata_locator_record_flag==1)
+ buf += 1 + buf[1];
+ if (flags->mpeg_carriage_flags < 3)
+ buf += sizeof(struct mpeg_metadata_pointer_descriptor_program_number);
+ if (flags->mpeg_carriage_flags != 1)
+ buf += sizeof(struct mpeg_metadata_pointer_descriptor_carriage);
+
+ *length = end - buf;
+ return buf;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/metadata_section.c b/lib/libucsi/mpeg/metadata_section.c
new file mode 100644
index 0000000..c1ce019
--- /dev/null
+++ b/lib/libucsi/mpeg/metadata_section.c
@@ -0,0 +1,27 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/mpeg/metadata_section.h>
+
+struct mpeg_metadata_section * mpeg_metadata_section_codec(struct section_ext * ext)
+{
+ return (struct mpeg_metadata_section *)ext;
+}
diff --git a/lib/libucsi/mpeg/metadata_section.h b/lib/libucsi/mpeg/metadata_section.h
new file mode 100644
index 0000000..62c4e03
--- /dev/null
+++ b/lib/libucsi/mpeg/metadata_section.h
@@ -0,0 +1,122 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_METADATA_SECTION_H
+#define _UCSI_MPEG_METADATA_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * mpeg_metadata_section structure.
+ */
+struct mpeg_metadata_section {
+ struct section_ext head;
+
+ /* uint8_t data[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_metadata_section structure.
+ *
+ * @param section Pointer to the section_ext structure.
+ * @return Pointer to the mpeg_metadata_section structure, or NULL on error.
+ */
+extern struct mpeg_metadata_section *mpeg_metadata_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for the random_access_indicator field of a metadata section.
+ *
+ * @param metadata metadata section pointer.
+ * @return The random_access_indicator.
+ */
+static inline uint8_t mpeg_metadata_section_random_access_indicator(struct mpeg_metadata_section *metadata)
+{
+ return metadata->head.reserved >> 1;
+}
+
+/**
+ * Accessor for the decoder_config_flag field of a metadata section.
+ *
+ * @param metadata metadata section pointer.
+ * @return The decoder_config_flag.
+ */
+static inline uint8_t mpeg_metadata_section_decoder_config_flag(struct mpeg_metadata_section *metadata)
+{
+ return metadata->head.reserved & 1;
+}
+
+/**
+ * Accessor for the fragment_indicator field of a metadata section.
+ *
+ * @param metadata metadata section pointer.
+ * @return The fragment_indicator.
+ */
+static inline uint8_t mpeg_metadata_section_fragment_indicator(struct mpeg_metadata_section *metadata)
+{
+ return metadata->head.reserved1;
+}
+
+/**
+ * Accessor for the service_id field of a metadata section.
+ *
+ * @param metadata metadata section pointer.
+ * @return The service_id.
+ */
+static inline uint16_t mpeg_metadata_section_service_id(struct mpeg_metadata_section *metadata)
+{
+ return metadata->head.table_id_ext >> 8;
+}
+
+/**
+ * Retrieve pointer to data field of an mpeg_metadata_section.
+ *
+ * @param s mpeg_metadata_section pointer.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ mpeg_metadata_section_data(struct mpeg_metadata_section *s)
+{
+ return (uint8_t *) s + sizeof(struct mpeg_metadata_section);
+}
+
+
+/**
+ * Determine length of the data field of an mpeg_copyright_descriptor.
+ *
+ * @param s mpeg_metadata_section_data pointer.
+ * @return Length of field in bytes.
+ */
+static inline int
+ mpeg_metadata_section_data_length(struct mpeg_metadata_section *s)
+{
+ return section_ext_length(&s->head) - sizeof(struct mpeg_metadata_section);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/metadata_std_descriptor.h b/lib/libucsi/mpeg/metadata_std_descriptor.h
new file mode 100644
index 0000000..fc83e6e
--- /dev/null
+++ b/lib/libucsi/mpeg/metadata_std_descriptor.h
@@ -0,0 +1,72 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_METADATA_STD_DESCRIPTOR
+#define _UCSI_MPEG_METADATA_STD_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_metadata_std_descriptor structure.
+ */
+struct mpeg_metadata_std_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint32_t reserved_1 : 2; ,
+ uint32_t metadata_input_leak_rate :22; );
+ EBIT2(uint32_t reserved_2 : 2; ,
+ uint32_t metadata_buffer_size :22; );
+ EBIT2(uint32_t reserved_3 : 2; ,
+ uint32_t metadata_output_leak_rate :22; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_metadata_std_descriptor.
+ *
+ * @param d Pointer to the generic descriptor structure.
+ * @return Pointer to the mpeg_metadata_std_descriptor, or NULL on error.
+ */
+static inline struct mpeg_metadata_std_descriptor*
+ mpeg_metadata_std_descriptor_codec(struct descriptor* d)
+{
+ uint8_t *buf = (uint8_t*) d;
+
+ if (d->len != (sizeof(struct mpeg_metadata_std_descriptor) - 2))
+ return NULL;
+
+ bswap24(buf + 2);
+ bswap24(buf + 5);
+ bswap24(buf + 8);
+
+ return (struct mpeg_metadata_std_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/mpeg4_audio_descriptor.h b/lib/libucsi/mpeg/mpeg4_audio_descriptor.h
new file mode 100644
index 0000000..f876759
--- /dev/null
+++ b/lib/libucsi/mpeg/mpeg4_audio_descriptor.h
@@ -0,0 +1,61 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG4_AUDIO_DESCRIPTOR
+#define _UCSI_MPEG4_AUDIO_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg4_audio_descriptor structure.
+ */
+struct mpeg4_audio_descriptor {
+ struct descriptor d;
+
+ uint8_t mpeg4_audio_profile_and_level;
+} __ucsi_packed;
+
+/**
+ * Process an mpeg4_audio_descriptor.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to an mpeg4_audio_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg4_audio_descriptor*
+ mpeg4_audio_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg4_audio_descriptor) - 2))
+ return NULL;
+
+ return (struct mpeg4_audio_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/mpeg4_video_descriptor.h b/lib/libucsi/mpeg/mpeg4_video_descriptor.h
new file mode 100644
index 0000000..b956b91
--- /dev/null
+++ b/lib/libucsi/mpeg/mpeg4_video_descriptor.h
@@ -0,0 +1,61 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG4_VIDEO_DESCRIPTOR
+#define _UCSI_MPEG4_VIDEO_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg4_video_descriptor structure.
+ */
+struct mpeg4_video_descriptor {
+ struct descriptor d;
+
+ uint8_t mpeg4_visual_profile_and_level;
+} __ucsi_packed;
+
+/**
+ * Process an mpeg4_video_descriptor structure.
+ *
+ * @param d Pointer to generic descriptor structure.
+ * @return Pointer to mpeg4_video_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg4_video_descriptor*
+ mpeg4_video_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg4_video_descriptor) - 2))
+ return NULL;
+
+ return (struct mpeg4_video_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/multiplex_buffer_descriptor.h b/lib/libucsi/mpeg/multiplex_buffer_descriptor.h
new file mode 100644
index 0000000..d55ce3d
--- /dev/null
+++ b/lib/libucsi/mpeg/multiplex_buffer_descriptor.h
@@ -0,0 +1,65 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_MULTIPLEX_BUFFER_DESCRIPTOR
+#define _UCSI_MPEG_MULTIPLEX_BUFFER_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_multiplex_buffer_descriptor descriptor.
+ */
+struct mpeg_multiplex_buffer_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint64_t mb_buffer_size : 24; ,
+ uint64_t tb_leak_rate : 24; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_multiplex_buffer_descriptor.
+ *
+ * @param d Pointer to generic descriptor structure.
+ * @return Pointer to an mpeg_multiplex_buffer_descriptor structure, or NULL on
+ * error.
+ */
+static inline struct mpeg_multiplex_buffer_descriptor*
+ mpeg_multiplex_buffer_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_multiplex_buffer_descriptor) - 2))
+ return NULL;
+
+ bswap48((uint8_t*) d + 2);
+
+ return (struct mpeg_multiplex_buffer_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/multiplex_buffer_utilization_descriptor.h b/lib/libucsi/mpeg/multiplex_buffer_utilization_descriptor.h
new file mode 100644
index 0000000..16550ed
--- /dev/null
+++ b/lib/libucsi/mpeg/multiplex_buffer_utilization_descriptor.h
@@ -0,0 +1,67 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_MULTIPLEX_BUFFER_UTILIZATION_DESCRIPTOR
+#define _UCSI_MPEG_MULTIPLEX_BUFFER_UTILIZATION_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_multiplex_buffer_utilization_descriptor structure.
+ */
+struct mpeg_multiplex_buffer_utilization_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint16_t bound_valid_flag : 1; ,
+ uint16_t ltw_offset_lower_bound : 15; );
+ EBIT2(uint16_t reserved : 1; ,
+ uint16_t ltw_offset_upper_bound : 15; );
+} __ucsi_packed;
+
+/**
+ * Process a mpeg_multiplex_buffer_utilization_descriptor.
+ *
+ * @param d Generic descriptor pointer.
+ * @return mpeg_multiplex_buffer_utilization_descriptor pointer, or NULL on error.
+ */
+static inline struct mpeg_multiplex_buffer_utilization_descriptor*
+ mpeg_multiplex_buffer_utilization_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_multiplex_buffer_utilization_descriptor) - 2))
+ return NULL;
+
+ bswap16((uint8_t*) d + 2);
+ bswap16((uint8_t*) d + 4);
+
+ return (struct mpeg_multiplex_buffer_utilization_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/muxcode_descriptor.h b/lib/libucsi/mpeg/muxcode_descriptor.h
new file mode 100644
index 0000000..6bed334
--- /dev/null
+++ b/lib/libucsi/mpeg/muxcode_descriptor.h
@@ -0,0 +1,82 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_MUXCODE_DESCRIPTOR
+#define _UCSI_MPEG_MUXCODE_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_muxcode_descriptor structure
+ */
+struct mpeg_muxcode_descriptor {
+ struct descriptor d;
+
+ /* uint8_t entries[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_muxcode_descriptor.
+ *
+ * @param d Pointer to a generic descriptor structure.
+ * @return Pointer to an mpeg_muxcode_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_muxcode_descriptor*
+ mpeg_muxcode_descriptor_codec(struct descriptor* d)
+{
+ return (struct mpeg_muxcode_descriptor*) d;
+}
+
+/**
+ * Retrieve pointer to entries field of an mpeg_muxcode_descriptor structure.
+ *
+ * @param d Generic descriptor structure.
+ * @return Pointer to the entries field.
+ */
+static inline uint8_t *
+ mpeg_muxcode_descriptor_entries(struct mpeg_muxcode_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct mpeg_muxcode_descriptor);
+}
+
+/**
+ * Determine length of entries field of an mpeg_muxcode_descriptor structure.
+ *
+ * @param d Generic descriptor structure.
+ * @return Number of bytes in the entries field.
+ */
+static inline int
+ mpeg_muxcode_descriptor_entries_length(struct mpeg_muxcode_descriptor *d)
+{
+ return d->d.len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/odsmt_section.c b/lib/libucsi/mpeg/odsmt_section.c
new file mode 100644
index 0000000..07407f2
--- /dev/null
+++ b/lib/libucsi/mpeg/odsmt_section.c
@@ -0,0 +1,80 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/mpeg/odsmt_section.h>
+
+struct mpeg_odsmt_section *mpeg_odsmt_section_codec(struct section_ext * ext)
+{
+ struct mpeg_odsmt_section * odsmt = (struct mpeg_odsmt_section *)ext;
+ uint8_t * buf = (uint8_t *)ext;
+ size_t pos = sizeof(struct section_ext);
+ size_t len = section_ext_length(ext);
+ int i;
+
+ if (len < sizeof(struct mpeg_odsmt_section))
+ return NULL;
+
+ pos++;
+
+ if (odsmt->stream_count == 0) {
+ struct mpeg_odsmt_stream * stream =
+ (struct mpeg_odsmt_stream *) (buf + pos);
+
+ if ((pos + sizeof(struct mpeg_odsmt_stream_single)) > len)
+ return NULL;
+
+ bswap16(buf+pos);
+ pos+=3;
+
+ if ((pos + stream->u.single.es_info_length) >= len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, stream->u.single.es_info_length))
+ return NULL;
+
+ pos += stream->u.single.es_info_length;
+ } else {
+ for (i=0; i< odsmt->stream_count; i++) {
+ struct mpeg_odsmt_stream * stream =
+ (struct mpeg_odsmt_stream *)(buf + pos);
+
+ if ((pos + sizeof(struct mpeg_odsmt_stream_multi)) > len)
+ return NULL;
+
+ bswap16(buf+pos);
+ pos += sizeof(struct mpeg_odsmt_stream_multi);
+
+ if ((pos + stream->u.multi.es_info_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos,
+ stream->u.multi.es_info_length))
+ return NULL;
+
+ pos += stream->u.multi.es_info_length;
+ }
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return (struct mpeg_odsmt_section *) ext;
+}
diff --git a/lib/libucsi/mpeg/odsmt_section.h b/lib/libucsi/mpeg/odsmt_section.h
new file mode 100644
index 0000000..4e01085
--- /dev/null
+++ b/lib/libucsi/mpeg/odsmt_section.h
@@ -0,0 +1,224 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_ODSMT_SECTION_H
+#define _UCSI_MPEG_ODSMT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * mpeg_odsmt_section structure.
+ */
+struct mpeg_odsmt_section {
+ struct section_ext head;
+
+ uint8_t stream_count;
+ /* stream_count==0 => struct mpeg_odsmt_stream_single streams
+ stream_count>0 => struct mpeg_odsmt_stream_multi streams[] */
+ /* uint8_t object_descriptors[] */
+} __ucsi_packed;
+
+struct mpeg_odsmt_stream_single
+{
+ uint16_t esid;
+ uint8_t es_info_length;
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+struct mpeg_odsmt_stream_multi
+{
+ uint16_t esid;
+ uint8_t fmc;
+ uint8_t es_info_length;
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Structure describing the stream information held in an mpeg_odsmt_section.
+ */
+struct mpeg_odsmt_stream {
+ union {
+ struct mpeg_odsmt_stream_single single;
+ struct mpeg_odsmt_stream_multi multi;
+ } u;
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_odsmt_section.
+ *
+ * @param section Pointer to the generic section_ext structure.
+ * @return Pointer to a mpeg_odsmt_section structure, or NULL on error.
+ */
+extern struct mpeg_odsmt_section *mpeg_odsmt_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for the PID field of an ODSMT.
+ *
+ * @param odsmt odsmt pointer.
+ * @return The pid.
+ */
+static inline uint16_t mpeg_odsmt_section_pid(struct mpeg_odsmt_section *odsmt)
+{
+ return odsmt->head.table_id_ext & 0x1fff;
+}
+
+/**
+ * Convenience iterator for the streams field of an mpeg_odsmt_section.
+ *
+ * @param osdmt Pointer to the mpeg_odsmt_section structure.
+ * @param pos Variable holding pointer to the current mpeg_odsmt_stream structure.
+ * @param index Variable holding the stream index.
+ */
+#define mpeg_odsmt_section_streams_for_each(osdmt, pos, index) \
+ for (index=0, (pos) = mpeg_odsmt_section_streams_first(odsmt); \
+ (pos); \
+ (pos) = mpeg_odsmt_section_streams_next(odsmt, pos, ++index))
+
+/**
+ * Convenience iterator for the descriptors field of an mpeg_odsmt_stream.
+ *
+ * @param osdmt Pointer to the mpeg_odsmt_section structure.
+ * @param stream Pointer to the mpeg_odsmt_stream structure.
+ * @param pos Variable holding pointer to the current descriptor structure.
+ */
+#define mpeg_odsmt_stream_descriptors_for_each(osdmt, stream, pos) \
+ for ((pos) = mpeg_odsmt_stream_descriptors_first(odsmt, stream); \
+ (pos); \
+ (pos) = mpeg_odsmt_stream_descriptors_next(odsmt, stream, pos))
+
+/**
+ * Retrieve a pointer to the object_descriptors field of an mpeg_odsmt_section.
+ *
+ * @param osdmt Pointer to the mpeg_odsmt_section structure.
+ * @param len On return, will contain the number of bytes in the object descriptors field.
+ * @return Pointer to the object_descriptors field, or NULL on error.
+ */
+static inline uint8_t*
+ mpeg_odsmt_section_object_descriptors(struct mpeg_odsmt_section * odsmt,
+ size_t* len);
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct mpeg_odsmt_stream *
+ mpeg_odsmt_section_streams_first(struct mpeg_odsmt_section *odsmt)
+{
+ size_t pos = sizeof(struct mpeg_odsmt_section);
+
+ if (pos >= section_ext_length(&odsmt->head))
+ return NULL;
+
+ return (struct mpeg_odsmt_stream *) ((uint8_t *) odsmt + pos);
+}
+
+static inline struct mpeg_odsmt_stream *
+ mpeg_odsmt_section_streams_next(struct mpeg_odsmt_section *odsmt,
+ struct mpeg_odsmt_stream *pos,
+ int _index)
+{
+ uint8_t *end = (uint8_t*) odsmt + section_ext_length(&odsmt->head);
+ uint8_t *next;
+
+ if (_index > odsmt->stream_count)
+ return NULL;
+
+ next = (uint8_t *) pos + sizeof(struct mpeg_odsmt_stream_multi) +
+ pos->u.multi.es_info_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct mpeg_odsmt_stream *) next;
+}
+
+static inline struct descriptor *
+ mpeg_odsmt_stream_descriptors_first(struct mpeg_odsmt_section *odsmt,
+ struct mpeg_odsmt_stream *stream)
+{
+ if (odsmt->stream_count == 0) {
+ if (stream->u.single.es_info_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t*) stream + sizeof(struct mpeg_odsmt_stream_single));
+ } else {
+ if (stream->u.multi.es_info_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t*) stream + sizeof(struct mpeg_odsmt_stream_multi));
+ }
+}
+
+static inline struct descriptor *
+ mpeg_odsmt_stream_descriptors_next(struct mpeg_odsmt_section *odsmt,
+ struct mpeg_odsmt_stream *stream,
+ struct descriptor* pos)
+{
+ if (odsmt->stream_count == 0) {
+ return next_descriptor((uint8_t *) stream + sizeof(struct mpeg_odsmt_stream_single),
+ stream->u.single.es_info_length,
+ pos);
+ } else {
+ return next_descriptor((uint8_t *) stream + sizeof(struct mpeg_odsmt_stream_multi),
+ stream->u.multi.es_info_length,
+ pos);
+ }
+}
+
+static inline uint8_t*
+ mpeg_odsmt_section_object_descriptors(struct mpeg_odsmt_section * odsmt,
+ size_t* len)
+{
+ struct mpeg_odsmt_stream* pos;
+ size_t size = sizeof(struct mpeg_odsmt_section);
+ int _index;
+
+ mpeg_odsmt_section_streams_for_each(odsmt, pos, _index) {
+ if (odsmt->stream_count == 0)
+ size += sizeof(struct mpeg_odsmt_stream_single) +
+ pos->u.single.es_info_length;
+ else
+ size += sizeof(struct mpeg_odsmt_stream_multi) +
+ pos->u.multi.es_info_length;
+ }
+
+ *len = section_ext_length(&odsmt->head) - size;
+ return (uint8_t*) odsmt + size;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/pat_section.c b/lib/libucsi/mpeg/pat_section.c
new file mode 100644
index 0000000..2e4c2cc
--- /dev/null
+++ b/lib/libucsi/mpeg/pat_section.c
@@ -0,0 +1,46 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/mpeg/pat_section.h>
+
+struct mpeg_pat_section *mpeg_pat_section_codec(struct section_ext * ext)
+{
+ uint8_t *buf = (uint8_t *)ext;
+ size_t pos = sizeof(struct section_ext);
+ size_t len = section_ext_length(ext);
+
+ if (len < sizeof(struct mpeg_pat_section))
+ return NULL;
+
+ while (pos < len) {
+ if ((pos + 4) > len)
+ return NULL;
+
+ bswap16(buf + pos);
+ bswap16(buf + pos + 2);
+ pos += 4;
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return (struct mpeg_pat_section *)ext;
+}
diff --git a/lib/libucsi/mpeg/pat_section.h b/lib/libucsi/mpeg/pat_section.h
new file mode 100644
index 0000000..eadfe28
--- /dev/null
+++ b/lib/libucsi/mpeg/pat_section.h
@@ -0,0 +1,118 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_PAT_SECTION_H
+#define _UCSI_MPEG_PAT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * mpeg_pat_section structure.
+ */
+struct mpeg_pat_section {
+ struct section_ext head; /* table_id_ext == transport_stream_id */
+
+ /* struct mpeg_pat_program programs[] */
+} __ucsi_packed;
+
+/**
+ * A program within an mpeg_pat_section.
+ */
+struct mpeg_pat_program {
+ uint16_t program_number;
+ EBIT2(uint16_t reserved : 3; ,
+ uint16_t pid :13; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_pat_section.
+ *
+ * @param section Pointer to the generic section_ext structure.
+ * @return Pointer to the mpeg_pat_section structure, or NULL on error.
+ */
+extern struct mpeg_pat_section *mpeg_pat_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for the transport_stream_id field of a PAT.
+ *
+ * @param pat PAT pointer.
+ * @return The transport_stream_id.
+ */
+static inline uint16_t mpeg_pat_section_transport_stream_id(struct mpeg_pat_section *pat)
+{
+ return pat->head.table_id_ext;
+}
+
+/**
+ * Conveience iterator for the programs field of an mpeg_pat_section.
+ *
+ * @param pat Pointer to the mpeg_pat_section structure.
+ * @param pos Variable holding a pointer to the current mpeg_pat_program structure.
+ */
+#define mpeg_pat_section_programs_for_each(pat, pos) \
+ for ((pos) = mpeg_pat_section_programs_first(pat); \
+ (pos); \
+ (pos) = mpeg_pat_section_programs_next(pat, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct mpeg_pat_program *
+ mpeg_pat_section_programs_first(struct mpeg_pat_section * pat)
+{
+ size_t pos = sizeof(struct mpeg_pat_section);
+
+ if (pos >= section_ext_length(&pat->head))
+ return NULL;
+
+ return (struct mpeg_pat_program*)((uint8_t *) pat + pos);
+}
+
+static inline
+ struct mpeg_pat_program *mpeg_pat_section_programs_next(struct mpeg_pat_section * pat,
+ struct mpeg_pat_program * pos)
+{
+ uint8_t *end = (uint8_t*) pat + section_ext_length(&pat->head);
+ uint8_t *next= (uint8_t *) pos + sizeof(struct mpeg_pat_program);
+
+ if (next >= end)
+ return NULL;
+
+ return (struct mpeg_pat_program *) next;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/pmt_section.c b/lib/libucsi/mpeg/pmt_section.c
new file mode 100644
index 0000000..e5aec6a
--- /dev/null
+++ b/lib/libucsi/mpeg/pmt_section.c
@@ -0,0 +1,71 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/mpeg/pmt_section.h>
+
+struct mpeg_pmt_section * mpeg_pmt_section_codec(struct section_ext * ext)
+{
+ uint8_t * buf = (uint8_t *) ext;
+ struct mpeg_pmt_section * pmt = (struct mpeg_pmt_section *) ext;
+ size_t pos = sizeof(struct section_ext);
+ size_t len = section_ext_length(ext);
+
+ if (len < sizeof(struct mpeg_pmt_section))
+ return NULL;
+
+ bswap16(buf + pos);
+ pos += 2;
+ bswap16(buf + pos);
+ pos += 2;
+
+ if ((pos + pmt->program_info_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, pmt->program_info_length))
+ return NULL;
+
+ pos += pmt->program_info_length;
+
+ while (pos < len) {
+ struct mpeg_pmt_stream * stream =
+ (struct mpeg_pmt_stream *) (buf + pos);
+
+ if ((pos + sizeof(struct mpeg_pmt_stream)) > len)
+ return NULL;
+
+ bswap16(buf + pos + 1);
+ bswap16(buf + pos + 3);
+ pos += sizeof(struct mpeg_pmt_stream);
+
+ if ((pos + stream->es_info_length) > len)
+ return NULL;
+
+ if (verify_descriptors(buf + pos, stream->es_info_length))
+ return NULL;
+
+ pos += stream->es_info_length;
+ }
+
+ if (pos != len)
+ return NULL;
+
+ return (struct mpeg_pmt_section *) ext;
+}
diff --git a/lib/libucsi/mpeg/pmt_section.h b/lib/libucsi/mpeg/pmt_section.h
new file mode 100644
index 0000000..03dea1b
--- /dev/null
+++ b/lib/libucsi/mpeg/pmt_section.h
@@ -0,0 +1,188 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_PMT_SECTION_H
+#define _UCSI_MPEG_PMT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * mpeg_pmt_section structure.
+ */
+struct mpeg_pmt_section {
+ struct section_ext head;
+
+ EBIT2(uint16_t reserved_1 : 3; ,
+ uint16_t pcr_pid :13; );
+ EBIT2(uint16_t reserved_2 : 4; ,
+ uint16_t program_info_length :12; );
+ /* struct descriptor descriptors[] */
+ /* struct mpeg_pmt_stream streams[] */
+} __ucsi_packed;
+
+/**
+ * A stream within an mpeg_pmt_section.
+ */
+struct mpeg_pmt_stream {
+ uint8_t stream_type;
+ EBIT2(uint16_t reserved_1 : 3; ,
+ uint16_t pid :13; );
+ EBIT2(uint16_t reserved_2 : 4; ,
+ uint16_t es_info_length :12; );
+
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_pmt_section section.
+ *
+ * @param section Pointer to the generic section header.
+ * @return Pointer to the mpeg_pmt_section structure, or NULL on error.
+ */
+extern struct mpeg_pmt_section *mpeg_pmt_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for program_number field of a PMT.
+ *
+ * @param pmt PMT pointer.
+ * @return The program_number.
+ */
+static inline uint16_t mpeg_pmt_section_program_number(struct mpeg_pmt_section *pmt)
+{
+ return pmt->head.table_id_ext;
+}
+
+/**
+ * Convenience iterator for the descriptors field of the mpeg_pmt_section structure.
+ *
+ * @param pmt Pointer to the mpeg_pmt_section structure.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define mpeg_pmt_section_descriptors_for_each(pmt, pos) \
+ for ((pos) = mpeg_pmt_section_descriptors_first(pmt); \
+ (pos); \
+ (pos) = mpeg_pmt_section_descriptors_next(pmt, pos))
+
+/**
+ * Convenience iterator for the streams field of the mpeg_pmt_section structure.
+ *
+ * @param pmt Pointer to the mpeg_pmt_section structure.
+ * @param pos Variable holding a pointer to the current mpeg_pmt_stream.
+ */
+#define mpeg_pmt_section_streams_for_each(pmt, pos) \
+ for ((pos) = mpeg_pmt_section_streams_first(pmt); \
+ (pos); \
+ (pos) = mpeg_pmt_section_streams_next(pmt, pos))
+
+/**
+ * Convenience iterator for the descriptors field of an mpeg_pmt_stream structure.
+ *
+ * @param stream Pointer to the mpeg_pmt_stream structure.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define mpeg_pmt_stream_descriptors_for_each(stream, pos) \
+ for ((pos) = mpeg_pmt_stream_descriptors_first(stream); \
+ (pos); \
+ (pos) = mpeg_pmt_stream_descriptors_next(stream, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ mpeg_pmt_section_descriptors_first(struct mpeg_pmt_section * pmt)
+{
+ if (pmt->program_info_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) pmt + sizeof(struct mpeg_pmt_section));
+}
+
+static inline struct descriptor *
+ mpeg_pmt_section_descriptors_next(struct mpeg_pmt_section *pmt,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t *) pmt + sizeof(struct mpeg_pmt_section),
+ pmt->program_info_length,
+ pos);
+}
+
+static inline struct mpeg_pmt_stream *
+ mpeg_pmt_section_streams_first(struct mpeg_pmt_section * pmt)
+{
+ size_t pos = sizeof(struct mpeg_pmt_section) + pmt->program_info_length;
+
+ if (pos >= section_ext_length(&pmt->head))
+ return NULL;
+
+ return (struct mpeg_pmt_stream *)((uint8_t *)pmt + pos);
+}
+
+static inline struct mpeg_pmt_stream *
+ mpeg_pmt_section_streams_next(struct mpeg_pmt_section * pmt,
+ struct mpeg_pmt_stream * pos)
+{
+ uint8_t *end = (uint8_t*) pmt + section_ext_length(&pmt->head);
+ uint8_t *next = (uint8_t *) pos + sizeof(struct mpeg_pmt_stream) +
+ pos->es_info_length;
+
+ if (next >= end)
+ return NULL;
+
+ return (struct mpeg_pmt_stream *) next;
+}
+
+static inline struct descriptor *
+ mpeg_pmt_stream_descriptors_first(struct mpeg_pmt_stream *stream)
+{
+ if (stream->es_info_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t*) stream + sizeof(struct mpeg_pmt_stream));
+}
+
+static inline struct descriptor *
+ mpeg_pmt_stream_descriptors_next(struct mpeg_pmt_stream *stream,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t *) stream + sizeof(struct mpeg_pmt_stream),
+ stream->es_info_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/private_data_indicator_descriptor.h b/lib/libucsi/mpeg/private_data_indicator_descriptor.h
new file mode 100644
index 0000000..80e8ef3
--- /dev/null
+++ b/lib/libucsi/mpeg/private_data_indicator_descriptor.h
@@ -0,0 +1,63 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_PRIVATE_DATA_INDICATOR_DESCRIPTOR
+#define _UCSI_MPEG_PRIVATE_DATA_INDICATOR_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_private_data_indicator_descriptor structure
+ */
+struct mpeg_private_data_indicator_descriptor {
+ struct descriptor d;
+
+ uint32_t private_data_indicator;
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_private_data_indicator_descriptor structure.
+ *
+ * @param d Pointer to the generic descriptor structure.
+ * @return Pointer to the mpeg_private_data_indicator_descriptor, or NULL on error.
+ */
+static inline struct mpeg_private_data_indicator_descriptor*
+ mpeg_private_data_indicator_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_private_data_indicator_descriptor) - 2))
+ return NULL;
+
+ bswap32((uint8_t*) d + 2);
+
+ return (struct mpeg_private_data_indicator_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/registration_descriptor.h b/lib/libucsi/mpeg/registration_descriptor.h
new file mode 100644
index 0000000..df5c186
--- /dev/null
+++ b/lib/libucsi/mpeg/registration_descriptor.h
@@ -0,0 +1,91 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_REGISTRATION_DESCRIPTOR
+#define _UCSI_MPEG_REGISTRATION_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_registration_descriptor structure.
+ */
+struct mpeg_registration_descriptor {
+ struct descriptor d;
+
+ uint32_t format_identifier;
+ /* uint8_t additional_id_info[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_registration_descriptor.
+ *
+ * @param d Pointer to the generic descriptor structure.
+ * @return Pointer to the mpeg_registration_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_registration_descriptor*
+ mpeg_registration_descriptor_codec(struct descriptor* d)
+{
+ if (d->len < (sizeof(struct mpeg_registration_descriptor) - 2))
+ return NULL;
+
+ bswap32((uint8_t*) d + 2);
+
+ return (struct mpeg_registration_descriptor*) d;
+}
+
+/**
+ * Retrieve a pointer to the additional_id_info field of the
+ * mpeg_registration_descriptor structure.
+ *
+ * @param d Pointer to the mpeg_registration_descriptor structure.
+ * @return Pointer to the field.
+ */
+static inline uint8_t *
+ mpeg_registration_descriptor_additional_id_info(struct mpeg_registration_descriptor *d)
+{
+ return (uint8_t *) d + sizeof(struct mpeg_registration_descriptor);
+}
+
+/**
+ * Determine number of bytes in the additional_id_info field of the
+ * mpeg_registration_descriptor structure.
+ *
+ * @param d Pointer to the mpeg_registration_descriptor structure.
+ * @return Number of bytes.
+ */
+
+static inline int
+ mpeg_registration_descriptor_additional_id_info_length(struct mpeg_registration_descriptor *d)
+{
+ return d->d.len - 4;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/section.h b/lib/libucsi/mpeg/section.h
new file mode 100644
index 0000000..7dbff93
--- /dev/null
+++ b/lib/libucsi/mpeg/section.h
@@ -0,0 +1,58 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_SECTION_H
+#define _UCSI_MPEG_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/mpeg/cat_section.h>
+#include <libucsi/mpeg/odsmt_section.h>
+#include <libucsi/mpeg/pat_section.h>
+#include <libucsi/mpeg/pmt_section.h>
+#include <libucsi/mpeg/tsdt_section.h>
+#include <libucsi/mpeg/metadata_section.h>
+
+#define TRANSPORT_PAT_PID 0x00
+#define TRANSPORT_CAT_PID 0x01
+#define TRANSPORT_TSDT_PID 0x02
+
+/**
+ * Enumeration of MPEG section tags.
+ */
+enum mpeg_section_tag {
+ stag_mpeg_program_association = 0x00,
+ stag_mpeg_conditional_access = 0x01,
+ stag_mpeg_program_map = 0x02,
+ stag_mpeg_transport_stream_description = 0x03,
+ stag_mpeg_iso14496_scene_description = 0x04,
+ stag_mpeg_iso14496_object_description = 0x05,
+ stag_mpeg_metadata = 0x06,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/sl_descriptor.h b/lib/libucsi/mpeg/sl_descriptor.h
new file mode 100644
index 0000000..ab086e3
--- /dev/null
+++ b/lib/libucsi/mpeg/sl_descriptor.h
@@ -0,0 +1,63 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_SL_DESCRIPTOR
+#define _UCSI_MPEG_SL_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_sl_descriptor structure.
+ */
+struct mpeg_sl_descriptor {
+ struct descriptor d;
+
+ uint16_t es_id;
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_sl_descriptor.
+ *
+ * @param d The generic descriptor structure.
+ * @return Pointer to an mpeg_sl_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_sl_descriptor*
+ mpeg_sl_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_sl_descriptor) - 2))
+ return NULL;
+
+ bswap16((uint8_t*) d + 2);
+
+ return (struct mpeg_sl_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/smoothing_buffer_descriptor.h b/lib/libucsi/mpeg/smoothing_buffer_descriptor.h
new file mode 100644
index 0000000..5e6ad33
--- /dev/null
+++ b/lib/libucsi/mpeg/smoothing_buffer_descriptor.h
@@ -0,0 +1,66 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_SMOOTHING_BUFFER_DESCRIPTOR
+#define _UCSI_MPEG_SMOOTHING_BUFFER_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_smoothing_buffer_descriptor structure.
+ */
+struct mpeg_smoothing_buffer_descriptor {
+ struct descriptor d;
+
+ EBIT4(uint64_t reserved_1 : 2; ,
+ uint64_t sb_leak_rate :22; ,
+ uint64_t reserved_2 : 2; ,
+ uint64_t sb_size :22; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_smoothing_buffer_descriptor.
+ *
+ * @param d The generic descriptor structure.
+ * @return Pointer to mpeg_smoothing_buffer_descriptor, or NULL on error.
+ */
+static inline struct mpeg_smoothing_buffer_descriptor*
+ mpeg_smoothing_buffer_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_smoothing_buffer_descriptor) - 2))
+ return NULL;
+
+ bswap48((uint8_t*) d + 2);
+
+ return (struct mpeg_smoothing_buffer_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/std_descriptor.h b/lib/libucsi/mpeg/std_descriptor.h
new file mode 100644
index 0000000..2625a41
--- /dev/null
+++ b/lib/libucsi/mpeg/std_descriptor.h
@@ -0,0 +1,62 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_STD_DESCRIPTOR
+#define _UCSI_MPEG_STD_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_std_descriptor structure.
+ */
+struct mpeg_std_descriptor {
+ struct descriptor d;
+
+ EBIT2(uint8_t reserved : 7; ,
+ uint8_t leak_valid_flag : 1; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_std_descriptor.
+ *
+ * @param d Pointer to the generic descriptor structure.
+ * @return Pointer to the mpeg_std_descriptor, or NULL on error.
+ */
+static inline struct mpeg_std_descriptor*
+ mpeg_std_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_std_descriptor) - 2))
+ return NULL;
+
+ return (struct mpeg_std_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/system_clock_descriptor.h b/lib/libucsi/mpeg/system_clock_descriptor.h
new file mode 100644
index 0000000..681641f
--- /dev/null
+++ b/lib/libucsi/mpeg/system_clock_descriptor.h
@@ -0,0 +1,65 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_SYSTEM_CLOCK_DESCRIPTOR
+#define _UCSI_MPEG_SYSTEM_CLOCK_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_system_clock_descriptor structure.
+ */
+struct mpeg_system_clock_descriptor {
+ struct descriptor d;
+
+ EBIT3(uint8_t external_clock_reference_indicator : 1; ,
+ uint8_t reserved_1 : 1; ,
+ uint8_t clock_accuracy_integer : 6; );
+ EBIT2(uint8_t clock_accuracy_exponent : 3; ,
+ uint8_t reserved_2 : 5; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_system_clock_descriptor.
+ *
+ * @param d The generic descriptor structure.
+ * @return Pointer to a mpeg_system_clock_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_system_clock_descriptor*
+ mpeg_system_clock_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_system_clock_descriptor) - 2))
+ return NULL;
+
+ return (struct mpeg_system_clock_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/target_background_grid_descriptor.h b/lib/libucsi/mpeg/target_background_grid_descriptor.h
new file mode 100644
index 0000000..7394e82
--- /dev/null
+++ b/lib/libucsi/mpeg/target_background_grid_descriptor.h
@@ -0,0 +1,66 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_TARGET_BACKGROUND_GRID_DESCRIPTOR
+#define _UCSI_MPEG_TARGET_BACKGROUND_GRID_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * mpeg_target_background_grid_descriptor structure.
+ */
+struct mpeg_target_background_grid_descriptor {
+ struct descriptor d;
+
+ EBIT3(uint32_t horizontal_size : 14; ,
+ uint32_t vertical_size : 14; ,
+ uint32_t aspect_ratio_information : 4; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_target_background_grid_descriptor structure.
+ *
+ * @param d Pointer to the generic descriptor structure.
+ * @return Pointer to the mpeg_target_background_grid_descriptor structure, or
+ * NULL on error.
+ */
+static inline struct mpeg_target_background_grid_descriptor*
+ mpeg_target_background_grid_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_target_background_grid_descriptor) - 2))
+ return NULL;
+
+ bswap32((uint8_t*) d + 2);
+
+ return (struct mpeg_target_background_grid_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/tsdt_section.c b/lib/libucsi/mpeg/tsdt_section.c
new file mode 100644
index 0000000..fec9dd7
--- /dev/null
+++ b/lib/libucsi/mpeg/tsdt_section.c
@@ -0,0 +1,34 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libucsi/mpeg/tsdt_section.h>
+
+struct mpeg_tsdt_section * mpeg_tsdt_section_codec(struct section_ext * ext)
+{
+ uint8_t * buf = (uint8_t *)ext;
+ size_t pos = sizeof(struct section_ext);
+
+ if (verify_descriptors(buf + pos,
+ section_ext_length(ext) - sizeof(struct mpeg_tsdt_section)))
+ return NULL;
+
+ return (struct mpeg_tsdt_section *)ext;
+}
diff --git a/lib/libucsi/mpeg/tsdt_section.h b/lib/libucsi/mpeg/tsdt_section.h
new file mode 100644
index 0000000..2bbae02
--- /dev/null
+++ b/lib/libucsi/mpeg/tsdt_section.h
@@ -0,0 +1,94 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_TSDT_SECTION_H
+#define _UCSI_MPEG_TSDT_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * mpeg_tsdt_section structure.
+ */
+struct mpeg_tsdt_section {
+ struct section_ext head;
+
+ /* struct descriptor descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_tsdt_section structure.
+ *
+ * @param section Pointer to the section_ext structure.
+ * @return Pointer to the mpeg_tsdt_section structure, or NULL on error.
+ */
+extern struct mpeg_tsdt_section *mpeg_tsdt_section_codec(struct section_ext *section);
+
+/**
+ * Convenience iterator for descriptors field.
+ *
+ * @param tsdt Pointer to the mpeg_tsdt_section structure.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define mpeg_tsdt_section_descriptors_for_each(tsdt, pos) \
+ for ((pos) = mpeg_tsdt_section_descriptors_first(tsdt); \
+ (pos); \
+ (pos) = mpeg_tsdt_section_descriptors_next(tsdt, pos))
+
+
+
+
+
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ mpeg_tsdt_section_descriptors_first(struct mpeg_tsdt_section * tsdt)
+{
+ size_t pos = sizeof(struct mpeg_tsdt_section);
+
+ if (pos >= section_ext_length(&tsdt->head))
+ return NULL;
+
+ return (struct descriptor*)((uint8_t *) tsdt + pos);
+}
+
+static inline struct descriptor *
+ mpeg_tsdt_section_descriptors_next(struct mpeg_tsdt_section *tsdt,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t *) tsdt + sizeof(struct mpeg_tsdt_section),
+ section_ext_length(&tsdt->head) - sizeof(struct mpeg_tsdt_section),
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/types.h b/lib/libucsi/mpeg/types.h
new file mode 100644
index 0000000..300cb23
--- /dev/null
+++ b/lib/libucsi/mpeg/types.h
@@ -0,0 +1,127 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_TYPES_H
+#define _UCSI_MPEG_TYPES_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Known stream types.
+ */
+enum {
+ MPEG_STREAM_TYPE_ISO11172_VIDEO = 0x01,
+ MPEG_STREAM_TYPE_ISO13818_2_VIDEO = 0x02,
+ MPEG_STREAM_TYPE_ISO11172_AUDIO = 0x03,
+ MPEG_STREAM_TYPE_ISO13818_3_AUDIO = 0x04,
+ MPEG_STREAM_TYPE_ISO13818_1_PRIVATE_SECTIONS = 0x05,
+ MPEG_STREAM_TYPE_ISO13818_1_PRIVATE_PES = 0x06,
+ MPEG_STREAM_TYPE_ISO13522_MHEG = 0x07,
+ MPEG_STREAM_TYPE_ISO13818_DSMCC = 0x08,
+ MPEG_STREAM_TYPE_ITUH222_1 = 0x09,
+ MPEG_STREAM_TYPE_ISO13818_6_A = 0x0a,
+ MPEG_STREAM_TYPE_ISO13818_6_B = 0x0b,
+ MPEG_STREAM_TYPE_ISO13818_6_C = 0x0c,
+ MPEG_STREAM_TYPE_ISO13818_6_D = 0x0d,
+ MPEG_STREAM_TYPE_ISO13818_1_AUX = 0x0e,
+ MPEG_STREAM_TYPE_ISO13818_7_AUDIO_ADTS = 0x0f,
+ MPEG_STREAM_TYPE_ISO14496_2_VISUAL = 0x10,
+ MPEG_STREAM_TYPE_ISO14496_3_AUDIO_LATM = 0x11,
+ MPEG_STREAM_TYPE_ISO14496_1_PES = 0x12,
+ MPEG_STREAM_TYPE_ISO14496_1_SECTIONS = 0x13,
+ MPEG_STREAM_TYPE_ISO14496_6_SYNCDOWNLOAD = 0x14,
+ MPEG_STREAM_TYPE_METADATA_PES = 0x15,
+ MPEG_STREAM_TYPE_METADATA_SECTIONS = 0x16,
+ MPEG_STREAM_TYPE_METADATA_DSMCC_DATA = 0x17,
+ MPEG_STREAM_TYPE_METADATA_DSMCC_OBJECT = 0x18,
+ MPEG_STREAM_TYPE_METADATA_SYNCDOWNLOAD = 0x19,
+};
+
+/**
+ * Metadata formats
+ */
+enum {
+ MPEG_METADATA_FORMAT_ISO15938_1_TEM = 0x01,
+ MPEG_METADATA_FORMAT_ISO15938_1_BIM = 0x02,
+ MPEG_METADATA_FORMAT_METADATA_APPLICATION_FORMAT = 0x3F,
+ MPEG_METADATA_FORMAT_METADATA_APPLICATION_FORMAT_ID = 0xFF,
+};
+
+/**
+ * MPEG 4 audio profile and levels.
+ */
+enum {
+ MPEG4_AUDIO_PROFILE_MAIN_LEVEL_1 = 0x10,
+ MPEG4_AUDIO_PROFILE_MAIN_LEVEL_2 = 0x11,
+ MPEG4_AUDIO_PROFILE_MAIN_LEVEL_3 = 0x12,
+ MPEG4_AUDIO_PROFILE_MAIN_LEVEL_4 = 0x13,
+
+ MPEG4_AUDIO_PROFILE_SCALABLE_LEVEL_1 = 0x18,
+ MPEG4_AUDIO_PROFILE_SCALABLE_LEVEL_2 = 0x19,
+ MPEG4_AUDIO_PROFILE_SCALABLE_LEVEL_3 = 0x1a,
+ MPEG4_AUDIO_PROFILE_SCALABLE_LEVEL_4 = 0x1b,
+
+ MPEG4_AUDIO_PROFILE_SPEECH_LEVEL_1 = 0x20,
+ MPEG4_AUDIO_PROFILE_SPEECH_LEVEL_2 = 0x21,
+
+ MPEG4_AUDIO_PROFILE_SYNTHESIS_LEVEL_1 = 0x28,
+ MPEG4_AUDIO_PROFILE_SYNTHESIS_LEVEL_2 = 0x29,
+ MPEG4_AUDIO_PROFILE_SYNTHESIS_LEVEL_3 = 0x2a,
+
+ MPEG4_AUDIO_PROFILE_HQ_LEVEL_1 = 0x30,
+ MPEG4_AUDIO_PROFILE_HQ_LEVEL_2 = 0x31,
+ MPEG4_AUDIO_PROFILE_HQ_LEVEL_3 = 0x32,
+ MPEG4_AUDIO_PROFILE_HQ_LEVEL_4 = 0x33,
+ MPEG4_AUDIO_PROFILE_HQ_LEVEL_5 = 0x34,
+ MPEG4_AUDIO_PROFILE_HQ_LEVEL_6 = 0x35,
+ MPEG4_AUDIO_PROFILE_HQ_LEVEL_7 = 0x36,
+ MPEG4_AUDIO_PROFILE_HQ_LEVEL_8 = 0x37,
+
+ MPEG4_AUDIO_PROFILE_LOW_DELAY_LEVEL_1 = 0x38,
+ MPEG4_AUDIO_PROFILE_LOW_DELAY_LEVEL_2 = 0x39,
+ MPEG4_AUDIO_PROFILE_LOW_DELAY_LEVEL_3 = 0x3a,
+ MPEG4_AUDIO_PROFILE_LOW_DELAY_LEVEL_4 = 0x3b,
+ MPEG4_AUDIO_PROFILE_LOW_DELAY_LEVEL_5 = 0x3c,
+ MPEG4_AUDIO_PROFILE_LOW_DELAY_LEVEL_6 = 0x3d,
+ MPEG4_AUDIO_PROFILE_LOW_DELAY_LEVEL_7 = 0x3e,
+ MPEG4_AUDIO_PROFILE_LOW_DELAY_LEVEL_8 = 0x3f,
+
+ MPEG4_AUDIO_PROFILE_NATURAL_LEVEL_1 = 0x40,
+ MPEG4_AUDIO_PROFILE_NATURAL_LEVEL_2 = 0x41,
+ MPEG4_AUDIO_PROFILE_NATURAL_LEVEL_3 = 0x42,
+ MPEG4_AUDIO_PROFILE_NATURAL_LEVEL_4 = 0x43,
+
+ MPEG4_AUDIO_PROFILE_MOBILE_LEVEL_1 = 0x48,
+ MPEG4_AUDIO_PROFILE_MOBILE_LEVEL_2 = 0x49,
+ MPEG4_AUDIO_PROFILE_MOBILE_LEVEL_3 = 0x4a,
+ MPEG4_AUDIO_PROFILE_MOBILE_LEVEL_4 = 0x4b,
+ MPEG4_AUDIO_PROFILE_MOBILE_LEVEL_5 = 0x4c,
+ MPEG4_AUDIO_PROFILE_MOBILE_LEVEL_6 = 0x4d,
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/video_stream_descriptor.h b/lib/libucsi/mpeg/video_stream_descriptor.h
new file mode 100644
index 0000000..14e9196
--- /dev/null
+++ b/lib/libucsi/mpeg/video_stream_descriptor.h
@@ -0,0 +1,101 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_VIDEO_STREAM_DESCRIPTOR
+#define _UCSI_MPEG_VIDEO_STREAM_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+#include <libucsi/endianops.h>
+
+/**
+ * The mpeg_video_stream_descriptor structure
+ */
+struct mpeg_video_stream_descriptor {
+ struct descriptor d;
+
+ EBIT5(uint8_t multiple_frame_rate_flag : 1; ,
+ uint8_t frame_rate_code : 4; ,
+ uint8_t mpeg_1_only_flag : 1; ,
+ uint8_t constrained_parameter_flag : 1; ,
+ uint8_t still_picture_flag : 1; );
+ /* if (mpeg_1_only_flag == 0) struct mpeg_video_stream_extra extra */
+} __ucsi_packed;
+
+/**
+ * The mpeg_video_stream_extra - only present in non-MPEG1-only streams.
+ */
+struct mpeg_video_stream_extra {
+ uint8_t profile_and_level_indication;
+ EBIT3(uint8_t chroma_format : 2; ,
+ uint8_t frame_rate_extension : 1; ,
+ uint8_t reserved : 5; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_video_stream_descriptor structure.
+ *
+ * @param d Pointer to the generic descriptor structure.
+ * @return Pointer to the mpeg_video_stream_descriptor, or NULL on error.
+ */
+static inline struct mpeg_video_stream_descriptor*
+ mpeg_video_stream_descriptor_codec(struct descriptor* d)
+{
+ struct mpeg_video_stream_descriptor* vsd =
+ (struct mpeg_video_stream_descriptor*) d;
+
+ if (d->len < (sizeof(struct mpeg_video_stream_descriptor) - 2))
+ return NULL;
+
+ if (!vsd->mpeg_1_only_flag) {
+ if (d->len != (sizeof(struct mpeg_video_stream_descriptor) +
+ sizeof(struct mpeg_video_stream_extra) - 2))
+ return NULL;
+ }
+
+ return (struct mpeg_video_stream_descriptor*) d;
+}
+
+/**
+ * Get a pointer to the mpeg_video_stream_extra structure.
+ *
+ * @param d Pointer to the mpeg_video_stream_descriptor structure.
+ * @return Pointer to the mpeg_video_stream_extra structure, or NULL on error.
+ */
+static inline struct mpeg_video_stream_extra*
+ mpeg_video_stream_descriptor_extra(struct mpeg_video_stream_descriptor* d)
+{
+ if (d->mpeg_1_only_flag != 0)
+ return NULL;
+
+ return (struct mpeg_video_stream_extra*)
+ ((uint8_t*) d + sizeof(struct mpeg_video_stream_descriptor));
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/mpeg/video_window_descriptor.h b/lib/libucsi/mpeg/video_window_descriptor.h
new file mode 100644
index 0000000..a9a63c7
--- /dev/null
+++ b/lib/libucsi/mpeg/video_window_descriptor.h
@@ -0,0 +1,64 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_MPEG_VIDEO_WINDOW_DESCRIPTOR
+#define _UCSI_MPEG_VIDEO_WINDOW_DESCRIPTOR 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/descriptor.h>
+
+/**
+ * mpeg_video_window_descriptor structure.
+ */
+struct mpeg_video_window_descriptor {
+ struct descriptor d;
+
+ EBIT3(uint32_t horizontal_offset : 14; ,
+ uint32_t vertical_offset : 14; ,
+ uint32_t window_priority : 4; );
+} __ucsi_packed;
+
+/**
+ * Process an mpeg_video_window_descriptor.
+ *
+ * @param d Pointer to the generic descriptor structure.
+ * @return Pointer to the mpeg_video_window_descriptor structure, or NULL on error.
+ */
+static inline struct mpeg_video_window_descriptor*
+ mpeg_video_window_descriptor_codec(struct descriptor* d)
+{
+ if (d->len != (sizeof(struct mpeg_video_window_descriptor) - 2))
+ return NULL;
+
+ bswap32((uint8_t*) d + 2);
+
+ return (struct mpeg_video_window_descriptor*) d;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/section.h b/lib/libucsi/section.h
new file mode 100644
index 0000000..53ad07f
--- /dev/null
+++ b/lib/libucsi/section.h
@@ -0,0 +1,253 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_SECTION_H
+#define _UCSI_SECTION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/endianops.h>
+#include <libucsi/descriptor.h>
+#include <libucsi/crc32.h>
+#include <stdint.h>
+#include <string.h>
+
+#define CRC_SIZE 4
+
+
+/**
+ * Generic section header.
+ */
+struct section {
+ uint8_t table_id;
+ EBIT4(uint16_t syntax_indicator : 1; ,
+ uint16_t private_indicator : 1; , /* 2.4.4.10 */
+ uint16_t reserved : 2; ,
+ uint16_t length :12; );
+} __ucsi_packed;
+
+/**
+ * Generic extended section header structure.
+ */
+struct section_ext {
+ uint8_t table_id;
+ EBIT4(uint16_t syntax_indicator : 1; ,
+ uint16_t private_indicator : 1; , /* 2.4.4.10 */
+ uint16_t reserved : 2; ,
+ uint16_t length :12; );
+
+ uint16_t table_id_ext;
+ EBIT3(uint8_t reserved1 : 2; ,
+ uint8_t version_number : 5; ,
+ uint8_t current_next_indicator : 1; );
+ uint8_t section_number;
+ uint8_t last_section_number;
+} __ucsi_packed;
+
+/**
+ * Structure for keeping track of sections of a PSI table.
+ */
+struct psi_table_state {
+ uint8_t version_number;
+ uint16_t next_section_number;
+ uint8_t complete:1;
+ uint8_t new_table:1;
+} __ucsi_packed;
+
+
+/**
+ * Determine the total length of a section, including the header.
+ *
+ * @param section The parsed section structure.
+ * @return The length.
+ */
+static inline size_t section_length(struct section *section)
+{
+ return section->length + sizeof(struct section);
+}
+
+/**
+ * Determine the total length of an extended section, including the header,
+ * but omitting the CRC.
+ *
+ * @param section The parsed section_ext structure.
+ * @return The length.
+ */
+static inline size_t section_ext_length(struct section_ext * section)
+{
+ return section->length + sizeof(struct section) - CRC_SIZE;
+}
+
+/**
+ * Process a section structure in-place.
+ *
+ * @param buf Pointer to the data.
+ * @param len Length of data.
+ * @return Pointer to the section structure, or NULL if invalid.
+ */
+static inline struct section * section_codec(uint8_t * buf, size_t len)
+{
+ struct section * ret = (struct section *)buf;
+
+ if (len < 3)
+ return NULL;
+
+ bswap16(buf+1);
+
+ if (len != ret->length + 3U)
+ return NULL;
+
+ return ret;
+}
+
+/**
+ * Some sections have a CRC even though they are not section_exts.
+ * This function is to allow checking of them.
+ *
+ * @param section Pointer to the processed section structure.
+ * @return Nonzero on error, or 0 if the CRC was correct.
+ */
+static inline int section_check_crc(struct section *section)
+{
+ uint8_t * buf = (uint8_t *) section;
+ size_t len = section_length(section);
+ uint32_t crc;
+
+ /* the crc check has to be performed on the unswapped data */
+ bswap16(buf+1);
+ crc = crc32(CRC32_INIT, buf, len);
+ bswap16(buf+1);
+
+ /* the crc check includes the crc value,
+ * the result should therefore be zero.
+ */
+ if (crc)
+ return -1;
+ return 0;
+}
+
+
+/**
+ * Decode an extended section structure.
+ *
+ * @param section Pointer to the processed section structure.
+ * @param check_crc If 1, the CRC of the section will also be checked.
+ * @return Pointer to the parsed section_ext structure, or NULL if invalid.
+ */
+static inline struct section_ext * section_ext_decode(struct section * section,
+ int check_crc)
+{
+ if (section->syntax_indicator == 0)
+ return NULL;
+
+ if (check_crc) {
+ if (section_check_crc(section))
+ return NULL;
+ }
+
+ bswap16((uint8_t *)section + sizeof(struct section));
+
+ return (struct section_ext *)section;
+}
+
+/**
+ * Encode an extended section structure for transmission.
+ *
+ * @param section Pointer to the section_ext structure.
+ * @param update_crc If 1, the CRC of the section will also be updated.
+ * @return Pointer to the encoded section_ext structure, or NULL if invalid.
+ */
+static inline struct section_ext * section_ext_encode(struct section_ext* section,
+ int update_crc)
+{
+ if (section->syntax_indicator == 0)
+ return NULL;
+
+ bswap16((uint8_t *)section + sizeof(struct section));
+
+ if (update_crc) {
+ uint8_t * buf = (uint8_t *) section;
+ int len = sizeof(struct section) + section->length;
+ uint32_t crc;
+
+ /* the crc has to be performed on the swapped data */
+ bswap16(buf+1);
+ crc = crc32(CRC32_INIT, buf, len-4);
+ bswap16(buf+1);
+
+ /* update the CRC */
+ *((uint32_t*) (buf+len-4)) = crc;
+ bswap32(buf+len-4);
+ }
+
+ return (struct section_ext *)section;
+}
+
+/**
+ * Reset a psi_table_state structure.
+ *
+ * @param tstate The structure to reset.
+ */
+static inline void psi_table_state_reset(struct psi_table_state *tstate)
+{
+ tstate->version_number = 0xff;
+}
+
+/**
+ * Check if a supplied section_ext is something we want to process.
+ *
+ * @param section The parsed section_ext structure.
+ * @param tstate The state structure for this PSI table.
+ * @return 0=> not useful. nonzero => useful.
+ */
+static inline int section_ext_useful(struct section_ext *section, struct psi_table_state *tstate)
+{
+ if ((section->version_number == tstate->version_number) && tstate->complete)
+ return 0;
+ if (section->version_number != tstate->version_number) {
+ if (section->section_number != 0)
+ return 0;
+
+ tstate->next_section_number = 0;
+ tstate->complete = 0;
+ tstate->version_number = section->version_number;
+ tstate->new_table = 1;
+ } else if (section->section_number == tstate->next_section_number) {
+ tstate->new_table = 0;
+ } else {
+ return 0;
+ }
+
+ tstate->next_section_number++;
+ if (section->last_section_number < tstate->next_section_number) {
+ tstate->complete = 1;
+ }
+
+ return 1;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/section_buf.c b/lib/libucsi/section_buf.c
new file mode 100644
index 0000000..35d465e
--- /dev/null
+++ b/lib/libucsi/section_buf.c
@@ -0,0 +1,173 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <errno.h>
+#include <string.h>
+#include "section_buf.h"
+
+#define SECTION_HDR_SIZE 3
+#define SECTION_PAD 0xff
+
+int section_buf_init(struct section_buf *section, int max)
+{
+ if (max < SECTION_HDR_SIZE)
+ return -EINVAL;
+
+ memset(section, 0, sizeof(struct section_buf));
+ section->max = max; /* max size of data */
+ section->len = SECTION_HDR_SIZE;
+ section->wait_pdu = 1;
+
+ return 0;
+}
+
+int section_buf_add(struct section_buf *section, uint8_t* frag, int len, int *section_status)
+{
+ int copy;
+ int used = 0;
+ uint8_t *data;
+ uint8_t *pos = (uint8_t*) section + sizeof(struct section_buf) + section->count;
+
+ /* have we finished? */
+ if (section->header && (section->len == section->count)) {
+ *section_status = 1;
+ return 0;
+ }
+
+ /* skip over section padding bytes */
+ *section_status = 0;
+ if (section->count == 0) {
+ while(len && (*frag == SECTION_PAD)) {
+ frag++;
+ len--;
+ used++;
+ }
+
+ if (len == 0)
+ return used;
+ }
+
+ /* grab the header to get the section length */
+ if (!section->header) {
+ /* copy the header frag */
+ copy = SECTION_HDR_SIZE - section->count;
+ if (copy > len)
+ copy = len;
+ memcpy(pos, frag, copy);
+ section->count += copy;
+ pos += copy;
+ frag += copy;
+ used += copy;
+ len -= copy;
+
+ /* we need 3 bytes for the section header */
+ if (section->count != SECTION_HDR_SIZE)
+ return used;
+
+ /* work out the length & check it isn't too big */
+ data = (uint8_t*) section + sizeof(struct section_buf);
+ section->len = SECTION_HDR_SIZE + (((data[1] & 0x0f) << 8) | data[2]);
+ if (section->len > section->max) {
+ *section_status = -ERANGE;
+ return len + used;
+ }
+
+ /* update fields */
+ section->header = 1;
+ }
+
+ /* accumulate frag */
+ copy = section->len - section->count;
+ if (copy > len)
+ copy = len;
+ memcpy(pos, frag, copy);
+ section->count += copy;
+ used += copy;
+
+ /* have we finished? */
+ if (section->header && (section->len == section->count))
+ *section_status = 1;
+
+ /* return number of bytes used */
+ return used;
+}
+
+int section_buf_add_transport_payload(struct section_buf *section,
+ uint8_t* payload, int len,
+ int pdu_start, int *section_status)
+{
+ int used = 0;
+ int tmp;
+
+ /* have we finished? */
+ if (section->header && (section->len == section->count)) {
+ *section_status = 1;
+ return 0;
+ }
+
+ /* don't bother if we're waiting for a PDU */
+ *section_status = 0;
+ if (section->wait_pdu && (!pdu_start))
+ return len;
+
+ /* if we're at a PDU start, we need extra handling for the extra first
+ * byte giving the offset to the start of the next section. */
+ if (pdu_start) {
+ /* we have received a pdu */
+ section->wait_pdu = 0;
+
+ /* work out the offset to the _next_ payload */
+ int offset = payload[0];
+ if ((offset+1) > len) {
+ section->wait_pdu = 1;
+ *section_status = -EINVAL;
+ return len;
+ }
+
+ /* accumulate the end if we need to */
+ if (section->count != 0) {
+ /* add the final fragment. */
+ tmp = section_buf_add(section, payload + 1, offset, section_status);
+
+ /* the stream said this was the final fragment
+ * (PDU START bit) - check that it really was! */
+ if ((tmp != offset) || section_buf_remaining(section) || (*section_status != 1)) {
+ *section_status = -ERANGE;
+ section->wait_pdu = 1;
+ return 1 + tmp;
+ }
+
+ /* it is complete - return the number of bytes we used */
+ return 1 + tmp;
+ }
+
+ /* otherwise, we skip the end of the previous section, and
+ * start accumulating the new data. */
+ used = 1 + offset;
+ }
+
+ /* ok, just accumulate the data as normal */
+ tmp = section_buf_add(section, payload+used, len - used, section_status);
+ if (*section_status < 0) {
+ section->wait_pdu = 1;
+ }
+
+ return used + tmp;
+}
diff --git a/lib/libucsi/section_buf.h b/lib/libucsi/section_buf.h
new file mode 100644
index 0000000..52d2f84
--- /dev/null
+++ b/lib/libucsi/section_buf.h
@@ -0,0 +1,124 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_SECTION_BUF_H
+#define _UCSI_SECTION_BUF_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+#define DVB_MAX_SECTION_BYTES 4096
+
+/**
+ * Buffer used to keep track of section fragments. You should allocate an
+ * area of memory of size (sizeof(section_buf) + <maxsectionsize>), and pass that area
+ * to section_buf_init() to set it up.
+ */
+struct section_buf {
+ uint32_t max; /* maximum size of section - setup by section_buf_init() */
+ uint32_t count; /* number of bytes currently accumulated */
+ uint32_t len; /* total number of bytes expected in the complete section */
+ uint8_t header:1; /* flag indicating the section header has been commpletely received */
+ uint8_t wait_pdu:1;/* flag indicating to wait till the next PDU start */
+ /* uint8_t data[] */
+};
+
+/**
+ * Initialise a section_buf structure.
+ *
+ * @param section The section_buf to initialise.
+ * @param max Maximum number of bytes in section (must be > 3)
+ * @return 0 on success, nonzero on error.
+ */
+extern int section_buf_init(struct section_buf *section, int max);
+
+/**
+ * Reset a section_buf structure (e.g. if a discontinuity occurred). The
+ * section_buf will wait for the first PDU start indicator.
+ *
+ * @param section The section_buf to reset.
+ */
+static inline void section_buf_reset(struct section_buf *section)
+{
+ int tmp = section->wait_pdu;
+ section_buf_init(section, section->max);
+ section->wait_pdu = tmp;
+}
+
+/**
+ * Add a data fragment to a section_buf.
+ *
+ * @param section section_buf to add to.
+ * @param frag Pointer to data fragment.
+ * @param len Number of bytes of data.
+ * @param section_status 0: nothing special. 1: section complete. -ERANGE indicates that the
+ * section is larger than section->max.
+ * @return Number of bytes which were consumed.
+ */
+extern int section_buf_add(struct section_buf *section, uint8_t* frag, int len, int *section_status);
+
+/**
+ * Add a transport packet PSI payload to a section_buf. This takes into account
+ * the extra byte present in PDU_START flagged packets.
+ *
+ * @param section section_buf to add to.
+ * @param payload Pointer to packet payload data.
+ * @param len Number of bytes of data.
+ * @param pdu_start True if the payload_unit_start_indicator flag was set in the
+ * TS packet.
+ * @param section_status 0: nothing special. 1: section complete. -ERANGE indicates that the
+ * section is larger than section->max. -EINVAL indicates the pointer_field was completely
+ * invalid (too large).
+ */
+extern int section_buf_add_transport_payload(struct section_buf *section,
+ uint8_t* payload, int len,
+ int pdu_start, int *section_status);
+
+/**
+ * Get the number of bytes left to be received in a section_buf.
+ *
+ * @param section The section_buf concerned.
+ * @return The number of bytes.
+ */
+static inline int section_buf_remaining(struct section_buf *section)
+{
+ return section->len - section->count;
+}
+
+/**
+ * Return a pointer to the start of the data in the section_buf.
+ *
+ * @param section The section_buf concerned.
+ * @return The data.
+ */
+static inline uint8_t* section_buf_data(struct section_buf *section)
+{
+ return (uint8_t*) section + sizeof(struct section_buf);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/testrecord.txt b/lib/libucsi/testrecord.txt
new file mode 100644
index 0000000..84d56aa
--- /dev/null
+++ b/lib/libucsi/testrecord.txt
@@ -0,0 +1,146 @@
+libucsi test record. Anything without PASS is either not tested, or is
+currently broken.
+
+Testing means (a) ensure there are no segfaults etc. (b) dump the raw hex,
+decode it by hand, and check it matches the output.
+
+Sections:
+PASS mpeg/cat_section.h
+ mpeg/odsmt_section.h
+PASS mpeg/pat_section.h
+PASS mpeg/pmt_section.h
+ mpeg/tsdt_section.h
+ mpeg/metadata_section.h
+
+PASS dvb/bat_section.h
+ dvb/dit_section.h
+PASS dvb/eit_section.h
+ dvb/int_section.h
+PASS dvb/nit_section.h
+ dvb/rst_section.h
+PASS dvb/sdt_section.h
+ dvb/sit_section.h
+PASS dvb/st_section.h
+PASS dvb/tdt_section.h
+PASS dvb/tot_section.h
+ dvb/tva_container_section.h
+
+PASS atsc/cvct_section.h
+ atsc/dccsct_section.h
+ atsc/dcct_section.h
+PASS atsc/eit_section.h
+PASS atsc/ett_section.h
+PASS atsc/mgt_section.h
+ atsc/rrt_section.h
+PASS atsc/stt_section.h
+PASS atsc/tvct_section.h
+
+Descriptors:
+PASS mpeg/audio_stream_descriptor.h
+PASS mpeg/ca_descriptor.h
+ mpeg/content_labelling_descriptor.h
+PASS mpeg/copyright_descriptor.h
+PASS mpeg/data_stream_alignment_descriptor.h
+PASS mpeg/external_es_id_descriptor.h
+ mpeg/fmc_descriptor.h
+PASS mpeg/fmxbuffer_size_descriptor.h
+ mpeg/hierarchy_descriptor.h
+ mpeg/ibp_descriptor.h
+ mpeg/iod_descriptor.h
+PASS mpeg/iso_639_language_descriptor.h
+PASS mpeg/maximum_bitrate_descriptor.h
+ mpeg/metadata_descriptor.h
+ mpeg/metadata_pointer_descriptor.h
+ mpeg/metadata_std_descriptor.h
+ mpeg/mpeg4_audio_descriptor.h
+ mpeg/mpeg4_video_descriptor.h
+ mpeg/multiplex_buffer_descriptor.h
+PASS mpeg/multiplex_buffer_utilization_descriptor.h
+ mpeg/muxcode_descriptor.h
+PASS mpeg/private_data_indicator_descriptor.h
+PASS mpeg/registration_descriptor.h
+ mpeg/sl_descriptor.h
+PASS mpeg/smoothing_buffer_descriptor.h
+PASS mpeg/std_descriptor.h
+PASS mpeg/system_clock_descriptor.h
+ mpeg/target_background_grid_descriptor.h
+PASS mpeg/video_stream_descriptor.h
+ mpeg/video_window_descriptor.h
+
+ dvb/ac3_descriptor.h
+ dvb/adaptation_field_data_descriptor.h
+ dvb/ait_application_descriptor.h
+ dvb/ait_application_icons_descriptor.h
+ dvb/ait_application_name_descriptor.h
+ dvb/ait_external_application_authorisation_descriptor.h
+ dvb/ancillary_data_descriptor.h
+ dvb/announcement_support_descriptor.h
+ dvb/application_signalling_descriptor.h
+PASS dvb/bouquet_name_descriptor.h
+PASS dvb/ca_identifier_descriptor.h
+ dvb/cable_delivery_descriptor.h
+ dvb/cell_frequency_link_descriptor.h
+ dvb/cell_list_descriptor.h
+PASS dvb/component_descriptor.h
+PASS dvb/content_descriptor.h
+ dvb/content_identifier_descriptor.h
+ dvb/country_availability_descriptor.h
+ dvb/data_broadcast_descriptor.h
+PASS dvb/data_broadcast_id_descriptor.h
+ dvb/default_authority_descriptor.h
+ dvb/dsng_descriptor.h
+ dvb/extended_event_descriptor.h
+PASS dvb/frequency_list_descriptor.h
+PASS dvb/linkage_descriptor.h
+PASS dvb/local_time_offset_descriptor.h
+ dvb/mhp_data_broadcast_id_descriptor.h
+ dvb/mosaic_descriptor.h
+ dvb/multilingual_bouquet_name_descriptor.h
+PASS dvb/multilingual_component_descriptor.h
+ dvb/multilingual_network_name_descriptor.h
+ dvb/multilingual_service_name_descriptor.h
+PASS dvb/network_name_descriptor.h
+ dvb/nvod_reference_descriptor.h
+PASS dvb/parental_rating_descriptor.h
+ dvb/partial_transport_stream_descriptor.h
+ dvb/pdc_descriptor.h
+PASS dvb/private_data_specifier_descriptor.h
+ dvb/related_content_descriptor.h
+ dvb/rnt_rar_over_dvb_stream_descriptor.h
+ dvb/rnt_rar_over_ip_descriptor.h
+ dvb/rnt_rnt_scan_descriptor.h
+ dvb/s2_satellite_delivery_descriptor.h
+PASS dvb/satellite_delivery_descriptor.h
+ dvb/scrambling_descriptor.h
+ dvb/service_availablility_descriptor.h
+PASS dvb/service_descriptor.h
+ dvb/service_identifier_descriptor.h
+PASS dvb/service_list_descriptor.h
+ dvb/service_move_descriptor.h
+PASS dvb/short_event_descriptor.h
+ dvb/short_smoothing_buffer_descriptor.h
+PASS dvb/stream_identifier_descriptor.h
+PASS dvb/stuffing_descriptor.h
+PASS dvb/subtitling_descriptor.h
+ dvb/telephone_descriptor.h
+ dvb/teletext_descriptor.h
+PASS dvb/terrestrial_delivery_descriptor.h
+ dvb/time_shifted_event_descriptor.h
+ dvb/time_shifted_service_descriptor.h
+ dvb/transport_stream_descriptor.h
+ dvb/tva_id_descriptor.h
+ dvb/vbi_data_descriptor.h
+ dvb/vbi_teletext_descriptor.h
+
+PASS atsc/ac3_descriptor.h
+PASS atsc/caption_service_descriptor.h
+ atsc/component_name_descriptor.h
+PASS atsc/content_advisory_descriptor.h
+ atsc/dcc_arriving_request_descriptor.h
+ atsc/dcc_departing_request_descriptor.h
+PASS atsc/extended_channel_name_descriptor.h
+ atsc/genre_descriptor.h
+ atsc/rc_descriptor.h
+PASS atsc/service_location_descriptor.h
+PASS atsc/stuffing_descriptor.h
+ atsc/time_shifted_service_descriptor.h
diff --git a/lib/libucsi/transport_packet.c b/lib/libucsi/transport_packet.c
new file mode 100644
index 0000000..ca6c2e1
--- /dev/null
+++ b/lib/libucsi/transport_packet.c
@@ -0,0 +1,256 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "transport_packet.h"
+
+#define CONTINUITY_VALID 0x80
+#define CONTINUITY_DUPESEEN 0x40
+
+int transport_packet_values_extract(struct transport_packet *pkt,
+ struct transport_values *out,
+ enum transport_value extract)
+{
+ uint8_t *end = (uint8_t*) pkt + TRANSPORT_PACKET_LENGTH;
+ uint8_t *adapend;
+ uint8_t *pos = (uint8_t*) pkt + sizeof(struct transport_packet);
+ enum transport_value extracted = 0;
+ enum transport_adaptation_flags adapflags = 0;
+ enum transport_adaptation_extension_flags adapextflags = 0;
+ int adaplength = 0;
+ int adapextlength = 0;
+
+ /* does the packet contain an adaptation field ? */
+ if ((pkt->adaptation_field_control & 2) == 0)
+ goto extract_payload;
+
+ /* get the adaptation field length and skip the byte */
+ adaplength = *pos++;
+
+ /* do we actually have any adaptation data? */
+ if (adaplength == 0)
+ goto extract_payload;
+
+ /* sanity check */
+ adapend = pos + adaplength;
+ if (adapend > end)
+ return -1;
+
+ /* extract the adaptation flags (we must have at least 1 byte to be here) */
+ adapflags = *pos++;
+
+ /* do we actually want anything else? */
+ if ((extract & 0xffff) == 0)
+ goto extract_payload;
+
+ /* PCR? */
+ if (adapflags & transport_adaptation_flag_pcr) {
+ if ((pos+6) > adapend)
+ return -1;
+
+ if (extract & transport_value_pcr) {
+ uint64_t base = ((uint64_t) pos[0] << 25) |
+ ((uint64_t) pos[1] << 17) |
+ ((uint64_t) pos[2] << 9) |
+ ((uint64_t) pos[3] << 1) |
+ ((uint64_t) pos[4] >> 7);
+ uint64_t ext = (((uint64_t) pos[4] & 1) << 8) |
+ (uint64_t) pos[5];
+ out->pcr= base * 300ULL + ext;
+ extracted |= transport_value_pcr;
+ }
+ pos += 6;
+ }
+
+ /* OPCR? */
+ if (adapflags & transport_adaptation_flag_opcr) {
+ if ((pos+6) > adapend)
+ return -1;
+
+ if (extract & transport_value_opcr) {
+ uint64_t base = ((uint64_t) pos[0] << 25) |
+ ((uint64_t) pos[1] << 17) |
+ ((uint64_t) pos[2] << 9) |
+ ((uint64_t) pos[3] << 1) |
+ ((uint64_t) pos[4] >> 7);
+ uint64_t ext = (((uint64_t) pos[4] & 1) << 8) |
+ (uint64_t) pos[5];
+ out->opcr= base * 300ULL + ext;
+ extracted |= transport_value_opcr;
+ }
+ pos += 6;
+ }
+
+ /* splice countdown? */
+ if (adapflags & transport_adaptation_flag_splicing_point) {
+ if ((pos+1) > adapend)
+ return -1;
+
+ if (extract & transport_value_splice_countdown) {
+ out->splice_countdown = *pos;
+ extracted |= transport_value_splice_countdown;
+ }
+ pos++;
+ }
+
+ /* private data? */
+ if (adapflags & transport_adaptation_flag_private_data) {
+ if ((pos+1) > adapend)
+ return -1;
+ if ((pos+1+*pos) > adapend)
+ return -1;
+
+ if (extract & transport_value_private_data) {
+ out->private_data_length = *pos;
+ out->private_data = pos + 1;
+ extracted |= transport_value_private_data;
+ }
+ pos += 1 + *pos;
+ }
+
+ /* is there an adaptation extension? */
+ if (!(adapflags & transport_adaptation_flag_extension))
+ goto extract_payload;
+
+ /* get/check the length */
+ if (pos >= adapend)
+ return -1;
+ adapextlength = *pos++;
+ if ((pos + adapextlength) > adapend)
+ return -1;
+
+ /* do we want/have anything in the adaptation extension? */
+ if (((extract & 0xff00) == 0) || (adapextlength == 0))
+ goto extract_payload;
+
+ /* extract the adaptation extension flags (we must have at least 1 byte
+ * to be here) */
+ adapextflags = *pos++;
+
+ /* LTW? */
+ if (adapextflags & transport_adaptation_extension_flag_ltw) {
+ if ((pos+2) > adapend)
+ return -1;
+
+ if (extract & transport_value_ltw) {
+ if (*pos & 0x80) {
+ out->ltw_offset = ((pos[0] & 0x7f) << 8) |
+ (pos[1]);
+ extracted |= transport_value_ltw;
+ }
+ }
+ pos += 2;
+ }
+
+ /* piecewise_rate? */
+ if (adapextflags & transport_adaptation_extension_flag_piecewise_rate) {
+ if ((pos+3) > adapend)
+ return -1;
+
+ if (extract & transport_value_piecewise_rate) {
+ out->piecewise_rate = ((pos[0] & 0x3f) << 16) |
+ (pos[1] << 8) |
+ pos[2];
+ extracted |= transport_value_piecewise_rate;
+ }
+ pos += 3;
+ }
+
+ /* seamless_splice? */
+ if (adapextflags & transport_adaptation_extension_flag_seamless_splice) {
+ if ((pos+5) > adapend)
+ return -1;
+
+ if (extract & transport_value_piecewise_rate) {
+ out->splice_type = pos[0] >> 4;
+ out->dts_next_au = ((pos[0] & 0x0e) << 29) |
+ (pos[1] << 22) |
+ ((pos[2] & 0xfe) << 14) |
+ (pos[3] << 7) |
+ ((pos[4] & 0xfe) >> 1);
+ extracted |= transport_value_seamless_splice;
+ }
+ pos += 5;
+ }
+
+
+
+extract_payload:
+ /* does the packet contain a payload? */
+ if (pkt->adaptation_field_control & 1) {
+ int off = sizeof(struct transport_packet);
+ if (pkt->adaptation_field_control & 2)
+ off++;
+ off += adaplength;
+
+ out->payload = (uint8_t*) pkt + off;
+ out->payload_length = TRANSPORT_PACKET_LENGTH - off;
+ } else {
+ out->payload = NULL;
+ out->payload_length = 0;
+ }
+
+ out->flags = adapflags;
+ return extracted;
+}
+
+int transport_packet_continuity_check(struct transport_packet *pkt,
+ int discontinuity_indicator, unsigned char *cstate)
+{
+ unsigned char pktcontinuity = pkt->continuity_counter;
+ unsigned char prevcontinuity = *cstate & 0x0f;
+ unsigned char nextcontinuity;
+
+ /* NULL packets have undefined continuity */
+ if (transport_packet_pid(pkt) == TRANSPORT_NULL_PID)
+ return 0;
+
+ /* is the state valid? */
+ if (!(*cstate & CONTINUITY_VALID)) {
+ *cstate = pktcontinuity | CONTINUITY_VALID;
+ return 0;
+ }
+
+ /* check for discontinuity_indicator */
+ if (discontinuity_indicator) {
+ *cstate = pktcontinuity | CONTINUITY_VALID;
+ return 0;
+ }
+
+ /* only packets with a payload should increment the counter */
+ if (pkt->adaptation_field_control & 1)
+ nextcontinuity = (prevcontinuity + 1) & 0xf;
+ else
+ nextcontinuity = prevcontinuity;
+
+ /* check for a normal continuity progression */
+ if (nextcontinuity == pktcontinuity) {
+ *cstate = pktcontinuity | CONTINUITY_VALID;
+ return 0;
+ }
+
+ /* one dupe is allowed */
+ if ((prevcontinuity == pktcontinuity) && (!(*cstate & CONTINUITY_DUPESEEN))) {
+ *cstate = pktcontinuity | (CONTINUITY_VALID|CONTINUITY_DUPESEEN);
+ return 0;
+ }
+
+ /* continuity error */
+ return -1;
+}
diff --git a/lib/libucsi/transport_packet.h b/lib/libucsi/transport_packet.h
new file mode 100644
index 0000000..6314eca
--- /dev/null
+++ b/lib/libucsi/transport_packet.h
@@ -0,0 +1,195 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_TRANSPORT_PACKET_H
+#define _UCSI_TRANSPORT_PACKET_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+#include "descriptor.h"
+
+#define TRANSPORT_PACKET_LENGTH 188
+#define TRANSPORT_PACKET_SYNC 0x47
+#define TRANSPORT_MAX_PIDS 0x2000
+#define TRANSPORT_NULL_PID 0x1fff
+
+
+/**
+ * Enumeration of adaptation field control values.
+ */
+enum transport_adaptation_field_control {
+ transport_adaptation_field_control_reserved = 0x00,
+ transport_adaptation_field_control_payload_only = 0x01,
+ transport_adaptation_field_control_adaptation_only = 0x02,
+ transport_adaptation_field_control_adaptation_payload = 0x03,
+};
+
+/**
+ * Enumeration of scrambling control values.
+ */
+enum transport_scrambling_control {
+ transport_scrambling_control_unscrambled = 0x00,
+ transport_scrambling_control_user_1 = 0x01,
+ transport_scrambling_control_user_2 = 0x02,
+ transport_scrambling_control_user_3 = 0x03,
+};
+
+/**
+ * Enumeration of adaptation flags.
+ */
+enum transport_adaptation_flags {
+ transport_adaptation_flag_discontinuity = 0x80,
+ transport_adaptation_flag_random_access = 0x40,
+ transport_adaptation_flag_es_priority = 0x20,
+ transport_adaptation_flag_pcr = 0x10,
+ transport_adaptation_flag_opcr = 0x08,
+ transport_adaptation_flag_splicing_point = 0x04,
+ transport_adaptation_flag_private_data = 0x02,
+ transport_adaptation_flag_extension = 0x01,
+};
+
+/**
+ * Enumeration of adaptation extension flags.
+ */
+enum transport_adaptation_extension_flags {
+ transport_adaptation_extension_flag_ltw = 0x80,
+ transport_adaptation_extension_flag_piecewise_rate = 0x40,
+ transport_adaptation_extension_flag_seamless_splice = 0x20,
+};
+
+/**
+ * Enumeration of flags controlling which values to extract using the
+ * transport_packet_values_extract() function.
+ */
+enum transport_value {
+ /* normal adaptation */
+ transport_value_pcr = 0x0001,
+ transport_value_opcr = 0x0002,
+ transport_value_splice_countdown = 0x0004,
+ transport_value_private_data = 0x0008,
+
+ /* extension adaptation */
+ transport_value_ltw = 0x0100,
+ transport_value_piecewise_rate = 0x0200,
+ transport_value_seamless_splice = 0x0400,
+};
+
+/**
+ * Structure describing a transport packet header.
+ */
+struct transport_packet {
+ uint8_t sync_byte;
+ EBIT4(uint8_t transport_error_indicator : 1; ,
+ uint8_t payload_unit_start_indicator : 1; ,
+ uint8_t transport_priority : 1; ,
+ uint8_t pid_hi : 5; );
+ uint8_t pid_lo;
+ EBIT3(uint8_t transport_scrambling_control : 2; ,
+ uint8_t adaptation_field_control : 2; ,
+ uint8_t continuity_counter : 4; );
+ /* values */
+} __ucsi_packed;
+
+/**
+ * Structure to extract values into using the transport_packet_values_extract()
+ * function.
+ */
+struct transport_values {
+ enum transport_adaptation_flags flags; /* always extracted */
+ uint8_t *payload; /* always extracted */
+ uint16_t payload_length; /* always extracted */
+
+ uint64_t pcr;
+ uint64_t opcr;
+ uint8_t splice_countdown;
+ uint8_t private_data_length;
+ uint8_t *private_data;
+ uint16_t ltw_offset;
+ uint32_t piecewise_rate;
+ uint8_t splice_type;
+ uint64_t dts_next_au;
+};
+
+/**
+ * Extract the PID from a transport packet.
+ *
+ * @param pkt The packet.
+ * @return The PID.
+ */
+static inline int transport_packet_pid(struct transport_packet *pkt)
+{
+ return (pkt->pid_hi << 8) | (pkt->pid_lo);
+}
+
+/**
+ * Process a buffer into a transport packet.
+ *
+ * @param buf Raw buffer. Note, this function assumes there are 188 bytes available.
+ * @return transport_packet pointer, or NULL on error.
+ */
+static inline struct transport_packet *transport_packet_init(unsigned char *buf)
+{
+ struct transport_packet *pkt = (struct transport_packet*) buf;
+
+ if (pkt->sync_byte != TRANSPORT_PACKET_SYNC)
+ return NULL;
+
+ if (transport_packet_pid(pkt) >= TRANSPORT_MAX_PIDS)
+ return NULL;
+
+ return pkt;
+}
+
+/**
+ * Check the continuity counter for a packet in a PID stream.
+ *
+ * @param pkt transport_packet to check.
+ * @param discontinuity_indicator Set to 1 if the packet's discontinuity_indicator flag is set.
+ * @param cstate Pointer to a single 8 bit character, used to store state for validating
+ * continuity. To initialise the state, simply set it to 0 before the first call.
+ * @return 0 if the continuity was correct, or nonzero on error. cstate will not be updated on error,
+ * it is up to the caller to clear it to accept the next packet.
+ */
+extern int transport_packet_continuity_check(struct transport_packet *pkt,
+ int discontinuity_indicator, unsigned char *cstate);
+
+/**
+ * Extract selected fields from a transport packet.
+ *
+ * @param pkt The packet.
+ * @param out Destination structure for values.
+ * @param extract Orred bitmask of enum transport_value - tells it what fields
+ * to extract if they are available.
+ * @return < 0 => error. Otherwise, an orred bitmask of enum transport_value
+ * telling you what fields were successfully extracted.
+ */
+extern int transport_packet_values_extract(struct transport_packet *pkt,
+ struct transport_values *out,
+ enum transport_value extract);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libucsi/types.h b/lib/libucsi/types.h
new file mode 100644
index 0000000..b01d79a
--- /dev/null
+++ b/lib/libucsi/types.h
@@ -0,0 +1,36 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _UCSI_TYPES_H
+#define _UCSI_TYPES_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef uint8_t iso639lang_t[3];
+typedef uint8_t iso639country_t[3];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif