@@ -163,14 +163,14 @@ static void RemainFlush( stream_sys_t *p_sys )
163
163
164
164
#define ALL_READY (UNIT_SIZE_READY|ECM_READY|PMT_READY)
165
165
166
- static int DecoderRead ( stream_t * p_stream , uint8_t * p_dst , int i_toread )
166
+ static ssize_t Read ( stream_t * p_stream , void * p_buf , size_t i_toread )
167
167
{
168
168
stream_sys_t * p_sys = p_stream -> p_sys ;
169
- ARIB_STD_B25_BUFFER getbuf = { NULL , 0 } ;
169
+ uint8_t * p_dst = p_buf ;
170
170
int i_total_read = 0 ;
171
171
int i_ret ;
172
172
173
- if ( !p_dst || ! i_toread )
173
+ if ( !p_dst || !i_toread )
174
174
return -1 ;
175
175
176
176
/* Use data from previous reads */
@@ -179,71 +179,54 @@ static int DecoderRead( stream_t *p_stream, uint8_t *p_dst, int i_toread )
179
179
p_dst += i_fromremain ;
180
180
i_toread -= i_fromremain ;
181
181
182
- while ( i_toread )
182
+ while ( i_toread )
183
183
{
184
-
185
- do
184
+ /* make use of the existing buffer, overwritten by decoder data later */
185
+ int i_srcread = stream_Read ( p_stream -> p_source , p_dst , i_toread );
186
+ if ( i_srcread > 0 )
186
187
{
187
- getbuf .size = 0 ;
188
-
189
- i_ret = p_sys -> p_b25 -> get ( p_sys -> p_b25 , & getbuf );
188
+ ARIB_STD_B25_BUFFER putbuf = { p_dst , i_srcread };
189
+ i_ret = p_sys -> p_b25 -> put ( p_sys -> p_b25 , & putbuf );
190
190
if ( i_ret < 0 )
191
- msg_Err ( p_stream , "decoder get failed: %s" ,
192
- GetErrorMessage ( i_ret , b25_errors ) );
193
-
194
- /* If the decoders needs buffering or data is not ready, push some */
195
- if ( i_ret == 0 && getbuf .size == 0 )
196
191
{
197
- /* make use of the existing buffer,
198
- overwritten by decoder data later */
199
- int i_srcread = stream_Read ( p_stream -> p_source , p_dst , i_toread );
200
- if ( i_srcread > 0 )
201
- {
202
- ARIB_STD_B25_BUFFER putbuf = { p_dst , i_srcread };
203
- i_ret = p_sys -> p_b25 -> put ( p_sys -> p_b25 , & putbuf );
204
- if ( i_ret < 0 )
205
- msg_Err ( p_stream , "decoder put failed: %s" ,
206
- GetErrorMessage ( i_ret , b25_errors ) );
207
- }
208
- else
209
- {
210
- if ( i_srcread < 0 )
211
- msg_Err ( p_stream , "Can't read %d bytes from source stream: %d" , i_toread , i_srcread );
212
- i_ret = -1 ;
213
- }
192
+ msg_Err ( p_stream , "decoder put failed: %s" ,
193
+ GetErrorMessage ( i_ret , b25_errors ) );
194
+ return -1 ;
214
195
}
215
196
}
216
- while ( i_ret == 0 && getbuf .size == 0 );
197
+ else
198
+ {
199
+ if ( i_srcread < 0 )
200
+ msg_Err ( p_stream , "Can't read %lu bytes from source stream: %d" , i_toread , i_srcread );
201
+ return -1 ;
202
+ }
217
203
204
+ ARIB_STD_B25_BUFFER getbuf ;
205
+ i_ret = p_sys -> p_b25 -> get ( p_sys -> p_b25 , & getbuf );
218
206
if ( i_ret < 0 )
207
+ {
208
+ msg_Err ( p_stream , "decoder get failed: %s" ,
209
+ GetErrorMessage ( i_ret , b25_errors ) );
219
210
return -1 ;
211
+ }
220
212
221
- memcpy ( p_dst , getbuf .data , __MIN (getbuf .size , i_toread ) );
222
-
223
- if ( getbuf .size > i_toread )
213
+ if ( (size_t )getbuf .size > i_toread )
224
214
{
225
215
/* Hold remaining data for next call */
226
216
RemainAdd ( p_stream , getbuf .data + i_toread , getbuf .size - i_toread );
227
217
}
228
218
229
- i_total_read += __MIN (getbuf .size , i_toread );
230
- p_dst += __MIN (getbuf .size , i_toread );
231
- i_toread -= __MIN (getbuf .size , i_toread );
219
+ int consume = __MIN ( (size_t )getbuf .size , i_toread );
220
+ memcpy ( p_dst , getbuf .data , consume );
232
221
222
+ i_total_read += consume ;
223
+ p_dst += consume ;
224
+ i_toread -= consume ;
233
225
}
234
226
235
227
return i_total_read ;
236
228
}
237
229
238
- static ssize_t Read ( stream_t * p_stream , void * p_buf , size_t i_toread )
239
- {
240
- stream_sys_t * p_sys = p_stream -> p_sys ;
241
- int i_read = DecoderRead ( p_stream , p_buf , i_toread );
242
- if ( i_read < 0 )
243
- return -1 ;
244
- return i_read ;
245
- }
246
-
247
230
/**
248
231
*
249
232
*/
0 commit comments