FlacFrameReader { public static int readFrameBlockSizeSamplesFromKey(ParsableByteArray data, int blockSizeKey) { switch (blockSizeKey) { case 1: return 192; case 2: case 3: case 4: case 5: return 576 << (blockSizeKey - 2); case 6: return data.readUnsignedByte() + 1; case 7: return data.readUnsignedShort() + 1; case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: return 256 << (blockSizeKey - 8); default: return -1; } } private  FlacFrameReader(); static boolean checkAndReadFrameHeader(
      ParsableByteArray data,
      FlacStreamMetadata flacStreamMetadata,
      int frameStartMarker,
      SampleNumberHolder sampleNumberHolder); static boolean checkFrameHeaderFromPeek(
      ExtractorInput input,
      FlacStreamMetadata flacStreamMetadata,
      int frameStartMarker,
      SampleNumberHolder sampleNumberHolder); static long getFirstSampleNumber(
      ExtractorInput input, FlacStreamMetadata flacStreamMetadata); static int readFrameBlockSizeSamplesFromKey(ParsableByteArray data, int blockSizeKey);  }
@Test public void readFrameBlockSizeSamplesFromKey_keyIs1_returnsCorrectBlockSize() { int result = FlacFrameReader.readFrameBlockSizeSamplesFromKey( new ParsableByteArray( 0), 1); assertThat(result).isEqualTo(192); }
@Test public void readFrameBlockSizeSamplesFromKey_keyBetween2and5_returnsCorrectBlockSize() { int result = FlacFrameReader.readFrameBlockSizeSamplesFromKey( new ParsableByteArray( 0), 3); assertThat(result).isEqualTo(1152); }
@Test public void readFrameBlockSizeSamplesFromKey_keyBetween6And7_returnsCorrectBlockSize() throws Exception { ExtractorInput input = buildExtractorInput("flac/bear_one_metadata_block.flac"); input.skipFully(164033); ParsableByteArray scratch = new ParsableByteArray(2); input.readFully(scratch.data, 0, 2); int result = FlacFrameReader.readFrameBlockSizeSamplesFromKey(scratch, 7); assertThat(result).isEqualTo(496); }
@Test public void readFrameBlockSizeSamplesFromKey_keyBetween8and15_returnsCorrectBlockSize() { int result = FlacFrameReader.readFrameBlockSizeSamplesFromKey( new ParsableByteArray( 0), 11); assertThat(result).isEqualTo(2048); }
@Test public void readFrameBlockSizeSamplesFromKey_invalidKey_returnsCorrectBlockSize() { int result = FlacFrameReader.readFrameBlockSizeSamplesFromKey( new ParsableByteArray( 0), 25); assertThat(result).isEqualTo(-1); }