7 #include <dvdread/ifo_types.h>
13 #include <linux/cdrom.h>
15 #include <sys/types.h>
17 #include <sys/ioctl.h>
22 #include "stream_dvd_common.h"
23 #include "ffmpeg_files/intreadwrite.h"
25 const char * const dvd_audio_stream_types
[8] = { "ac3","unknown","mpeg1","mpeg2ext","lpcm","unknown","dts" };
26 const char * const dvd_audio_stream_channels
[6] = { "mono", "stereo", "unknown", "unknown", "5.1/6.1", "5.1" };
28 int dvd_speed
=0; /* 0 => don't touch speed */
30 void dvd_set_speed(char *device
, unsigned speed
)
32 #if defined(__linux__) && defined(SG_IO) && defined(GPCMD_SET_STREAMING)
34 unsigned char buffer
[28];
35 unsigned char cmd
[12];
36 struct sg_io_hdr sghdr
;
39 memset(&st
, 0, sizeof(st
));
41 if (stat(device
, &st
) == -1) return;
43 if (!S_ISBLK(st
.st_mode
)) return; /* not a block device */
46 case 0: /* don't touch speed setting */
48 case -1: /* restore default value */
49 if (dvd_speed
== 0) return; /* we haven't touched the speed setting */
50 mp_tmsg(MSGT_OPEN
, MSGL_INFO
, "Restoring DVD speed... ");
52 default: /* limit to <speed> KB/s */
53 // speed < 100 is multiple of DVD single speed (1350KB/s)
56 mp_tmsg(MSGT_OPEN
, MSGL_INFO
, "Limiting DVD speed to %dKB/s... ", speed
);
60 memset(&sghdr
, 0, sizeof(sghdr
));
61 sghdr
.interface_id
= 'S';
63 sghdr
.dxfer_direction
= SG_DXFER_TO_DEV
;
64 sghdr
.dxfer_len
= sizeof(buffer
);
65 sghdr
.dxferp
= buffer
;
66 sghdr
.cmd_len
= sizeof(cmd
);
69 memset(cmd
, 0, sizeof(cmd
));
70 cmd
[0] = GPCMD_SET_STREAMING
;
71 cmd
[10] = sizeof(buffer
);
73 memset(buffer
, 0, sizeof(buffer
));
74 /* first sector 0, last sector 0xffffffff */
75 AV_WB32(buffer
+ 8, 0xffffffff);
77 buffer
[0] = 4; /* restore default */
79 /* <speed> kilobyte */
80 AV_WB32(buffer
+ 12, speed
);
81 AV_WB32(buffer
+ 20, speed
);
84 AV_WB16(buffer
+ 18, 1000);
85 AV_WB16(buffer
+ 26, 1000);
87 fd
= open(device
, O_RDWR
| O_NONBLOCK
);
89 mp_tmsg(MSGT_OPEN
, MSGL_INFO
, "Couldn't open DVD device for writing, changing DVD speed needs write access.\n");
93 if (ioctl(fd
, SG_IO
, &sghdr
) < 0)
94 mp_tmsg(MSGT_OPEN
, MSGL_INFO
, "failed\n");
96 mp_tmsg(MSGT_OPEN
, MSGL_INFO
, "successful\n");
103 \brief Converts DVD time structure to milliseconds.
104 \param *dev the DVD time structure to convert
105 \return returns the time in milliseconds
107 int mp_dvdtimetomsec(dvd_time_t
*dt
)
109 static int framerates
[4] = {0, 2500, 0, 2997};
110 int framerate
= framerates
[(dt
->frame_u
& 0xc0) >> 6];
111 int msec
= (((dt
->hour
& 0xf0) >> 3) * 5 + (dt
->hour
& 0x0f)) * 3600000;
112 msec
+= (((dt
->minute
& 0xf0) >> 3) * 5 + (dt
->minute
& 0x0f)) * 60000;
113 msec
+= (((dt
->second
& 0xf0) >> 3) * 5 + (dt
->second
& 0x0f)) * 1000;
115 msec
+= (((dt
->frame_u
& 0x30) >> 3) * 5 + (dt
->frame_u
& 0x0f)) * 100000 / framerate
;