mirror of
https://github.com/samsonjs/media.git
synced 2026-04-03 10:55:48 +00:00
Add DummyDataSource
A dummy DataSource which provides no data. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=150868950
This commit is contained in:
parent
382ba7ecf0
commit
8f636991ad
2 changed files with 63 additions and 14 deletions
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer2.upstream;
|
||||
|
||||
import android.net.Uri;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A dummy DataSource which provides no data. {@link #open(DataSpec)} throws {@link IOException}.
|
||||
*/
|
||||
public final class DummyDataSource implements DataSource {
|
||||
|
||||
public static final DummyDataSource INSTANCE = new DummyDataSource();
|
||||
|
||||
/** A factory that that produces {@link DummyDataSource}. */
|
||||
public static final Factory FACTORY = new Factory() {
|
||||
@Override
|
||||
public DataSource createDataSource() {
|
||||
return new DummyDataSource();
|
||||
}
|
||||
};
|
||||
|
||||
private DummyDataSource() {}
|
||||
|
||||
@Override
|
||||
public long open(DataSpec dataSpec) throws IOException {
|
||||
throw new IOException("Dummy source");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] buffer, int offset, int readLength) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getUri() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -23,10 +23,8 @@ import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet;
|
|||
import com.google.android.exoplayer2.source.dash.manifest.Period;
|
||||
import com.google.android.exoplayer2.source.dash.manifest.Representation;
|
||||
import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase;
|
||||
import com.google.android.exoplayer2.testutil.FakeDataSource;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DummyDataSource;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
@ -37,25 +35,25 @@ public final class DashUtilTest extends TestCase {
|
|||
|
||||
public void testLoadDrmInitDataFromManifest() throws Exception {
|
||||
Period period = newPeriod(newAdaptationSets(newRepresentations(newDrmInitData())));
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(newDataSource(), period);
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||
assertEquals(newDrmInitData(), drmInitData);
|
||||
}
|
||||
|
||||
public void testLoadDrmInitDataMissing() throws Exception {
|
||||
Period period = newPeriod(newAdaptationSets(newRepresentations(null /* no init data */)));
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(newDataSource(), period);
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||
assertNull(drmInitData);
|
||||
}
|
||||
|
||||
public void testLoadDrmInitDataNoRepresentations() throws Exception {
|
||||
Period period = newPeriod(newAdaptationSets(/* no representation */));
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(newDataSource(), period);
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||
assertNull(drmInitData);
|
||||
}
|
||||
|
||||
public void testLoadDrmInitDataNoAdaptationSets() throws Exception {
|
||||
Period period = newPeriod(/* no adaptation set */);
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(newDataSource(), period);
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||
assertNull(drmInitData);
|
||||
}
|
||||
|
||||
|
|
@ -81,11 +79,4 @@ public final class DashUtilTest extends TestCase {
|
|||
new byte[]{1, 4, 7, 0, 3, 6}));
|
||||
}
|
||||
|
||||
private static DataSource newDataSource() {
|
||||
// TODO: Use DummyDataSource when available.
|
||||
FakeDataSource fakeDataSource = new FakeDataSource();
|
||||
fakeDataSource.getDataSet().newDefaultData().appendReadError(new IOException("Unexpected"));
|
||||
return fakeDataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue