1 /*
2 * IIDC1394 grab interface (uses libdc1394 and libraw1394)
3 * Copyright (c) 2004 Roman Shaposhnik
4 * Copyright (c) 2008 Alessandro Sappia
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <dc1394/dc1394.h>
24
32
35
42 int frame_rate;
/**< frames per 1000 seconds (fps * 1000) */
43 char *
video_size;
/**< String describing video size, set by a private option. */
46
50
61 { 0, 0, 0, 0 } /* gotta be the last one */
62 };
63
68 { 1875, DC1394_FRAMERATE_1_875 },
69 { 3750, DC1394_FRAMERATE_3_75 },
70 { 7500, DC1394_FRAMERATE_7_5 },
71 { 15000, DC1394_FRAMERATE_15 },
72 { 30000, DC1394_FRAMERATE_30 },
73 { 60000, DC1394_FRAMERATE_60 },
74 {120000, DC1394_FRAMERATE_120 },
75 {240000, DC1394_FRAMERATE_240 },
76 { 0, 0 } /* gotta be the last one */
77 };
78
79 #define OFFSET(x) offsetof(dc1394_data, x)
80 #define DEC AV_OPT_FLAG_DECODING_PARAM
82 {
"video_size",
"A string describing frame size, such as 640x480 or hd720.",
OFFSET(video_size),
AV_OPT_TYPE_STRING, {.str =
"qvga"}, 0, 0,
DEC },
86 };
87
94 };
95
96
99 {
108
113 }
114
118 }
122 }
124
127 break;
128
131 break;
132
138 }
139
140 /* create a video stream */
142 if (!vst) {
145 }
153
158
161 *select_fps = fps;
162 *select_fmt = fmt;
165 }
166
168 {
170 dc1394camera_list_t *
list;
174
176 return -1;
177
178 /* Now let us prep the hardware. */
179 dc1394->
d = dc1394_new();
180 if (dc1394_camera_enumerate(dc1394->
d, &
list) != DC1394_SUCCESS || !
list) {
183 }
184
185 if (
list->num == 0) {
187 dc1394_camera_free_list(
list);
189 }
190
191 /* FIXME: To select a specific camera I need to search in list its guid */
192 dc1394->
camera = dc1394_camera_new (dc1394->
d,
list->ids[0].guid);
193
197 dc1394_camera_free_list(
list);
199 }
200
203 }
204
205 /* Freeing list of cameras */
206 dc1394_camera_free_list (
list);
207
208 /* Select MAX Speed possible from the cam */
209 if (dc1394->
camera->bmode_capable>0) {
210 dc1394_video_set_operation_mode(dc1394->
camera, DC1394_OPERATION_MODE_1394B);
211 i = DC1394_ISO_SPEED_800;
212 } else {
213 i = DC1394_ISO_SPEED_400;
214 }
215
216 for (res = DC1394_FAILURE;
i >= DC1394_ISO_SPEED_MIN && res != DC1394_SUCCESS;
i--) {
217 res=dc1394_video_set_iso_speed(dc1394->
camera,
i);
218 }
219 if (res != DC1394_SUCCESS) {
221 goto out_camera;
222 }
223
226 goto out_camera;
227 }
228
231 goto out_camera;
232 }
233 if (dc1394_capture_setup(dc1394->
camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS) {
235 goto out_camera;
236 }
237
238 if (dc1394_video_set_transmission(dc1394->
camera, DC1394_ON) !=DC1394_SUCCESS) {
240 goto out_camera;
241 }
242 return 0;
243
244 out_camera:
245 dc1394_capture_stop(dc1394->
camera);
246 dc1394_video_set_transmission(dc1394->
camera, DC1394_OFF);
247 dc1394_camera_free (dc1394->
camera);
249 dc1394_free(dc1394->
d);
250 return -1;
251 }
252
254 {
256 int res;
257
258 /* discard stale frame */
260 if (dc1394_capture_enqueue(dc1394->
camera, dc1394->
frame) != DC1394_SUCCESS)
262 }
263
264 res = dc1394_capture_dequeue(dc1394->
camera, DC1394_CAPTURE_POLICY_WAIT, &dc1394->
frame);
265 if (res == DC1394_SUCCESS) {
271 } else {
274 }
275
277 }
278
280 {
282
283 dc1394_video_set_transmission(dc1394->
camera, DC1394_OFF);
284 dc1394_capture_stop(dc1394->
camera);
285 dc1394_camera_free(dc1394->
camera);
286 dc1394_free(dc1394->
d);
287
288 return 0;
289 }
290
300 };