[mythtv] [PATCH] MythVideo & Mediamonitoring (suite)
Xavier Hervy
maxpower44 at tiscali.fr
Wed Jun 16 10:43:00 EDT 2004
I have add patch from Leo that allow mediamonitoring to detect DVD which
have /video_ts path instead of /VIDEO_TS.
I will try again, without trouble. i'm waiting for the feedback of your
test.
I hope to have more feedbacks to know for who it's work and for who it
don't work.
Xavier
-------------- next part --------------
? mythtv/log
Index: mythtv/libs/libmyth/mythcdrom-linux.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcdrom-linux.cpp,v
retrieving revision 1.2
diff -u -r1.2 mythcdrom-linux.cpp
--- mythtv/libs/libmyth/mythcdrom-linux.cpp 12 Jun 2004 21:02:17 -0000 1.2
+++ mythtv/libs/libmyth/mythcdrom-linux.cpp 16 Jun 2004 14:21:26 -0000
@@ -3,7 +3,8 @@
#include <linux/cdrom.h> // old ioctls for cdrom
#include <errno.h>
#include "mythcontext.h"
-
+#include <linux/iso_fs.h>
+#include <unistd.h>
#define ASSUME_WANT_AUDIO 1
MediaError MythCDROMLinux::eject()
@@ -67,7 +68,7 @@
//cout << "MythCDROMLinux::checkMedia - ";
//cout << "Test Media result != MEDIAERR_OK" << endl;
m_MediaType = MEDIATYPE_UNKNOWN;
- return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+ return setStatus(MEDIASTAT_UNKNOWN);
}
//cout << "MythCDROMLinux::checkMedia - ";
@@ -85,31 +86,31 @@
//cout << "disk ok - ";
if (isMounted(true))
//cout << "it's mounted" << endl;
- return setStatus(MEDIASTAT_MOUNTED, OpenedHere);
+ return setStatus(MEDIASTAT_MOUNTED);
// If the disk is ok but not yet mounted we'll test it further down after this switch exits.
break;
case CDS_TRAY_OPEN:
case CDS_NO_DISC:
//cout << "Tray open or no disc" << endl;
m_MediaType = MEDIATYPE_UNKNOWN;
- return setStatus(MEDIASTAT_OPEN, OpenedHere);
+ return setStatus(MEDIASTAT_OPEN);
break;
case CDS_NO_INFO:
case CDS_DRIVE_NOT_READY:
//cout << "No info or drive not ready" << endl;
m_MediaType = MEDIATYPE_UNKNOWN;
- return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+ return setStatus(MEDIASTAT_UNKNOWN);
default:
//cout << "unknown result from ioctl (" << ret << ")" << endl;
m_MediaType = MEDIATYPE_UNKNOWN;
- return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+ return setStatus(MEDIASTAT_UNKNOWN);
}
if (mediaChanged())
{
//cout << "media changed - ";
// Regardless of the actual status lie here and say it's open for now, so we can over the case of a missed open.
- return setStatus(MEDIASTAT_OPEN, OpenedHere);
+ return setStatus(MEDIASTAT_OPEN);
}
else
{
@@ -127,12 +128,23 @@
//cout << "found a data disk" << endl;
// We'll return NOTMOUNTED here because we're switching media.
// The base class will try to mount the deivce causing the next pass to pick up the MOUNTED status.
- return setStatus(MEDIASTAT_NOTMOUNTED, OpenedHere);
+ //grab volumeinfo from iso9660
+ struct iso_primary_descriptor buf;
+ lseek(this->m_DeviceHandle,(off_t) 2048*16,SEEK_SET);
+ read(this->m_DeviceHandle,&buf,2048);
+ this->m_VolumeID = QString(buf.volume_id).stripWhiteSpace();
+ this->m_KeyID = QString("%1%2")
+ .arg(this->m_VolumeID)
+ .arg(QString(buf.creation_date).left(16));
+ // QString date_creation = QString(buf.creation_date).left(16);
+ cout << "VolumeID " << this->m_VolumeID << endl;
+ cout << "KeyID "<<this->m_KeyID << endl;
+ return setStatus(MEDIASTAT_NOTMOUNTED);
break;
case CDS_AUDIO:
//cout << "found an audio disk" << endl;
m_MediaType = MEDIATYPE_AUDIO;
- return setStatus(MEDIASTAT_USEABLE, OpenedHere);
+ return setStatus(MEDIASTAT_USEABLE);
break;
case CDS_MIXED:
m_MediaType = MEDIATYPE_MIXED;
@@ -140,30 +152,30 @@
// Note: Mixed mode CDs require an explixit mount call since we'll usually want the audio portion.
// undefine ASSUME_WANT_AUDIO to change this behavior.
#ifdef ASSUME_WANT_AUDIO
- return setStatus(MEDIASTAT_USEABLE, OpenedHere);
+ return setStatus(MEDIASTAT_USEABLE);
#else
mount();
- return setStatus(MEDIASTAT_NOTMOUNTED, OpenedHere);
+ return setStatus(MEDIASTAT_NOTMOUNTED);
#endif
break;
case CDS_NO_INFO:
case CDS_NO_DISC:
//cout << "found no disk" << endl;
m_MediaType = MEDIATYPE_UNKNOWN;
- return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+ return setStatus(MEDIASTAT_UNKNOWN);
break;
default:
//cout << "found unknown disk type" << endl;
fprintf(stderr, "Unknown data type: %d\n", type);
m_MediaType = MEDIATYPE_UNKNOWN;
- return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+ return setStatus(MEDIASTAT_UNKNOWN);
}
}
else if (m_Status == MEDIASTAT_MOUNTED ||
m_Status == MEDIASTAT_NOTMOUNTED)
{
//cout << "current status == " << MythMediaDevice::MediaStatusStrings[m_Status] << " setting status to not mounted - ";
- setStatus(MEDIASTAT_NOTMOUNTED, OpenedHere);
+ setStatus(MEDIASTAT_NOTMOUNTED);
}
if (m_AllowEject)
@@ -174,12 +186,9 @@
{
//cout << "device not open returning unknown" << endl;
m_MediaType = MEDIATYPE_UNKNOWN;
- return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+ return setStatus(MEDIASTAT_UNKNOWN);
}
- if (OpenedHere)
- closeDevice();
-
//cout << "returning " << MythMediaDevice::MediaStatusStrings[m_Status] << endl;
return m_Status;
}
Index: mythtv/libs/libmyth/mythcdrom.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcdrom.cpp,v
retrieving revision 1.7
diff -u -r1.7 mythcdrom.cpp
--- mythtv/libs/libmyth/mythcdrom.cpp 4 Jun 2004 02:31:22 -0000 1.7
+++ mythtv/libs/libmyth/mythcdrom.cpp 16 Jun 2004 14:21:26 -0000
@@ -14,8 +14,9 @@
// end for testing
#ifndef PATHTO_DVD_DETECT
-#define PATHTO_DVD_DETECT "/VIDEO_TS"
+#define PATHTO_DVD_DETECT "/VIDEO_TS" , "/video_ts"
#endif
+static char * Dvd_detect_strings[] = {PATHTO_DVD_DETECT};
#ifndef PATHTO_VCD_DETECT
#define PATHTO_VCD_DETECT "/vcd"
@@ -55,17 +56,22 @@
void MythCDROM::onDeviceMounted()
{
QString DetectPath;
- DetectPath.sprintf("%s%s", (const char*)m_MountPath, PATHTO_DVD_DETECT);
- VERBOSE(VB_ALL, QString("Looking for: '%1'").arg(DetectPath));
struct stat sbuf;
- if (stat(DetectPath, &sbuf) == 0)
+ for (unsigned i = 0; i < sizeof(Dvd_detect_strings)/sizeof(char*);i++)
{
- VERBOSE(VB_GENERAL, "Probable DVD detected.");
- m_MediaType = MEDIATYPE_DVD;
- // HACK make it possible to eject a DVD by unmounting it
- performMountCmd(false);
- m_Status = MEDIASTAT_USEABLE;
+ DetectPath.sprintf("%s%s", (const char*)m_MountPath,
+ Dvd_detect_strings[i]);
+ VERBOSE(VB_ALL, QString("Looking for: '%1'").arg(DetectPath));
+ if (stat(DetectPath, &sbuf) == 0)
+ {
+ VERBOSE(VB_GENERAL, "Probable DVD detected.");
+ m_MediaType = MEDIATYPE_DVD;
+ // HACK make it possible to eject a DVD by unmounting it
+ performMountCmd(false);
+ m_Status = MEDIASTAT_USEABLE;
+ break;
+ }
}
DetectPath.sprintf("%s%s", (const char*)m_MountPath, PATHTO_VCD_DETECT);
Index: mythtv/libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.121
diff -u -r1.121 mythcontext.cpp
--- mythtv/libs/libmyth/mythcontext.cpp 25 Apr 2004 14:59:40 -0000 1.121
+++ mythtv/libs/libmyth/mythcontext.cpp 16 Jun 2004 14:21:27 -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: mythtv/libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.h,v
retrieving revision 1.149
diff -u -r1.149 mythcontext.h
--- mythtv/libs/libmyth/mythcontext.h 4 Jun 2004 05:37:55 -0000 1.149
+++ mythtv/libs/libmyth/mythcontext.h 16 Jun 2004 14:21:27 -0000
@@ -15,6 +15,10 @@
#include <iostream>
#include <vector>
+
+#include <mythmediamonitor.h>
+#include <mythmedia.h>
+
using namespace std;
#if (QT_VERSION < 0x030100)
@@ -160,6 +164,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: mythtv/libs/libmyth/mythdialogs.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.cpp,v
retrieving revision 1.74
diff -u -r1.74 mythdialogs.cpp
--- mythtv/libs/libmyth/mythdialogs.cpp 5 Jun 2004 04:01:42 -0000 1.74
+++ mythtv/libs/libmyth/mythdialogs.cpp 16 Jun 2004 14:21:28 -0000
@@ -76,7 +76,7 @@
struct MHData
{
- void (*callback)(void);
+ void (*callback)(MythMediaDevice * mediadevice);
int MediaType;
QString destination;
QString description;
@@ -110,6 +110,10 @@
void (*exitmenucallback)(void);
+ void (*exitmenumediadevicecallback)(MythMediaDevice *);
+ MythMediaDevice * mediadeviceforcallback;
+
+
int escapekey;
};
@@ -147,6 +151,8 @@
d->ignore_lirc_keys = false;
d->exitingtomain = false;
d->exitmenucallback = false;
+ d->exitmenumediadevicecallback = false;
+ d->mediadeviceforcallback = NULL;
d->escapekey = Key_Escape;
#ifdef USE_LIRC
@@ -305,6 +311,14 @@
d->exitmenucallback = NULL;
callback();
+ }else if(d->exitmenumediadevicecallback && d->mediadeviceforcallback)
+ {
+ void (*callback)(MythMediaDevice *)= d->exitmenumediadevicecallback;
+ d->exitmenumediadevicecallback = NULL;
+ MythMediaDevice * mediadevice = d->mediadeviceforcallback;
+ d->mediadeviceforcallback = NULL;
+
+ callback(mediadevice);
}
}
}
@@ -499,7 +513,7 @@
void MythMainWindow::RegisterMediaHandler(const QString &destination,
const QString &description,
const QString &key,
- void (*callback)(void),
+ void (*callback)(MythMediaDevice * mediadevice),
int mediaType)
{
(void)key;
@@ -597,7 +611,8 @@
{
cout << "Found a handler" << endl;
d->exitingtomain = true;
- d->exitmenucallback = itr.data().callback;
+ d->exitmenumediadevicecallback = itr.data().callback;
+ d->mediadeviceforcallback= pDev;
QApplication::postEvent(this, new ExitToMainMenuEvent());
break;
}
Index: mythtv/libs/libmyth/mythdialogs.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.h,v
retrieving revision 1.37
diff -u -r1.37 mythdialogs.h
--- mythtv/libs/libmyth/mythdialogs.h 25 May 2004 05:08:53 -0000 1.37
+++ mythtv/libs/libmyth/mythdialogs.h 16 Jun 2004 14:21:28 -0000
@@ -91,7 +91,7 @@
const QString &key, void (*callback)(void));
void RegisterMediaHandler(const QString &destination,
const QString &description, const QString &key,
- void (*callback)(void), int mediaType);
+ void (*callback)(MythMediaDevice * mediadevice), int mediaType);
void RegisterMediaPlugin(const QString &name, const QString &desc,
MediaPlayCallback fn);
Index: mythtv/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
--- mythtv/libs/libmyth/mythmedia.cpp 12 Jun 2004 21:02:17 -0000 1.6
+++ mythtv/libs/libmyth/mythmedia.cpp 16 Jun 2004 14:21:29 -0000
@@ -69,9 +69,6 @@
{
QString MountCommand;
- if (isDeviceOpen())
- closeDevice();
-
if (!m_SuperMount)
{
// Build a command line for mount/unmount and execute it... Is there a better way to do this?
@@ -79,8 +76,11 @@
MountCommand.sprintf("%s %s", PATHTO_MOUNT,
(const char*)m_DevicePath);
else
+ {
MountCommand.sprintf("%s %s", PATHTO_UNMOUNT,
(const char*)m_DevicePath);
+ closeDevice();
+ }
VERBOSE(VB_ALL, QString("Executing '%1'").arg(MountCommand));
if (0 == system(MountCommand))
@@ -91,13 +91,16 @@
onDeviceMounted();
}
else
- onDeviceUnmounted();
+ {
+ m_Status = MEDIASTAT_NOTMOUNTED;
+ onDeviceUnmounted();
+ }
return true;
}
else
{
- VERBOSE(VB_GENERAL, QString("Failed to mount %1.")
- .arg(m_DevicePath));
+ VERBOSE(VB_GENERAL, QString("Failed to %1.")
+ .arg(MountCommand));
}
}
else
@@ -179,7 +182,7 @@
return false;
}
-MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus, bool CloseIt )
+MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus)
{
MediaStatus OldStatus = m_Status;
@@ -203,8 +206,11 @@
// as MEDIASTAT_OPEN, MEDISTAT_ERROR or MEDIASTAT_UNKNOWN.
mount();
break;
- case MEDIASTAT_UNKNOWN:
+ case MEDIASTAT_UNKNOWN:break;
case MEDIASTAT_OPEN:
+ if (MEDIASTAT_MOUNTED == OldStatus)
+ unmount();
+ break;
case MEDIASTAT_USEABLE:
case MEDIASTAT_MOUNTED:
// get rid of the compiler warning...
@@ -217,9 +223,6 @@
}
- if (CloseIt)
- closeDevice();
-
return m_Status;
}
Index: mythtv/libs/libmyth/mythmedia.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmedia.h,v
retrieving revision 1.3
diff -u -r1.3 mythmedia.h
--- mythtv/libs/libmyth/mythmedia.h 24 Feb 2004 07:31:08 -0000 1.3
+++ mythtv/libs/libmyth/mythmedia.h 16 Jun 2004 14:21:29 -0000
@@ -45,6 +45,7 @@
MediaStatus getStatus() const { return m_Status; }
const QString& getVolumeID() const { return m_VolumeID; }
+ const QString& getKeyID() const { return m_KeyID; }
bool getAllowEject() const { return m_AllowEject; }
void setAllowEject(bool allowEject) { m_AllowEject = allowEject; }
@@ -85,12 +86,14 @@
virtual void onDeviceMounted() {};
virtual void onDeviceUnmounted() {};
- MediaStatus setStatus(MediaStatus newStat, bool CloseIt=false);
+ MediaStatus setStatus(MediaStatus newStat);
QString m_MountPath; ///< The path to this media's mount point (i.e. /mnt/cdrom). Read only.
QString m_DevicePath; ///< The path to this media's device (i.e. /dev/cdrom). Read/write.
MediaStatus m_Status; ///< The status of the media as of the last call to checkMedia. Read only.
QString m_VolumeID; ///< The volume ID of the media. Read Only.
+ QString m_KeyID; ///< The Key ID of the media. Read Only.
+ // For iso 9660 VolumeID + creation date
bool m_Locked; ///< Is this media locked? Read only.
bool m_AllowEject; ///< Allow the user to eject the media? Read/write.
int m_DeviceHandle; ///< A file handle for opening and closing the device.
Index: mythtv/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
--- mythtv/libs/libmyth/mythmediamonitor.cpp 12 Jun 2004 21:02:17 -0000 1.7
+++ mythtv/libs/libmyth/mythmediamonitor.cpp 16 Jun 2004 14:21:29 -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: mythtv/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
--- mythtv/libs/libmyth/mythmediamonitor.h 12 Jun 2004 21:02:17 -0000 1.3
+++ mythtv/libs/libmyth/mythmediamonitor.h 16 Jun 2004 14:21:29 -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: mythtv/programs/mythfrontend/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/main.cpp,v
retrieving revision 1.145
diff -u -r1.145 main.cpp
--- mythtv/programs/mythfrontend/main.cpp 29 May 2004 18:30:46 -0000 1.145
+++ mythtv/programs/mythfrontend/main.cpp 16 Jun 2004 14:21:29 -0000
@@ -995,6 +995,7 @@
mon->addFSTab();
VERBOSE(VB_ALL, QString("Starting media monitor."));
mon->startMonitoring();
+ gContext->SetMediaMonitor(mon);
}
#endif
More information about the mythtv-dev
mailing list