From 3f0a52b9e2b2538a87ee76354c5ee879da60dcce Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 27 Dec 2012 15:02:37 +0100 Subject: [PATCH] Bug 823921 - Replaced _com_ptr_t usage by RefPtr r=paul --- content/media/wmf/WMF.h | 8 ------ content/media/wmf/WMFByteStream.cpp | 29 ++++++++++----------- content/media/wmf/WMFReader.cpp | 39 +++++++++++++++-------------- content/media/wmf/WMFReader.h | 2 +- content/media/wmf/WMFUtils.cpp | 5 ++-- 5 files changed, 39 insertions(+), 44 deletions(-) diff --git a/content/media/wmf/WMF.h b/content/media/wmf/WMF.h index e975cf866a6..7017b0595d6 100644 --- a/content/media/wmf/WMF.h +++ b/content/media/wmf/WMF.h @@ -26,20 +26,12 @@ which makes Windows Media Foundation unavailable. #include #include #include -#include #include #include #pragma comment(lib,"uuid.lib") #pragma comment(lib,"mfuuid.lib") -_COM_SMARTPTR_TYPEDEF(IMFSourceReader, IID_IMFSourceReader); -_COM_SMARTPTR_TYPEDEF(IMFMediaType, IID_IMFMediaType); -_COM_SMARTPTR_TYPEDEF(IMFSample, IID_IMFSample); -_COM_SMARTPTR_TYPEDEF(IMFMediaBuffer, IID_IMFMediaBuffer); -_COM_SMARTPTR_TYPEDEF(IMFAsyncResult, IID_IMFAsyncResult); -_COM_SMARTPTR_TYPEDEF(IMF2DBuffer, IID_IMF2DBuffer); - namespace mozilla { namespace wmf { diff --git a/content/media/wmf/WMFByteStream.cpp b/content/media/wmf/WMFByteStream.cpp index 3b468552b45..5edb30da79a 100644 --- a/content/media/wmf/WMFByteStream.cpp +++ b/content/media/wmf/WMFByteStream.cpp @@ -6,13 +6,14 @@ #include "WMF.h" -#include "Unknwn.h" +#include #include #include "WMFByteStream.h" #include "WMFUtils.h" #include "MediaResource.h" #include "nsISeekableStream.h" +#include "mozilla/RefPtr.h" namespace mozilla { @@ -139,15 +140,15 @@ WMFByteStream::BeginRead(BYTE *aBuffer, mOffset, mResource->Tell(), aLength); // Create an object to store our state. - IUnknownPtr requestState = new AsyncReadRequestState(mOffset, aBuffer, aLength); + RefPtr requestState = new AsyncReadRequestState(mOffset, aBuffer, aLength); // Create an IMFAsyncResult, this is passed back to the caller as a token to // retrieve the number of bytes read. - IMFAsyncResultPtr callersResult; + RefPtr callersResult; HRESULT hr = wmf::MFCreateAsyncResult(requestState, aCallback, aCallerState, - &callersResult); + byRef(callersResult)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); // Queue a work item on our Windows Media Foundation work queue to call @@ -173,18 +174,18 @@ WMFByteStream::Invoke(IMFAsyncResult* aResult) // media resoure. // Extract the caller's IMFAsyncResult object from the wrapping aResult object. - IMFAsyncResultPtr callerResult; - IUnknownPtr unknown; - HRESULT hr = aResult->GetState(&unknown); + RefPtr callerResult; + RefPtr unknown; + HRESULT hr = aResult->GetState(byRef(unknown)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); - callerResult = unknown; - NS_ENSURE_TRUE(callerResult, E_FAIL); + hr = unknown->QueryInterface(static_cast(byRef(callerResult))); + NS_ENSURE_TRUE(SUCCEEDED(hr), E_FAIL); // Get the object that holds our state information for the asynchronous call. - hr = callerResult->GetObject(&unknown); + hr = callerResult->GetObject(byRef(unknown)); NS_ENSURE_TRUE(SUCCEEDED(hr) && unknown, hr); AsyncReadRequestState* requestState = - static_cast(unknown.GetInterfacePtr()); + static_cast(unknown.get()); // Ensure the read head is at the correct offset in the resource. It may not // be if the SourceReader seeked. @@ -256,13 +257,13 @@ WMFByteStream::EndRead(IMFAsyncResult* aResult, ULONG *aBytesRead) ReentrantMonitorAutoEnter mon(mReentrantMonitor); // Extract our state object. - IUnknownPtr unknown; - HRESULT hr = aResult->GetObject(&unknown); + RefPtr unknown; + HRESULT hr = aResult->GetObject(byRef(unknown)); if (FAILED(hr) || !unknown) { return E_INVALIDARG; } AsyncReadRequestState* requestState = - static_cast(unknown.GetInterfacePtr()); + static_cast(unknown.get()); // Important: Only advance the read cursor if the caller hasn't seeked // since it called BeginRead(). If it has seeked, we still must report diff --git a/content/media/wmf/WMFReader.cpp b/content/media/wmf/WMFReader.cpp index c4e73e76388..40666ff24d4 100644 --- a/content/media/wmf/WMFReader.cpp +++ b/content/media/wmf/WMFReader.cpp @@ -118,12 +118,12 @@ ConfigureSourceReaderStream(IMFSourceReader *aReader, NS_ENSURE_TRUE(aReader, E_POINTER); NS_ENSURE_TRUE(aAllowedInSubTypes, E_POINTER); - IMFMediaTypePtr nativeType; - IMFMediaTypePtr type; + RefPtr nativeType; + RefPtr type; HRESULT hr; // Find the native format of the stream. - hr = aReader->GetNativeMediaType(aStreamIndex, 0, &nativeType); + hr = aReader->GetNativeMediaType(aStreamIndex, 0, byRef(nativeType)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); // Get the native output subtype of the stream. This denotes the uncompressed @@ -152,7 +152,7 @@ ConfigureSourceReaderStream(IMFSourceReader *aReader, NS_ENSURE_TRUE(SUCCEEDED(hr), hr); // Define the output type. - hr = wmf::MFCreateMediaType(&type); + hr = wmf::MFCreateMediaType(byRef(type)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); hr = type->SetGUID(MF_MT_MAJOR_TYPE, majorType); @@ -258,9 +258,9 @@ WMFReader::ConfigureVideoDecoder() return; } - IMFMediaTypePtr mediaType; + RefPtr mediaType; hr = mSourceReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, - &mediaType); + byRef(mediaType)); if (FAILED(hr)) { NS_WARNING("Failed to get configured video media type"); return; @@ -324,9 +324,9 @@ WMFReader::ConfigureAudioDecoder() return; } - IMFMediaTypePtr mediaType; + RefPtr mediaType; HRESULT hr = mSourceReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, - &mediaType); + byRef(mediaType)); if (FAILED(hr)) { NS_WARNING("Failed to get configured audio media type"); return; @@ -353,7 +353,7 @@ WMFReader::ReadMetadata(VideoInfo* aInfo, LOG("WMFReader::ReadMetadata()"); HRESULT hr; - hr = wmf::MFCreateSourceReaderFromByteStream(mByteStream, NULL, &mSourceReader); + hr = wmf::MFCreateSourceReaderFromByteStream(mByteStream, NULL, byRef(mSourceReader)); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); ConfigureVideoDecoder(); @@ -396,13 +396,13 @@ WMFReader::DecodeAudioData() LONGLONG timestampHns; HRESULT hr; - IMFSamplePtr sample; + RefPtr sample; hr = mSourceReader->ReadSample(MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, // control flags nullptr, // read stream index &flags, ×tampHns, - &sample); + byRef(sample)); if (FAILED(hr) || (flags & MF_SOURCE_READERF_ERROR) || @@ -412,8 +412,8 @@ WMFReader::DecodeAudioData() return false; } - IMFMediaBufferPtr buffer; - hr = sample->ConvertToContiguousBuffer(&buffer); + RefPtr buffer; + hr = sample->ConvertToContiguousBuffer(byRef(buffer)); NS_ENSURE_TRUE(SUCCEEDED(hr), false); BYTE* data = nullptr; // Note: *data will be owned by the IMFMediaBuffer, we don't need to free it. @@ -461,13 +461,13 @@ WMFReader::DecodeVideoFrame(bool &aKeyframeSkip, LONGLONG timestampHns; HRESULT hr; - IMFSamplePtr sample; + RefPtr sample; hr = mSourceReader->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, // control flags nullptr, // read stream index &flags, ×tampHns, - &sample); + byRef(sample)); if (flags & MF_SOURCE_READERF_ERROR) { NS_WARNING("WMFReader: Catastrophic failure reading video sample"); // Future ReadSample() calls will fail, so give up and report end of stream. @@ -498,10 +498,10 @@ WMFReader::DecodeVideoFrame(bool &aKeyframeSkip, int64_t offset = mDecoder->GetResource()->Tell(); int64_t duration = GetSampleDuration(sample); - IMFMediaBufferPtr buffer; + RefPtr buffer; // Must convert to contiguous buffer to use IMD2DBuffer interface. - hr = sample->ConvertToContiguousBuffer(&buffer); + hr = sample->ConvertToContiguousBuffer(byRef(buffer)); if (FAILED(hr)) { NS_WARNING("ConvertToContiguousBuffer() failed!"); return true; @@ -512,8 +512,9 @@ WMFReader::DecodeVideoFrame(bool &aKeyframeSkip, // but only some systems (Windows 8?) support it. BYTE* data = nullptr; LONG stride = 0; - IMF2DBufferPtr twoDBuffer = buffer; - if (twoDBuffer) { + RefPtr twoDBuffer; + hr = buffer->QueryInterface(static_cast(byRef(twoDBuffer))); + if (SUCCEEDED(hr)) { hr = twoDBuffer->Lock2D(&data, &stride); NS_ENSURE_TRUE(SUCCEEDED(hr), false); } else { diff --git a/content/media/wmf/WMFReader.h b/content/media/wmf/WMFReader.h index bb559f0f7b7..51f5d4d54a6 100644 --- a/content/media/wmf/WMFReader.h +++ b/content/media/wmf/WMFReader.h @@ -50,7 +50,7 @@ private: void ConfigureAudioDecoder(); void ConfigureVideoDecoder(); - IMFSourceReaderPtr mSourceReader; + RefPtr mSourceReader; RefPtr mByteStream; uint32_t mAudioChannels; diff --git a/content/media/wmf/WMFUtils.cpp b/content/media/wmf/WMFUtils.cpp index 03fbfb28d3d..1b358ad78c9 100644 --- a/content/media/wmf/WMFUtils.cpp +++ b/content/media/wmf/WMFUtils.cpp @@ -6,6 +6,7 @@ #include "WMFUtils.h" #include "mozilla/StandardInteger.h" +#include "mozilla/RefPtr.h" #include "prlog.h" #include "nsThreadUtils.h" @@ -193,8 +194,8 @@ nsCString GetGUIDName(const GUID& guid) bool SourceReaderHasStream(IMFSourceReader* aReader, const DWORD aIndex) { - IMFMediaTypePtr nativeType; - HRESULT hr = aReader->GetNativeMediaType(aIndex, 0, &nativeType); + RefPtr nativeType; + HRESULT hr = aReader->GetNativeMediaType(aIndex, 0, byRef(nativeType)); return FAILED(hr) ? false : true; }