Commit 73b922ee by kimvde Committed by Oliver Woodman

Add capture policy option to AudioAttributes

PiperOrigin-RevId: 268035329
parent e21467f6
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
### dev-v2 (not yet released) ### ### dev-v2 (not yet released) ###
* Add `allowedCapturePolicy` field to `AudioAttributes` wrapper to allow to
opt-out of audio recording.
* Add `DataSpec.httpRequestHeaders` to set HTTP request headers when connecting * Add `DataSpec.httpRequestHeaders` to set HTTP request headers when connecting
to an HTTP source. `DefaultHttpDataSource`, `CronetDataSource` and to an HTTP source. `DefaultHttpDataSource`, `CronetDataSource` and
`OkHttpDataSource` include headers set in the DataSpec when connecting to the `OkHttpDataSource` include headers set in the DataSpec when connecting to the
......
...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2; ...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioFormat; import android.media.AudioFormat;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.MediaCodec; import android.media.MediaCodec;
...@@ -441,6 +442,21 @@ public final class C { ...@@ -441,6 +442,21 @@ public final class C {
android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING; android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING;
/** /**
* Capture policies for {@link com.google.android.exoplayer2.audio.AudioAttributes}. One of {@link
* #ALLOW_CAPTURE_BY_ALL}, {@link #ALLOW_CAPTURE_BY_NONE} or {@link #ALLOW_CAPTURE_BY_SYSTEM}.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef({ALLOW_CAPTURE_BY_ALL, ALLOW_CAPTURE_BY_NONE, ALLOW_CAPTURE_BY_SYSTEM})
public @interface AudioAllowedCapturePolicy {}
/** See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_ALL}. */
public static final int ALLOW_CAPTURE_BY_ALL = AudioAttributes.ALLOW_CAPTURE_BY_ALL;
/** See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_NONE}. */
public static final int ALLOW_CAPTURE_BY_NONE = AudioAttributes.ALLOW_CAPTURE_BY_NONE;
/** See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_SYSTEM}. */
public static final int ALLOW_CAPTURE_BY_SYSTEM = AudioAttributes.ALLOW_CAPTURE_BY_SYSTEM;
/**
* Audio focus types. One of {@link #AUDIOFOCUS_NONE}, {@link #AUDIOFOCUS_GAIN}, {@link * Audio focus types. One of {@link #AUDIOFOCUS_NONE}, {@link #AUDIOFOCUS_GAIN}, {@link
* #AUDIOFOCUS_GAIN_TRANSIENT}, {@link #AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK} or {@link * #AUDIOFOCUS_GAIN_TRANSIENT}, {@link #AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK} or {@link
* #AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}. * #AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}.
......
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.audio; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.audio;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.Util;
/** /**
* Attributes for audio playback, which configure the underlying platform * Attributes for audio playback, which configure the underlying platform
...@@ -42,17 +43,19 @@ public final class AudioAttributes { ...@@ -42,17 +43,19 @@ public final class AudioAttributes {
private @C.AudioContentType int contentType; private @C.AudioContentType int contentType;
private @C.AudioFlags int flags; private @C.AudioFlags int flags;
private @C.AudioUsage int usage; private @C.AudioUsage int usage;
private @C.AudioAllowedCapturePolicy int allowedCapturePolicy;
/** /**
* Creates a new builder for {@link AudioAttributes}. * Creates a new builder for {@link AudioAttributes}.
* <p> *
* By default the content type is {@link C#CONTENT_TYPE_UNKNOWN}, usage is * <p>By default the content type is {@link C#CONTENT_TYPE_UNKNOWN}, usage is {@link
* {@link C#USAGE_MEDIA}, and no flags are set. * C#USAGE_MEDIA}, capture policy is {@link C#ALLOW_CAPTURE_BY_ALL} and no flags are set.
*/ */
public Builder() { public Builder() {
contentType = C.CONTENT_TYPE_UNKNOWN; contentType = C.CONTENT_TYPE_UNKNOWN;
flags = 0; flags = 0;
usage = C.USAGE_MEDIA; usage = C.USAGE_MEDIA;
allowedCapturePolicy = C.ALLOW_CAPTURE_BY_ALL;
} }
/** /**
...@@ -79,11 +82,15 @@ public final class AudioAttributes { ...@@ -79,11 +82,15 @@ public final class AudioAttributes {
return this; return this;
} }
/** /** See {@link android.media.AudioAttributes.Builder#setAllowedCapturePolicy(int)}. */
* Creates an {@link AudioAttributes} instance from this builder. public Builder setAllowedCapturePolicy(@C.AudioAllowedCapturePolicy int allowedCapturePolicy) {
*/ this.allowedCapturePolicy = allowedCapturePolicy;
return this;
}
/** Creates an {@link AudioAttributes} instance from this builder. */
public AudioAttributes build() { public AudioAttributes build() {
return new AudioAttributes(contentType, flags, usage); return new AudioAttributes(contentType, flags, usage, allowedCapturePolicy);
} }
} }
...@@ -91,24 +98,38 @@ public final class AudioAttributes { ...@@ -91,24 +98,38 @@ public final class AudioAttributes {
public final @C.AudioContentType int contentType; public final @C.AudioContentType int contentType;
public final @C.AudioFlags int flags; public final @C.AudioFlags int flags;
public final @C.AudioUsage int usage; public final @C.AudioUsage int usage;
public final @C.AudioAllowedCapturePolicy int allowedCapturePolicy;
@Nullable private android.media.AudioAttributes audioAttributesV21; @Nullable private android.media.AudioAttributes audioAttributesV21;
private AudioAttributes(@C.AudioContentType int contentType, @C.AudioFlags int flags, private AudioAttributes(
@C.AudioUsage int usage) { @C.AudioContentType int contentType,
@C.AudioFlags int flags,
@C.AudioUsage int usage,
@C.AudioAllowedCapturePolicy int allowedCapturePolicy) {
this.contentType = contentType; this.contentType = contentType;
this.flags = flags; this.flags = flags;
this.usage = usage; this.usage = usage;
this.allowedCapturePolicy = allowedCapturePolicy;
} }
/**
* Returns a {@link android.media.AudioAttributes} from this instance.
*
* <p>Field {@link AudioAttributes#allowedCapturePolicy} is ignored for API levels prior to 29.
*/
@TargetApi(21) @TargetApi(21)
public android.media.AudioAttributes getAudioAttributesV21() { public android.media.AudioAttributes getAudioAttributesV21() {
if (audioAttributesV21 == null) { if (audioAttributesV21 == null) {
audioAttributesV21 = new android.media.AudioAttributes.Builder() android.media.AudioAttributes.Builder builder =
new android.media.AudioAttributes.Builder()
.setContentType(contentType) .setContentType(contentType)
.setFlags(flags) .setFlags(flags)
.setUsage(usage) .setUsage(usage);
.build(); if (Util.SDK_INT >= 29) {
builder.setAllowedCapturePolicy(allowedCapturePolicy);
}
audioAttributesV21 = builder.build();
} }
return audioAttributesV21; return audioAttributesV21;
} }
...@@ -122,8 +143,10 @@ public final class AudioAttributes { ...@@ -122,8 +143,10 @@ public final class AudioAttributes {
return false; return false;
} }
AudioAttributes other = (AudioAttributes) obj; AudioAttributes other = (AudioAttributes) obj;
return this.contentType == other.contentType && this.flags == other.flags return this.contentType == other.contentType
&& this.usage == other.usage; && this.flags == other.flags
&& this.usage == other.usage
&& this.allowedCapturePolicy == other.allowedCapturePolicy;
} }
@Override @Override
...@@ -132,6 +155,7 @@ public final class AudioAttributes { ...@@ -132,6 +155,7 @@ public final class AudioAttributes {
result = 31 * result + contentType; result = 31 * result + contentType;
result = 31 * result + flags; result = 31 * result + flags;
result = 31 * result + usage; result = 31 * result + usage;
result = 31 * result + allowedCapturePolicy;
return result; return result;
} }
......
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