@@ -70,61 +70,67 @@ static int mpegts_probe(unsigned char *buf, int buf_size)
70
70
return -1 ;
71
71
}
72
72
73
+ struct section_parser
74
+ {
75
+ int total_len ;
76
+ uint8_t cc ;
77
+ uint8_t buffer [65535 ];
78
+ int32_t limit_len ;
79
+ };
80
+
73
81
// do memcpy if section length greater than one packet
74
82
int16_t section_preproc (uint16_t pid , uint8_t * pkt , uint16_t len , uint8_t * * buffering ,
75
83
uint8_t payload_unit_start_indicator , uint8_t continuity_counter , uint8_t psi_or_pes )
76
84
{
77
- static int total_len [8192 ] = { 0 };
78
- static uint8_t cc [8192 ] = { 0 };
79
- static uint8_t buffer [8192 ][65535 ];
80
- static int32_t limit_len [8192 ] = { 0 };
85
+ static struct section_parser sec [8192 ];
81
86
uint8_t pointer_field = 0 ;
87
+ struct section_parser * p = & sec [pid ];
82
88
* buffering = NULL ;
83
89
// indicate start of PES or PSI
84
90
if (payload_unit_start_indicator == 1 ) {
85
- cc [ pid ] = continuity_counter ;
91
+ p -> cc = continuity_counter ;
86
92
if (psi_or_pes == 0 ) // PSI
87
93
{
88
94
pointer_field = pkt [0 ];
89
95
/*skip pointer_field, valid for PSI and stream_type 0x05 private_sections*/
90
- total_len [ pid ] = len - 1 - pointer_field ;
91
- limit_len [ pid ] = (int32_t )(((int16_t )pkt [2 + pointer_field ] << 8 ) | pkt [3 + pointer_field ]) & 0x0FFF ;
92
- limit_len [ pid ] += 3 ;
96
+ p -> total_len = len - 1 - pointer_field ;
97
+ p -> limit_len = (int32_t )(((int16_t )pkt [2 + pointer_field ] << 8 ) | pkt [3 + pointer_field ]) & 0x0FFF ;
98
+ p -> limit_len += 3 ;
93
99
/*section in one pkt , go without buffering*/
94
- if (limit_len [ pid ] <= (total_len [ pid ] )) {
100
+ if (p -> limit_len <= (p -> total_len )) {
95
101
* buffering = (pkt + 1 + pointer_field );
96
- return limit_len [ pid ] ;
102
+ return p -> limit_len ;
97
103
} else {
98
- memset (buffer [ pid ] , 0 , 4096 ); // PSI length less than this
99
- memcpy (buffer [ pid ] , pkt + 1 + pointer_field , total_len [ pid ] );
104
+ memset (p -> buffer , 0 , 4096 ); // PSI length less than this
105
+ memcpy (p -> buffer , pkt + 1 + pointer_field , p -> total_len );
100
106
}
101
- } else {
102
- total_len [ pid ] = len ;
103
- limit_len [ pid ] = ((int32_t )pkt [4 ] << 8 | pkt [5 ]);
104
- if (limit_len [ pid ] == 0 ) {
107
+ } else { // PES
108
+ p -> total_len = len ;
109
+ p -> limit_len = ((int32_t )pkt [4 ] << 8 | pkt [5 ]);
110
+ if (p -> limit_len == 0 ) {
105
111
// for video stream, unlimit length
106
112
}
107
- limit_len [ pid ] += 6 ;
108
- if (limit_len [ pid ] <= (total_len [ pid ] )) {
113
+ p -> limit_len += 6 ;
114
+ if (p -> limit_len <= (p -> total_len )) {
109
115
* buffering = pkt ;
110
- return limit_len [ pid ] ;
116
+ return p -> limit_len ;
111
117
} else {
112
- memset (buffer [ pid ] , 0 , 65535 );
113
- memcpy (buffer [ pid ] , pkt , total_len [ pid ] );
118
+ memset (p -> buffer , 0 , 65535 );
119
+ memcpy (p -> buffer , pkt , p -> total_len );
114
120
}
115
121
}
116
122
117
123
} else {
118
124
// if(psi_or_pes==0)//PSI
119
125
{
120
- if (total_len [ pid ] == 0 )
126
+ if (p -> total_len == 0 )
121
127
return -1 ;
122
- memcpy (buffer [ pid ] + total_len [ pid ] , pkt , len );
123
- total_len [ pid ] += len ;
124
- if (total_len [ pid ] >= limit_len [ pid ] ) {
125
- * buffering = buffer [ pid ] ;
126
- total_len [ pid ] = 0 ;
127
- return limit_len [ pid ] ;
128
+ memcpy (p -> buffer + p -> total_len , pkt , len );
129
+ p -> total_len += len ;
130
+ if (p -> total_len >= p -> limit_len ) {
131
+ * buffering = p -> buffer ;
132
+ p -> total_len = 0 ;
133
+ return p -> limit_len ;
128
134
}
129
135
}
130
136
}
0 commit comments