Fix VorbisComment.populateMediaMetadata key comparison to ignore case

Issue: androidx/media#876

#minor-release

PiperOrigin-RevId: 590215918
This commit is contained in:
ibaker 2023-12-12 08:40:09 -08:00 committed by Copybara-Service
parent 8e33fbd536
commit 5580b78b13
19 changed files with 31 additions and 24 deletions

View File

@ -74,6 +74,9 @@
`DefaultExtractorsFactory.setTextTrackTranscodingEnabled` `DefaultExtractorsFactory.setTextTrackTranscodingEnabled`
([#836](https://github.com/androidx/media/issues/836)). ([#836](https://github.com/androidx/media/issues/836)).
* Metadata: * Metadata:
* Fix bug where `MediaMetadata` was only populated from Vorbis comments
with upper-case keys
([#876](https://github.com/androidx/media/issues/876)).
* DRM: * DRM:
* Extend workaround for spurious ClearKey `https://default.url` license * Extend workaround for spurious ClearKey `https://default.url` license
URL to API 33+ (previously the workaround only applied on API 33 URL to API 33+ (previously the workaround only applied on API 33

View File

@ -23,6 +23,7 @@ import androidx.annotation.Nullable;
import androidx.media3.common.MediaMetadata; import androidx.media3.common.MediaMetadata;
import androidx.media3.common.Metadata; import androidx.media3.common.Metadata;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import com.google.common.base.Ascii;
/** /**
* @deprecated Use {@link androidx.media3.extractor.metadata.vorbis.VorbisComment} instead. * @deprecated Use {@link androidx.media3.extractor.metadata.vorbis.VorbisComment} instead.
@ -31,18 +32,21 @@ import androidx.media3.common.util.UnstableApi;
@UnstableApi @UnstableApi
public class VorbisComment implements Metadata.Entry { public class VorbisComment implements Metadata.Entry {
/** The key. */ /** The key in upper case, to ease case-insensitive comparisons. */
public final String key; public final String key;
/** The value. */ /** The value. */
public final String value; public final String value;
/** /**
* @param key The key. * Constructs an instance.
*
* @param key The key. Must be an ASCII string containing only characters between 0x20 and 0x7D
* (inclusive), excluding 0x3D ('=').
* @param value The value. * @param value The value.
*/ */
public VorbisComment(String key, String value) { public VorbisComment(String key, String value) {
this.key = key; this.key = Ascii.toUpperCase(key);
this.value = value; this.value = value;
} }

View File

@ -75,10 +75,10 @@ public final class FlacStreamMetadataTest {
assertThat(metadata.length()).isEqualTo(2); assertThat(metadata.length()).isEqualTo(2);
VorbisComment commentFrame = (VorbisComment) metadata.get(0); VorbisComment commentFrame = (VorbisComment) metadata.get(0);
assertThat(commentFrame.key).isEqualTo("Title"); assertThat(commentFrame.key).isEqualTo("TITLE");
assertThat(commentFrame.value).isEqualTo("Song"); assertThat(commentFrame.value).isEqualTo("Song");
commentFrame = (VorbisComment) metadata.get(1); commentFrame = (VorbisComment) metadata.get(1);
assertThat(commentFrame.key).isEqualTo("Artist"); assertThat(commentFrame.key).isEqualTo("ARTIST");
assertThat(commentFrame.value).isEqualTo("Singer"); assertThat(commentFrame.value).isEqualTo("Singer");
} }
@ -124,7 +124,7 @@ public final class FlacStreamMetadataTest {
assertThat(metadata.length()).isEqualTo(1); assertThat(metadata.length()).isEqualTo(1);
VorbisComment commentFrame = (VorbisComment) metadata.get(0); VorbisComment commentFrame = (VorbisComment) metadata.get(0);
assertThat(commentFrame.key).isEqualTo("Title"); assertThat(commentFrame.key).isEqualTo("TITLE");
assertThat(commentFrame.value).isEqualTo("So=ng"); assertThat(commentFrame.value).isEqualTo("So=ng");
} }
@ -150,7 +150,7 @@ public final class FlacStreamMetadataTest {
assertThat(metadata.length()).isEqualTo(1); assertThat(metadata.length()).isEqualTo(1);
VorbisComment commentFrame = (VorbisComment) metadata.get(0); VorbisComment commentFrame = (VorbisComment) metadata.get(0);
assertThat(commentFrame.key).isEqualTo("Artist"); assertThat(commentFrame.key).isEqualTo("ARTIST");
assertThat(commentFrame.value).isEqualTo("Singer"); assertThat(commentFrame.value).isEqualTo("Singer");
} }
} }

View File

@ -54,9 +54,9 @@ public final class VorbisCommentTest {
List<Metadata.Entry> entries = List<Metadata.Entry> entries =
ImmutableList.of( ImmutableList.of(
new VorbisComment("TITLE", title), new VorbisComment("TITLE", title),
new VorbisComment("ARTIST", artist), new VorbisComment("ArTisT", artist),
new VorbisComment("ALBUM", albumTitle), new VorbisComment("ALBUM", albumTitle),
new VorbisComment("ALBUMARTIST", albumArtist), new VorbisComment("albumartist", albumArtist),
new VorbisComment("DESCRIPTION", description)); new VorbisComment("DESCRIPTION", description));
MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon(); MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();

View File

@ -13,7 +13,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C

View File

@ -13,7 +13,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C

View File

@ -13,7 +13,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C

View File

@ -13,7 +13,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C

View File

@ -10,7 +10,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C

View File

@ -13,7 +13,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C

View File

@ -13,7 +13,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C

View File

@ -13,7 +13,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C

View File

@ -13,7 +13,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C

View File

@ -10,7 +10,7 @@ track 0:
sampleMimeType = audio/opus sampleMimeType = audio/opus
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
metadata = entries=[VC: encoder=Lavf54.20.4] metadata = entries=[VC: ENCODER=Lavf54.20.4]
initializationData: initializationData:
data = length 19, hash BFE794DB data = length 19, hash BFE794DB
data = length 8, hash CA22068C data = length 8, hash CA22068C