OSVR-Core
directx_samplegrabber_callback.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_directx_samplegrabber_callback_h_GUID_F0A39DA1_440B_4E8A_AF25_1383D20934AA
26 #define INCLUDED_directx_samplegrabber_callback_h_GUID_F0A39DA1_440B_4E8A_AF25_1383D20934AA
27 
28 // Internal Includes
29 #include "MediaSampleExchange.h"
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <dshow.h>
36 #include "qedit_wrapper.h"
37 
38 // This class is used to handle callbacks from the SampleGrabber filter. It
39 // grabs each sample and holds onto it until the camera server that is
40 // associated with the object comes and gets it. The callback method in this
41 // class is called in another thread, so its methods need to be controlled:
42 // the MediaSampleExchange object shared between this object and the camera
43 // server regulates that produce/consume cycle.
44 class directx_samplegrabber_callback : public ISampleGrabberCB {
45  public:
46  directx_samplegrabber_callback(MediaSampleExchangePtr const &exchange);
48 
49  void shutdown();
50 
51  // These three methods must be defined because of the IUnknown parent class.
52  // XXX The first two are a hack to pretend that we are doing reference
53  // counting; this object must last longer than the sample grabber it is
54  // connected to in order to avoid segmentations faults.
55  STDMETHODIMP_(ULONG) AddRef(void) { return 1; }
56  STDMETHODIMP_(ULONG) Release(void) { return 2; }
57  STDMETHOD(QueryInterface)
58  (REFIID interfaceRequested, void **handleToInterfaceRequested);
59 
60  // One of the following two methods must be defined do to the
61  // ISampleGraberCB parent class; this is the way we hear from the grabber.
62  // We implement the one that gives us unbuffered access. Be sure to turn
63  // off buffering in the SampleGrabber that is associated with this callback
64  // handler.
65  STDMETHODIMP BufferCB(double, BYTE *, long) { return E_NOTIMPL; }
66  STDMETHOD(SampleCB)(double time, IMediaSample *sample);
67 
68  private:
69  BITMAPINFOHEADER _bitmapInfo; //< Describes format of the bitmap
70  volatile bool _stayAlive = true; //< Tells all threads to exit
71  MediaSampleExchangePtr sampleExchange_;
72 };
73 
74 #endif // INCLUDED_directx_samplegrabber_callback_h_GUID_F0A39DA1_440B_4E8A_AF25_1383D20934AA
void shutdown()
Definition: directx_samplegrabber_callback.cpp:49
Definition: directx_samplegrabber_callback.h:44