Skip to content

Commit

Permalink
Support for UDP data source
Browse files Browse the repository at this point in the history
  • Loading branch information
arodriguez authored and ojw28 committed Jun 19, 2019
1 parent d3967b5 commit 692f415
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,21 @@ public final class DefaultDataSource implements DataSource {
private static final String SCHEME_ASSET = "asset";
private static final String SCHEME_CONTENT = "content";
private static final String SCHEME_RTMP = "rtmp";
private static final String SCHEME_UDP = "udp";
private static final String SCHEME_RAW = RawResourceDataSource.RAW_RESOURCE_SCHEME;

private final Context context;
private final List<TransferListener> transferListeners;
private final DataSource baseDataSource;

// Lazily initialized.
private @Nullable DataSource fileDataSource;
private @Nullable DataSource assetDataSource;
private @Nullable DataSource contentDataSource;
private @Nullable DataSource rtmpDataSource;
private @Nullable DataSource dataSchemeDataSource;
private @Nullable DataSource rawResourceDataSource;
@Nullable private DataSource fileDataSource;
@Nullable private DataSource assetDataSource;
@Nullable private DataSource contentDataSource;
@Nullable private DataSource rtmpDataSource;
@Nullable private DataSource udpDataSource;
@Nullable private DataSource dataSchemeDataSource;
@Nullable private DataSource rawResourceDataSource;

private @Nullable DataSource dataSource;

Expand Down Expand Up @@ -218,6 +220,7 @@ public void addTransferListener(TransferListener transferListener) {
maybeAddListenerToDataSource(assetDataSource, transferListener);
maybeAddListenerToDataSource(contentDataSource, transferListener);
maybeAddListenerToDataSource(rtmpDataSource, transferListener);
maybeAddListenerToDataSource(udpDataSource, transferListener);
maybeAddListenerToDataSource(dataSchemeDataSource, transferListener);
maybeAddListenerToDataSource(rawResourceDataSource, transferListener);
}
Expand All @@ -240,6 +243,8 @@ public long open(DataSpec dataSpec) throws IOException {
dataSource = getContentDataSource();
} else if (SCHEME_RTMP.equals(scheme)) {
dataSource = getRtmpDataSource();
} else if(SCHEME_UDP.equals(scheme)){
dataSource = getUdpDataSource();
} else if (DataSchemeDataSource.SCHEME_DATA.equals(scheme)) {
dataSource = getDataSchemeDataSource();
} else if (SCHEME_RAW.equals(scheme)) {
Expand Down Expand Up @@ -277,6 +282,14 @@ public void close() throws IOException {
}
}

private DataSource getUdpDataSource(){
if (udpDataSource == null) {
udpDataSource = new UdpDataSource();
addListenersToDataSource(udpDataSource);
}
return udpDataSource;
}

private DataSource getFileDataSource() {
if (fileDataSource == null) {
fileDataSource = new FileDataSource();
Expand Down

0 comments on commit 692f415

Please sign in to comment.