# PsshAtomUtil

Artifact: [androidx.media3:media3-extractor](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/extractor/mp4/PsshAtomUtil.java+class:androidx.media3.extractor.mp4.PsshAtomUtil)

*** ** * ** ***


```
@UnstableApi
public final class PsshAtomUtil
```

<br />

*** ** * ** ***

Utility methods for handling PSSH atoms.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/extractor/mp4/PsshAtomUtil.PsshAtom` A class representing the mp4 PSSH Atom as specified in ISO/IEC 23001-7. |

| ### Public methods |
|---|---|
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/PsshAtomUtil#buildPsshAtom(java.util.UUID,byte[])(https://developer.android.com/reference/java/util/UUID.html systemId, @https://developer.android.com/reference/androidx/annotation/Nullable byte[] data)` Builds a version 0 PSSH atom for a given system id, containing the given data. |
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/PsshAtomUtil#buildPsshAtom(java.util.UUID,java.util.UUID[],byte[])(https://developer.android.com/reference/java/util/UUID.html systemId, @https://developer.android.com/reference/androidx/annotation/Nullable UUID[] keyIds, @https://developer.android.com/reference/androidx/annotation/Nullable byte[] data)` Builds a PSSH atom for the given system id, containing the given key ids and data. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/PsshAtomUtil#isPsshAtom(byte[])(byte[] data)` Returns whether the data is a valid PSSH atom. |
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/mp4/PsshAtomUtil.PsshAtom` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/PsshAtomUtil#parsePsshAtom(byte[])(byte[] atom)` Parses a PSSH atom. |
| `static @https://developer.android.com/reference/androidx/annotation/Nullable byte[]` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/PsshAtomUtil#parseSchemeSpecificData(byte[],java.util.UUID)(byte[] atom, https://developer.android.com/reference/java/util/UUID.html uuid)` Parses the scheme specific data from a PSSH atom. |
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/UUID.html` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/PsshAtomUtil#parseUuid(byte[])(byte[] atom)` Parses the UUID from a PSSH atom. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/PsshAtomUtil#parseVersion(byte[])(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 |
|---|---|
| `https://developer.android.com/reference/java/util/UUID.html systemId` | The system id of the scheme. |
| `@https://developer.android.com/reference/androidx/annotation/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 |
|---|---|
| `https://developer.android.com/reference/java/util/UUID.html systemId` | The system id of the scheme. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable UUID[] keyIds` | The key ids for a version 1 PSSH atom, or null for a version 0 PSSH atom. |
| `@https://developer.android.com/reference/androidx/annotation/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/mp4/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. |
| `https://developer.android.com/reference/java/util/UUID.html uuid` | The required UUID of the PSSH atom, or null to accept any UUID. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/UUID.html` | 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. |