changeset 22381:6cabac4d35b5

tv driver loading rework. As a side effect "-tv driver=help" option is implemented.
author voroshil
date Thu, 01 Mar 2007 18:38:00 +0000
parents e47d88c5cbc0
children 0cdde40210bd
files stream/tv.c stream/tv.h stream/tvi_bsdbt848.c stream/tvi_def.h stream/tvi_dummy.c stream/tvi_v4l.c stream/tvi_v4l2.c
diffstat 7 files changed, 75 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/stream/tv.c	Thu Mar 01 17:34:24 2007 +0000
+++ b/stream/tv.c	Thu Mar 01 18:38:00 2007 +0000
@@ -71,8 +71,8 @@
 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
 int tv_param_alsa = 0;
 #endif
+#endif
 char* tv_param_adevice = NULL;
-#endif
 int tv_param_brightness = 0;
 int tv_param_contrast = 0;
 int tv_param_hue = 0;
@@ -81,6 +81,33 @@
 tv_channels_t *tv_channel_current, *tv_channel_last;
 char *tv_channel_last_real;
 
+/* enumerating drivers (like in stream.c) */
+extern tvi_info_t tvi_info_dummy;
+#ifdef HAVE_TV_V4L1
+extern tvi_info_t tvi_info_v4l;
+#endif
+#ifdef HAVE_TV_V4L2
+extern tvi_info_t tvi_info_v4l2;
+#endif
+#ifdef HAVE_TV_BSDBT848
+extern tvi_info_t tvi_info_bsdbt848;
+#endif
+
+static const tvi_info_t* tvi_driver_list[]={
+    &tvi_info_dummy,
+#ifdef HAVE_TV_V4L1
+    &tvi_info_v4l,
+#endif
+#ifdef HAVE_TV_V4L2
+    &tvi_info_v4l2,
+#endif
+#ifdef HAVE_TV_BSDBT848
+    &tvi_info_bsdbt848,
+#endif
+    NULL
+};
+
+
 /* ================== DEMUX_TV ===================== */
 /*
   Return value:
@@ -482,7 +509,7 @@
     
     demuxer->priv=NULL;
     if(!(tvh=tv_begin())) return NULL;
-    if (!tv_init(tvh)) return NULL;
+    if (!tvh->functions->init(tvh->priv)) return NULL;
     if (!open_tv(tvh)){
 	tv_uninit(tvh);
 	return NULL;
@@ -632,43 +659,41 @@
 }
 
 /* ================== STREAM_TV ===================== */
-tvi_handle_t *tvi_init_dummy(char *device);
-tvi_handle_t *tvi_init_v4l(char *device, char *adevice);
-tvi_handle_t *tvi_init_v4l2(char *device, char *adevice);
-tvi_handle_t *tvi_init_bsdbt848(char *device);
 
 tvi_handle_t *tv_begin(void)
 {
-    if (!strcmp(tv_param_driver, "dummy"))
-	return tvi_init_dummy(tv_param_device);
-#ifdef HAVE_TV_V4L1
-    if (!strcmp(tv_param_driver, "v4l"))
-	return tvi_init_v4l(tv_param_device, tv_param_adevice);
-#endif
-#ifdef HAVE_TV_V4L2
-    if (!strcmp(tv_param_driver, "v4l2"))
-	return tvi_init_v4l2(tv_param_device, tv_param_adevice);
-#endif
-#ifdef HAVE_TV_BSDBT848
-    if (!strcmp(tv_param_driver, "bsdbt848"))
-	return tvi_init_bsdbt848(tv_param_device);
-#endif
+    int i;
+    tvi_info_t* info;
+    tvi_handle_t* h;
+    if(!strcmp(tv_param_driver,"help")){
+        mp_msg(MSGT_TV,MSGL_INFO,"Available drivers:\n");
+        for(i=0;tvi_driver_list[i];i++){
+	    mp_msg(MSGT_TV,MSGL_INFO," %s\t%s",tvi_driver_list[i]->short_name,tvi_driver_list[i]->name);
+	    if(tvi_driver_list[i]->comment)
+	        mp_msg(MSGT_TV,MSGL_INFO," (%s)",tvi_driver_list[i]->comment);
+	    mp_msg(MSGT_TV,MSGL_INFO,"\n");
+	}
+	return NULL;
+    }
 
+    for(i=0;tvi_driver_list[i];i++){
+        if (!strcmp(tvi_driver_list[i]->short_name, tv_param_driver)){
+            h=tvi_driver_list[i]->tvi_init(tv_param_device,tv_param_adevice);
+            if(!h) return NULL;
+
+            mp_msg(MSGT_TV, MSGL_INFO, "Selected driver: %s\n", tvi_driver_list[i]->short_name);
+            mp_msg(MSGT_TV, MSGL_INFO, " name: %s\n", tvi_driver_list[i]->name);
+            mp_msg(MSGT_TV, MSGL_INFO, " author: %s\n", tvi_driver_list[i]->author);
+            if (tvi_driver_list[i]->comment)
+                mp_msg(MSGT_TV, MSGL_INFO, " comment: %s\n", tvi_driver_list[i]->comment);
+            return h;
+        }
+    }
+    
     mp_msg(MSGT_TV, MSGL_ERR, "No such driver: %s\n", tv_param_driver); 
     return(NULL);
 }
 
-int tv_init(tvi_handle_t *tvh)
-{
-    mp_msg(MSGT_TV, MSGL_INFO, "Selected driver: %s\n", tvh->info->short_name);
-    mp_msg(MSGT_TV, MSGL_INFO, " name: %s\n", tvh->info->name);
-    mp_msg(MSGT_TV, MSGL_INFO, " author: %s\n", tvh->info->author);
-    if (tvh->info->comment)
-	mp_msg(MSGT_TV, MSGL_INFO, " comment: %s\n", tvh->info->comment);
-
-    return(tvh->functions->init(tvh->priv));
-}
-
 int tv_uninit(tvi_handle_t *tvh)
 {
     int res;
--- a/stream/tv.h	Thu Mar 01 17:34:24 2007 +0000
+++ b/stream/tv.h	Thu Mar 01 18:38:00 2007 +0000
@@ -52,6 +52,7 @@
 
 typedef struct tvi_info_s
 {
+    struct tvi_handle_s * (*tvi_init)(char *device,char *adevice);
     const char *name;
     const char *short_name;
     const char *author;
@@ -74,7 +75,6 @@
 } tvi_functions_t;
 
 typedef struct tvi_handle_s {
-    tvi_info_t		*info;
     tvi_functions_t	*functions;
     void		*priv;
     int 		seq;
--- a/stream/tvi_bsdbt848.c	Thu Mar 01 17:34:24 2007 +0000
+++ b/stream/tvi_bsdbt848.c	Thu Mar 01 18:38:00 2007 +0000
@@ -66,8 +66,10 @@
 #include "libmpcodecs/img_format.h"
 #include "tv.h"
 
+static tvi_handle_t *tvi_init_bsdbt848(char *device, char *adevice);
 /* information about this file */
-static tvi_info_t info = {
+tvi_info_t tvi_info_bsdbt848 = {
+    tvi_init_bsdbt848,
     "Brooktree848 Support",
     "bsdbt848",
     "Charles Henrich",
@@ -169,7 +171,7 @@
 }
 
 /* handler creator - entry point ! */
-tvi_handle_t *tvi_init_bsdbt848(char *device)
+static tvi_handle_t *tvi_init_bsdbt848(char *device,char* adevice)
 {
     return(new_handle());
 }
--- a/stream/tvi_def.h	Thu Mar 01 17:34:24 2007 +0000
+++ b/stream/tvi_def.h	Thu Mar 01 18:38:00 2007 +0000
@@ -41,7 +41,6 @@
 	return(NULL);
     }
     memset(h->priv, 0, sizeof(priv_t));
-    h->info = &info;
     h->functions = &functions;
     h->seq = 0;
     h->chanlist = -1;
--- a/stream/tvi_dummy.c	Thu Mar 01 17:34:24 2007 +0000
+++ b/stream/tvi_dummy.c	Thu Mar 01 18:38:00 2007 +0000
@@ -8,8 +8,10 @@
 #include "libmpcodecs/img_format.h"
 #include "tv.h"
 
+static tvi_handle_t *tvi_init_dummy(char *device,char *adevice);
 /* information about this file */
-static tvi_info_t info = {
+tvi_info_t tvi_info_dummy = {
+	tvi_init_dummy,
 	"NULL-TV",
 	"dummy",
 	"alex",
@@ -25,7 +27,7 @@
 #include "tvi_def.h"
 
 /* handler creator - entry point ! */
-tvi_handle_t *tvi_init_dummy(char *device)
+static tvi_handle_t *tvi_init_dummy(char *device,char *adevice)
 {
     return(new_handle());
 }
--- a/stream/tvi_v4l.c	Thu Mar 01 17:34:24 2007 +0000
+++ b/stream/tvi_v4l.c	Thu Mar 01 18:38:00 2007 +0000
@@ -48,7 +48,10 @@
 
 #include "audio_in.h"
 
-static tvi_info_t info = {
+static tvi_handle_t *tvi_init_v4l(char *device, char *adevice);
+
+tvi_info_t tvi_info_v4l = {
+	tvi_init_v4l,
 	"Video 4 Linux input",
 	"v4l",
 	"Alex Beregszaszi",
@@ -266,7 +269,7 @@
 	   priv->audio_buffer_size, priv->audio_in.blocksize, priv->aud_skew_cnt);
 }
 
-tvi_handle_t *tvi_init_v4l(char *device, char *adevice)
+static tvi_handle_t *tvi_init_v4l(char *device, char *adevice)
 {
     tvi_handle_t *h;
     priv_t *priv;
--- a/stream/tvi_v4l2.c	Thu Mar 01 17:34:24 2007 +0000
+++ b/stream/tvi_v4l2.c	Thu Mar 01 18:38:00 2007 +0000
@@ -46,8 +46,11 @@
 #include "tv.h"
 #include "audio_in.h"
 
+#define info tvi_info_v4l2
+static tvi_handle_t *tvi_init_v4l2(char *video_dev, char *audio_dev);
 /* information about this file */
-static tvi_info_t info = {
+tvi_info_t tvi_info_v4l2 = {
+    tvi_init_v4l2,
     "Video 4 Linux 2 input",
     "v4l2",
     "Martin Olschewski <olschewski@zpr.uni-koeln.de>",
@@ -814,7 +817,7 @@
 #define PRIV ((priv_t *) (tvi_handle->priv))
 
 /* handler creator - entry point ! */
-tvi_handle_t *tvi_init_v4l2(char *video_dev, char *audio_dev)
+static tvi_handle_t *tvi_init_v4l2(char *video_dev, char *audio_dev)
 {
     tvi_handle_t *tvi_handle;