Add Media-Protect patch for libdvdread-4.1.3.
[overlay.git] / media-libs / libdvdread / files / libdvdread-4.1.3-media-protect.patch
1 diff -Nur libdvdread-4.1.3_p1168-orig/src/dvd_input.c libdvdread-4.1.3_p1168/src/dvd_input.c
2 --- libdvdread-4.1.3_p1168-orig/src/dvd_input.c 2009-03-09 18:41:50.000000000 +0100
3 +++ libdvdread-4.1.3_p1168/src/dvd_input.c      2010-08-16 01:52:24.000000000 +0200
4 @@ -332,6 +332,8 @@
5    }
6  #endif /* HAVE_DVDCSS_DVDCSS_H */
7  
8 +  fprintf(stderr, "libdvdread patched to play DVDs with DVD-Movie-Protect\n");
9 +
10    if(dvdcss_library != NULL) {
11      /*
12      char *psz_method = getenv( "DVDCSS_METHOD" );
13 diff -Nur libdvdread-4.1.3_p1168-orig/src/dvd_udf.c libdvdread-4.1.3_p1168/src/dvd_udf.c
14 --- libdvdread-4.1.3_p1168-orig/src/dvd_udf.c   2009-03-09 18:41:50.000000000 +0100
15 +++ libdvdread-4.1.3_p1168/src/dvd_udf.c        2010-08-16 01:53:03.000000000 +0200
16 @@ -38,10 +38,16 @@
17  #include <sys/stat.h>
18  #include <unistd.h>
19  #include <inttypes.h>
20 +#ifndef __WIN32__
21 +#include <fnmatch.h>
22 +#endif
23  
24  #include "dvdread/dvd_reader.h"
25  #include "dvdread/dvd_udf.h"
26  
27 +#include "dvdread/ifo_types.h"
28 +#include "dvdread/ifo_read.h"
29 +
30  /* Private but located in/shared with dvd_reader.c */
31  extern int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number,
32                               size_t block_count, unsigned char *data,
33 @@ -784,7 +790,7 @@
34    return part->valid;
35  }
36  
37 -uint32_t UDFFindFile( dvd_reader_t *device, char *filename,
38 +static uint32_t UDFFindFileReal( dvd_reader_t *device, char *filename,
39                        uint32_t *filesize )
40  {
41    uint8_t LogBlock_base[ DVD_VIDEO_LB_LEN + 2048 ];
42 @@ -863,6 +869,83 @@
43      return partition.Start + File.Location;
44  }
45  
46 +/**
47 + * Get the offset from the ifo files to allow playback of DVDs
48 + * with a deliberately broken UDF file system (aka DVD-Movie-Protect).
49 + * When the file is not an IFO or VOB, it calls the real UDF routine.
50 + */
51 +uint32_t UDFFindFile( dvd_reader_t *device, char *filename,
52 +                     uint32_t *filesize )
53 +{
54 +#ifndef __WIN32__
55 +  if (!fnmatch("/VIDEO_TS/VTS_[0-9][0-9]_[0-9].???", filename, FNM_PATHNAME)) {
56 +#else
57 +  if (strlen("/VIDEO_TS/VTS_01_1.VOB") == strlen(filename)
58 +      && !strncmp(filename, "/VIDEO_TS/VTS_", strlen("/VIDEO_TS/VTS_"))        ) {
59 +#endif
60 +               size_t len = strlen(filename);
61 +               char *extension = &filename[len-3];
62 +               if (!strcmp(extension, "IFO") || !strcmp(extension, "VOB")) {
63 +                       int title = atoi(&filename[len-8]);
64 +                       int part = atoi(&filename[len-5]);
65 +
66 +                       ifo_handle_t *ifo_handle = ifoOpen(device, 0);
67 +                       if (0 == ifo_handle)
68 +                               return 0;
69 +
70 +                       uint32_t tmp_filesize;
71 +                       uint32_t offset = UDFFindFileReal(device, "/VIDEO_TS/VIDEO_TS.IFO", &tmp_filesize);
72 +
73 +                       int i;
74 +                       for (i=0; i<ifo_handle->tt_srpt->nr_of_srpts; i++)
75 +                               if (title == ifo_handle->tt_srpt->title[i].title_set_nr)
76 +                                       break;
77 +
78 +                       if (i == ifo_handle->tt_srpt->nr_of_srpts) {
79 +                               /* not found */
80 +                               ifoClose(ifo_handle);
81 +                               return 0;
82 +                       }
83 +                       offset += ifo_handle->tt_srpt->title[i].title_set_sector;
84 +                       ifoClose(ifo_handle);
85 +
86 +                       if (!strcmp(extension, "VOB")) {
87 +                               ifo_handle = ifoOpen(device, title);
88 +                               if (0 == ifo_handle)
89 +                                       return 0;
90 +
91 +                               switch(part) {
92 +                                       case 0:
93 +                                               if (0 == ifo_handle->vtsi_mat->vtsm_vobs) {
94 +                                                       ifoClose(ifo_handle);
95 +                                                       return 0;
96 +                                               }
97 +                                               offset += ifo_handle->vtsi_mat->vtsm_vobs;
98 +                                               break;
99 +                                       case 1:
100 +                                               if (0 == ifo_handle->vtsi_mat->vtstt_vobs) {
101 +                                                       ifoClose(ifo_handle);
102 +                                                       return 0;
103 +                                               }
104 +                                               offset += ifo_handle->vtsi_mat->vtstt_vobs;
105 +                                               break;
106 +                                       default: /* can't get other parts (also no need to) */
107 +                                               offset = 0;
108 +                                               break;
109 +                               }
110 +
111 +                               ifoClose(ifo_handle);
112 +                       }
113 +
114 +
115 +                       *filesize = 1000000; /* File size unknown */
116 +                       if (offset != 0)
117 +                               return offset;
118 +               }
119 +       }
120 +
121 +       return UDFFindFileReal( device, filename, filesize);
122 +}
123  
124  
125  /**