csvorbis.Info.synthesis_headerin C# (CSharp) Method

synthesis_headerin() public method

public synthesis_headerin ( Comment vc, Packet op ) : int
vc Comment
op csogg.Packet
return int
        public int synthesis_headerin(Comment vc, Packet op)
        {
            csBuffer opb=new csBuffer();

            if(op!=null)
            {
                opb.readinit(op.packet_base, op.packet, op.bytes);

                // Which of the three types of header is this?
                // Also verify header-ness, vorbis
            {
                byte[] buffer=new byte[6];
                int packtype=opb.read(8);
                //memset(buffer,0,6);
                opb.read(buffer,6);
                if(buffer[0]!='v' || buffer[1]!='o' || buffer[2]!='r' ||
                    buffer[3]!='b' || buffer[4]!='i' || buffer[5]!='s')
                {
                    // not a vorbis header
                    return(-1);
                }
                switch(packtype)
                {
                    case 0x01: // least significant *bit* is read first
                        if(op.b_o_s==0)
                        {
                            // Not the initial packet
                            return(-1);
                        }
                        if(rate!=0)
                        {
                            // previously initialized info header
                            return(-1);
                        }
                        return(unpack_info(opb));
                    case 0x03: // least significant *bit* is read first
                        if(rate==0)
                        {
                            // um... we didn't get the initial header
                            return(-1);
                        }
                        return(vc.unpack(opb));
                    case 0x05: // least significant *bit* is read first
                        if(rate==0 || vc.vendor==null)
                        {
                            // um... we didn;t get the initial header or comments yet
                            return(-1);
                        }
                        return(unpack_books(opb));
                    default:
                        // Not a valid vorbis header type
                        //return(-1);
                        break;
                }
            }
            }
            return(-1);
        }

Usage Example

		// uses the local ogg_stream storage in vf; this is important for
		// non-streaming input sources
        public int fetch_headers(Info vi, Comment vc, int[] serialno, Page og_ptr, VorbisFileInstance instance)
		{
			//System.err.println("fetch_headers");
			Page og=new Page();
			Packet op=new Packet();
			int ret;

			if(og_ptr==null)
			{
                ret = get_next_page(og, CHUNKSIZE, instance);
				if(ret==OV_EREAD)return OV_EREAD;
				if(ret<0) return OV_ENOTVORBIS;
				og_ptr=og;
			}
  
			if(serialno!=null)serialno[0]=og_ptr.serialno();

			instance.os.init(og_ptr.serialno());
  
			// extract the initial header from the first page and verify that the
			// Ogg bitstream is in fact Vorbis data
  
			vi.init();
			vc.init();
  
			int i=0;
			while(i<3)
			{
                instance.os.pagein(og_ptr);
				while(i<3)
				{
                    int result = instance.os.packetout(op);
					if(result==0)break;
					if(result==-1)
					{
						Console.Error.WriteLine("Corrupt header in logical bitstream.");
						//goto bail_header;
						vi.clear();
						vc.clear();
                        instance.os.clear();
						return -1;
					}
					if(vi.synthesis_headerin(vc, op)!=0)
					{
						Console.Error.WriteLine("Illegal header in logical bitstream.");
						//goto bail_header;
						vi.clear();
						vc.clear();
                        instance.os.clear();
						return -1;
					}
					i++;
				}
				if(i<3)
					if(get_next_page(og_ptr, 1, instance)<0)
					{
						Console.Error.WriteLine("Missing header in logical bitstream.");
						//goto bail_header;
						vi.clear();
						vc.clear();
                        instance.os.clear();
						return -1;
					}
			}
			return 0; 
		}
All Usage Examples Of csvorbis.Info::synthesis_headerin