/**
   * Get the next rtp packet recorded in the rtpdump file.
   *
   * @param loopFile if true, when the end of the rtpdump file is reached, this
   *     <tt>RtpdumpFileReader</tt> will go back at the beginning of the file and get the first
   *     packet.
   * @return a <tt>RawPacket</tt> containing all the information and data of the next rtp packet
   *     recorded in the rtpdump file
   * @throws IOException if <tt>loopFile</tt> was false and the end of the file is reached.
   */
  public RawPacket getNextPacket(boolean loopFile) throws IOException {
    if (loopFile && (stream.getFilePointer() >= stream.length())) {
      resetFile();
    }

    byte[] rtpdumpPacket;
    int sizeInBytes;

    stream.readShort(); // read away an useless short (2 bytes)
    sizeInBytes = stream.readUnsignedShort();
    rtpdumpPacket = new byte[sizeInBytes];
    stream.readInt(); // read away the rtpdump timestamp

    stream.read(rtpdumpPacket);

    return new RawPacket(rtpdumpPacket, 0, rtpdumpPacket.length);
  }
 /**
  * Go to the beginning of the rtpdump file and skip the first line of ascii (giving the file
  * version) and skip the file header (useless)
  *
  * @throws IOException if an error occur during the seek and reading of the file.
  */
 private void resetFile() throws IOException {
   stream.seek(0);
   stream.readLine(); // read the first line that is in ascii
   stream.seek(stream.getFilePointer() + RtpdumpFileReader.FILE_HEADER_LENGTH);
 }