Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cdad156b
authored
Oct 26, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Further tweaks to ScriptTagPayloadReader
parent
dff17f24
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
38 deletions
library/src/main/java/com/google/android/exoplayer/extractor/flv/ScriptTagPayloadReader.java
library/src/main/java/com/google/android/exoplayer/extractor/flv/ScriptTagPayloadReader.java
View file @
cdad156b
...
@@ -19,7 +19,6 @@ import com.google.android.exoplayer.C;
...
@@ -19,7 +19,6 @@ import com.google.android.exoplayer.C;
import
com.google.android.exoplayer.extractor.TrackOutput
;
import
com.google.android.exoplayer.extractor.TrackOutput
;
import
com.google.android.exoplayer.util.ParsableByteArray
;
import
com.google.android.exoplayer.util.ParsableByteArray
;
import
java.nio.ByteBuffer
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -63,29 +62,29 @@ import java.util.Map;
...
@@ -63,29 +62,29 @@ import java.util.Map;
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Override
@Override
protected
void
parsePayload
(
ParsableByteArray
data
,
long
timeUs
)
{
protected
void
parsePayload
(
ParsableByteArray
data
,
long
timeUs
)
{
String
name
=
readAmfName
(
data
);
int
nameType
=
readAmfType
(
data
);
if
(
NAME_METADATA
.
equals
(
name
))
{
if
(
nameType
!=
AMF_TYPE_STRING
)
{
// Not interested.
// Should never happen.
return
;
}
String
name
=
readAmfString
(
data
);
if
(!
NAME_METADATA
.
equals
(
name
))
{
// We're only interested in metadata.
return
;
return
;
}
}
int
type
=
readAmfType
(
data
);
int
type
=
readAmfType
(
data
);
if
(
type
!=
AMF_TYPE_ECMA_ARRAY
)
{
if
(
type
!=
AMF_TYPE_ECMA_ARRAY
)
{
//
Not interested
.
//
Should never happen
.
return
;
return
;
}
}
// Set the duration.
// Set the duration
to the metadata's value, if present
.
Map
<
String
,
Object
>
metadata
=
(
Map
<
String
,
Object
>)
readAmfData
(
data
,
type
);
Map
<
String
,
Object
>
metadata
=
(
Map
<
String
,
Object
>)
readAmfData
(
data
,
type
);
if
(
metadata
.
containsKey
(
KEY_DURATION
))
{
if
(
metadata
.
containsKey
(
KEY_DURATION
))
{
double
durationSeconds
=
(
double
)
metadata
.
get
(
KEY_DURATION
);
double
durationSeconds
=
(
double
)
metadata
.
get
(
KEY_DURATION
);
setDurationUs
((
long
)
durationSeconds
*
C
.
MICROS_PER_SECOND
);
setDurationUs
((
long
)
(
durationSeconds
*
C
.
MICROS_PER_SECOND
)
);
}
}
}
}
private
String
readAmfName
(
ParsableByteArray
data
)
{
int
size
=
data
.
readUnsignedShort
();
return
new
String
(
data
.
data
,
data
.
getPosition
(),
size
);
}
private
int
readAmfType
(
ParsableByteArray
data
)
{
private
int
readAmfType
(
ParsableByteArray
data
)
{
return
data
.
readUnsignedByte
();
return
data
.
readUnsignedByte
();
}
}
...
@@ -93,19 +92,19 @@ import java.util.Map;
...
@@ -93,19 +92,19 @@ import java.util.Map;
private
Object
readAmfData
(
ParsableByteArray
data
,
int
type
)
{
private
Object
readAmfData
(
ParsableByteArray
data
,
int
type
)
{
switch
(
type
)
{
switch
(
type
)
{
case
AMF_TYPE_NUMBER:
case
AMF_TYPE_NUMBER:
return
readA
MF
Double
(
data
);
return
readA
mf
Double
(
data
);
case
AMF_TYPE_BOOLEAN:
case
AMF_TYPE_BOOLEAN:
return
readA
MF
Boolean
(
data
);
return
readA
mf
Boolean
(
data
);
case
AMF_TYPE_STRING:
case
AMF_TYPE_STRING:
return
readA
MF
String
(
data
);
return
readA
mf
String
(
data
);
case
AMF_TYPE_OBJECT:
case
AMF_TYPE_OBJECT:
return
readA
MF
Object
(
data
);
return
readA
mf
Object
(
data
);
case
AMF_TYPE_ECMA_ARRAY:
case
AMF_TYPE_ECMA_ARRAY:
return
readA
MF
EcmaArray
(
data
);
return
readA
mf
EcmaArray
(
data
);
case
AMF_TYPE_STRICT_ARRAY:
case
AMF_TYPE_STRICT_ARRAY:
return
readA
MF
StrictArray
(
data
);
return
readA
mf
StrictArray
(
data
);
case
AMF_TYPE_DATE:
case
AMF_TYPE_DATE:
return
readA
MF
Date
(
data
);
return
readA
mf
Date
(
data
);
default
:
default
:
return
null
;
return
null
;
}
}
...
@@ -117,20 +116,18 @@ import java.util.Map;
...
@@ -117,20 +116,18 @@ import java.util.Map;
* @param data The buffer from which to read.
* @param data The buffer from which to read.
* @return The value read from the buffer.
* @return The value read from the buffer.
*/
*/
private
Boolean
readA
MF
Boolean
(
ParsableByteArray
data
)
{
private
Boolean
readA
mf
Boolean
(
ParsableByteArray
data
)
{
return
data
.
readUnsignedByte
()
==
1
;
return
data
.
readUnsignedByte
()
==
1
;
}
}
/**
/**
* Read a double number from an AMF encoded buffer
* Read a double number from an AMF encoded buffer
.
*
*
* @param data The buffer from which to read.
* @param data The buffer from which to read.
* @return The value read from the buffer.
* @return The value read from the buffer.
*/
*/
private
Double
readAMFDouble
(
ParsableByteArray
data
)
{
private
Double
readAmfDouble
(
ParsableByteArray
data
)
{
byte
[]
b
=
new
byte
[
8
];
return
Double
.
longBitsToDouble
(
data
.
readLong
());
data
.
readBytes
(
b
,
0
,
b
.
length
);
return
ByteBuffer
.
wrap
(
b
).
getDouble
();
}
}
/**
/**
...
@@ -139,11 +136,11 @@ import java.util.Map;
...
@@ -139,11 +136,11 @@ import java.util.Map;
* @param data The buffer from which to read.
* @param data The buffer from which to read.
* @return The value read from the buffer.
* @return The value read from the buffer.
*/
*/
private
String
readA
MF
String
(
ParsableByteArray
data
)
{
private
String
readA
mf
String
(
ParsableByteArray
data
)
{
int
size
=
data
.
readUnsignedShort
();
int
size
=
data
.
readUnsignedShort
();
byte
[]
b
=
new
byte
[
size
]
;
int
position
=
data
.
getPosition
()
;
data
.
readBytes
(
b
,
0
,
b
.
length
);
data
.
skipBytes
(
size
);
return
new
String
(
b
);
return
new
String
(
data
.
data
,
position
,
size
);
}
}
/**
/**
...
@@ -152,7 +149,7 @@ import java.util.Map;
...
@@ -152,7 +149,7 @@ import java.util.Map;
* @param data The buffer from which to read.
* @param data The buffer from which to read.
* @return The value read from the buffer.
* @return The value read from the buffer.
*/
*/
private
Object
readA
MF
StrictArray
(
ParsableByteArray
data
)
{
private
Object
readA
mf
StrictArray
(
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
++)
{
...
@@ -168,11 +165,11 @@ import java.util.Map;
...
@@ -168,11 +165,11 @@ import java.util.Map;
* @param data The buffer from which to read.
* @param data The buffer from which to read.
* @return The value read from the buffer.
* @return The value read from the buffer.
*/
*/
private
Object
readA
MF
Object
(
ParsableByteArray
data
)
{
private
Object
readA
mf
Object
(
ParsableByteArray
data
)
{
HashMap
<
String
,
Object
>
array
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
array
=
new
HashMap
<>();
while
(
true
)
{
while
(
true
)
{
String
key
=
readA
MF
String
(
data
);
String
key
=
readA
mf
String
(
data
);
int
type
=
data
.
readUnsignedByte
(
);
int
type
=
readAmfType
(
data
);
if
(
type
==
AMF_TYPE_END_MARKER
)
{
if
(
type
==
AMF_TYPE_END_MARKER
)
{
break
;
break
;
}
}
...
@@ -187,12 +184,12 @@ import java.util.Map;
...
@@ -187,12 +184,12 @@ import java.util.Map;
* @param data The buffer from which to read.
* @param data The buffer from which to read.
* @return The value read from the buffer.
* @return The value read from the buffer.
*/
*/
private
Object
readA
MF
EcmaArray
(
ParsableByteArray
data
)
{
private
Object
readA
mf
EcmaArray
(
ParsableByteArray
data
)
{
long
count
=
data
.
readUnsignedInt
();
long
count
=
data
.
readUnsignedInt
();
HashMap
<
String
,
Object
>
array
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
array
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
String
key
=
readA
MF
String
(
data
);
String
key
=
readA
mf
String
(
data
);
int
type
=
data
.
readUnsignedByte
(
);
int
type
=
readAmfType
(
data
);
array
.
put
(
key
,
readAmfData
(
data
,
type
));
array
.
put
(
key
,
readAmfData
(
data
,
type
));
}
}
return
array
;
return
array
;
...
@@ -204,8 +201,8 @@ import java.util.Map;
...
@@ -204,8 +201,8 @@ import java.util.Map;
* @param data The buffer from which to read.
* @param data The buffer from which to read.
* @return The value read from the buffer.
* @return The value read from the buffer.
*/
*/
private
Date
readA
MF
Date
(
ParsableByteArray
data
)
{
private
Date
readA
mf
Date
(
ParsableByteArray
data
)
{
final
Date
date
=
new
Date
((
long
)
readA
MF
Double
(
data
).
doubleValue
());
final
Date
date
=
new
Date
((
long
)
readA
mf
Double
(
data
).
doubleValue
());
data
.
readUnsignedShort
();
data
.
readUnsignedShort
();
return
date
;
return
date
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment