• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 // Implement a simple base class for a DirectShow input pin. It may only be
6 // used in a single threaded apartment.
7 
8 #ifndef MEDIA_VIDEO_CAPTURE_WIN_PIN_BASE_WIN_H_
9 #define MEDIA_VIDEO_CAPTURE_WIN_PIN_BASE_WIN_H_
10 
11 // Avoid including strsafe.h via dshow as it will cause build warnings.
12 #define NO_DSHOW_STRSAFE
13 #include <dshow.h>
14 
15 #include "base/memory/ref_counted.h"
16 #include "base/win/scoped_comptr.h"
17 
18 namespace media {
19 
20 class PinBase
21     : public IPin,
22       public IMemInputPin,
23       public base::RefCounted<PinBase> {
24  public:
25   explicit PinBase(IBaseFilter* owner);
26   virtual ~PinBase();
27 
28   // Function used for changing the owner.
29   // If the owner is deleted the owner should first call this function
30   // with owner = NULL.
31   void SetOwner(IBaseFilter* owner);
32 
33   // Checks if a media type is acceptable. This is called when this pin is
34   // connected to an output pin. Must return true if the media type is
35   // acceptable, false otherwise.
36   virtual bool IsMediaTypeValid(const AM_MEDIA_TYPE* media_type) = 0;
37 
38   // Enumerates valid media types.
39   virtual bool GetValidMediaType(int index, AM_MEDIA_TYPE* media_type) = 0;
40 
41   // Called when new media is received. Note that this is not on the same
42   // thread as where the pin is created.
43   STDMETHOD(Receive)(IMediaSample* sample) = 0;
44 
45   STDMETHOD(Connect)(IPin* receive_pin, const AM_MEDIA_TYPE* media_type);
46 
47   STDMETHOD(ReceiveConnection)(IPin* connector,
48                                const AM_MEDIA_TYPE* media_type);
49 
50   STDMETHOD(Disconnect)();
51 
52   STDMETHOD(ConnectedTo)(IPin** pin);
53 
54   STDMETHOD(ConnectionMediaType)(AM_MEDIA_TYPE* media_type);
55 
56   STDMETHOD(QueryPinInfo)(PIN_INFO* info);
57 
58   STDMETHOD(QueryDirection)(PIN_DIRECTION* pin_dir);
59 
60   STDMETHOD(QueryId)(LPWSTR* id);
61 
62   STDMETHOD(QueryAccept)(const AM_MEDIA_TYPE* media_type);
63 
64   STDMETHOD(EnumMediaTypes)(IEnumMediaTypes** types);
65 
66   STDMETHOD(QueryInternalConnections)(IPin** pins, ULONG* no_pins);
67 
68   STDMETHOD(EndOfStream)();
69 
70   STDMETHOD(BeginFlush)();
71 
72   STDMETHOD(EndFlush)();
73 
74   STDMETHOD(NewSegment)(REFERENCE_TIME start,
75                         REFERENCE_TIME stop,
76                         double dRate);
77 
78   // Inherited from IMemInputPin.
79   STDMETHOD(GetAllocator)(IMemAllocator** allocator);
80 
81   STDMETHOD(NotifyAllocator)(IMemAllocator* allocator, BOOL read_only);
82 
83   STDMETHOD(GetAllocatorRequirements)(ALLOCATOR_PROPERTIES* properties);
84 
85   STDMETHOD(ReceiveMultiple)(IMediaSample** samples,
86                              long sample_count,
87                              long* processed);
88   STDMETHOD(ReceiveCanBlock)();
89 
90   // Inherited from IUnknown.
91   STDMETHOD(QueryInterface)(REFIID id, void** object_ptr);
92 
93   STDMETHOD_(ULONG, AddRef)();
94 
95   STDMETHOD_(ULONG, Release)();
96 
97  private:
98   AM_MEDIA_TYPE current_media_type_;
99   base::win::ScopedComPtr<IPin> connected_pin_;
100   // owner_ is the filter owning this pin. We don't reference count it since
101   // that would create a circular reference count.
102   IBaseFilter* owner_;
103 };
104 
105 }  // namespace media
106 
107 #endif  // MEDIA_VIDEO_CAPTURE_WIN_PIN_BASE_WIN_H_
108