annotate stream/stream_dvd_common.c @ 33284:326bd394efab

configure: Handle X11 dependencies in the checks for dependent features. This makes each individual feature check self-contained, which is desirable.
author diego
date Thu, 05 May 2011 10:25:17 +0000
parents ce0122361a39
children edd8273dc025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30426
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
1 /*
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
2 * This file is part of MPlayer.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
3 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
5 * it under the terms of the GNU General Public License as published by
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
7 * (at your option) any later version.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
8 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
12 * GNU General Public License for more details.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
13 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
14 * You should have received a copy of the GNU General Public License along
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
17 */
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29852
diff changeset
18
26907
f0d0b666ee35 Fix compilation with internal dvdnav
rtogni
parents: 26906
diff changeset
19 #include "config.h"
29852
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
20 #include <fcntl.h>
24047
de28f9e8cb00 Sync libdvdread with version 0.9.5 (functional changes).
diego
parents: 23993
diff changeset
21 #include <inttypes.h>
29852
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
22 #include <unistd.h>
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
23 #include <stdio.h>
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
24 #include <string.h>
27466
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents: 27341
diff changeset
25 #include <dvdread/ifo_types.h>
29852
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
26 #ifdef __FreeBSD__
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
27 #include <sys/cdrio.h>
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
28 #endif
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
29
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
30 #ifdef __linux__
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
31 #include <linux/cdrom.h>
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
32 #include <scsi/sg.h>
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
33 #include <sys/types.h>
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
34 #include <sys/stat.h>
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
35 #include <sys/ioctl.h>
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
36 #endif
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
37
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
38 #include "mp_msg.h"
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
39 #include "help_mp.h"
23993
2107f38b6ca1 Moved dvdtimetomsec to stream_dvd_common.c.
cehoyos
parents: 23691
diff changeset
40 #include "stream_dvd_common.h"
29852
32d288088a0f Move headers related to setting dvd speed to dvd_common.
reimar
parents: 29848
diff changeset
41 #include "libavutil/intreadwrite.h"
15518
9391bf60ccdf ported dvd:// to the new stream api
nicodvb
parents:
diff changeset
42
29847
e37311e178e1 Move arrays used by both dvd and dvdnav to dvd_common.
reimar
parents: 29263
diff changeset
43 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
44 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
45
29848
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
46 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
47
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
48 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
49 {
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
50 #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
51 int fd;
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
52 unsigned char buffer[28];
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
53 unsigned char cmd[12];
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
54 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
55 struct stat st;
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
56
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
57 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
58
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
59 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
60
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
61 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
62
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
63 switch (speed) {
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
64 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
65 return;
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
66 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
67 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
68 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
69 break;
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
70 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
71 // 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
72 if (speed < 100)
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
73 speed *= 1350;
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
74 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
75 break;
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
76 }
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
77
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
78 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
79 sghdr.interface_id = 'S';
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
80 sghdr.timeout = 5000;
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
81 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
82 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
83 sghdr.dxferp = buffer;
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
84 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
85 sghdr.cmdp = cmd;
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 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
88 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
89 cmd[10] = sizeof(buffer);
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
90
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
91 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
92 /* 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
93 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
94 if (speed == -1)
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
95 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
96 else {
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
97 /* <speed> kilobyte */
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
98 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
99 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
100 }
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
101 /* 1 second */
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
102 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
103 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
104
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
105 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
106 if (fd == -1) {
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
107 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
108 return;
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
109 }
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
110
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
111 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
112 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
113 else
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
114 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
115
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
116 close(fd);
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
117 #endif
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
118 }
c20a30ebbe56 Move dvd_speed and dvd_set_speed to dvd_common and implement -dvd-speed
reimar
parents: 29847
diff changeset
119
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28245
diff changeset
120 /**
16544
a10adcba312f Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents: 15551
diff changeset
121 \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
122 \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
123 \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
124 */
23993
2107f38b6ca1 Moved dvdtimetomsec to stream_dvd_common.c.
cehoyos
parents: 23691
diff changeset
125 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
126 {
a10adcba312f Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents: 15551
diff changeset
127 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
128 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
129 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
130 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
131 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
132 if(framerate > 0)
a10adcba312f Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents: 15551
diff changeset
133 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
134 return msec;
a10adcba312f Prints the number of titles, DVD disk ID, the numbers of chapters and
gpoirier
parents: 15551
diff changeset
135 }