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
fe52a486
authored
Jul 15, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Inject Allocator into ExtractorSampleSource.
parent
b4879236
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
18 deletions
demo/src/main/java/com/google/android/exoplayer/demo/player/ExtractorRendererBuilder.java
demo_misc/webm_sw_decoder/src/main/java/com/google/android/exoplayer/demo/webm/VideoPlayer.java
library/src/main/java/com/google/android/exoplayer/extractor/ExtractorSampleSource.java
library/src/main/java/com/google/android/exoplayer/upstream/Allocator.java
library/src/main/java/com/google/android/exoplayer/upstream/DefaultAllocator.java
demo/src/main/java/com/google/android/exoplayer/demo/player/ExtractorRendererBuilder.java
View file @
fe52a486
...
...
@@ -24,7 +24,9 @@ import com.google.android.exoplayer.extractor.Extractor;
import
com.google.android.exoplayer.extractor.ExtractorSampleSource
;
import
com.google.android.exoplayer.text.TextTrackRenderer
;
import
com.google.android.exoplayer.text.tx3g.Tx3gParser
;
import
com.google.android.exoplayer.upstream.Allocator
;
import
com.google.android.exoplayer.upstream.DataSource
;
import
com.google.android.exoplayer.upstream.DefaultAllocator
;
import
com.google.android.exoplayer.upstream.DefaultBandwidthMeter
;
import
com.google.android.exoplayer.upstream.DefaultUriDataSource
;
...
...
@@ -37,7 +39,8 @@ import android.net.Uri;
*/
public
class
ExtractorRendererBuilder
implements
RendererBuilder
{
private
static
final
int
BUFFER_SIZE
=
10
*
1024
*
1024
;
private
static
final
int
BUFFER_SEGMENT_SIZE
=
64
*
1024
;
private
static
final
int
BUFFER_SEGMENT_COUNT
=
160
;
private
final
Context
context
;
private
final
String
userAgent
;
...
...
@@ -53,12 +56,14 @@ public class ExtractorRendererBuilder implements RendererBuilder {
@Override
public
void
buildRenderers
(
DemoPlayer
player
,
RendererBuilderCallback
callback
)
{
Allocator
allocator
=
new
DefaultAllocator
(
BUFFER_SEGMENT_SIZE
);
// Build the video and audio renderers.
DefaultBandwidthMeter
bandwidthMeter
=
new
DefaultBandwidthMeter
(
player
.
getMainHandler
(),
null
);
DataSource
dataSource
=
new
DefaultUriDataSource
(
context
,
bandwidthMeter
,
userAgent
);
ExtractorSampleSource
sampleSource
=
new
ExtractorSampleSource
(
uri
,
dataSource
,
extractor
,
BUFFER
_SIZE
);
allocator
,
BUFFER_SEGMENT_COUNT
*
BUFFER_SEGMENT
_SIZE
);
MediaCodecVideoTrackRenderer
videoRenderer
=
new
MediaCodecVideoTrackRenderer
(
sampleSource
,
null
,
true
,
MediaCodec
.
VIDEO_SCALING_MODE_SCALE_TO_FIT
,
5000
,
null
,
player
.
getMainHandler
(),
player
,
50
);
...
...
demo_misc/webm_sw_decoder/src/main/java/com/google/android/exoplayer/demo/webm/VideoPlayer.java
View file @
fe52a486
...
...
@@ -25,6 +25,7 @@ import com.google.android.exoplayer.ext.vp9.VpxDecoderException;
import
com.google.android.exoplayer.ext.vp9.VpxVideoSurfaceView
;
import
com.google.android.exoplayer.extractor.ExtractorSampleSource
;
import
com.google.android.exoplayer.extractor.webm.WebmExtractor
;
import
com.google.android.exoplayer.upstream.DefaultAllocator
;
import
com.google.android.exoplayer.upstream.DefaultUriDataSource
;
import
com.google.android.exoplayer.util.PlayerControl
;
import
com.google.android.exoplayer.util.Util
;
...
...
@@ -56,7 +57,9 @@ public class VideoPlayer extends Activity implements OnClickListener,
public
static
final
String
USE_OPENGL_ID_EXTRA
=
"use_opengl"
;
private
static
final
int
FILE_PICKER_REQUEST
=
1
;
private
static
final
int
EXTRACTOR_BUFFER_SIZE
=
10
*
1024
*
1024
;
private
static
final
int
BUFFER_SEGMENT_SIZE
=
64
*
1024
;
private
static
final
int
BUFFER_SEGMENT_COUNT
=
160
;
private
boolean
isDash
;
private
String
manifestUrl
;
...
...
@@ -161,7 +164,8 @@ public class VideoPlayer extends Activity implements OnClickListener,
ExtractorSampleSource
sampleSource
=
new
ExtractorSampleSource
(
Uri
.
fromFile
(
new
File
(
filename
)),
new
DefaultUriDataSource
(
this
,
Util
.
getUserAgent
(
this
,
"ExoPlayerExtWebMDemo"
)),
new
WebmExtractor
(),
EXTRACTOR_BUFFER_SIZE
);
new
WebmExtractor
(),
new
DefaultAllocator
(
BUFFER_SEGMENT_SIZE
),
BUFFER_SEGMENT_SIZE
*
BUFFER_SEGMENT_COUNT
);
TrackRenderer
videoRenderer
=
new
LibvpxVideoTrackRenderer
(
sampleSource
,
true
,
handler
,
this
,
50
);
if
(
useOpenGL
)
{
...
...
library/src/main/java/com/google/android/exoplayer/extractor/ExtractorSampleSource.java
View file @
fe52a486
...
...
@@ -54,12 +54,11 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
*/
public
static
final
int
DEFAULT_MIN_LOADABLE_RETRY_COUNT_LIVE
=
6
;
private
static
final
int
BUFFER_FRAGMENT_LENGTH
=
256
*
1024
;
private
static
final
int
MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA
=
-
1
;
private
static
final
int
NO_RESET_PENDING
=
-
1
;
private
final
Extractor
extractor
;
private
final
Default
Allocator
allocator
;
private
final
Allocator
allocator
;
private
final
int
requestedBufferSize
;
private
final
SparseArray
<
InternalTrackOutput
>
sampleQueues
;
private
final
int
minLoadableRetryCount
;
...
...
@@ -106,9 +105,24 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
* @param requestedBufferSize The requested total buffer size for storing sample data, in bytes.
* The actual allocated size may exceed the value passed in if the implementation requires it.
*/
@Deprecated
public
ExtractorSampleSource
(
Uri
uri
,
DataSource
dataSource
,
Extractor
extractor
,
int
requestedBufferSize
)
{
this
(
uri
,
dataSource
,
extractor
,
requestedBufferSize
,
MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA
);
this
(
uri
,
dataSource
,
extractor
,
new
DefaultAllocator
(
64
*
1024
),
requestedBufferSize
);
}
/**
* @param uri The {@link Uri} of the media stream.
* @param dataSource A data source to read the media stream.
* @param extractor An {@link Extractor} to extract the media stream.
* @param allocator An {@link Allocator} from which to obtain memory allocations.
* @param requestedBufferSize The requested total buffer size for storing sample data, in bytes.
* The actual allocated size may exceed the value passed in if the implementation requires it.
*/
public
ExtractorSampleSource
(
Uri
uri
,
DataSource
dataSource
,
Extractor
extractor
,
Allocator
allocator
,
int
requestedBufferSize
)
{
this
(
uri
,
dataSource
,
extractor
,
allocator
,
requestedBufferSize
,
MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA
);
}
/**
...
...
@@ -120,15 +134,32 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
* @param minLoadableRetryCount The minimum number of times that the sample source will retry
* if a loading error occurs.
*/
@Deprecated
public
ExtractorSampleSource
(
Uri
uri
,
DataSource
dataSource
,
Extractor
extractor
,
int
requestedBufferSize
,
int
minLoadableRetryCount
)
{
this
(
uri
,
dataSource
,
extractor
,
new
DefaultAllocator
(
64
*
1024
),
requestedBufferSize
,
minLoadableRetryCount
);
}
/**
* @param uri The {@link Uri} of the media stream.
* @param dataSource A data source to read the media stream.
* @param extractor An {@link Extractor} to extract the media stream.
* @param allocator An {@link Allocator} from which to obtain memory allocations.
* @param requestedBufferSize The requested total buffer size for storing sample data, in bytes.
* The actual allocated size may exceed the value passed in if the implementation requires it.
* @param minLoadableRetryCount The minimum number of times that the sample source will retry
* if a loading error occurs.
*/
public
ExtractorSampleSource
(
Uri
uri
,
DataSource
dataSource
,
Extractor
extractor
,
Allocator
allocator
,
int
requestedBufferSize
,
int
minLoadableRetryCount
)
{
this
.
uri
=
uri
;
this
.
dataSource
=
dataSource
;
this
.
extractor
=
extractor
;
this
.
allocator
=
allocator
;
this
.
requestedBufferSize
=
requestedBufferSize
;
this
.
minLoadableRetryCount
=
minLoadableRetryCount
;
sampleQueues
=
new
SparseArray
<>();
allocator
=
new
DefaultAllocator
(
BUFFER_FRAGMENT_LENGTH
);
pendingResetPositionUs
=
NO_RESET_PENDING
;
frameAccurateSeeking
=
true
;
extractor
.
init
(
this
);
...
...
@@ -561,7 +592,7 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
private
final
Uri
uri
;
private
final
DataSource
dataSource
;
private
final
Extractor
extractor
;
private
final
Default
Allocator
allocator
;
private
final
Allocator
allocator
;
private
final
int
requestedBufferSize
;
private
final
PositionHolder
positionHolder
;
...
...
@@ -570,7 +601,7 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
private
boolean
pendingExtractorSeek
;
public
ExtractingLoadable
(
Uri
uri
,
DataSource
dataSource
,
Extractor
extractor
,
Default
Allocator
allocator
,
int
requestedBufferSize
,
long
position
)
{
Allocator
allocator
,
int
requestedBufferSize
,
long
position
)
{
this
.
uri
=
Assertions
.
checkNotNull
(
uri
);
this
.
dataSource
=
Assertions
.
checkNotNull
(
dataSource
);
this
.
extractor
=
Assertions
.
checkNotNull
(
extractor
);
...
...
library/src/main/java/com/google/android/exoplayer/upstream/Allocator.java
View file @
fe52a486
...
...
@@ -46,6 +46,15 @@ public interface Allocator {
void
trim
(
int
targetSize
);
/**
* Blocks execution until the number of bytes allocated is not greater than the limit, or the
* thread is interrupted.
*
* @param limit The limit in bytes.
* @throws InterruptedException If the thread is interrupted.
*/
void
blockWhileTotalBytesAllocatedExceeds
(
int
limit
)
throws
InterruptedException
;
/**
* Returns the total number of bytes currently allocated.
*/
int
getTotalBytesAllocated
();
...
...
library/src/main/java/com/google/android/exoplayer/upstream/DefaultAllocator.java
View file @
fe52a486
...
...
@@ -143,14 +143,6 @@ public final class DefaultAllocator implements Allocator {
}
@Override
public
int
getIndividualAllocationLength
()
{
return
individualAllocationSize
;
}
/**
* Blocks execution until the allocated number of bytes allocated is not greater than the
* threshold, or the thread is interrupted.
*/
public
synchronized
void
blockWhileTotalBytesAllocatedExceeds
(
int
limit
)
throws
InterruptedException
{
while
(
getTotalBytesAllocated
()
>
limit
)
{
...
...
@@ -158,4 +150,9 @@ public final class DefaultAllocator implements Allocator {
}
}
@Override
public
int
getIndividualAllocationLength
()
{
return
individualAllocationSize
;
}
}
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