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

Revision 4744, 7.9 KB (checked in by douglask, 4 years ago)

Perform a 'scc.MaxOutputSize?.cy > max_height' test instead of 'scc.MaxOutputSize?.cx > max_width' as it will support more anamorphic square pixel resolutions that can be clipped if need be.

  • 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;
89
90struct Port {
91       int id;
92       char name[64];
93};
94
95class DirectShowGrabber : public Grabber {
96   public:
97      DirectShowGrabber(IBaseFilter *, const char * cformat, const char * nick = 0);
98      ~DirectShowGrabber();
99      virtual int  command(int argc, const char*const* argv);
100
101          inline void  converter(Converter* v) {
102                  converter_ = v;
103          }
104
105          void         capture(BYTE *, long);
106
107          bool             hasDV_SD(){
108              return (have_DVSD_);
109          }
110
111          int              maxWidth(){
112              return max_width_;
113          }
114
115          int              maxHeight(){
116                  return max_height_;
117          }
118
119          int              minWidth(){
120              return min_width_;
121          }
122
123          int              minHeight(){
124                  return min_height_;
125          }
126
127          Port **          getInputPorts(){
128                  return inputPorts;
129          }
130
131      int          capturing_;
132      HANDLE       cb_mutex_;
133   protected:
134      virtual void start();
135      virtual void stop();
136      virtual void fps(int);
137      virtual void setsize();
138      virtual int  grab();
139      void         setport(const char *port);
140      int          getCaptureCapabilities(int preferred_max_height=720);
141      virtual void setCaptureOutputFormat();
142
143      int          useconfig_;
144      int          basewidth_;
145      int          baseheight_;
146      u_int        max_fps_;
147      int          max_width_;
148      int          max_height_;
149      int          min_width_;
150      int          min_height_;
151      int          width_;
152      int          height_;
153      int          cformat_;
154
155      Port *       inputPorts[NUM_PORTS];
156      int          numInputPorts;
157      int          initializedPorts;
158      int          compositePortNum;
159      int          svideoPortNum;
160
161      bool         have_I420_;  // YUV 4:2:0 planar
162      bool         have_UYVY_;  // YUV 4:2:2 packed
163      bool         have_YUY2_;  // as for UYVY but with different component ordering
164      bool         have_HDYC_;  // YUV 4:2:2 packed, same as UYVY but using BT709 color space
165      bool         have_RGB24_; // RGB 24 bit
166      bool         have_DVSD_;  // DV standard definition
167
168      u_int        decimate_;    // set in this::command via small/normal/large in vic UI; msp
169      BYTE         *last_frame_;
170      Converter    *converter_;
171
172   private:
173      IBaseFilter*           pFilter_;
174      IBaseFilter*           pCaptureFilter_;
175      ISampleGrabber*        pSampleGrabber_;
176      IBaseFilter*           pGrabberBaseFilter_;
177      IIPDVDec*              pDVVideoDecoder_;
178      IBaseFilter*           pDVDecoderBaseFilter_;
179      IBaseFilter*           pNullRenderer_;
180      IBaseFilter*           pNullBaseFilter_;
181      IGraphBuilder*         pGraph_;
182      ICaptureGraphBuilder2* pBuild_;
183      IMediaControl*         pMediaControl_;
184      DWORD                  dwRegister_;
185      AM_MEDIA_TYPE          mt_;
186      Callback               *callback_;
187
188      IAMCrossbar            *pXBar_;
189      Crossbar               *crossbar_;
190      Crossbar               *crossbarCursor_;
191      char                   input_port_[20];
192      bool                   findCrossbar(IBaseFilter *);
193      void                   addCrossbar(IAMCrossbar *);
194      void                   routeCrossbar();
195
196};
197
198//#########################################################################
199
200class Callback : public ISampleGrabberCB {
201   private:
202      volatile long m_cRef;
203   public:
204      Callback() {}     
205
206      DirectShowGrabber *grabber;
207
208      // IUnknown methods
209      STDMETHODIMP_(ULONG) AddRef() {
210         return InterlockedIncrement(&m_cRef);
211      }
212
213      STDMETHODIMP_(ULONG) Release() {
214         long lCount = InterlockedDecrement(&m_cRef);
215         if (lCount == 0) {
216            delete this;
217         }
218         // Return the temporary variable, not the member
219         // variable, for thread safety.
220         return (ULONG)lCount;
221      }
222
223      STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject);
224
225      // our callbacks
226      STDMETHODIMP SampleCB(double sampleTime, IMediaSample *pSample);
227      STDMETHODIMP BufferCB(double sampleTime, BYTE *pBuffer, long bufferLen);
228};
229
230//#########################################################################
231
232class DirectShowDevice : public InputDevice {
233   public:
234      DirectShowDevice(char *, IBaseFilter *);
235          ~DirectShowDevice();
236      virtual int command(int argc, const char* const* argv);     
237
238   protected:
239      IBaseFilter*           pDirectShowFilter_;
240
241      //IBaseFilter       *directShowFilter_;
242      DirectShowGrabber *directShowGrabber_;   
243          char *attri_;
244};
245
246//#########################################################################
247
248class DirectShowScanner {
249   public:     
250      DirectShowScanner();
251      ~DirectShowScanner();
252   protected:
253      DirectShowDevice *devs_[NUM_DEVS];
254      IMoniker*     pMoniker_;
255
256};
Note: See TracBrowser for help on using the browser.