~ubuntu-branches/ubuntu/oneiric/libogg/oneiric

« back to all changes in this revision

Viewing changes to src/framing.c

  • Committer: Bazaar Package Importer
  • Author(s): Ron Lee
  • Date: 2010-04-10 23:23:54 UTC
  • mfrom: (1.1.4 upstream) (2.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100410232354-zd4yp6og8797w0b6
Tags: 1.2.0~dfsg-1
* Alter default flushing behavior to span less often and use larger page
  sizes when packet sizes are large.
* Documentation updates.
* Closes: #575675 (wish for new upstream release)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/********************************************************************
2
2
 *                                                                  *
3
 
 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
 
3
 * THIS FILE IS PART OF THE Ogg CONTAINER SOURCE CODE.              *
4
4
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
5
5
 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6
6
 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
7
7
 *                                                                  *
8
 
 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
 
8
 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2010             *
9
9
 * by the Xiph.Org Foundation http://www.xiph.org/                  *
10
10
 *                                                                  *
11
11
 ********************************************************************
12
12
 
13
13
 function: code raw packets into framed OggSquish stream and
14
14
           decode Ogg streams back into raw packets
15
 
 last mod: $Id: framing.c 16051 2009-05-27 05:00:06Z xiphmont $
 
15
 last mod: $Id: framing.c 17039 2010-03-26 00:34:54Z xiphmont $
16
16
 
17
17
 note: The CRC code is directly derived from public domain code by
18
18
 Ross Williams (ross@guest.adelaide.edu.au).  See docs/framing.html
366
366
  return ogg_stream_iovecin(os, &iov, 1, op->e_o_s, op->granulepos);
367
367
}
368
368
 
369
 
/* This will flush remaining packets into a page (returning nonzero),
370
 
   even if there is not enough data to trigger a flush normally
371
 
   (undersized page). If there are no packets or partial packets to
372
 
   flush, ogg_stream_flush returns 0.  Note that ogg_stream_flush will
373
 
   try to flush a normal sized page like ogg_stream_pageout; a call to
374
 
   ogg_stream_flush does not guarantee that all packets have flushed.
375
 
   Only a return value of 0 from ogg_stream_flush indicates all packet
376
 
   data is flushed into pages.
377
 
 
378
 
   since ogg_stream_flush will flush the last page in a stream even if
379
 
   it's undersized, you almost certainly want to use ogg_stream_pageout
380
 
   (and *not* ogg_stream_flush) unless you specifically need to flush 
381
 
   an page regardless of size in the middle of a stream. */
382
 
 
383
 
int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
 
369
/* Conditionally flush a page; force==0 will only flush nominal-size
 
370
   pages, force==1 forces us to flush a page regardless of page size
 
371
   so long as there's any data available at all. */
 
372
static int ogg_stream_flush_i(ogg_stream_state *os,ogg_page *og, int force){
384
373
  int i;
385
374
  int vals=0;
386
375
  int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
388
377
  long acc=0;
389
378
  ogg_int64_t granule_pos=-1;
390
379
 
391
 
  if(ogg_stream_check(os)) return 0;
392
 
  if(maxvals==0)return 0;
393
 
  
 
380
  if(ogg_stream_check(os)) return(0);
 
381
  if(maxvals==0) return(0);
 
382
 
394
383
  /* construct a page */
395
384
  /* decide how many segments to include */
396
 
  
 
385
 
397
386
  /* If this is the initial header case, the first page must only include
398
387
     the initial header packet */
399
388
  if(os->b_o_s==0){  /* 'initial header page' case */
405
394
      }
406
395
    }
407
396
  }else{
 
397
 
 
398
    /* The extra packets_done, packet_just_done logic here attempts to do two things:
 
399
       1) Don't unneccessarily span pages.
 
400
       2) Unless necessary, don't flush pages if there are less than four packets on
 
401
          them; this expands page size to reduce unneccessary overhead if incoming packets
 
402
          are large.
 
403
       These are not necessary behaviors, just 'always better than naive flushing'
 
404
       without requiring an application to explicitly request a specific optimized
 
405
       behavior. We'll want an explicit behavior setup pathway eventually as well. */
 
406
 
 
407
    int packets_done=0;
 
408
    int packet_just_done=0;
408
409
    for(vals=0;vals<maxvals;vals++){
409
 
      if(acc>4096)break;
 
410
      if(acc>4096 && packet_just_done>=4){
 
411
        force=1;
 
412
        break;
 
413
      }
410
414
      acc+=os->lacing_vals[vals]&0x0ff;
411
 
      if((os->lacing_vals[vals]&0xff)<255)
 
415
      if((os->lacing_vals[vals]&0xff)<255){
412
416
        granule_pos=os->granule_vals[vals];
 
417
        packet_just_done=++packets_done;
 
418
      }else
 
419
        packet_just_done=0;
413
420
    }
 
421
    if(vals==255)force=1;
414
422
  }
415
 
  
 
423
 
 
424
  if(!force) return(0);
 
425
 
416
426
  /* construct the header in temp storage */
417
427
  memcpy(os->header,"OggS",4);
418
 
  
 
428
 
419
429
  /* stream structure version */
420
430
  os->header[4]=0x00;
421
 
  
 
431
 
422
432
  /* continued packet flag? */
423
433
  os->header[5]=0x00;
424
434
  if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
490
500
  return(1);
491
501
}
492
502
 
 
503
/* This will flush remaining packets into a page (returning nonzero),
 
504
   even if there is not enough data to trigger a flush normally
 
505
   (undersized page). If there are no packets or partial packets to
 
506
   flush, ogg_stream_flush returns 0.  Note that ogg_stream_flush will
 
507
   try to flush a normal sized page like ogg_stream_pageout; a call to
 
508
   ogg_stream_flush does not guarantee that all packets have flushed.
 
509
   Only a return value of 0 from ogg_stream_flush indicates all packet
 
510
   data is flushed into pages.
 
511
 
 
512
   since ogg_stream_flush will flush the last page in a stream even if
 
513
   it's undersized, you almost certainly want to use ogg_stream_pageout
 
514
   (and *not* ogg_stream_flush) unless you specifically need to flush
 
515
   an page regardless of size in the middle of a stream. */
 
516
 
 
517
int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
 
518
  return ogg_stream_flush_i(os,og,1);
 
519
}
493
520
 
494
521
/* This constructs pages from buffered packet segments.  The pointers
495
522
returned are to static buffers; do not free. The returned buffers are
496
523
good only until the next call (using the same ogg_stream_state) */
497
524
 
498
525
int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
 
526
  int force=0;
499
527
  if(ogg_stream_check(os)) return 0;
500
528
 
501
529
  if((os->e_o_s&&os->lacing_fill) ||          /* 'were done, now flush' case */
502
 
     os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
503
 
     os->lacing_fill>=255 ||                  /* 'segment table full' case */
504
 
     (os->lacing_fill&&!os->b_o_s)){          /* 'initial header page' case */
505
 
        
506
 
    return(ogg_stream_flush(os,og));
507
 
  }
508
 
  
509
 
  /* not enough data to construct a page and not end of stream */
510
 
  return 0;
 
530
     (os->lacing_fill&&!os->b_o_s))           /* 'initial header page' case */
 
531
    force=1;
 
532
 
 
533
  return(ogg_stream_flush_i(os,og,force));
511
534
}
512
535
 
513
536
int ogg_stream_eos(ogg_stream_state *os){
990
1013
  static int lastno=0;
991
1014
 
992
1015
  if(op->bytes!=len){
993
 
    fprintf(stderr,"incorrect packet length!\n");
 
1016
    fprintf(stderr,"incorrect packet length (%d != %d)!\n",op->bytes,len);
994
1017
    exit(1);
995
1018
  }
996
1019
  if(op->granulepos!=pos){
997
 
    fprintf(stderr,"incorrect packet position!\n");
 
1020
    fprintf(stderr,"incorrect packet granpos (%ld != %ld)!\n",(long)op->granulepos,pos);
998
1021
    exit(1);
999
1022
  }
1000
1023
 
1161
1184
const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
1162
1185
                       0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
1163
1186
                       0x01,0x02,0x03,0x04,1,0,0,0,
1164
 
                       0x54,0x05,0x51,0xc8,
1165
 
                       17,
1166
 
                       255,255,255,255,255,255,255,255,
1167
 
                       255,255,255,255,255,255,255,255,255};
 
1187
                       0xf8,0x3c,0x19,0x79,
 
1188
                       255,
 
1189
                       255,255,255,255,255,255,255,255,
 
1190
                       255,255,255,255,255,255,255,255,
 
1191
                       255,255,255,255,255,255,255,255,
 
1192
                       255,255,255,255,255,255,255,255,
 
1193
                       255,255,255,255,255,255,255,255,
 
1194
                       255,255,255,255,255,255,255,255,
 
1195
                       255,255,255,255,255,255,255,255,
 
1196
                       255,255,255,255,255,255,255,255,
 
1197
                       255,255,255,255,255,255,255,255,
 
1198
                       255,255,255,255,255,255,255,255,
 
1199
                       255,255,255,255,255,255,255,255,
 
1200
                       255,255,255,255,255,255,255,255,
 
1201
                       255,255,255,255,255,255,255,255,
 
1202
                       255,255,255,255,255,255,255,255,
 
1203
                       255,255,255,255,255,255,255,255,
 
1204
                       255,255,255,255,255,255,255,255,
 
1205
                       255,255,255,255,255,255,255,255,
 
1206
                       255,255,255,255,255,255,255,255,
 
1207
                       255,255,255,255,255,255,255,255,
 
1208
                       255,255,255,255,255,255,255,255,
 
1209
                       255,255,255,255,255,255,255,255,
 
1210
                       255,255,255,255,255,255,255,255,
 
1211
                       255,255,255,255,255,255,255,255,
 
1212
                       255,255,255,255,255,255,255,255,
 
1213
                       255,255,255,255,255,255,255,255,
 
1214
                       255,255,255,255,255,255,255,255,
 
1215
                       255,255,255,255,255,255,255,255,
 
1216
                       255,255,255,255,255,255,255,255,
 
1217
                       255,255,255,255,255,255,255,255,
 
1218
                       255,255,255,255,255,255,255,255,
 
1219
                       255,255,255,255,255,255,255,255,
 
1220
                       255,255,255,255,255,255,255};
1168
1221
 
1169
1222
const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
1170
1223
                       0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
1171
1224
                       0x01,0x02,0x03,0x04,2,0,0,0,
1172
 
                       0xc8,0xc3,0xcb,0xed,
1173
 
                       5,
1174
 
                       10,255,4,255,0};
1175
 
 
 
1225
                       0x38,0xe6,0xb6,0x28,
 
1226
                       6,
 
1227
                       255,220,255,4,255,0};
 
1228
 
 
1229
 
 
1230
/* spill expansion test */
 
1231
const int head1_4b[] = {0x4f,0x67,0x67,0x53,0,0x02,
 
1232
                        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 
1233
                        0x01,0x02,0x03,0x04,0,0,0,0,
 
1234
                        0xff,0x7b,0x23,0x17,
 
1235
                        1,
 
1236
                        0};
 
1237
 
 
1238
const int head2_4b[] = {0x4f,0x67,0x67,0x53,0,0x00,
 
1239
                        0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
 
1240
                        0x01,0x02,0x03,0x04,1,0,0,0,
 
1241
                        0xce,0x8f,0x17,0x1a,
 
1242
                        23,
 
1243
                        255,255,255,255,255,255,255,255,
 
1244
                        255,255,255,255,255,255,255,255,255,10,255,4,255,0,0};
 
1245
 
 
1246
 
 
1247
const int head3_4b[] = {0x4f,0x67,0x67,0x53,0,0x04,
 
1248
                        0x07,0x14,0x00,0x00,0x00,0x00,0x00,0x00,
 
1249
                        0x01,0x02,0x03,0x04,2,0,0,0,
 
1250
                        0x9b,0xb2,0x50,0xa1,
 
1251
                        1,
 
1252
                        0};
1176
1253
 
1177
1254
/* page with the 255 segment limit */
1178
1255
const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
1239
1316
const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
1240
1317
                       0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
1241
1318
                       0x01,0x02,0x03,0x04,1,0,0,0,
1242
 
                       0x3c,0xd9,0x4d,0x3f,
1243
 
                       17,
1244
 
                       100,255,255,255,255,255,255,255,255,
1245
 
                       255,255,255,255,255,255,255,255};
 
1319
                       0x68,0x22,0x7c,0x3d,
 
1320
                       255,
 
1321
                       100,
 
1322
                       255,255,255,255,255,255,255,255,
 
1323
                       255,255,255,255,255,255,255,255,
 
1324
                       255,255,255,255,255,255,255,255,
 
1325
                       255,255,255,255,255,255,255,255,
 
1326
                       255,255,255,255,255,255,255,255,
 
1327
                       255,255,255,255,255,255,255,255,
 
1328
                       255,255,255,255,255,255,255,255,
 
1329
                       255,255,255,255,255,255,255,255,
 
1330
                       255,255,255,255,255,255,255,255,
 
1331
                       255,255,255,255,255,255,255,255,
 
1332
                       255,255,255,255,255,255,255,255,
 
1333
                       255,255,255,255,255,255,255,255,
 
1334
                       255,255,255,255,255,255,255,255,
 
1335
                       255,255,255,255,255,255,255,255,
 
1336
                       255,255,255,255,255,255,255,255,
 
1337
                       255,255,255,255,255,255,255,255,
 
1338
                       255,255,255,255,255,255,255,255,
 
1339
                       255,255,255,255,255,255,255,255,
 
1340
                       255,255,255,255,255,255,255,255,
 
1341
                       255,255,255,255,255,255,255,255,
 
1342
                       255,255,255,255,255,255,255,255,
 
1343
                       255,255,255,255,255,255,255,255,
 
1344
                       255,255,255,255,255,255,255,255,
 
1345
                       255,255,255,255,255,255,255,255,
 
1346
                       255,255,255,255,255,255,255,255,
 
1347
                       255,255,255,255,255,255,255,255,
 
1348
                       255,255,255,255,255,255,255,255,
 
1349
                       255,255,255,255,255,255,255,255,
 
1350
                       255,255,255,255,255,255,255,255,
 
1351
                       255,255,255,255,255,255,255,255,
 
1352
                       255,255,255,255,255,255,255,255,
 
1353
                       255,255,255,255,255,255};
1246
1354
 
1247
1355
const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
1248
1356
                       0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
1249
1357
                       0x01,0x02,0x03,0x04,2,0,0,0,
1250
 
                       0x01,0xd2,0xe5,0xe5,
1251
 
                       17,
1252
 
                       255,255,255,255,255,255,255,255,
1253
 
                       255,255,255,255,255,255,255,255,255};
 
1358
                       0xf4,0x87,0xba,0xf3,
 
1359
                       255,
 
1360
                       255,255,255,255,255,255,255,255,
 
1361
                       255,255,255,255,255,255,255,255,
 
1362
                       255,255,255,255,255,255,255,255,
 
1363
                       255,255,255,255,255,255,255,255,
 
1364
                       255,255,255,255,255,255,255,255,
 
1365
                       255,255,255,255,255,255,255,255,
 
1366
                       255,255,255,255,255,255,255,255,
 
1367
                       255,255,255,255,255,255,255,255,
 
1368
                       255,255,255,255,255,255,255,255,
 
1369
                       255,255,255,255,255,255,255,255,
 
1370
                       255,255,255,255,255,255,255,255,
 
1371
                       255,255,255,255,255,255,255,255,
 
1372
                       255,255,255,255,255,255,255,255,
 
1373
                       255,255,255,255,255,255,255,255,
 
1374
                       255,255,255,255,255,255,255,255,
 
1375
                       255,255,255,255,255,255,255,255,
 
1376
                       255,255,255,255,255,255,255,255,
 
1377
                       255,255,255,255,255,255,255,255,
 
1378
                       255,255,255,255,255,255,255,255,
 
1379
                       255,255,255,255,255,255,255,255,
 
1380
                       255,255,255,255,255,255,255,255,
 
1381
                       255,255,255,255,255,255,255,255,
 
1382
                       255,255,255,255,255,255,255,255,
 
1383
                       255,255,255,255,255,255,255,255,
 
1384
                       255,255,255,255,255,255,255,255,
 
1385
                       255,255,255,255,255,255,255,255,
 
1386
                       255,255,255,255,255,255,255,255,
 
1387
                       255,255,255,255,255,255,255,255,
 
1388
                       255,255,255,255,255,255,255,255,
 
1389
                       255,255,255,255,255,255,255,255,
 
1390
                       255,255,255,255,255,255,255,255,
 
1391
                       255,255,255,255,255,255,255};
1254
1392
 
1255
1393
const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
1256
1394
                       0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
1257
1395
                       0x01,0x02,0x03,0x04,3,0,0,0,
1258
 
                       0xef,0xdd,0x88,0xde,
1259
 
                       7,
1260
 
                       255,255,75,255,4,255,0};
 
1396
                       0xf7,0x2f,0x6c,0x60,
 
1397
                       5,
 
1398
                       254,255,4,255,0};
1261
1399
 
1262
1400
/* packet that overspans over an entire page */
1263
1401
const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
1270
1408
const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
1271
1409
                       0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
1272
1410
                       0x01,0x02,0x03,0x04,1,0,0,0,
1273
 
                       0x3c,0xd9,0x4d,0x3f,
1274
 
                       17,
1275
 
                       100,255,255,255,255,255,255,255,255,
1276
 
                       255,255,255,255,255,255,255,255};
 
1411
                       0x68,0x22,0x7c,0x3d,
 
1412
                       255,
 
1413
                       100,
 
1414
                       255,255,255,255,255,255,255,255,
 
1415
                       255,255,255,255,255,255,255,255,
 
1416
                       255,255,255,255,255,255,255,255,
 
1417
                       255,255,255,255,255,255,255,255,
 
1418
                       255,255,255,255,255,255,255,255,
 
1419
                       255,255,255,255,255,255,255,255,
 
1420
                       255,255,255,255,255,255,255,255,
 
1421
                       255,255,255,255,255,255,255,255,
 
1422
                       255,255,255,255,255,255,255,255,
 
1423
                       255,255,255,255,255,255,255,255,
 
1424
                       255,255,255,255,255,255,255,255,
 
1425
                       255,255,255,255,255,255,255,255,
 
1426
                       255,255,255,255,255,255,255,255,
 
1427
                       255,255,255,255,255,255,255,255,
 
1428
                       255,255,255,255,255,255,255,255,
 
1429
                       255,255,255,255,255,255,255,255,
 
1430
                       255,255,255,255,255,255,255,255,
 
1431
                       255,255,255,255,255,255,255,255,
 
1432
                       255,255,255,255,255,255,255,255,
 
1433
                       255,255,255,255,255,255,255,255,
 
1434
                       255,255,255,255,255,255,255,255,
 
1435
                       255,255,255,255,255,255,255,255,
 
1436
                       255,255,255,255,255,255,255,255,
 
1437
                       255,255,255,255,255,255,255,255,
 
1438
                       255,255,255,255,255,255,255,255,
 
1439
                       255,255,255,255,255,255,255,255,
 
1440
                       255,255,255,255,255,255,255,255,
 
1441
                       255,255,255,255,255,255,255,255,
 
1442
                       255,255,255,255,255,255,255,255,
 
1443
                       255,255,255,255,255,255,255,255,
 
1444
                       255,255,255,255,255,255,255,255,
 
1445
                       255,255,255,255,255,255};
1277
1446
 
1278
1447
const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
1279
1448
                       0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
1280
1449
                       0x01,0x02,0x03,0x04,2,0,0,0,
1281
1450
                       0xd4,0xe0,0x60,0xe5,
1282
 
                       1,0};
 
1451
                       1,
 
1452
                       0};
1283
1453
 
1284
 
void test_pack(const int *pl, const int **headers, int byteskip, 
 
1454
void test_pack(const int *pl, const int **headers, int byteskip,
1285
1455
               int pageskip, int packetskip){
1286
1456
  unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
1287
1457
  long inptr=0;
1473
1643
    /* 17 only */
1474
1644
    const int packets[]={17, -1};
1475
1645
    const int *headret[]={head1_0,NULL};
1476
 
    
 
1646
 
1477
1647
    fprintf(stderr,"testing single page encoding... ");
1478
1648
    test_pack(packets,headret,0,0,0);
1479
1649
  }
1482
1652
    /* 17, 254, 255, 256, 500, 510, 600 byte, pad */
1483
1653
    const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
1484
1654
    const int *headret[]={head1_1,head2_1,NULL};
1485
 
    
 
1655
 
1486
1656
    fprintf(stderr,"testing basic page encoding... ");
1487
1657
    test_pack(packets,headret,0,0,0);
1488
1658
  }
1491
1661
    /* nil packets; beginning,middle,end */
1492
1662
    const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
1493
1663
    const int *headret[]={head1_2,head2_2,NULL};
1494
 
    
 
1664
 
1495
1665
    fprintf(stderr,"testing basic nil packets... ");
1496
1666
    test_pack(packets,headret,0,0,0);
1497
1667
  }
1500
1670
    /* large initial packet */
1501
1671
    const int packets[]={4345,259,255,-1};
1502
1672
    const int *headret[]={head1_3,head2_3,NULL};
1503
 
    
 
1673
 
1504
1674
    fprintf(stderr,"testing initial-packet lacing > 4k... ");
1505
1675
    test_pack(packets,headret,0,0,0);
1506
1676
  }
1507
1677
 
1508
1678
  {
1509
 
    /* continuing packet test */
1510
 
    const int packets[]={0,4345,259,255,-1};
 
1679
    /* continuing packet test; with page spill expansion, we have to
 
1680
       overflow the lacing table. */
 
1681
    const int packets[]={0,65500,259,255,-1};
1511
1682
    const int *headret[]={head1_4,head2_4,head3_4,NULL};
1512
 
    
 
1683
 
1513
1684
    fprintf(stderr,"testing single packet page span... ");
1514
1685
    test_pack(packets,headret,0,0,0);
1515
1686
  }
1516
1687
 
 
1688
  {
 
1689
    /* spill expand packet test */
 
1690
    const int packets[]={0,4345,259,255,0,0,-1};
 
1691
    const int *headret[]={head1_4b,head2_4b,head3_4b,NULL};
 
1692
 
 
1693
    fprintf(stderr,"testing page spill expansion... ");
 
1694
    test_pack(packets,headret,0,0,0);
 
1695
  }
 
1696
 
1517
1697
  /* page with the 255 segment limit */
1518
1698
  {
1519
1699
 
1557
1737
 
1558
1738
  {
1559
1739
    /* packet that overspans over an entire page */
1560
 
    const int packets[]={0,100,9000,259,255,-1};
 
1740
    const int packets[]={0,100,130049,259,255,-1};
1561
1741
    const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
1562
1742
    
1563
1743
    fprintf(stderr,"testing very large packets... ");
1567
1747
  {
1568
1748
    /* test for the libogg 1.1.1 resync in large continuation bug
1569
1749
       found by Josh Coalson)  */
1570
 
    const int packets[]={0,100,9000,259,255,-1};
 
1750
    const int packets[]={0,100,130049,259,255,-1};
1571
1751
    const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
1572
1752
    
1573
1753
    fprintf(stderr,"testing continuation resync in very large packets... ");
1576
1756
 
1577
1757
  {
1578
1758
    /* term only page.  why not? */
1579
 
    const int packets[]={0,100,4080,-1};
 
1759
    const int packets[]={0,100,64770,-1};
1580
1760
    const int *headret[]={head1_7,head2_7,head3_7,NULL};
1581
1761
    
1582
1762
    fprintf(stderr,"testing zero data page (1 nil packet)... ");
1588
1768
  {
1589
1769
    /* build a bunch of pages for testing */
1590
1770
    unsigned char *data=_ogg_malloc(1024*1024);
1591
 
    int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
 
1771
    int pl[]={0, 1,1,98,4079, 1,1,2954,2057, 76,34,912,0,234,1000,1000, 1000,300,-1};
1592
1772
    int inptr=0,i,j;
1593
1773
    ogg_page og[5];
1594
1774
    
1649
1829
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1650
1830
      checkpacket(&test,0,0,0);
1651
1831
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1652
 
      checkpacket(&test,100,1,-1);
1653
 
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1654
 
      checkpacket(&test,4079,2,3000);
 
1832
      checkpacket(&test,1,1,-1);
 
1833
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1834
      checkpacket(&test,1,2,-1);
 
1835
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1836
      checkpacket(&test,98,3,-1);
 
1837
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1838
      checkpacket(&test,4079,4,5000);
1655
1839
      if(ogg_stream_packetout(&os_de,&test)!=-1){
1656
1840
        fprintf(stderr,"Error: loss of page did not return error\n");
1657
1841
        exit(1);
1658
1842
      }
1659
1843
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1660
 
      checkpacket(&test,76,5,-1);
 
1844
      checkpacket(&test,76,9,-1);
1661
1845
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1662
 
      checkpacket(&test,34,6,-1);
 
1846
      checkpacket(&test,34,10,-1);
1663
1847
      fprintf(stderr,"ok.\n");
1664
1848
    }
1665
1849
 
1692
1876
      ogg_stream_pagein(&os_de,&temp);
1693
1877
 
1694
1878
      /* do we get the expected results/packets? */
1695
 
      
 
1879
 
1696
1880
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1697
1881
      checkpacket(&test,0,0,0);
1698
1882
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1699
 
      checkpacket(&test,100,1,-1);
1700
 
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1701
 
      checkpacket(&test,4079,2,3000);
1702
 
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1703
 
      checkpacket(&test,2956,3,4000);
 
1883
      checkpacket(&test,1,1,-1);
 
1884
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1885
      checkpacket(&test,1,2,-1);
 
1886
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1887
      checkpacket(&test,98,3,-1);
 
1888
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1889
      checkpacket(&test,4079,4,5000);
 
1890
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1891
      checkpacket(&test,1,5,-1);
 
1892
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1893
      checkpacket(&test,1,6,-1);
 
1894
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1895
      checkpacket(&test,2954,7,-1);
 
1896
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
 
1897
      checkpacket(&test,2057,8,9000);
1704
1898
      if(ogg_stream_packetout(&os_de,&test)!=-1){
1705
1899
        fprintf(stderr,"Error: loss of page did not return error\n");
1706
1900
        exit(1);
1707
1901
      }
1708
1902
      if(ogg_stream_packetout(&os_de,&test)!=1)error();
1709
 
      checkpacket(&test,300,13,14000);
 
1903
      checkpacket(&test,300,17,18000);
1710
1904
      fprintf(stderr,"ok.\n");
1711
1905
    }
1712
 
    
 
1906
 
1713
1907
    /* the rest only test sync */
1714
1908
    {
1715
1909
      ogg_page og_de;
1720
1914
             3);
1721
1915
      ogg_sync_wrote(&oy,3);
1722
1916
      if(ogg_sync_pageout(&oy,&og_de)>0)error();
1723
 
      
 
1917
 
1724
1918
      /* Test fractional page inputs: incomplete fixed header */
1725
1919
      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
1726
1920
             20);
1727
1921
      ogg_sync_wrote(&oy,20);
1728
1922
      if(ogg_sync_pageout(&oy,&og_de)>0)error();
1729
 
      
 
1923
 
1730
1924
      /* Test fractional page inputs: incomplete header */
1731
1925
      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
1732
1926
             5);
1733
1927
      ogg_sync_wrote(&oy,5);
1734
1928
      if(ogg_sync_pageout(&oy,&og_de)>0)error();
1735
 
      
 
1929
 
1736
1930
      /* Test fractional page inputs: incomplete body */
1737
 
      
 
1931
 
1738
1932
      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
1739
1933
             og[1].header_len-28);
1740
1934
      ogg_sync_wrote(&oy,og[1].header_len-28);
1741
1935
      if(ogg_sync_pageout(&oy,&og_de)>0)error();
1742
 
      
 
1936
 
1743
1937
      memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
1744
1938
      ogg_sync_wrote(&oy,1000);
1745
1939
      if(ogg_sync_pageout(&oy,&og_de)>0)error();
1746
 
      
 
1940
 
1747
1941
      memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
1748
1942
             og[1].body_len-1000);
1749
1943
      ogg_sync_wrote(&oy,og[1].body_len-1000);
1750
1944
      if(ogg_sync_pageout(&oy,&og_de)<=0)error();
1751
 
      
 
1945
 
1752
1946
      fprintf(stderr,"ok.\n");
1753
1947
    }
1754
1948
 
1756
1950
    {
1757
1951
      ogg_page og_de;
1758
1952
      fprintf(stderr,"Testing sync on 1+partial inputs... ");
1759
 
      ogg_sync_reset(&oy); 
 
1953
      ogg_sync_reset(&oy);
1760
1954
 
1761
1955
      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
1762
1956
             og[1].header_len);