[MPlayer-dev-eng] [Patch 1/2] dvd_set_speed fixes/addons
Sebastian Kemper
sebastian_ml at gmx.net
Fri Nov 16 21:30:58 CET 2007
Hello all,
attached patch fixes some glitches in dvd_set_speed() (stream_dvd.c).
- unsigned speed to int speed (because restoring the initial speed means
to set speed=-1)
- use the correct ATAPI command length for SET STREAMING (12 bytes); at
least libata (for now anyways) won't let commands through when the
command length is wrong ("old" ATA is more forgiving and cuts the last
4 bytes)
- add a check to make sure the device really is an SG device (taken from
sg_simple2.c)
I'm not sure you guys like the printf() but I don't really want to
dive into mplayer's message system
- add close(fd)'s where feasible
- add a missing return
Regards
Sebastian
-------------- next part --------------
diff -Nur mplayer/stream/stream_dvd.c mplayer.new/stream/stream_dvd.c
--- mplayer/stream/stream_dvd.c 2007-11-16 20:38:26.000000000 +0100
+++ mplayer.new/stream/stream_dvd.c 2007-11-16 21:14:10.000000000 +0100
@@ -42,12 +42,12 @@
int dvd_angle=1;
int dvd_speed=0; /* 0 => don't touch speed */
-static void dvd_set_speed(char *device, unsigned speed)
+static void dvd_set_speed(char *device, int speed)
{
#if defined(__linux__) && defined(SG_IO) && defined(GPCMD_SET_STREAMING)
- int fd;
+ int fd, k;
unsigned char buffer[28];
- unsigned char cmd[16];
+ unsigned char cmd[12];
unsigned char sense[16];
struct sg_io_hdr sghdr;
struct stat st;
@@ -67,15 +67,26 @@
return;
}
- if (speed < 100) { /* speed times 1350KB/s (DVD single speed) */
+ /* Is this really an sg device? */
+ if ((ioctl(fd, SG_GET_VERSION_NUM, &k) < 0) || (k < 30000)) {
+ printf("%s is not an sg device, or old sg driver\n", device);
+ close(fd);
+ return;
+ }
+
+ if (speed < 100 && speed > 0) { /* speed times 1350KB/s (DVD single speed) */
speed *= 1350;
}
switch (speed) {
case 0: /* don't touch speed setting */
+ close(fd);
return;
case -1: /* restore default value */
- if (dvd_speed == 0) return; /* we haven't touched the speed setting */
+ if (dvd_speed == 0) {
+ close(fd);
+ return; /* we haven't touched the speed setting */
+ }
speed = 0;
buffer[0] = 4; /* restore default */
mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_DVDrestoreSpeed);
@@ -113,8 +124,11 @@
if (ioctl(fd, SG_IO, &sghdr) < 0) {
mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_DVDlimitFail);
+ close(fd);
+ return;
}
mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_DVDlimitOk);
+ close(fd);
#endif
}
More information about the MPlayer-dev-eng
mailing list