mirror of
https://github.com/androidx/media.git
synced 2025-05-04 06:00:37 +08:00
Some probably correct tweaks to ScriptTagPayloadReader
This commit is contained in:
parent
950cc70003
commit
dff17f244c
@ -30,8 +30,10 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
/* package */ final class ScriptTagPayloadReader extends TagPayloadReader {
|
/* package */ final class ScriptTagPayloadReader extends TagPayloadReader {
|
||||||
|
|
||||||
|
private static final String NAME_METADATA = "onMetaData";
|
||||||
|
private static final String KEY_DURATION = "duration";
|
||||||
|
|
||||||
// AMF object types
|
// AMF object types
|
||||||
private static final int AMF_TYPE_UNKNOWN = -1;
|
|
||||||
private static final int AMF_TYPE_NUMBER = 0;
|
private static final int AMF_TYPE_NUMBER = 0;
|
||||||
private static final int AMF_TYPE_BOOLEAN = 1;
|
private static final int AMF_TYPE_BOOLEAN = 1;
|
||||||
private static final int AMF_TYPE_STRING = 2;
|
private static final int AMF_TYPE_STRING = 2;
|
||||||
@ -61,34 +63,34 @@ import java.util.Map;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
protected void parsePayload(ParsableByteArray data, long timeUs) {
|
protected void parsePayload(ParsableByteArray data, long timeUs) {
|
||||||
// Read message name (don't store it because we don't yet have a use for it).
|
String name = readAmfName(data);
|
||||||
readAMFData(data, AMF_TYPE_UNKNOWN);
|
if (NAME_METADATA.equals(name)) {
|
||||||
// Read message data.
|
// Not interested.
|
||||||
Object obj = readAMFData(data, AMF_TYPE_UNKNOWN);
|
return;
|
||||||
|
}
|
||||||
if (obj instanceof Map) {
|
int type = readAmfType(data);
|
||||||
Map<String, Object> extractedMetadata = (Map<String, Object>) obj;
|
if (type != AMF_TYPE_ECMA_ARRAY) {
|
||||||
for (Map.Entry<String, Object> entry : extractedMetadata.entrySet()) {
|
// Not interested.
|
||||||
if (entry.getValue() == null) {
|
return;
|
||||||
continue;
|
}
|
||||||
}
|
// Set the duration.
|
||||||
|
Map<String, Object> metadata = (Map<String, Object>) readAmfData(data, type);
|
||||||
switch (entry.getKey()) {
|
if (metadata.containsKey(KEY_DURATION)) {
|
||||||
case "duration":
|
double durationSeconds = (double) metadata.get(KEY_DURATION);
|
||||||
setDurationUs((long) (C.MICROS_PER_SECOND * (Double)(entry.getValue())));
|
setDurationUs((long) durationSeconds * C.MICROS_PER_SECOND);
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object readAMFData(ParsableByteArray data, int type) {
|
private String readAmfName(ParsableByteArray data) {
|
||||||
if (type == AMF_TYPE_UNKNOWN) {
|
int size = data.readUnsignedShort();
|
||||||
type = data.readUnsignedByte();
|
return new String(data.data, data.getPosition(), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int readAmfType(ParsableByteArray data) {
|
||||||
|
return data.readUnsignedByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object readAmfData(ParsableByteArray data, int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case AMF_TYPE_NUMBER:
|
case AMF_TYPE_NUMBER:
|
||||||
return readAMFDouble(data);
|
return readAMFDouble(data);
|
||||||
@ -110,9 +112,10 @@ import java.util.Map;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a boolean from an AMF encoded buffer
|
* Read a boolean from an AMF encoded buffer.
|
||||||
* @param data Buffer
|
*
|
||||||
* @return Boolean value read from the buffer
|
* @param data The buffer from which to read.
|
||||||
|
* @return The value read from the buffer.
|
||||||
*/
|
*/
|
||||||
private Boolean readAMFBoolean(ParsableByteArray data) {
|
private Boolean readAMFBoolean(ParsableByteArray data) {
|
||||||
return data.readUnsignedByte() == 1;
|
return data.readUnsignedByte() == 1;
|
||||||
@ -120,8 +123,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a double number from an AMF encoded buffer
|
* Read a double number from an AMF encoded buffer
|
||||||
* @param data Buffer
|
*
|
||||||
* @return Double number read from the buffer
|
* @param data The buffer from which to read.
|
||||||
|
* @return The value read from the buffer.
|
||||||
*/
|
*/
|
||||||
private Double readAMFDouble(ParsableByteArray data) {
|
private Double readAMFDouble(ParsableByteArray data) {
|
||||||
byte []b = new byte[8];
|
byte []b = new byte[8];
|
||||||
@ -130,9 +134,10 @@ import java.util.Map;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a string from an AMF encoded buffer
|
* Read a string from an AMF encoded buffer.
|
||||||
* @param data Buffer
|
*
|
||||||
* @return String read from the buffer
|
* @param data The buffer from which to read.
|
||||||
|
* @return The value read from the buffer.
|
||||||
*/
|
*/
|
||||||
private String readAMFString(ParsableByteArray data) {
|
private String readAMFString(ParsableByteArray data) {
|
||||||
int size = data.readUnsignedShort();
|
int size = data.readUnsignedShort();
|
||||||
@ -142,23 +147,26 @@ import java.util.Map;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read an array from an AMF encoded buffer
|
* Read an array from an AMF encoded buffer.
|
||||||
* @param data Buffer
|
*
|
||||||
* @return Array read from the buffer
|
* @param data The buffer from which to read.
|
||||||
|
* @return The value read from the buffer.
|
||||||
*/
|
*/
|
||||||
private Object readAMFStrictArray(ParsableByteArray data) {
|
private Object readAMFStrictArray(ParsableByteArray data) {
|
||||||
long count = data.readUnsignedInt();
|
long count = data.readUnsignedInt();
|
||||||
ArrayList<Object> list = new ArrayList<>();
|
ArrayList<Object> list = new ArrayList<>();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
list.add(readAMFData(data, AMF_TYPE_UNKNOWN));
|
int type = readAmfType(data);
|
||||||
|
list.add(readAmfData(data, type));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read an object from an AMF encoded buffer
|
* Read an object from an AMF encoded buffer.
|
||||||
* @param data Buffer
|
*
|
||||||
* @return Object read from the buffer
|
* @param data The buffer from which to read.
|
||||||
|
* @return The value read from the buffer.
|
||||||
*/
|
*/
|
||||||
private Object readAMFObject(ParsableByteArray data) {
|
private Object readAMFObject(ParsableByteArray data) {
|
||||||
HashMap<String, Object> array = new HashMap<>();
|
HashMap<String, Object> array = new HashMap<>();
|
||||||
@ -168,15 +176,16 @@ import java.util.Map;
|
|||||||
if (type == AMF_TYPE_END_MARKER) {
|
if (type == AMF_TYPE_END_MARKER) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
array.put(key, readAMFData(data, type));
|
array.put(key, readAmfData(data, type));
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read am ecma array from an AMF encoded buffer
|
* Read an ECMA array from an AMF encoded buffer.
|
||||||
* @param data Buffer
|
*
|
||||||
* @return Ecma array read from the buffer
|
* @param data The buffer from which to read.
|
||||||
|
* @return The value read from the buffer.
|
||||||
*/
|
*/
|
||||||
private Object readAMFEcmaArray(ParsableByteArray data) {
|
private Object readAMFEcmaArray(ParsableByteArray data) {
|
||||||
long count = data.readUnsignedInt();
|
long count = data.readUnsignedInt();
|
||||||
@ -184,15 +193,16 @@ import java.util.Map;
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
String key = readAMFString(data);
|
String key = readAMFString(data);
|
||||||
int type = data.readUnsignedByte();
|
int type = data.readUnsignedByte();
|
||||||
array.put(key, readAMFData(data, type));
|
array.put(key, readAmfData(data, type));
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a date from an AMF encoded buffer
|
* Read a date from an AMF encoded buffer.
|
||||||
* @param data Buffer
|
*
|
||||||
* @return Date read from the buffer
|
* @param data The buffer from which to read.
|
||||||
|
* @return The value read from the buffer.
|
||||||
*/
|
*/
|
||||||
private Date readAMFDate(ParsableByteArray data) {
|
private Date readAMFDate(ParsableByteArray data) {
|
||||||
final Date date = new Date((long) readAMFDouble(data).doubleValue());
|
final Date date = new Date((long) readAMFDouble(data).doubleValue());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user