Example #1
0
Boolean OggFileParser::parse() {
  try {
    while (1) {
      switch (fCurrentParseState) {
        case PARSING_START_OF_FILE: {
	  if (parseStartOfFile()) return True;
	}
        case PARSING_AND_DELIVERING_PAGES: {
	  parseAndDeliverPages();
        }
        case DELIVERING_PACKET_WITHIN_PAGE: {
	  if (deliverPacketWithinPage()) return False;
	}
      }
    }
  } catch (int /*e*/) {
#ifdef DEBUG
    fprintf(stderr, "OggFileParser::parse() EXCEPTION (This is normal behavior - *not* an error)\n");
#endif
    return False; // the parsing got interrupted
  }
}
Boolean MatroskaFileParser::parse() {
  Boolean areDone = False;

  try {
    do {
      switch (fCurrentParseState) {
        case PARSING_START_OF_FILE: {
	  areDone = parseStartOfFile();
	  break;
	}
        case LOOKING_FOR_TRACKS: {
	  lookForNextTrack();
	  break;
	}
        case PARSING_TRACK: {
	  areDone = parseTrack();
	  if (areDone && fOurFile.fCuesOffset > 0) {
	    // We've finished parsing the 'Track' information.  There are also 'Cues' in the file, so parse those before finishing:
	    // Seek to the specified position in the file.  We were already told that the 'Cues' begins there:
#ifdef DEBUG
	    fprintf(stderr, "Seeking to file position %llu (the previously-reported location of 'Cues')\n", fOurFile.fCuesOffset);
#endif
	    seekToFilePosition(fOurFile.fCuesOffset);
	    fCurrentParseState = PARSING_CUES;
	    areDone = False;
	  }
	  break;
	}
        case PARSING_CUES: {
	  areDone = parseCues();
	  break;
	}
        case LOOKING_FOR_CLUSTER: {
	  if (fOurFile.fClusterOffset > 0) {
	    // Optimization: Seek to the specified position in the file.  We were already told that the 'Cluster' begins there:
#ifdef DEBUG
	    fprintf(stderr, "Optimization: Seeking to file position %llu (the previously-reported location of a 'Cluster')\n", fOurFile.fClusterOffset);
#endif
	    seekToFilePosition(fOurFile.fClusterOffset);
	  }
	  fCurrentParseState = LOOKING_FOR_BLOCK;
	  break;
	}
        case LOOKING_FOR_BLOCK: {
	  lookForNextBlock();
	  break;
	}
        case PARSING_BLOCK: {
	  parseBlock();
	  break;
	}
        case DELIVERING_FRAME_WITHIN_BLOCK: {
	  if (!deliverFrameWithinBlock()) return False;
	  break;
	}
        case DELIVERING_FRAME_BYTES: {
	  deliverFrameBytes();
	  return False; // Halt parsing for now.  A new 'read' from downstream will cause parsing to resume.
	  break;
	}
      }
    } while (!areDone);

    return True;
  } catch (int /*e*/) {
#ifdef DEBUG
    fprintf(stderr, "MatroskaFileParser::parse() EXCEPTION (This is normal behavior - *not* an error)\n");
#endif
    return False;  // the parsing got interrupted
  }
}