[mythtv] [PATCH] MediaMonitor data and MythVideo support

Matt Porter mporter at kernel.crashing.org
Mon Jun 28 19:42:38 EDT 2004


Hi,

I went through Xavier's patches and removed all the things that
weren't being utilized and extra commented code. I'm left with
two patches that are working well on my systems.

The first patch detects any mounted "cdrom" media as MEDIATYPE_DATA
if it doesn't match with the dvd/vcd/svcd path probing.  In the
future, I plan to make this better by parsing videotypes to detect
a MEDIATYPE_VIDEODATA media. Likewise, MEDIATYPE_AUDIODATA can be
detected for mythmusic handling. In addition, it adds a hook to
MythContext so the plugin can get information on which media
monitor devices have matching MEDIATYPE info. Also, I removed
O_EXCL so a mounted device can be opened for ioctls to work
and made sure a mounted device was unmounted when MEDIASTATUS_OPEN
occurs.

The second patch just cleans up the basic videotree media handling
code, and is functionally equivalent to Xavier's original.

I've been giving this a workout on my systems with vcd/svcd, cdda, and
iso9660 (.avi,.mpg) media.  It's working real well. This should provide
a good base for more intricate mythvideo media support that has been
mentioned a few times, though it's useful as is.

Comments?

-Matt

-------------- next part --------------
Index: libs/libmyth/mythcdrom.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcdrom.cpp,v
retrieving revision 1.8
diff -u -r1.8 mythcdrom.cpp
--- libs/libmyth/mythcdrom.cpp	28 Jun 2004 20:25:02 -0000	1.8
+++ libs/libmyth/mythcdrom.cpp	28 Jun 2004 23:26:35 -0000
@@ -59,6 +59,18 @@
 void MythCDROM::onDeviceMounted()
 {
     QString DetectPath, DetectPath2;
+
+    // We should do some fine-grained checking using
+    // extensions or true filetype verification to determine
+    // what kind of data this is.  It could be audio or
+    // video data on an iso9660 fs, for example.
+    //
+    // Default is data media
+    m_MediaType = MEDIATYPE_DATA;
+
+    // Default is mounted media
+    m_Status = MEDIASTAT_MOUNTED;
+
     DetectPath.sprintf("%s%s", (const char*)m_MountPath, PATHTO_DVD_DETECT);
     VERBOSE(VB_ALL, QString("Looking for: '%1'").arg(DetectPath));
 
Index: libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.122
diff -u -r1.122 mythcontext.cpp
--- libs/libmyth/mythcontext.cpp	21 Jun 2004 20:30:58 -0000	1.122
+++ libs/libmyth/mythcontext.cpp	28 Jun 2004 23:26:43 -0000
@@ -91,6 +91,8 @@
     int m_logenable, m_logmaxcount, m_logprintlevel;
     QMap<QString,int> lastLogCounts;
     QMap<QString,QString> lastLogStrings;
+
+    MediaMonitor * media_monitor;
 };
 
 MythContextPrivate::MythContextPrivate(MythContext *lparent)
@@ -114,6 +116,8 @@
 
     m_db = QSqlDatabase::addDatabase("QMYSQL3", "MythContext");
     screensaver = new ScreenSaverControl();
+
+    media_monitor = NULL;
 }
 
 void MythContextPrivate::Init(bool gui, bool lcd)
@@ -1226,6 +1230,19 @@
     d->m_settings->SetSetting(key, newValue);
 }
 
+void MythContext::SetMediaMonitor(MediaMonitor * lmediamonitor)
+{
+    d->media_monitor = lmediamonitor;
+}
+
+QValueList <MythMediaDevice*> MythContext::GetMedias(MediaType mediatype)
+{
+    QValueList <MythMediaDevice*> medias;
+    if (d->media_monitor != NULL)
+        medias = d->media_monitor->getMedias(mediatype);
+    return medias;
+}
+
 bool MythContext::SendReceiveStringList(QStringList &strlist, bool quickTimeout)
 {
     d->serverSockLock.lock();
Index: libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.h,v
retrieving revision 1.150
diff -u -r1.150 mythcontext.h
--- libs/libmyth/mythcontext.h	24 Jun 2004 09:51:04 -0000	1.150
+++ libs/libmyth/mythcontext.h	28 Jun 2004 23:26:45 -0000
@@ -15,6 +15,10 @@
 
 #include <iostream>
 #include <vector>
+
+#include <mythtv/mythmediamonitor.h>
+#include <mythtv/mythmedia.h>
+
 using namespace std;
 
 #if (QT_VERSION < 0x030100)
@@ -161,6 +165,9 @@
 
     void SetSetting(const QString &key, const QString &newValue);
 
+    void SetMediaMonitor(MediaMonitor * lmediamonitor);
+    QValueList <MythMediaDevice*> GetMedias(MediaType mediatype);
+
     QFont GetBigFont();
     QFont GetMediumFont();
     QFont GetSmallFont();
Index: libs/libmyth/mythmedia.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmedia.cpp,v
retrieving revision 1.6
diff -u -r1.6 mythmedia.cpp
--- libs/libmyth/mythmedia.cpp	12 Jun 2004 21:02:17 -0000	1.6
+++ libs/libmyth/mythmedia.cpp	28 Jun 2004 23:26:47 -0000
@@ -43,7 +43,7 @@
     if (isDeviceOpen())
         return true;
  
-    m_DeviceHandle = open(m_DevicePath, O_RDONLY | O_NONBLOCK | O_EXCL);
+    m_DeviceHandle = open(m_DevicePath, O_RDONLY | O_NONBLOCK);
     
     return isDeviceOpen();
 }
@@ -192,6 +192,7 @@
         {
             // the disk is not / should not be mounted.
             case MEDIASTAT_ERROR:
+            case MEDIASTAT_OPEN:
                 if (MEDIASTAT_MOUNTED == OldStatus)
                     unmount();
                 break;
@@ -204,7 +205,6 @@
                 mount();
                 break;
             case MEDIASTAT_UNKNOWN:
-            case MEDIASTAT_OPEN:
             case MEDIASTAT_USEABLE:
             case MEDIASTAT_MOUNTED:
                 // get rid of the compiler warning...
Index: libs/libmyth/mythmediamonitor.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmediamonitor.cpp,v
retrieving revision 1.7
diff -u -r1.7 mythmediamonitor.cpp
--- libs/libmyth/mythmediamonitor.cpp	12 Jun 2004 21:02:17 -0000	1.7
+++ libs/libmyth/mythmediamonitor.cpp	28 Jun 2004 23:26:49 -0000
@@ -286,6 +286,23 @@
     m_Thread.wait();
 }
 
+// Ask for available media
+QValueList <MythMediaDevice*> MediaMonitor::getMedias(MediaType mediatype)
+{
+    QValueList <MythMediaDevice*> medias;
+    QValueList <MythMediaDevice*>::Iterator itr = m_Devices.begin();
+    MythMediaDevice* pDev;
+    while (itr!=m_Devices.end())
+    {
+        pDev = *itr;
+        if ((pDev->getMediaType()==mediatype) &&
+            ((pDev->getStatus()==MEDIASTAT_USEABLE) ||
+            (pDev->getStatus()==MEDIASTAT_MOUNTED)))
+            medias.push_back(pDev);
+        itr++;
+    }
+    return medias;
+}
 // Signal handler.
 void MediaMonitor::mediaStatusChanged(MediaStatus oldStatus, 
                                       MythMediaDevice* pMedia)
Index: libs/libmyth/mythmediamonitor.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmediamonitor.h,v
retrieving revision 1.3
diff -u -r1.3 mythmediamonitor.h
--- libs/libmyth/mythmediamonitor.h	12 Jun 2004 21:02:17 -0000	1.3
+++ libs/libmyth/mythmediamonitor.h	28 Jun 2004 23:26:49 -0000
@@ -55,6 +55,7 @@
     void checkDevices(void);
     void startMonitoring(void);
     void stopMonitoring(void);
+    QValueList <MythMediaDevice*> getMedias(MediaType mediatype);
 
   public slots:
     void mediaStatusChanged( MediaStatus oldStatus, MythMediaDevice* pMedia);
Index: programs/mythfrontend/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/main.cpp,v
retrieving revision 1.146
diff -u -r1.146 main.cpp
--- programs/mythfrontend/main.cpp	24 Jun 2004 09:51:05 -0000	1.146
+++ programs/mythfrontend/main.cpp	28 Jun 2004 23:26:58 -0000
@@ -1000,6 +1000,7 @@
         mon->addFSTab();
         VERBOSE(VB_ALL, QString("Starting media monitor."));
         mon->startMonitoring();
+        gContext->SetMediaMonitor(mon);
     }
 #endif
 
-------------- next part --------------
Index: mythvideo/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/main.cpp,v
retrieving revision 1.31
diff -u -r1.31 main.cpp
--- mythvideo/main.cpp	12 Jun 2004 17:35:12 -0000	1.31
+++ mythvideo/main.cpp	28 Jun 2004 23:26:04 -0000
@@ -29,6 +29,7 @@
 #include <mythtv/themedmenu.h>
 #include <mythtv/mythcontext.h>
 #include <mythtv/mythplugin.h>
+#include <mythtv/mythmedia.h>
 
 enum VideoFileLocation
 {
@@ -54,6 +55,10 @@
 void runVideoBrowser(void);
 void runVideoTree(void);
 void runVideoGallery(void);
+void runMediaHandle(void)
+{
+     runVideoTree();
+}
 
 void setupKeys(void)
 {
@@ -74,7 +79,7 @@
     REG_KEY("Video","INCPARENT","Increase Parental Level","Right");
     REG_KEY("Video","DECPARENT","Decrease Parental Level","Left");
 
-
+    REG_MEDIA_HANDLER("MythVideo Removable Media handler","","",runMediaHandle,MEDIATYPE_DATA);
 }
 
 
Index: mythvideo/videotree.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videotree.cpp,v
retrieving revision 1.28
diff -u -r1.28 videotree.cpp
--- mythvideo/videotree.cpp	10 Apr 2004 18:52:28 -0000	1.28
+++ mythvideo/videotree.cpp	28 Jun 2004 23:26:08 -0000
@@ -12,6 +12,7 @@
 #include <mythtv/mythwidgets.h>
 #include <mythtv/uitypes.h>
 #include <mythtv/util.h>
+#include <mythtv/mythmedia.h>
 
 VideoTree::VideoTree(MythMainWindow *parent, QSqlDatabase *ldb,
                      QString window_name, QString theme_filename,
@@ -30,7 +31,6 @@
 
     wireUpTheme();
     video_tree_root = new GenericTree("video root", -2, false);
-    video_tree_data = video_tree_root->addNode("videos", -2, false);
 
     buildVideoList();
     
@@ -38,8 +38,13 @@
     //  Tell the tree list to highlight the 
     //  first entry and then display it
     //
-    
-    video_tree_list->setCurrentNode(video_tree_data);
+    for (int i=0; i < video_tree_root->childCount();i++){
+	    video_tree_data = video_tree_root->getChildAt(i,0);
+	    if ((video_tree_data->childCount()>0) 
+		&& (video_tree_data->getChildAt(0,0)->getString() !=
+			tr("No files found"))) break;
+    }
+   video_tree_list->setCurrentNode(video_tree_data);
     if(video_tree_data->childCount() > 0)
     {
         video_tree_list->setCurrentNode(video_tree_data->getChildAt(0, 0));
@@ -262,21 +267,51 @@
         //  Fill metadata from directory structure
         //
         
-        buildFileList(gContext->GetSetting("VideoStartupDir"));
+        QStringList nodesname;
+        QStringList nodespath;
 
+        nodespath.append(gContext->GetSetting("VideoStartupDir"));
+        nodesname.append("videos");
+        QValueList<MythMediaDevice*> medias = gContext->GetMedias(MEDIATYPE_DATA);
+        QValueList<MythMediaDevice*>::Iterator itr = medias.begin();
+        MythMediaDevice * pDev;
+        while (itr != medias.end())
+        {
+           pDev = *itr;
+           if (pDev){
+                QString path = pDev->getMountPath();
+                QString name = path.right(path.length()-path.findRev("/")-1);
+		cout << "adding " << path << " as " << name << endl;
+                nodespath.append(path);
+                nodesname.append(name);
+          }
+           itr++;
+        }
+	for (uint j=0;j<nodesname.count();j++){
+		video_tree_data = video_tree_root->addNode(nodesname[j], -2, false);
+        	buildFileList(nodespath[j]);
+	}
+	uint mainnodeindex=0;
+	QString prefix = nodespath[mainnodeindex];
+        GenericTree *where_to_add = video_tree_root->getChildAt(mainnodeindex);
         for(uint i=0; i < browser_mode_files.count(); i++)
         {
             QString file_string = *(browser_mode_files.at(i));
-            QString prefix = gContext->GetSetting("VideoStartupDir");
-            if(prefix.length() < 1)
+
+            if (prefix.compare(file_string.left(prefix.length()))!=0){
+		mainnodeindex++;
+	    }
+	if (mainnodeindex < nodespath.count()){
+			prefix = nodespath[mainnodeindex];
+			where_to_add = video_tree_root->getChildAt(mainnodeindex	);
+	}
+    if(prefix.length() < 1)
             {
                 cerr << "videotree.o: Seems unlikely that this is going to work" << endl;
             }
             file_string.remove(0, prefix.length());
             QStringList list(QStringList::split("/", file_string));
 
-            GenericTree *where_to_add;
-            where_to_add = video_tree_data;
             int a_counter = 0;
             QStringList::Iterator an_it = list.begin();
             for( ; an_it != list.end(); ++an_it)
@@ -319,6 +354,8 @@
         //  widget that handles navigation
         //
 
+ 	video_tree_data = video_tree_root->addNode("videos", -2, false);
+
         QSqlQuery query("SELECT intid FROM videometadata ;", db);
         Metadata *myData;
     


More information about the mythtv-dev mailing list