~ubuntu-branches/ubuntu/natty/vlc/natty

« back to all changes in this revision

Viewing changes to src/input/stream.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * stream.c
3
3
 *****************************************************************************
4
4
 * Copyright (C) 1999-2004 the VideoLAN team
5
 
 * $Id: 8947f2393b8787829bcf414a1d757df8c3e45bba $
 
5
 * $Id: aaf7f94169673cea50f9584475718935214fa1e7 $
6
6
 *
7
7
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8
8
 *
31
31
#include <vlc_common.h>
32
32
#include <vlc_strings.h>
33
33
#include <vlc_osd.h>
34
 
#include <vlc_charset.h>
 
34
#include <vlc_memory.h>
35
35
 
36
36
#include <libvlc.h>
37
37
 
100
100
{
101
101
    int64_t i_date;
102
102
 
103
 
    int64_t i_start;
104
 
    int64_t i_end;
 
103
    uint64_t i_start;
 
104
    uint64_t i_end;
105
105
 
106
106
    uint8_t *p_buffer;
107
107
 
110
110
typedef struct
111
111
{
112
112
    char     *psz_path;
113
 
    int64_t  i_size;
 
113
    uint64_t  i_size;
114
114
 
115
115
} access_entry_t;
116
116
 
126
126
 
127
127
    stream_read_method_t   method;    /* method to use */
128
128
 
129
 
    int64_t     i_pos;      /* Current reading offset */
 
129
    uint64_t     i_pos;      /* Current reading offset */
130
130
 
131
131
    /* Method 1: pf_block */
132
132
    struct
133
133
    {
134
 
        int64_t i_start;        /* Offset of block for p_first */
135
 
        int64_t i_offset;       /* Offset for data in p_current */
 
134
        uint64_t i_start;        /* Offset of block for p_first */
 
135
        uint64_t i_offset;       /* Offset for data in p_current */
136
136
        block_t *p_current;     /* Current block */
137
137
 
138
 
        int     i_size;         /* Total amount of data in the list */
 
138
        uint64_t i_size;         /* Total amount of data in the list */
139
139
        block_t *p_first;
140
140
        block_t **pp_last;
141
141
 
144
144
    /* Method 2: for pf_read */
145
145
    struct
146
146
    {
147
 
        int i_offset;   /* Buffer offset in the current track */
148
 
        int i_tk;       /* Current track */
 
147
        unsigned i_offset;   /* Buffer offset in the current track */
 
148
        int      i_tk;       /* Current track */
149
149
        stream_track_t tk[STREAM_CACHE_TRACK];
150
150
 
151
151
        /* Global buffer */
152
152
        uint8_t *p_buffer;
153
153
 
154
154
        /* */
155
 
        int i_used; /* Used since last read */
156
 
        int i_read_size;
 
155
        unsigned i_used; /* Used since last read */
 
156
        unsigned i_read_size;
157
157
 
158
158
    } stream;
159
159
 
167
167
        bool b_fastseek;  /* From access */
168
168
 
169
169
        /* Stat about reading data */
170
 
        int64_t i_read_count;
171
 
        int64_t i_bytes;
172
 
        int64_t i_read_time;
 
170
        uint64_t i_read_count;
 
171
        uint64_t i_bytes;
 
172
        uint64_t i_read_time;
173
173
 
174
174
        /* Stat about seek */
175
 
        int     i_seek_count;
176
 
        int64_t i_seek_time;
 
175
        unsigned i_seek_count;
 
176
        uint64_t i_seek_time;
177
177
 
178
178
    } stat;
179
179
 
187
187
/* Method 1: */
188
188
static int  AStreamReadBlock( stream_t *s, void *p_read, unsigned int i_read );
189
189
static int  AStreamPeekBlock( stream_t *s, const uint8_t **p_peek, unsigned int i_read );
190
 
static int  AStreamSeekBlock( stream_t *s, int64_t i_pos );
 
190
static int  AStreamSeekBlock( stream_t *s, uint64_t i_pos );
191
191
static void AStreamPrebufferBlock( stream_t *s );
192
192
static block_t *AReadBlock( stream_t *s, bool *pb_eof );
193
193
 
194
194
/* Method 2 */
195
195
static int  AStreamReadStream( stream_t *s, void *p_read, unsigned int i_read );
196
196
static int  AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, unsigned int i_read );
197
 
static int  AStreamSeekStream( stream_t *s, int64_t i_pos );
 
197
static int  AStreamSeekStream( stream_t *s, uint64_t i_pos );
198
198
static void AStreamPrebufferStream( stream_t *s );
199
199
static int  AReadStream( stream_t *s, void *p_read, unsigned int i_read );
200
200
 
202
202
static int AStreamControl( stream_t *s, int i_query, va_list );
203
203
static void AStreamDestroy( stream_t *s );
204
204
static void UStreamDestroy( stream_t *s );
205
 
static int  ASeek( stream_t *s, int64_t i_pos );
 
205
static int  ASeek( stream_t *s, uint64_t i_pos );
206
206
 
207
207
/****************************************************************************
208
208
 * stream_CommonNew: create an empty stream structure
229
229
 
230
230
    return s;
231
231
}
 
232
 
232
233
void stream_CommonDelete( stream_t *s )
233
234
{
234
235
    if( s->p_text )
241
242
    vlc_object_release( s );
242
243
}
243
244
 
 
245
#undef stream_UrlNew
244
246
/****************************************************************************
245
247
 * stream_UrlNew: create a stream from a access
246
248
 ****************************************************************************/
247
 
stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
 
249
stream_t *stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
248
250
{
249
251
    const char *psz_access, *psz_demux;
250
252
    char *psz_path;
258
260
    strcpy( psz_dup, psz_url );
259
261
    input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
260
262
 
 
263
    /* Get a weak link to the parent input */
 
264
    /* FIXME: This should probably be removed in favor of a NULL input. */
 
265
    input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_parent, VLC_OBJECT_INPUT, FIND_PARENT );
 
266
    
261
267
    /* Now try a real access */
262
 
    p_access = access_New( p_parent, psz_access, psz_demux, psz_path );
 
268
    p_access = access_New( p_parent, p_input, psz_access, psz_demux, psz_path );
 
269
 
 
270
    if(p_input)
 
271
        vlc_object_release((vlc_object_t*)p_input);
263
272
 
264
273
    if( p_access == NULL )
265
274
    {
285
294
    if( !s )
286
295
        return NULL;
287
296
 
 
297
    s->p_input = p_access->p_input;
288
298
    s->psz_path = strdup( p_access->psz_path );
289
299
    s->p_sys = p_sys = malloc( sizeof( *p_sys ) );
290
300
    if( !s->psz_path || !s->p_sys )
348
358
            if( !psz_name )
349
359
                break;
350
360
 
351
 
            access_t *p_tmp = access_New( p_access,
 
361
            access_t *p_tmp = access_New( p_access, p_access->p_input,
352
362
                                          p_access->psz_access, "", psz_name );
353
363
            if( !p_tmp )
354
364
                continue;
451
461
        free( p_sys->list[--(p_sys->i_list)] );
452
462
    free( p_sys->list );
453
463
    free( s->p_sys );
454
 
    vlc_object_detach( s );
455
464
    stream_CommonDelete( s );
456
465
    return NULL;
457
466
}
463
472
{
464
473
    stream_sys_t *p_sys = s->p_sys;
465
474
 
466
 
    vlc_object_detach( s );
467
 
 
468
475
    if( p_sys->method == STREAM_METHOD_BLOCK )
469
476
        block_ChainRelease( p_sys->block.p_first );
470
477
    else
568
575
    stream_sys_t *p_sys = s->p_sys;
569
576
    access_t     *p_access = p_sys->p_access;
570
577
 
571
 
    bool    *p_bool;
572
 
    int64_t *pi_64, i_64;
573
 
    int     i_int;
 
578
    bool     *p_bool;
 
579
    uint64_t *pi_64, i_64;
 
580
    int      i_int;
574
581
 
575
582
    switch( i_query )
576
583
    {
577
584
        case STREAM_GET_SIZE:
578
 
            pi_64 = (int64_t*)va_arg( args, int64_t * );
 
585
            pi_64 = va_arg( args, uint64_t * );
579
586
            if( s->p_sys->i_list )
580
587
            {
581
588
                int i;
598
605
            break;
599
606
 
600
607
        case STREAM_GET_POSITION:
601
 
            pi_64 = (int64_t*)va_arg( args, int64_t * );
 
608
            pi_64 = va_arg( args, uint64_t * );
602
609
            *pi_64 = p_sys->i_pos;
603
610
            break;
604
611
 
605
612
        case STREAM_SET_POSITION:
606
 
            i_64 = (int64_t)va_arg( args, int64_t );
 
613
            i_64 = va_arg( args, uint64_t );
607
614
            switch( p_sys->method )
608
615
            {
609
616
            case STREAM_METHOD_BLOCK:
678
685
                         (p_sys->stat.i_read_time + 1);
679
686
 
680
687
            msg_Dbg( s, "prebuffering done %"PRId64" bytes in %"PRId64"s - "
681
 
                     "%"PRId64" kbytes/s",
 
688
                     "%"PRId64" KiB/s",
682
689
                     p_sys->stat.i_bytes,
683
690
                     p_sys->stat.i_read_time / INT64_C(1000000),
684
691
                     i_byterate / 1024 );
796
803
    /* We need to create a local copy */
797
804
    if( p_sys->i_peek < i_read )
798
805
    {
799
 
        p_sys->p_peek = realloc( p_sys->p_peek, i_read );
 
806
        p_sys->p_peek = realloc_or_free( p_sys->p_peek, i_read );
800
807
        if( !p_sys->p_peek )
801
808
        {
802
809
            p_sys->i_peek = 0;
843
850
    return i_data;
844
851
}
845
852
 
846
 
static int AStreamSeekBlock( stream_t *s, int64_t i_pos )
 
853
static int AStreamSeekBlock( stream_t *s, uint64_t i_pos )
847
854
{
848
855
    stream_sys_t *p_sys = s->p_sys;
849
856
    access_t   *p_access = p_sys->p_access;
851
858
    bool b_seek;
852
859
 
853
860
    /* We already have thoses data, just update p_current/i_offset */
854
 
    if( i_offset >= 0 && i_offset < p_sys->block.i_size )
 
861
    if( i_offset >= 0 && (uint64_t)i_offset < p_sys->block.i_size )
855
862
    {
856
863
        block_t *b = p_sys->block.p_first;
857
864
        int i_current = 0;
858
865
 
859
 
        while( i_current + b->i_buffer < i_offset )
 
866
        while( i_current + b->i_buffer < (uint64_t)i_offset )
860
867
        {
861
868
            i_current += b->i_buffer;
862
869
            b = b->p_next;
950
957
    {
951
958
        do
952
959
        {
953
 
            /* Read and skip enough data */
954
 
            if( AStreamRefillBlock( s ) )
955
 
                return VLC_EGENERIC;
956
 
 
957
960
            while( p_sys->block.p_current &&
958
 
                   p_sys->i_pos + p_sys->block.p_current->i_buffer - p_sys->block.i_offset < i_pos )
 
961
                   p_sys->i_pos + p_sys->block.p_current->i_buffer - p_sys->block.i_offset <= i_pos )
959
962
            {
960
963
                p_sys->i_pos += p_sys->block.p_current->i_buffer - p_sys->block.i_offset;
961
964
                p_sys->block.p_current = p_sys->block.p_current->p_next;
962
965
                p_sys->block.i_offset = 0;
963
966
            }
 
967
            if( !p_sys->block.p_current && AStreamRefillBlock( s ) )
 
968
            {
 
969
                if( p_sys->i_pos != i_pos )
 
970
                    return VLC_EGENERIC;
 
971
            }
964
972
        }
965
973
        while( p_sys->block.i_start + p_sys->block.i_size < i_pos );
966
974
 
1048
1056
 
1049
1057
    if( !p_read )
1050
1058
    {
1051
 
        const int64_t i_pos_wanted = p_sys->i_pos + i_read;
 
1059
        const uint64_t i_pos_wanted = p_sys->i_pos + i_read;
1052
1060
 
1053
1061
        if( AStreamSeekStream( s, i_pos_wanted ) )
1054
1062
        {
1064
1072
{
1065
1073
    stream_sys_t *p_sys = s->p_sys;
1066
1074
    stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
1067
 
    int64_t i_off;
 
1075
    uint64_t i_off;
1068
1076
 
1069
1077
    if( tk->i_start >= tk->i_end ) return 0; /* EOF */
1070
1078
 
1079
1087
    if( i_read > STREAM_CACHE_TRACK_SIZE / 2 )
1080
1088
        i_read = STREAM_CACHE_TRACK_SIZE / 2;
1081
1089
 
1082
 
    while( tk->i_end - tk->i_start - p_sys->stream.i_offset < i_read )
 
1090
    while( tk->i_end < tk->i_start + p_sys->stream.i_offset + i_read )
1083
1091
    {
1084
1092
        if( p_sys->stream.i_used <= 1 )
1085
1093
        {
1086
1094
            /* Be sure we will read something */
1087
 
            p_sys->stream.i_used += i_read -
1088
 
                (tk->i_end - tk->i_start - p_sys->stream.i_offset);
 
1095
            p_sys->stream.i_used += tk->i_start + p_sys->stream.i_offset + i_read - tk->i_end;
1089
1096
        }
1090
1097
        if( AStreamRefillStream( s ) ) break;
1091
1098
    }
1092
1099
 
1093
 
    if( tk->i_end - tk->i_start - p_sys->stream.i_offset < i_read )
 
1100
    if( tk->i_end < tk->i_start + p_sys->stream.i_offset + i_read )
 
1101
    {
1094
1102
        i_read = tk->i_end - tk->i_start - p_sys->stream.i_offset;
 
1103
    }
 
1104
 
1095
1105
 
1096
1106
    /* Now, direct pointer or a copy ? */
1097
1107
    i_off = (tk->i_start + p_sys->stream.i_offset) % STREAM_CACHE_TRACK_SIZE;
1103
1113
 
1104
1114
    if( p_sys->i_peek < i_read )
1105
1115
    {
1106
 
        p_sys->p_peek = realloc( p_sys->p_peek, i_read );
 
1116
        p_sys->p_peek = realloc_or_free( p_sys->p_peek, i_read );
1107
1117
        if( !p_sys->p_peek )
1108
1118
        {
1109
1119
            p_sys->i_peek = 0;
1121
1131
    return i_read;
1122
1132
}
1123
1133
 
1124
 
static int AStreamSeekStream( stream_t *s, int64_t i_pos )
 
1134
static int AStreamSeekStream( stream_t *s, uint64_t i_pos )
1125
1135
{
1126
1136
    stream_sys_t *p_sys = s->p_sys;
1127
1137
 
1152
1162
    access_Control( p_access, ACCESS_CAN_FASTSEEK, &b_afastseek );
1153
1163
 
1154
1164
    /* FIXME compute seek cost (instead of static 'stupid' value) */
1155
 
    int64_t i_skip_threshold;
 
1165
    uint64_t i_skip_threshold;
1156
1166
    if( b_aseek )
1157
1167
        i_skip_threshold = b_afastseek ? 128 : 3*p_sys->stream.i_read_size;
1158
1168
    else
1166
1176
    int i_tk_idx = -1;
1167
1177
 
1168
1178
    /* Prefer the current track */
1169
 
    if( p_current->i_start <= i_pos && i_pos - p_current->i_end <= i_skip_threshold )
 
1179
    if( p_current->i_start <= i_pos && i_pos <= p_current->i_end + i_skip_threshold )
1170
1180
    {
1171
1181
        tk = p_current;
1172
1182
        i_tk_idx = p_sys->stream.i_tk;
1206
1216
 
1207
1217
    if( tk != p_current )
1208
1218
        i_skip_threshold = 0;
1209
 
    if( tk->i_start <= i_pos && i_pos - tk->i_end <= i_skip_threshold )
 
1219
    if( tk->i_start <= i_pos && i_pos <= tk->i_end + i_skip_threshold )
1210
1220
    {
1211
1221
#ifdef STREAM_DEBUG
1212
1222
        msg_Err( s, "AStreamSeekStream: reusing %d start=%"PRId64
1224
1234
            if( ASeek( s, tk->i_end ) )
1225
1235
                return VLC_EGENERIC;
1226
1236
        }
1227
 
        else
 
1237
        else if( i_pos > tk->i_end )
1228
1238
        {
1229
 
            int64_t i_skip = i_pos - tk->i_end;
 
1239
            uint64_t i_skip = i_pos - tk->i_end;
1230
1240
            while( i_skip > 0 )
1231
1241
            {
1232
1242
                const int i_read_max = __MIN( 10 * STREAM_READ_ATONCE, i_skip );
1257
1267
     *    - refilling threshold
1258
1268
     *    - how much to refill
1259
1269
     */
1260
 
    if( (tk->i_end - tk->i_start) - p_sys->stream.i_offset < p_sys->stream.i_read_size )
 
1270
    if( tk->i_end < tk->i_start + p_sys->stream.i_offset + p_sys->stream.i_read_size )
1261
1271
    {
1262
1272
        if( p_sys->stream.i_used < STREAM_READ_ATONCE / 2 )
1263
1273
            p_sys->stream.i_used = STREAM_READ_ATONCE / 2;
1288
1298
 
1289
1299
    while( i_data < i_read )
1290
1300
    {
1291
 
        int i_off = (tk->i_start + p_sys->stream.i_offset) %
1292
 
                    STREAM_CACHE_TRACK_SIZE;
 
1301
        unsigned i_off = (tk->i_start + p_sys->stream.i_offset) % STREAM_CACHE_TRACK_SIZE;
1293
1302
        unsigned int i_current =
1294
 
            __MAX(0,__MIN( tk->i_end - tk->i_start - p_sys->stream.i_offset,
1295
 
                   STREAM_CACHE_TRACK_SIZE - i_off ));
 
1303
            __MIN( tk->i_end - tk->i_start - p_sys->stream.i_offset,
 
1304
                   STREAM_CACHE_TRACK_SIZE - i_off );
1296
1305
        int i_copy = __MIN( i_current, i_read - i_data );
1297
1306
 
1298
1307
        if( i_copy <= 0 ) break; /* EOF */
1313
1322
        /* */
1314
1323
        p_sys->stream.i_used += i_copy;
1315
1324
 
1316
 
        if( tk->i_end - tk->i_start - p_sys->stream.i_offset <= i_read -i_data )
 
1325
        if( tk->i_end + i_data <= tk->i_start + p_sys->stream.i_offset + i_read )
1317
1326
        {
1318
 
            const int i_read_requested = __MAX( __MIN( i_read - i_data,
1319
 
                                                       STREAM_READ_ATONCE * 10 ),
1320
 
                                                STREAM_READ_ATONCE / 2 );
 
1327
            const unsigned i_read_requested = __MAX( __MIN( i_read - i_data,
 
1328
                                                            STREAM_READ_ATONCE * 10 ),
 
1329
                                                     STREAM_READ_ATONCE / 2 );
1321
1330
 
1322
1331
            if( p_sys->stream.i_used < i_read_requested )
1323
1332
                p_sys->stream.i_used = i_read_requested;
1382
1391
        tk->i_end += i_read;
1383
1392
 
1384
1393
        /* Windows of STREAM_CACHE_TRACK_SIZE */
1385
 
        if( tk->i_end - tk->i_start > STREAM_CACHE_TRACK_SIZE )
 
1394
        if( tk->i_start + STREAM_CACHE_TRACK_SIZE < tk->i_end )
1386
1395
        {
1387
 
            int i_invalid = tk->i_end - tk->i_start - STREAM_CACHE_TRACK_SIZE;
 
1396
            unsigned i_invalid = tk->i_end - tk->i_start - STREAM_CACHE_TRACK_SIZE;
1388
1397
 
1389
1398
            tk->i_start += i_invalid;
1390
1399
            p_sys->stream.i_offset -= i_invalid;
1418
1427
 
1419
1428
        int64_t i_date = mdate();
1420
1429
        int i_read;
 
1430
        int i_buffered = tk->i_end - tk->i_start;
1421
1431
 
1422
 
        if( s->b_die || tk->i_end >= STREAM_CACHE_PREBUFFER_SIZE )
 
1432
        if( s->b_die || i_buffered >= STREAM_CACHE_PREBUFFER_SIZE )
1423
1433
        {
1424
1434
            int64_t i_byterate;
1425
1435
 
1426
1436
            /* Update stat */
1427
 
            p_sys->stat.i_bytes = tk->i_end - tk->i_start;
 
1437
            p_sys->stat.i_bytes = i_buffered;
1428
1438
            p_sys->stat.i_read_time = i_date - i_start;
1429
1439
            i_byterate = ( INT64_C(1000000) * p_sys->stat.i_bytes ) /
1430
1440
                         (p_sys->stat.i_read_time+1);
1431
1441
 
1432
1442
            msg_Dbg( s, "pre-buffering done %"PRId64" bytes in %"PRId64"s - "
1433
 
                     "%"PRId64" kbytes/s",
 
1443
                     "%"PRId64" KiB/s",
1434
1444
                     p_sys->stat.i_bytes,
1435
1445
                     p_sys->stat.i_read_time / INT64_C(1000000),
1436
1446
                     i_byterate / 1024 );
1438
1448
        }
1439
1449
 
1440
1450
        /* */
1441
 
        i_read = STREAM_CACHE_TRACK_SIZE - tk->i_end;
1442
 
        i_read = __MIN( p_sys->stream.i_read_size, i_read );
1443
 
        i_read = AReadStream( s, &tk->p_buffer[tk->i_end], i_read );
 
1451
        i_read = STREAM_CACHE_TRACK_SIZE - i_buffered;
 
1452
        i_read = __MIN( (int)p_sys->stream.i_read_size, i_read );
 
1453
        i_read = AReadStream( s, &tk->p_buffer[i_buffered], i_read );
1444
1454
        if( i_read <  0 )
1445
1455
            continue;
1446
1456
        else if( i_read == 0 )
1533
1543
                }
1534
1544
 
1535
1545
                /* FIXME that's UGLY */
1536
 
                input_thread_t *p_input;
1537
 
                p_input = (input_thread_t *)vlc_object_find( s, VLC_OBJECT_INPUT, FIND_PARENT );
 
1546
                input_thread_t *p_input = s->p_input;
1538
1547
                if( p_input != NULL)
1539
1548
                {
1540
1549
                    var_Create( p_input, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
1541
1550
                    var_SetString( p_input, "subsdec-encoding", "UTF-8" );
1542
 
                    vlc_object_release( p_input );
1543
1551
                }
1544
1552
            }
1545
1553
        }
1559
1567
        {
1560
1568
            /* UTF-8: 0A <LF> */
1561
1569
            psz_eol = memchr( p_data, '\n', i_data );
 
1570
            if( psz_eol == NULL )
 
1571
                /* UTF-8: 0D <CR> */
 
1572
                psz_eol = memchr( p_data, '\r', i_data );
1562
1573
        }
1563
1574
        else
1564
1575
        {
1565
 
            const uint8_t *p = p_data;
1566
 
            const uint8_t *p_last = p + i_data - s->p_text->i_char_width;
1567
 
 
1568
 
            if( s->p_text->i_char_width == 2 )
1569
 
            {
1570
 
                if( s->p_text->b_little_endian == true)
1571
 
                {
1572
 
                    /* UTF-16LE: 0A 00 <LF> */
1573
 
                    while( p <= p_last && ( p[0] != 0x0A || p[1] != 0x00 ) )
1574
 
                        p += 2;
1575
 
                }
1576
 
                else
1577
 
                {
1578
 
                    /* UTF-16BE: 00 0A <LF> */
1579
 
                    while( p <= p_last && ( p[1] != 0x0A || p[0] != 0x00 ) )
1580
 
                        p += 2;
1581
 
                }
1582
 
            }
1583
 
 
1584
 
            if( p > p_last )
1585
 
            {
1586
 
                psz_eol = NULL;
1587
 
            }
1588
 
            else
1589
 
            {
1590
 
                psz_eol = (char *)p + ( s->p_text->i_char_width - 1 );
 
1576
            const uint8_t *p_last = p_data + i_data - s->p_text->i_char_width;
 
1577
            uint16_t eol = s->p_text->b_little_endian ? 0x0A00 : 0x00A0;
 
1578
 
 
1579
            assert( s->p_text->i_char_width == 2 );
 
1580
            psz_eol = NULL;
 
1581
            /* UTF-16: 000A <LF> */
 
1582
            for( const uint8_t *p = p_data; p <= p_last; p += 2 )
 
1583
            {
 
1584
                if( U16_AT( p ) == eol )
 
1585
                {
 
1586
                     psz_eol = (char *)p + 1;
 
1587
                     break;
 
1588
                }
 
1589
            }
 
1590
 
 
1591
            if( psz_eol == NULL )
 
1592
            {   /* UTF-16: 000D <CR> */
 
1593
                eol = s->p_text->b_little_endian ? 0x0D00 : 0x00D0;
 
1594
                for( const uint8_t *p = p_data; p <= p_last; p += 2 )
 
1595
                {
 
1596
                    if( U16_AT( p ) == eol )
 
1597
                    {
 
1598
                        psz_eol = (char *)p + 1;
 
1599
                        break;
 
1600
                    }
 
1601
                }
1591
1602
            }
1592
1603
        }
1593
1604
 
1594
1605
        if( psz_eol )
1595
1606
        {
1596
1607
            i_data = (psz_eol - (char *)p_data) + 1;
1597
 
            p_line = realloc( p_line, i_line + i_data + s->p_text->i_char_width ); /* add \0 */
 
1608
            p_line = realloc_or_free( p_line,
 
1609
                     i_line + i_data + s->p_text->i_char_width ); /* add \0 */
1598
1610
            if( !p_line )
1599
1611
                goto error;
1600
1612
            i_data = stream_Read( s, &p_line[i_line], i_data );
1607
1619
        }
1608
1620
 
1609
1621
        /* Read data (+1 for easy \0 append) */
1610
 
        p_line = realloc( p_line, i_line + STREAM_PROBE_LINE + s->p_text->i_char_width );
 
1622
        p_line = realloc_or_free( p_line,
 
1623
                       i_line + STREAM_PROBE_LINE + s->p_text->i_char_width );
1611
1624
        if( !p_line )
1612
1625
            goto error;
1613
1626
        i_data = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE );
1716
1729
 
1717
1730
        msg_Dbg( s, "opening input `%s'", psz_name );
1718
1731
 
1719
 
        p_list_access = access_New( s, p_access->psz_access, "", psz_name );
 
1732
        p_list_access = access_New( s, s->p_input, p_access->psz_access, "", psz_name );
1720
1733
 
1721
1734
        if( !p_list_access ) return 0;
1722
1735
 
1788
1801
 
1789
1802
        msg_Dbg( s, "opening input `%s'", psz_name );
1790
1803
 
1791
 
        p_list_access = access_New( s, p_access->psz_access, "", psz_name );
 
1804
        p_list_access = access_New( s, s->p_input, p_access->psz_access, "", psz_name );
1792
1805
 
1793
1806
        if( !p_list_access ) return 0;
1794
1807
 
1817
1830
    return p_block;
1818
1831
}
1819
1832
 
1820
 
static int ASeek( stream_t *s, int64_t i_pos )
 
1833
static int ASeek( stream_t *s, uint64_t i_pos )
1821
1834
{
1822
1835
    stream_sys_t *p_sys = s->p_sys;
1823
1836
    access_t *p_access = p_sys->p_access;
1824
1837
 
1825
 
    if( i_pos < 0 )
1826
 
        return VLC_EGENERIC;
1827
 
 
1828
1838
    /* Check which stream we need to access */
1829
1839
    if( p_sys->i_list )
1830
1840
    {
1846
1856
        if( i != p_sys->i_list_index && i != 0 )
1847
1857
        {
1848
1858
            p_list_access =
1849
 
                access_New( s, p_access->psz_access, "", psz_name );
 
1859
                access_New( s, s->p_input, p_access->psz_access, "", psz_name );
1850
1860
        }
1851
1861
        else if( i != p_sys->i_list_index )
1852
1862
        {