Mercurial > mplayer.hg
annotate stream/stream_dvd_common.c @ 29968:4e0ff9be2b1e
Avoid '&>' bashism for redirecting both stdout and stderr.
author | diego |
---|---|
date | Sun, 13 Dec 2009 23:48:20 +0000 |
parents | 32d288088a0f |
children | ce0122361a39 |
rev | line source |
---|---|
26907 | 1 #include "config.h" |
29852
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
2 #include <fcntl.h> |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
23993
diff
changeset
|
3 #include <inttypes.h> |
29852
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
4 #include <unistd.h> |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
5 #include <stdio.h> |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
6 #include <string.h> |
27466
ea01824701a5
Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
27341
diff
changeset
|
7 #include <dvdread/ifo_types.h> |
29852
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
8 #ifdef __FreeBSD__ |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
9 #include <sys/cdrio.h> |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
10 #endif |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
11 |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
12 #ifdef __linux__ |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
13 #include <linux/cdrom.h> |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
14 #include <scsi/sg.h> |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
15 #include <sys/types.h> |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
16 #include <sys/stat.h> |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
17 #include <sys/ioctl.h> |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
18 #endif |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
19 |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
20 #include "mp_msg.h" |
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
21 #include "help_mp.h" |
23993 | 22 #include "stream_dvd_common.h" |
29852
32d288088a0f
Move headers related to setting dvd speed to dvd_common.
reimar
parents:
29848
diff
changeset
|
23 #include "libavutil/intreadwrite.h" |
15518 | 24 |
29847
e37311e178e1
Move arrays used by both dvd and dvdnav to dvd_common.
reimar
parents:
29263
diff
changeset
|
25 const char * const dvd_audio_stream_types[8] = { "ac3","unknown","mpeg1","mpeg2ext","lpcm","unknown","dts" }; |
e37311e178e1
Move arrays used by both dvd and dvdnav to dvd_common.
reimar
parents:
29263
diff
changeset
|
26 const char * const dvd_audio_stream_channels[6] = { "mono", "stereo", "unknown", "unknown", "5.1/6.1", "5.1" }; |
e37311e178e1
Move arrays used by both dvd and dvdnav to dvd_common.
reimar
parents:
29263
diff
changeset
|
27 |
29848
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
28 int dvd_speed=0; /* 0 => don't touch speed */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
29 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
30 void dvd_set_speed(char *device, unsigned speed) |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
31 { |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
32 #if defined(__linux__) && defined(SG_IO) && defined(GPCMD_SET_STREAMING) |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
33 int fd; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
34 unsigned char buffer[28]; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
35 unsigned char cmd[12]; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
36 struct sg_io_hdr sghdr; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
37 struct stat st; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
38 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
39 memset(&st, 0, sizeof(st)); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
40 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
41 if (stat(device, &st) == -1) return; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
42 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
43 if (!S_ISBLK(st.st_mode)) return; /* not a block device */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
44 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
45 switch (speed) { |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
46 case 0: /* don't touch speed setting */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
47 return; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
48 case -1: /* restore default value */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
49 if (dvd_speed == 0) return; /* we haven't touched the speed setting */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
50 mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_DVDrestoreSpeed); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
51 break; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
52 default: /* limit to <speed> KB/s */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
53 // speed < 100 is multiple of DVD single speed (1350KB/s) |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
54 if (speed < 100) |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
55 speed *= 1350; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
56 mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_DVDlimitSpeed, speed); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
57 break; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
58 } |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
59 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
60 memset(&sghdr, 0, sizeof(sghdr)); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
61 sghdr.interface_id = 'S'; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
62 sghdr.timeout = 5000; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
63 sghdr.dxfer_direction = SG_DXFER_TO_DEV; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
64 sghdr.dxfer_len = sizeof(buffer); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
65 sghdr.dxferp = buffer; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
66 sghdr.cmd_len = sizeof(cmd); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
67 sghdr.cmdp = cmd; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
68 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
69 memset(cmd, 0, sizeof(cmd)); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
70 cmd[0] = GPCMD_SET_STREAMING; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
71 cmd[10] = sizeof(buffer); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
72 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
73 memset(buffer, 0, sizeof(buffer)); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
74 /* first sector 0, last sector 0xffffffff */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
75 AV_WB32(buffer + 8, 0xffffffff); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
76 if (speed == -1) |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
77 buffer[0] = 4; /* restore default */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
78 else { |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
79 /* <speed> kilobyte */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
80 AV_WB32(buffer + 12, speed); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
81 AV_WB32(buffer + 20, speed); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
82 } |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
83 /* 1 second */ |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
84 AV_WB16(buffer + 18, 1000); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
85 AV_WB16(buffer + 26, 1000); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
86 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
87 fd = open(device, O_RDWR | O_NONBLOCK); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
88 if (fd == -1) { |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
89 mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_DVDspeedCantOpen); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
90 return; |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
91 } |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
92 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
93 if (ioctl(fd, SG_IO, &sghdr) < 0) |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
94 mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_DVDlimitFail); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
95 else |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
96 mp_msg(MSGT_OPEN, MSGL_INFO, MSGTR_DVDlimitOk); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
97 |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
98 close(fd); |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
99 #endif |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
100 } |
c20a30ebbe56
Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents:
29847
diff
changeset
|
101 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28245
diff
changeset
|
102 /** |
16544
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
103 \brief Converts DVD time structure to milliseconds. |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
104 \param *dev the DVD time structure to convert |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
105 \return returns the time in milliseconds |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
106 */ |
23993 | 107 int mp_dvdtimetomsec(dvd_time_t *dt) |
16544
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
108 { |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
109 static int framerates[4] = {0, 2500, 0, 2997}; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
110 int framerate = framerates[(dt->frame_u & 0xc0) >> 6]; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
111 int msec = (((dt->hour & 0xf0) >> 3) * 5 + (dt->hour & 0x0f)) * 3600000; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
112 msec += (((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f)) * 60000; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
113 msec += (((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f)) * 1000; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
114 if(framerate > 0) |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
115 msec += (((dt->frame_u & 0x30) >> 3) * 5 + (dt->frame_u & 0x0f)) * 100000 / framerate; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
116 return msec; |
a10adcba312f
Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents:
15551
diff
changeset
|
117 } |