|
| 1 | +/* |
| 2 | + * Copyright 2025 The Android Open Source Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
1 | 16 | package androidx.media3.common; |
2 | 17 |
|
3 | 18 | import static java.lang.annotation.ElementType.TYPE_USE; |
4 | 19 |
|
5 | 20 | import android.media.MediaFormat; |
6 | 21 | import android.os.Build; |
7 | | - |
8 | 22 | import androidx.annotation.IntDef; |
9 | 23 | import androidx.annotation.Nullable; |
10 | 24 | import androidx.annotation.RequiresApi; |
11 | | - |
| 25 | +import androidx.media3.common.util.UnstableApi; |
12 | 26 | import java.lang.annotation.Documented; |
13 | 27 | import java.lang.annotation.Retention; |
14 | 28 | import java.lang.annotation.RetentionPolicy; |
15 | 29 | import java.lang.annotation.Target; |
16 | 30 |
|
17 | 31 | /** |
18 | | - * A {@link CodecParameter} holds the key, value and the value type for signalling a parameter change to a |
19 | | - * decoder. The key can be an arbitrary string which must be known by the decoder instance. |
| 32 | + * A parameter for configuring an underlying {@link android.media.MediaCodec}. |
| 33 | + * |
| 34 | + * <p>The key must be a key that is understood by the underlying decoder instance. |
20 | 35 | */ |
21 | | -public class CodecParameter { |
22 | | - |
23 | | - private static final String TAG = "CodecParameter"; |
| 36 | +@UnstableApi |
| 37 | +public final class CodecParameter { |
24 | 38 |
|
25 | 39 | /** |
26 | | - * @see MediaFormat#KEY_AAC_DRC_ALBUM_MODE |
| 40 | + * Value types for a {@link CodecParameter}. One of {@link #TYPE_NULL}, {@link #TYPE_INT}, {@link |
| 41 | + * #TYPE_LONG}, {@link #TYPE_FLOAT}, {@link #TYPE_STRING} or {@link #TYPE_BYTE_BUFFER}. |
27 | 42 | */ |
28 | | - @RequiresApi(api = Build.VERSION_CODES.R) |
29 | | - public final static String KEY_AAC_DRC_ALBUM_MODE = MediaFormat.KEY_AAC_DRC_ALBUM_MODE; |
| 43 | + @Documented |
| 44 | + @Retention(RetentionPolicy.SOURCE) |
| 45 | + @Target(TYPE_USE) |
| 46 | + @IntDef({TYPE_NULL, TYPE_INT, TYPE_LONG, TYPE_FLOAT, TYPE_STRING, TYPE_BYTE_BUFFER}) |
| 47 | + public @interface ValueType {} |
30 | 48 |
|
31 | 49 | /** |
32 | | - * @see MediaFormat#KEY_AAC_DRC_ATTENUATION_FACTOR |
| 50 | + * @see MediaFormat#TYPE_NULL |
33 | 51 | */ |
34 | | - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) |
35 | | - public final static String KEY_AAC_DRC_ATTENUATION_FACTOR = MediaFormat.KEY_AAC_DRC_ATTENUATION_FACTOR; |
| 52 | + public static final int TYPE_NULL = 0; |
36 | 53 |
|
37 | 54 | /** |
38 | | - * @see MediaFormat#KEY_AAC_DRC_BOOST_FACTOR |
| 55 | + * @see MediaFormat#TYPE_INTEGER |
39 | 56 | */ |
40 | | - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) |
41 | | - public final static String KEY_AAC_DRC_BOOST_FACTOR = MediaFormat.KEY_AAC_DRC_BOOST_FACTOR; |
| 57 | + public static final int TYPE_INT = 1; |
42 | 58 |
|
43 | 59 | /** |
44 | | - * @see MediaFormat#KEY_AAC_DRC_EFFECT_TYPE |
| 60 | + * @see MediaFormat#TYPE_LONG |
45 | 61 | */ |
46 | | - @RequiresApi(api = Build.VERSION_CODES.P) |
47 | | - public final static String KEY_AAC_DRC_EFFECT_TYPE = MediaFormat.KEY_AAC_DRC_EFFECT_TYPE; |
| 62 | + public static final int TYPE_LONG = 2; |
48 | 63 |
|
49 | 64 | /** |
50 | | - * @see MediaFormat#KEY_AAC_DRC_TARGET_REFERENCE_LEVEL |
| 65 | + * @see MediaFormat#TYPE_FLOAT |
51 | 66 | */ |
52 | | - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) |
53 | | - public final static String KEY_AAC_DRC_TARGET_REFERENCE_LEVEL = MediaFormat.KEY_AAC_DRC_TARGET_REFERENCE_LEVEL; |
| 67 | + public static final int TYPE_FLOAT = 3; |
54 | 68 |
|
55 | 69 | /** |
56 | | - * @see MediaFormat#KEY_AAC_DRC_OUTPUT_LOUDNESS |
| 70 | + * @see MediaFormat#TYPE_STRING |
57 | 71 | */ |
58 | | - @RequiresApi(api = Build.VERSION_CODES.R) |
59 | | - public final static String KEY_AAC_DRC_OUTPUT_LOUDNESS = MediaFormat.KEY_AAC_DRC_OUTPUT_LOUDNESS; |
60 | | - |
| 72 | + public static final int TYPE_STRING = 4; |
61 | 73 |
|
62 | 74 | /** |
63 | | - * Key to set the MPEG-H output mode. |
64 | | - * The corresponding value must be of value type {@link ValueType#VALUETYPE_INT}. |
65 | | - * Possible values are: |
66 | | - * 0 for PCM output (decoding the MPEG-H bitstream with a certain MPEG-H target layout CICP index) |
67 | | - * 1 for MPEG-H bitstream bypass (using IEC61937-13 with a sample rate factor of 4) |
68 | | - * 2 for MPEG-H bitstream bypass (using IEC61937-13 with a sample rate factor of 16) |
| 75 | + * @see MediaFormat#TYPE_BYTE_BUFFER |
69 | 76 | */ |
70 | | - public final static String KEY_MPEGH_OUTPUT_MODE = "mpegh-output-mode"; |
| 77 | + public static final int TYPE_BYTE_BUFFER = 5; |
71 | 78 |
|
72 | 79 | /** |
73 | | - * Key to set the MPEG-H target layout CICP index. |
74 | | - * The corresponding value must be of value type {@link ValueType#VALUETYPE_INT}. |
75 | | - * It must be set before decoder initialization. A change during runtime does not have any effect. |
76 | | - * Supported values are: 0, 1, 2, 6, 8, 10, 12 |
77 | | - * A value of 0 tells the decoder to create binauralized output. |
| 80 | + * @see MediaFormat#KEY_AAC_DRC_ALBUM_MODE |
78 | 81 | */ |
79 | | - public final static String KEY_MPEGH_TARGET_LAYOUT = "mpegh-target-layout"; |
| 82 | + @RequiresApi(api = Build.VERSION_CODES.R) |
| 83 | + public static final String KEY_AAC_DRC_ALBUM_MODE = MediaFormat.KEY_AAC_DRC_ALBUM_MODE; |
80 | 84 |
|
81 | 85 | /** |
82 | | - * Key to set the MPEG-H UI configuration. |
83 | | - * The corresponding value must be of value type {@link ValueType#VALUETYPE_STRING}. |
84 | | - * This key is returned from the MPEG-H UI manager. |
| 86 | + * @see MediaFormat#KEY_AAC_DRC_ATTENUATION_FACTOR |
85 | 87 | */ |
86 | | - public final static String KEY_MPEGH_UI_CONFIG = "mpegh-ui-config"; |
| 88 | + public static final String KEY_AAC_DRC_ATTENUATION_FACTOR = |
| 89 | + MediaFormat.KEY_AAC_DRC_ATTENUATION_FACTOR; |
87 | 90 |
|
88 | 91 | /** |
89 | | - * Key to set the MPEG-H UI command. |
90 | | - * The corresponding value must be of value type {@link ValueType#VALUETYPE_STRING}. |
91 | | - * This key is passed to the MPEG-H UI manager. |
| 92 | + * @see MediaFormat#KEY_AAC_DRC_BOOST_FACTOR |
92 | 93 | */ |
93 | | - public final static String KEY_MPEGH_UI_COMMAND = "mpegh-ui-command"; |
| 94 | + public static final String KEY_AAC_DRC_BOOST_FACTOR = MediaFormat.KEY_AAC_DRC_BOOST_FACTOR; |
94 | 95 |
|
95 | 96 | /** |
96 | | - * Key to set the MPEG-H UI persistence storage path. |
97 | | - * The corresponding value must be of value type {@link ValueType#VALUETYPE_STRING}. |
98 | | - * This key is passed to the MPEG-H UI manager. |
| 97 | + * @see MediaFormat#KEY_AAC_DRC_EFFECT_TYPE |
99 | 98 | */ |
100 | | - public final static String KEY_MPEGH_UI_PERSISTENCESTORAGE_PATH = "mpegh-ui-persistencestorage-path"; |
| 99 | + @RequiresApi(api = Build.VERSION_CODES.P) |
| 100 | + public static final String KEY_AAC_DRC_EFFECT_TYPE = MediaFormat.KEY_AAC_DRC_EFFECT_TYPE; |
101 | 101 |
|
102 | 102 | /** |
103 | | - * @see MediaFormat#TYPE_NULL |
| 103 | + * @see MediaFormat#KEY_AAC_DRC_TARGET_REFERENCE_LEVEL |
104 | 104 | */ |
105 | | - public static final int VALUETYPE_NULL = 0; // MediaFormat.TYPE_NULL; |
| 105 | + public static final String KEY_AAC_DRC_TARGET_REFERENCE_LEVEL = |
| 106 | + MediaFormat.KEY_AAC_DRC_TARGET_REFERENCE_LEVEL; |
| 107 | + |
106 | 108 | /** |
107 | | - * @see MediaFormat#TYPE_INTEGER |
| 109 | + * @see MediaFormat#KEY_AAC_DRC_OUTPUT_LOUDNESS |
108 | 110 | */ |
109 | | - public static final int VALUETYPE_INT = 1; // MediaFormat.TYPE_INTEGER; |
| 111 | + @RequiresApi(api = Build.VERSION_CODES.R) |
| 112 | + public static final String KEY_AAC_DRC_OUTPUT_LOUDNESS = MediaFormat.KEY_AAC_DRC_OUTPUT_LOUDNESS; |
| 113 | + |
110 | 114 | /** |
111 | | - * @see MediaFormat#TYPE_LONG |
| 115 | + * Key to set the MPEG-H output mode. The corresponding value must be of value type {@link |
| 116 | + * ValueType#TYPE_INT}. |
| 117 | + * |
| 118 | + * <p>Possible values are: |
| 119 | + * |
| 120 | + * <ul> |
| 121 | + * <li>0 for PCM output (decoding the MPEG-H bitstream with a certain MPEG-H target layout CICP |
| 122 | + * index) |
| 123 | + * <li>1 for MPEG-H bitstream bypass (using IEC61937-13 with a sample rate factor of 4) |
| 124 | + * <li>2 for MPEG-H bitstream bypass (using IEC61937-13 with a sample rate factor of 16) |
| 125 | + * </ul> |
112 | 126 | */ |
113 | | - public static final int VALUETYPE_LONG = 2; // MediaFormat.TYPE_LONG; |
| 127 | + public static final String KEY_MPEGH_OUTPUT_MODE = "mpegh-output-mode"; |
| 128 | + |
114 | 129 | /** |
115 | | - * @see MediaFormat#TYPE_FLOAT |
| 130 | + * Key to set the MPEG-H target layout CICP index. The corresponding value must be of value type |
| 131 | + * {@link ValueType#TYPE_INT}. It must be set before decoder initialization. A change during |
| 132 | + * runtime does not have any effect. |
| 133 | + * |
| 134 | + * <p>Supported values are: 0, 1, 2, 6, 8, 10, 12. A value of 0 tells the decoder to create |
| 135 | + * binauralized output. |
116 | 136 | */ |
117 | | - public static final int VALUETYPE_FLOAT = 3; // MediaFormat.TYPE_FLOAT; |
| 137 | + public static final String KEY_MPEGH_TARGET_LAYOUT = "mpegh-target-layout"; |
| 138 | + |
118 | 139 | /** |
119 | | - * @see MediaFormat#TYPE_STRING |
| 140 | + * Key to set the MPEG-H UI configuration. The corresponding value must be of value type {@link |
| 141 | + * ValueType#TYPE_STRING}. This key is returned from the MPEG-H UI manager. |
120 | 142 | */ |
121 | | - public static final int VALUETYPE_STRING = 4; // MediaFormat.TYPE_STRING; |
| 143 | + public static final String KEY_MPEGH_UI_CONFIG = "mpegh-ui-config"; |
| 144 | + |
122 | 145 | /** |
123 | | - * @see MediaFormat#TYPE_BYTE_BUFFER |
| 146 | + * Key to set the MPEG-H UI command. The corresponding value must be of value type {@link |
| 147 | + * ValueType#TYPE_STRING}. This key is passed to the MPEG-H UI manager. |
124 | 148 | */ |
125 | | - public static final int VALUETYPE_BYTE_BUFFER = 5; // MediaFormat.TYPE_BYTE_BUFFER; |
| 149 | + public static final String KEY_MPEGH_UI_COMMAND = "mpegh-ui-command"; |
126 | 150 |
|
127 | 151 | /** |
128 | | - * Value types for a {@link CodecParameter}. |
129 | | - * One of {@link #VALUETYPE_NULL}, {@link #VALUETYPE_INT}, {@link #VALUETYPE_LONG}, |
130 | | - * {@link #VALUETYPE_FLOAT}, {@link #VALUETYPE_STRING} or {@link #VALUETYPE_BYTE_BUFFER}. |
| 152 | + * Key to set the MPEG-H UI persistence storage path. The corresponding value must be of value |
| 153 | + * type {@link ValueType#TYPE_STRING}. This key is passed to the MPEG-H UI manager. |
131 | 154 | */ |
132 | | - @Documented |
133 | | - @Retention(RetentionPolicy.SOURCE) |
134 | | - @Target(TYPE_USE) |
135 | | - @IntDef({ |
136 | | - VALUETYPE_NULL, |
137 | | - VALUETYPE_INT, |
138 | | - VALUETYPE_LONG, |
139 | | - VALUETYPE_FLOAT, |
140 | | - VALUETYPE_STRING, |
141 | | - VALUETYPE_BYTE_BUFFER |
142 | | - }) |
143 | | - public @interface ValueType { |
144 | | - |
145 | | - } |
| 155 | + public static final String KEY_MPEGH_UI_PERSISTENCESTORAGE_PATH = |
| 156 | + "mpegh-ui-persistencestorage-path"; |
146 | 157 |
|
| 158 | + /** The key of the codec parameter. */ |
| 159 | + public final String key; |
147 | 160 |
|
148 | | - public String key; |
149 | | - public @Nullable Object value; |
150 | | - public @ValueType int valueType; |
| 161 | + /** The value of the codec parameter. */ |
| 162 | + public final @Nullable Object value; |
151 | 163 |
|
| 164 | + /** The {@link ValueType} of the value object. */ |
| 165 | + public final @ValueType int valueType; |
152 | 166 |
|
153 | 167 | /** |
154 | | - * Creates a new codec parameter. |
| 168 | + * Creates an instance. |
155 | 169 | * |
156 | | - * @param key A string holding the key of the codec parameter. |
157 | | - * @param value An object representing the value of the codec parameter. |
158 | | - * @param valueType The value type of the value object. |
| 170 | + * @param key The key of the codec parameter. |
| 171 | + * @param value The value of the codec parameter. |
| 172 | + * @param valueType The {@link ValueType} of the value object. |
159 | 173 | */ |
160 | 174 | public CodecParameter(String key, @Nullable Object value, @ValueType int valueType) { |
161 | 175 | this.key = key; |
|
0 commit comments