Logo Search packages:      
Sourcecode: libjlayer-java version File versions  Download package

void javazoom::jl::decoder::Header::parseVBR ( byte[]  firstframe  )  throws BitstreamException [inline, package]

Parse frame to extract optionnal VBR frame.

Parameters:
firstframe 
Author:
E.B (javalayer@javazoom.net)

Definition at line 241 of file Header.java.

References MPEG1.

Referenced by javazoom::jl::decoder::Bitstream::readFrame().

      {
            // Trying Xing header.
            String xing = "Xing";
            byte tmp[] = new byte[4];
            int offset = 0;
            // Compute "Xing" offset depending on MPEG version and channels.
            if (h_version == MPEG1) 
            {
              if (h_mode == SINGLE_CHANNEL)  offset=21-4;
              else offset=36-4;
            } 
            else 
            {
              if (h_mode == SINGLE_CHANNEL) offset=13-4;
              else offset = 21-4;           
            }
            try
            {
                  System.arraycopy(firstframe, offset, tmp, 0, 4);
                  // Is "Xing" ?
                  if (xing.equals(new String(tmp)))
                  {
                        //Yes.
                        h_vbr = true;
                        h_vbr_frames = -1;
                        h_vbr_bytes = -1;
                        h_vbr_scale = -1;
                        h_vbr_toc = new byte[100];
                                                
                        int length = 4;
                        // Read flags.
                        byte flags[] = new byte[4];
                        System.arraycopy(firstframe, offset + length, flags, 0, flags.length);
                        length += flags.length;
                        // Read number of frames (if available).
                        if ((flags[3] & (byte) (1 << 0)) != 0)
                        {
                              System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
                              h_vbr_frames = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
                              length += 4;      
                        }
                        // Read size (if available).
                        if ((flags[3] & (byte) (1 << 1)) != 0)
                        {
                              System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
                              h_vbr_bytes = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
                              length += 4;      
                        }
                        // Read TOC (if available).
                        if ((flags[3] & (byte) (1 << 2)) != 0)
                        {
                              System.arraycopy(firstframe, offset + length, h_vbr_toc, 0, h_vbr_toc.length);
                              length += h_vbr_toc.length;   
                        }
                        // Read scale (if available).
                        if ((flags[3] & (byte) (1 << 3)) != 0)
                        {
                              System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
                              h_vbr_scale = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
                              length += 4;      
                        }
                        //System.out.println("VBR:"+xing+" Frames:"+ h_vbr_frames +" Size:"+h_vbr_bytes);               
                  }                       
            }
            catch (ArrayIndexOutOfBoundsException e)
            {
                  throw new BitstreamException("XingVBRHeader Corrupted",e);
            }
            
            // Trying VBRI header.              
            String vbri = "VBRI";
            offset = 36-4;
            try
            {
                  System.arraycopy(firstframe, offset, tmp, 0, 4);
                  // Is "VBRI" ?
                  if (vbri.equals(new String(tmp)))
                  {
                        //Yes.
                        h_vbr = true;
                        h_vbr_frames = -1;
                        h_vbr_bytes = -1;
                        h_vbr_scale = -1;
                        h_vbr_toc = new byte[100];
                        // Bytes.                     
                        int length = 4 + 6;
                        System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
                        h_vbr_bytes = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
                        length += 4;      
                        // Frames.  
                        System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
                        h_vbr_frames = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
                        length += 4;      
                        //System.out.println("VBR:"+vbri+" Frames:"+ h_vbr_frames +" Size:"+h_vbr_bytes);
                        // TOC
                        // TODO                       
                  }
            }
            catch (ArrayIndexOutOfBoundsException e)
            {
                  throw new BitstreamException("VBRIVBRHeader Corrupted",e);
            }
      }


Generated by  Doxygen 1.6.0   Back to index