Merge "AudioMetadata: Translate KEY_ATMOS_PRESENT for JNI" into rvc-dev am: 65c14feec9 am: ad914e2c08 am: 13047d0bf6

Change-Id: Ib82b8f5aaa08153a9ef7ff0055f17612ab8dce9d
This commit is contained in:
Andy Hung
2020-05-07 04:27:36 +00:00
committed by Automerger Merge Worker

View File

@@ -166,9 +166,24 @@ public final class AudioMetadata {
*
* A Boolean value which is true if Atmos is present in an E-AC3 stream.
*/
// Since Boolean isn't handled by Parceling, we translate
// internally to KEY_HAS_ATMOS when sending through JNI.
// Consider deprecating this key for KEY_HAS_ATMOS in the future.
//
@NonNull public static final Key<Boolean> KEY_ATMOS_PRESENT =
createKey("atmos-present", Boolean.class);
/**
* A key representing the presence of Atmos in an E-AC3 stream.
*
* An Integer value which is nonzero if Atmos is present in an E-AC3 stream.
* The integer representation is used for communication to the native side.
* @hide
*/
@NonNull public static final Key<Integer> KEY_HAS_ATMOS =
createKey("has-atmos", Integer.class);
/**
* A key representing the audio encoding used for the stream.
* This is the same encoding used in {@link AudioFormat#getEncoding()}.
@@ -731,6 +746,15 @@ public final class AudioMetadata {
Log.e(TAG, "Failed to unpack value for map");
return null;
}
// Special handling of KEY_ATMOS_PRESENT.
if (key.equals(Format.KEY_HAS_ATMOS.getName())
&& value.first == Format.KEY_HAS_ATMOS.getValueClass()) {
ret.set(Format.KEY_ATMOS_PRESENT,
(Boolean) ((int) value.second != 0)); // Translate Integer to Boolean
continue; // Should we store both keys in the java table?
}
ret.set(createKey(key, value.first), value.first.cast(value.second));
}
return ret;
@@ -746,11 +770,19 @@ public final class AudioMetadata {
return false;
}
for (Key<?> key : obj.keySet()) {
Object value = obj.get(key);
// Special handling of KEY_ATMOS_PRESENT.
if (key == Format.KEY_ATMOS_PRESENT) {
key = Format.KEY_HAS_ATMOS;
value = (Integer) ((boolean) value ? 1 : 0); // Translate Boolean to Integer
}
if (!strDataPackage.pack(output, key.getName())) {
Log.i(TAG, "Failed to pack key: " + key.getName());
return false;
}
if (!OBJECT_PACKAGE.pack(output, new Pair<>(key.getValueClass(), obj.get(key)))) {
if (!OBJECT_PACKAGE.pack(output, new Pair<>(key.getValueClass(), value))) {
Log.i(TAG, "Failed to pack value: " + obj.get(key));
return false;
}