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
5f6b1973
authored
Oct 27, 2014
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Allow direct and indirect buffer replacement.
Also tweak ManifestFetcher.
parent
ae6e082d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
26 deletions
library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java
library/src/main/java/com/google/android/exoplayer/SampleHolder.java
library/src/main/java/com/google/android/exoplayer/chunk/SingleSampleMediaChunk.java
library/src/main/java/com/google/android/exoplayer/parser/mp4/FragmentedMp4Extractor.java
library/src/main/java/com/google/android/exoplayer/parser/webm/WebmExtractor.java
library/src/main/java/com/google/android/exoplayer/text/SubtitleParserHelper.java
library/src/main/java/com/google/android/exoplayer/util/ManifestFetcher.java
library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java
View file @
5f6b1973
...
...
@@ -174,7 +174,7 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
this
.
eventHandler
=
eventHandler
;
this
.
eventListener
=
eventListener
;
codecCounters
=
new
CodecCounters
();
sampleHolder
=
new
SampleHolder
(
false
);
sampleHolder
=
new
SampleHolder
(
SampleHolder
.
BUFFER_REPLACEMENT_MODE_DISABLED
);
formatHolder
=
new
MediaFormatHolder
();
decodeOnlyPresentationTimestamps
=
new
HashSet
<
Long
>();
outputBufferInfo
=
new
MediaCodec
.
BufferInfo
();
...
...
library/src/main/java/com/google/android/exoplayer/SampleHolder.java
View file @
5f6b1973
...
...
@@ -23,10 +23,19 @@ import java.nio.ByteBuffer;
public
final
class
SampleHolder
{
/**
* Whether a {@link SampleSource} is permitted to replace {@link #data} if its current value is
* null or of insufficient size to hold the sample.
* Disallows buffer replacement.
*/
public
final
boolean
allowDataBufferReplacement
;
public
static
final
int
BUFFER_REPLACEMENT_MODE_DISABLED
=
0
;
/**
* Allows buffer replacement using {@link ByteBuffer#allocate(int)}.
*/
public
static
final
int
BUFFER_REPLACEMENT_MODE_NORMAL
=
1
;
/**
* Allows buffer replacement using {@link ByteBuffer#allocateDirect(int)}.
*/
public
static
final
int
BUFFER_REPLACEMENT_MODE_DIRECT
=
2
;
public
final
CryptoInfo
cryptoInfo
;
...
...
@@ -57,12 +66,34 @@ public final class SampleHolder {
*/
public
boolean
decodeOnly
;
private
final
int
bufferReplacementMode
;
/**
* @param allowDataBufferReplacement See {@link #allowDataBufferReplacement}.
* @param bufferReplacementMode Determines the behavior of {@link #replaceBuffer(int)}. One of
* {@link #BUFFER_REPLACEMENT_MODE_DISABLED}, {@link #BUFFER_REPLACEMENT_MODE_NORMAL} and
* {@link #BUFFER_REPLACEMENT_MODE_DIRECT}.
*/
public
SampleHolder
(
boolean
allowDataBufferReplacement
)
{
public
SampleHolder
(
int
bufferReplacementMode
)
{
this
.
cryptoInfo
=
new
CryptoInfo
();
this
.
allowDataBufferReplacement
=
allowDataBufferReplacement
;
this
.
bufferReplacementMode
=
bufferReplacementMode
;
}
/**
* Attempts to replace {@link #data} with a {@link ByteBuffer} of the specified capacity.
*
* @param capacity The capacity of the replacement buffer, in bytes.
* @return True if the buffer was replaced. False otherwise.
*/
public
boolean
replaceBuffer
(
int
capacity
)
{
switch
(
bufferReplacementMode
)
{
case
BUFFER_REPLACEMENT_MODE_NORMAL:
data
=
ByteBuffer
.
allocate
(
capacity
);
return
true
;
case
BUFFER_REPLACEMENT_MODE_DIRECT:
data
=
ByteBuffer
.
allocateDirect
(
capacity
);
return
true
;
}
return
false
;
}
}
library/src/main/java/com/google/android/exoplayer/chunk/SingleSampleMediaChunk.java
View file @
5f6b1973
...
...
@@ -22,7 +22,6 @@ import com.google.android.exoplayer.upstream.DataSpec;
import
com.google.android.exoplayer.upstream.NonBlockingInputStream
;
import
com.google.android.exoplayer.util.Assertions
;
import
java.nio.ByteBuffer
;
import
java.util.Map
;
import
java.util.UUID
;
...
...
@@ -97,9 +96,8 @@ public class SingleSampleMediaChunk extends MediaChunk {
if
(
headerData
!=
null
)
{
sampleSize
+=
headerData
.
length
;
}
if
(
holder
.
allowDataBufferReplacement
&&
(
holder
.
data
==
null
||
holder
.
data
.
capacity
()
<
sampleSize
))
{
holder
.
data
=
ByteBuffer
.
allocate
(
sampleSize
);
if
(
holder
.
data
==
null
||
holder
.
data
.
capacity
()
<
sampleSize
)
{
holder
.
replaceBuffer
(
sampleSize
);
}
int
bytesRead
;
if
(
holder
.
data
!=
null
)
{
...
...
library/src/main/java/com/google/android/exoplayer/parser/mp4/FragmentedMp4Extractor.java
View file @
5f6b1973
...
...
@@ -1069,21 +1069,20 @@ public final class FragmentedMp4Extractor implements Extractor {
if
(
out
==
null
)
{
return
RESULT_NEED_SAMPLE_HOLDER
;
}
ByteBuffer
outputData
=
out
.
data
;
out
.
timeUs
=
fragmentRun
.
getSamplePresentationTime
(
sampleIndex
)
*
1000L
;
out
.
flags
=
0
;
if
(
fragmentRun
.
sampleIsSyncFrameTable
[
sampleIndex
])
{
out
.
flags
|=
MediaExtractor
.
SAMPLE_FLAG_SYNC
;
lastSyncSampleIndex
=
sampleIndex
;
}
if
(
out
.
allowDataBufferReplacement
&&
(
out
.
data
==
null
||
out
.
data
.
capacity
()
<
sampleSize
))
{
outputData
=
ByteBuffer
.
allocate
(
sampleSize
);
out
.
data
=
outputData
;
if
(
out
.
data
==
null
||
out
.
data
.
capacity
()
<
sampleSize
)
{
out
.
replaceBuffer
(
sampleSize
);
}
if
(
fragmentRun
.
definesEncryptionData
)
{
readSampleEncryptionData
(
fragmentRun
.
sampleEncryptionData
,
out
);
}
ByteBuffer
outputData
=
out
.
data
;
if
(
outputData
==
null
)
{
inputStream
.
skip
(
sampleSize
);
out
.
size
=
0
;
...
...
library/src/main/java/com/google/android/exoplayer/parser/webm/WebmExtractor.java
View file @
5f6b1973
...
...
@@ -347,13 +347,11 @@ public final class WebmExtractor implements Extractor {
throw
new
IllegalStateException
(
"Lacing mode "
+
lacing
+
" not supported"
);
}
ByteBuffer
outputData
=
sampleHolder
.
data
;
if
(
sampleHolder
.
allowDataBufferReplacement
&&
(
sampleHolder
.
data
==
null
||
sampleHolder
.
data
.
capacity
()
<
sampleHolder
.
size
))
{
outputData
=
ByteBuffer
.
allocate
(
sampleHolder
.
size
);
sampleHolder
.
data
=
outputData
;
if
(
sampleHolder
.
data
==
null
||
sampleHolder
.
data
.
capacity
()
<
sampleHolder
.
size
)
{
sampleHolder
.
replaceBuffer
(
sampleHolder
.
size
);
}
ByteBuffer
outputData
=
sampleHolder
.
data
;
if
(
outputData
==
null
)
{
reader
.
skipBytes
(
inputStream
,
sampleHolder
.
size
);
sampleHolder
.
size
=
0
;
...
...
library/src/main/java/com/google/android/exoplayer/text/SubtitleParserHelper.java
View file @
5f6b1973
...
...
@@ -55,7 +55,7 @@ public class SubtitleParserHelper implements Handler.Callback {
* Flushes the helper, canceling the current parsing operation, if there is one.
*/
public
synchronized
void
flush
()
{
sampleHolder
=
new
SampleHolder
(
true
);
sampleHolder
=
new
SampleHolder
(
SampleHolder
.
BUFFER_REPLACEMENT_MODE_NORMAL
);
parsing
=
false
;
result
=
null
;
error
=
null
;
...
...
library/src/main/java/com/google/android/exoplayer/util/ManifestFetcher.java
View file @
5f6b1973
...
...
@@ -24,8 +24,8 @@ import android.util.Pair;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.concurrent.CancellationException
;
/**
...
...
@@ -282,10 +282,10 @@ public class ManifestFetcher<T> implements Loader.Callback {
@Override
public
void
load
()
throws
IOException
,
InterruptedException
{
String
inputEncoding
=
null
;
String
inputEncoding
;
InputStream
inputStream
=
null
;
try
{
HttpURLConnection
connection
=
configureHttp
Connection
(
new
URL
(
manifestUrl
));
URLConnection
connection
=
configure
Connection
(
new
URL
(
manifestUrl
));
inputStream
=
connection
.
getInputStream
();
inputEncoding
=
connection
.
getContentEncoding
();
result
=
parser
.
parse
(
inputStream
,
inputEncoding
,
contentId
,
...
...
@@ -297,8 +297,8 @@ public class ManifestFetcher<T> implements Loader.Callback {
}
}
private
HttpURLConnection
configureHttp
Connection
(
URL
url
)
throws
IOException
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
private
URLConnection
configure
Connection
(
URL
url
)
throws
IOException
{
URLConnection
connection
=
url
.
openConnection
();
connection
.
setConnectTimeout
(
TIMEOUT_MILLIS
);
connection
.
setReadTimeout
(
TIMEOUT_MILLIS
);
connection
.
setDoOutput
(
false
);
...
...
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