import Mpeg4BoxHeader from "../mpeg4BoxHeader"; import { ByteVector } from "../../byteVector"; import { File } from "../../file"; /** * This class provides a generic implementation of a ISO/IEC 14496-12 box. */ export default abstract class Mpeg4Box { private readonly _children; private _data; private _handlerType; private _header; private _baseDataPosition; private _dataPosition; /** * Protected constructor to force construction via static functions. */ protected constructor(); /** * Initializes a new instance of @see Mpeg4Box with a specified header and handler. * @param header A @see Mpeg4BoxHeader object describing the new instance. * @param handlerType Type of the handler box object containing the handler that applies to the * new instance, or undefined if no handler applies. */ protected initializeFromHeader(header: Mpeg4BoxHeader, handlerType?: ByteVector): void; /** * Initializes a new instance of @see Mpeg4Box with a specified box type. * @param type A @see ByteVector object containing the box type to use for the new instance. */ protected initializeFromType(type: ByteVector): void; /** * Gets the MPEG-4 box type of the current instance. */ get boxType(): ByteVector; /** * Gets the child boxes of the current instance. * @internal */ get children(): Mpeg4Box[]; /** * Gets the data contained in the current instance. */ get data(): ByteVector; /** * Sets the data contained in the current instance. */ set data(v: ByteVector); /** * Gets the position of the data contained in the current instance, after any box specific headers. */ get dataPosition(): number; /** * Gets the size of the data contained in the current instance, minus the size of any box specific headers. */ get dataSize(): number; /** * Gets the type of the handler box that applies to the current instance. */ get handlerType(): ByteVector; /** * Gets whether the current instance has children. */ get hasChildren(): boolean; /** * Gets the header of the current instance. */ get header(): Mpeg4BoxHeader; /** * Gets the total size of the current instance as it last appeared on disk. */ get size(): number; /** * Adds a specified box to the current instance. * @param box A @see Mpeg4Box object to add to the current instance. */ addChild(box: Mpeg4Box): void; /** * Removes all children from the current instance. */ clearChildren(): void; /** * Gets a child box from the current instance by finding a matching box type. * @param type A @see ByteVector object containing the box type to match. * @param predicate Optional predicate to filter boxes with the provided type. * @returns TBox Box containing the matched box, or `undefined` if no match was found. */ getChild(type: ByteVector, predicate?: (b: TBox) => boolean): TBox; /** * Gets a child box from the current instance by finding a matching box type, searching recursively. * @param type A @see ByteVector object containing the box type to match. * @returns Mpeg4Box Matching box, or `undefined` if no matching box was found */ getChildRecursively(type: ByteVector): Mpeg4Box; /** * Gets all child boxes from the current instance by finding a matching box type. * @param type A @see ByteVector object containing the box type to match. * @param predicate Optional predicate to filter boxes with the provided type. * @returns Mpeg4Box[] Array of matching boxes, or `undefined` if no matching boxes was found. */ getChildren(type: ByteVector, predicate?: (b: TBox) => boolean): TBox[]; /** * Removes a specified box from the current instance. * @param box Box to remove from the current instance. */ removeChildByBox(box: Mpeg4Box): void; /** * Removes all children with a specified box type from the current instance. * @param type Type of box to remove */ removeChildByType(type: ByteVector): void; /** * Removes all specified boxes from the current instance. * @param boxes Collection of boxes to remove from the current instance. */ removeChildrenByBox(boxes: Mpeg4Box[]): void; /** * Loads the data of the current instance from a specified file using the internal data position and size. * @param file The @see File from which the current instance was read and from which to read the data. * @returns ByteVector Data read from the file. */ loadData(file: File): ByteVector; /** * Increases the data position by a given value. This function can be used by boxes * which extend from @see Mpeg4Box to increase the data position, because the data * is located after their box specific headers. * @param value The value to add to the data position. * @returns number Data position before the increase. */ increaseDataPosition(value: number): number; /** * Generates the headers that are specific to the box type for use in rendering. * @internal */ renderBoxHeaders(): ByteVector[]; }