Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/video/capture/win/pin_base_win.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace media { | |
| 10 | |
| 11 // Implement IEnumPins. | |
| 12 class TypeEnumerator : public IEnumMediaTypes, | |
| 13 public base::RefCounted<TypeEnumerator> { | |
| 14 public: | |
| 15 explicit TypeEnumerator(PinBase* pin) | |
| 16 : pin_(pin), | |
| 17 index_(0), | |
| 18 ref_count_(0) { | |
| 19 } | |
| 20 | |
| 21 ~TypeEnumerator() { | |
| 22 } | |
| 23 | |
| 24 // Implement from IUnknown. | |
| 25 STDMETHOD(QueryInterface)(REFIID iid, void** object_ptr) { | |
| 26 if (iid == IID_IEnumMediaTypes || iid == IID_IUnknown) { | |
| 27 AddRef(); | |
| 28 *object_ptr = static_cast<IEnumMediaTypes*>(this); | |
| 29 return S_OK; | |
| 30 } | |
| 31 return E_NOINTERFACE; | |
| 32 } | |
| 33 | |
| 34 STDMETHOD_(ULONG, AddRef)() { | |
| 35 base::RefCounted<TypeEnumerator>::AddRef(); | |
| 36 return ++ref_count_; | |
| 37 } | |
| 38 | |
| 39 STDMETHOD_(ULONG, Release)() { | |
| 40 int ret = --ref_count_; | |
| 41 base::RefCounted<TypeEnumerator>::Release(); | |
| 42 return ret; | |
| 43 } | |
| 44 | |
| 45 // Implement IEnumMediaTypes. | |
| 46 STDMETHOD(Next)(ULONG count, AM_MEDIA_TYPE** types, ULONG* fetched) { | |
| 47 ULONG types_fetched = 0; | |
| 48 | |
| 49 while (types_fetched < count) { | |
| 50 // Allocate AM_MEDIA_TYPE that we will store the media type in. | |
| 51 AM_MEDIA_TYPE* type = static_cast<AM_MEDIA_TYPE*> (CoTaskMemAlloc( | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
This should be reinterpret_cast.
Also, no space be
Per K
2011/06/27 11:47:50
Done.
| |
| 52 sizeof(AM_MEDIA_TYPE))); | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
indent
Per K
2011/06/27 11:47:50
Done.
| |
| 53 if (!type) { | |
| 54 FreeAllocatedMediaTypes(types_fetched, types); | |
| 55 return E_OUTOFMEMORY; | |
| 56 } | |
| 57 ZeroMemory(type, sizeof(AM_MEDIA_TYPE)); | |
| 58 | |
| 59 // Allocate a VIDEOINFOHEADER and connect it to the AM_MEDIA_TYPE. | |
| 60 type->cbFormat = sizeof(VIDEOINFOHEADER); | |
| 61 BYTE *format = static_cast<BYTE*> (CoTaskMemAlloc( | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
BYTE* format = ...
same as above for cast and spac
Per K
2011/06/27 11:47:50
Done.
| |
| 62 sizeof(VIDEOINFOHEADER))); | |
| 63 if (!format) { | |
| 64 CoTaskMemFree(type); | |
| 65 FreeAllocatedMediaTypes(types_fetched, types); | |
| 66 return E_OUTOFMEMORY; | |
| 67 } | |
| 68 type->pbFormat = format; | |
| 69 // Get the media type from the pin. | |
| 70 if (pin_->GetValidMediaType(index_++, type)) { | |
| 71 types[types_fetched++] = type; | |
| 72 } else { | |
| 73 CoTaskMemFree(format); | |
| 74 CoTaskMemFree(type); | |
| 75 break; | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 if (fetched) | |
| 80 *fetched = types_fetched; | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
fix space
Per K
2011/06/27 11:47:50
Done.
| |
| 81 | |
| 82 return types_fetched == count ? S_OK : S_FALSE; | |
| 83 } | |
| 84 | |
| 85 STDMETHOD(Skip)(ULONG count) { | |
| 86 index_ += count; | |
| 87 return S_OK; | |
| 88 } | |
| 89 | |
| 90 STDMETHOD(Reset)() { | |
| 91 index_ = 0; | |
| 92 return S_OK; | |
| 93 } | |
| 94 | |
| 95 STDMETHOD(Clone)(IEnumMediaTypes** clone) { | |
| 96 TypeEnumerator* type_enum = new TypeEnumerator(pin_); | |
| 97 if (!type_enum) | |
| 98 return E_OUTOFMEMORY; | |
| 99 type_enum->AddRef(); | |
| 100 type_enum->index_ = index_; | |
| 101 *clone = type_enum; | |
| 102 return S_OK; | |
| 103 } | |
| 104 | |
| 105 private: | |
| 106 void FreeAllocatedMediaTypes(int allocated, AM_MEDIA_TYPE** types) { | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
should allocated be of type ULONG? (and |i| in the
Per K
2011/06/27 11:47:50
Done.
| |
| 107 for (int i = 0; i < allocated; ++i) { | |
| 108 CoTaskMemFree(types[i]->pbFormat); | |
| 109 CoTaskMemFree(types[i]); | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 scoped_refptr<PinBase> pin_; | |
| 114 int index_; | |
| 115 int ref_count_; | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
remove?
Per K
2011/06/27 11:47:50
Done.
| |
| 116 }; | |
| 117 | |
| 118 PinBase::PinBase(IBaseFilter* owner) | |
| 119 : owner_(owner), | |
| 120 connected_pin_(NULL) { | |
| 121 } | |
| 122 | |
| 123 PinBase::~PinBase() { | |
| 124 } | |
| 125 | |
| 126 /* Called on an output pin to and establish a | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
use // instead of /*
same throughout.
Per K
2011/06/27 11:47:50
Done.
| |
| 127 connection. | |
| 128 */ | |
| 129 STDMETHODIMP PinBase::Connect(IPin* receive_pin, const AM_MEDIA_TYPE* mt) { | |
| 130 if (!receive_pin || !mt) | |
| 131 return E_POINTER; | |
| 132 | |
| 133 current_media_type_ = *mt; | |
| 134 connected_pin_ = receive_pin; | |
| 135 receive_pin->AddRef(); | |
| 136 HRESULT hr = receive_pin->ReceiveConnection(this, mt); | |
| 137 | |
| 138 return hr; | |
| 139 } | |
| 140 | |
| 141 /* Called from an output pin on an input pin to and establish a | |
| 142 connection. | |
| 143 */ | |
| 144 STDMETHODIMP PinBase::ReceiveConnection(IPin* connector, | |
| 145 const AM_MEDIA_TYPE* mt) { | |
| 146 if (IsMediaTypeValid(mt)) { | |
| 147 connected_pin_ = connector; | |
| 148 current_media_type_ = current_media_type_; | |
| 149 connected_pin_->AddRef(); | |
| 150 return S_OK; | |
| 151 } | |
| 152 return VFW_E_TYPE_NOT_ACCEPTED; | |
| 153 } | |
| 154 | |
| 155 STDMETHODIMP PinBase::Disconnect() { | |
| 156 if (connected_pin_) { | |
| 157 int r = connected_pin_->Release(); | |
| 158 connected_pin_ = NULL; | |
| 159 return S_OK; | |
| 160 } | |
| 161 return S_FALSE; | |
| 162 } | |
| 163 | |
| 164 STDMETHODIMP PinBase::ConnectedTo(IPin** pin) { | |
| 165 *pin = connected_pin_; | |
| 166 if (connected_pin_ != NULL) { | |
| 167 int r = connected_pin_->AddRef(); | |
| 168 return S_OK; | |
| 169 } else { | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
nit: no need for an else. just do as above.
Per K
2011/06/27 11:47:50
Done.
| |
| 170 return VFW_E_NOT_CONNECTED; | |
| 171 } | |
| 172 } | |
| 173 | |
| 174 STDMETHODIMP PinBase::ConnectionMediaType(AM_MEDIA_TYPE* mt) { | |
| 175 if (!connected_pin_) { | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
nit: remove braces
Per K
2011/06/27 11:47:50
Done.
| |
| 176 return VFW_E_NOT_CONNECTED; | |
| 177 } | |
| 178 *mt = current_media_type_; | |
| 179 return S_OK; | |
| 180 } | |
| 181 | |
| 182 STDMETHODIMP PinBase::QueryPinInfo(PIN_INFO* pInfo) { | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
remove hungarian
Per K
2011/06/27 11:47:50
Done.
| |
| 183 pInfo->dir = PINDIR_INPUT; | |
| 184 pInfo->pFilter = owner_; | |
| 185 if (owner_) { | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
nit: remove braces
Per K
2011/06/27 11:47:50
Done.
| |
| 186 owner_->AddRef(); | |
| 187 } | |
| 188 pInfo->achName[0] = L'\0'; | |
| 189 | |
| 190 return S_OK; | |
| 191 } | |
| 192 | |
| 193 STDMETHODIMP PinBase::QueryDirection(PIN_DIRECTION* pin_dir) { | |
| 194 *pin_dir = PINDIR_INPUT; | |
| 195 return S_OK; | |
| 196 } | |
| 197 | |
| 198 STDMETHODIMP PinBase::QueryId(LPWSTR* Id) { | |
| 199 NOTREACHED(); | |
| 200 return E_OUTOFMEMORY; | |
| 201 } | |
| 202 | |
| 203 STDMETHODIMP PinBase::QueryAccept(const AM_MEDIA_TYPE* mt) { | |
| 204 return S_FALSE; | |
| 205 } | |
| 206 | |
| 207 STDMETHODIMP PinBase::EnumMediaTypes(IEnumMediaTypes** types) { | |
| 208 *types = new TypeEnumerator(this); | |
| 209 (*types)->AddRef(); | |
| 210 return S_OK; | |
| 211 } | |
| 212 | |
| 213 STDMETHODIMP PinBase::QueryInternalConnections(IPin** pins, ULONG* count) { | |
| 214 return E_NOTIMPL; | |
| 215 } | |
| 216 | |
| 217 STDMETHODIMP PinBase::EndOfStream() { | |
| 218 return S_OK; | |
| 219 } | |
| 220 | |
| 221 STDMETHODIMP PinBase::BeginFlush() { | |
| 222 return S_OK; | |
| 223 } | |
| 224 | |
| 225 STDMETHODIMP PinBase::EndFlush() { | |
| 226 return S_OK; | |
| 227 } | |
| 228 | |
| 229 STDMETHODIMP PinBase::NewSegment(REFERENCE_TIME start, REFERENCE_TIME stop, | |
| 230 double rate) { | |
| 231 NOTREACHED(); | |
| 232 return E_NOTIMPL; | |
| 233 } | |
| 234 | |
| 235 // Inherited from IMemInputPin. | |
| 236 STDMETHODIMP PinBase::GetAllocator(IMemAllocator** allocator) { | |
| 237 return VFW_E_NO_ALLOCATOR; | |
| 238 } | |
| 239 | |
| 240 STDMETHODIMP PinBase::NotifyAllocator(IMemAllocator* allocator, | |
| 241 BOOL read_only) { | |
| 242 return S_OK; | |
| 243 } | |
| 244 | |
| 245 STDMETHODIMP PinBase::GetAllocatorRequirements(ALLOCATOR_PROPERTIES* props) { | |
| 246 return E_NOTIMPL; | |
| 247 } | |
| 248 | |
| 249 STDMETHODIMP PinBase::ReceiveMultiple(IMediaSample** samples, | |
| 250 long sample_count, | |
| 251 long* processed) { | |
| 252 NOTREACHED(); | |
| 253 return VFW_E_INVALIDMEDIATYPE; | |
| 254 } | |
| 255 | |
| 256 STDMETHODIMP PinBase::ReceiveCanBlock() { | |
| 257 return S_FALSE; | |
| 258 } | |
| 259 | |
| 260 // Inherited from IUnknown. | |
| 261 STDMETHODIMP PinBase::QueryInterface(REFIID id, void** object_ptr) { | |
| 262 if (id == IID_IPin || id == IID_IUnknown) { | |
| 263 AddRef(); | |
| 264 *object_ptr = static_cast<IPin*>(this); | |
| 265 } else if (id == IID_IMemInputPin) { | |
| 266 AddRef(); | |
| 267 *object_ptr = static_cast<IMemInputPin*>(this); | |
| 268 } else { | |
| 269 return E_NOINTERFACE; | |
| 270 } | |
| 271 return S_OK; | |
| 272 } | |
| 273 | |
| 274 STDMETHODIMP_(ULONG) PinBase::AddRef() { | |
| 275 base::RefCounted<PinBase>::AddRef(); | |
| 276 return owner_->AddRef(); | |
| 277 } | |
| 278 | |
| 279 STDMETHODIMP_(ULONG) PinBase::Release() { | |
| 280 int ret = owner_->Release(); | |
|
tommi (sloooow) - chröme
2011/06/23 14:05:56
this looks like it could be a circular reference.
Per K
2011/06/27 11:47:50
This is to make sure the owner is not deleted befo
| |
| 281 base::RefCounted<PinBase>::Release(); | |
| 282 return ret; | |
| 283 } | |
| 284 | |
| 285 } // namespace media | |
| OLD | NEW |