Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cVideoVFW.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cVideoVFW_H
7 #define _INC_cVideoVFW_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cVideoCodec.h"
13 
14 #if defined(_WIN32) && ! defined(UNDER_CE)
15 #include "../WinAPI/WinTypes.h"
19 
20 #include <vfw.h> // COMPVARS ICINFO
21 
22 namespace Gray
23 {
24  template <> inline void cHandlePtr<HIC>::CloseHandle(HIC h) // static
25  {
27  ::ICClose(h);
28  }
29 }
30 
31 namespace GrayLib
32 {
33  class GRAYLIB_LINK cVideoVFW
34  {
37 
38  public:
39  static const FOURCC k_FormNull = MAKEFOURCC('D', 'I', 'B', ' ');
40  static HRESULT GRAYCALL GetHResultFrom(LRESULT lRes);
41 
42  UNITTEST_FRIEND(cVideoVFW);
43  };
44 
45  class GRAYLIB_LINK cVideoVFWComp : public IVideoCompress, public cVideoVFW
46  {
50  public:
51 
52  class cParams
53  {
58 
59  public:
60  cFourCC m_fccHandler;
61  LONG m_lKeyRate;
62  LONG m_lDataRate;
63  AV_QUALITY_t m_nQuality;
64 
65  public:
66  cParams(FOURCC fccHandler = cVideoVFW::k_FormNull, LONG lKeyRate = 1, LONG lDataRate = 300, AV_QUALITY_t nQuality = k_AV_QUALITY_DEF) noexcept
67  : m_fccHandler(fccHandler)
68  , m_lKeyRate(lKeyRate)
69  , m_lDataRate(lDataRate)
70  , m_nQuality(nQuality)
71  {
72  }
73 
74  bool isCodecNull() const noexcept
75  {
77  return(m_fccHandler == cVideoVFW::k_FormNull);
78  }
79  bool isValidFormat() const noexcept
80  {
81  return true;
82  }
83 
84  bool SetCodecParams(FOURCC fccHandler = k_FormNull, LONG lKeyRate = 1, LONG lDataRate = 300, AV_QUALITY_t nQuality = k_AV_QUALITY_DEF) noexcept
85  {
86  // Params for video codec.
87  m_fccHandler = fccHandler;
88  m_lKeyRate = lKeyRate;
89  m_lDataRate = lDataRate;
90  m_nQuality = nQuality; // ICQUALITY_DEFAULT
91  return true;
92  }
93 
94  // serializers
95  StrLen_t GetCodecStr(char* pszValue, StrLen_t iSizeMax) const;
96  bool put_CodecStr(const char* pszValue);
97  };
98 
99  private:
100  COMPVARS m_v;
101  cSurfaceBitmapInfo m_biIn;
102  bool m_bCompStart;
103 
104  public:
105  cVideoVFWComp();
106  cVideoVFWComp(const cParams& params);
107  cVideoVFWComp(const cVideoVFWComp& copythis);
108  virtual ~cVideoVFWComp();
109 
110  bool isCodecAlloc() const noexcept
111  {
113  return(m_v.cbSize != 0);
114  }
115  bool isCodecNull() const noexcept
116  {
118  return(m_v.fccHandler == k_FormNull);
119  }
120  bool isCodecOpen() const
121  {
123  if (isCodecNull())
124  return true;
125  return m_v.hic != HANDLE_NULL;
126  }
127  bool isCompStarted() const
128  {
130  if (!m_bCompStart)
131  return false;
132  ASSERT(isCodecOpen());
133  ASSERT(m_v.lpbiOut != nullptr);
134  return true;
135  }
136 
137  void DestroyCodec();
138 
139  HRESULT OpenCodec(WORD wMode = ICMODE_FASTCOMPRESS);
140  void CloseCodec();
141  HRESULT ResetCodec();
142 
143  bool GetCodecInfo(ICINFO& icInfo) const;
144  HRESULT GetCompFormat(const tagBITMAPINFO* lpbiIn, tagBITMAPINFO* lpbiOut = nullptr) const;
145  bool GetCodecParams(cParams& params) const;
146  bool SetCodecParams(const cParams& params);
147 
148  bool CompSupportsConfigureDlg() const;
149  HRESULT CompConfigureDlg(HWND hWndApp);
150  bool CompChooseDlg(HWND hWndApp, const char* lpszTitle);
151 
152 #ifdef _DEBUG
153  void DumpSettings();
154 #endif
155 
156  // IVideoCompress
157  virtual HRESULT CompStart(const cSurfaceInfo& rInfo, cSurfaceBitmapInfo* pbiOut) override;
158  virtual HRESULT CompFrame(const cSurfaceBase& frame, OUT const void*& rpCompRet, OUT size_t& rnSizeRet, OUT bool& rbIsKey) override;
159  virtual void CompEnd();
160  virtual AV_QUALITY_t get_CompQuality() const
161  {
162  return (AV_QUALITY_t)m_v.lQ;
163  }
164  };
165 
166  class GRAYLIB_LINK cVideoVFWDecomp : public IVideoDecompress, public cVideoVFW
167  {
171  private:
172  cHandlePtr<HIC> m_hic;
173  ICDECOMPRESS m_Decomp;
174  public:
175  cVideoVFWDecomp() noexcept
176  : m_hic(HANDLE_NULL)
177  {
178  }
179  virtual ~cVideoVFWDecomp()
180  {
181  }
182  virtual HRESULT DecompStart(const cSurfaceBitmapInfo* pbiInp, cSurfaceInfo* pFrameInfo) override
183  {
184  UNREFERENCED_PARAMETER(pbiInp);
185  UNREFERENCED_PARAMETER(pFrameInfo);
186  return E_NOTIMPL;
187  }
188  virtual HRESULT DecompFrame(const void* pCompData, size_t nSizeComp, cSurfaceBase& frame) override
189  {
190  UNREFERENCED_PARAMETER(pCompData);
191  UNREFERENCED_PARAMETER(nSizeComp);
192  UNREFERENCED_REFERENCE(frame);
193  return E_NOTIMPL;
194  }
195  };
196 }
197 #endif
198 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define UNREFERENCED_PARAMETER(P)
< _WIN32 type thing. get rid of stupid warning.
Definition: SysTypes.h:299
#define UNREFERENCED_REFERENCE(x)
Definition: SysTypes.h:318
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
UINT32 FOURCC
32 bit code. Also defined in _MMSYSTEM_H
Definition: cFourCC.h:19
#define MAKEFOURCC(ch0, ch1, ch2, ch3)
Definition: cFourCC.h:24
#define HANDLE_NULL
Invalid OS handle for _WIN32. Not invalid OS handle for linux.
Definition: cOSHandle.h:21
#define UNITTEST_FRIEND(n)
Define this in the class body to be unit tested. Allow the unit test to access private/protected stuf...
Definition: cUnitTestDecl.h:17
void CloseHandle()
Definition: cHandlePtr.h:79
Definition: cMesh.h:22
short AV_QUALITY_t
0 to 10000 e.g. 9900 = 99%. same as ICQUALITY_LOW,ICQUALITY_HIGH
Definition: cAVSink.h:21
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32