@UnstableApi
public final class PsshAtomUtil


Utility methods for handling PSSH atoms.

Summary

Nested types

public final class PsshAtomUtil.PsshAtom

A class representing the mp4 PSSH Atom as specified in ISO/IEC 23001-7.

Public methods

static byte[]
buildPsshAtom(UUID systemId, @Nullable byte[] data)

Builds a version 0 PSSH atom for a given system id, containing the given data.

static byte[]
buildPsshAtom(UUID systemId, @Nullable UUID[] keyIds, @Nullable byte[] data)

Builds a PSSH atom for the given system id, containing the given key ids and data.

static boolean
isPsshAtom(byte[] data)

Returns whether the data is a valid PSSH atom.

static @Nullable PsshAtomUtil.PsshAtom
parsePsshAtom(byte[] atom)

Parses a PSSH atom.

static @Nullable byte[]
parseSchemeSpecificData(byte[] atom, UUID uuid)

Parses the scheme specific data from a PSSH atom.

static @Nullable UUID
parseUuid(byte[] atom)

Parses the UUID from a PSSH atom.

static int
parseVersion(byte[] atom)

Parses the version from a PSSH atom.

Public methods

buildPsshAtom

public static byte[] buildPsshAtom(UUID systemId, @Nullable byte[] data)

Builds a version 0 PSSH atom for a given system id, containing the given data.

Parameters
UUID systemId

The system id of the scheme.

@Nullable byte[] data

The scheme specific data.

Returns
byte[]

The PSSH atom.

buildPsshAtom

public static byte[] buildPsshAtom(UUID systemId, @Nullable UUID[] keyIds, @Nullable byte[] data)

Builds a PSSH atom for the given system id, containing the given key ids and data.

Parameters
UUID systemId

The system id of the scheme.

@Nullable UUID[] keyIds

The key ids for a version 1 PSSH atom, or null for a version 0 PSSH atom.

@Nullable byte[] data

The scheme specific data.

Returns
byte[]

The PSSH atom.

isPsshAtom

public static boolean isPsshAtom(byte[] data)

Returns whether the data is a valid PSSH atom.

Parameters
byte[] data

The data to parse.

Returns
boolean

Whether the data is a valid PSSH atom.

parsePsshAtom

public static @Nullable PsshAtomUtil.PsshAtom parsePsshAtom(byte[] atom)

Parses a PSSH atom. Version 0 and 1 PSSH atoms are supported.

Parameters
byte[] atom

The atom to parse.

Returns
@Nullable PsshAtomUtil.PsshAtom

The parsed PSSH atom. Null if the input is not a valid PSSH atom, or if the PSSH atom has an unsupported version.

parseSchemeSpecificData

public static @Nullable byte[] parseSchemeSpecificData(byte[] atom, UUID uuid)

Parses the scheme specific data from a PSSH atom. Version 0 and 1 PSSH atoms are supported.

The scheme specific data is only parsed if the data is a valid PSSH atom matching the given UUID, or if the data is a valid PSSH atom of any type in the case that the passed UUID is null.

Parameters
byte[] atom

The atom to parse.

UUID uuid

The required UUID of the PSSH atom, or null to accept any UUID.

Returns
@Nullable byte[]

The parsed scheme specific data. Null if the input is not a valid PSSH atom, or if the PSSH atom has an unsupported version, or if the PSSH atom does not match the passed UUID.

parseUuid

public static @Nullable UUID parseUuid(byte[] atom)

Parses the UUID from a PSSH atom. Version 0 and 1 PSSH atoms are supported.

The UUID is only parsed if the data is a valid PSSH atom.

Parameters
byte[] atom

The atom to parse.

Returns
@Nullable UUID

The parsed UUID. Null if the input is not a valid PSSH atom, or if the PSSH atom has an unsupported version.

parseVersion

public static int parseVersion(byte[] atom)

Parses the version from a PSSH atom. Version 0 and 1 PSSH atoms are supported.

The version is only parsed if the data is a valid PSSH atom.

Parameters
byte[] atom

The atom to parse.

Returns
int

The parsed version. -1 if the input is not a valid PSSH atom, or if the PSSH atom has an unsupported version.