changeset 24403:d31512f03462

Implementation of tv:// driver autodetection. If user did not specify driver directly, all available drivers will be probed (in order: v4l2,v4l1,bsdbt848,dummy). In most cases first probed driver will be successfully autodetected and used. Autodetection will be disabled if user specified driver directly (in command line or config).
author voroshil
date Mon, 10 Sep 2007 17:09:35 +0000
parents 93b87066f9da
children 67e6bb7dcac4
files DOCS/man/en/mplayer.1 help/help_mp-en.h stream/stream_tv.c stream/tv.c
diffstat 4 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1	Mon Sep 10 16:17:13 2007 +0000
+++ b/DOCS/man/en/mplayer.1	Mon Sep 10 17:09:35 2007 +0000
@@ -1759,7 +1759,7 @@
 Default is 0 (automute disabled).
 .IPs driver=<value>
 See \-tv driver=help for a list of compiled-in TV input drivers.
-available: dummy, v4l, v4l2, bsdbt848
+available: dummy, v4l, v4l2, bsdbt848 (default: autodetect)
 .IPs device=<value>
 Specify TV device (default: /dev/\:video0).
 .I NOTE:
--- a/help/help_mp-en.h	Mon Sep 10 16:17:13 2007 +0000
+++ b/help/help_mp-en.h	Mon Sep 10 17:09:35 2007 +0000
@@ -2081,6 +2081,7 @@
 #define MSGTR_TV_AvailableDrivers "Available drivers:\n"
 #define MSGTR_TV_DriverInfo "Selected driver: %s\n name: %s\n author: %s\n comment: %s\n"
 #define MSGTR_TV_NoSuchDriver "No such driver: %s\n"
+#define MSGTR_TV_DriverAutoDetectionFailed "TV driver autodetection failed.\n"
 #define MSGTR_TV_UnknownColorOption "Unknown color option (%d) specified!\n"
 #define MSGTR_TV_CurrentFrequency "Current frequency: %lu (%.3f)\n"
 #define MSGTR_TV_NoTeletext "No teletext"
--- a/stream/stream_tv.c	Mon Sep 10 16:17:13 2007 +0000
+++ b/stream/stream_tv.c	Mon Sep 10 17:09:35 2007 +0000
@@ -40,7 +40,7 @@
     -1,            //normid
 #endif
     NULL,          //device
-    "dummy",       //driver
+    NULL,          //driver
     -1,            //width
     -1,            //height
     0,             //input, used in v4l and bttv
--- a/stream/tv.c	Mon Sep 10 16:17:13 2007 +0000
+++ b/stream/tv.c	Mon Sep 10 17:09:35 2007 +0000
@@ -52,17 +52,18 @@
 extern tvi_info_t tvi_info_bsdbt848;
 #endif
 
+/** List of drivers in autodetection order */
 static const tvi_info_t* tvi_driver_list[]={
-    &tvi_info_dummy,
+#ifdef HAVE_TV_V4L2
+    &tvi_info_v4l2,
+#endif
 #ifdef HAVE_TV_V4L1
     &tvi_info_v4l,
 #endif
-#ifdef HAVE_TV_V4L2
-    &tvi_info_v4l2,
-#endif
 #ifdef HAVE_TV_BSDBT848
     &tvi_info_bsdbt848,
 #endif
+    &tvi_info_dummy,
     NULL
 };
 
@@ -560,7 +561,7 @@
 {
     int i;
     tvi_handle_t* h;
-    if(!strcmp(tv_param->driver,"help")){
+    if(tv_param->driver && !strcmp(tv_param->driver,"help")){
         mp_msg(MSGT_TV,MSGL_INFO,MSGTR_TV_AvailableDrivers);
         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);
@@ -572,20 +573,29 @@
     }
 
     for(i=0;tvi_driver_list[i];i++){
-        if (!strcmp(tvi_driver_list[i]->short_name, tv_param->driver)){
+        if (!tv_param->driver || !strcmp(tvi_driver_list[i]->short_name, tv_param->driver)){
             h=tvi_driver_list[i]->tvi_init(tv_param);
-            if(!h) return NULL;
+            //Requested driver initialization failed
+            if (!h && tv_param->driver)
+                return NULL;
+            //Driver initialization failed during autodetection process.
+            if (!h)
+                continue;
 
             h->tv_param=tv_param;
             mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_DriverInfo, tvi_driver_list[i]->short_name,
             tvi_driver_list[i]->name,
             tvi_driver_list[i]->author,
             tvi_driver_list[i]->comment?tvi_driver_list[i]->comment:"");
+            tv_param->driver=strdup(tvi_driver_list[i]->short_name);
             return h;
         }
     }
     
-    mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_NoSuchDriver, tv_param->driver); 
+    if(tv_param->driver)
+        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_NoSuchDriver, tv_param->driver); 
+    else
+        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_DriverAutoDetectionFailed);
     return(NULL);
 }