⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 framing.c

📁 mediastreamer2是开源的网络传输媒体流的库
💻 C
📖 第 1 页 / 共 4 页
字号:
  }  _ogg_free(data);  if(headers[pageno]!=NULL){    fprintf(stderr,"did not write last page!\n");    exit(1);  }  if(headers[pageout]!=NULL){    fprintf(stderr,"did not decode last page!\n");    exit(1);  }  if(inptr!=outptr){    fprintf(stderr,"encoded page data incomplete!\n");    exit(1);  }  if(inptr!=deptr){    fprintf(stderr,"decoded page data incomplete!\n");    exit(1);  }  if(inptr!=depacket){    fprintf(stderr,"decoded packet data incomplete!\n");    exit(1);  }  if(!eosflag){    fprintf(stderr,"Never got a packet with EOS set!\n");    exit(1);  }  fprintf(stderr,"ok.\n");}int main(void){  ogg_stream_init(&os_en,0x04030201);  ogg_stream_init(&os_de,0x04030201);  ogg_sync_init(&oy);  /* Exercise each code path in the framing code.  Also verify that     the checksums are working.  */  {    /* 17 only */    const int packets[]={17, -1};    const int *headret[]={head1_0,NULL};        fprintf(stderr,"testing single page encoding... ");    test_pack(packets,headret,0,0,0);  }  {    /* 17, 254, 255, 256, 500, 510, 600 byte, pad */    const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};    const int *headret[]={head1_1,head2_1,NULL};        fprintf(stderr,"testing basic page encoding... ");    test_pack(packets,headret,0,0,0);  }  {    /* nil packets; beginning,middle,end */    const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};    const int *headret[]={head1_2,head2_2,NULL};        fprintf(stderr,"testing basic nil packets... ");    test_pack(packets,headret,0,0,0);  }  {    /* large initial packet */    const int packets[]={4345,259,255,-1};    const int *headret[]={head1_3,head2_3,NULL};        fprintf(stderr,"testing initial-packet lacing > 4k... ");    test_pack(packets,headret,0,0,0);  }  {    /* continuing packet test */    const int packets[]={0,4345,259,255,-1};    const int *headret[]={head1_4,head2_4,head3_4,NULL};        fprintf(stderr,"testing single packet page span... ");    test_pack(packets,headret,0,0,0);  }  /* page with the 255 segment limit */  {    const int packets[]={0,10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,10,		   10,10,10,10,10,10,10,50,-1};    const int *headret[]={head1_5,head2_5,head3_5,NULL};        fprintf(stderr,"testing max packet segments... ");    test_pack(packets,headret,0,0,0);  }  {    /* packet that overspans over an entire page */    const int packets[]={0,100,9000,259,255,-1};    const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};        fprintf(stderr,"testing very large packets... ");    test_pack(packets,headret,0,0,0);  }  {    /* test for the libogg 1.1.1 resync in large continuation bug       found by Josh Coalson)  */    const int packets[]={0,100,9000,259,255,-1};    const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};        fprintf(stderr,"testing continuation resync in very large packets... ");    test_pack(packets,headret,100,2,3);  }  {    /* term only page.  why not? */    const int packets[]={0,100,4080,-1};    const int *headret[]={head1_7,head2_7,head3_7,NULL};        fprintf(stderr,"testing zero data page (1 nil packet)... ");    test_pack(packets,headret,0,0,0);  }  {    /* build a bunch of pages for testing */    unsigned char *data=_ogg_malloc(1024*1024);    int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};    int inptr=0,i,j;    ogg_page og[5];        ogg_stream_reset(&os_en);    for(i=0;pl[i]!=-1;i++){      ogg_packet op;      int len=pl[i];            op.packet=data+inptr;      op.bytes=len;      op.e_o_s=(pl[i+1]<0?1:0);      op.granulepos=(i+1)*1000;      for(j=0;j<len;j++)data[inptr++]=i+j;      ogg_stream_packetin(&os_en,&op);    }    _ogg_free(data);    /* retrieve finished pages */    for(i=0;i<5;i++){      if(ogg_stream_pageout(&os_en,&og[i])==0){	fprintf(stderr,"Too few pages output building sync tests!\n");	exit(1);      }      copy_page(&og[i]);    }    /* Test lost pages on pagein/packetout: no rollback */    {      ogg_page temp;      ogg_packet test;      fprintf(stderr,"Testing loss of pages... ");      ogg_sync_reset(&oy);      ogg_stream_reset(&os_de);      for(i=0;i<5;i++){	memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,	       og[i].header_len);	ogg_sync_wrote(&oy,og[i].header_len);	memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);	ogg_sync_wrote(&oy,og[i].body_len);      }      ogg_sync_pageout(&oy,&temp);      ogg_stream_pagein(&os_de,&temp);      ogg_sync_pageout(&oy,&temp);      ogg_stream_pagein(&os_de,&temp);      ogg_sync_pageout(&oy,&temp);      /* skip */      ogg_sync_pageout(&oy,&temp);      ogg_stream_pagein(&os_de,&temp);      /* do we get the expected results/packets? */            if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,0,0,0);      if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,100,1,-1);      if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,4079,2,3000);      if(ogg_stream_packetout(&os_de,&test)!=-1){	fprintf(stderr,"Error: loss of page did not return error\n");	exit(1);      }      if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,76,5,-1);      if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,34,6,-1);      fprintf(stderr,"ok.\n");    }    /* Test lost pages on pagein/packetout: rollback with continuation */    {      ogg_page temp;      ogg_packet test;      fprintf(stderr,"Testing loss of pages (rollback required)... ");      ogg_sync_reset(&oy);      ogg_stream_reset(&os_de);      for(i=0;i<5;i++){	memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,	       og[i].header_len);	ogg_sync_wrote(&oy,og[i].header_len);	memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);	ogg_sync_wrote(&oy,og[i].body_len);      }      ogg_sync_pageout(&oy,&temp);      ogg_stream_pagein(&os_de,&temp);      ogg_sync_pageout(&oy,&temp);      ogg_stream_pagein(&os_de,&temp);      ogg_sync_pageout(&oy,&temp);      ogg_stream_pagein(&os_de,&temp);      ogg_sync_pageout(&oy,&temp);      /* skip */      ogg_sync_pageout(&oy,&temp);      ogg_stream_pagein(&os_de,&temp);      /* do we get the expected results/packets? */            if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,0,0,0);      if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,100,1,-1);      if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,4079,2,3000);      if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,2956,3,4000);      if(ogg_stream_packetout(&os_de,&test)!=-1){	fprintf(stderr,"Error: loss of page did not return error\n");	exit(1);      }      if(ogg_stream_packetout(&os_de,&test)!=1)error();      checkpacket(&test,300,13,14000);      fprintf(stderr,"ok.\n");    }        /* the rest only test sync */    {      ogg_page og_de;      /* Test fractional page inputs: incomplete capture */      fprintf(stderr,"Testing sync on partial inputs... ");      ogg_sync_reset(&oy);      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,	     3);      ogg_sync_wrote(&oy,3);      if(ogg_sync_pageout(&oy,&og_de)>0)error();            /* Test fractional page inputs: incomplete fixed header */      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,	     20);      ogg_sync_wrote(&oy,20);      if(ogg_sync_pageout(&oy,&og_de)>0)error();            /* Test fractional page inputs: incomplete header */      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,	     5);      ogg_sync_wrote(&oy,5);      if(ogg_sync_pageout(&oy,&og_de)>0)error();            /* Test fractional page inputs: incomplete body */            memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,	     og[1].header_len-28);      ogg_sync_wrote(&oy,og[1].header_len-28);      if(ogg_sync_pageout(&oy,&og_de)>0)error();            memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);      ogg_sync_wrote(&oy,1000);      if(ogg_sync_pageout(&oy,&og_de)>0)error();            memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,	     og[1].body_len-1000);      ogg_sync_wrote(&oy,og[1].body_len-1000);      if(ogg_sync_pageout(&oy,&og_de)<=0)error();            fprintf(stderr,"ok.\n");    }    /* Test fractional page inputs: page + incomplete capture */    {      ogg_page og_de;      fprintf(stderr,"Testing sync on 1+partial inputs... ");      ogg_sync_reset(&oy);       memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,	     og[1].header_len);      ogg_sync_wrote(&oy,og[1].header_len);      memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,	     og[1].body_len);      ogg_sync_wrote(&oy,og[1].body_len);      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,	     20);      ogg_sync_wrote(&oy,20);      if(ogg_sync_pageout(&oy,&og_de)<=0)error();      if(ogg_sync_pageout(&oy,&og_de)>0)error();      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,	     og[1].header_len-20);      ogg_sync_wrote(&oy,og[1].header_len-20);      memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,	     og[1].body_len);      ogg_sync_wrote(&oy,og[1].body_len);      if(ogg_sync_pageout(&oy,&og_de)<=0)error();      fprintf(stderr,"ok.\n");    }        /* Test recapture: garbage + page */    {      ogg_page og_de;      fprintf(stderr,"Testing search for capture... ");      ogg_sync_reset(&oy);             /* 'garbage' */      memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,	     og[1].body_len);      ogg_sync_wrote(&oy,og[1].body_len);      memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,	     og[1].header_len);      ogg_sync_wrote(&oy,og[1].header_len);      memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,	     og[1].body_len);      ogg_sync_wrote(&oy,og[1].body_len);      memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,	     20);      ogg_sync_wrote(&oy,20);      if(ogg_sync_pageout(&oy,&og_de)>0)error();      if(ogg_sync_pageout(&oy,&og_de)<=0)error();      if(ogg_sync_pageout(&oy,&og_de)>0)error();      memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,	     og[2].header_len-20);      ogg_sync_wrote(&oy,og[2].header_len-20);      memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,	     og[2].body_len);      ogg_sync_wrote(&oy,og[2].body_len);      if(ogg_sync_pageout(&oy,&og_de)<=0)error();      fprintf(stderr,"ok.\n");    }    /* Test recapture: page + garbage + page */    {      ogg_page og_de;      fprintf(stderr,"Testing recapture... ");      ogg_sync_reset(&oy);       memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,	     og[1].header_len);      ogg_sync_wrote(&oy,og[1].header_len);      memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,	     og[1].body_len);      ogg_sync_wrote(&oy,og[1].body_len);      memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,	     og[2].header_len);      ogg_sync_wrote(&oy,og[2].header_len);      memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,	     og[2].header_len);      ogg_sync_wrote(&oy,og[2].header_len);      if(ogg_sync_pageout(&oy,&og_de)<=0)error();      memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,	     og[2].body_len-5);      ogg_sync_wrote(&oy,og[2].body_len-5);      memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,	     og[3].header_len);      ogg_sync_wrote(&oy,og[3].header_len);      memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,	     og[3].body_len);      ogg_sync_wrote(&oy,og[3].body_len);      if(ogg_sync_pageout(&oy,&og_de)>0)error();      if(ogg_sync_pageout(&oy,&og_de)<=0)error();      fprintf(stderr,"ok.\n");    }    /* Free page data that was previously copied */    {      for(i=0;i<5;i++){	free_page(&og[i]);      }    }  }      return(0);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -