mirror of
https://github.com/androidx/media.git
synced 2025-05-14 02:59:52 +08:00
Fix CronetDataSource handling of 200 response for range request
Issue: #8090 #minor-release PiperOrigin-RevId: 342638922
This commit is contained in:
parent
5698eadc08
commit
1f49867746
@ -34,6 +34,9 @@
|
||||
* Fix a bug that caused multiple ads in an ad pod to be skipped when one
|
||||
ad in the ad pod was skipped.
|
||||
* Fix passing an ads response to the `ImaAdsLoader` builder.
|
||||
* Cronet extension:
|
||||
* Fix handling of HTTP status code 200 when making unbounded length range
|
||||
requests ([#8090](https://github.com/google/ExoPlayer/issues/8090)).
|
||||
* Text
|
||||
* Allow tx3g subtitles with `styl` boxes with start and/or end offsets
|
||||
that lie outside the length of the cue text.
|
||||
|
@ -506,7 +506,9 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||
if (dataSpec.length != C.LENGTH_UNSET) {
|
||||
bytesRemaining = dataSpec.length;
|
||||
} else {
|
||||
bytesRemaining = getContentLength(responseInfo);
|
||||
long contentLength = getContentLength(responseInfo);
|
||||
bytesRemaining =
|
||||
contentLength != C.LENGTH_UNSET ? (contentLength - bytesToSkip) : C.LENGTH_UNSET;
|
||||
}
|
||||
} else {
|
||||
// If the response is compressed then the content length will be that of the compressed data
|
||||
|
@ -534,7 +534,8 @@ public final class CronetDataSourceTest {
|
||||
testUrlResponseInfo = createUrlResponseInfo(206); // Server supports range requests.
|
||||
testDataSpec = new DataSpec(Uri.parse(TEST_URL), 1000, 5000);
|
||||
|
||||
dataSourceUnderTest.open(testDataSpec);
|
||||
long length = dataSourceUnderTest.open(testDataSpec);
|
||||
assertThat(length).isEqualTo(5000);
|
||||
|
||||
byte[] returnedBuffer = new byte[16];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
||||
@ -551,7 +552,26 @@ public final class CronetDataSourceTest {
|
||||
testUrlResponseInfo = createUrlResponseInfo(200); // Server does not support range requests.
|
||||
testDataSpec = new DataSpec(Uri.parse(TEST_URL), 1000, 5000);
|
||||
|
||||
dataSourceUnderTest.open(testDataSpec);
|
||||
long length = dataSourceUnderTest.open(testDataSpec);
|
||||
assertThat(length).isEqualTo(5000);
|
||||
|
||||
byte[] returnedBuffer = new byte[16];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
||||
assertThat(bytesRead).isEqualTo(16);
|
||||
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(1000, 16));
|
||||
verify(mockTransferListener)
|
||||
.onBytesTransferred(dataSourceUnderTest, testDataSpec, /* isNetwork= */ true, 16);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unboundedRangeRequestWith200Response() throws HttpDataSourceException {
|
||||
mockResponseStartSuccess();
|
||||
mockReadSuccess(0, (int) TEST_CONTENT_LENGTH);
|
||||
testUrlResponseInfo = createUrlResponseInfo(200); // Server does not support range requests.
|
||||
testDataSpec = new DataSpec(Uri.parse(TEST_URL), 1000, C.LENGTH_UNSET);
|
||||
|
||||
long length = dataSourceUnderTest.open(testDataSpec);
|
||||
assertThat(length).isEqualTo(TEST_CONTENT_LENGTH - 1000);
|
||||
|
||||
byte[] returnedBuffer = new byte[16];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
||||
@ -777,7 +797,8 @@ public final class CronetDataSourceTest {
|
||||
testUrlResponseInfo = createUrlResponseInfo(206); // Server supports range requests.
|
||||
testDataSpec = new DataSpec(Uri.parse(TEST_URL), 1000, 5000);
|
||||
|
||||
dataSourceUnderTest.open(testDataSpec);
|
||||
long length = dataSourceUnderTest.open(testDataSpec);
|
||||
assertThat(length).isEqualTo(5000);
|
||||
|
||||
ByteBuffer returnedBuffer = ByteBuffer.allocateDirect(16);
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer);
|
||||
@ -796,7 +817,8 @@ public final class CronetDataSourceTest {
|
||||
testUrlResponseInfo = createUrlResponseInfo(200); // Server does not support range requests.
|
||||
testDataSpec = new DataSpec(Uri.parse(TEST_URL), 1000, 5000);
|
||||
|
||||
dataSourceUnderTest.open(testDataSpec);
|
||||
long length = dataSourceUnderTest.open(testDataSpec);
|
||||
assertThat(length).isEqualTo(5000);
|
||||
|
||||
ByteBuffer returnedBuffer = ByteBuffer.allocateDirect(16);
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user