1 // Copyright (c) 2012 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.
5 // Implement a simple base class for a DirectShow input pin. It may only be
6 // used in a single threaded apartment.
8 #ifndef MEDIA_VIDEO_CAPTURE_WIN_PIN_BASE_WIN_H_
9 #define MEDIA_VIDEO_CAPTURE_WIN_PIN_BASE_WIN_H_
11 // Avoid including strsafe.h via dshow as it will cause build warnings.
12 #define NO_DSHOW_STRSAFE
15 #include "base/memory/ref_counted.h"
16 #include "base/win/scoped_comptr.h"
20 class PinBase
: public IPin
,
22 public base::RefCounted
<PinBase
> {
24 explicit PinBase(IBaseFilter
* owner
);
26 // Function used for changing the owner.
27 // If the owner is deleted the owner should first call this function
29 void SetOwner(IBaseFilter
* owner
);
31 // Checks if a media type is acceptable. This is called when this pin is
32 // connected to an output pin. Must return true if the media type is
33 // acceptable, false otherwise.
34 virtual bool IsMediaTypeValid(const AM_MEDIA_TYPE
* media_type
) = 0;
36 // Enumerates valid media types.
37 virtual bool GetValidMediaType(int index
, AM_MEDIA_TYPE
* media_type
) = 0;
39 // Called when new media is received. Note that this is not on the same
40 // thread as where the pin is created.
41 STDMETHOD(Receive
)(IMediaSample
* sample
) override
= 0;
43 STDMETHOD(Connect
)(IPin
* receive_pin
,
44 const AM_MEDIA_TYPE
* media_type
) override
;
46 STDMETHOD(ReceiveConnection
)(IPin
* connector
,
47 const AM_MEDIA_TYPE
* media_type
) override
;
49 STDMETHOD(Disconnect
)() override
;
51 STDMETHOD(ConnectedTo
)(IPin
** pin
) override
;
53 STDMETHOD(ConnectionMediaType
)(AM_MEDIA_TYPE
* media_type
) override
;
55 STDMETHOD(QueryPinInfo
)(PIN_INFO
* info
) override
;
57 STDMETHOD(QueryDirection
)(PIN_DIRECTION
* pin_dir
) override
;
59 STDMETHOD(QueryId
)(LPWSTR
* id
) override
;
61 STDMETHOD(QueryAccept
)(const AM_MEDIA_TYPE
* media_type
) override
;
63 STDMETHOD(EnumMediaTypes
)(IEnumMediaTypes
** types
) override
;
65 STDMETHOD(QueryInternalConnections
)(IPin
** pins
, ULONG
* no_pins
) override
;
67 STDMETHOD(EndOfStream
)() override
;
69 STDMETHOD(BeginFlush
)() override
;
71 STDMETHOD(EndFlush
)() override
;
73 STDMETHOD(NewSegment
)(REFERENCE_TIME start
,
75 double dRate
) override
;
77 // Inherited from IMemInputPin.
78 STDMETHOD(GetAllocator
)(IMemAllocator
** allocator
) override
;
80 STDMETHOD(NotifyAllocator
)(IMemAllocator
* allocator
, BOOL read_only
) override
;
82 STDMETHOD(GetAllocatorRequirements
)(
83 ALLOCATOR_PROPERTIES
* properties
) override
;
85 STDMETHOD(ReceiveMultiple
)(IMediaSample
** samples
,
87 long* processed
) override
;
88 STDMETHOD(ReceiveCanBlock
)() override
;
90 // Inherited from IUnknown.
91 STDMETHOD(QueryInterface
)(REFIID id
, void** object_ptr
) override
;
93 STDMETHOD_(ULONG
, AddRef
)() override
;
95 STDMETHOD_(ULONG
, Release
)() override
;
98 friend class base::RefCounted
<PinBase
>;
102 AM_MEDIA_TYPE current_media_type_
;
103 base::win::ScopedComPtr
<IPin
> connected_pin_
;
104 // owner_ is the filter owning this pin. We don't reference count it since
105 // that would create a circular reference count.
111 #endif // MEDIA_VIDEO_CAPTURE_WIN_PIN_BASE_WIN_H_