diff options
Diffstat (limited to 'stream/stream_dvd_common.c')
-rw-r--r-- | stream/stream_dvd_common.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/stream/stream_dvd_common.c b/stream/stream_dvd_common.c index 9302b5670b..d5c4cc14a6 100644 --- a/stream/stream_dvd_common.c +++ b/stream/stream_dvd_common.c @@ -1,7 +1,103 @@ #include "config.h" +#include <fcntl.h> #include <inttypes.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> #include <dvdread/ifo_types.h> +#ifdef __FreeBSD__ +#include <sys/cdrio.h> +#endif + +#ifdef __linux__ +#include <linux/cdrom.h> +#include <scsi/sg.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#endif + +#include "mp_msg.h" +#include "help_mp.h" #include "stream_dvd_common.h" +#include "ffmpeg_files/intreadwrite.h" + +const char * const dvd_audio_stream_types[8] = { "ac3","unknown","mpeg1","mpeg2ext","lpcm","unknown","dts" }; +const char * const dvd_audio_stream_channels[6] = { "mono", "stereo", "unknown", "unknown", "5.1/6.1", "5.1" }; + +int dvd_speed=0; /* 0 => don't touch speed */ + +void dvd_set_speed(char *device, unsigned speed) +{ +#if defined(__linux__) && defined(SG_IO) && defined(GPCMD_SET_STREAMING) + int fd; + unsigned char buffer[28]; + unsigned char cmd[12]; + struct sg_io_hdr sghdr; + struct stat st; + + memset(&st, 0, sizeof(st)); + + if (stat(device, &st) == -1) return; + + if (!S_ISBLK(st.st_mode)) return; /* not a block device */ + + switch (speed) { + case 0: /* don't touch speed setting */ + return; + case -1: /* restore default value */ + if (dvd_speed == 0) return; /* we haven't touched the speed setting */ + mp_tmsg(MSGT_OPEN, MSGL_INFO, "Restoring DVD speed... "); + break; + default: /* limit to <speed> KB/s */ + // speed < 100 is multiple of DVD single speed (1350KB/s) + if (speed < 100) + speed *= 1350; + mp_tmsg(MSGT_OPEN, MSGL_INFO, "Limiting DVD speed to %dKB/s... ", speed); + break; + } + + memset(&sghdr, 0, sizeof(sghdr)); + sghdr.interface_id = 'S'; + sghdr.timeout = 5000; + sghdr.dxfer_direction = SG_DXFER_TO_DEV; + sghdr.dxfer_len = sizeof(buffer); + sghdr.dxferp = buffer; + sghdr.cmd_len = sizeof(cmd); + sghdr.cmdp = cmd; + + memset(cmd, 0, sizeof(cmd)); + cmd[0] = GPCMD_SET_STREAMING; + cmd[10] = sizeof(buffer); + + memset(buffer, 0, sizeof(buffer)); + /* first sector 0, last sector 0xffffffff */ + AV_WB32(buffer + 8, 0xffffffff); + if (speed == -1) + buffer[0] = 4; /* restore default */ + else { + /* <speed> kilobyte */ + AV_WB32(buffer + 12, speed); + AV_WB32(buffer + 20, speed); + } + /* 1 second */ + AV_WB16(buffer + 18, 1000); + AV_WB16(buffer + 26, 1000); + + fd = open(device, O_RDWR | O_NONBLOCK); + if (fd == -1) { + mp_tmsg(MSGT_OPEN, MSGL_INFO, "Couldn't open DVD device for writing, changing DVD speed needs write access.\n"); + return; + } + + if (ioctl(fd, SG_IO, &sghdr) < 0) + mp_tmsg(MSGT_OPEN, MSGL_INFO, "failed\n"); + else + mp_tmsg(MSGT_OPEN, MSGL_INFO, "successful\n"); + + close(fd); +#endif +} /** \brief Converts DVD time structure to milliseconds. |