[mythtv] [PATCH] MythVideo & Mediamonitoring (suite)
Xavier Hervy
maxpower44 at tiscali.fr
Mon Jun 7 13:04:45 EDT 2004
Ok i have made a patch that fix bug with mediamonitoring and mountable
device.
What change:
- device will never be close otherwise we can't open it again for
checking the status of mounted device.
- mounted device will be close just before unmount otherwise we can
unmount it.
I try this with DVDVIDEO and DATA CD (with my other patch for using cd
in mythvideo) but it should be work to for other kind of media.
Donavan can you tell me what do you think about these changes ?
I probably make other change in mediamonitor to send informations
through event media
Xavier
-------------- next part --------------
Index: mythtv/libs/libmyth/mythcdrom.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcdrom.cpp,v
retrieving revision 1.5
diff -u -r1.5 mythcdrom.cpp
--- mythtv/libs/libmyth/mythcdrom.cpp 24 Feb 2004 07:31:08 -0000 1.5
+++ mythtv/libs/libmyth/mythcdrom.cpp 7 Jun 2004 16:54:17 -0000
@@ -100,13 +100,13 @@
MediaStatus MythCDROM::checkMedia()
{
bool OpenedHere = false;
-
+
if (testMedia() != MEDIAERR_OK)
{
//cout << "MythCDROM::checkMedia - ";
//cout << "Test Media result != MEDIAERR_OK" << endl;
m_MediaType = MEDIATYPE_UNKNOWN;
- return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+ return setStatus(MEDIASTAT_UNKNOWN);
}
//cout << "MythCDROM::checkMedia - ";
@@ -122,33 +122,34 @@
{
case CDS_DISC_OK:
//cout << "disk ok - ";
- if (isMounted(true))
+ 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
{
@@ -166,12 +167,12 @@
//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);
+ 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;
@@ -179,30 +180,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)
@@ -213,12 +214,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/mythmedia.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmedia.cpp,v
retrieving revision 1.5
diff -u -r1.5 mythmedia.cpp
--- mythtv/libs/libmyth/mythmedia.cpp 24 Feb 2004 07:31:08 -0000 1.5
+++ mythtv/libs/libmyth/mythmedia.cpp 7 Jun 2004 16:54:17 -0000
@@ -44,7 +44,7 @@
return true;
m_DeviceHandle = open(m_DevicePath, O_RDONLY | O_NONBLOCK | O_EXCL);
-
+
return isDeviceOpen();
}
@@ -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,20 @@
onDeviceMounted();
}
else
+ {
+ m_Status = MEDIASTAT_NOTMOUNTED;
onDeviceUnmounted();
+ }
return true;
}
else
{
- VERBOSE(VB_GENERAL, QString("Failed to mount %1.")
+ if (DoMount)
+ VERBOSE(VB_GENERAL, QString("Failed to mount %1.")
.arg(m_DevicePath));
+ else
+ VERBOSE(VB_GENERAL, QString("Failed to unmount %1.")
+ .arg(m_DevicePath));
}
}
else
@@ -131,10 +138,7 @@
{
m_Locked = false;
- if (closeDevice())
- return MEDIAERR_OK;
-
- return MEDIAERR_FAILED;
+ return MEDIAERR_OK;
}
bool MythMediaDevice::isMounted(bool Verify)
@@ -182,7 +186,7 @@
return false;
}
-MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus, bool CloseIt )
+MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus )
{
MediaStatus OldStatus = m_Status;
@@ -206,9 +210,13 @@
// as MEDIASTAT_OPEN, MEDISTAT_ERROR or MEDIASTAT_UNKNOWN.
mount();
break;
- case MEDIASTAT_UNKNOWN:
+ case MEDIASTAT_UNKNOWN:break;
case MEDIASTAT_OPEN:
- case MEDIASTAT_USEABLE:
+ if (MEDIASTAT_MOUNTED == OldStatus){
+ unmount();
+ }
+ break;
+ case MEDIASTAT_USEABLE:
case MEDIASTAT_MOUNTED:
// get rid of the compiler warning...
break;
@@ -219,10 +227,6 @@
emit statusChanged(OldStatus, this);
}
-
- 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 7 Jun 2004 16:54:17 -0000
@@ -85,7 +85,7 @@
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.
More information about the mythtv-dev
mailing list