Avionics
Dropship Simulator
Webcam.h
Go to the documentation of this file.
1 #pragma once
2 
3 // have to include these in this order because bass.h refers to something that screws it up
4 #include <WinSock2.h>
5 #include <Windows.h>
6 //#include <WS2tcpip.h>
7 
8 #include <mfapi.h>
9 #include <mfidl.h>
10 #include <mfreadwrite.h>
11 //#include <Wmcodecdsp.h>
12 
13 #include "Bus.h"
14 
15 namespace Devices
16 {
18  {
19  public:
20  bool enabled = false;
21  std::wstring videoDevice;
22  std::wstring audioDevice;
23 
24  UINT width = 640;
25  UINT height = 480;
26  UINT frequency = 44100;
27  UINT channels = 1;
28  UINT numerator = 24;
29  UINT denominator = 1;
30  };
31 
32  class DeviceList
33  {
34  private:
35  UINT32 m_cDevices;
36  IMFActivate** m_ppDevices;
38 
39  public:
40  DeviceList(GUID guidDevice);
41 
43  {
44  Clear();
45  }
46 
47  UINT32 Count() const
48  {
49  return m_cDevices;
50  }
51 
52  void Clear();
54  HRESULT GetDevicebyID(std::wstring id, IMFActivate** ppActivate) const;
55  };
56 
57  class Webcam : public IMFSourceReaderCallback
58  {
59  private:
60  Logger* logger = nullptr;
61  WebcamConfig* config = nullptr;
62  Bus* bus = nullptr;
63 
64  bool initialized = false;
65  std::wstring pathAndFileName;
66  std::string pathAndFileNameA;
67 
70 
71  IMFActivate* pVideoActivate = nullptr;
72  IMFActivate* pAudioActivate = nullptr;
73 
74  IMFMediaSource* pVideoSource = nullptr;
75  IMFMediaSource* pAudioSource = nullptr;
76  IMFMediaSource* pSource = nullptr;
77 
78  long m_nRefCount = 0; // Reference count.
79  CRITICAL_SECTION m_critsec;
80 
81  IMFSourceReader* m_pReader = nullptr;
82  IMFSinkWriter* m_pWriter = nullptr;
83 
84  BOOL m_bVideoFirstSample = false;
85  BOOL m_bAudioFirstSample = false;
86  LONGLONG m_llVideoBaseTime = 0;
87  LONGLONG m_llAudioBaseTime = 0;
88  DWORD sink_video_stream = 0;
89  DWORD sink_audio_stream = 1;
90 
92 
93  // IUnknown methods
94  STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
95  STDMETHODIMP_(ULONG) AddRef();
96  STDMETHODIMP_(ULONG) Release();
97 
98  // IMFSourceReaderCallback methods
99  STDMETHODIMP OnReadSample(
100  HRESULT hrStatus,
101  DWORD dwStreamIndex,
102  DWORD dwStreamFlags,
103  LONGLONG llTimestamp,
104  IMFSample* pSample
105  );
106 
107  STDMETHODIMP OnEvent(DWORD, IMFMediaEvent*)
108  {
109  return S_OK;
110  }
111 
112  STDMETHODIMP OnFlush(DWORD)
113  {
114  return S_OK;
115  }
116 
117  HRESULT CreateAggregatedSource(IMFMediaSource* pSource1, IMFMediaSource* pSource2, IMFMediaSource** ppAggSource) const;
118 
119  HRESULT OpenMediaSource(IMFMediaSource* pSource);
120 
121  HRESULT ConfigureCapture();
122 
123  HRESULT CreateTargetVideoMediaType(IMFMediaType* pNativeMediaType, IMFMediaType** ppTargetMediaType) const;
124  HRESULT CreateTargetAudioMediaType(IMFMediaType* pNativeMediaType, IMFMediaType** ppTargetMediaType) const;
125 
126  HRESULT NegotiateStreamFormat(DWORD dwStreamIndex, REFGUID guidMajorType, DWORD cFormats, const GUID** paFormats) const;
127 
128  HRESULT NegotiateVideoStreamFormat(DWORD dwStreamIndex) const;
129  HRESULT NegotiateAudioStreamFormat(DWORD dwStreamIndex) const;
130 
131  BOOL IsCapturing();
132 
134 
135  public:
136 
137  Webcam();
138  void Initialize(Logger* prmLogger, WebcamConfig* prmConfig, Bus* prmBus);
139  void FrameMove();
140  void StartRecord();
141  void StopRecord();
142  void Destroy();
143  virtual ~Webcam();
144  };
145 }
STDMETHODIMP QueryInterface(REFIID iid, void **ppv)
IUnknown methods below can be moved where?
Definition: Webcam.cpp:47
Bus * bus
Definition: Webcam.h:62
HRESULT NegotiateAudioStreamFormat(DWORD dwStreamIndex) const
Definition: Webcam.cpp:648
std::wstring videoDevice
Definition: Webcam.h:21
IMFMediaSource * pVideoSource
Definition: Webcam.h:74
void Destroy()
Definition: Webcam.cpp:864
Definition: Logger.h:5
std::string pathAndFileNameA
Definition: Webcam.h:66
IMFActivate * pAudioActivate
Definition: Webcam.h:72
IMFActivate ** m_ppDevices
Definition: Webcam.h:36
WebcamConfig * config
Definition: Webcam.h:61
IMFActivate * pVideoActivate
Definition: Webcam.h:71
bool initialized
Definition: Webcam.h:64
HRESULT NegotiateStreamFormat(DWORD dwStreamIndex, REFGUID guidMajorType, DWORD cFormats, const GUID **paFormats) const
Definition: Webcam.cpp:519
HRESULT CreateTargetAudioMediaType(IMFMediaType *pNativeMediaType, IMFMediaType **ppTargetMediaType) const
Definition: Webcam.cpp:417
std::wstring audioDevice
Definition: Webcam.h:22
UINT32 Count() const
Definition: Webcam.h:47
IMFMediaSource * pSource
Definition: Webcam.h:76
okay, the portable keyboard numbers don&#39;t work like the outside keypad because the outside keypad is ...
Definition: Analog.cpp:3
Config config
Definition: Avionics.cpp:22
HRESULT CreateAggregatedSource(IMFMediaSource *pSource1, IMFMediaSource *pSource2, IMFMediaSource **ppAggSource) const
Definition: Webcam.cpp:140
Logger * logger
Definition: Webcam.h:60
Definition: Bus.h:12
Logger logger
Definition: Avionics.cpp:17
std::wstring pathAndFileName
Definition: Webcam.h:65
void StartRecord()
Definition: Webcam.cpp:688
HRESULT OpenMediaSource(IMFMediaSource *pSource)
Definition: Webcam.cpp:175
virtual ~Webcam()
Definition: Webcam.cpp:27
IMFMediaSource * pAudioSource
Definition: Webcam.h:75
DeviceList * videoDevices
Definition: Webcam.h:68
HRESULT NegotiateVideoStreamFormat(DWORD dwStreamIndex) const
Definition: Webcam.cpp:624
DeviceList(GUID guidDevice)
Definition: Webcam.cpp:875
HRESULT ConfigureCapture()
Definition: Webcam.cpp:202
IMFSourceReader * m_pReader
Definition: Webcam.h:81
HRESULT GetDevicebyID(std::wstring id, IMFActivate **ppActivate) const
Definition: Webcam.cpp:979
LONGLONG m_llVideoBaseTime
Definition: Webcam.h:86
HRESULT CreateTargetVideoMediaType(IMFMediaType *pNativeMediaType, IMFMediaType **ppTargetMediaType) const
Definition: Webcam.cpp:291
void StopRecord()
Definition: Webcam.cpp:819
STDMETHODIMP OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex, DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample)
Definition: Webcam.cpp:53
long m_nRefCount
Definition: Webcam.h:78
DWORD sink_video_stream
Definition: Webcam.h:88
HRESULT EnumerateDevices(Logger *logger, WebcamConfig *config)
Definition: Webcam.cpp:892
BOOL IsCapturing()
Definition: Webcam.cpp:659
BOOL m_bVideoFirstSample
Definition: Webcam.h:84
UINT32 m_cDevices
Definition: Webcam.h:35
BOOL m_bAudioFirstSample
Definition: Webcam.h:85
STDMETHODIMP_(ULONG) AddRef()
void FrameMove()
Definition: Webcam.cpp:1012
LONGLONG m_llAudioBaseTime
Definition: Webcam.h:87
DWORD sink_audio_stream
Definition: Webcam.h:89
STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *)
Definition: Webcam.h:107
IMFSinkWriter * m_pWriter
Definition: Webcam.h:82
DeviceList * audioDevices
Definition: Webcam.h:69
void Initialize(Logger *prmLogger, WebcamConfig *prmConfig, Bus *prmBus)
Definition: Webcam.cpp:670
STDMETHODIMP OnFlush(DWORD)
Definition: Webcam.h:112
CRITICAL_SECTION m_critsec
Definition: Webcam.h:79
int recordingNumber
Definition: Webcam.h:133