Source length calculation in ContentDataSource changed#2963
Source length calculation in ContentDataSource changed#2963ojw28 merged 4 commits intogoogle:dev-v2from
Conversation
ojw28
left a comment
There was a problem hiding this comment.
Thanks for finding this! Please find a couple of comments inlined.
| uri = dataSpec.uri; | ||
| assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r"); | ||
| inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor()); | ||
| inputStream = assetFileDescriptor.createInputStream(); |
There was a problem hiding this comment.
Rather than doing this, I think it would be preferable to modify L84 to do:
bytesRemaining = assetFileDescriptor.getLength();
if (bytesRemaining == AssetFileDescriptor.UNKNOWN_LENGTH) {
// The asset must extend to the end of the file.
bytesRemaining = inputStream.available();
if (bytesRemaining == 0) {
// FileInputStream.available() returns 0 if the remaining length cannot be determined, or
// if it's greater than Integer.MAX_VALUE. We don't know the true length in either case,
// so treat as unbounded.
bytesRemaining = C.LENGTH_UNSET;
}
}
Which makes it explicit what's going on (and also allows bytesRemaining to be greater than Integer.MAX_VALUE, at least in theory).
| import android.net.Uri; | ||
| import android.test.InstrumentationTestCase; | ||
|
|
||
| public class AndroidDataSourceTest extends InstrumentationTestCase { |
There was a problem hiding this comment.
Please split into separate AssetDataSourceTest and ContentDataSourceTest classes. Thanks.
|
Changed. |
|
Do you understand under what conditions null can actually be returned, and have you managed to reproduce? I see it's marked as If you do understand the conditions, and/or if handling is trivial anyway (which I guess it is), then yes feel free to fix in this PR. What will you do in that case though? Throw something? What? |
|
There may be a custom
something like that: |
|
Maybe |
|
Done. |
|
Thanks! |
| DataSpec dataSpec = new DataSpec(contentUri); | ||
| long sourceLengthBytes = dataSource.open(dataSpec); | ||
|
|
||
| assertEquals(SAMPLE_MP4_BYTES, sourceLengthBytes); |
There was a problem hiding this comment.
Hm, I tried to modify this test to also validate that the data being read was correct, but it appears the data read from the DataSource is not as expected. Any ideas?
There was a problem hiding this comment.
It is actually broken. Seems reverting back to using assetFileDescriptor.createInputStream(), as you had it originally, fixes the problem. As does adding inputStream.skip(assetFileDescriptor.getStartOffset()).
I'm working on a bit of a cleanup change, so will merge a fix as part of that.
Fixes
UnrecognizedInputFormatExceptions with valid files loaded fromcontent://URIs