mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1190238: P2. Have MediaResourceIndex::ReadAt() only stop early when reaching EOS or error. r=cpearce
MediaResource::ReadAt() requires to loop several times to ensure that all data has been read as it may return less data than requested. This will allow to remove the handling of this particular shortcoming in MediaResources' users.
This commit is contained in:
parent
b2f4db10c9
commit
1105f69a58
@ -1695,7 +1695,7 @@ MediaResourceIndex::Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes)
|
||||
// We purposefuly don't check that we may attempt to read past
|
||||
// mResource->GetLength() as the resource's length may change over time.
|
||||
|
||||
nsresult rv = mResource->ReadAt(mOffset, aBuffer, aCount, aBytes);
|
||||
nsresult rv = ReadAt(mOffset, aBuffer, aCount, aBytes);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
@ -1703,6 +1703,26 @@ MediaResourceIndex::Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
MediaResourceIndex::ReadAt(int64_t aOffset, char* aBuffer,
|
||||
uint32_t aCount, uint32_t* aBytes) const
|
||||
{
|
||||
*aBytes = 0;
|
||||
while (aCount > 0) {
|
||||
uint32_t bytesRead = 0;
|
||||
nsresult rv = mResource->ReadAt(aOffset, aBuffer, aCount, &bytesRead);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!bytesRead) {
|
||||
break;
|
||||
}
|
||||
*aBytes += bytesRead;
|
||||
aOffset += bytesRead;
|
||||
aBuffer += bytesRead;
|
||||
aCount -= bytesRead;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
MediaResourceIndex::Seek(int32_t aWhence, int64_t aOffset)
|
||||
{
|
||||
|
@ -832,20 +832,22 @@ public:
|
||||
// Return the underlying MediaResource.
|
||||
MediaResource* GetResource() const { return mResource; }
|
||||
|
||||
// Read up to aCount bytes from the stream. The read starts at
|
||||
// aOffset in the stream, seeking to that location initially if
|
||||
// it is not the current stream offset.
|
||||
// Unlike MediaResource::ReadAt, ReadAt only returns fewer bytes than
|
||||
// requested if end of stream or an error is encountered. There is no need to
|
||||
// call it again to get more data.
|
||||
// *aBytes will contain the number of bytes copied, even if an error occurred.
|
||||
// ReadAt doesn't have an impact on the offset returned by Tell().
|
||||
nsresult ReadAt(int64_t aOffset, char* aBuffer,
|
||||
uint32_t aCount, uint32_t* aBytes) const;
|
||||
|
||||
// Convenience methods, directly calling the MediaResource method of the same
|
||||
// name.
|
||||
// Those functions do not update the MediaResource offset as returned
|
||||
// by Tell().
|
||||
|
||||
// Read up to aCount bytes from the stream. The read starts at
|
||||
// aOffset in the stream, seeking to that location initially if
|
||||
// it is not the current stream offset. The remaining arguments,
|
||||
// results and requirements are the same as per the Read method.
|
||||
nsresult ReadAt(int64_t aOffset, char* aBuffer,
|
||||
uint32_t aCount, uint32_t* aBytes) const
|
||||
{
|
||||
return mResource->ReadAt(aOffset, aBuffer, aCount, aBytes);
|
||||
}
|
||||
// This method returns nullptr if anything fails.
|
||||
// Otherwise, it returns an owned buffer.
|
||||
// MediaReadAt may return fewer bytes than requested if end of stream is
|
||||
|
Loading…
Reference in New Issue
Block a user