media-stream-library
Version:
Media stream library for Node & the Web.
150 lines (149 loc) • 4.89 kB
TypeScript
import { MediaTrack } from '../../../utils/protocols/isom';
type BufferMutation = (buffer: Buffer, offset: number) => void;
declare abstract class BoxElement {
byteLength: number;
value: any;
abstract copy(buffer: Buffer, offset: number): void;
abstract load(buffer: Buffer, offset: number): void;
constructor(size: number);
}
/**
* Box class.
*
* Defines a box as an entity similar to a C struct, where the struct is
* represented by a Map of elements.
* Each element is an object with at least:
* - a 'byteLength' property (size of element in bytes)
* - a 'copy' method (BufferMutation signature)
*/
export declare class Box extends BoxElement {
type: string;
config: {
[key: string]: any;
};
struct: Map<string, {
offset: number;
element: {
value?: any;
byteLength: number;
copy: BufferMutation;
load?: BufferMutation;
format?: (indent?: number) => string;
};
}>;
/**
* Create a new Box.
* @param type 4-character ASCII string
* @param config Configuration holding (key: value) fields
*/
constructor(type: string, config?: {
[key: string]: any;
});
/**
* Get access to an element based on it's name.
* @param key The element's name
* @return Object with 'byteLength' property and 'copy' method
*/
element(key: string): {
value?: any;
byteLength: number;
copy: BufferMutation;
load?: BufferMutation;
format?: (indent?: number) => string;
};
/**
* Set an element's value.
* @param key The element's name
* @param value The element's (new) value
*/
set(key: string, value: any): void;
/**
* Get an element's value.
* @param key The element's name
* @return The element's value
*/
get(key: string): any;
/**
* Get an element's offset.
* @param key The element's name
* @return The element's offset
*/
offset(key: string): number;
/**
* Check if a certain element exists
* @param key The element's name
* @return true if the element is known, false if not
*/
has(key: string): boolean;
/**
* Add a new element to the box.
* @param key A _new_ non-existing element name.
* @param element Something with a 'byteLength' property and 'copy' method.
* @return this box, so that 'add' can be used in a chain
*/
add(key: string, element: BoxElement | Buffer): this;
/**
* Create a buffer and copy all element values to it.
* @return Data representing the box.
*/
buffer(): Buffer;
/**
* Copy all values of the box into an existing buffer.
* @param buffer The target buffer to accept the box data
* @param [offset=0] The number of bytes into the target to start at.
*/
copy(buffer: Buffer, offset?: number): void;
/**
* Read element values from a box's data representation.
* @param buffer The source buffer with box data
* @param [offset=0] The number of bytes into the source to start at.
*/
load(buffer: Buffer, offset?: number): void;
/**
* Pretty-format an entire box as an element/box hierarchy.
* @param [indent=0] How large an indentation to use for the hierarchy
*/
format(indent?: number): string;
/**
* Pretty-print an entire box as an element/box hierarchy.
* @param [indent=0] How large an indentation to use for the hierarchy
*/
print(indent: number): void;
}
/**
* Container class
*
* special box with an 'add' method which allows appending of other boxes,
* and a 'parse' method to extract contained boxes.
*/
export declare class Container extends Box {
boxSize: number;
/**
* Create a new container box
* @param type 4-character ASCII string
* @param config Configuration holding (key: value) fields
* @param boxes One or more boxes to append.
*/
constructor(type: string, config?: {
[key: string]: any;
}, ...boxes: Box[]);
/**
* Add one or more boxes to the container.
* @param boxes The box(es) to append
* @return this container, so that add can be used in a chain
*/
append(...boxes: Box[]): this;
/**
* Parse a container box by looking for boxes that it contains, and
* recursively proceed when it is another container.
*
* FIXME: this cannot properly handle different versions of the FullBox,
* currenlty the loader is hardcoded to the version used in this file.
* Also, appearance of an esds box is assumed to be AAC audio information,
* while the avcC box signals H.264 video information.
*
* @param data The data to parse.
*/
parse(data: Buffer): MediaTrack[];
}
export {};