summaryrefslogtreecommitdiff
path: root/include/gpac/internal/dvb_mpe_dev.h
blob: 084bb65844b8b1dc161e87ea50229c9bd531a177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
 *			GPAC - Multimedia Framework C SDK
 *
 *			Authors: Walid B.H - Jean Le Feuvre
 *			Copyright (c) Telecom ParisTech 2000-2012
 *					All rights reserved
 *
 *  This file is part of GPAC / MPEG2-TS sub-project
 *
 *  GPAC 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 gf_free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  GPAC 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; see the file COPYING.  If not, write to
 *  the gf_free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */


#ifndef _GF_DVB_MPE_DEV_H_
#define _GF_DVB_MPE_DEV_H_

#include <gpac/dvb_mpe.h>
#include <gpac/internal/reedsolomon.h>


#ifndef GPAC_DISABLE_MPEG2TS


/*INT object*/
typedef struct
{
	u32 id;
	u32 processing_order;
	u32 number_of_descriptor;
	GF_List * descriptors;

} GF_M2TS_INT;

typedef struct
{
	u32 tag;
	u32 length;
	u32 network_id;
	u32 original_network_id;
	u32 ts_id;
	u32 service_id;
	u32 component_tag;

} GF_M2TS_LOC_DSCPTR_IP_STREAM;

typedef struct descriptor_TimeSliceFec
{
	Bool time_slicing;
	u8 mpe_fec;
	u8 frame_size;
	u8 max_burst_duration;
	u8 max_average_rate;
	u8 time_slice_fec_id;
	u8 * id_selector;
} GF_M2TS_DesTimeSliceFec;

typedef struct
{
	u16	network_id;
	u16 original_network_id;
	u16 transport_stream_id;
	u16 service_id;
	u8 component_tag;
} GF_M2TS_DesLocation;

typedef struct {
	u8 type; /* 0 = target_IP_descriptor, 1 = target_IP_address_descriptor */
	u32 address_mask;
	u8 address[4];
	u8 slash_mask;
	u32 rx_port[10];   /* list of the address port */
} GF_M2TS_IP_Target;

typedef struct
{
	GF_List *targets; /* list of IP destination for the IP streams in the platform */
	u32 PID;
	Bool stream_info_gathered;

	/* location descriptor only valid for the associated targets */
	GF_M2TS_DesLocation location;

	GF_M2TS_DesTimeSliceFec time_slice_fec;
} GF_M2TS_IP_Stream;


/*IP_Platform object*/
typedef struct __gf_dvb_mpe_ip_platform
{
	/* remaining from INT, to be delete */
	u32 id;
	u32 processing_order;
	u32 number_of_descriptor;

	u8 *name; /* platform name */
	u8 *provider_name; /* platform provider name */

	/* location descriptor valid for the whole platform */
	GF_M2TS_DesLocation *location;

	GF_List * ip_streams;
	Bool all_info_gathered;
	GF_List *socket_struct;

} GF_M2TS_IP_PLATFORM;

typedef struct
{
	char *data;                        /* Data */
	u32 u32_version;                   /* IP version */
	u32 u32_hdr_length;                /* header length by piece of 4 bytes */
	u32 u32_total_length;              /* the length of the datagram (hdr+payload) in bytes */
	u32 u32_payload_size;              /* the length of the payload */
	u32 u32_id_nb;                     /* the number of the paquet, in case of frag */
	u32 u32_flag;                      /* if 010 unfrag packet, 100 fragmented packet, check the id_nb to know the packet number.
	                                      0 is the last one */
	u32 u32_frag_offset;               /* The offset position of this packet compare to the first packet. unit : 8 bytes */
	u32 u32_TTL;                       /* (Time To Live) when = 0 , the packet is ignored and error message */
	u32 u32_protocol;                  /* TCP = 6, UDP = 17, ICMP = 1 */
	u32 u32_crc;
	u8 u8_tx_adr[4];                   /* source address */
	u8 u8_rx_adr[4];                   /* destination address */
	u32 u32_size_option;               /* size of the option before payload */
	u32 u32_padding;                   /* = 1 if where read padding columns */
	u32 u32_sum;

	/* UDP */
	u32 u32_tx_udp_port;                /* source port */
	u32 u32_rx_udp_port;                /* destination port */
	u32 u32_udp_data_size;
	u32 u32_udp_chksm;
} GF_M2TS_IP_Packet;




#define MPE_ADT_COLS 191
#define MPE_RS_COLS NPAR

typedef struct mpe_error_holes
{
	u32 offset;
	u32 length;

} MPE_Error_Holes;

typedef struct mpe_fec_frame
{
	u32 rows;
	u32 col_adt ;
	u32 col_rs ;
	u8 *p_adt; /* pointer to the application data table*/
	u8 *p_rs;  /* pointer to the RS data table*/
	u32 *p_error_adt;
	u32 *p_error_rs ;

	u32 capacity_total;
	u32 current_offset_adt ;
	u32 current_offset_rs;
	u32 initialized ;
	u8  ADT_done;
	u32 PID;
	GF_List *mpe_holes;
	//u32 erasures [] p_erasures; /*pointer to the error indicators*/
} MPE_FEC_FRAME;


/* Get INT table */
void gf_m2ts_process_int(GF_M2TS_Demuxer *ts, GF_M2TS_SECTION_ES *ip_table, unsigned char *data, u32 data_size, u32 table_id);

void section_DSMCC_INT(GF_M2TS_IP_PLATFORM* ip_platform, u8 *data, u32 data_size);

u32  platform_descriptorDSMCC_INT_UNT  (GF_M2TS_IP_PLATFORM* ip_platform,u8 *data);
u32 dsmcc_pto_platform_descriptor_loop (GF_M2TS_IP_PLATFORM* ip_platform,u8 *data);

u32  descriptorDSMCC_INT_UNT  (GF_M2TS_IP_Stream *ip_str,u8 *data);
void descriptorDSMCC_target_IP_address ( GF_M2TS_IP_Stream *ip_str, u8 *data);
u32 dsmcc_pto_descriptor_loop (GF_M2TS_IP_Stream *ip_str, u8 *data);
void descriptorTime_slice_fec_identifier(GF_M2TS_IP_Stream *ip_str, u8 *data);
void gf_m2ts_target_ip( GF_M2TS_IP_Stream* ip_str, u8 *data);
void descriptorLocation(GF_M2TS_IP_Stream *ip_str , u8 *data);


void gf_ip_platform_descriptor(GF_M2TS_IP_PLATFORM* ip_platform, u8 *data);
void gf_ip_platform_provider_descriptor(GF_M2TS_IP_PLATFORM* ip_platform,u8 *data);
void gf_m2ts_ip_platform_init(GF_M2TS_IP_PLATFORM * ip_platform);

u32 gf_m2ts_ipdatagram_reader(u8 *datagram, GF_M2TS_IP_Packet *ip_packet, u32 offset);
void gf_m2ts_process_ipdatagram(MPE_FEC_FRAME *mff,GF_M2TS_Demuxer *ts);
Bool gf_m2ts_compare_ip(u8 rx_ip_address[4], u8 ip_address_bootstrap[4]);

struct _sock_entry
{
	u32 ipv4_addr;
	u16 port;
	GF_Socket *sock;
	Bool bind_failure;
};
struct tag_m2ts_section_mpe
{
	ABSTRACT_ES
	GF_M2TS_SectionFilter *sec;

	/* if this stream is an MPE section stream, we need:
	    - a direct access to the timeslice fec descriptor
		- an MPE FEC Frame Structure to process RS code */
	GF_M2TS_IP_Stream *ip_platform;
	MPE_FEC_FRAME *mff;

};


void gf_m2ts_process_mpe(GF_M2TS_Demuxer *ts, GF_M2TS_SECTION_MPE *mpe, unsigned char *data, u32 data_size, u8 table_id);
void gf_m2ts_gather_ipdatagram_information(MPE_FEC_FRAME *mff,GF_M2TS_Demuxer *ts);

void socket_simu(GF_M2TS_IP_Packet *ip_packet, GF_M2TS_Demuxer *ts, Bool yield);

void gf_m2ts_mpe_send_datagram(GF_M2TS_Demuxer *ts, u32 pid, unsigned char *data, u32 data_size);

/* allocate the necessary memory space*/
u32 init_frame(MPE_FEC_FRAME * mff, u32 rows);

void getRowFromADT(MPE_FEC_FRAME * mff,u32 index, u8 * adt_row);
void getRowFromRS(MPE_FEC_FRAME * mff,u32 index, u8 * rs_row);
void setRowRS(MPE_FEC_FRAME * mff,u32 index, u8 * p_rs);

/*return the number of errors and the position of the error in the row*/
void getErrorPositions(MPE_FEC_FRAME * mff, u32 row, u32 * errPositions);

void setColRS( MPE_FEC_FRAME * mff, u32 offset, u8 * pds, u32 length );
void getColRS(MPE_FEC_FRAME * mff, u32 offset, u8 * pds, u32 length);
void setIpDatagram(MPE_FEC_FRAME * mff,u32 offset, u8 * dgram, u32 length );

void setErrorIndicator(u32 * data , u32 offset1, u32 length  );
void resetMFF(MPE_FEC_FRAME * mff) ;
u32  getErrasurePositions( MPE_FEC_FRAME *mff , u32 row, u32 *errasures);

void decode_fec(MPE_FEC_FRAME * mff);


// Descriptor tag space/scope...
typedef enum {
	MPEG, DVB_SI,
	DSMCC_STREAM, DSMCC_CAROUSEL, DSMCC_INT_UNT, MHP_AIT, TVA_RNT
} DTAG_SCOPE;

void descriptor_PRIVATE (u8 *b, DTAG_SCOPE tag_scope, GF_List * descriptors );


#endif //GPAC_DISABLE_MPEG2TS

#endif	//_GF_DVB_MPE_DEV_H_