2929import java .util .stream .Collectors ;
3030
3131/**
32+ * <p>
33+ * This class is used to convert a WebM stream containing Opus or Vorbis audio
34+ * into an Ogg stream.
35+ * </p>
36+ *
37+ * <p>
38+ * The following specifications are used for the implementation:
39+ * </p>
40+ * <ul>
41+ * <li>Opus: All specs can be found at <a href="https://opus-codec.org/docs/">
42+ * https://opus-codec.org/docs/</a>.
43+ * <a href="https://datatracker.ietf.org/doc/html/rfc7845.html">RFC7845</a>
44+ * defines the Ogg encapsulation for Opus streams, i.e.the container format and metadata.
45+ * </li>
46+ * <li>Vorbis: <a href="https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html">Vorbis I</a></li>
47+ * </ul>
48+ *
3249 * @author kapodamy
50+ * @author tobigr
3351 */
3452public class OggFromWebMWriter implements Closeable {
3553 private static final byte FLAG_UNSET = 0x00 ;
@@ -203,7 +221,7 @@ public void build() throws IOException {
203221 /* step 2: create packet with code init data */
204222 if (webmTrack .codecPrivate != null ) {
205223 addPacketSegment (webmTrack .codecPrivate .length );
206- makePacketheader (0x00 , header , webmTrack .codecPrivate );
224+ makePacketHeader (0x00 , header , webmTrack .codecPrivate );
207225 write (header );
208226 output .write (webmTrack .codecPrivate );
209227 }
@@ -212,7 +230,7 @@ public void build() throws IOException {
212230 final byte [] buffer = makeMetadata ();
213231 if (buffer != null ) {
214232 addPacketSegment (buffer .length );
215- makePacketheader (0x00 , header , buffer );
233+ makePacketHeader (0x00 , header , buffer );
216234 write (header );
217235 output .write (buffer );
218236 }
@@ -251,7 +269,7 @@ public void build() throws IOException {
251269 elapsedNs = Math .ceil (elapsedNs * resolution );
252270
253271 // create header and calculate page checksum
254- int checksum = makePacketheader ((long ) elapsedNs , header , null );
272+ int checksum = makePacketHeader ((long ) elapsedNs , header , null );
255273 checksum = calcCrc32 (checksum , page .array (), page .position ());
256274
257275 header .putInt (HEADER_CHECKSUM_OFFSET , checksum );
@@ -264,7 +282,7 @@ public void build() throws IOException {
264282 }
265283 }
266284
267- private int makePacketheader (final long granPos , @ NonNull final ByteBuffer buffer ,
285+ private int makePacketHeader (final long granPos , @ NonNull final ByteBuffer buffer ,
268286 final byte [] immediatePage ) {
269287 short length = HEADER_SIZE ;
270288
@@ -297,6 +315,16 @@ private int makePacketheader(final long granPos, @NonNull final ByteBuffer buffe
297315 return checksumCrc32 ;
298316 }
299317
318+ /**
319+ * Creates the metadata header for the selected codec (Opus or Vorbis).
320+ *
321+ * Opus metadata can contain
322+ *
323+ * @ImplNote See <a href="https://datatracker.ietf.org/doc/html/rfc7845.html#section-5.2">
324+ * RFC7845 5.2</a>
325+ *
326+ * @return
327+ */
300328 @ Nullable
301329 private byte [] makeMetadata () {
302330 if (DEBUG ) {
@@ -326,6 +354,10 @@ private byte[] makeMetadata() {
326354
327355 return makeOpusTagsHeader (metadata );
328356 } else if ("A_VORBIS" .equals (webmTrack .codecId )) {
357+ /**
358+ * See <a href="https://datatracker.ietf.org/doc/html/rfc7845.html#section-5.2">
359+ * RFC7845 5.2</a>
360+ */
329361 return new byte []{
330362 0x03 , // ???
331363 0x76 , 0x6f , 0x72 , 0x62 , 0x69 , 0x73 , // "vorbis" binary string
@@ -413,6 +445,9 @@ private static Pair<String, String> makeOpusPictureTag(final Bitmap bitmap) {
413445 * You probably want to use makeOpusMetadata(), which uses this function to create
414446 * a header with sensible metadata filled in.
415447 *
448+ * @ImplNote See <a href="https://datatracker.ietf.org/doc/html/rfc7845.html#section-5.2">
449+ * RFC7845 5.2</a>
450+ *
416451 * @param keyValueLines A list of pairs of the tags. This can also be though of as a mapping
417452 * from one key to multiple values.
418453 * @return The binary header
0 commit comments