Merge pull request #710 from loki666:patch-2
PiperOrigin-RevId: 575817952
This commit is contained in:
commit
64d93eb0d1
@ -38,6 +38,8 @@
|
|||||||
* Smooth Streaming Extension:
|
* Smooth Streaming Extension:
|
||||||
* RTSP Extension:
|
* RTSP Extension:
|
||||||
* Decoder Extensions (FFmpeg, VP9, AV1, MIDI, etc.):
|
* Decoder Extensions (FFmpeg, VP9, AV1, MIDI, etc.):
|
||||||
|
* MIDI decoder: Ignore SysEx event messages
|
||||||
|
([#710](https://github.com/androidx/media/pull/710)).
|
||||||
* Leanback extension:
|
* Leanback extension:
|
||||||
* Cast Extension:
|
* Cast Extension:
|
||||||
* Test Utilities:
|
* Test Utilities:
|
||||||
|
@ -37,6 +37,8 @@ import androidx.media3.common.util.UnstableApi;
|
|||||||
public static final int DATA_FIELD_UNSET = Integer.MIN_VALUE;
|
public static final int DATA_FIELD_UNSET = Integer.MIN_VALUE;
|
||||||
|
|
||||||
private static final int TICKS_UNSET = -1;
|
private static final int TICKS_UNSET = -1;
|
||||||
|
private static final int SYSEX_BEGIN_STATUS = 0xF0;
|
||||||
|
private static final int SYSEX_END_STATUS = 0xF7;
|
||||||
private static final int META_EVENT_STATUS = 0xFF;
|
private static final int META_EVENT_STATUS = 0xFF;
|
||||||
private static final int META_END_OF_TRACK = 0x2F;
|
private static final int META_END_OF_TRACK = 0x2F;
|
||||||
private static final int META_TEMPO_CHANGE = 0x51;
|
private static final int META_TEMPO_CHANGE = 0x51;
|
||||||
@ -82,9 +84,40 @@ import androidx.media3.common.util.UnstableApi;
|
|||||||
int firstByte = parsableTrackEventBytes.readUnsignedByte();
|
int firstByte = parsableTrackEventBytes.readUnsignedByte();
|
||||||
eventDecoderSizeBytes = 1;
|
eventDecoderSizeBytes = 1;
|
||||||
|
|
||||||
if ((firstByte & 0xF0) != 0xF0) {
|
if (firstByte == SYSEX_BEGIN_STATUS) {
|
||||||
// Most significant nibble is not 0xF, this is a MIDI channel event.
|
// TODO(b/228838584): Handle this gracefully.
|
||||||
|
statusByte = firstByte;
|
||||||
|
|
||||||
|
int currentByte;
|
||||||
|
do { // Consume SysEx message.
|
||||||
|
currentByte = parsableTrackEventBytes.readUnsignedByte();
|
||||||
|
} while (currentByte != SYSEX_END_STATUS);
|
||||||
|
} else if (firstByte == META_EVENT_STATUS) { // This is a Meta event.
|
||||||
|
int metaEventMessageType = parsableTrackEventBytes.readUnsignedByte();
|
||||||
|
int eventLength = readVariableLengthInt(parsableTrackEventBytes);
|
||||||
|
|
||||||
|
statusByte = firstByte;
|
||||||
|
|
||||||
|
switch (metaEventMessageType) {
|
||||||
|
case META_TEMPO_CHANGE:
|
||||||
|
usPerQuarterNote = parsableTrackEventBytes.readUnsignedInt24();
|
||||||
|
|
||||||
|
if (usPerQuarterNote <= 0) {
|
||||||
|
throw ParserException.createForUnsupportedContainerFeature(
|
||||||
|
"Tempo event data value must be a non-zero positive value. Parsed value: "
|
||||||
|
+ usPerQuarterNote);
|
||||||
|
}
|
||||||
|
|
||||||
|
parsableTrackEventBytes.skipBytes(eventLength - /* tempoDataLength */ 3);
|
||||||
|
break;
|
||||||
|
case META_END_OF_TRACK:
|
||||||
|
parsableTrackEventBytes.setPosition(startingPosition);
|
||||||
|
reset();
|
||||||
|
return false;
|
||||||
|
default: // Ignore all other Meta events.
|
||||||
|
parsableTrackEventBytes.skipBytes(eventLength);
|
||||||
|
}
|
||||||
|
} else { // This is a MIDI channel event.
|
||||||
// Check for running status, an occurrence where the statusByte has been omitted from the
|
// Check for running status, an occurrence where the statusByte has been omitted from the
|
||||||
// bytes of this event. The standard expects us to assume that this command has the same
|
// bytes of this event. The standard expects us to assume that this command has the same
|
||||||
// statusByte as the last command.
|
// statusByte as the last command.
|
||||||
@ -113,37 +146,6 @@ import androidx.media3.common.util.UnstableApi;
|
|||||||
}
|
}
|
||||||
|
|
||||||
statusByte = firstByte;
|
statusByte = firstByte;
|
||||||
} else {
|
|
||||||
if (firstByte == META_EVENT_STATUS) { // This is a Meta event.
|
|
||||||
int metaEventMessageType = parsableTrackEventBytes.readUnsignedByte();
|
|
||||||
int eventLength = readVariableLengthInt(parsableTrackEventBytes);
|
|
||||||
|
|
||||||
statusByte = firstByte;
|
|
||||||
|
|
||||||
switch (metaEventMessageType) {
|
|
||||||
case META_TEMPO_CHANGE:
|
|
||||||
usPerQuarterNote = parsableTrackEventBytes.readUnsignedInt24();
|
|
||||||
|
|
||||||
if (usPerQuarterNote <= 0) {
|
|
||||||
throw ParserException.createForUnsupportedContainerFeature(
|
|
||||||
"Tempo event data value must be a non-zero positive value. Parsed value: "
|
|
||||||
+ usPerQuarterNote);
|
|
||||||
}
|
|
||||||
|
|
||||||
parsableTrackEventBytes.skipBytes(eventLength - /* tempoDataLength */ 3);
|
|
||||||
break;
|
|
||||||
case META_END_OF_TRACK:
|
|
||||||
parsableTrackEventBytes.setPosition(startingPosition);
|
|
||||||
reset();
|
|
||||||
return false;
|
|
||||||
default: // Ignore all other Meta events.
|
|
||||||
parsableTrackEventBytes.skipBytes(eventLength);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO(b/228838584): Handle this gracefully.
|
|
||||||
throw ParserException.createForUnsupportedContainerFeature(
|
|
||||||
"SysEx track events are not yet supported.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eventFileSizeBytes = parsableTrackEventBytes.getPosition() - startingPosition;
|
eventFileSizeBytes = parsableTrackEventBytes.getPosition() - startingPosition;
|
||||||
@ -154,8 +156,7 @@ import androidx.media3.common.util.UnstableApi;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMidiEvent() {
|
public boolean isMidiEvent() {
|
||||||
// TODO(b/228838584): Update with SysEx event check when implemented.
|
return statusByte != META_EVENT_STATUS && statusByte != SYSEX_BEGIN_STATUS;
|
||||||
return statusByte != META_EVENT_STATUS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNoteChannelEvent() {
|
public boolean isNoteChannelEvent() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user