mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
Add capture policy option to AudioAttributes
PiperOrigin-RevId: 268035329
This commit is contained in:
parent
e21467f653
commit
73b922ee59
3 changed files with 58 additions and 16 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
### 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
|
||||
to an HTTP source. `DefaultHttpDataSource`, `CronetDataSource` and
|
||||
`OkHttpDataSource` include headers set in the DataSpec when connecting to the
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2;
|
|||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaCodec;
|
||||
|
|
@ -440,6 +441,21 @@ public final class C {
|
|||
public static final int 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
|
||||
* #AUDIOFOCUS_GAIN_TRANSIENT}, {@link #AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK} or {@link
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.audio;
|
|||
import android.annotation.TargetApi;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
/**
|
||||
* Attributes for audio playback, which configure the underlying platform
|
||||
|
|
@ -42,17 +43,19 @@ public final class AudioAttributes {
|
|||
private @C.AudioContentType int contentType;
|
||||
private @C.AudioFlags int flags;
|
||||
private @C.AudioUsage int usage;
|
||||
private @C.AudioAllowedCapturePolicy int allowedCapturePolicy;
|
||||
|
||||
/**
|
||||
* Creates a new builder for {@link AudioAttributes}.
|
||||
* <p>
|
||||
* By default the content type is {@link C#CONTENT_TYPE_UNKNOWN}, usage is
|
||||
* {@link C#USAGE_MEDIA}, and no flags are set.
|
||||
*
|
||||
* <p>By default the content type is {@link C#CONTENT_TYPE_UNKNOWN}, usage is {@link
|
||||
* C#USAGE_MEDIA}, capture policy is {@link C#ALLOW_CAPTURE_BY_ALL} and no flags are set.
|
||||
*/
|
||||
public Builder() {
|
||||
contentType = C.CONTENT_TYPE_UNKNOWN;
|
||||
flags = 0;
|
||||
usage = C.USAGE_MEDIA;
|
||||
allowedCapturePolicy = C.ALLOW_CAPTURE_BY_ALL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -79,11 +82,15 @@ public final class AudioAttributes {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link AudioAttributes} instance from this builder.
|
||||
*/
|
||||
/** See {@link android.media.AudioAttributes.Builder#setAllowedCapturePolicy(int)}. */
|
||||
public Builder setAllowedCapturePolicy(@C.AudioAllowedCapturePolicy int allowedCapturePolicy) {
|
||||
this.allowedCapturePolicy = allowedCapturePolicy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Creates an {@link AudioAttributes} instance from this builder. */
|
||||
public AudioAttributes build() {
|
||||
return new AudioAttributes(contentType, flags, usage);
|
||||
return new AudioAttributes(contentType, flags, usage, allowedCapturePolicy);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -91,24 +98,38 @@ public final class AudioAttributes {
|
|||
public final @C.AudioContentType int contentType;
|
||||
public final @C.AudioFlags int flags;
|
||||
public final @C.AudioUsage int usage;
|
||||
public final @C.AudioAllowedCapturePolicy int allowedCapturePolicy;
|
||||
|
||||
@Nullable private android.media.AudioAttributes audioAttributesV21;
|
||||
|
||||
private AudioAttributes(@C.AudioContentType int contentType, @C.AudioFlags int flags,
|
||||
@C.AudioUsage int usage) {
|
||||
private AudioAttributes(
|
||||
@C.AudioContentType int contentType,
|
||||
@C.AudioFlags int flags,
|
||||
@C.AudioUsage int usage,
|
||||
@C.AudioAllowedCapturePolicy int allowedCapturePolicy) {
|
||||
this.contentType = contentType;
|
||||
this.flags = flags;
|
||||
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)
|
||||
public android.media.AudioAttributes getAudioAttributesV21() {
|
||||
if (audioAttributesV21 == null) {
|
||||
audioAttributesV21 = new android.media.AudioAttributes.Builder()
|
||||
.setContentType(contentType)
|
||||
.setFlags(flags)
|
||||
.setUsage(usage)
|
||||
.build();
|
||||
android.media.AudioAttributes.Builder builder =
|
||||
new android.media.AudioAttributes.Builder()
|
||||
.setContentType(contentType)
|
||||
.setFlags(flags)
|
||||
.setUsage(usage);
|
||||
if (Util.SDK_INT >= 29) {
|
||||
builder.setAllowedCapturePolicy(allowedCapturePolicy);
|
||||
}
|
||||
audioAttributesV21 = builder.build();
|
||||
}
|
||||
return audioAttributesV21;
|
||||
}
|
||||
|
|
@ -122,8 +143,10 @@ public final class AudioAttributes {
|
|||
return false;
|
||||
}
|
||||
AudioAttributes other = (AudioAttributes) obj;
|
||||
return this.contentType == other.contentType && this.flags == other.flags
|
||||
&& this.usage == other.usage;
|
||||
return this.contentType == other.contentType
|
||||
&& this.flags == other.flags
|
||||
&& this.usage == other.usage
|
||||
&& this.allowedCapturePolicy == other.allowedCapturePolicy;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -132,6 +155,7 @@ public final class AudioAttributes {
|
|||
result = 31 * result + contentType;
|
||||
result = 31 * result + flags;
|
||||
result = 31 * result + usage;
|
||||
result = 31 * result + allowedCapturePolicy;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue