- const int64_t i_pos_wanted = p_sys->i_pos + i_read;
-
- if( AStreamSeekStream( s, i_pos_wanted ) )
- {
- if( p_sys->i_pos != i_pos_wanted )
- return 0;
- }
- return i_read;
- }
- }
-
-#ifdef STREAM_DEBUG
- msg_Dbg( s, "AStreamReadStream: %d pos=%"PRId64" tk=%d start=%"PRId64
- " offset=%d end=%"PRId64,
- i_read, p_sys->i_pos, p_sys->stream.i_tk,
- tk->i_start, p_sys->stream.i_offset, tk->i_end );
-#endif
-
- while( i_data < i_read )
- {
- int i_off = (tk->i_start + p_sys->stream.i_offset) %
- STREAM_CACHE_TRACK_SIZE;
- unsigned int i_current =
- __MAX(0,__MIN( tk->i_end - tk->i_start - p_sys->stream.i_offset,
- STREAM_CACHE_TRACK_SIZE - i_off ));
- int i_copy = __MIN( i_current, i_read - i_data );
-
- if( i_copy <= 0 ) break; /* EOF */
-
- /* Copy data */
- /* msg_Dbg( s, "AStreamReadStream: copy %d", i_copy ); */
- if( p_data )
- {
- memcpy( p_data, &tk->p_buffer[i_off], i_copy );
- p_data += i_copy;
- }
- i_data += i_copy;
- p_sys->stream.i_offset += i_copy;
-
- /* Update pos now */
- p_sys->i_pos += i_copy;
-
- /* */
- p_sys->stream.i_used += i_copy;
-
- if( tk->i_end - tk->i_start - p_sys->stream.i_offset <= i_read -i_data )
- {
- const int i_read_requested = __MAX( __MIN( i_read - i_data,
- STREAM_READ_ATONCE * 10 ),
- STREAM_READ_ATONCE / 2 );
-
- if( p_sys->stream.i_used < i_read_requested )
- p_sys->stream.i_used = i_read_requested;
-
- if( AStreamRefillStream( s ) )
- {
- /* EOF */
- if( tk->i_start >= tk->i_end ) break;
- }