public interface

EbmlProcessor

 androidx.media3.extractor.mkv.EbmlProcessor

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-extractor', version: '1.5.0-alpha01'

  • groupId: androidx.media3
  • artifactId: media3-extractor
  • version: 1.5.0-alpha01

Artifact androidx.media3:media3-extractor:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Defines EBML element IDs/types and processes events.

Summary

Fields
public static final intELEMENT_TYPE_BINARY

Type for binary elements.

public static final intELEMENT_TYPE_FLOAT

Type for IEEE floating point value elements of either 4 or 8 bytes.

public static final intELEMENT_TYPE_MASTER

Type for elements that contain child elements.

public static final intELEMENT_TYPE_STRING

Type for string elements.

public static final intELEMENT_TYPE_UNKNOWN

Type for unknown elements.

public static final intELEMENT_TYPE_UNSIGNED_INT

Type for integer value elements of up to 8 bytes.

Methods
public voidbinaryElement(int id, int contentsSize, ExtractorInput input)

Called when a binary element is encountered.

public voidendMasterElement(int id)

Called when the end of a master element is encountered.

public voidfloatElement(int id, double value)

Called when a float element is encountered.

public intgetElementType(int id)

Maps an element ID to a corresponding type.

public voidintegerElement(int id, long value)

Called when an integer element is encountered.

public booleanisLevel1Element(int id)

Checks if the given id is that of a level 1 element.

public voidstartMasterElement(int id, long contentPosition, long contentSize)

Called when the start of a master element is encountered.

public voidstringElement(int id, java.lang.String value)

Called when a string element is encountered.

Fields

public static final int ELEMENT_TYPE_UNKNOWN

Type for unknown elements.

public static final int ELEMENT_TYPE_MASTER

Type for elements that contain child elements.

public static final int ELEMENT_TYPE_UNSIGNED_INT

Type for integer value elements of up to 8 bytes.

public static final int ELEMENT_TYPE_STRING

Type for string elements.

public static final int ELEMENT_TYPE_BINARY

Type for binary elements.

public static final int ELEMENT_TYPE_FLOAT

Type for IEEE floating point value elements of either 4 or 8 bytes.

Methods

public int getElementType(int id)

Maps an element ID to a corresponding type.

If EbmlProcessor.ELEMENT_TYPE_UNKNOWN is returned then the element is skipped. Note that all children of a skipped element are also skipped.

Parameters:

id: The element ID to map.

Returns:

One of EbmlProcessor.ELEMENT_TYPE_UNKNOWN, EbmlProcessor.ELEMENT_TYPE_MASTER, EbmlProcessor.ELEMENT_TYPE_UNSIGNED_INT, EbmlProcessor.ELEMENT_TYPE_STRING, EbmlProcessor.ELEMENT_TYPE_BINARY and EbmlProcessor.ELEMENT_TYPE_FLOAT.

public boolean isLevel1Element(int id)

Checks if the given id is that of a level 1 element.

Parameters:

id: The element ID.

Returns:

Whether the given id is that of a level 1 element.

public void startMasterElement(int id, long contentPosition, long contentSize)

Called when the start of a master element is encountered.

Following events should be considered as taking place within this element until a matching call to EbmlProcessor.endMasterElement(int) is made.

Note that it is possible for another master element of the same element ID to be nested within itself.

Parameters:

id: The element ID.
contentPosition: The position of the start of the element's content in the stream.
contentSize: The size of the element's content in bytes.

public void endMasterElement(int id)

Called when the end of a master element is encountered.

Parameters:

id: The element ID.

public void integerElement(int id, long value)

Called when an integer element is encountered.

Parameters:

id: The element ID.
value: The integer value that the element contains.

public void floatElement(int id, double value)

Called when a float element is encountered.

Parameters:

id: The element ID.
value: The float value that the element contains

public void stringElement(int id, java.lang.String value)

Called when a string element is encountered.

Parameters:

id: The element ID.
value: The string value that the element contains.

public void binaryElement(int id, int contentsSize, ExtractorInput input)

Called when a binary element is encountered.

The element header (containing the element ID and content size) will already have been read. Implementations are required to consume the whole remainder of the element, which is contentSize bytes in length, before returning. Implementations are permitted to fail (by throwing an exception) having partially consumed the data, however if they do this, they must consume the remainder of the content when called again.

Parameters:

id: The element ID.
contentsSize: The element's content size.
input: The ExtractorInput from which data should be read.

Source

/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.media3.extractor.mkv;

import static java.lang.annotation.ElementType.TYPE_USE;

import androidx.annotation.IntDef;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.extractor.ExtractorInput;
import java.io.IOException;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** Defines EBML element IDs/types and processes events. */
@UnstableApi
public interface EbmlProcessor {

  /**
   * EBML element types. One of {@link #ELEMENT_TYPE_UNKNOWN}, {@link #ELEMENT_TYPE_MASTER}, {@link
   * #ELEMENT_TYPE_UNSIGNED_INT}, {@link #ELEMENT_TYPE_STRING}, {@link #ELEMENT_TYPE_BINARY} or
   * {@link #ELEMENT_TYPE_FLOAT}.
   */
  @Documented
  @Retention(RetentionPolicy.SOURCE)
  @Target(TYPE_USE)
  @IntDef({
    ELEMENT_TYPE_UNKNOWN,
    ELEMENT_TYPE_MASTER,
    ELEMENT_TYPE_UNSIGNED_INT,
    ELEMENT_TYPE_STRING,
    ELEMENT_TYPE_BINARY,
    ELEMENT_TYPE_FLOAT
  })
  @interface ElementType {}

  /** Type for unknown elements. */
  int ELEMENT_TYPE_UNKNOWN = 0;

  /** Type for elements that contain child elements. */
  int ELEMENT_TYPE_MASTER = 1;

  /** Type for integer value elements of up to 8 bytes. */
  int ELEMENT_TYPE_UNSIGNED_INT = 2;

  /** Type for string elements. */
  int ELEMENT_TYPE_STRING = 3;

  /** Type for binary elements. */
  int ELEMENT_TYPE_BINARY = 4;

  /** Type for IEEE floating point value elements of either 4 or 8 bytes. */
  int ELEMENT_TYPE_FLOAT = 5;

  /**
   * Maps an element ID to a corresponding type.
   *
   * <p>If {@link #ELEMENT_TYPE_UNKNOWN} is returned then the element is skipped. Note that all
   * children of a skipped element are also skipped.
   *
   * @param id The element ID to map.
   * @return One of {@link #ELEMENT_TYPE_UNKNOWN}, {@link #ELEMENT_TYPE_MASTER}, {@link
   *     #ELEMENT_TYPE_UNSIGNED_INT}, {@link #ELEMENT_TYPE_STRING}, {@link #ELEMENT_TYPE_BINARY} and
   *     {@link #ELEMENT_TYPE_FLOAT}.
   */
  @ElementType
  int getElementType(int id);

  /**
   * Checks if the given id is that of a level 1 element.
   *
   * @param id The element ID.
   * @return Whether the given id is that of a level 1 element.
   */
  boolean isLevel1Element(int id);

  /**
   * Called when the start of a master element is encountered.
   *
   * <p>Following events should be considered as taking place within this element until a matching
   * call to {@link #endMasterElement(int)} is made.
   *
   * <p>Note that it is possible for another master element of the same element ID to be nested
   * within itself.
   *
   * @param id The element ID.
   * @param contentPosition The position of the start of the element's content in the stream.
   * @param contentSize The size of the element's content in bytes.
   * @throws ParserException If a parsing error occurs.
   */
  void startMasterElement(int id, long contentPosition, long contentSize) throws ParserException;

  /**
   * Called when the end of a master element is encountered.
   *
   * @param id The element ID.
   * @throws ParserException If a parsing error occurs.
   */
  void endMasterElement(int id) throws ParserException;

  /**
   * Called when an integer element is encountered.
   *
   * @param id The element ID.
   * @param value The integer value that the element contains.
   * @throws ParserException If a parsing error occurs.
   */
  void integerElement(int id, long value) throws ParserException;

  /**
   * Called when a float element is encountered.
   *
   * @param id The element ID.
   * @param value The float value that the element contains
   * @throws ParserException If a parsing error occurs.
   */
  void floatElement(int id, double value) throws ParserException;

  /**
   * Called when a string element is encountered.
   *
   * @param id The element ID.
   * @param value The string value that the element contains.
   * @throws ParserException If a parsing error occurs.
   */
  void stringElement(int id, String value) throws ParserException;

  /**
   * Called when a binary element is encountered.
   *
   * <p>The element header (containing the element ID and content size) will already have been read.
   * Implementations are required to consume the whole remainder of the element, which is {@code
   * contentSize} bytes in length, before returning. Implementations are permitted to fail (by
   * throwing an exception) having partially consumed the data, however if they do this, they must
   * consume the remainder of the content when called again.
   *
   * @param id The element ID.
   * @param contentsSize The element's content size.
   * @param input The {@link ExtractorInput} from which data should be read.
   * @throws ParserException If a parsing error occurs.
   * @throws IOException If an error occurs reading from the input.
   */
  void binaryElement(int id, int contentsSize, ExtractorInput input) throws IOException;
}