1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 1999-2004 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
27 #include "input_internal.h"
32 * - tune the 2 methods
33 * - compute cost for seek
34 * - improve stream mode seeking with closest segments
40 * One linked list of data read
42 * More complex scheme using mutliple track to avoid seeking
45 /* How many tracks we have, currently only used for stream mode */
46 #ifdef OPTIMIZE_MEMORY
47 # define STREAM_CACHE_TRACK 1
48 /* Max size of our cache 128Ko per track */
49 # define STREAM_CACHE_SIZE (STREAM_CACHE_TRACK*1024*128)
51 # define STREAM_CACHE_TRACK 3
52 /* Max size of our cache 4Mo per track */
53 # define STREAM_CACHE_SIZE (4*STREAM_CACHE_TRACK*1024*1024)
56 /* How many data we try to prebuffer */
57 #define STREAM_CACHE_PREBUFFER_SIZE (32767)
58 /* Maximum time we take to pre-buffer */
59 #define STREAM_CACHE_PREBUFFER_LENGTH (100*1000)
61 /* Method1: Simple, for pf_block.
62 * We get blocks and put them in the linked list.
63 * We release blocks once the total size is bigger than CACHE_BLOCK_SIZE
65 #define STREAM_DATA_WAIT 40000 /* Time between before a pf_block retry */
67 /* Method2: A bit more complex, for pf_read
68 * - We use ring buffers, only one if unseekable, all if seekable
69 * - Upon seek date current ring, then search if one ring match the pos,
70 * yes: switch to it, seek the access to match the end of the ring
71 * no: search the ring with i_end the closer to i_pos,
72 * if close enough, read data and use this ring
73 * else use the oldest ring, seek and use it.
75 * TODO: - with access non seekable: use all space available for only one ring, but
76 * we have to support seekable/non-seekable switch on the fly.
77 * - compute a good value for i_read_size
80 #define STREAM_READ_ATONCE 32767
81 #define STREAM_CACHE_TRACK_SIZE (STREAM_CACHE_SIZE/STREAM_CACHE_TRACK)
105 vlc_bool_t b_block; /* Block method (1) or stream */
107 int64_t i_pos; /* Current reading offset */
109 /* Method 1: pf_block */
112 int64_t i_start; /* Offset of block for p_first */
113 int i_offset; /* Offset for data in p_current */
114 block_t *p_current; /* Current block */
116 int i_size; /* Total amount of data in the list */
122 /* Method 2: for pf_read */
125 int i_offset; /* Buffer offset in the current track */
126 int i_tk; /* Current track */
127 stream_track_t tk[STREAM_CACHE_TRACK];
133 int i_used; /* Used since last read */
138 /* Peek temporary buffer */
142 /* Stat for both method */
145 vlc_bool_t b_fastseek; /* From access */
147 /* Stat about reading data */
148 int64_t i_read_count;
152 /* Stat about seek */
160 access_entry_t **list;
162 access_t *p_list_access;
164 /* Preparse mode ? */
169 static int AStreamReadBlock( stream_t *s, void *p_read, int i_read );
170 static int AStreamPeekBlock( stream_t *s, uint8_t **p_peek, int i_read );
171 static int AStreamSeekBlock( stream_t *s, int64_t i_pos );
172 static void AStreamPrebufferBlock( stream_t *s );
173 static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof );
176 static int AStreamReadStream( stream_t *s, void *p_read, int i_read );
177 static int AStreamPeekStream( stream_t *s, uint8_t **pp_peek, int i_read );
178 static int AStreamSeekStream( stream_t *s, int64_t i_pos );
179 static void AStreamPrebufferStream( stream_t *s );
180 static int AReadStream( stream_t *s, void *p_read, int i_read );
183 static int AStreamControl( stream_t *s, int i_query, va_list );
184 static void AStreamDestroy( stream_t *s );
185 static void UStreamDestroy( stream_t *s );
186 static int ASeek( stream_t *s, int64_t i_pos );
189 /****************************************************************************
190 * stream_UrlNew: create a stream from a access
191 ****************************************************************************/
192 stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
194 const char *psz_access, *psz_demux;
199 if( !psz_url ) return 0;
201 char psz_dup[strlen (psz_url) + 1];
202 strcpy (psz_dup, psz_url);;
203 MRLSplit( p_parent, psz_dup, &psz_access, &psz_demux, &psz_path );
205 /* Now try a real access */
206 p_access = access2_New( p_parent, psz_access, psz_demux, psz_path, 0 );
208 if( p_access == NULL )
210 msg_Err( p_parent, "no suitable access module for `%s'", psz_url );
214 if( !( p_res = stream_AccessNew( p_access, VLC_TRUE ) ) )
216 access2_Delete( p_access );
220 p_res->pf_destroy = UStreamDestroy;
224 stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick )
226 stream_t *s = vlc_object_create( p_access, VLC_OBJECT_STREAM );
230 if( !s ) return NULL;
232 /* Attach it now, needed for b_die */
233 vlc_object_attach( s, p_access );
236 s->pf_read = NULL; /* Set up later */
238 s->pf_control = AStreamControl;
239 s->pf_destroy = AStreamDestroy;
241 s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) );
243 /* UTF16 and UTF32 text file conversion */
245 s->b_little_endian = VLC_FALSE;
246 s->conv = (vlc_iconv_t)(-1);
249 p_sys->p_access = p_access;
250 p_sys->b_block = p_access->pf_block ? VLC_TRUE : VLC_FALSE;
251 p_sys->i_pos = p_access->info.i_pos;
254 access2_Control( p_access, ACCESS_CAN_FASTSEEK, &p_sys->stat.b_fastseek );
255 p_sys->stat.i_bytes = 0;
256 p_sys->stat.i_read_time = 0;
257 p_sys->stat.i_read_count = 0;
258 p_sys->stat.i_seek_count = 0;
259 p_sys->stat.i_seek_time = 0;
263 p_sys->i_list_index = 0;
264 p_sys->p_list_access = 0;
266 p_sys->b_quick = b_quick;
268 /* Get the additional list of inputs if any (for concatenation) */
269 if( (psz_list = var_CreateGetString( s, "input-list" )) && *psz_list )
271 access_entry_t *p_entry = malloc( sizeof(access_entry_t) );
272 char *psz_name, *psz_parser = psz_name = psz_list;
274 p_sys->p_list_access = p_access;
275 p_entry->i_size = p_access->info.i_size;
276 p_entry->psz_path = strdup( p_access->psz_path );
277 TAB_APPEND( p_sys->i_list, p_sys->list, p_entry );
278 msg_Dbg( p_access, "adding file `%s', ("I64Fd" bytes)",
279 p_entry->psz_path, p_access->info.i_size );
281 while( psz_name && *psz_name )
283 psz_parser = strchr( psz_name, ',' );
284 if( psz_parser ) *psz_parser = 0;
286 psz_name = strdup( psz_name );
289 access_t *p_tmp = access2_New( p_access, p_access->psz_access,
294 psz_name = psz_parser;
295 if( psz_name ) psz_name++;
299 msg_Dbg( p_access, "adding file `%s', ("I64Fd" bytes)",
300 psz_name, p_tmp->info.i_size );
302 p_entry = malloc( sizeof(access_entry_t) );
303 p_entry->i_size = p_tmp->info.i_size;
304 p_entry->psz_path = psz_name;
305 TAB_APPEND( p_sys->i_list, p_sys->list, p_entry );
307 access2_Delete( p_tmp );
310 psz_name = psz_parser;
311 if( psz_name ) psz_name++;
314 if( psz_list ) free( psz_list );
318 p_sys->p_peek = NULL;
322 s->pf_read = AStreamReadBlock;
323 s->pf_peek = AStreamPeekBlock;
325 /* Init all fields of p_sys->block */
326 p_sys->block.i_start = p_sys->i_pos;
327 p_sys->block.i_offset = 0;
328 p_sys->block.p_current = NULL;
329 p_sys->block.i_size = 0;
330 p_sys->block.p_first = NULL;
331 p_sys->block.pp_last = &p_sys->block.p_first;
333 /* Do the prebuffering */
334 AStreamPrebufferBlock( s );
336 if( p_sys->block.i_size <= 0 )
338 msg_Err( s, "cannot pre fill buffer" );
346 s->pf_read = AStreamReadStream;
347 s->pf_peek = AStreamPeekStream;
349 /* Allocate/Setup our tracks */
350 p_sys->stream.i_offset = 0;
351 p_sys->stream.i_tk = 0;
352 p_sys->stream.p_buffer = malloc( STREAM_CACHE_SIZE );
353 p_sys->stream.i_used = 0;
354 access2_Control( p_access, ACCESS_GET_MTU,
355 &p_sys->stream.i_read_size );
356 if( p_sys->stream.i_read_size <= 0 )
357 p_sys->stream.i_read_size = STREAM_READ_ATONCE;
358 else if( p_sys->stream.i_read_size <= 256 )
359 p_sys->stream.i_read_size = 256;
361 for( i = 0; i < STREAM_CACHE_TRACK; i++ )
363 p_sys->stream.tk[i].i_date = 0;
364 p_sys->stream.tk[i].i_start = p_sys->i_pos;
365 p_sys->stream.tk[i].i_end = p_sys->i_pos;
366 p_sys->stream.tk[i].p_buffer=
367 &p_sys->stream.p_buffer[i * STREAM_CACHE_TRACK_SIZE];
370 /* Do the prebuffering */
371 AStreamPrebufferStream( s );
373 if( p_sys->stream.tk[p_sys->stream.i_tk].i_end <= 0 )
375 msg_Err( s, "cannot pre fill buffer" );
389 free( p_sys->stream.p_buffer );
392 vlc_object_detach( s );
393 vlc_object_destroy( s );
397 /****************************************************************************
399 ****************************************************************************/
400 static void AStreamDestroy( stream_t *s )
402 stream_sys_t *p_sys = s->p_sys;
404 vlc_object_detach( s );
406 if( p_sys->b_block ) block_ChainRelease( p_sys->block.p_first );
407 else free( p_sys->stream.p_buffer );
409 if( p_sys->p_peek ) free( p_sys->p_peek );
411 if( p_sys->p_list_access && p_sys->p_list_access != p_sys->p_access )
412 access2_Delete( p_sys->p_list_access );
414 while( p_sys->i_list-- )
416 free( p_sys->list[p_sys->i_list]->psz_path );
417 free( p_sys->list[p_sys->i_list] );
418 if( !p_sys->i_list ) free( p_sys->list );
422 vlc_object_destroy( s );
425 static void UStreamDestroy( stream_t *s )
427 access_t *p_access = (access_t*)vlc_object_find( s, VLC_OBJECT_ACCESS, FIND_PARENT );
429 vlc_object_release( p_access );
430 access2_Delete( p_access );
433 /****************************************************************************
434 * stream_AccessReset:
435 ****************************************************************************/
436 void stream_AccessReset( stream_t *s )
438 stream_sys_t *p_sys = s->p_sys;
440 p_sys->i_pos = p_sys->p_access->info.i_pos;
444 block_ChainRelease( p_sys->block.p_first );
446 /* Init all fields of p_sys->block */
447 p_sys->block.i_start = p_sys->i_pos;
448 p_sys->block.i_offset = 0;
449 p_sys->block.p_current = NULL;
450 p_sys->block.i_size = 0;
451 p_sys->block.p_first = NULL;
452 p_sys->block.pp_last = &p_sys->block.p_first;
454 /* Do the prebuffering */
455 AStreamPrebufferBlock( s );
461 /* Setup our tracks */
462 p_sys->stream.i_offset = 0;
463 p_sys->stream.i_tk = 0;
464 p_sys->stream.i_used = 0;
466 for( i = 0; i < STREAM_CACHE_TRACK; i++ )
468 p_sys->stream.tk[i].i_date = 0;
469 p_sys->stream.tk[i].i_start = p_sys->i_pos;
470 p_sys->stream.tk[i].i_end = p_sys->i_pos;
473 /* Do the prebuffering */
474 AStreamPrebufferStream( s );
478 /****************************************************************************
479 * stream_AccessUpdate:
480 ****************************************************************************/
481 void stream_AccessUpdate( stream_t *s )
483 stream_sys_t *p_sys = s->p_sys;
485 p_sys->i_pos = p_sys->p_access->info.i_pos;
490 for( i = 0; i < p_sys->i_list_index; i++ )
492 p_sys->i_pos += p_sys->list[i]->i_size;
497 /****************************************************************************
499 ****************************************************************************/
500 static int AStreamControl( stream_t *s, int i_query, va_list args )
502 stream_sys_t *p_sys = s->p_sys;
503 access_t *p_access = p_sys->p_access;
506 int64_t *pi_64, i_64;
511 case STREAM_GET_SIZE:
512 pi_64 = (int64_t*)va_arg( args, int64_t * );
513 if( s->p_sys->i_list )
517 for( i = 0; i < s->p_sys->i_list; i++ )
518 *pi_64 += s->p_sys->list[i]->i_size;
521 *pi_64 = p_access->info.i_size;
524 case STREAM_CAN_SEEK:
525 p_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
526 access2_Control( p_access, ACCESS_CAN_SEEK, p_bool );
529 case STREAM_CAN_FASTSEEK:
530 p_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
531 access2_Control( p_access, ACCESS_CAN_FASTSEEK, p_bool );
534 case STREAM_GET_POSITION:
535 pi_64 = (int64_t*)va_arg( args, int64_t * );
536 *pi_64 = p_sys->i_pos;
539 case STREAM_SET_POSITION:
540 i_64 = (int64_t)va_arg( args, int64_t );
542 return AStreamSeekBlock( s, i_64 );
544 return AStreamSeekStream( s, i_64 );
549 case STREAM_CONTROL_ACCESS:
550 i_int = (int) va_arg( args, int );
551 if( i_int != ACCESS_SET_PRIVATE_ID_STATE &&
552 i_int != ACCESS_SET_PRIVATE_ID_CA &&
553 i_int != ACCESS_GET_PRIVATE_ID_STATE )
555 msg_Err( s, "Hey, what are you thinking ?"
556 "DON'T USE STREAM_CONTROL_ACCESS !!!" );
559 return access2_vaControl( p_access, i_int, args );
562 msg_Err( s, "invalid stream_vaControl query=0x%x", i_query );
570 /****************************************************************************
572 ****************************************************************************/
573 static void AStreamPrebufferBlock( stream_t *s )
575 stream_sys_t *p_sys = s->p_sys;
576 access_t *p_access = p_sys->p_access;
581 msg_Dbg( s, "pre buffering" );
585 int64_t i_date = mdate();
589 if( s->b_die || p_sys->block.i_size > STREAM_CACHE_PREBUFFER_SIZE ||
590 ( i_first > 0 && i_first + STREAM_CACHE_PREBUFFER_LENGTH < i_date ) )
595 p_sys->stat.i_bytes = p_sys->block.i_size;
596 p_sys->stat.i_read_time = i_date - i_start;
597 i_byterate = ( I64C(1000000) * p_sys->stat.i_bytes ) /
598 (p_sys->stat.i_read_time + 1);
600 msg_Dbg( s, "prebuffering done "I64Fd" bytes in "I64Fd"s - "
603 p_sys->stat.i_read_time / I64C(1000000),
609 if( ( b = AReadBlock( s, &b_eof ) ) == NULL )
613 msleep( STREAM_DATA_WAIT );
619 /* Append the block */
620 p_sys->block.i_size += b->i_buffer;
621 *p_sys->block.pp_last = b;
622 p_sys->block.pp_last = &b->p_next;
624 p_sys->stat.i_read_count++;
628 if( p_access->info.b_prebuffered )
630 /* Access has already prebufferred - update stats and exit */
631 p_sys->stat.i_bytes = p_sys->block.i_size;
632 p_sys->stat.i_read_time = mdate() - i_start;
639 msg_Dbg( s, "received first data for our buffer");
644 p_sys->block.p_current = p_sys->block.p_first;
647 static int AStreamRefillBlock( stream_t *s );
649 static int AStreamReadBlock( stream_t *s, void *p_read, int i_read )
651 stream_sys_t *p_sys = s->p_sys;
653 uint8_t *p_data= (uint8_t*)p_read;
657 if( p_sys->block.p_current == NULL )
662 /* seek within this stream if possible, else use plain old read and discard */
663 stream_sys_t *p_sys = s->p_sys;
664 access_t *p_access = p_sys->p_access;
666 access2_Control( p_access, ACCESS_CAN_SEEK, &b_aseek );
668 return AStreamSeekBlock( s, p_sys->i_pos + i_read ) ? 0 : i_read;
671 while( i_data < i_read )
674 p_sys->block.p_current->i_buffer - p_sys->block.i_offset;
675 int i_copy = __MIN( i_current, i_read - i_data);
681 &p_sys->block.p_current->p_buffer[p_sys->block.i_offset],
687 p_sys->block.i_offset += i_copy;
688 if( p_sys->block.i_offset >= p_sys->block.p_current->i_buffer )
690 /* Current block is now empty, switch to next */
691 if( p_sys->block.p_current )
693 p_sys->block.i_offset = 0;
694 p_sys->block.p_current = p_sys->block.p_current->p_next;
697 if( AStreamRefillBlock( s ) )
704 p_sys->i_pos += i_data;
708 static int AStreamPeekBlock( stream_t *s, uint8_t **pp_peek, int i_read )
710 stream_sys_t *p_sys = s->p_sys;
716 if( p_sys->block.p_current == NULL ) return 0; /* EOF */
718 /* We can directly give a pointer over our buffer */
719 if( i_read <= p_sys->block.p_current->i_buffer - p_sys->block.i_offset )
721 *pp_peek = &p_sys->block.p_current->p_buffer[p_sys->block.i_offset];
725 /* We need to create a local copy */
726 if( p_sys->i_peek < i_read )
728 p_sys->p_peek = realloc( p_sys->p_peek, i_read );
734 p_sys->i_peek = i_read;
737 /* Fill enough data */
738 while( p_sys->block.i_size - (p_sys->i_pos - p_sys->block.i_start)
741 block_t **pp_last = p_sys->block.pp_last;
743 if( AStreamRefillBlock( s ) ) break;
745 /* Our buffer are probably filled enough, don't try anymore */
746 if( pp_last == p_sys->block.pp_last ) break;
749 /* Copy what we have */
750 b = p_sys->block.p_current;
751 i_offset = p_sys->block.i_offset;
752 p_data = p_sys->p_peek;
754 while( b && i_data < i_read )
756 int i_current = b->i_buffer - i_offset;
757 int i_copy = __MIN( i_current, i_read - i_data );
759 memcpy( p_data, &b->p_buffer[i_offset], i_copy );
764 if( i_offset >= b->i_buffer )
771 *pp_peek = p_sys->p_peek;
775 static int AStreamSeekBlock( stream_t *s, int64_t i_pos )
777 stream_sys_t *p_sys = s->p_sys;
778 access_t *p_access = p_sys->p_access;
779 int64_t i_offset = i_pos - p_sys->block.i_start;
782 /* We already have thoses data, just update p_current/i_offset */
783 if( i_offset >= 0 && i_offset < p_sys->block.i_size )
785 block_t *b = p_sys->block.p_first;
788 while( i_current + b->i_buffer < i_offset )
790 i_current += b->i_buffer;
794 p_sys->block.p_current = b;
795 p_sys->block.i_offset = i_offset - i_current;
797 p_sys->i_pos = i_pos;
802 /* We may need to seek or to read data */
806 access2_Control( p_access, ACCESS_CAN_SEEK, &b_aseek );
810 msg_Err( s, "backward seeking impossible (access not seekable)" );
818 vlc_bool_t b_aseek, b_aseekfast;
820 access2_Control( p_access, ACCESS_CAN_SEEK, &b_aseek );
821 access2_Control( p_access, ACCESS_CAN_FASTSEEK, &b_aseekfast );
826 msg_Warn( s, I64Fd" bytes need to be skipped "
827 "(access non seekable)",
828 i_offset - p_sys->block.i_size );
832 int64_t i_skip = i_offset - p_sys->block.i_size;
834 /* Avg bytes per packets */
835 int i_avg = p_sys->stat.i_bytes / p_sys->stat.i_read_count;
836 /* TODO compute a seek cost instead of fixed threshold */
837 int i_th = b_aseekfast ? 1 : 5;
839 if( i_skip <= i_th * i_avg &&
840 i_skip < STREAM_CACHE_SIZE )
845 msg_Dbg( s, "b_seek=%d th*avg=%d skip="I64Fd,
846 b_seek, i_th*i_avg, i_skip );
852 int64_t i_start, i_end;
853 /* Do the access seek */
855 if( ASeek( s, i_pos ) ) return VLC_EGENERIC;
859 block_ChainRelease( p_sys->block.p_first );
862 p_sys->block.i_start = p_sys->i_pos = i_pos;
863 p_sys->block.i_offset = 0;
864 p_sys->block.p_current = NULL;
865 p_sys->block.i_size = 0;
866 p_sys->block.p_first = NULL;
867 p_sys->block.pp_last = &p_sys->block.p_first;
870 if( AStreamRefillBlock( s ) )
872 msg_Err( s, "cannot re fill buffer" );
876 p_sys->stat.i_seek_time += i_end - i_start;
877 p_sys->stat.i_seek_count++;
882 /* Read enough data */
883 while( p_sys->block.i_start + p_sys->block.i_size < i_pos )
885 if( AStreamRefillBlock( s ) )
887 msg_Err( s, "can't read enough data in seek" );
890 while( p_sys->block.p_current &&
891 p_sys->i_pos + p_sys->block.p_current->i_buffer < i_pos )
893 p_sys->i_pos += p_sys->block.p_current->i_buffer;
894 p_sys->block.p_current = p_sys->block.p_current->p_next;
898 p_sys->block.i_offset = i_pos - p_sys->i_pos;
899 p_sys->i_pos = i_pos;
908 static int AStreamRefillBlock( stream_t *s )
910 stream_sys_t *p_sys = s->p_sys;
911 int64_t i_start, i_stop;
915 while( p_sys->block.i_size >= STREAM_CACHE_SIZE &&
916 p_sys->block.p_first != p_sys->block.p_current )
918 block_t *b = p_sys->block.p_first;
920 p_sys->block.i_start += b->i_buffer;
921 p_sys->block.i_size -= b->i_buffer;
922 p_sys->block.p_first = b->p_next;
926 if( p_sys->block.i_size >= STREAM_CACHE_SIZE &&
927 p_sys->block.p_current == p_sys->block.p_first &&
928 p_sys->block.p_current->p_next ) /* At least 2 packets */
930 /* Enough data, don't read more */
934 /* Now read a new block */
940 if( s->b_die ) return VLC_EGENERIC;
944 if( ( b = AReadBlock( s, &b_eof ) ) ) break;
946 if( b_eof ) return VLC_EGENERIC;
948 msleep( STREAM_DATA_WAIT );
955 /* Append the block */
956 p_sys->block.i_size += b->i_buffer;
957 *p_sys->block.pp_last = b;
958 p_sys->block.pp_last = &b->p_next;
961 if( p_sys->block.p_current == NULL )
962 p_sys->block.p_current = b;
965 p_sys->stat.i_bytes += b->i_buffer;
966 p_sys->stat.i_read_time += i_stop - i_start;
967 p_sys->stat.i_read_count++;
976 /****************************************************************************
978 ****************************************************************************/
979 static int AStreamRefillStream( stream_t *s );
981 static int AStreamReadStream( stream_t *s, void *p_read, int i_read )
983 stream_sys_t *p_sys = s->p_sys;
984 stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
986 uint8_t *p_data = (uint8_t *)p_read;
989 if( tk->i_start >= tk->i_end ) return 0; /* EOF */
993 /* seek within this stream if possible, else use plain old read and discard */
994 stream_sys_t *p_sys = s->p_sys;
995 access_t *p_access = p_sys->p_access;
997 access2_Control( p_access, ACCESS_CAN_SEEK, &b_aseek );
999 return AStreamSeekStream( s, p_sys->i_pos + i_read ) ? 0 : i_read;
1003 msg_Dbg( s, "AStreamReadStream: %d pos="I64Fd" tk=%d start="I64Fd
1004 " offset=%d end="I64Fd,
1005 i_read, p_sys->i_pos, p_sys->stream.i_tk,
1006 tk->i_start, p_sys->stream.i_offset, tk->i_end );
1009 while( i_data < i_read )
1011 int i_off = (tk->i_start + p_sys->stream.i_offset) %
1012 STREAM_CACHE_TRACK_SIZE;
1014 __MIN( tk->i_end - tk->i_start - p_sys->stream.i_offset,
1015 STREAM_CACHE_TRACK_SIZE - i_off );
1016 int i_copy = __MIN( i_current, i_read - i_data );
1018 if( i_copy <= 0 ) break; /* EOF */
1021 /* msg_Dbg( s, "AStreamReadStream: copy %d", i_copy ); */
1024 memcpy( p_data, &tk->p_buffer[i_off], i_copy );
1028 p_sys->stream.i_offset += i_copy;
1030 /* Update pos now */
1031 p_sys->i_pos += i_copy;
1034 p_sys->stream.i_used += i_copy;
1035 if( tk->i_start + p_sys->stream.i_offset >= tk->i_end ||
1036 p_sys->stream.i_used >= p_sys->stream.i_read_size )
1038 if( AStreamRefillStream( s ) )
1041 if( tk->i_start >= tk->i_end ) break;
1049 static int AStreamPeekStream( stream_t *s, uint8_t **pp_peek, int i_read )
1051 stream_sys_t *p_sys = s->p_sys;
1052 stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
1055 if( tk->i_start >= tk->i_end ) return 0; /* EOF */
1058 msg_Dbg( s, "AStreamPeekStream: %d pos="I64Fd" tk=%d "
1059 "start="I64Fd" offset=%d end="I64Fd,
1060 i_read, p_sys->i_pos, p_sys->stream.i_tk,
1061 tk->i_start, p_sys->stream.i_offset, tk->i_end );
1064 /* Avoid problem, but that should *never* happen */
1065 if( i_read > STREAM_CACHE_TRACK_SIZE / 2 )
1066 i_read = STREAM_CACHE_TRACK_SIZE / 2;
1068 while( tk->i_end - tk->i_start - p_sys->stream.i_offset < i_read )
1070 if( p_sys->stream.i_used <= 1 )
1072 /* Be sure we will read something */
1073 p_sys->stream.i_used += i_read -
1074 (tk->i_end - tk->i_start - p_sys->stream.i_offset);
1076 if( AStreamRefillStream( s ) ) break;
1079 if( tk->i_end - tk->i_start - p_sys->stream.i_offset < i_read )
1080 i_read = tk->i_end - tk->i_start - p_sys->stream.i_offset;
1082 /* Now, direct pointer or a copy ? */
1083 i_off = (tk->i_start + p_sys->stream.i_offset) % STREAM_CACHE_TRACK_SIZE;
1084 if( i_off + i_read <= STREAM_CACHE_TRACK_SIZE )
1086 *pp_peek = &tk->p_buffer[i_off];
1090 if( p_sys->i_peek < i_read )
1092 p_sys->p_peek = realloc( p_sys->p_peek, i_read );
1093 if( !p_sys->p_peek )
1098 p_sys->i_peek = i_read;
1101 memcpy( p_sys->p_peek, &tk->p_buffer[i_off],
1102 STREAM_CACHE_TRACK_SIZE - i_off );
1103 memcpy( &p_sys->p_peek[STREAM_CACHE_TRACK_SIZE - i_off],
1104 &tk->p_buffer[0], i_read - (STREAM_CACHE_TRACK_SIZE - i_off) );
1106 *pp_peek = p_sys->p_peek;
1110 static int AStreamSeekStream( stream_t *s, int64_t i_pos )
1112 stream_sys_t *p_sys = s->p_sys;
1113 access_t *p_access = p_sys->p_access;
1115 vlc_bool_t b_afastseek;
1121 msg_Dbg( s, "AStreamSeekStream: to "I64Fd" pos="I64Fd
1122 " tk=%d start="I64Fd" offset=%d end="I64Fd,
1123 i_pos, p_sys->i_pos, p_sys->stream.i_tk,
1124 p_sys->stream.tk[p_sys->stream.i_tk].i_start,
1125 p_sys->stream.i_offset,
1126 p_sys->stream.tk[p_sys->stream.i_tk].i_end );
1130 /* Seek in our current track ? */
1131 if( i_pos >= p_sys->stream.tk[p_sys->stream.i_tk].i_start &&
1132 i_pos < p_sys->stream.tk[p_sys->stream.i_tk].i_end )
1134 stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
1136 msg_Dbg( s, "AStreamSeekStream: current track" );
1138 p_sys->i_pos = i_pos;
1139 p_sys->stream.i_offset = i_pos - tk->i_start;
1141 /* If there is not enough data left in the track, refill */
1142 /* \todo How to get a correct value for
1143 * - refilling threshold
1144 * - how much to refill
1146 if( (tk->i_end - tk->i_start ) - p_sys->stream.i_offset <
1147 p_sys->stream.i_read_size )
1149 if( p_sys->stream.i_used < STREAM_READ_ATONCE / 2 )
1151 p_sys->stream.i_used = STREAM_READ_ATONCE / 2 ;
1152 AStreamRefillStream( s );
1158 access2_Control( p_access, ACCESS_CAN_SEEK, &b_aseek );
1161 /* We can't do nothing */
1162 msg_Dbg( s, "AStreamSeekStream: can't seek" );
1163 return VLC_EGENERIC;
1166 /* Date the current track */
1167 p_sys->stream.tk[p_sys->stream.i_tk].i_date = mdate();
1169 /* Try to reuse already read data */
1170 for( i = 0; i < STREAM_CACHE_TRACK; i++ )
1172 stream_track_t *tk = &p_sys->stream.tk[i];
1174 if( i_pos >= tk->i_start && i_pos <= tk->i_end )
1177 msg_Dbg( s, "AStreamSeekStream: reusing %d start="I64Fd
1178 " end="I64Fd, i, tk->i_start, tk->i_end );
1181 /* Seek at the end of the buffer */
1182 if( ASeek( s, tk->i_end ) ) return VLC_EGENERIC;
1185 p_sys->i_pos = i_pos;
1186 p_sys->stream.i_tk = i;
1187 p_sys->stream.i_offset = i_pos - tk->i_start;
1189 if( p_sys->stream.i_used < 1024 )
1190 p_sys->stream.i_used = 1024;
1192 if( AStreamRefillStream( s ) && i_pos == tk->i_end )
1193 return VLC_EGENERIC;
1199 access2_Control( p_access, ACCESS_CAN_SEEK, &b_afastseek );
1200 /* FIXME compute seek cost (instead of static 'stupid' value) */
1201 i_maxth = __MIN( p_sys->stream.i_read_size, STREAM_READ_ATONCE / 2 );
1207 /* Search closest segment TODO */
1208 for( i = 0; i < STREAM_CACHE_TRACK; i++ )
1210 stream_track_t *tk = &p_sys->stream.tk[i];
1212 if( i_pos + i_maxth >= tk->i_start )
1214 msg_Dbg( s, "good segment before current pos, TODO" );
1216 if( i_pos - i_maxth <= tk->i_end )
1218 msg_Dbg( s, "good segment after current pos, TODO" );
1223 /* Nothing good, seek and choose oldest segment */
1224 if( ASeek( s, i_pos ) ) return VLC_EGENERIC;
1225 p_sys->i_pos = i_pos;
1228 for( i = 1; i < STREAM_CACHE_TRACK; i++ )
1230 if( p_sys->stream.tk[i].i_date < p_sys->stream.tk[i_new].i_date )
1234 /* Reset the segment */
1235 p_sys->stream.i_tk = i_new;
1236 p_sys->stream.i_offset = 0;
1237 p_sys->stream.tk[i_new].i_start = i_pos;
1238 p_sys->stream.tk[i_new].i_end = i_pos;
1241 if( p_sys->stream.i_used < STREAM_READ_ATONCE / 2 )
1242 p_sys->stream.i_used = STREAM_READ_ATONCE / 2;
1244 if( AStreamRefillStream( s ) )
1245 return VLC_EGENERIC;
1250 static int AStreamRefillStream( stream_t *s )
1252 stream_sys_t *p_sys = s->p_sys;
1253 stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
1255 /* We read but won't increase i_start after initial start + offset */
1257 __MIN( p_sys->stream.i_used, STREAM_CACHE_TRACK_SIZE -
1258 (tk->i_end - tk->i_start - p_sys->stream.i_offset) );
1259 vlc_bool_t b_read = VLC_FALSE;
1260 int64_t i_start, i_stop;
1262 if( i_toread <= 0 ) return VLC_EGENERIC; /* EOF */
1265 msg_Dbg( s, "AStreamRefillStream: used=%d toread=%d",
1266 p_sys->stream.i_used, i_toread );
1270 while( i_toread > 0 )
1272 int i_off = tk->i_end % STREAM_CACHE_TRACK_SIZE;
1276 return VLC_EGENERIC;
1278 i_read = __MIN( i_toread, STREAM_CACHE_TRACK_SIZE - i_off );
1279 i_read = AReadStream( s, &tk->p_buffer[i_off], i_read );
1281 /* msg_Dbg( s, "AStreamRefillStream: read=%d", i_read ); */
1284 msleep( STREAM_DATA_WAIT );
1287 else if( i_read == 0 )
1289 if( !b_read ) return VLC_EGENERIC;
1295 tk->i_end += i_read;
1297 /* Windows of STREAM_CACHE_TRACK_SIZE */
1298 if( tk->i_end - tk->i_start > STREAM_CACHE_TRACK_SIZE )
1300 int i_invalid = tk->i_end - tk->i_start - STREAM_CACHE_TRACK_SIZE;
1302 tk->i_start += i_invalid;
1303 p_sys->stream.i_offset -= i_invalid;
1307 p_sys->stream.i_used -= i_read;
1309 p_sys->stat.i_bytes += i_read;
1310 p_sys->stat.i_read_count++;
1314 p_sys->stat.i_read_time += i_stop - i_start;
1319 static void AStreamPrebufferStream( stream_t *s )
1321 stream_sys_t *p_sys = s->p_sys;
1322 access_t *p_access = p_sys->p_access;
1324 int64_t i_first = 0;
1326 int64_t i_prebuffer = p_sys->b_quick ? STREAM_CACHE_TRACK_SIZE /100 :
1327 ( (p_access->info.i_title > 1 || p_access->info.i_seekpoint > 1) ?
1328 STREAM_CACHE_PREBUFFER_SIZE : STREAM_CACHE_TRACK_SIZE / 3 );
1330 msg_Dbg( s, "pre-buffering..." );
1334 stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
1336 int64_t i_date = mdate();
1339 if( s->b_die || tk->i_end >= i_prebuffer ||
1340 (i_first > 0 && i_first + STREAM_CACHE_PREBUFFER_LENGTH < i_date) )
1345 p_sys->stat.i_bytes = tk->i_end - tk->i_start;
1346 p_sys->stat.i_read_time = i_date - i_start;
1347 i_byterate = ( I64C(1000000) * p_sys->stat.i_bytes ) /
1348 (p_sys->stat.i_read_time+1);
1350 msg_Dbg( s, "pre-buffering done "I64Fd" bytes in "I64Fd"s - "
1352 p_sys->stat.i_bytes,
1353 p_sys->stat.i_read_time / I64C(1000000),
1354 i_byterate / 1024 );
1359 i_read = STREAM_CACHE_TRACK_SIZE - tk->i_end;
1360 i_read = __MIN( p_sys->stream.i_read_size, i_read );
1361 i_read = AReadStream( s, &tk->p_buffer[tk->i_end], i_read );
1364 msleep( STREAM_DATA_WAIT );
1367 else if( i_read == 0 )
1376 msg_Dbg( s, "received first data for our buffer");
1379 tk->i_end += i_read;
1381 p_sys->stat.i_read_count++;
1386 /****************************************************************************
1388 ****************************************************************************/
1390 * Read from the stream untill first newline.
1391 * \param s Stream handle to read from
1392 * \return A pointer to the allocated output string. You need to free this when you are done.
1394 #define STREAM_PROBE_LINE 2048
1395 #define STREAM_LINE_MAX (2048*100)
1396 char * stream_ReadLine( stream_t *s )
1398 char *p_line = NULL;
1399 int i_line = 0, i_read = 0;
1401 while( i_read < STREAM_LINE_MAX )
1408 /* Probe new data */
1409 i_data = stream_Peek( s, &p_data, STREAM_PROBE_LINE );
1410 if( i_data <= 0 ) break; /* No more data */
1413 i_pos = stream_Tell( s );
1414 if( i_pos == 0 && i_data > 4 )
1417 char *psz_encoding = NULL;
1419 if( p_data[0] == 0xEF && p_data[1] == 0xBB && p_data[2] == 0xBF )
1421 psz_encoding = strdup( "UTF-8" );
1424 else if( p_data[0] == 0x00 && p_data[1] == 0x00 )
1426 if( p_data[2] == 0xFE && p_data[3] == 0xFF )
1428 psz_encoding = strdup( "UTF-32BE" );
1429 s->i_char_width = 4;
1433 else if( p_data[0] == 0xFF && p_data[1] == 0xFE )
1435 if( p_data[2] == 0x00 && p_data[3] == 0x00 )
1437 psz_encoding = strdup( "UTF-32LE" );
1438 s->i_char_width = 4;
1439 s->b_little_endian = VLC_TRUE;
1444 psz_encoding = strdup( "UTF-16LE" );
1445 s->b_little_endian = VLC_TRUE;
1446 s->i_char_width = 2;
1450 else if( p_data[0] == 0xFE && p_data[1] == 0xFF )
1452 psz_encoding = strdup( "UTF-16BE" );
1453 s->i_char_width = 2;
1457 /* Seek past the BOM */
1460 stream_Seek( s, i_bom_size );
1461 p_data += i_bom_size;
1462 i_data -= i_bom_size;
1465 /* Open the converter if we need it */
1466 if( psz_encoding != NULL )
1468 input_thread_t *p_input;
1469 msg_Dbg( s, "%s BOM detected", psz_encoding );
1470 p_input = (input_thread_t *)vlc_object_find( s, VLC_OBJECT_INPUT, FIND_PARENT );
1471 if( s->i_char_width > 1 )
1473 s->conv = vlc_iconv_open( "UTF-8", psz_encoding );
1474 if( s->conv == (vlc_iconv_t)-1 )
1476 msg_Err( s, "iconv_open failed" );
1479 if( p_input != NULL)
1481 var_Create( p_input, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
1482 var_SetString( p_input, "subsdec-encoding", "UTF-8" );
1483 vlc_object_release( p_input );
1485 if( psz_encoding ) free( psz_encoding );
1489 if( i_data % s->i_char_width )
1491 /* keep i_char_width boundary */
1492 i_data = i_data - ( i_data % s->i_char_width );
1493 msg_Warn( s, "the read is not i_char_width compatible");
1499 /* Check if there is an EOL */
1500 if( s->i_char_width == 1 )
1502 /* UTF-8: 0A <LF> */
1503 psz_eol = memchr( p_data, '\n', i_data );
1507 uint8_t *p = p_data;
1508 uint8_t *p_last = p + i_data - s->i_char_width;
1510 if( s->i_char_width == 2 )
1512 if( s->b_little_endian == VLC_TRUE)
1514 /* UTF-16LE: 0A 00 <LF> */
1515 while( p <= p_last && ( p[0] != 0x0A || p[1] != 0x00 ) )
1520 /* UTF-16BE: 00 0A <LF> */
1521 while( p <= p_last && ( p[1] != 0x0A || p[0] != 0x00 ) )
1525 else if( s->i_char_width == 4 )
1527 if( s->b_little_endian == VLC_TRUE)
1529 /* UTF-32LE: 0A 00 00 00 <LF> */
1530 while( p <= p_last && ( p[0] != 0x0A || p[1] != 0x00 ||
1531 p[2] != 0x00 || p[3] != 0x00 ) )
1536 /* UTF-32BE: 00 00 00 0A <LF> */
1537 while( p <= p_last && ( p[3] != 0x0A || p[2] != 0x00 ||
1538 p[1] != 0x00 || p[0] != 0x00 ) )
1549 psz_eol = (char *)p + ( s->i_char_width - 1 );
1555 i_data = (psz_eol - (char *)p_data) + 1;
1556 p_line = realloc( p_line, i_line + i_data + s->i_char_width ); /* add \0 */
1557 i_data = stream_Read( s, &p_line[i_line], i_data );
1558 if( i_data <= 0 ) break; /* Hmmm */
1559 i_line += i_data - s->i_char_width; /* skip \n */;
1562 /* We have our line */
1566 /* Read data (+1 for easy \0 append) */
1567 p_line = realloc( p_line, i_line + STREAM_PROBE_LINE + s->i_char_width );
1568 i_data = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE );
1569 if( i_data <= 0 ) break; /* Hmmm */
1577 for( j = 0; j < s->i_char_width; j++ )
1579 p_line[i_line + j] = '\0';
1581 i_line += s->i_char_width; /* the added \0 */
1582 if( s->i_char_width > 1 )
1584 size_t i_in = 0, i_out = 0;
1585 const char * p_in = NULL;
1586 char * p_out = NULL;
1587 char * psz_new_line = NULL;
1590 psz_new_line = malloc( i_line );
1592 i_in = i_out = (size_t)i_line;
1594 p_out = psz_new_line;
1596 if( vlc_iconv( s->conv, &p_in, &i_in, &p_out, &i_out ) == (size_t)-1 )
1598 msg_Err( s, "iconv failed" );
1599 msg_Dbg( s, "original: %d, in %d, out %d", i_line, (int)i_in, (int)i_out );
1601 if( p_line ) free( p_line );
1602 p_line = psz_new_line;
1603 i_line = (size_t)i_line - i_out; /* does not include \0 */
1606 /* Remove trailing LF/CR */
1607 while( i_line >= 2 && ( p_line[i_line-2] == '\r' ||
1608 p_line[i_line-2] == '\n') ) i_line--;
1610 /* Make sure the \0 is there */
1611 p_line[i_line-1] = '\0';
1616 /* We failed to read any data, probably EOF */
1617 if( p_line ) free( p_line );
1618 if( s->conv != (vlc_iconv_t)(-1) ) vlc_iconv_close( s->conv );
1622 /****************************************************************************
1623 * Access reading/seeking wrappers to handle concatenated streams.
1624 ****************************************************************************/
1625 static int AReadStream( stream_t *s, void *p_read, int i_read )
1627 stream_sys_t *p_sys = s->p_sys;
1628 access_t *p_access = p_sys->p_access;
1629 input_thread_t *p_input = NULL;
1630 int i_read_orig = i_read;
1633 if( s->p_parent && s->p_parent->p_parent &&
1634 s->p_parent->p_parent->i_object_type == VLC_OBJECT_INPUT )
1635 p_input = (input_thread_t *)s->p_parent->p_parent;
1637 if( !p_sys->i_list )
1639 i_read = p_access->pf_read( p_access, p_read, i_read );
1642 vlc_object_yield( p_input );
1643 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1644 stats_UpdateInteger( s, p_input->p->counters.p_read_bytes, i_read,
1646 stats_UpdateFloat( s, p_input->p->counters.p_input_bitrate,
1647 (float)i_total, NULL );
1648 stats_UpdateInteger( s, p_input->p->counters.p_read_packets, 1, NULL );
1649 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1650 vlc_object_release( p_input );
1655 i_read = p_sys->p_list_access->pf_read( p_sys->p_list_access, p_read,
1658 /* If we reached an EOF then switch to the next stream in the list */
1659 if( i_read == 0 && p_sys->i_list_index + 1 < p_sys->i_list )
1661 char *psz_name = p_sys->list[++p_sys->i_list_index]->psz_path;
1662 access_t *p_list_access;
1664 msg_Dbg( s, "opening input `%s'", psz_name );
1666 p_list_access = access2_New( s, p_access->psz_access, 0, psz_name, 0 );
1668 if( !p_list_access ) return 0;
1670 if( p_sys->p_list_access != p_access )
1671 access2_Delete( p_sys->p_list_access );
1673 p_sys->p_list_access = p_list_access;
1675 /* We have to read some data */
1676 return AReadStream( s, p_read, i_read_orig );
1679 /* Update read bytes in input */
1682 vlc_object_yield( p_input );
1683 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1684 stats_UpdateInteger( s, p_input->p->counters.p_read_bytes, i_read, &i_total );
1685 stats_UpdateFloat( s, p_input->p->counters.p_input_bitrate,
1686 (float)i_total, NULL );
1687 stats_UpdateInteger( s, p_input->p->counters.p_read_packets, 1, NULL );
1688 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1689 vlc_object_release( p_input );
1694 static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
1696 stream_sys_t *p_sys = s->p_sys;
1697 access_t *p_access = p_sys->p_access;
1698 input_thread_t *p_input = NULL;
1703 if( s->p_parent && s->p_parent->p_parent &&
1704 s->p_parent->p_parent->i_object_type == VLC_OBJECT_INPUT )
1705 p_input = (input_thread_t *)s->p_parent->p_parent;
1707 if( !p_sys->i_list )
1709 p_block = p_access->pf_block( p_access );
1710 if( pb_eof ) *pb_eof = p_access->info.b_eof;
1711 if( p_input && p_block && p_access->p_libvlc->b_stats )
1713 vlc_object_yield( p_input );
1714 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1715 stats_UpdateInteger( s, p_input->p->counters.p_read_bytes,
1716 p_block->i_buffer, &i_total );
1717 stats_UpdateFloat( s, p_input->p->counters.p_input_bitrate,
1718 (float)i_total, NULL );
1719 stats_UpdateInteger( s, p_input->p->counters.p_read_packets, 1, NULL );
1720 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1721 vlc_object_release( p_input );
1726 p_block = p_sys->p_list_access->pf_block( p_access );
1727 b_eof = p_sys->p_list_access->info.b_eof;
1728 if( pb_eof ) *pb_eof = b_eof;
1730 /* If we reached an EOF then switch to the next stream in the list */
1731 if( !p_block && b_eof && p_sys->i_list_index + 1 < p_sys->i_list )
1733 char *psz_name = p_sys->list[++p_sys->i_list_index]->psz_path;
1734 access_t *p_list_access;
1736 msg_Dbg( s, "opening input `%s'", psz_name );
1738 p_list_access = access2_New( s, p_access->psz_access, 0, psz_name, 0 );
1740 if( !p_list_access ) return 0;
1742 if( p_sys->p_list_access != p_access )
1743 access2_Delete( p_sys->p_list_access );
1745 p_sys->p_list_access = p_list_access;
1747 /* We have to read some data */
1748 return AReadBlock( s, pb_eof );
1754 vlc_object_yield( p_input );
1755 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1756 stats_UpdateInteger( s, p_input->p->counters.p_read_bytes,
1757 p_block->i_buffer, &i_total );
1758 stats_UpdateFloat( s, p_input->p->counters.p_input_bitrate,
1759 (float)i_total, NULL );
1760 stats_UpdateInteger( s, p_input->p->counters.p_read_packets,
1762 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1763 vlc_object_release( p_input );
1769 static int ASeek( stream_t *s, int64_t i_pos )
1771 stream_sys_t *p_sys = s->p_sys;
1772 access_t *p_access = p_sys->p_access;
1774 /* Check which stream we need to access */
1780 access_t *p_list_access = 0;
1782 for( i = 0; i < p_sys->i_list - 1; i++ )
1784 if( i_pos < p_sys->list[i]->i_size + i_size ) break;
1785 i_size += p_sys->list[i]->i_size;
1787 psz_name = p_sys->list[i]->psz_path;
1789 if( i != p_sys->i_list_index )
1790 msg_Dbg( s, "opening input `%s'", psz_name );
1792 if( i != p_sys->i_list_index && i != 0 )
1795 access2_New( s, p_access->psz_access, 0, psz_name, 0 );
1797 else if( i != p_sys->i_list_index )
1799 p_list_access = p_access;
1804 if( p_sys->p_list_access != p_access )
1805 access2_Delete( p_sys->p_list_access );
1807 p_sys->p_list_access = p_list_access;
1810 p_sys->i_list_index = i;
1811 return p_sys->p_list_access->pf_seek( p_sys->p_list_access,
1815 return p_access->pf_seek( p_access, i_pos );