add_savefile: remove callback parameter
[vlc/asuraparaju-public.git] / modules / access / dc1394.c
blob8ab82de5d318d8495f86b723c74c23d3f75013da
1 /*****************************************************************************
2 * dc1394.c: firewire input module
3 *****************************************************************************
4 * Copyright (C) 2006-2009 VideoLAN
6 * Authors: Xant Majere <xant@xant.net>
7 * Rob Shortt <rob@tvcentric.com> - libdc1394 V2 API updates
8 * Frederic Benoist <fridorik@gmail.com> - updates from Rob's work
10 *****************************************************************************
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation;
14 * version 2 of the License.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *****************************************************************************/
27 /*****************************************************************************
28 * Preamble
29 *****************************************************************************/
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_input.h>
38 #include <vlc_demux.h>
39 #include <vlc_fs.h>
40 #include <vlc_picture.h>
42 #ifdef HAVE_FCNTL_H
43 # include <fcntl.h>
44 #endif
45 #ifdef HAVE_UNISTD_H
46 # include <unistd.h>
47 #elif defined( WIN32 ) && !defined( UNDER_CE )
48 # include <io.h>
49 #endif
51 #include <sys/ioctl.h>
52 #include <sys/soundcard.h>
54 #include <libraw1394/raw1394.h>
55 #include <dc1394/dc1394.h>
57 #define MAX_IEEE1394_HOSTS 32
58 #define MAX_CAMERA_NODES 32
60 /*****************************************************************************
61 * Module descriptor
62 *****************************************************************************/
63 static int Open ( vlc_object_t * );
64 static void Close( vlc_object_t * );
65 static int OpenAudioDev( demux_t *p_demux );
66 static inline void CloseAudioDev( demux_t *p_demux );
68 vlc_module_begin()
69 set_description( N_("dc1394 input") )
70 set_capability( "access_demux", 10 )
71 add_shortcut( "dc1394" )
72 set_callbacks( Open, Close )
73 vlc_module_end()
75 struct demux_sys_t
77 /* camera info */
78 dc1394_t *p_dccontext;
79 uint32_t num_cameras;
80 dc1394camera_t *camera;
81 int selected_camera;
82 uint64_t selected_uid;
83 picture_t pic;
84 uint32_t dma_buffers;
85 dc1394featureset_t features;
86 quadlet_t supported_framerates;
87 bool reset_bus;
89 /* video info */
90 char *video_device;
91 dc1394video_mode_t video_mode;
92 int width;
93 int height;
94 int frame_size;
95 int frame_rate;
96 unsigned int brightness;
97 unsigned int focus;
98 es_out_id_t *p_es_video;
99 dc1394video_frame_t *frame;
101 /* audio stuff */
102 int i_sample_rate;
103 int channels;
104 int i_audio_max_frame_size;
105 int fd_audio;
106 char *audio_device;
107 es_out_id_t *p_es_audio;
110 /*****************************************************************************
111 * Local prototypes
112 *****************************************************************************/
113 static int Demux( demux_t *p_demux );
114 static int Control( demux_t *, int, va_list );
115 static block_t *GrabVideo( demux_t *p_demux );
116 static block_t *GrabAudio( demux_t *p_demux );
117 static int process_options( demux_t *p_demux);
119 /*****************************************************************************
120 * FindCameras
121 *****************************************************************************/
122 static int FindCamera( demux_sys_t *sys, demux_t *p_demux )
124 dc1394camera_list_t *list;
125 int i_ret = VLC_EGENERIC;
127 msg_Dbg( p_demux, "Scanning for ieee1394 ports ..." );
129 if( dc1394_camera_enumerate (sys->p_dccontext, &list) != DC1394_SUCCESS )
131 msg_Err(p_demux, "Can not ennumerate cameras");
132 goto end;
135 if( list->num == 0 )
137 msg_Err(p_demux, "Can not find cameras");
138 goto end;
141 sys->num_cameras = list->num;
142 msg_Dbg( p_demux, "Found %d dc1394 cameras.", list->num);
144 if( sys->selected_uid )
146 int found = 0;
147 for( unsigned i = 0; i < sys->num_cameras; i++ )
149 if( list->ids[i].guid == sys->selected_uid )
151 sys->camera = dc1394_camera_new(sys->p_dccontext,
152 list->ids[i].guid);
153 found++;
154 break;
157 if( !found )
159 msg_Err( p_demux, "Can't find camera with uid : 0x%"PRIx64".",
160 sys->selected_uid );
161 goto end;
164 else if( sys->selected_camera >= (int)list->num )
166 msg_Err( p_demux, "There are not this many cameras. (%d/%d)",
167 sys->selected_camera, sys->num_cameras );
168 goto end;
170 else if( sys->selected_camera >= 0 )
172 sys->camera = dc1394_camera_new(sys->p_dccontext,
173 list->ids[sys->selected_camera].guid);
175 else
177 sys->camera = dc1394_camera_new(sys->p_dccontext,
178 list->ids[0].guid);
181 i_ret = VLC_SUCCESS;
183 end:
184 dc1394_camera_free_list (list);
185 return i_ret;
188 /*****************************************************************************
189 * Open:
190 *****************************************************************************/
191 static int Open( vlc_object_t *p_this )
193 demux_t *p_demux = (demux_t*)p_this;
194 demux_sys_t *p_sys;
195 es_format_t fmt;
196 dc1394error_t res;
197 int i_width;
198 int i_height;
200 if( strncmp(p_demux->psz_access, "dc1394", 6) != 0 )
201 return VLC_EGENERIC;
203 /* Set up p_demux */
204 p_demux->pf_demux = Demux;
205 p_demux->pf_control = Control;
206 p_demux->info.i_update = 0;
207 p_demux->info.i_title = 0;
208 p_demux->info.i_seekpoint = 0;
210 p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
211 if( !p_sys )
212 return VLC_ENOMEM;
214 memset( &fmt, 0, sizeof( es_format_t ) );
216 /* DEFAULTS */
217 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV422;
218 p_sys->width = 640;
219 p_sys->height = 480;
220 p_sys->frame_rate = DC1394_FRAMERATE_15;
221 p_sys->brightness = 200;
222 p_sys->focus = 0;
223 p_sys->fd_audio = -1;
224 p_sys->p_dccontext = NULL;
225 p_sys->camera = NULL;
226 p_sys->selected_camera = -1;
227 p_sys->dma_buffers = 1;
228 p_sys->reset_bus = 0;
230 /* PROCESS INPUT OPTIONS */
231 if( process_options(p_demux) != VLC_SUCCESS )
233 msg_Err( p_demux, "Bad MRL, please check the option line "
234 "(MRL was: %s)",
235 p_demux->psz_location );
236 free( p_sys );
237 return VLC_EGENERIC;
240 p_sys->p_dccontext = dc1394_new();
241 if( !p_sys->p_dccontext )
243 msg_Err( p_demux, "Failed to initialise libdc1394");
244 free( p_sys );
245 return VLC_EGENERIC;
248 if( FindCamera( p_sys, p_demux ) != VLC_SUCCESS )
250 dc1394_free( p_sys->p_dccontext );
251 free( p_sys );
252 return VLC_EGENERIC;
255 if( !p_sys->camera )
257 msg_Err( p_demux, "No camera found !!" );
258 dc1394_free( p_sys->p_dccontext );
259 free( p_sys );
260 return VLC_EGENERIC;
263 if( p_sys->reset_bus )
265 if( dc1394_reset_bus( p_sys->camera ) != DC1394_SUCCESS )
267 msg_Err( p_demux, "Unable to reset IEEE 1394 bus");
268 Close( p_this );
269 return VLC_EGENERIC;
271 else msg_Dbg( p_demux, "Successfully reset IEEE 1394 bus");
274 if( dc1394_camera_reset( p_sys->camera ) != DC1394_SUCCESS )
276 msg_Err( p_demux, "Unable to reset camera");
277 Close( p_this );
278 return VLC_EGENERIC;
281 if( dc1394_camera_print_info( p_sys->camera,
282 stderr ) != DC1394_SUCCESS )
284 msg_Err( p_demux, "Unable to print camera info");
285 Close( p_this );
286 return VLC_EGENERIC;
289 if( dc1394_feature_get_all( p_sys->camera,
290 &p_sys->features ) != DC1394_SUCCESS )
292 msg_Err( p_demux, "Unable to get feature set");
293 Close( p_this );
294 return VLC_EGENERIC;
296 // TODO: only print features if verbosity increased
297 dc1394_feature_print_all(&p_sys->features, stderr);
299 #if 0 //"Note that you need to execute this function only if you use exotic video1394 device names. /dev/video1394, /dev/video1394/* and /dev/video1394-* are automatically recognized." http://damien.douxchamps.net/ieee1394/libdc1394/v2.x/api/capture/
300 if( p_sys->video_device )
302 if( dc1394_capture_set_device_filename( p_sys->camera,
303 p_sys->video_device ) != DC1394_SUCCESS )
305 msg_Err( p_demux, "Unable to set video device");
306 Close( p_this );
307 return VLC_EGENERIC;
310 #endif
312 if( p_sys->focus )
314 if( dc1394_feature_set_value( p_sys->camera,
315 DC1394_FEATURE_FOCUS,
316 p_sys->focus ) != DC1394_SUCCESS )
318 msg_Err( p_demux, "Unable to set initial focus to %u",
319 p_sys->focus );
321 else
322 msg_Dbg( p_demux, "Initial focus set to %u", p_sys->focus );
325 if( dc1394_feature_set_value( p_sys->camera,
326 DC1394_FEATURE_FOCUS,
327 p_sys->brightness ) != DC1394_SUCCESS )
329 msg_Err( p_demux, "Unable to set initial brightness to %u",
330 p_sys->brightness );
332 else
333 msg_Dbg( p_demux, "Initial brightness set to %u", p_sys->brightness );
335 if( dc1394_video_set_framerate( p_sys->camera,
336 p_sys->frame_rate ) != DC1394_SUCCESS )
338 msg_Err( p_demux, "Unable to set framerate");
339 Close( p_this );
340 return VLC_EGENERIC;
343 if( dc1394_video_set_mode( p_sys->camera,
344 p_sys->video_mode ) != DC1394_SUCCESS )
346 msg_Err( p_demux, "Unable to set video mode");
347 Close( p_this );
348 return VLC_EGENERIC;
351 if( dc1394_video_set_iso_speed( p_sys->camera,
352 DC1394_ISO_SPEED_400 ) != DC1394_SUCCESS )
354 msg_Err( p_demux, "Unable to set iso speed");
355 Close( p_this );
356 return VLC_EGENERIC;
359 /* and setup capture */
360 res = dc1394_capture_setup( p_sys->camera,
361 p_sys->dma_buffers,
362 DC1394_CAPTURE_FLAGS_DEFAULT);
363 if( res != DC1394_SUCCESS )
365 if( res == DC1394_NO_BANDWIDTH )
367 msg_Err( p_demux ,"No bandwidth: try adding the "
368 "\"resetbus\" option" );
370 else
372 msg_Err( p_demux ,"Unable to setup capture" );
374 Close( p_this );
375 return VLC_EGENERIC;
378 /* TODO - UYV444 chroma converter is missing, when it will be available
379 * fourcc will become variable (and not just a fixed value for UYVY)
381 i_width = p_sys->width;
382 i_height = p_sys->height;
384 if( picture_Setup( &p_sys->pic, VLC_CODEC_UYVY,
385 i_width, i_height, 1, 1 ) )
387 msg_Err( p_demux ,"unknown chroma" );
388 Close( p_this );
389 return VLC_EGENERIC;
392 es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_UYVY );
394 fmt.video.i_width = i_width;
395 fmt.video.i_height = i_height;
397 msg_Dbg( p_demux, "Added new video es %4.4s %dx%d",
398 (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
400 p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );
402 if( p_sys->audio_device )
404 if( OpenAudioDev( p_demux ) == VLC_SUCCESS )
406 es_format_t fmt;
407 es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_S16L ); /* FIXME: hmm, ?? */
409 fmt.audio.i_channels = p_sys->channels ? p_sys->channels : 1;
410 fmt.audio.i_rate = p_sys->i_sample_rate;
411 fmt.audio.i_bitspersample = 16;
412 fmt.audio.i_blockalign = fmt.audio.i_channels *
413 fmt.audio.i_bitspersample / 8;
414 fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
415 fmt.audio.i_bitspersample;
417 msg_Dbg( p_demux, "New audio es %d channels %dHz",
418 fmt.audio.i_channels, fmt.audio.i_rate );
420 p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt );
424 /* have the camera start sending us data */
425 if( dc1394_video_set_transmission( p_sys->camera,
426 DC1394_ON ) != DC1394_SUCCESS )
428 msg_Err( p_demux, "Unable to start camera iso transmission" );
429 dc1394_capture_stop( p_sys->camera );
430 Close( p_this );
431 return VLC_EGENERIC;
433 msg_Dbg( p_demux, "Set iso transmission" );
434 // TODO: reread camera
435 return VLC_SUCCESS;
438 static int OpenAudioDev( demux_t *p_demux )
440 demux_sys_t *p_sys = p_demux->p_sys;
441 char *psz_device = p_sys->audio_device;
442 int i_format = AFMT_S16_LE;
443 int result;
445 p_sys->fd_audio = vlc_open( psz_device, O_RDONLY | O_NONBLOCK );
446 if( p_sys->fd_audio < 0 )
448 msg_Err( p_demux, "Cannot open audio device (%s)", psz_device );
449 return VLC_EGENERIC;
452 if( !p_sys->i_sample_rate )
453 p_sys->i_sample_rate = 44100;
455 result = ioctl( p_sys->fd_audio, SNDCTL_DSP_SETFMT, &i_format );
456 if( (result < 0) || (i_format != AFMT_S16_LE) )
458 msg_Err( p_demux, "Cannot set audio format (16b little endian) "
459 "(%d)", i_format );
460 goto error;
463 result = ioctl( p_sys->fd_audio, SNDCTL_DSP_CHANNELS, &p_sys->channels );
464 if( result < 0 )
466 msg_Err( p_demux, "Cannot set audio channels count (%d)",
467 p_sys->channels );
468 goto error;
471 result = ioctl( p_sys->fd_audio, SNDCTL_DSP_SPEED, &p_sys->i_sample_rate );
472 if( result < 0 )
474 msg_Err( p_demux, "Cannot set audio sample rate (%d)",
475 p_sys->i_sample_rate );
476 goto error;
479 msg_Dbg( p_demux, "Opened adev=`%s' %s %dHz",
480 psz_device,
481 (p_sys->channels > 1) ? "stereo" : "mono",
482 p_sys->i_sample_rate );
484 p_sys->i_audio_max_frame_size = 32 * 1024;
486 return VLC_SUCCESS;
488 error:
489 CloseAudioDev( p_demux );
490 p_sys->fd_audio = -1;
491 return VLC_EGENERIC;
494 static inline void CloseAudioDev( demux_t *p_demux )
496 demux_sys_t *p_sys = p_demux->p_sys;
498 if( p_sys->fd_audio >= 0 )
499 close( p_sys->fd_audio );
502 /*****************************************************************************
503 * Close:
504 *****************************************************************************/
505 static void Close( vlc_object_t *p_this )
507 demux_t *p_demux = (demux_t*)p_this;
508 demux_sys_t *p_sys = p_demux->p_sys;
510 /* Stop data transmission */
511 if( dc1394_video_set_transmission( p_sys->camera,
512 DC1394_OFF ) != DC1394_SUCCESS )
513 msg_Err( p_demux, "Unable to stop camera iso transmission" );
515 /* Close camera */
516 dc1394_capture_stop( p_sys->camera );
518 CloseAudioDev( p_demux );
520 dc1394_camera_free(p_sys->camera);
521 dc1394_free(p_sys->p_dccontext);
523 free( p_sys->video_device );
524 free( p_sys->audio_device );
525 free( p_sys );
528 #if 0
529 static void MovePixelUYVY( void *src, int spos, void *dst, int dpos )
531 char u,v,y;
532 u_char *sc;
533 u_char *dc;
535 sc = (u_char *)src + (spos*2);
536 if( spos % 2 )
538 v = sc[0];
539 y = sc[1];
540 u = *(sc -2);
542 else
544 u = sc[0];
545 y = sc[1];
546 v = sc[2];
548 dc = (u_char *)dst+(dpos*2);
549 if( dpos % 2 )
551 dc[0] = v;
552 dc[1] = y;
554 else
556 dc[0] = u;
557 dc[1] = y;
560 #endif
562 /*****************************************************************************
563 * Demux:
564 *****************************************************************************/
565 static block_t *GrabVideo( demux_t *p_demux )
567 demux_sys_t *p_sys = p_demux->p_sys;
568 block_t *p_block = NULL;
570 if( dc1394_capture_dequeue( p_sys->camera,
571 DC1394_CAPTURE_POLICY_WAIT,
572 &p_sys->frame ) != DC1394_SUCCESS )
574 msg_Err( p_demux, "Unable to capture a frame" );
575 return NULL;
578 p_block = block_New( p_demux, p_sys->frame->size[0] *
579 p_sys->frame->size[1] * 2 );
580 if( !p_block )
582 msg_Err( p_demux, "Can not get block" );
583 return NULL;
586 if( !p_sys->frame->image )
588 msg_Err (p_demux, "Capture buffer empty");
589 block_Release( p_block );
590 return NULL;
593 memcpy( p_block->p_buffer, (const char *)p_sys->frame->image,
594 p_sys->width * p_sys->height * 2 );
596 p_block->i_pts = p_block->i_dts = mdate();
597 dc1394_capture_enqueue( p_sys->camera, p_sys->frame );
598 return p_block;
601 static block_t *GrabAudio( demux_t *p_demux )
603 demux_sys_t *p_sys = p_demux->p_sys;
604 struct audio_buf_info buf_info;
605 block_t *p_block = NULL;
606 int i_read = 0;
607 int i_correct = 0;
608 int result = 0;
610 p_block = block_New( p_demux, p_sys->i_audio_max_frame_size );
611 if( !p_block )
613 msg_Warn( p_demux, "Cannot get buffer" );
614 return NULL;
617 i_read = read( p_sys->fd_audio, p_block->p_buffer,
618 p_sys->i_audio_max_frame_size );
620 if( i_read <= 0 )
622 block_Release( p_block );
623 return NULL;
626 p_block->i_buffer = i_read;
628 /* Correct the date because of kernel buffering */
629 i_correct = i_read;
630 result = ioctl( p_sys->fd_audio, SNDCTL_DSP_GETISPACE, &buf_info );
631 if( result == 0 )
632 i_correct += buf_info.bytes;
634 p_block->i_pts = p_block->i_dts =
635 mdate() - INT64_C(1000000) * (mtime_t)i_correct /
636 2 / p_sys->channels / p_sys->i_sample_rate;
637 return p_block;
640 static int Demux( demux_t *p_demux )
642 demux_sys_t *p_sys = p_demux->p_sys;
643 block_t *p_blocka = NULL;
644 block_t *p_blockv = NULL;
646 /* Try grabbing audio frames first */
647 if( p_sys->fd_audio >= 0 )
648 p_blocka = GrabAudio( p_demux );
650 /* Try grabbing video frame */
651 p_blockv = GrabVideo( p_demux );
653 if( !p_blocka && !p_blockv )
655 /* Sleep so we do not consume all the cpu, 10ms seems
656 * like a good value (100fps)
658 msleep( 10000 );
659 return 1;
662 if( p_blocka )
664 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_blocka->i_pts );
665 es_out_Send( p_demux->out, p_sys->p_es_audio, p_blocka );
668 if( p_blockv )
670 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_blockv->i_pts );
671 es_out_Send( p_demux->out, p_sys->p_es_video, p_blockv );
673 return 1;
676 /*****************************************************************************
677 * Control:
678 *****************************************************************************/
679 static int Control( demux_t *p_demux, int i_query, va_list args )
681 VLC_UNUSED( p_demux );
682 switch( i_query )
684 /* Special for access_demux */
685 case DEMUX_CAN_PAUSE:
686 case DEMUX_CAN_SEEK:
687 case DEMUX_SET_PAUSE_STATE:
688 case DEMUX_CAN_CONTROL_PACE:
689 *va_arg( args, bool * ) = false;
690 return VLC_SUCCESS;
692 case DEMUX_GET_PTS_DELAY:
693 *va_arg( args, int64_t * ) = (int64_t)DEFAULT_PTS_DELAY;
694 return VLC_SUCCESS;
696 case DEMUX_GET_TIME:
697 *va_arg( args, int64_t * ) = mdate();
698 return VLC_SUCCESS;
700 /* TODO implement others */
701 default:
702 return VLC_EGENERIC;
704 return VLC_EGENERIC;
707 static int process_options( demux_t *p_demux )
709 demux_sys_t *p_sys = p_demux->p_sys;
710 char *psz_dup;
711 char *psz_parser;
712 char *token = NULL;
713 char *state = NULL;
714 const char *in_size = NULL;
715 const char *in_fmt = NULL;
716 float rate_f;
718 psz_dup = strdup( p_demux->psz_location );
719 psz_parser = psz_dup;
720 for( token = strtok_r( psz_parser,":",&state); token;
721 token = strtok_r( NULL, ":", &state ) )
723 if( strncmp( token, "size=", strlen("size=") ) == 0 )
725 token += strlen("size=");
726 if( strncmp( token, "160x120", 7 ) == 0 )
728 /* TODO - UYV444 chroma converter is needed ...
729 * video size of 160x120 is temporarily disabled
731 msg_Err( p_demux,
732 "video size of 160x120 is actually disabled for lack of"
733 "chroma support. It will relased ASAP, until then try "
734 "an higher size (320x240 and 640x480 are fully supported)" );
735 free(psz_dup);
736 return VLC_EGENERIC;
737 #if 0
738 in_size = "160x120";
739 p_sys->width = 160;
740 p_sys->height = 120;
741 #endif
743 else if( strncmp( token, "320x240", 7 ) == 0 )
745 in_size = "320x240";
746 p_sys->width = 320;
747 p_sys->height = 240;
749 else if( strncmp( token, "640x480", 7 ) == 0 )
751 in_size = "640x480";
752 p_sys->width = 640;
753 p_sys->height = 480;
755 else
757 msg_Err( p_demux,
758 "This program currently suppots frame sizes of"
759 " 160x120, 320x240, and 640x480. "
760 "Please specify one of them. You have specified %s.",
761 token );
762 free(psz_dup);
763 return VLC_EGENERIC;
765 msg_Dbg( p_demux, "Requested video size : %s",token );
767 if( strncmp( token, "format=", strlen("format=") ) == 0 )
769 token += strlen("format=");
770 if( strncmp( token, "YUV411", 6 ) == 0 )
772 in_fmt = "YUV411";
774 else if( strncmp( token, "YUV422", 6 ) == 0 )
776 in_fmt = "YUV422";
778 else if( strncmp( token, "YUV444", 6 ) == 0 )
780 in_fmt = "YUV444";
782 else if( strncmp( token, "RGB8", 4 ) == 0 )
784 in_fmt = "RGB8";
786 else if( strncmp( token, "MONO8", 5 ) == 0 )
788 in_fmt = "MONO8";
790 else if( strncmp( token, "MONO16", 6 ) == 0 )
792 in_fmt = "MONO16";
794 else
796 msg_Err( p_demux, "Invalid format %s.", token );
797 free(psz_dup);
798 return VLC_EGENERIC;
800 msg_Dbg( p_demux, "Requested video format : %s", token );
802 else if( strncmp( token, "fps=", strlen( "fps=" ) ) == 0 )
804 token += strlen("fps=");
805 sscanf( token, "%g", &rate_f );
806 if( rate_f == 1.875 )
807 p_sys->frame_rate = DC1394_FRAMERATE_1_875;
808 else if( rate_f == 3.75 )
809 p_sys->frame_rate = DC1394_FRAMERATE_3_75;
810 else if( rate_f == 7.5 )
811 p_sys->frame_rate = DC1394_FRAMERATE_7_5;
812 else if( rate_f == 15 )
813 p_sys->frame_rate = DC1394_FRAMERATE_15;
814 else if( rate_f == 30 )
815 p_sys->frame_rate = DC1394_FRAMERATE_30;
816 else if( rate_f == 60 )
817 p_sys->frame_rate = DC1394_FRAMERATE_60;
818 else
820 msg_Err( p_demux ,
821 "This program supports framerates of"
822 " 1.875, 3.75, 7.5, 15, 30, 60. "
823 "Please specify one of them. You have specified %s.",
824 token);
825 free(psz_dup);
826 return VLC_EGENERIC;
828 msg_Dbg( p_demux, "Requested frame rate : %s",token );
830 else if( strncmp( token, "resetbus", strlen( "resetbus" ) ) == 0 )
832 token += strlen("resetbus");
833 p_sys->reset_bus = 1;
835 else if( strncmp( token, "brightness=", strlen( "brightness=" ) ) == 0 )
837 int nr = 0;
838 token += strlen("brightness=");
839 nr = sscanf( token, "%u", &p_sys->brightness);
840 if( nr != 1 )
842 msg_Err( p_demux, "Bad brightness value '%s', "
843 "must be an unsigned integer.",
844 token );
845 free(psz_dup);
846 return VLC_EGENERIC;
849 else if( strncmp( token, "buffers=", strlen( "buffers=" ) ) == 0 )
851 int nr = 0;
852 int in_buf = 0;
853 token += strlen("buffers=");
854 nr = sscanf( token, "%d", &in_buf);
855 if( nr != 1 || in_buf < 1 )
857 msg_Err( p_demux, "DMA buffers must be 1 or greater." );
858 free(psz_dup);
859 return VLC_EGENERIC;
861 else p_sys->dma_buffers = in_buf;
863 #if 0
864 // NOTE: If controller support is added back, more logic will needed to be added
865 // after the cameras are scanned.
866 else if( strncmp( token, "controller=", strlen( "controller=" ) ) == 0 )
868 int nr = 0;
869 token += strlen("controller=");
870 nr = sscanf( token, "%u", &p_sys->controller );
871 if( nr != 1)
873 msg_Err(p_demux, "Bad controller value '%s', "
874 "must be an unsigned integer.",
875 token );
876 return VLC_EGENERIC;
879 #endif
880 else if( strncmp( token, "camera=", strlen( "camera=" ) ) == 0 )
882 int nr = 0;
883 token += strlen("camera=");
884 nr = sscanf(token,"%u",&p_sys->selected_camera);
885 if( nr != 1)
887 msg_Err( p_demux, "Bad camera number '%s', "
888 "must be an unsigned integer.",
889 token );
890 free(psz_dup);
891 return VLC_EGENERIC;
894 else if( strncmp( token, "vdev=", strlen( "vdev=" ) ) == 0)
896 token += strlen("vdev=");
897 p_sys->video_device = strdup(token);
898 msg_Dbg( p_demux, "Using video device '%s'.", token );
900 else if( strncmp( token, "adev=", strlen( "adev=" ) ) == 0 )
902 token += strlen("adev=");
903 p_sys->audio_device = strdup(token);
904 msg_Dbg( p_demux, "Using audio device '%s'.", token );
906 else if( strncmp( token, "samplerate=", strlen( "samplerate=" ) ) == 0 )
908 token += strlen("samplerate=");
909 sscanf( token, "%d", &p_sys->i_sample_rate );
911 else if( strncmp( token, "channels=", strlen("channels=" ) ) == 0 )
913 token += strlen("channels=");
914 sscanf( token, "%d", &p_sys->channels );
916 else if( strncmp( token, "focus=", strlen("focus=" ) ) == 0)
918 int nr = 0;
919 token += strlen("focus=");
920 nr = sscanf( token, "%u", &p_sys->focus );
921 if( nr != 1 )
923 msg_Err( p_demux, "Bad focus value '%s', "
924 "must be an unsigned integer.",
925 token );
926 free(psz_dup);
927 return VLC_EGENERIC;
930 else if( strncmp( token, "uid=", strlen("uid=") ) == 0)
932 token += strlen("uid=");
933 sscanf( token, "0x%"SCNx64, &p_sys->selected_uid );
937 // The mode is a combination of size and format and not every format
938 // is supported by every size.
939 if( in_size)
941 if( strcmp( in_size, "160x120") == 0)
943 if( in_fmt && (strcmp( in_fmt, "YUV444") != 0) )
944 msg_Err(p_demux, "160x120 only supports YUV444 - forcing");
945 p_sys->video_mode = DC1394_VIDEO_MODE_160x120_YUV444;
947 else if( strcmp( in_size, "320x240") == 0)
949 if( in_fmt && (strcmp( in_fmt, "YUV422") != 0) )
950 msg_Err(p_demux, "320x240 only supports YUV422 - forcing");
951 p_sys->video_mode = DC1394_VIDEO_MODE_320x240_YUV422;
954 else
955 { // 640x480 default
956 if( in_fmt )
958 if( strcmp( in_fmt, "RGB8") == 0)
959 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_RGB8;
960 else if( strcmp( in_fmt, "MONO8") == 0)
961 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_MONO8;
962 else if( strcmp( in_fmt, "MONO16") == 0)
963 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_MONO16;
964 else if( strcmp( in_fmt, "YUV411") == 0)
965 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV411;
966 else // YUV422 default
967 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV422;
969 else // YUV422 default
970 p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV422;
973 free( psz_dup );
974 return VLC_SUCCESS;