mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 09:49:14 +00:00
Bug 839031 - Implement WMFByteStream::Read(). r=padenot
This commit is contained in:
parent
60678029fa
commit
8562d13911
@ -192,9 +192,9 @@ NS_IMPL_THREADSAFE_RELEASE(WMFByteStream)
|
||||
|
||||
|
||||
// Stores data regarding an async read opreation.
|
||||
class AsyncReadRequest MOZ_FINAL : public IUnknown {
|
||||
class ReadRequest MOZ_FINAL : public IUnknown {
|
||||
public:
|
||||
AsyncReadRequest(int64_t aOffset, BYTE* aBuffer, ULONG aLength)
|
||||
ReadRequest(int64_t aOffset, BYTE* aBuffer, ULONG aLength)
|
||||
: mOffset(aOffset),
|
||||
mBuffer(aBuffer),
|
||||
mBufferLength(aLength),
|
||||
@ -216,14 +216,14 @@ public:
|
||||
NS_DECL_OWNINGTHREAD
|
||||
};
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(AsyncReadRequest)
|
||||
NS_IMPL_THREADSAFE_RELEASE(AsyncReadRequest)
|
||||
NS_IMPL_THREADSAFE_ADDREF(ReadRequest)
|
||||
NS_IMPL_THREADSAFE_RELEASE(ReadRequest)
|
||||
|
||||
// IUnknown Methods
|
||||
STDMETHODIMP
|
||||
AsyncReadRequest::QueryInterface(REFIID aIId, void **aInterface)
|
||||
ReadRequest::QueryInterface(REFIID aIId, void **aInterface)
|
||||
{
|
||||
LOG("AsyncReadRequest::QueryInterface %s", GetGUIDName(aIId).get());
|
||||
LOG("ReadRequest::QueryInterface %s", GetGUIDName(aIId).get());
|
||||
|
||||
if (aIId == IID_IUnknown) {
|
||||
return DoGetInterface(static_cast<IUnknown*>(this), aInterface);
|
||||
@ -237,7 +237,7 @@ class ProcessReadRequestEvent MOZ_FINAL : public nsRunnable {
|
||||
public:
|
||||
ProcessReadRequestEvent(WMFByteStream* aStream,
|
||||
IMFAsyncResult* aResult,
|
||||
AsyncReadRequest* aRequestState)
|
||||
ReadRequest* aRequestState)
|
||||
: mStream(aStream),
|
||||
mResult(aResult),
|
||||
mRequestState(aRequestState) {}
|
||||
@ -249,7 +249,7 @@ public:
|
||||
private:
|
||||
RefPtr<WMFByteStream> mStream;
|
||||
RefPtr<IMFAsyncResult> mResult;
|
||||
RefPtr<AsyncReadRequest> mRequestState;
|
||||
RefPtr<ReadRequest> mRequestState;
|
||||
};
|
||||
|
||||
// IMFByteStream Methods
|
||||
@ -271,7 +271,7 @@ WMFByteStream::BeginRead(BYTE *aBuffer,
|
||||
}
|
||||
|
||||
// Create an object to store our state.
|
||||
RefPtr<AsyncReadRequest> requestState = new AsyncReadRequest(mOffset, aBuffer, aLength);
|
||||
RefPtr<ReadRequest> requestState = new ReadRequest(mOffset, aBuffer, aLength);
|
||||
|
||||
// Create an IMFAsyncResult, this is passed back to the caller as a token to
|
||||
// retrieve the number of bytes read.
|
||||
@ -298,7 +298,7 @@ WMFByteStream::BeginRead(BYTE *aBuffer,
|
||||
}
|
||||
|
||||
nsresult
|
||||
WMFByteStream::Read(AsyncReadRequest* aRequestState)
|
||||
WMFByteStream::Read(ReadRequest* aRequestState)
|
||||
{
|
||||
ReentrantMonitorAutoEnter mon(mResourceMonitor);
|
||||
|
||||
@ -334,7 +334,7 @@ WMFByteStream::Read(AsyncReadRequest* aRequestState)
|
||||
// Note: This is called on one of the thread pool's threads.
|
||||
void
|
||||
WMFByteStream::ProcessReadRequest(IMFAsyncResult* aResult,
|
||||
AsyncReadRequest* aRequestState)
|
||||
ReadRequest* aRequestState)
|
||||
{
|
||||
if (mResource->GetLength() > -1 &&
|
||||
aRequestState->mOffset > mResource->GetLength()) {
|
||||
@ -390,8 +390,8 @@ WMFByteStream::EndRead(IMFAsyncResult* aResult, ULONG *aBytesRead)
|
||||
if (FAILED(hr) || !unknown) {
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
AsyncReadRequest* requestState =
|
||||
static_cast<AsyncReadRequest*>(unknown.get());
|
||||
ReadRequest* requestState =
|
||||
static_cast<ReadRequest*>(unknown.get());
|
||||
|
||||
// Report result.
|
||||
*aBytesRead = requestState->mBytesRead;
|
||||
@ -477,10 +477,21 @@ WMFByteStream::IsEndOfStream(BOOL *aEndOfStream)
|
||||
}
|
||||
|
||||
STDMETHODIMP
|
||||
WMFByteStream::Read(BYTE*, ULONG, ULONG*)
|
||||
WMFByteStream::Read(BYTE* aBuffer, ULONG aBufferLength, ULONG* aOutBytesRead)
|
||||
{
|
||||
LOG("WMFByteStream::Read()");
|
||||
return E_NOTIMPL;
|
||||
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
||||
ReadRequest request(mOffset, aBuffer, aBufferLength);
|
||||
if (NS_FAILED(Read(&request))) {
|
||||
LOG("WMFByteStream::Read() offset=%lld failed!", mOffset);
|
||||
return E_FAIL;
|
||||
}
|
||||
if (aOutBytesRead) {
|
||||
*aOutBytesRead = request.mBytesRead;
|
||||
}
|
||||
LOG("WMFByteStream::Read() offset=%lld length=%u bytesRead=%u",
|
||||
mOffset, aBufferLength, request.mBytesRead);
|
||||
mOffset += request.mBytesRead;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP
|
||||
|
@ -19,13 +19,13 @@ class nsIThreadPool;
|
||||
namespace mozilla {
|
||||
|
||||
class MediaResource;
|
||||
class AsyncReadRequest;
|
||||
class ReadRequest;
|
||||
|
||||
// Wraps a MediaResource around an IMFByteStream interface, so that it can
|
||||
// be used by the IMFSourceReader. Each WMFByteStream creates a WMF Work Queue
|
||||
// on which blocking I/O is performed. The SourceReader requests reads
|
||||
// asynchronously using {Begin,End}Read(). The synchronous I/O methods aren't
|
||||
// used by the SourceReader, so they're not implemented on this class.
|
||||
// asynchronously using {Begin,End}Read(), and more rarely synchronously
|
||||
// using Read().
|
||||
//
|
||||
// Note: This implementation attempts to be bug-compatible with Windows Media
|
||||
// Foundation's implementation of IMFByteStream. The behaviour of WMF's
|
||||
@ -75,12 +75,12 @@ public:
|
||||
// Processes an async read request, storing the result in aResult, and
|
||||
// notifying the caller when the read operation is complete.
|
||||
void ProcessReadRequest(IMFAsyncResult* aResult,
|
||||
AsyncReadRequest* aRequestState);
|
||||
ReadRequest* aRequestState);
|
||||
private:
|
||||
|
||||
// Locks the MediaResource and performs the read. This is a helper
|
||||
// for ProcessReadRequest().
|
||||
nsresult Read(AsyncReadRequest* aRequestState);
|
||||
// Locks the MediaResource and performs the read. The other read methods
|
||||
// call this function.
|
||||
nsresult Read(ReadRequest* aRequestState);
|
||||
|
||||
// Returns true if the current position of the stream is at end of stream.
|
||||
bool IsEOS();
|
||||
|
Loading…
x
Reference in New Issue
Block a user