Package com.google.android.exoplayer2.extractor

## Class VorbisUtil

- java.lang.Object
- - com.google.android.exoplayer2.extractor.VorbisUtil

-     public final class VorbisUtil
      extends Object

  Utility methods for parsing Vorbis streams.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `VorbisUtil.CommentHeader` | Vorbis comment header.
    `static class` | `VorbisUtil.Mode` | Vorbis setup header modes.
    `static class` | `VorbisUtil.VorbisIdHeader` | Vorbis identification header.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static int` | `iLog​(int x)` | Returns ilog(x), which is the index of the highest set bit in `x`.
    `static VorbisUtil.CommentHeader` | `readVorbisCommentHeader​(ParsableByteArray headerData)` | Reads a Vorbis comment header.
    `static VorbisUtil.CommentHeader` | `readVorbisCommentHeader​(ParsableByteArray headerData, boolean hasMetadataHeader, boolean hasFramingBit)` | Reads a Vorbis comment header.
    `static VorbisUtil.VorbisIdHeader` | `readVorbisIdentificationHeader​(ParsableByteArray headerData)` | Reads a Vorbis identification header from `headerData`.
    `static VorbisUtil.Mode[]` | `readVorbisModes​(ParsableByteArray headerData, int channels)` | This method reads the modes which are located at the very end of the Vorbis setup header.
    `static boolean` | `verifyVorbisHeaderCapturePattern​(int headerType, ParsableByteArray header, boolean quiet)` | Verifies whether the next bytes in `header` are a Vorbis header of the given `headerType`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### iLog

          public static int iLog​(int x)

      Returns ilog(x), which is the index of the highest set bit in `x`.
      Parameters:
        `x` - the value of which the ilog should be calculated.
      Returns:
        ilog(x)
      See Also:
        Vorbis spec

    - #### readVorbisIdentificationHeader

          public static VorbisUtil.VorbisIdHeader readVorbisIdentificationHeader​(ParsableByteArray headerData)
                                                                          throws ParserException

      Reads a Vorbis identification header from `headerData`.
      Parameters:
        `headerData` - a `ParsableByteArray` wrapping the header data.
      Returns:
        a `VorbisUtil.VorbisIdHeader` with meta data.
      Throws:
        `ParserException` - thrown if invalid capture pattern is detected.
      See Also:
        Vorbis spec/Identification header

    - #### readVorbisCommentHeader

          public static VorbisUtil.CommentHeader readVorbisCommentHeader​(ParsableByteArray headerData)
                                                                  throws ParserException

      Reads a Vorbis comment header.
      Parameters:
        `headerData` - A `ParsableByteArray` wrapping the header data.
      Returns:
        A `VorbisUtil.CommentHeader` with all the comments.
      Throws:
        `ParserException` - If an error occurs parsing the comment header.
      See Also:
        Vorbis spec/Comment header

    - #### readVorbisCommentHeader

          public static VorbisUtil.CommentHeader readVorbisCommentHeader​(ParsableByteArray headerData,
                                                                         boolean hasMetadataHeader,
                                                                         boolean hasFramingBit)
                                                                  throws ParserException

      Reads a Vorbis comment header.

      The data provided may not contain the Vorbis metadata common header and the framing bit.

      Parameters:
        `headerData` - A `ParsableByteArray` wrapping the header data.
        `hasMetadataHeader` - Whether the `headerData` contains a Vorbis metadata common header preceding the comment header.
        `hasFramingBit` - Whether the `headerData` contains a framing bit.
      Returns:
        A `VorbisUtil.CommentHeader` with all the comments.
      Throws:
        `ParserException` - If an error occurs parsing the comment header.
      See Also:
        Vorbis spec/Comment header

    - #### verifyVorbisHeaderCapturePattern

          public static boolean verifyVorbisHeaderCapturePattern​(int headerType,
                                                                 ParsableByteArray header,
                                                                 boolean quiet)
                                                          throws ParserException

      Verifies whether the next bytes in `header` are a Vorbis header of the given `headerType`.
      Parameters:
        `headerType` - the type of the header expected.
        `header` - the alleged header bytes.
        `quiet` - if `true` no exceptions are thrown. Instead `false` is returned.
      Returns:
        the number of bytes read.
      Throws:
        `ParserException` - thrown if header type or capture pattern is not as expected.

    - #### readVorbisModes

          public static VorbisUtil.Mode[] readVorbisModes​(ParsableByteArray headerData,
                                                          int channels)
                                                   throws ParserException

      This method reads the modes which are located at the very end of the Vorbis setup header. That's why we need to partially decode or at least read the entire setup header to know where to start reading the modes.
      Parameters:
        `headerData` - a `ParsableByteArray` containing setup header data.
        `channels` - the number of channels.
      Returns:
        an array of `VorbisUtil.Mode`s.
      Throws:
        `ParserException` - thrown if bit stream is invalid.
      See Also:
        Vorbis spec/Setup header