1 /*
2  * videoio1394avc.h
3  *
4  * This file is a based on videoio1394dc.h
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 2003 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): Georgi Georgiev <chutz@gg3.net>
25  *
26  * $Revision: 20385 $
27  * $Author: rjongbloed $
28  * $Date: 2008-06-04 05:40:38 -0500 (Wed, 04 Jun 2008) $
29  */
30 
31 
32 #ifndef _PVIDEOIO1394AVC
33 
34 #define _PVIDEOIO1394AVC
35 
36 #ifdef __GNUC__
37 #pragma interface
38 #endif
39 
40 #include <sys/utsname.h>
41 #include <libraw1394/raw1394.h>
42 #include <libavc1394/avc1394.h>
43 #include <libavc1394/rom1394.h>
44 #include <libraw1394/csr.h>
45 #include <libdv/dv.h>
46 
47 #include <ptlib.h>
48 #include <ptlib/videoio.h>
49 #include <ptlib/vconvert.h>
50 #include <ptlib/file.h>
51 #if !P_USE_INLINES
52 #include <ptlib/contain.inl>
53 #endif
54 #include <ptclib/delaychan.h>
55 
56 
57 /** This class defines a video input device that
58     generates fictitous image data.
59 */
60 
61 class PVideoInputDevice_1394AVC : public PVideoInputDevice
62 {
63     PCLASSINFO(PVideoInputDevice_1394AVC, PVideoInputDevice);
64  public:
65   /** Create a new video input device.
66    */
67     PVideoInputDevice_1394AVC();
68 
69     /**Close the video input device on destruction.
70       */
71     ~PVideoInputDevice_1394AVC();
72 
73     /**Open the device given the device name.
74       */
75     PBoolean Open(
76       const PString & deviceName,   /// Device name to open
77       PBoolean startImmediate = PTrue    /// Immediately start device
78     );
79 
80     /**Determine of the device is currently open.
81       */
82     PBoolean IsOpen();
83 
84     /**Close the device.
85       */
86     PBoolean Close();
87 
88     /**Start the video device I/O.
89       */
90     PBoolean Start();
91 
92     /**Stop the video device I/O capture.
93       */
94     PBoolean Stop();
95 
96     /**Determine if the video device I/O capture is in progress.
97       */
98     PBoolean IsCapturing();
99 
100     /**Get a list of all of the drivers available.
101       */
102     static PStringArray GetInputDeviceNames();
103 
GetDeviceNames()104     PStringArray GetDeviceNames() const
105     { return GetInputDeviceNames(); }
106 
107     /**Get the maximum frame size in bytes.
108 
109        Note a particular device may be able to provide variable length
110        frames (eg motion JPEG) so will be the maximum size of all frames.
111       */
112     PINDEX GetMaxFrameBytes();
113 
114     /**Grab a frame, after a delay as specified by the frame rate.
115       */
116     PBoolean GetFrameData(
117       BYTE * buffer,                 /// Buffer to receive frame
118       PINDEX * bytesReturned = NULL  /// OPtional bytes returned.
119     );
120 
121     /**Grab a frame. Do not delay according to the current frame rate parameter.
122       */
123     PBoolean GetFrameDataNoDelay(
124       BYTE * buffer,                 /// Buffer to receive frame
125       PINDEX * bytesReturned = NULL  /// OPtional bytes returned.
126     );
127 
128 
129     /**Get the brightness of the image. 0xffff-Very bright.
130      */
131     int GetBrightness();
132 
133     /**Set brightness of the image. 0xffff-Very bright.
134      */
135     PBoolean SetBrightness(unsigned newBrightness);
136 
137 
138     /**Get the whiteness of the image. 0xffff-Very white.
139      */
140     int GetWhiteness();
141 
142     /**Set whiteness of the image. 0xffff-Very white.
143      */
144     PBoolean SetWhiteness(unsigned newWhiteness);
145 
146 
147     /**Get the colour of the image. 0xffff-lots of colour.
148      */
149     int GetColour();
150 
151     /**Set colour of the image. 0xffff-lots of colour.
152      */
153     PBoolean SetColour(unsigned newColour);
154 
155 
156     /**Get the contrast of the image. 0xffff-High contrast.
157      */
158     int GetContrast();
159 
160     /**Set contrast of the image. 0xffff-High contrast.
161      */
162     PBoolean SetContrast(unsigned newContrast);
163 
164 
165     /**Get the hue of the image. 0xffff-High hue.
166      */
167     int GetHue();
168 
169     /**Set hue of the image. 0xffff-High hue.
170      */
171     PBoolean SetHue(unsigned newHue);
172 
173 
174     /**Return whiteness, brightness, colour, contrast and hue in one call.
175      */
176     PBoolean GetParameters (int *whiteness, int *brightness,
177 				int *colour, int *contrast, int *hue);
178 
179     /**Get the minimum & maximum size of a frame on the device.
180     */
181     PBoolean GetFrameSizeLimits(
182       unsigned & minWidth,   /// Variable to receive minimum width
183       unsigned & minHeight,  /// Variable to receive minimum height
184       unsigned & maxWidth,   /// Variable to receive maximum width
185       unsigned & maxHeight   /// Variable to receive maximum height
186     ) ;
187 
188     void ClearMapping();
189 
190     int GetNumChannels();
191     PBoolean SetChannel(
192          int channelNumber  /// New channel number for device.
193     );
194     PBoolean SetFrameRate(
195       unsigned rate  /// Frames  per second
196     );
197     PBoolean SetVideoFormat(
198       VideoFormat videoFormat   /// New video format
199     );
200     PBoolean SetFrameSize(
201       unsigned width,   /// New width of frame
202       unsigned height   /// New height of frame
203     );
204     PBoolean SetColourFormat(
205       const PString & colourFormat   // New colour format for device.
206     );
207 
208 
209     /**Try all known video formats & see which ones are accepted by the video driver
210      */
211     PBoolean TestAllFormats();
212 
213 
214  protected:
215 
216     raw1394handle_t handle;
217     PBoolean is_capturing;
218     PBoolean UseDMA;
219     dv_decoder_t * dv_decoder;
220     PINDEX frameBytes;
221     int port;
222     PAdaptiveDelay m_pacing;
223 
224     PBoolean SetupHandle();
225 };
226 
227 int RawISOHandler (raw1394handle_t handle, int channel, size_t length, u_int32_t * data);
228 
229 #endif
230 
231 
232 // End Of File ///////////////////////////////////////////////////////////////
233