aboutsummaryrefslogtreecommitdiffstats
path: root/src/tvtime-startup.c
diff options
context:
space:
mode:
authorvektor <devnull@localhost>2004-06-26 03:22:27 +0000
committervektor <devnull@localhost>2004-06-26 03:22:27 +0000
commita61848b5cc112e8537518fd16267c0f1289e0a93 (patch)
tree5033d56d5727b0188834be3ca3865ffd43e5a689 /src/tvtime-startup.c
parentb8641134fd8e665210e439dbdb22e038c1cce997 (diff)
25 Jun 2004 Billy Biggs <vektor@dumbterm.net>
* tvtime/src/tvtime-startup.c: Updated tvtime-startup with some more ideas. Nothing really usable yet.
Diffstat (limited to 'src/tvtime-startup.c')
-rw-r--r--src/tvtime-startup.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/tvtime-startup.c b/src/tvtime-startup.c
index 936fbcf..87b2afc 100644
--- a/src/tvtime-startup.c
+++ b/src/tvtime-startup.c
@@ -17,6 +17,14 @@
*/
#include <gtk/gtk.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@@ -26,6 +34,104 @@
#else
# define _(string) string
#endif
+#include "videodev.h"
+#include "videodev2.h"
+
+
+void probe_device( const char *device )
+{
+ struct video_capability caps_v4l1;
+ struct v4l2_capability caps_v4l2;
+ char *drivername;
+ int isv4l2 = 0;
+ int isbttv = 0;
+ int numinputs = 0;
+ int fd;
+ int i;
+
+ /* First, open the device. */
+ fd = open( device, O_RDWR );
+ if( fd < 0 ) {
+ fprintf( stderr, "videoinput: Cannot open capture device %s: %s\n",
+ device, strerror( errno ) );
+ return;
+ }
+
+ /**
+ * Next, ask for its capabilities. This will also confirm it's a V4L2
+ * device.
+ */
+ if( ioctl( fd, VIDIOC_QUERYCAP, &caps_v4l2 ) < 0 ) {
+ /* Can't get V4L2 capabilities, maybe this is a V4L1 device? */
+ if( ioctl( fd, VIDIOCGCAP, &caps_v4l1 ) < 0 ) {
+ fprintf( stderr, "videoinput: %s is not a video4linux device.\n",
+ device );
+ close( fd );
+ return;
+ } else {
+ fprintf( stderr, "videoinput: Using video4linux driver '%s'.\n"
+ "videoinput: Card type is %x, audio %d.\n",
+ caps_v4l1.name, caps_v4l1.type, caps_v4l1.audios );
+ }
+ //snprintf( drivername, sizeof( vidin->drivername ), "%s", caps_v4l1.name );
+ } else {
+ fprintf( stderr, "videoinput: Using video4linux2 driver '%s', card '%s' (bus %s).\n"
+ "videoinput: Version is %u, capabilities %x.\n",
+ caps_v4l2.driver, caps_v4l2.card, caps_v4l2.bus_info,
+ caps_v4l2.version, caps_v4l2.capabilities );
+ isv4l2 = 1;
+ /*
+ snprintf( vidin->drivername, sizeof( vidin->drivername ),
+ "%s (card %s, bus %s) - %u",
+ caps_v4l2.driver, caps_v4l2.card,
+ caps_v4l2.bus_info, caps_v4l2.version );
+ */
+ }
+
+ if( isv4l2 ) {
+ struct v4l2_input in;
+
+ numinputs = 0;
+ in.index = numinputs;
+
+ /**
+ * We have to enumerate all of the inputs just to know how many
+ * there are.
+ */
+ while( ioctl( fd, VIDIOC_ENUMINPUT, &in ) >= 0 ) {
+ numinputs++;
+ in.index = numinputs;
+ }
+
+ if( !numinputs ) {
+ fprintf( stderr, "videoinput: No inputs available on "
+ "video4linux2 device '%s'.\n", device );
+ close( fd );
+ return;
+ }
+ } else {
+ /* The capabilities should tell us how many inputs this card has. */
+ numinputs = caps_v4l1.channels;
+ if( numinputs == 0 ) {
+ fprintf( stderr, "videoinput: No inputs available on "
+ "video4linux device '%s'.\n", device );
+ close( fd );
+ return;
+ }
+ }
+ fprintf( stderr, "%d inputs\n", numinputs );
+
+ /* Check if this is a bttv-based card. Code taken from xawtv. */
+#define BTTV_VERSION _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
+ /* dirty hack time / v4l design flaw -- works with bttv only
+ * this adds support for a few less common PAL versions */
+ if( !(ioctl( fd, BTTV_VERSION, &i ) < 0) ) {
+ isbttv = 1;
+ fprintf( stderr, "bttv\n" );
+ }
+#undef BTTV_VERSION
+}
+
int main( int argc, char **argv )
{
@@ -33,6 +139,12 @@ int main( int argc, char **argv )
gtk_init_check( &argc, &argv );
+
+ probe_device( "/dev/video0" );
+ probe_device( "/dev/video1" );
+ probe_device( "/dev/video2" );
+ probe_device( "/dev/video3" );
+
/* Here is how we will talk to the user. */
dialog = gtk_message_dialog_new( 0,
GTK_DIALOG_DESTROY_WITH_PARENT,

Privacy Policy