Ticket #4209: libogg-1.1.4.diff
File libogg-1.1.4.diff, 81.2 KB (added by , 15 years ago) |
---|
-
src/add-ons/media/plugins/ogg/OggTobiasStream.h
7 7 8 8 class OggTobiasStream : public OggStream { 9 9 public: 10 static bool IsValidHeader(const ogg_packet & packet);10 static bool IsValidHeader(const ogg_packet & packet); 11 11 public: 12 OggTobiasStream(long serialno);13 virtual ~OggTobiasStream();12 OggTobiasStream(long serialno); 13 virtual ~OggTobiasStream(); 14 14 15 15 virtual status_t GetStreamInfo(int64 *frameCount, bigtime_t *duration, 16 16 media_format *format); -
src/add-ons/media/plugins/ogg/OggVorbisSeekable.h
9 9 private: 10 10 typedef OggSeekable inherited; 11 11 public: 12 static bool IsValidHeader(const ogg_packet & packet);12 static bool IsValidHeader(const ogg_packet & packet); 13 13 public: 14 OggVorbisSeekable(long serialno);15 virtual ~OggVorbisSeekable();14 OggVorbisSeekable(long serialno); 15 virtual ~OggVorbisSeekable(); 16 16 17 17 virtual status_t GetStreamInfo(int64 *frameCount, bigtime_t *duration, 18 18 media_format *format); -
src/add-ons/media/plugins/ogg/OggSpeexStream.h
7 7 8 8 class OggSpeexStream : public OggStream { 9 9 public: 10 static bool IsValidHeader(const ogg_packet & packet);10 static bool IsValidHeader(const ogg_packet & packet); 11 11 public: 12 OggSpeexStream(long serialno);13 virtual ~OggSpeexStream();12 OggSpeexStream(long serialno); 13 virtual ~OggSpeexStream(); 14 14 15 15 virtual status_t GetStreamInfo(int64 *frameCount, bigtime_t *duration, 16 16 media_format *format); -
src/add-ons/media/plugins/ogg/OggTrack.h
12 12 protected: 13 13 static bool findIdentifier(const ogg_packet & packet, 14 14 const char * id, uint pos); 15 OggTrack(long serialno);15 OggTrack(long serialno); 16 16 public: 17 virtual ~OggTrack();18 long GetSerial() const;17 virtual ~OggTrack(); 18 long GetSerial() const; 19 19 20 20 // push interface 21 21 virtual status_t AddPage(off_t position, const ogg_page & page) = 0; … … 29 29 30 30 protected: 31 31 // GetStreamInfo helpers 32 void SaveHeaderPacket(ogg_packet packet);32 void SaveHeaderPacket(ogg_packet packet); 33 33 const std::vector<ogg_packet> & GetHeaderPackets(); 34 34 35 35 private: 36 36 std::vector<ogg_packet> fHeaderPackets; 37 long fSerialno;37 long fSerialno; 38 38 }; 39 39 40 40 } } // namespace BPrivate::media -
src/add-ons/media/plugins/ogg/OggSeekable.h
20 20 media_header *mediaHeader); 21 21 22 22 protected: 23 OggSeekable(long serialno);23 OggSeekable(long serialno); 24 24 public: 25 virtual ~OggSeekable();25 virtual ~OggSeekable(); 26 26 27 27 // reader push input function 28 status_t AddPage(off_t position, const ogg_page & page);28 status_t AddPage(off_t position, const ogg_page & page); 29 29 30 void SetLastPagePosition(off_t position);31 off_t GetLastPagePosition();30 void SetLastPagePosition(off_t position); 31 off_t GetLastPagePosition(); 32 32 private: 33 33 off_t fLastPagePosition; 34 34 35 35 protected: 36 off_t Seek(off_t position, int32 mode);37 off_t Position(void) const;38 status_t GetSize(off_t * size);39 status_t ReadPage(ogg_page * page, int read_size = 4*B_PAGE_SIZE);36 off_t Seek(off_t position, int32 mode); 37 off_t Position(void) const; 38 status_t GetSize(off_t * size); 39 status_t ReadPage(ogg_page * page, int read_size = 4*B_PAGE_SIZE); 40 40 41 41 // subclass pull input function 42 status_t GetPacket(ogg_packet * packet);42 status_t GetPacket(ogg_packet * packet); 43 43 44 44 protected: 45 45 int64 fCurrentFrame; -
src/add-ons/media/plugins/ogg/OggTobiasSeekable.h
9 9 private: 10 10 typedef OggSeekable inherited; 11 11 public: 12 static bool IsValidHeader(const ogg_packet & packet);12 static bool IsValidHeader(const ogg_packet & packet); 13 13 public: 14 OggTobiasSeekable(long serialno);15 virtual ~OggTobiasSeekable();14 OggTobiasSeekable(long serialno); 15 virtual ~OggTobiasSeekable(); 16 16 17 17 virtual status_t GetStreamInfo(int64 *frameCount, bigtime_t *duration, 18 18 media_format *format); -
src/add-ons/media/plugins/ogg/libogg/framing.c
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-200 2*8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 9 * by the Xiph.Org Foundation http://www.xiph.org/ * 10 10 * * 11 11 ******************************************************************** 12 12 13 function: code raw [Vorbis]packets into framed OggSquish stream and13 function: code raw packets into framed OggSquish stream and 14 14 decode Ogg streams back into raw packets 15 last mod: $Id : framing.c,v 1.2 2004/02/24 13:52:39 shatty Exp$15 last mod: $Id$ 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 … … 26 26 27 27 /* A complete description of Ogg framing exists in docs/framing.html */ 28 28 29 int ogg_page_version( ogg_page *og){29 int ogg_page_version(const ogg_page *og){ 30 30 return((int)(og->header[4])); 31 31 } 32 32 33 int ogg_page_continued( ogg_page *og){33 int ogg_page_continued(const ogg_page *og){ 34 34 return((int)(og->header[5]&0x01)); 35 35 } 36 36 37 int ogg_page_bos( ogg_page *og){37 int ogg_page_bos(const ogg_page *og){ 38 38 return((int)(og->header[5]&0x02)); 39 39 } 40 40 41 int ogg_page_eos( ogg_page *og){41 int ogg_page_eos(const ogg_page *og){ 42 42 return((int)(og->header[5]&0x04)); 43 43 } 44 44 45 ogg_int64_t ogg_page_granulepos( ogg_page *og){45 ogg_int64_t ogg_page_granulepos(const ogg_page *og){ 46 46 unsigned char *page=og->header; 47 47 ogg_int64_t granulepos=page[13]&(0xff); 48 48 granulepos= (granulepos<<8)|(page[12]&0xff); … … 55 55 return(granulepos); 56 56 } 57 57 58 int ogg_page_serialno( ogg_page *og){58 int ogg_page_serialno(const ogg_page *og){ 59 59 return(og->header[14] | 60 61 62 60 (og->header[15]<<8) | 61 (og->header[16]<<16) | 62 (og->header[17]<<24)); 63 63 } 64 64 65 long ogg_page_pageno( ogg_page *og){65 long ogg_page_pageno(const ogg_page *og){ 66 66 return(og->header[18] | 67 68 69 67 (og->header[19]<<8) | 68 (og->header[20]<<16) | 69 (og->header[21]<<24)); 70 70 } 71 71 72 72 … … 88 88 ogg_page_continued(page) !=0 89 89 */ 90 90 91 int ogg_page_packets( ogg_page *og){91 int ogg_page_packets(const ogg_page *og){ 92 92 int i,n=og->header[26],count=0; 93 93 for(i=0;i<n;i++) 94 94 if(og->header[27+i]<255)count++; … … 108 108 for (i=0; i<8; i++) 109 109 if (r & 0x80000000UL) 110 110 r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator 111 112 113 111 polynomial, although we use an 112 unreflected alg and an init/final 113 of 0, not 0xffffffff */ 114 114 else 115 115 r<<=1; 116 116 return (r & 0xffffffffUL); 117 117 } 118 118 #endif 119 119 120 static ogg_uint32_t crc_lookup[256]={120 static const ogg_uint32_t crc_lookup[256]={ 121 121 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9, 122 122 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005, 123 123 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61, … … 189 189 if(os){ 190 190 memset(os,0,sizeof(*os)); 191 191 os->body_storage=16*1024; 192 os->lacing_storage=1024; 193 192 194 os->body_data=_ogg_malloc(os->body_storage*sizeof(*os->body_data)); 193 194 os->lacing_storage=1024;195 195 os->lacing_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals)); 196 196 os->granule_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals)); 197 197 198 if(!os->body_data || !os->lacing_vals || !os->granule_vals){ 199 ogg_stream_clear(os); 200 return -1; 201 } 202 198 203 os->serialno=serialno; 199 204 200 205 return(0); … … 202 207 return(-1); 203 208 } 204 209 210 /* async/delayed error detection for the ogg_stream_state */ 211 int ogg_stream_check(ogg_stream_state *os){ 212 if(!os || !os->body_data) return -1; 213 return 0; 214 } 215 205 216 /* _clear does not free os, only the non-flat storage within */ 206 217 int ogg_stream_clear(ogg_stream_state *os){ 207 218 if(os){ … … 225 236 /* Helpers for ogg_stream_encode; this keeps the structure and 226 237 what's happening fairly clear */ 227 238 228 static void_os_body_expand(ogg_stream_state *os,int needed){239 static int _os_body_expand(ogg_stream_state *os,int needed){ 229 240 if(os->body_storage<=os->body_fill+needed){ 241 void *ret; 242 ret=_ogg_realloc(os->body_data,(os->body_storage+needed+1024)* 243 sizeof(*os->body_data)); 244 if(!ret){ 245 ogg_stream_clear(os); 246 return -1; 247 } 230 248 os->body_storage+=(needed+1024); 231 os->body_data= _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));249 os->body_data=ret; 232 250 } 251 return 0; 233 252 } 234 253 235 static void_os_lacing_expand(ogg_stream_state *os,int needed){254 static int _os_lacing_expand(ogg_stream_state *os,int needed){ 236 255 if(os->lacing_storage<=os->lacing_fill+needed){ 256 void *ret; 257 ret=_ogg_realloc(os->lacing_vals,(os->lacing_storage+needed+32)* 258 sizeof(*os->lacing_vals)); 259 if(!ret){ 260 ogg_stream_clear(os); 261 return -1; 262 } 263 os->lacing_vals=ret; 264 ret=_ogg_realloc(os->granule_vals,(os->lacing_storage+needed+32)* 265 sizeof(*os->granule_vals)); 266 if(!ret){ 267 ogg_stream_clear(os); 268 return -1; 269 } 270 os->granule_vals=ret; 237 271 os->lacing_storage+=(needed+32); 238 os->lacing_vals=_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));239 os->granule_vals=_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));240 272 } 273 return 0; 241 274 } 242 275 243 276 /* checksum the page */ … … 260 293 for(i=0;i<og->body_len;i++) 261 294 crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]]; 262 295 263 og->header[22]= crc_reg&0xff;264 og->header[23]=( crc_reg>>8)&0xff;265 og->header[24]=( crc_reg>>16)&0xff;266 og->header[25]=( crc_reg>>24)&0xff;296 og->header[22]=(unsigned char)(crc_reg&0xff); 297 og->header[23]=(unsigned char)((crc_reg>>8)&0xff); 298 og->header[24]=(unsigned char)((crc_reg>>16)&0xff); 299 og->header[25]=(unsigned char)((crc_reg>>24)&0xff); 267 300 } 268 301 } 269 302 270 303 /* submit data to the internal buffer of the framing engine */ 271 int ogg_stream_ packetin(ogg_stream_state *os,ogg_packet *op){272 int lacing_vals=op->bytes/255+1,i;304 int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, int count, 305 long e_o_s, ogg_int64_t granulepos){ 273 306 307 int bytes = 0, lacing_vals, i; 308 309 if(ogg_stream_check(os)) return -1; 310 if(!iov) return 0; 311 312 for (i = 0; i < count; ++i) bytes += (int)iov[i].iov_len; 313 lacing_vals=bytes/255+1; 314 274 315 if(os->body_returned){ 275 316 /* advance packet data according to the body_returned pointer. We 276 317 had to keep it around to return a pointer into the buffer last … … 279 320 os->body_fill-=os->body_returned; 280 321 if(os->body_fill) 281 322 memmove(os->body_data,os->body_data+os->body_returned, 282 323 os->body_fill); 283 324 os->body_returned=0; 284 325 } 285 326 286 327 /* make sure we have the buffer storage */ 287 _os_body_expand(os,op->bytes);288 _os_lacing_expand(os,lacing_vals);328 if(_os_body_expand(os,bytes) || _os_lacing_expand(os,lacing_vals)) 329 return -1; 289 330 290 331 /* Copy in the submitted packet. Yes, the copy is a waste; this is 291 332 the liability of overly clean abstraction for the time being. It 292 333 will actually be fairly easy to eliminate the extra copy in the 293 334 future */ 294 335 295 memcpy(os->body_data+os->body_fill,op->packet,op->bytes); 296 os->body_fill+=op->bytes; 336 for (i = 0; i < count; ++i) { 337 memcpy(os->body_data+os->body_fill, iov[i].iov_base, iov[i].iov_len); 338 os->body_fill += (int)iov[i].iov_len; 339 } 297 340 298 341 /* Store lacing vals for this packet */ 299 342 for(i=0;i<lacing_vals-1;i++){ 300 343 os->lacing_vals[os->lacing_fill+i]=255; 301 344 os->granule_vals[os->lacing_fill+i]=os->granulepos; 302 345 } 303 os->lacing_vals[os->lacing_fill+i]= (op->bytes)%255;304 os->granulepos=os->granule_vals[os->lacing_fill+i]= op->granulepos;346 os->lacing_vals[os->lacing_fill+i]=bytes%255; 347 os->granulepos=os->granule_vals[os->lacing_fill+i]=granulepos; 305 348 306 349 /* flag the first segment as the beginning of the packet */ 307 350 os->lacing_vals[os->lacing_fill]|= 0x100; … … 311 354 /* for the sake of completeness */ 312 355 os->packetno++; 313 356 314 if( op->e_o_s)os->e_o_s=1;357 if(e_o_s)os->e_o_s=1; 315 358 316 359 return(0); 317 360 } 318 361 362 int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){ 363 ogg_iovec_t iov; 364 iov.iov_base = op->packet; 365 iov.iov_len = op->bytes; 366 return ogg_stream_iovecin(os, &iov, 1, op->e_o_s, op->granulepos); 367 } 368 319 369 /* This will flush remaining packets into a page (returning nonzero), 320 370 even if there is not enough data to trigger a flush normally 321 371 (undersized page). If there are no packets or partial packets to … … 336 386 int maxvals=(os->lacing_fill>255?255:os->lacing_fill); 337 387 int bytes=0; 338 388 long acc=0; 339 ogg_int64_t granule_pos= os->granule_vals[0];389 ogg_int64_t granule_pos=-1; 340 390 341 if(maxvals==0)return(0); 391 if(ogg_stream_check(os)) return 0; 392 if(maxvals==0)return 0; 342 393 343 394 /* construct a page */ 344 395 /* decide how many segments to include */ … … 349 400 granule_pos=0; 350 401 for(vals=0;vals<maxvals;vals++){ 351 402 if((os->lacing_vals[vals]&0x0ff)<255){ 352 353 403 vals++; 404 break; 354 405 } 355 406 } 356 407 }else{ 357 408 for(vals=0;vals<maxvals;vals++){ 358 409 if(acc>4096)break; 359 410 acc+=os->lacing_vals[vals]&0x0ff; 360 granule_pos=os->granule_vals[vals]; 411 if((os->lacing_vals[vals]&0xff)<255) 412 granule_pos=os->granule_vals[vals]; 361 413 } 362 414 } 363 415 … … 378 430 379 431 /* 64 bits of PCM position */ 380 432 for(i=6;i<14;i++){ 381 os->header[i]=( granule_pos&0xff);433 os->header[i]=(unsigned char)(granule_pos&0xff); 382 434 granule_pos>>=8; 383 435 } 384 436 … … 386 438 { 387 439 long serialno=os->serialno; 388 440 for(i=14;i<18;i++){ 389 os->header[i]=( serialno&0xff);441 os->header[i]=(unsigned char)(serialno&0xff); 390 442 serialno>>=8; 391 443 } 392 444 } … … 394 446 /* 32 bits of page counter (we have both counter and page header 395 447 because this val can roll over) */ 396 448 if(os->pageno==-1)os->pageno=0; /* because someone called 397 398 399 400 449 stream_reset; this would be a 450 strange thing to do in an 451 encode stream, but it has 452 plausible uses */ 401 453 { 402 454 long pageno=os->pageno++; 403 455 for(i=18;i<22;i++){ 404 os->header[i]=( pageno&0xff);456 os->header[i]=(unsigned char)(pageno&0xff); 405 457 pageno>>=8; 406 458 } 407 459 } … … 413 465 os->header[25]=0; 414 466 415 467 /* segment table */ 416 os->header[26]= vals&0xff;468 os->header[26]=(unsigned char)(vals&0xff); 417 469 for(i=0;i<vals;i++) 418 bytes+=os->header[i+27]=( os->lacing_vals[i]&0xff);470 bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff); 419 471 420 472 /* set pointers in the ogg_page struct */ 421 473 og->header=os->header; … … 444 496 good only until the next call (using the same ogg_stream_state) */ 445 497 446 498 int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){ 499 if(ogg_stream_check(os)) return 0; 447 500 448 501 if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */ 449 502 os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */ … … 454 507 } 455 508 456 509 /* not enough data to construct a page and not end of stream */ 457 return (0);510 return 0; 458 511 } 459 512 460 513 int ogg_stream_eos(ogg_stream_state *os){ 514 if(ogg_stream_check(os)) return 1; 461 515 return os->e_o_s; 462 516 } 463 517 … … 474 528 ogg_stream_pagein() along with the appropriate 475 529 ogg_stream_state* (ie, matching serialno). We then get raw 476 530 packets out calling ogg_stream_packetout() with a 477 ogg_stream_state. See the 'frame-prog.txt' docs for details and 478 example code. */ 531 ogg_stream_state. */ 479 532 480 533 /* initialize the struct to a known state */ 481 534 int ogg_sync_init(ogg_sync_state *oy){ 482 535 if(oy){ 536 oy->storage = -1; /* used as a readiness flag */ 483 537 memset(oy,0,sizeof(*oy)); 484 538 } 485 539 return(0); … … 489 543 int ogg_sync_clear(ogg_sync_state *oy){ 490 544 if(oy){ 491 545 if(oy->data)_ogg_free(oy->data); 492 ogg_sync_init(oy);546 memset(oy,0,sizeof(*oy)); 493 547 } 494 548 return(0); 495 549 } … … 502 556 return(0); 503 557 } 504 558 559 int ogg_sync_check(ogg_sync_state *oy){ 560 if(oy->storage<0) return -1; 561 return 0; 562 } 563 505 564 char *ogg_sync_buffer(ogg_sync_state *oy, long size){ 565 if(ogg_sync_check(oy)) return NULL; 506 566 507 567 /* first, clear out any space that has been previously returned */ 508 568 if(oy->returned){ … … 515 575 if(size>oy->storage-oy->fill){ 516 576 /* We need to extend the internal buffer */ 517 577 long newsize=size+oy->fill+4096; /* an extra page to be nice */ 578 void *ret; 518 579 519 580 if(oy->data) 520 oy->data=_ogg_realloc(oy->data,newsize);581 ret=_ogg_realloc(oy->data,newsize); 521 582 else 522 oy->data=_ogg_malloc(newsize); 583 ret=_ogg_malloc(newsize); 584 if(!ret){ 585 ogg_sync_clear(oy); 586 return NULL; 587 } 588 oy->data=ret; 523 589 oy->storage=newsize; 524 590 } 525 591 … … 528 594 } 529 595 530 596 int ogg_sync_wrote(ogg_sync_state *oy, long bytes){ 531 if(oy->fill+bytes>oy->storage)return(-1); 597 if(ogg_sync_check(oy))return -1; 598 if(oy->fill+bytes>oy->storage)return -1; 532 599 oy->fill+=bytes; 533 600 return(0); 534 601 } … … 547 614 unsigned char *page=oy->data+oy->returned; 548 615 unsigned char *next; 549 616 long bytes=oy->fill-oy->returned; 617 618 if(ogg_sync_check(oy))return 0; 550 619 551 620 if(oy->headerbytes==0){ 552 621 int headerbytes,i; … … 586 655 /* Compare */ 587 656 if(memcmp(chksum,page+22,4)){ 588 657 /* D'oh. Mismatch! Corrupt page (or miscapture and not a page 589 658 at all) */ 590 659 /* replace the computed checksum with the one actually read in */ 591 660 memcpy(page+22,chksum,4); 592 661 … … 624 693 if(!next) 625 694 next=oy->data+oy->fill; 626 695 627 oy->returned= next-oy->data;628 return( -(next-page));696 oy->returned=(int)(next-oy->data); 697 return((long)-(next-page)); 629 698 } 630 699 631 700 /* sync the stream and get a page. Keep trying until we find a page. … … 641 710 642 711 int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){ 643 712 713 if(ogg_sync_check(oy))return 0; 714 644 715 /* all we need to do is verify a page at the head of the stream 645 716 buffer. If it doesn't verify, we look for the next potential 646 717 frame */ 647 718 648 while(1){719 for(;;){ 649 720 long ret=ogg_sync_pageseek(oy,og); 650 721 if(ret>0){ 651 722 /* have a page */ … … 685 756 long pageno=ogg_page_pageno(og); 686 757 int segments=header[26]; 687 758 759 if(ogg_stream_check(os)) return -1; 760 688 761 /* clean up 'returned data' */ 689 762 { 690 763 long lr=os->lacing_returned; … … 694 767 if(br){ 695 768 os->body_fill-=br; 696 769 if(os->body_fill) 697 770 memmove(os->body_data,os->body_data+br,os->body_fill); 698 771 os->body_returned=0; 699 772 } 700 773 701 774 if(lr){ 702 775 /* segment table */ 703 776 if(os->lacing_fill-lr){ 704 705 706 707 777 memmove(os->lacing_vals,os->lacing_vals+lr, 778 (os->lacing_fill-lr)*sizeof(*os->lacing_vals)); 779 memmove(os->granule_vals,os->granule_vals+lr, 780 (os->lacing_fill-lr)*sizeof(*os->granule_vals)); 708 781 } 709 782 os->lacing_fill-=lr; 710 783 os->lacing_packet-=lr; … … 716 789 if(serialno!=os->serialno)return(-1); 717 790 if(version>0)return(-1); 718 791 719 _os_lacing_expand(os,segments+1);792 if(_os_lacing_expand(os,segments+1)) return -1; 720 793 721 794 /* are we in sequence? */ 722 795 if(pageno!=os->pageno){ … … 732 805 os->lacing_vals[os->lacing_fill++]=0x400; 733 806 os->lacing_packet++; 734 807 } 808 } 735 809 736 /* are we a 'continued packet' page? If so, we'll need to skip 737 some segments */ 738 if(continued){ 810 /* are we a 'continued packet' page? If so, we may need to skip 811 some segments */ 812 if(continued){ 813 if(os->lacing_fill<1 || 814 os->lacing_vals[os->lacing_fill-1]==0x400){ 739 815 bos=0; 740 816 for(;segptr<segments;segptr++){ 741 742 743 744 745 746 747 817 int val=header[27+segptr]; 818 body+=val; 819 bodysize-=val; 820 if(val<255){ 821 segptr++; 822 break; 823 } 748 824 } 749 825 } 750 826 } 751 827 752 828 if(bodysize){ 753 _os_body_expand(os,bodysize);829 if(_os_body_expand(os,bodysize)) return -1; 754 830 memcpy(os->body_data+os->body_fill,body,bodysize); 755 831 os->body_fill+=bodysize; 756 832 } … … 763 839 os->granule_vals[os->lacing_fill]=-1; 764 840 765 841 if(bos){ 766 767 842 os->lacing_vals[os->lacing_fill]|=0x100; 843 bos=0; 768 844 } 769 845 770 846 if(val<255)saved=os->lacing_fill; … … 795 871 796 872 /* clear things to an initial state. Good to call, eg, before seeking */ 797 873 int ogg_sync_reset(ogg_sync_state *oy){ 874 if(ogg_sync_check(oy))return -1; 875 798 876 oy->fill=0; 799 877 oy->returned=0; 800 878 oy->unsynced=0; … … 804 882 } 805 883 806 884 int ogg_stream_reset(ogg_stream_state *os){ 885 if(ogg_stream_check(os)) return -1; 886 807 887 os->body_fill=0; 808 888 os->body_returned=0; 809 889 … … 823 903 } 824 904 825 905 int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){ 906 if(ogg_stream_check(os)) return -1; 826 907 ogg_stream_reset(os); 827 908 os->serialno=serialno; 828 909 return(0); … … 883 964 } 884 965 885 966 int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){ 967 if(ogg_stream_check(os)) return 0; 886 968 return _packetout(os,op,1); 887 969 } 888 970 889 971 int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){ 972 if(ogg_stream_check(os)) return 0; 890 973 return _packetout(os,op,0); 891 974 } 892 975 … … 927 1010 lastno=no; 928 1011 if(op->packetno!=sequence){ 929 1012 fprintf(stderr,"incorrect packet sequence %ld != %d\n", 930 1013 (long)(op->packetno),sequence); 931 1014 exit(1); 932 1015 } 933 1016 … … 935 1018 for(j=0;j<op->bytes;j++) 936 1019 if(op->packet[j]!=((j+no)&0xff)){ 937 1020 fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n", 938 1021 j,op->packet[j],(j+no)&0xff); 939 1022 exit(1); 940 1023 } 941 1024 } … … 946 1029 for(j=0;j<og->body_len;j++) 947 1030 if(og->body[j]!=data[j]){ 948 1031 fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n", 949 1032 j,data[j],og->body[j]); 950 1033 exit(1); 951 1034 } 952 1035 … … 955 1038 if(og->header[j]!=header[j]){ 956 1039 fprintf(stderr,"header content mismatch at pos %ld:\n",j); 957 1040 for(j=0;j<header[26]+27;j++) 958 1041 fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]); 959 1042 fprintf(stderr,"\n"); 960 1043 exit(1); 961 1044 } 962 1045 } 963 1046 if(og->header_len!=header[26]+27){ 964 1047 fprintf(stderr,"header length incorrect! (%ld!=%d)\n", 965 1048 og->header_len,header[26]+27); 966 1049 exit(1); 967 1050 } 968 1051 } … … 971 1054 int j; 972 1055 fprintf(stderr,"\nHEADER:\n"); 973 1056 fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n", 974 975 1057 og->header[0],og->header[1],og->header[2],og->header[3], 1058 (int)og->header[4],(int)og->header[5]); 976 1059 977 1060 fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n", 978 979 980 981 982 983 1061 (og->header[9]<<24)|(og->header[8]<<16)| 1062 (og->header[7]<<8)|og->header[6], 1063 (og->header[17]<<24)|(og->header[16]<<16)| 1064 (og->header[15]<<8)|og->header[14], 1065 ((long)(og->header[21])<<24)|(og->header[20]<<16)| 1066 (og->header[19]<<8)|og->header[18]); 984 1067 985 1068 fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (", 986 987 988 1069 (int)og->header[22],(int)og->header[23], 1070 (int)og->header[24],(int)og->header[25], 1071 (int)og->header[26]); 989 1072 990 1073 for(j=27;j<og->header_len;j++) 991 1074 fprintf(stderr,"%d ",(int)og->header[j]); … … 1002 1085 og->body=temp; 1003 1086 } 1004 1087 1088 void free_page(ogg_page *og){ 1089 _ogg_free (og->header); 1090 _ogg_free (og->body); 1091 } 1092 1005 1093 void error(void){ 1006 1094 fprintf(stderr,"error!\n"); 1007 1095 exit(1); … … 1009 1097 1010 1098 /* 17 only */ 1011 1099 const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06, 1012 1013 1014 1015 1016 1100 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1101 0x01,0x02,0x03,0x04,0,0,0,0, 1102 0x15,0xed,0xec,0x91, 1103 1, 1104 17}; 1017 1105 1018 1106 /* 17, 254, 255, 256, 500, 510, 600 byte, pad */ 1019 1107 const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02, 1020 1021 1022 1023 1024 1108 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1109 0x01,0x02,0x03,0x04,0,0,0,0, 1110 0x59,0x10,0x6c,0x2c, 1111 1, 1112 17}; 1025 1113 const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04, 1026 1027 1028 1029 1030 1031 1114 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00, 1115 0x01,0x02,0x03,0x04,1,0,0,0, 1116 0x89,0x33,0x85,0xce, 1117 13, 1118 254,255,0,255,1,255,245,255,255,0, 1119 255,255,90}; 1032 1120 1033 1121 /* nil packets; beginning,middle,end */ 1034 1122 const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02, 1035 1036 1037 1038 1039 1123 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1124 0x01,0x02,0x03,0x04,0,0,0,0, 1125 0xff,0x7b,0x23,0x17, 1126 1, 1127 0}; 1040 1128 const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04, 1041 1042 1043 1044 1045 1046 1129 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00, 1130 0x01,0x02,0x03,0x04,1,0,0,0, 1131 0x5c,0x3f,0x66,0xcb, 1132 17, 1133 17,254,255,0,0,255,1,0,255,245,255,255,0, 1134 255,255,90,0}; 1047 1135 1048 1136 /* large initial packet */ 1049 1137 const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02, 1050 1051 1052 1053 1054 1055 1138 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1139 0x01,0x02,0x03,0x04,0,0,0,0, 1140 0x01,0x27,0x31,0xaa, 1141 18, 1142 255,255,255,255,255,255,255,255, 1143 255,255,255,255,255,255,255,255,255,10}; 1056 1144 1057 1145 const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04, 1058 1059 1060 1061 1062 1146 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00, 1147 0x01,0x02,0x03,0x04,1,0,0,0, 1148 0x7f,0x4e,0x8a,0xd2, 1149 4, 1150 255,4,255,0}; 1063 1151 1064 1152 1065 1153 /* continuing packet test */ 1066 1154 const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02, 1067 1068 1069 1070 1071 1155 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1156 0x01,0x02,0x03,0x04,0,0,0,0, 1157 0xff,0x7b,0x23,0x17, 1158 1, 1159 0}; 1072 1160 1073 1161 const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00, 1074 0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,1075 1076 0x34,0x24,0xd5,0x29,1077 1078 1079 1162 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 1163 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}; 1080 1168 1081 1169 const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05, 1082 1083 1084 1085 1086 1170 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00, 1171 0x01,0x02,0x03,0x04,2,0,0,0, 1172 0xc8,0xc3,0xcb,0xed, 1173 5, 1174 10,255,4,255,0}; 1087 1175 1088 1176 1089 1177 /* page with the 255 segment limit */ 1090 1178 const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02, 1091 1092 1093 1094 1095 1179 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1180 0x01,0x02,0x03,0x04,0,0,0,0, 1181 0xff,0x7b,0x23,0x17, 1182 1, 1183 0}; 1096 1184 1097 1185 const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00, 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1186 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00, 1187 0x01,0x02,0x03,0x04,1,0,0,0, 1188 0xed,0x2a,0x2e,0xa7, 1189 255, 1190 10,10,10,10,10,10,10,10, 1191 10,10,10,10,10,10,10,10, 1192 10,10,10,10,10,10,10,10, 1193 10,10,10,10,10,10,10,10, 1194 10,10,10,10,10,10,10,10, 1195 10,10,10,10,10,10,10,10, 1196 10,10,10,10,10,10,10,10, 1197 10,10,10,10,10,10,10,10, 1198 10,10,10,10,10,10,10,10, 1199 10,10,10,10,10,10,10,10, 1200 10,10,10,10,10,10,10,10, 1201 10,10,10,10,10,10,10,10, 1202 10,10,10,10,10,10,10,10, 1203 10,10,10,10,10,10,10,10, 1204 10,10,10,10,10,10,10,10, 1205 10,10,10,10,10,10,10,10, 1206 10,10,10,10,10,10,10,10, 1207 10,10,10,10,10,10,10,10, 1208 10,10,10,10,10,10,10,10, 1209 10,10,10,10,10,10,10,10, 1210 10,10,10,10,10,10,10,10, 1211 10,10,10,10,10,10,10,10, 1212 10,10,10,10,10,10,10,10, 1213 10,10,10,10,10,10,10,10, 1214 10,10,10,10,10,10,10,10, 1215 10,10,10,10,10,10,10,10, 1216 10,10,10,10,10,10,10,10, 1217 10,10,10,10,10,10,10,10, 1218 10,10,10,10,10,10,10,10, 1219 10,10,10,10,10,10,10,10, 1220 10,10,10,10,10,10,10,10, 1221 10,10,10,10,10,10,10}; 1134 1222 1135 1223 const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04, 1136 1137 1138 1139 1140 1224 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00, 1225 0x01,0x02,0x03,0x04,2,0,0,0, 1226 0x6c,0x3b,0x82,0x3d, 1227 1, 1228 50}; 1141 1229 1142 1230 1143 1231 /* packet that overspans over an entire page */ 1144 1232 const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02, 1145 1146 1147 1148 1149 1233 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1234 0x01,0x02,0x03,0x04,0,0,0,0, 1235 0xff,0x7b,0x23,0x17, 1236 1, 1237 0}; 1150 1238 1151 1239 const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00, 1152 1153 1154 1155 1156 1157 1240 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00, 1241 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}; 1158 1246 1159 1247 const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01, 1160 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,1161 1162 0xbd,0xd5,0xb5,0x8b,1163 1164 1165 1248 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 1249 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}; 1166 1254 1167 1255 const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05, 1168 1169 1170 1171 1172 1256 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00, 1257 0x01,0x02,0x03,0x04,3,0,0,0, 1258 0xef,0xdd,0x88,0xde, 1259 7, 1260 255,255,75,255,4,255,0}; 1173 1261 1174 1262 /* packet that overspans over an entire page */ 1175 1263 const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02, 1176 1177 1178 1179 1180 1264 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1265 0x01,0x02,0x03,0x04,0,0,0,0, 1266 0xff,0x7b,0x23,0x17, 1267 1, 1268 0}; 1181 1269 1182 1270 const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00, 1183 1184 1185 1186 1187 1188 1271 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00, 1272 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}; 1189 1277 1190 1278 const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05, 1191 1192 1193 1194 1279 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00, 1280 0x01,0x02,0x03,0x04,2,0,0,0, 1281 0xd4,0xe0,0x60,0xe5, 1282 1,0}; 1195 1283 1196 void test_pack(const int *pl, const int **headers){ 1284 void test_pack(const int *pl, const int **headers, int byteskip, 1285 int pageskip, int packetskip){ 1197 1286 unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */ 1198 1287 long inptr=0; 1199 1288 long outptr=0; 1200 1289 long deptr=0; 1201 1290 long depacket=0; 1202 1291 long granule_pos=7,pageno=0; 1203 int i,j,packets,pageout= 0;1292 int i,j,packets,pageout=pageskip; 1204 1293 int eosflag=0; 1205 1294 int bosflag=0; 1206 1295 1296 int byteskipcount=0; 1297 1207 1298 ogg_stream_reset(&os_en); 1208 1299 ogg_stream_reset(&os_de); 1209 1300 ogg_sync_reset(&oy); 1210 1301 1302 for(packets=0;packets<packetskip;packets++) 1303 depacket+=pl[packets]; 1304 1211 1305 for(packets=0;;packets++)if(pl[packets]==-1)break; 1212 1306 1213 1307 for(i=0;i<packets;i++){ … … 1232 1326 ogg_page og; 1233 1327 1234 1328 while(ogg_stream_pageout(&os_en,&og)){ 1235 1329 /* We have a page. Check it carefully */ 1236 1330 1237 1331 fprintf(stderr,"%ld, ",pageno); 1238 1332 1239 1240 1241 1242 1333 if(headers[pageno]==NULL){ 1334 fprintf(stderr,"coded too many pages!\n"); 1335 exit(1); 1336 } 1243 1337 1244 1338 check_page(data+outptr,headers[pageno],&og); 1245 1339 1246 outptr+=og.body_len; 1247 pageno++; 1340 outptr+=og.body_len; 1341 pageno++; 1342 if(pageskip){ 1343 bosflag=1; 1344 pageskip--; 1345 deptr+=og.body_len; 1346 } 1248 1347 1249 1348 /* have a complete page; submit it to sync/decode */ 1250 1349 1251 { 1252 ogg_page og_de; 1253 ogg_packet op_de,op_de2; 1254 char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len); 1255 memcpy(buf,og.header,og.header_len); 1256 memcpy(buf+og.header_len,og.body,og.body_len); 1257 ogg_sync_wrote(&oy,og.header_len+og.body_len); 1350 { 1351 ogg_page og_de; 1352 ogg_packet op_de,op_de2; 1353 char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len); 1354 char *next=buf; 1355 byteskipcount+=og.header_len; 1356 if(byteskipcount>byteskip){ 1357 memcpy(next,og.header,byteskipcount-byteskip); 1358 next+=byteskipcount-byteskip; 1359 byteskipcount=byteskip; 1360 } 1258 1361 1259 while(ogg_sync_pageout(&oy,&og_de)>0){ 1260 /* got a page. Happy happy. Verify that it's good. */ 1261 1262 check_page(data+deptr,headers[pageout],&og_de);1263 deptr+=og_de.body_len;1264 pageout++; 1362 byteskipcount+=og.body_len; 1363 if(byteskipcount>byteskip){ 1364 memcpy(next,og.body,byteskipcount-byteskip); 1365 next+=byteskipcount-byteskip; 1366 byteskipcount=byteskip; 1367 } 1265 1368 1266 /* submit it to deconstitution */ 1267 ogg_stream_pagein(&os_de,&og_de); 1369 ogg_sync_wrote(&oy,next-buf); 1268 1370 1269 /* packets out? */ 1270 while(ogg_stream_packetpeek(&os_de,&op_de2)>0){ 1271 ogg_stream_packetpeek(&os_de,NULL); 1272 ogg_stream_packetout(&os_de,&op_de); /* just catching them all */ 1273 1274 /* verify peek and out match */ 1275 if(memcmp(&op_de,&op_de2,sizeof(op_de))){ 1276 fprintf(stderr,"packetout != packetpeek! pos=%ld\n", 1277 depacket); 1278 exit(1); 1279 } 1371 while(1){ 1372 int ret=ogg_sync_pageout(&oy,&og_de); 1373 if(ret==0)break; 1374 if(ret<0)continue; 1375 /* got a page. Happy happy. Verify that it's good. */ 1376 1377 fprintf(stderr,"(%ld), ",pageout); 1280 1378 1281 /* verify the packet! */ 1282 /* check data */ 1283 if(memcmp(data+depacket,op_de.packet,op_de.bytes)){ 1284 fprintf(stderr,"packet data mismatch in decode! pos=%ld\n", 1285 depacket); 1286 exit(1); 1287 } 1288 /* check bos flag */ 1289 if(bosflag==0 && op_de.b_o_s==0){ 1290 fprintf(stderr,"b_o_s flag not set on packet!\n"); 1291 exit(1); 1292 } 1293 if(bosflag && op_de.b_o_s){ 1294 fprintf(stderr,"b_o_s flag incorrectly set on packet!\n"); 1295 exit(1); 1296 } 1297 bosflag=1; 1298 depacket+=op_de.bytes; 1299 1300 /* check eos flag */ 1301 if(eosflag){ 1302 fprintf(stderr,"Multiple decoded packets with eos flag!\n"); 1303 exit(1); 1304 } 1379 check_page(data+deptr,headers[pageout],&og_de); 1380 deptr+=og_de.body_len; 1381 pageout++; 1305 1382 1306 if(op_de.e_o_s)eosflag=1; 1383 /* submit it to deconstitution */ 1384 ogg_stream_pagein(&os_de,&og_de); 1307 1385 1308 /* check granulepos flag */ 1309 if(op_de.granulepos!=-1){ 1310 fprintf(stderr," granule:%ld ",(long)op_de.granulepos); 1311 } 1312 } 1313 } 1314 } 1386 /* packets out? */ 1387 while(ogg_stream_packetpeek(&os_de,&op_de2)>0){ 1388 ogg_stream_packetpeek(&os_de,NULL); 1389 ogg_stream_packetout(&os_de,&op_de); /* just catching them all */ 1390 1391 /* verify peek and out match */ 1392 if(memcmp(&op_de,&op_de2,sizeof(op_de))){ 1393 fprintf(stderr,"packetout != packetpeek! pos=%ld\n", 1394 depacket); 1395 exit(1); 1396 } 1397 1398 /* verify the packet! */ 1399 /* check data */ 1400 if(memcmp(data+depacket,op_de.packet,op_de.bytes)){ 1401 fprintf(stderr,"packet data mismatch in decode! pos=%ld\n", 1402 depacket); 1403 exit(1); 1404 } 1405 /* check bos flag */ 1406 if(bosflag==0 && op_de.b_o_s==0){ 1407 fprintf(stderr,"b_o_s flag not set on packet!\n"); 1408 exit(1); 1409 } 1410 if(bosflag && op_de.b_o_s){ 1411 fprintf(stderr,"b_o_s flag incorrectly set on packet!\n"); 1412 exit(1); 1413 } 1414 bosflag=1; 1415 depacket+=op_de.bytes; 1416 1417 /* check eos flag */ 1418 if(eosflag){ 1419 fprintf(stderr,"Multiple decoded packets with eos flag!\n"); 1420 exit(1); 1421 } 1422 1423 if(op_de.e_o_s)eosflag=1; 1424 1425 /* check granulepos flag */ 1426 if(op_de.granulepos!=-1){ 1427 fprintf(stderr," granule:%ld ",(long)op_de.granulepos); 1428 } 1429 } 1430 } 1431 } 1315 1432 } 1316 1433 } 1317 1434 } … … 1358 1475 const int *headret[]={head1_0,NULL}; 1359 1476 1360 1477 fprintf(stderr,"testing single page encoding... "); 1361 test_pack(packets,headret );1478 test_pack(packets,headret,0,0,0); 1362 1479 } 1363 1480 1364 1481 { … … 1367 1484 const int *headret[]={head1_1,head2_1,NULL}; 1368 1485 1369 1486 fprintf(stderr,"testing basic page encoding... "); 1370 test_pack(packets,headret );1487 test_pack(packets,headret,0,0,0); 1371 1488 } 1372 1489 1373 1490 { … … 1376 1493 const int *headret[]={head1_2,head2_2,NULL}; 1377 1494 1378 1495 fprintf(stderr,"testing basic nil packets... "); 1379 test_pack(packets,headret );1496 test_pack(packets,headret,0,0,0); 1380 1497 } 1381 1498 1382 1499 { … … 1385 1502 const int *headret[]={head1_3,head2_3,NULL}; 1386 1503 1387 1504 fprintf(stderr,"testing initial-packet lacing > 4k... "); 1388 test_pack(packets,headret );1505 test_pack(packets,headret,0,0,0); 1389 1506 } 1390 1507 1391 1508 { … … 1394 1511 const int *headret[]={head1_4,head2_4,head3_4,NULL}; 1395 1512 1396 1513 fprintf(stderr,"testing single packet page span... "); 1397 test_pack(packets,headret );1514 test_pack(packets,headret,0,0,0); 1398 1515 } 1399 1516 1400 1517 /* page with the 255 segment limit */ 1401 1518 { 1402 1519 1403 1520 const int packets[]={0,10,10,10,10,10,10,10,10, 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1521 10,10,10,10,10,10,10,10, 1522 10,10,10,10,10,10,10,10, 1523 10,10,10,10,10,10,10,10, 1524 10,10,10,10,10,10,10,10, 1525 10,10,10,10,10,10,10,10, 1526 10,10,10,10,10,10,10,10, 1527 10,10,10,10,10,10,10,10, 1528 10,10,10,10,10,10,10,10, 1529 10,10,10,10,10,10,10,10, 1530 10,10,10,10,10,10,10,10, 1531 10,10,10,10,10,10,10,10, 1532 10,10,10,10,10,10,10,10, 1533 10,10,10,10,10,10,10,10, 1534 10,10,10,10,10,10,10,10, 1535 10,10,10,10,10,10,10,10, 1536 10,10,10,10,10,10,10,10, 1537 10,10,10,10,10,10,10,10, 1538 10,10,10,10,10,10,10,10, 1539 10,10,10,10,10,10,10,10, 1540 10,10,10,10,10,10,10,10, 1541 10,10,10,10,10,10,10,10, 1542 10,10,10,10,10,10,10,10, 1543 10,10,10,10,10,10,10,10, 1544 10,10,10,10,10,10,10,10, 1545 10,10,10,10,10,10,10,10, 1546 10,10,10,10,10,10,10,10, 1547 10,10,10,10,10,10,10,10, 1548 10,10,10,10,10,10,10,10, 1549 10,10,10,10,10,10,10,10, 1550 10,10,10,10,10,10,10,10, 1551 10,10,10,10,10,10,10,50,-1}; 1435 1552 const int *headret[]={head1_5,head2_5,head3_5,NULL}; 1436 1553 1437 1554 fprintf(stderr,"testing max packet segments... "); 1438 test_pack(packets,headret );1555 test_pack(packets,headret,0,0,0); 1439 1556 } 1440 1557 1441 1558 { … … 1444 1561 const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL}; 1445 1562 1446 1563 fprintf(stderr,"testing very large packets... "); 1447 test_pack(packets,headret );1564 test_pack(packets,headret,0,0,0); 1448 1565 } 1449 1566 1450 1567 { 1568 /* test for the libogg 1.1.1 resync in large continuation bug 1569 found by Josh Coalson) */ 1570 const int packets[]={0,100,9000,259,255,-1}; 1571 const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL}; 1572 1573 fprintf(stderr,"testing continuation resync in very large packets... "); 1574 test_pack(packets,headret,100,2,3); 1575 } 1576 1577 { 1451 1578 /* term only page. why not? */ 1452 1579 const int packets[]={0,100,4080,-1}; 1453 1580 const int *headret[]={head1_7,head2_7,head3_7,NULL}; 1454 1581 1455 1582 fprintf(stderr,"testing zero data page (1 nil packet)... "); 1456 test_pack(packets,headret );1583 test_pack(packets,headret,0,0,0); 1457 1584 } 1458 1585 1459 1586 … … 1485 1612 /* retrieve finished pages */ 1486 1613 for(i=0;i<5;i++){ 1487 1614 if(ogg_stream_pageout(&os_en,&og[i])==0){ 1488 1489 1615 fprintf(stderr,"Too few pages output building sync tests!\n"); 1616 exit(1); 1490 1617 } 1491 1618 copy_page(&og[i]); 1492 1619 } … … 1501 1628 ogg_sync_reset(&oy); 1502 1629 ogg_stream_reset(&os_de); 1503 1630 for(i=0;i<5;i++){ 1504 1505 1506 1507 1508 1631 memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header, 1632 og[i].header_len); 1633 ogg_sync_wrote(&oy,og[i].header_len); 1634 memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len); 1635 ogg_sync_wrote(&oy,og[i].body_len); 1509 1636 } 1510 1637 1511 1638 ogg_sync_pageout(&oy,&temp); … … 1526 1653 if(ogg_stream_packetout(&os_de,&test)!=1)error(); 1527 1654 checkpacket(&test,4079,2,3000); 1528 1655 if(ogg_stream_packetout(&os_de,&test)!=-1){ 1529 1530 1656 fprintf(stderr,"Error: loss of page did not return error\n"); 1657 exit(1); 1531 1658 } 1532 1659 if(ogg_stream_packetout(&os_de,&test)!=1)error(); 1533 1660 checkpacket(&test,76,5,-1); … … 1546 1673 ogg_sync_reset(&oy); 1547 1674 ogg_stream_reset(&os_de); 1548 1675 for(i=0;i<5;i++){ 1549 1550 1551 1552 1553 1676 memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header, 1677 og[i].header_len); 1678 ogg_sync_wrote(&oy,og[i].header_len); 1679 memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len); 1680 ogg_sync_wrote(&oy,og[i].body_len); 1554 1681 } 1555 1682 1556 1683 ogg_sync_pageout(&oy,&temp); … … 1575 1702 if(ogg_stream_packetout(&os_de,&test)!=1)error(); 1576 1703 checkpacket(&test,2956,3,4000); 1577 1704 if(ogg_stream_packetout(&os_de,&test)!=-1){ 1578 1579 1705 fprintf(stderr,"Error: loss of page did not return error\n"); 1706 exit(1); 1580 1707 } 1581 1708 if(ogg_stream_packetout(&os_de,&test)!=1)error(); 1582 1709 checkpacket(&test,300,13,14000); … … 1590 1717 fprintf(stderr,"Testing sync on partial inputs... "); 1591 1718 ogg_sync_reset(&oy); 1592 1719 memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, 1593 1720 3); 1594 1721 ogg_sync_wrote(&oy,3); 1595 1722 if(ogg_sync_pageout(&oy,&og_de)>0)error(); 1596 1723 1597 1724 /* Test fractional page inputs: incomplete fixed header */ 1598 1725 memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3, 1599 1726 20); 1600 1727 ogg_sync_wrote(&oy,20); 1601 1728 if(ogg_sync_pageout(&oy,&og_de)>0)error(); 1602 1729 1603 1730 /* Test fractional page inputs: incomplete header */ 1604 1731 memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23, 1605 1732 5); 1606 1733 ogg_sync_wrote(&oy,5); 1607 1734 if(ogg_sync_pageout(&oy,&og_de)>0)error(); 1608 1735 1609 1736 /* Test fractional page inputs: incomplete body */ 1610 1737 1611 1738 memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28, 1612 1739 og[1].header_len-28); 1613 1740 ogg_sync_wrote(&oy,og[1].header_len-28); 1614 1741 if(ogg_sync_pageout(&oy,&og_de)>0)error(); 1615 1742 … … 1618 1745 if(ogg_sync_pageout(&oy,&og_de)>0)error(); 1619 1746 1620 1747 memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000, 1621 1748 og[1].body_len-1000); 1622 1749 ogg_sync_wrote(&oy,og[1].body_len-1000); 1623 1750 if(ogg_sync_pageout(&oy,&og_de)<=0)error(); 1624 1751 … … 1632 1759 ogg_sync_reset(&oy); 1633 1760 1634 1761 memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, 1635 1762 og[1].header_len); 1636 1763 ogg_sync_wrote(&oy,og[1].header_len); 1637 1764 1638 1765 memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, 1639 1766 og[1].body_len); 1640 1767 ogg_sync_wrote(&oy,og[1].body_len); 1641 1768 1642 1769 memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, 1643 1770 20); 1644 1771 ogg_sync_wrote(&oy,20); 1645 1772 if(ogg_sync_pageout(&oy,&og_de)<=0)error(); 1646 1773 if(ogg_sync_pageout(&oy,&og_de)>0)error(); 1647 1774 1648 1775 memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20, 1649 1776 og[1].header_len-20); 1650 1777 ogg_sync_wrote(&oy,og[1].header_len-20); 1651 1778 memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, 1652 1779 og[1].body_len); 1653 1780 ogg_sync_wrote(&oy,og[1].body_len); 1654 1781 if(ogg_sync_pageout(&oy,&og_de)<=0)error(); 1655 1782 … … 1664 1791 1665 1792 /* 'garbage' */ 1666 1793 memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, 1667 1794 og[1].body_len); 1668 1795 ogg_sync_wrote(&oy,og[1].body_len); 1669 1796 1670 1797 memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, 1671 1798 og[1].header_len); 1672 1799 ogg_sync_wrote(&oy,og[1].header_len); 1673 1800 1674 1801 memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, 1675 1802 og[1].body_len); 1676 1803 ogg_sync_wrote(&oy,og[1].body_len); 1677 1804 1678 1805 memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header, 1679 1806 20); 1680 1807 ogg_sync_wrote(&oy,20); 1681 1808 if(ogg_sync_pageout(&oy,&og_de)>0)error(); 1682 1809 if(ogg_sync_pageout(&oy,&og_de)<=0)error(); 1683 1810 if(ogg_sync_pageout(&oy,&og_de)>0)error(); 1684 1811 1685 1812 memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20, 1686 1813 og[2].header_len-20); 1687 1814 ogg_sync_wrote(&oy,og[2].header_len-20); 1688 1815 memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body, 1689 1816 og[2].body_len); 1690 1817 ogg_sync_wrote(&oy,og[2].body_len); 1691 1818 if(ogg_sync_pageout(&oy,&og_de)<=0)error(); 1692 1819 … … 1700 1827 ogg_sync_reset(&oy); 1701 1828 1702 1829 memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, 1703 1830 og[1].header_len); 1704 1831 ogg_sync_wrote(&oy,og[1].header_len); 1705 1832 1706 1833 memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, 1707 1834 og[1].body_len); 1708 1835 ogg_sync_wrote(&oy,og[1].body_len); 1709 1836 1710 1837 memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header, 1711 1838 og[2].header_len); 1712 1839 ogg_sync_wrote(&oy,og[2].header_len); 1713 1840 1714 1841 memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header, 1715 1842 og[2].header_len); 1716 1843 ogg_sync_wrote(&oy,og[2].header_len); 1717 1844 1718 1845 if(ogg_sync_pageout(&oy,&og_de)<=0)error(); 1719 1846 1720 1847 memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body, 1721 1848 og[2].body_len-5); 1722 1849 ogg_sync_wrote(&oy,og[2].body_len-5); 1723 1850 1724 1851 memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header, 1725 1852 og[3].header_len); 1726 1853 ogg_sync_wrote(&oy,og[3].header_len); 1727 1854 1728 1855 memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body, 1729 1856 og[3].body_len); 1730 1857 ogg_sync_wrote(&oy,og[3].body_len); 1731 1858 1732 1859 if(ogg_sync_pageout(&oy,&og_de)>0)error(); … … 1734 1861 1735 1862 fprintf(stderr,"ok.\n"); 1736 1863 } 1864 1865 /* Free page data that was previously copied */ 1866 { 1867 for(i=0;i<5;i++){ 1868 free_page(&og[i]); 1869 } 1870 } 1737 1871 } 1738 1872 1739 1873 return(0); -
src/add-ons/media/plugins/ogg/libogg/bitwise.c
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-200 2*8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 9 * by the Xiph.Org Foundation http://www.xiph.org/ * 10 10 * * 11 11 ******************************************************************** 12 12 13 13 function: packing variable sized words into an octet stream 14 last mod: $Id : bitwise.c,v 1.2 2004/02/24 13:52:39 shatty Exp$14 last mod: $Id$ 15 15 16 16 ********************************************************************/ 17 17 … … 24 24 25 25 #define BUFFER_INCREMENT 256 26 26 27 static unsigned long mask[]=27 static const unsigned long mask[]= 28 28 {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f, 29 29 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff, 30 30 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff, … … 33 33 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff, 34 34 0x3fffffff,0x7fffffff,0xffffffff }; 35 35 36 static unsigned int mask8B[]=36 static const unsigned int mask8B[]= 37 37 {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; 38 38 39 39 void oggpack_writeinit(oggpack_buffer *b){ … … 47 47 oggpack_writeinit(b); 48 48 } 49 49 50 int oggpack_writecheck(oggpack_buffer *b){ 51 if(!b->ptr || !b->storage)return -1; 52 return 0; 53 } 54 55 int oggpackB_writecheck(oggpack_buffer *b){ 56 return oggpack_writecheck(b); 57 } 58 50 59 void oggpack_writetrunc(oggpack_buffer *b,long bits){ 51 60 long bytes=bits>>3; 52 bits-=bytes*8; 53 b->ptr=b->buffer+bytes; 54 b->endbit=bits; 55 b->endbyte=bytes; 56 *b->ptr&=mask[bits]; 61 if(b->ptr){ 62 bits-=bytes*8; 63 b->ptr=b->buffer+bytes; 64 b->endbit=bits; 65 b->endbyte=bytes; 66 *b->ptr&=mask[bits]; 67 } 57 68 } 58 69 59 70 void oggpackB_writetrunc(oggpack_buffer *b,long bits){ 60 71 long bytes=bits>>3; 61 bits-=bytes*8; 62 b->ptr=b->buffer+bytes; 63 b->endbit=bits; 64 b->endbyte=bytes; 65 *b->ptr&=mask8B[bits]; 72 if(b->ptr){ 73 bits-=bytes*8; 74 b->ptr=b->buffer+bytes; 75 b->endbit=bits; 76 b->endbyte=bytes; 77 *b->ptr&=mask8B[bits]; 78 } 66 79 } 67 80 68 81 /* Takes only up to 32 bits. */ 69 82 void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){ 70 83 if(b->endbyte+4>=b->storage){ 71 b->buffer=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT); 84 void *ret; 85 if(!b->ptr)return; 86 ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT); 87 if(!ret){ 88 oggpack_writeclear(b); 89 return; 90 } 91 b->buffer=ret; 72 92 b->storage+=BUFFER_INCREMENT; 73 93 b->ptr=b->buffer+b->endbyte; 74 94 } … … 79 99 b->ptr[0]|=value<<b->endbit; 80 100 81 101 if(bits>=8){ 82 b->ptr[1]= value>>(8-b->endbit);102 b->ptr[1]=(unsigned char)(value>>(8-b->endbit)); 83 103 if(bits>=16){ 84 b->ptr[2]= value>>(16-b->endbit);104 b->ptr[2]=(unsigned char)(value>>(16-b->endbit)); 85 105 if(bits>=24){ 86 b->ptr[3]=value>>(24-b->endbit); 87 88 89 b->ptr[4]=value>>(32-b->endbit);90 91 92 106 b->ptr[3]=(unsigned char)(value>>(24-b->endbit)); 107 if(bits>=32){ 108 if(b->endbit) 109 b->ptr[4]=(unsigned char)(value>>(32-b->endbit)); 110 else 111 b->ptr[4]=0; 112 } 93 113 } 94 114 } 95 115 } … … 102 122 /* Takes only up to 32 bits. */ 103 123 void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){ 104 124 if(b->endbyte+4>=b->storage){ 105 b->buffer=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT); 125 void *ret; 126 if(!b->ptr)return; 127 ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT); 128 if(!ret){ 129 oggpack_writeclear(b); 130 return; 131 } 132 b->buffer=ret; 106 133 b->storage+=BUFFER_INCREMENT; 107 134 b->ptr=b->buffer+b->endbyte; 108 135 } … … 113 140 b->ptr[0]|=value>>(24+b->endbit); 114 141 115 142 if(bits>=8){ 116 b->ptr[1]= value>>(16+b->endbit);143 b->ptr[1]=(unsigned char)(value>>(16+b->endbit)); 117 144 if(bits>=16){ 118 b->ptr[2]= value>>(8+b->endbit);145 b->ptr[2]=(unsigned char)(value>>(8+b->endbit)); 119 146 if(bits>=24){ 120 b->ptr[3]=value>>(b->endbit); 121 122 123 b->ptr[4]=value<<(8-b->endbit);124 125 126 147 b->ptr[3]=(unsigned char)(value>>(b->endbit)); 148 if(bits>=32){ 149 if(b->endbit) 150 b->ptr[4]=(unsigned char)(value<<(8-b->endbit)); 151 else 152 b->ptr[4]=0; 153 } 127 154 } 128 155 } 129 156 } … … 146 173 } 147 174 148 175 static void oggpack_writecopy_helper(oggpack_buffer *b, 149 150 151 152 153 154 176 void *source, 177 long bits, 178 void (*w)(oggpack_buffer *, 179 unsigned long, 180 int), 181 int msb){ 155 182 unsigned char *ptr=(unsigned char *)source; 156 183 157 184 long bytes=bits/8; … … 165 192 }else{ 166 193 /* aligned block copy */ 167 194 if(b->endbyte+bytes+1>=b->storage){ 195 void *ret; 196 if(!b->ptr)return; 168 197 b->storage=b->endbyte+bytes+BUFFER_INCREMENT; 169 b->buffer=_ogg_realloc(b->buffer,b->storage); 198 ret=_ogg_realloc(b->buffer,b->storage); 199 if(!ret){ 200 oggpack_writeclear(b); 201 return; 202 } 203 b->buffer=ret; 170 204 b->ptr=b->buffer+b->endbyte; 171 205 } 172 206 173 207 memmove(b->ptr,source,bytes); 174 208 b->ptr+=bytes; 175 b-> buffer+=bytes;209 b->endbyte+=bytes; 176 210 *b->ptr=0; 177 211 178 212 } … … 193 227 } 194 228 195 229 void oggpack_reset(oggpack_buffer *b){ 230 if(!b->ptr)return; 196 231 b->ptr=b->buffer; 197 232 b->buffer[0]=0; 198 233 b->endbit=b->endbyte=0; … … 203 238 } 204 239 205 240 void oggpack_writeclear(oggpack_buffer *b){ 206 _ogg_free(b->buffer);241 if(b->buffer)_ogg_free(b->buffer); 207 242 memset(b,0,sizeof(*b)); 208 243 } 209 244 … … 239 274 if(bits>16){ 240 275 ret|=b->ptr[2]<<(16-b->endbit); 241 276 if(bits>24){ 242 243 244 277 ret|=b->ptr[3]<<(24-b->endbit); 278 if(bits>32 && b->endbit) 279 ret|=b->ptr[4]<<(32-b->endbit); 245 280 } 246 281 } 247 282 } … … 266 301 if(bits>16){ 267 302 ret|=b->ptr[2]<<(8+b->endbit); 268 303 if(bits>24){ 269 270 271 304 ret|=b->ptr[3]<<(b->endbit); 305 if(bits>32 && b->endbit) 306 ret|=b->ptr[4]>>(8-b->endbit); 272 307 } 273 308 } 274 309 } 275 return ( ret>>(m>>1))>>((m+1)>>1);310 return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1); 276 311 } 277 312 278 313 long oggpack_look1(oggpack_buffer *b){ … … 310 345 311 346 /* bits <= 32 */ 312 347 long oggpack_read(oggpack_buffer *b,int bits){ 313 unsignedlong ret;348 long ret; 314 349 unsigned long m=mask[bits]; 315 350 316 351 bits+=b->endbit; 317 352 318 353 if(b->endbyte+4>=b->storage){ 319 354 /* not the main path */ 320 ret=-1 UL;355 ret=-1L; 321 356 if(b->endbyte*8+bits>b->storage*8)goto overflow; 322 357 } 323 358 … … 327 362 if(bits>16){ 328 363 ret|=b->ptr[2]<<(16-b->endbit); 329 364 if(bits>24){ 330 331 332 333 365 ret|=b->ptr[3]<<(24-b->endbit); 366 if(bits>32 && b->endbit){ 367 ret|=b->ptr[4]<<(32-b->endbit); 368 } 334 369 } 335 370 } 336 371 } … … 346 381 347 382 /* bits <= 32 */ 348 383 long oggpackB_read(oggpack_buffer *b,int bits){ 349 unsignedlong ret;384 long ret; 350 385 long m=32-bits; 351 386 352 387 bits+=b->endbit; 353 388 354 389 if(b->endbyte+4>=b->storage){ 355 390 /* not the main path */ 356 ret=-1 UL;391 ret=-1L; 357 392 if(b->endbyte*8+bits>b->storage*8)goto overflow; 393 /* special case to avoid reading b->ptr[0], which might be past the end of 394 the buffer; also skips some useless accounting */ 395 else if(!bits)return(0L); 358 396 } 359 397 360 398 ret=b->ptr[0]<<(24+b->endbit); … … 363 401 if(bits>16){ 364 402 ret|=b->ptr[2]<<(8+b->endbit); 365 403 if(bits>24){ 366 367 368 404 ret|=b->ptr[3]<<(b->endbit); 405 if(bits>32 && b->endbit) 406 ret|=b->ptr[4]>>(8-b->endbit); 369 407 } 370 408 } 371 409 } 372 ret=( ret>>(m>>1))>>((m+1)>>1);410 ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1); 373 411 374 412 overflow: 375 413 … … 380 418 } 381 419 382 420 long oggpack_read1(oggpack_buffer *b){ 383 unsignedlong ret;421 long ret; 384 422 385 423 if(b->endbyte>=b->storage){ 386 424 /* not the main path */ 387 ret=-1 UL;425 ret=-1L; 388 426 goto overflow; 389 427 } 390 428 … … 402 440 } 403 441 404 442 long oggpackB_read1(oggpack_buffer *b){ 405 unsignedlong ret;443 long ret; 406 444 407 445 if(b->endbyte>=b->storage){ 408 446 /* not the main path */ 409 ret=-1 UL;447 ret=-1L; 410 448 goto overflow; 411 449 } 412 450 … … 493 531 report("looked at incorrect value!\n"); 494 532 if(tbit==1) 495 533 if(oggpack_look1(&r)!=(b[i]&mask[tbit])) 496 534 report("looked at single bit incorrect value!\n"); 497 535 if(tbit==1){ 498 536 if(oggpack_read1(&r)!=(b[i]&mask[tbit])) 499 537 report("read incorrect single bit value!\n"); 500 538 }else{ 501 539 if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit])) 502 540 report("read incorrect value!\n"); … … 528 566 report("looked at incorrect value!\n"); 529 567 if(tbit==1) 530 568 if(oggpackB_look1(&r)!=(b[i]&mask[tbit])) 531 569 report("looked at single bit incorrect value!\n"); 532 570 if(tbit==1){ 533 571 if(oggpackB_read1(&r)!=(b[i]&mask[tbit])) 534 572 report("read incorrect single bit value!\n"); 535 573 }else{ 536 574 if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit])) 537 575 report("read incorrect value!\n"); … … 569 607 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172, 570 608 223,4}; 571 609 static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222, 572 573 610 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18, 611 245,251,128}; 574 612 575 613 int twosize=6; 576 614 static int two[6]={61,255,255,251,231,29}; … … 582 620 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10, 583 621 100,52,4,14,18,86,77,1}; 584 622 static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183, 585 586 587 623 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98, 624 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104, 625 200,20,254,4,58,106,176,144,0}; 588 626 589 627 int foursize=38; 590 628 static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72, 591 629 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169, 592 630 28,2,133,0,1}; 593 631 static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41, 594 595 632 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67, 633 129,10,4,32}; 596 634 597 635 int fivesize=45; 598 636 static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62, 599 637 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169, 600 638 84,75,159,2,1,0,132,192,8,0,0,18,22}; 601 639 static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226, 602 603 640 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77, 641 172,150,169,129,79,128,0,6,4,32,0,27,9,0}; 604 642 605 643 int sixsize=7; 606 644 static int six[7]={17,177,170,242,169,19,148}; … … 633 671 if(oggpack_look(&r,32)==-1)report("out of data. failed!"); 634 672 if(oggpack_look(&r,32)!=large[i]){ 635 673 fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i], 636 674 oggpack_look(&r,32),large[i]); 637 675 report("read incorrect value!\n"); 638 676 } 639 677 oggpack_adv(&r,32); … … 687 725 fprintf(stderr,"failed; read past end without -1.\n"); 688 726 exit(1); 689 727 } 728 oggpack_writeclear(&o); 690 729 fprintf(stderr,"ok.\n"); 691 730 692 731 /********** lazy, cut-n-paste retest with MSb packing ***********/ … … 718 757 if(oggpackB_look(&r,32)==-1)report("out of data. failed!"); 719 758 if(oggpackB_look(&r,32)!=large[i]){ 720 759 fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i], 721 760 oggpackB_look(&r,32),large[i]); 722 761 report("read incorrect value!\n"); 723 762 } 724 763 oggpackB_adv(&r,32); … … 772 811 fprintf(stderr,"failed; read past end without -1.\n"); 773 812 exit(1); 774 813 } 814 oggpackB_writeclear(&o); 775 815 fprintf(stderr,"ok.\n\n"); 776 816 777 817 -
src/add-ons/media/plugins/ogg/libogg/ogg/ogg.h
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-200 2*8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 9 * by the Xiph.Org Foundation http://www.xiph.org/ * 10 10 * * 11 11 ******************************************************************** 12 12 13 13 function: toplevel libogg include 14 last mod: $Id : ogg.h,v 1.2 2004/02/24 13:52:39 shatty Exp$14 last mod: $Id$ 15 15 16 16 ********************************************************************/ 17 17 #ifndef _OGG_H … … 21 21 extern "C" { 22 22 #endif 23 23 24 #include <stddef.h> 24 25 #include <ogg/os_types.h> 25 26 26 27 typedef struct { 28 void *iov_base; 29 size_t iov_len; 30 } ogg_iovec_t; 31 32 typedef struct { 27 33 long endbyte; 28 34 int endbit; 29 35 … … 53 59 54 60 int *lacing_vals; /* The values that will go to the segment table */ 55 61 ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact 56 57 62 this way, but it is simple coupled to the 63 lacing fifo */ 58 64 long lacing_storage; 59 65 long lacing_fill; 60 66 long lacing_packet; … … 69 75 of a logical bitstream */ 70 76 long serialno; 71 77 long pageno; 72 ogg_int64_t packetno; 78 ogg_int64_t packetno; /* sequence number for decode; the framing 73 79 knows where there's a hole in the data, 74 80 but we need coupling so that the codec 75 81 (which is in a seperate abstraction … … 88 94 long e_o_s; 89 95 90 96 ogg_int64_t granulepos; 91 97 92 98 ogg_int64_t packetno; /* sequence number for decode; the framing 93 94 95 96 99 knows where there's a hole in the data, 100 but we need coupling so that the codec 101 (which is in a seperate abstraction 102 layer) also knows about the gap */ 97 103 } ogg_packet; 98 104 99 105 typedef struct { … … 110 116 /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ 111 117 112 118 extern void oggpack_writeinit(oggpack_buffer *b); 119 extern int oggpack_writecheck(oggpack_buffer *b); 113 120 extern void oggpack_writetrunc(oggpack_buffer *b,long bits); 114 121 extern void oggpack_writealign(oggpack_buffer *b); 115 122 extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits); … … 128 135 extern unsigned char *oggpack_get_buffer(oggpack_buffer *b); 129 136 130 137 extern void oggpackB_writeinit(oggpack_buffer *b); 138 extern int oggpackB_writecheck(oggpack_buffer *b); 131 139 extern void oggpackB_writetrunc(oggpack_buffer *b,long bits); 132 140 extern void oggpackB_writealign(oggpack_buffer *b); 133 141 extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits); … … 148 156 /* Ogg BITSTREAM PRIMITIVES: encoding **************************/ 149 157 150 158 extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op); 159 extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, 160 int count, long e_o_s, ogg_int64_t granulepos); 151 161 extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og); 152 162 extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og); 153 163 … … 156 166 extern int ogg_sync_init(ogg_sync_state *oy); 157 167 extern int ogg_sync_clear(ogg_sync_state *oy); 158 168 extern int ogg_sync_reset(ogg_sync_state *oy); 159 extern int ogg_sync_destroy(ogg_sync_state *oy); 169 extern int ogg_sync_destroy(ogg_sync_state *oy); 170 extern int ogg_sync_check(ogg_sync_state *oy); 160 171 161 172 extern char *ogg_sync_buffer(ogg_sync_state *oy, long size); 162 173 extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); … … 173 184 extern int ogg_stream_reset(ogg_stream_state *os); 174 185 extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno); 175 186 extern int ogg_stream_destroy(ogg_stream_state *os); 187 extern int ogg_stream_check(ogg_stream_state *os); 176 188 extern int ogg_stream_eos(ogg_stream_state *os); 177 189 178 190 extern void ogg_page_checksum_set(ogg_page *og); 179 191 180 extern int ogg_page_version( ogg_page *og);181 extern int ogg_page_continued( ogg_page *og);182 extern int ogg_page_bos( ogg_page *og);183 extern int ogg_page_eos( ogg_page *og);184 extern ogg_int64_t ogg_page_granulepos( ogg_page *og);185 extern int ogg_page_serialno( ogg_page *og);186 extern long ogg_page_pageno( ogg_page *og);187 extern int ogg_page_packets( ogg_page *og);192 extern int ogg_page_version(const ogg_page *og); 193 extern int ogg_page_continued(const ogg_page *og); 194 extern int ogg_page_bos(const ogg_page *og); 195 extern int ogg_page_eos(const ogg_page *og); 196 extern ogg_int64_t ogg_page_granulepos(const ogg_page *og); 197 extern int ogg_page_serialno(const ogg_page *og); 198 extern long ogg_page_pageno(const ogg_page *og); 199 extern int ogg_page_packets(const ogg_page *og); 188 200 189 201 extern void ogg_packet_clear(ogg_packet *op); 190 202 … … 194 206 #endif 195 207 196 208 #endif /* _OGG_H */ 197 198 199 200 201 202 -
src/add-ons/media/plugins/ogg/libogg/ogg/os_types.h
24 24 #define _ogg_realloc realloc 25 25 #define _ogg_free free 26 26 27 #if def _WIN3227 #if defined(_WIN32) 28 28 29 # ifndef __GNUC__ 30 /* MSVC/Borland */ 31 typedef __int64 ogg_int64_t; 32 typedef __int32 ogg_int32_t; 33 typedef unsigned __int32 ogg_uint32_t; 34 typedef __int16 ogg_int16_t; 35 typedef unsigned __int16 ogg_uint16_t; 29 # if defined(__CYGWIN__) 30 # include <stdint.h> 31 typedef int16_t ogg_int16_t; 32 typedef uint16_t ogg_uint16_t; 33 typedef int32_t ogg_int32_t; 34 typedef uint32_t ogg_uint32_t; 35 typedef int64_t ogg_int64_t; 36 typedef uint64_t ogg_uint64_t; 37 # elif defined(__MINGW32__) 38 # include <sys/types.h> 39 typedef short ogg_int16_t; 40 typedef unsigned short ogg_uint16_t; 41 typedef int ogg_int32_t; 42 typedef unsigned int ogg_uint32_t; 43 typedef long long ogg_int64_t; 44 typedef unsigned long long ogg_uint64_t; 45 # elif defined(__MWERKS__) 46 typedef long long ogg_int64_t; 47 typedef int ogg_int32_t; 48 typedef unsigned int ogg_uint32_t; 49 typedef short ogg_int16_t; 50 typedef unsigned short ogg_uint16_t; 36 51 # else 37 /* Cygwin */ 38 #include <_G_config.h> 39 typedef _G_int64_t ogg_int64_t; 40 typedef _G_int32_t ogg_int32_t; 41 typedef _G_uint32_t ogg_uint32_t; 42 typedef _G_int16_t ogg_int16_t; 43 typedef _G_uint16_t ogg_uint16_t; 52 /* MSVC/Borland */ 53 typedef __int64 ogg_int64_t; 54 typedef __int32 ogg_int32_t; 55 typedef unsigned __int32 ogg_uint32_t; 56 typedef __int16 ogg_int16_t; 57 typedef unsigned __int16 ogg_uint16_t; 44 58 # endif 45 59 46 60 #elif defined(__MACOS__) … … 52 66 typedef UInt32 ogg_uint32_t; 53 67 typedef SInt64 ogg_int64_t; 54 68 55 #elif defined(__MACOSX__) /* MacOS X Framework build */69 #elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ 56 70 57 71 # include <sys/types.h> 58 72 typedef int16_t ogg_int16_t; … … 61 75 typedef u_int32_t ogg_uint32_t; 62 76 typedef int64_t ogg_int64_t; 63 77 64 #elif (defined(__BEOS__) || defined(__HAIKU__))78 #elif defined(__HAIKU__) 65 79 80 /* Haiku */ 81 # include <sys/types.h> 82 typedef short ogg_int16_t; 83 typedef unsigned short ogg_uint16_t; 84 typedef int ogg_int32_t; 85 typedef unsigned int ogg_uint32_t; 86 typedef long long ogg_int64_t; 87 88 #elif defined(__BEOS__) 89 66 90 /* Be */ 67 91 # include <inttypes.h> 68 92 typedef int16_t ogg_int16_t; … … 96 120 typedef unsigned ogg_uint32_t; 97 121 typedef short ogg_int16_t; 98 122 123 #elif defined(__SYMBIAN32__) 124 125 /* Symbian GCC */ 126 typedef signed short ogg_int16_t; 127 typedef unsigned short ogg_uint16_t; 128 typedef signed int ogg_int32_t; 129 typedef unsigned int ogg_uint32_t; 130 typedef long long int ogg_int64_t; 131 99 132 #else 100 133 101 134 # include <sys/types.h> -
src/add-ons/media/plugins/ogg/OggSpeexSeekable.h
9 9 private: 10 10 typedef OggSeekable inherited; 11 11 public: 12 static bool IsValidHeader(const ogg_packet & packet);12 static bool IsValidHeader(const ogg_packet & packet); 13 13 public: 14 OggSpeexSeekable(long serialno);15 virtual ~OggSpeexSeekable();14 OggSpeexSeekable(long serialno); 15 virtual ~OggSpeexSeekable(); 16 16 17 17 virtual status_t GetStreamInfo(int64 *frameCount, bigtime_t *duration, 18 18 media_format *format); -
src/add-ons/media/plugins/ogg/OggVorbisStream.h
7 7 8 8 class OggVorbisStream : public OggStream { 9 9 public: 10 static bool IsValidHeader(const ogg_packet & packet);10 static bool IsValidHeader(const ogg_packet & packet); 11 11 public: 12 OggVorbisStream(long serialno);13 virtual ~OggVorbisStream();12 OggVorbisStream(long serialno); 13 virtual ~OggVorbisStream(); 14 14 15 15 virtual status_t GetStreamInfo(int64 *frameCount, bigtime_t *duration, 16 16 media_format *format); -
src/add-ons/media/plugins/ogg/OggReaderPlugin.h
57 57 public: 58 58 class StreamInterface { 59 59 public: 60 virtual ~StreamInterface() {};60 virtual ~StreamInterface() {}; 61 61 virtual ssize_t ReadPage() = 0; 62 62 }; 63 63 }; -
src/add-ons/media/plugins/ogg/OggStream.h
19 19 media_header *mediaHeader); 20 20 21 21 protected: 22 OggStream(long serialno);22 OggStream(long serialno); 23 23 public: 24 virtual ~OggStream();24 virtual ~OggStream(); 25 25 26 26 // reader push input function 27 27 virtual status_t AddPage(off_t position, const ogg_page & page); 28 28 29 29 protected: 30 30 // subclass pull input function 31 status_t GetPacket(ogg_packet * packet);31 status_t GetPacket(ogg_packet * packet); 32 32 ogg_packet fChunkPacket; 33 33 34 34 protected: