Commit 9b4a3701 by olly Committed by Oliver Woodman

Clean up ExoMediaDrm reference counting documentation

PiperOrigin-RevId: 280106092
parent 20ab0510
...@@ -31,6 +31,16 @@ import java.util.UUID; ...@@ -31,6 +31,16 @@ import java.util.UUID;
/** /**
* Used to obtain keys for decrypting protected media streams. See {@link android.media.MediaDrm}. * Used to obtain keys for decrypting protected media streams. See {@link android.media.MediaDrm}.
*
* <h3>Reference counting</h3>
*
* <p>Access to an instance is managed by reference counting, where {@link #acquire()} increments
* the reference count and {@link #release()} decrements it. When the reference count drops to 0
* underlying resources are released, and the instance cannot be re-used.
*
* <p>Each new instance has an initial reference count of 1. Hence application code that creates a
* new instance does not normally need to call {@link #acquire()}, and must call {@link #release()}
* when the instance is no longer required.
*/ */
public interface ExoMediaDrm<T extends ExoMediaCrypto> { public interface ExoMediaDrm<T extends ExoMediaCrypto> {
...@@ -38,26 +48,25 @@ public interface ExoMediaDrm<T extends ExoMediaCrypto> { ...@@ -38,26 +48,25 @@ public interface ExoMediaDrm<T extends ExoMediaCrypto> {
interface Provider<T extends ExoMediaCrypto> { interface Provider<T extends ExoMediaCrypto> {
/** /**
* Returns an {@link ExoMediaDrm} instance with acquired ownership for the DRM scheme identified * Returns an {@link ExoMediaDrm} instance with an incremented reference count. When the caller
* by the given UUID. * no longer needs to use the instance, it must call {@link ExoMediaDrm#release()} to decrement
* * the reference count.
* <p>Each call to this method must have a corresponding call to {@link ExoMediaDrm#release()}
* to ensure correct resource management.
*/ */
ExoMediaDrm<T> acquireExoMediaDrm(UUID uuid); ExoMediaDrm<T> acquireExoMediaDrm(UUID uuid);
} }
/** /**
* {@link Provider} implementation which provides an {@link ExoMediaDrm} instance owned by the * Provides an {@link ExoMediaDrm} instance owned by the app.
* app.
* *
* <p>This provider should be used to manually handle {@link ExoMediaDrm} resources. * <p>Note that when using this provider the app will have instantiated the {@link ExoMediaDrm}
* instance, and remains responsible for calling {@link ExoMediaDrm#release()} on the instance
* when it's no longer being used.
*/ */
final class AppManagedProvider<T extends ExoMediaCrypto> implements Provider<T> { final class AppManagedProvider<T extends ExoMediaCrypto> implements Provider<T> {
private final ExoMediaDrm<T> exoMediaDrm; private final ExoMediaDrm<T> exoMediaDrm;
/** Creates an instance, which provides the given {@link ExoMediaDrm}. */ /** Creates an instance that provides the given {@link ExoMediaDrm}. */
public AppManagedProvider(ExoMediaDrm<T> exoMediaDrm) { public AppManagedProvider(ExoMediaDrm<T> exoMediaDrm) {
this.exoMediaDrm = exoMediaDrm; this.exoMediaDrm = exoMediaDrm;
} }
...@@ -269,17 +278,17 @@ public interface ExoMediaDrm<T extends ExoMediaCrypto> { ...@@ -269,17 +278,17 @@ public interface ExoMediaDrm<T extends ExoMediaCrypto> {
Map<String, String> queryKeyStatus(byte[] sessionId); Map<String, String> queryKeyStatus(byte[] sessionId);
/** /**
* Acquires ownership over this instance, which must be released by calling {@link #release()}. * Increments the reference count. When the caller no longer needs to use the instance, it must
* call {@link #release()} to decrement the reference count.
*
* <p>A new instance will have an initial reference count of 1, and therefore it is not normally
* necessary for application code to call this method.
*/ */
void acquire(); void acquire();
/** /**
* Releases ownership of this instance. If a call to this method causes this instance to have no * Decrements the reference count. If the reference count drops to 0 underlying resources are
* acquired ownerships, releases the underlying resources. * released, and the instance cannot be re-used.
*
* <p>Callers of this method must not make any further use of this instance.
*
* @see MediaDrm#release()
*/ */
void release(); void release();
......
...@@ -55,8 +55,6 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto ...@@ -55,8 +55,6 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto
* {@link ExoMediaDrm.Provider} that returns a new {@link FrameworkMediaDrm} for the requested * {@link ExoMediaDrm.Provider} that returns a new {@link FrameworkMediaDrm} for the requested
* UUID. Returns a {@link DummyExoMediaDrm} if the protection scheme identified by the given UUID * UUID. Returns a {@link DummyExoMediaDrm} if the protection scheme identified by the given UUID
* is not supported by the device. * is not supported by the device.
*
* <p>This provider should be used to make ExoPlayer handle {@link ExoMediaDrm} resources.
*/ */
public static final Provider<FrameworkMediaCrypto> DEFAULT_PROVIDER = public static final Provider<FrameworkMediaCrypto> DEFAULT_PROVIDER =
uuid -> { uuid -> {
...@@ -78,8 +76,8 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto ...@@ -78,8 +76,8 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto
private int referenceCount; private int referenceCount;
/** /**
* Creates an instance with an {@link #acquire() acquired reference} for the specified scheme * Creates an instance with an initial reference count of 1. {@link #release()} must be called on
* UUID. {@link #release()} must be called when the instance is no longer required. * the instance when it's no longer required.
* *
* @param uuid The scheme uuid. * @param uuid The scheme uuid.
* @return The created instance. * @return The created instance.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment