ExoPlayer ãæ±ãæã«ã¯ DataSource, SampleSource, Renderer ãçæãã ExoPlayer ã¤ã³ã¹ã¿ã³ã¹ã«æ¸¡ãå¿ è¦ãããã¾ãã 以å ExoPlayer ã®ç´¹ä»è¨äºãæ¸ããæã«è¼ãããµã³ãã«ã³ã¼ãã¯ä»¥ä¸ã®ãããªå½¢ã§ããã
DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent); ExtractorSampleSource sampleSource = new ExtractorSampleSource( uri, dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE); MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer( sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);
ãããããä½ãã㦠ExoPlayer ãã©ã®ããã«åä½ãã¦ãããã URL ãæå®ã㦠File ãã MP4 ãèªã¿è¾¼ãã¨ããæµãã追ã£ã¦ã¿ããã¨æãã¾ãã
DataSource
DataSource
㯠ExoPlayer ã§æ±ãåç»ãé³å£°ã®ãã¼ã¿ãã¡ã¤ã«ãããã¨ãããããã®ã¯ã©ã¹ã§ãã
ããªãã¡ã File ããèªã¿è¾¼ãã ãã HTTP ããèªã¿è¾¼ãã ããã¨ãããããªé¨åã管çãã¦ãã¾ãã
ãã®ã¯ã©ã¹ã§ã¯ mp4 ã webm ã¨ãã£ããå®éã«ã©ã®ãããªå½¢å¼ã®ã¡ãã£ã¢ãã¼ã¿ãªã®ãã¯æ±ãã¾ããã
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/upstream/DataSource.java
- InputStream ã¿ãã㪠Interface
- open(DataSpec), close(), read(buffer, offset, length) ã® 3 ã¤ã ããå®ç¾©ããã¦ã
public interface DataSource { long open(DataSpec dataSpec) throws IOException; void close() throws IOException; int read(byte[] buffer, int offset, int readLength) throws IOException; }
DefaultUriDataSource
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/upstream/DefaultUriDataSource.java
- URI ã® scheme é¨ãè¦ã¦ã©ã® DataSource ã使ããå¤å¥ãã¦ããæãã® DataSource ã«åã渡ãã¦ããã
- FileDataSource ...
file://
- AssetDataSource ...
asset://
ãfile://
ã®/android_asset/
- ContentDataSource ...
content://
- DefaultHttpDataSource ... ãã以å¤
- FileDataSource ...
public long open(DataSpec dataSpec) throws IOException { Assertions.checkState(dataSource == null); // Choose the correct source for the scheme. String scheme = dataSpec.uri.getScheme(); if (Util.isLocalFileUri(dataSpec.uri)) { if (dataSpec.uri.getPath().startsWith("/android_asset/")) { dataSource = assetDataSource; } else { dataSource = fileDataSource; } } else if (SCHEME_ASSET.equals(scheme)) { dataSource = assetDataSource; } else if (SCHEME_CONTENT.equals(scheme)) { dataSource = contentDataSource; } else { dataSource = httpDataSource; } // Open the source and return. return dataSource.open(dataSpec); }
ãã®å®è£
ãè¦ãã¨åããã¾ããã File, Asset, ContentResolver, Http ã® 4 種é¡ã® DataSource ã¤ã³ã¹ã¿ã³ã¹ãæã£ã¦ãã¦ã open()
ã¡ã½ãããå¼ã°ããã¨ãã«ã©ãã使ç¨ãããæ¯ãåãã¦ãã¾ãã
大ããã³ã¹ãã§ã¯ç¡ãã®ã§ãããå©ç¨ãã DataSource ã 1 種é¡ã®å ´å㯠DafaultUriDataSource ã使ããã«ãåå¥ã® DataSource ãå¼ã³åºããã»ããè¯ãã§ãããã
FileDataSource
RandomAccessFile ã使ã£ã¦ DataSource ã® Interface ã«åãããã«è¯ãæãã«ãã¡ã¤ã«ã seek ããã read ãã¾ãã
SampleSource
SampleSource
ã¯ã DataSource ã§èªã¿è¾¼ãã ãã¡ã¤ã«ã解æãããã¬ã¤ã¤ã¼ã¨ãã¦æ±ããåä½ã§èªã¿è¾¼ããããã«ããã¯ã©ã¹ã§ãã
ä¸è¬çã«ã³ã³ãããã©ã¼ãããã¨å¼ã°ãããã®ã® parse ãããã§è¡ãªã£ã¦ãåãã©ãã¯ãã¡ã¿ãã¼ã¿ã«ã¢ã¯ã»ã¹ã§ããããã«ãªãã¾ãã
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/SampleSource.java
- SampleSource
- register() ãã㨠SampleSourceReader ãè¿ãã ã
public interface SampleSource { public SampleSourceReader register(); }
- SampleSourceReader
- SampleSource ã® Inner Interface
- å®éã« SampleSource çãªåä½ãè¡ãªãã®ã¯ãã£ã¡ã®æ¹
- ã¡ãã£ã¢ãã¡ã¤ã«ãèªã¿è¾¼ãã ãããããã«å¿ è¦ãª Interface ãä¸éãå®ç¾©ããã¦ãã
public interface SampleSourceReader { public void maybeThrowError() throws IOException; public boolean prepare(long positionUs); public int getTrackCount(); public MediaFormat getFormat(int track); public void enable(int track, long positionUs); public boolean continueBuffering(int track, long positionUs); public long readDiscontinuity(int track); public int readData(int track, long positionUs, MediaFormatHolder formatHolder, SampleHolder sampleHolder); public void seekToUs(long positionUs); public long getBufferedPositionUs(); public void disable(int track); public void release(); }
ExtractorSampleSource
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorSampleSource.java
- SampleSource, SampleSourceReader, ExtractorOutput ãå®è£ ãã¦ãã
public final class ExtractorSampleSource implements SampleSource, SampleSourceReader, ExtractorOutput, Loader.Callback {
ExtractorOutput
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorOutput.java
Extractor
ã¯ã©ã¹ã®åºåã¯ã©ã¹
public interface ExtractorOutput { TrackOutput track(int trackId); void endTracks(); void seekMap(SeekMap seekMap); void drmInitData(DrmInitData drmInitData); }
Extractor
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/extractor/Extractor.java
- ã³ã³ãããã©ã¼ãããã® parse ãããããã® Interface
- init 㧠ExtractorOutput ãæå®ãã read ã§æå®ãã ExtractorInput ãããã¼ã¿ãèªã¿è¾¼ãã§åºåãã
- sniff ã¨ããã¡ã½ããã§èªåã parse ã§ããã³ã³ãããå¤æããã¡ã½ããããã
public interface Extractor { void init(ExtractorOutput output); boolean sniff(ExtractorInput input) throws IOException, InterruptedException; int read(ExtractorInput input, PositionHolder seekPosition) throws IOException, InterruptedException; void seek(); void release(); }
ExtractorInput
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorInput.java
- Extractor ã®å ¥åã¯ã©ã¹
public interface ExtractorInput { int read(byte[] target, int offset, int length) throws IOException, InterruptedException; boolean readFully(byte[] target, int offset, int length, boolean allowEndOfInput) throws IOException, InterruptedException; void readFully(byte[] target, int offset, int length) throws IOException, InterruptedException; int skip(int length) throws IOException, InterruptedException; boolean skipFully(int length, boolean allowEndOfInput) throws IOException, InterruptedException; void skipFully(int length) throws IOException, InterruptedException; boolean peekFully(byte[] target, int offset, int length, boolean allowEndOfInput) throws IOException, InterruptedException; void peekFully(byte[] target, int offset, int length) throws IOException, InterruptedException; boolean advancePeekPosition(int length, boolean allowEndOfInput) throws IOException, InterruptedException; void advancePeekPosition(int length) throws IOException, InterruptedException; void resetPeekPosition(); long getPeekPosition(); long getPosition(); long getLength(); }
TrackOutput
public interface TrackOutput { void format(MediaFormat format); int sampleData(ExtractorInput input, int length, boolean allowEndOfInput) throws IOException, InterruptedException; void sampleData(ParsableByteArray data, int length); void sampleMetadata(long timeUs, int flags, int size, int offset, byte[] encryptionKey); }
MediaFormat
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/MediaFormat.java
- ã³ã³ãããã©ã¼ãããã®è§£æçµæãä¿æããã¯ã©ã¹
- Parcelable ãå®è£ ãã¦ãã
Mp4Extractor
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Mp4Extractor.java
- MP4 ã® Extractor ãå®è£ ããã¯ã©ã¹
- ãã㯠unfragmented mp4 ã¨ãã°ãããã¼ã¿ãã³ã³ããã®ä¸ã§åºã¾ã£ã¦ãã parse ãããããã¤å°ç¨
- MPEG-DASH ã¨ãã§ä½¿ã fragmented mp4 㯠FragmentedMp4Extractor ã¯ã©ã¹
- read()
- ExtractorInput ããå
¥åãåã£ã¦
- ãããã«ããã¡ã¿æ å ±ãèªã¿è¾¼
- TrackOutput ä½æ
- moov ãèªãã°å¾ã¯åç»ã¨é³å£°ã®ãã¬ã¼ã ãç¶ãã¦ãã
- Sample èªã¿è¾¼ã¿
- TrackOutput ã«åºåãã
- ExtractingLoadable#load() 㧠Mp4Extractor#read() ãå¼ã°ãã
- ExtractorSampleSource#prepare() 㧠load() ãããã§ã
- ExtractorOutput 㯠ExtractorSampleSource èªèº«
- InternalTrackOutput
- DefaultTrackOutput
- RollingSampleBuffer ã«åºåããã Sample ãæã£ã¦ãã
- getData 㧠SampleHolder ã« RollingSampleBuffer ããå¾ããã¼ã¿ãæ¸ãè¾¼ã
- DefaultTrackOutput
- SampleHolder
- ByteBuffer 㧠Sample ãæã£ã¦ãã
- ExtractorInput ããå
¥åãåã£ã¦
TrackRenderer
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/TrackRenderer.java
- Player ã¿ãã㪠Interface ãæã£ã abstract class
MediaCodecVideoTrackRenderer
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/MediaCodecVideoTrackRenderer.java
- MediaCodecTrackRenderer ãç¶æ¿ãã¦ãã
- processOutputBuffer()
- MediaCodec ã使ã£ã¦ãã³ã¼ããããã¼ã¿ã Surface ã«æç»ãã
- MediaCodec#configure ã§æå®ãã Surface ã«æç»ãã
- https://developer.android.com/reference/android/media/MediaCodec.html
MediaCodecTrackRenderer
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java
- SampleSourceTrackRenderer ãç¶æ¿ãã¦ãã
SampleSourceTrackRenderer
- https://github.com/google/ExoPlayer/blob/r1.5.9/library/src/main/java/com/google/android/exoplayer/SampleSourceTrackRenderer.java
- TrackRenderer ãç¶æ¿ãã abstract class
- SampleSource ã SampleSourceReader ã使ã£ã¦ãã¼ã¿ãèªã¿è¾¼ã㧠Render ãã
ã¾ã¨ã
- DataSource ... ãã¡ã¤ã«ãèªã¿è¾¼ãã¤ããä¸èº«ãä½ãã¾ã§ã¯é¢ä¸ããªã
- SampleSource ... DataSource ã§å¾ããã¤ãåããã¼ã¹ãã¦ã¡ã¿æ å ±ãåç»ãã¼ã¿ã«ã¢ã¯ã»ã¹ã§ããããã«ãã
- MediaCodeVideoRenderer ... SampleSource ã§å¾ããã¼ã¿ã MediaCodec ã§ãã³ã¼ãã Surface ã«ã¬ã³ããªã³ã°ãã
ææ
- ExoPlayer ã Android 4.1 以éã¨ããã®ã¯ MediaCodec ã«ä¾åãã¦ãããããªã®ã ãã©ã MediaCodec ã«ä¾åãã¦ããã®ã¯ MediaCodecTrackRenderer 以ä¸ã®ã¯ã©ã¹ã ã
- MediaCodec ã使ããªã Renderer ãä½ãã° 4.1 æªæºã§ã ExoPlayer ã使ããã¨ã¯åºæ¥ã
- MediaPlayer ã使ã Renderer ãä½ããããªã¨æã£ãã MediaPlayer 㯠FileDescriptor ã URI ãæå®ãã¦å ¥åã½ã¼ã¹ã決ããã®ã§ç¡çãã
- Animation GIF ã Animation PNG ã表示ãããã®ã¯åºæ¥ãã (SampleSource ã¨ã Extractor ã¨ãä½ãå¿ è¦ã¯ãããã©)