streamstate.java
来自「java ogg player library. for play back o」· Java 代码 · 共 658 行 · 第 1/2 页
JAVA
658 行
lacing_vals[lacing_fill]|=0x100; bos=0; } if(val<255)saved=lacing_fill; lacing_fill++; segptr++; if(val<255)lacing_packet=lacing_fill; } /* set the granulepos on the last pcmval of the last full packet */ if(saved!=-1){ granule_vals[saved]=granulepos; } } if(eos!=0){ e_o_s=1; if(lacing_fill>0) lacing_vals[lacing_fill-1]|=0x200; } pageno=_pageno+1; return(0); }/* This will flush remaining packets into a page (returning nonzero), even if there is not enough data to trigger a flush normally (undersized page). If there are no packets or partial packets to flush, ogg_stream_flush returns 0. Note that ogg_stream_flush will try to flush a normal sized page like ogg_stream_pageout; a call to ogg_stream_flush does not gurantee that all packets have flushed. Only a return value of 0 from ogg_stream_flush indicates all packet data is flushed into pages. ogg_stream_page will flush the last page in a stream even if it's undersized; you almost certainly want to use ogg_stream_pageout (and *not* ogg_stream_flush) unless you need to flush an undersized page in the middle of a stream for some reason. */ public int flush(Page og){//System.out.println(this+" ---body_returned: "+body_returned); int i; int vals=0; int maxvals=(lacing_fill>255?255:lacing_fill); int bytes=0; int acc=0; long granule_pos=granule_vals[0]; if(maxvals==0)return(0); /* construct a page */ /* decide how many segments to include */ /* If this is the initial header case, the first page must only include the initial header packet */ if(b_o_s==0){ /* 'initial header page' case */ granule_pos=0; for(vals=0;vals<maxvals;vals++){ if((lacing_vals[vals]&0x0ff)<255){ vals++; break; } } } else{ for(vals=0;vals<maxvals;vals++){ if(acc>4096)break; acc+=(lacing_vals[vals]&0x0ff); granule_pos=granule_vals[vals]; } } /* construct the header in temp storage */ System.arraycopy("OggS".getBytes(), 0, header, 0, 4); /* stream structure version */ header[4]=0x00; /* continued packet flag? */ header[5]=0x00; if((lacing_vals[0]&0x100)==0)header[5]|=0x01; /* first page flag? */ if(b_o_s==0) header[5]|=0x02; /* last page flag? */ if(e_o_s!=0 && lacing_fill==vals) header[5]|=0x04; b_o_s=1; /* 64 bits of PCM position */ for(i=6;i<14;i++){ header[i]=(byte)granule_pos; granule_pos>>>=8; } /* 32 bits of stream serial number */ { int _serialno=serialno; for(i=14;i<18;i++){ header[i]=(byte)_serialno; _serialno>>>=8; } } /* 32 bits of page counter (we have both counter and page header because this val can roll over) */ if(pageno==-1)pageno=0; /* because someone called stream_reset; this would be a strange thing to do in an encode stream, but it has plausible uses */ { int _pageno=pageno++; for(i=18;i<22;i++){ header[i]=(byte)_pageno; _pageno>>>=8; } } /* zero for computation; filled in later */ header[22]=0; header[23]=0; header[24]=0; header[25]=0; /* segment table */ header[26]=(byte)vals; for(i=0;i<vals;i++){ header[i+27]=(byte)lacing_vals[i]; bytes+=(header[i+27]&0xff); } /* set pointers in the ogg_page struct */ og.header_base=header; og.header=0; og.header_len=header_fill=vals+27; og.body_base=body_data; og.body=body_returned; og.body_len=bytes; /* advance the lacing data and set the body_returned pointer */ //System.out.println("###body_returned: "+body_returned); lacing_fill-=vals; System.arraycopy(lacing_vals, vals, lacing_vals, 0, lacing_fill*4); System.arraycopy(granule_vals, vals, granule_vals, 0, lacing_fill*8); body_returned+=bytes;//System.out.println("####body_returned: "+body_returned); /* calculate the checksum */ og.checksum(); /* done */ return(1); }/* This constructs pages from buffered packet segments. The pointersreturned are to static buffers; do not free. The returned buffers aregood only until the next call (using the same ogg_stream_state) */ public int pageout(Page og){// if(body_returned!=0){// /* advance packet data according to the body_returned pointer. We// had to keep it around to return a pointer into the buffer last// call *///// body_fill-=body_returned;// if(body_fill!=0){ // overlap?// System.arraycopy(body_data, body_returned, body_data, 0, body_fill);// }// body_returned=0;// }////System.out.println("pageout: e_o_s="+e_o_s+" lacing_fill="+lacing_fill+" body_fill="+body_fill+", lacing_fill="+lacing_fill+" b_o_s="+b_o_s);//// if((e_o_s!=0&&lacing_fill!=0) || /* 'were done, now flush' case */// body_fill > 4096 || /* 'page nominal size' case */// lacing_fill>=255 || /* 'segment table full' case */// (lacing_fill!=0&&b_o_s==0)){ /* 'initial header page' case */// int vals=0,bytes=0;// int maxvals=(lacing_fill>255?255:lacing_fill);// long acc=0;// long pcm_pos=granule_vals[0];//// /* construct a page */// /* decide how many segments to include *///// /* If this is the initial header case, the first page must only include// the initial header packet */// if(b_o_s==0){ /* 'initial header page' case */// pcm_pos=0;// for(vals=0;vals<maxvals;vals++){// if((lacing_vals[vals]&0x0ff)<255){// vals++;// break;// }// }// }// else{// for(vals=0;vals<maxvals;vals++){// if(acc>4096)break;// acc+=lacing_vals[vals]&0x0ff;// pcm_pos=granule_vals[vals];// }// }//// /* construct the header in temp storage */// System.arraycopy("OggS".getBytes(), 0, header, 0, 4);//// /* stream structure version */// header[4]=0x00;// // /* continued packet flag? */// header[5]=0x00;// if((lacing_vals[0]&0x100)==0)header[5]|=0x01;// /* first page flag? */// if(b_o_s==0)header[5]|=0x02;// /* last page flag? */// if(e_o_s!=0 && lacing_fill==vals)header[5]|=0x04;// b_o_s=1;//// /* 64 bits of PCM position */// for(int i=6;i<14;i++){// header[i]=(byte)pcm_pos;// pcm_pos>>>=8;// }//// /* 32 bits of stream serial number */// {// int serialn=serialno;// for(int i=14;i<18;i++){// header[i]=(byte)serialn;// serialn>>>=8;// }// }///////* 32 bits of page counter (we have both counter and page header// because this val can roll over) */// if(pageno==-1)pageno=0; /* because someone called// stream_reset; this would be a// strange thing to do in an// encode stream, but it has// plausible uses */// {// int pagen=pageno++;// for(int i=18;i<22;i++){// header[i]=(byte)pagen;// pagen>>>=8;// }// }//// /* zero for computation; filled in later */// header[22]=0;// header[23]=0;// header[24]=0;// header[25]=0;//// /* segment table */// header[26]=(byte)vals;// for(int i=0;i<vals;i++){// header[i+27]=(byte)lacing_vals[i];// bytes+=header[i+27]&0xff;//// bytes+=header[i+27]=(lacing_vals[i]&0xff);// }// // /* advance the lacing data and set the body_returned pointer *///// lacing_fill-=vals;// System.arraycopy(lacing_vals, vals, lacing_vals, 0, lacing_fill);// System.arraycopy(granule_vals, vals, granule_vals, 0, lacing_fill);// body_returned=bytes;//// /* set pointers in the ogg_page struct */// og.header_base=header;// og.header=0;// og.header_len=header_fill=vals+27;//// og.body_base=body_data;// og.body=0;// og.body_len=bytes;//// /* calculate the checksum *///// og.checksum();// return(1);// }// /* not enough data to construct a page and not end of stream */// return(0);//System.out.println("pageout: "+body_returned); if((e_o_s!=0&&lacing_fill!=0) || /* 'were done, now flush' case */ body_fill-body_returned> 4096 || /* 'page nominal size' case */ lacing_fill>=255 || /* 'segment table full' case */ (lacing_fill!=0&&b_o_s==0)){ /* 'initial header page' case */ return flush(og); } return 0; } public int eof(){ return e_o_s; } public int reset(){ body_fill=0; body_returned=0; lacing_fill=0; lacing_packet=0; lacing_returned=0; header_fill=0; e_o_s=0; b_o_s=0; pageno=-1; packetno=0; granulepos=0; return(0); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?