M mmf.cpp +1 -1
@@ 15,7 15,7 @@
namespace {
std::wstring_convert<std::codecvt_utf8_utf16<TCHAR>> utf8cvt;
- template <typename T> using COM = ATL::CComPtr<T>;
+ template <typename T> using COM = MF::COM<T>;
std::string GetWinError(HRESULT hr) {
_com_error error(hr);
M mmfspackle.h +58 -2
@@ 4,14 4,70 @@
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
-#include <atlbase.h>
#include <cassert>
#include <functional>
#include <vector>
namespace MF {
- template <typename T> using COM = ATL::CComPtr<T>;
+ template <typename T> class COM {
+ mutable T* ptr = nullptr;
+ public:
+ template <typename U> COM(U* s = nullptr):ptr(s) {
+ Retain();
+ }
+
+ COM() { }
+
+ COM(const COM<T>& src) :ptr(src) {
+ Retain();
+ }
+
+ COM(COM<T>&& src) {
+ std::swap(ptr, src.ptr);
+ }
+
+ ~COM() {
+ Release();
+ }
+
+ operator T* () const { return ptr; }
+ operator T* () { return ptr; }
+
+ T** operator & () {
+ Release();
+ return &ptr;
+ }
+
+ COM<T>& operator=(COM<T>&& src) {
+ std::swap(ptr, src.ptr);
+ return *this;
+ }
+
+ COM<T>& operator=(const COM<T>& src) {
+ src.Retain();
+ Release();
+ ptr = src.ptr;
+ return *this;
+ }
+
+ void Retain() const {
+ if (ptr) ptr->AddRef();
+ }
+
+ void Release() const {
+ if (ptr) ptr->Release();
+ ptr = nullptr;
+ }
+
+ T* operator->() {
+ return ptr;
+ }
+
+ T* operator->() const {
+ return ptr;
+ }
+ };
class MediaType {
friend class SourceReader;