root/vic/branches/mpeg4/video/grabber-win32DS.h @ 4761

Revision 4761, 8.0 KB (checked in by turam, 4 years ago)

Properly map input pins to output pins (e.g. Winnov Videum); Select currently selected port in Port menu; Sort Device menu

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 *  Copyright (c) 1996 John Brezak
3 *  Copyright (c) 1996 Isidor Kouvelas (University College London)
4 *  Portions Copyright (c) 2004 EarthLink, Inc.
5 *  All rights reserved.
6 *
7 *  Redistribution and use in source and binary forms, with or without
8 *  modification, are permitted provided that the following conditions
9 *  are met:
10 *  1. Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *  2. Redistributions in binary form must reproduce the above copyright
13 *     notice, this list of conditions and the following disclaimer in the
14 *     documentation and/or other materials provided with the distribution.
15 *  3. The name of the author may not be used to endorse or promote products
16 *     derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31// grabber-win32DS.h
32
33//warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.
34// To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
35#define _CRT_SECURE_NO_WARNINGS
36#define _CRT_SECURE_NO_DEPRECATE
37
38#include <dshow.h>   // DirectShow
39#include <amstream.h>   // DirectShow
40
41#pragma include_alias("dxtrans.h", "qedit.h")
42#define __IDxtCompositor_INTERFACE_DEFINED__
43#define __IDxtAlphaSetter_INTERFACE_DEFINED__
44#define __IDxtJpeg_INTERFACE_DEFINED__
45#define __IDxtKey_INTERFACE_DEFINED__
46// dxtrans.h is missing with some DirectX SDKs and VisualStudio versions - broken M$ setup?!
47// the above #pragma and #define's make sure it's contents is not needed
48#include <qedit.h>   // DirectShow
49
50#include "crossbar.h"
51
52#define NUM_DEVS 20   // max number of capture devices we'll support
53#define NUM_PORTS 20  // max number of ports on a capture device
54
55//#define showErrorMessage(x)   ShowErrorMessage(x, __LINE__, __FILE__)
56
57//extern void ShowErrorMessage(HRESULT, int, char* );
58
59#define CF_422 0
60#define CF_420 1
61#define CF_CIF 2
62
63static const int D1_BASE_WIDTH  = 720;
64static const int D1_BASE_HEIGHT = 480;
65static const int NTSC_BASE_WIDTH  = 640;
66static const int NTSC_BASE_HEIGHT = 480;
67static const int PAL_BASE_WIDTH   = 768;
68static const int PAL_BASE_HEIGHT  = 568;
69static const int CIF_BASE_WIDTH   = 704;
70static const int CIF_BASE_HEIGHT  = 576;
71
72//#########################################################################
73
74/*
75class Crossbar {
76   public:
77      Crossbar(IAMCrossbar *);     
78      IAMCrossbar *getXBar();
79
80      Crossbar *next;
81   private:
82      IAMCrossbar  *xbar;     
83};
84*/
85
86//#########################################################################
87
88class Callback;
89struct Port {
90       int id;
91       char name[64];
92};
93
94class DirectShowGrabber : public Grabber {
95   public:
96      DirectShowGrabber(IBaseFilter *, const char * cformat, const char * nick = 0);
97      ~DirectShowGrabber();
98      virtual int  command(int argc, const char*const* argv);
99
100          inline void  converter(Converter* v) {
101                  converter_ = v;
102          }
103
104          void         capture(BYTE *, long);
105
106          bool             hasDV_SD(){
107              return (have_DVSD_);
108          }
109
110          int              maxWidth(){
111              return max_width_;
112          }
113
114          int              maxHeight(){
115                  return max_height_;
116          }
117
118          int              minWidth(){
119              return min_width_;
120          }
121
122          int              minHeight(){
123                  return min_height_;
124          }
125
126          Port **          getInputPorts(){
127                  return inputPorts;
128          }
129          char *                getInputPort(){
130                  return strdup(input_port_);
131          }
132      int          capturing_;
133      HANDLE       cb_mutex_;
134   protected:
135      virtual void start();
136      virtual void stop();
137      virtual void fps(int);
138      virtual void setsize();
139      virtual int  grab();
140      void         setport(const char *port);
141      int          getCaptureCapabilities(int preferred_max_height=720);
142      virtual void setCaptureOutputFormat();
143
144      int          useconfig_;
145      int          basewidth_;
146      int          baseheight_;
147      u_int        max_fps_;
148      int          max_width_;
149      int          max_height_;
150      int          min_width_;
151      int          min_height_;
152      int          width_;
153      int          height_;
154      int          cformat_;
155
156      Port *       inputPorts[NUM_PORTS];
157      int          numInputPorts;
158      int          initializedPorts;
159      int          compositePortNum;
160      int          svideoPortNum;
161
162      bool         have_I420_;  // YUV 4:2:0 planar
163      bool         have_UYVY_;  // YUV 4:2:2 packed
164      bool         have_YUY2_;  // as for UYVY but with different component ordering
165      bool         have_HDYC_;  // YUV 4:2:2 packed, same as UYVY but using BT709 color space
166      bool         have_RGB24_; // RGB 24 bit
167      bool         have_DVSD_;  // DV standard definition
168
169      u_int        decimate_;    // set in this::command via small/normal/large in vic UI; msp
170      BYTE         *last_frame_;
171      Converter    *converter_;
172
173   private:
174      IBaseFilter*           pFilter_;
175      IBaseFilter*           pCaptureFilter_;
176      ISampleGrabber*        pSampleGrabber_;
177      IBaseFilter*           pGrabberBaseFilter_;
178      IIPDVDec*              pDVVideoDecoder_;
179      IBaseFilter*           pDVDecoderBaseFilter_;
180      IBaseFilter*           pNullRenderer_;
181      IBaseFilter*           pNullBaseFilter_;
182      IGraphBuilder*         pGraph_;
183      ICaptureGraphBuilder2* pBuild_;
184      IMediaControl*         pMediaControl_;
185      DWORD                  dwRegister_;
186      AM_MEDIA_TYPE          mt_;
187      Callback               *callback_;
188
189      IAMCrossbar            *pXBar_;
190      Crossbar               *crossbar_;
191      Crossbar               *crossbarCursor_;
192      char                   input_port_[20];
193      bool                   findCrossbar(IBaseFilter *);
194      void                   addCrossbar(IAMCrossbar *);
195      void                   routeCrossbar();
196
197};
198
199//#########################################################################
200
201class Callback : public ISampleGrabberCB {
202   private:
203      volatile long m_cRef;
204   public:
205      Callback() {}     
206
207      DirectShowGrabber *grabber;
208
209      // IUnknown methods
210      STDMETHODIMP_(ULONG) AddRef() {
211         return InterlockedIncrement(&m_cRef);
212      }
213
214      STDMETHODIMP_(ULONG) Release() {
215         long lCount = InterlockedDecrement(&m_cRef);
216         if (lCount == 0) {
217            delete this;
218         }
219         // Return the temporary variable, not the member
220         // variable, for thread safety.
221         return (ULONG)lCount;
222      }
223
224      STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject);
225
226      // our callbacks
227      STDMETHODIMP SampleCB(double sampleTime, IMediaSample *pSample);
228      STDMETHODIMP BufferCB(double sampleTime, BYTE *pBuffer, long bufferLen);
229};
230
231//#########################################################################
232
233class DirectShowDevice : public InputDevice {
234   public:
235      DirectShowDevice(char *, IBaseFilter *);
236          ~DirectShowDevice();
237      virtual int command(int argc, const char* const* argv);     
238
239   protected:
240      IBaseFilter*           pDirectShowFilter_;
241
242      //IBaseFilter       *directShowFilter_;
243      DirectShowGrabber *directShowGrabber_;   
244          char *attri_;
245};
246
247//#########################################################################
248
249class DirectShowScanner {
250   public:     
251      DirectShowScanner();
252      ~DirectShowScanner();
253   protected:
254      DirectShowDevice *devs_[NUM_DEVS];
255      IMoniker*     pMoniker_;
256
257};
258
Note: See TracBrowser for help on using the browser.