1 /*
2  * 1394-Based Digital Camera Control Library
3  *
4  * Internal functions
5  *
6  * Written by Damien Douxchamps <ddouxchamps@users.sf.net>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22 
23 #ifndef __DC1394_INTERNAL_H__
24 #define __DC1394_INTERNAL_H__
25 
26 #include "config.h"
27 #include "offsets.h"
28 #include "platform.h"
29 
30 typedef struct _platform_info_t {
31     const platform_dispatch_t * dispatch;
32     const char * name;
33     platform_device_list_t * device_list;
34     platform_t * p;
35 } platform_info_t;
36 
37 typedef struct _dc1394camera_priv_t {
38     dc1394camera_t camera;
39 
40     platform_camera_t * pcam;
41     platform_info_t * platform;
42 
43     uint64_t allocated_channels;
44     int allocated_bandwidth;
45     int iso_persist;
46 } dc1394camera_priv_t;
47 
48 #define DC1394_CAMERA_PRIV(c) ((dc1394camera_priv_t *)c)
49 
50 typedef struct _camera_info_t {
51     uint64_t guid;
52     int unit;
53     uint32_t unit_directory;
54     uint32_t unit_dependent_directory;
55     uint32_t unit_spec_ID;
56     uint32_t unit_sw_version;
57     char * vendor;
58     char * model;
59     uint32_t vendor_id;
60     uint32_t model_id;
61     platform_device_t * device;
62     platform_info_t * platform;
63 } camera_info_t;
64 
65 struct __dc1394_t {
66     int num_platforms;
67     platform_info_t * platforms;
68 
69     int num_cameras;
70     camera_info_t * cameras;
71 };
72 
73 void juju_init(dc1394_t *d);
74 void linux_init(dc1394_t *d);
75 void macosx_init(dc1394_t *d);
76 void windows_init(dc1394_t *d);
77 void dc1394_usb_init(dc1394_t *d);
78 
79 void register_platform (dc1394_t * d, const platform_dispatch_t * dispatch,
80         const char * name);
81 
82 void free_enumeration (dc1394_t * d);
83 int refresh_enumeration (dc1394_t * d);
84 
85 /* Definitions which application developers shouldn't care about */
86 #define CONFIG_ROM_BASE             0xFFFFF0000000ULL
87 
88 #define DC1394_FEATURE_ON           0x80000000UL
89 #define DC1394_FEATURE_OFF          0x00000000UL
90 
91 /* Maximum number of write/read retries */
92 #define DC1394_MAX_RETRIES          20
93 
94 /* Maximum number of ISO channels */
95 /* Note that the maximum currently supported by a chipset is 8 so that 16 is already
96    a conservative number. A typical number of channels supported is 4. (TI chipset)
97    However, 1394b allows for more channels, hence we use 64 as the limit */
98 #define DC1394_NUM_ISO_CHANNELS     64
99 
100 /* A hard compiled factor that makes sure async read and writes don't happen
101    too fast */
102 /* Toshiyuki Umeda: use randomize timings to avoid locking indefinitely.
103    If several thread are used the seed will be the same and the wait will therefor be
104    identical. A call to srand(getpid()) should be performed after calling the
105    raw1394_new_handle but I (Damien) not sure this would solve the problem as the handle
106    creation might have happened in the creating (as opposed to created) thread.*/
107 #define DC1394_SLOW_DOWN            ((rand()%20)+10)
108 
109 /* Maximum number of characters in vendor and model strings */
110 #define MAX_CHARS                      256
111 
112 
113 // Format_0
114 #define DC1394_VIDEO_MODE_FORMAT0_MIN            DC1394_VIDEO_MODE_160x120_YUV444
115 #define DC1394_VIDEO_MODE_FORMAT0_MAX            DC1394_VIDEO_MODE_640x480_MONO16
116 #define DC1394_VIDEO_MODE_FORMAT0_NUM      (DC1394_VIDEO_MODE_FORMAT0_MAX - DC1394_VIDEO_MODE_FORMAT0_MIN + 1)
117 
118 // Format_1
119 #define DC1394_VIDEO_MODE_FORMAT1_MIN            DC1394_VIDEO_MODE_800x600_YUV422
120 #define DC1394_VIDEO_MODE_FORMAT1_MAX            DC1394_VIDEO_MODE_1024x768_MONO16
121 #define DC1394_VIDEO_MODE_FORMAT1_NUM      (DC1394_VIDEO_MODE_FORMAT1_MAX - DC1394_VIDEO_MODE_FORMAT1_MIN + 1)
122 
123 // Format_2
124 #define DC1394_VIDEO_MODE_FORMAT2_MIN            DC1394_VIDEO_MODE_1280x960_YUV422
125 #define DC1394_VIDEO_MODE_FORMAT2_MAX            DC1394_VIDEO_MODE_1600x1200_MONO16
126 #define DC1394_VIDEO_MODE_FORMAT2_NUM           (DC1394_VIDEO_MODE_FORMAT2_MAX - DC1394_VIDEO_MODE_FORMAT2_MIN + 1)
127 
128 // Format_6
129 #define DC1394_VIDEO_MODE_FORMAT6_MIN            DC1394_VIDEO_MODE_EXIF
130 #define DC1394_VIDEO_MODE_FORMAT6_MAX            DC1394_VIDEO_MODE_EXIF
131 #define DC1394_VIDEO_MODE_FORMAT6_NUM           (DC1394_VIDEO_MODE_FORMAT6_MAX - DC1394_VIDEO_MODE_FORMAT6_MIN + 1)
132 
133 /* Enumeration of camera image formats */
134 /* This could disappear from the API I think.*/
135 enum {
136     DC1394_FORMAT0= 384,
137     DC1394_FORMAT1,
138     DC1394_FORMAT2,
139     DC1394_FORMAT6=390,
140     DC1394_FORMAT7
141 };
142 #define DC1394_FORMAT_MIN           DC1394_FORMAT0
143 #define DC1394_FORMAT_MAX           DC1394_FORMAT7
144 //#define DC1394_FORMAT_NUM          (DC1394_FORMAT_MAX - DC1394_FORMAT_MIN + 1)
145 /* DANGER: FORMAT_NUM should be 5!! FORMAT_NUM is therefor undefined to avoid problems */
146 
147 #define FEATURE_TO_VALUE_OFFSET(feature, offset)                                 \
148     {                                                                            \
149     if ( (feature > DC1394_FEATURE_MAX) || (feature < DC1394_FEATURE_MIN) )      \
150       return DC1394_FAILURE;                                                     \
151     else if (feature < DC1394_FEATURE_ZOOM)                                      \
152       offset= REG_CAMERA_FEATURE_HI_BASE+(feature - DC1394_FEATURE_MIN)*0x04U;   \
153     else if (feature >= DC1394_FEATURE_CAPTURE_SIZE)                             \
154       offset= REG_CAMERA_FEATURE_LO_BASE +(feature+12-DC1394_FEATURE_ZOOM)*0x04U;\
155     else                                                                         \
156       offset= REG_CAMERA_FEATURE_LO_BASE +(feature-DC1394_FEATURE_ZOOM)*0x04U;   \
157                                                                                    }
158 
159 #define FEATURE_TO_INQUIRY_OFFSET(feature, offset)                                   \
160     {                                                                                \
161     if ( (feature > DC1394_FEATURE_MAX) || (feature < DC1394_FEATURE_MIN) )          \
162       return DC1394_FAILURE;                                                         \
163     else if (feature < DC1394_FEATURE_ZOOM)                                          \
164       offset= REG_CAMERA_FEATURE_HI_BASE_INQ+(feature - DC1394_FEATURE_MIN)*0x04U;   \
165     else if (feature >= DC1394_FEATURE_CAPTURE_SIZE)                                 \
166       offset= REG_CAMERA_FEATURE_LO_BASE_INQ +(feature+12-DC1394_FEATURE_ZOOM)*0x04U;\
167     else                                                                             \
168       offset= REG_CAMERA_FEATURE_LO_BASE_INQ +(feature-DC1394_FEATURE_ZOOM)*0x04U;   \
169     }
170 
171 /* Internal functions required by two different source files */
172 
173 dc1394error_t
174 get_quadlets_per_packet(uint32_t mode, uint32_t frame_rate, uint32_t *qpp);
175 
176 dc1394error_t
177 get_quadlets_from_format(dc1394camera_t *camera, uint32_t mode, uint32_t *quads);
178 
179 dc1394error_t
180 get_format_from_mode(uint32_t mode, uint32_t *format);
181 
182 dc1394bool_t
183 is_feature_bit_set(uint32_t value, uint32_t feature);
184 
185 /*
186 dc1394bool_t
187 _dc1394_iidc_check_video_mode(dc1394camera_t *camera, dc1394video_mode_t *mode);
188 */
189 dc1394error_t capture_basic_setup (dc1394camera_t * camera, dc1394video_frame_t * frame);
190 
191 #endif /* _DC1394_INTERNAL_H */
192