annotate remap.c @ 0:427b7da5cbdb src

first split of dvdread; it's just a copy of dvdnav still to be cleaned
author nicodvb
date Sun, 01 Jun 2008 08:39:07 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
1 /*
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
2 * This file is part of libdvdnav, a DVD navigation library.
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
3 *
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
4 * libdvdnav is free software; you can redistribute it and/or modify
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
7 * (at your option) any later version.
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
8 *
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
9 * libdvdnav is distributed in the hope that it will be useful,
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
12 * GNU General Public License for more details.
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
13 *
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
17 *
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
18 * $Id$
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
19 */
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
20
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
21 #ifdef HAVE_CONFIG_H
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
22 #include "config.h"
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
23 #endif
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
24
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
25 #include <stdlib.h>
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
26 #include <string.h>
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
27 #include <stdio.h>
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
28
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
29 #ifndef _MSC_VER
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
30 #include <sys/param.h>
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
31 #include <sys/fcntl.h>
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
32 #else
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
33 #ifndef MAXPATHLEN
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
34 #define MAXPATHLEN 255
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
35 #endif
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
36 #endif /* _MSC_VER */
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
37
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
38 #include <assert.h>
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
39 #include <inttypes.h>
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
40 #include <limits.h>
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
41 #include <sys/time.h>
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
42 #include "dvd_types.h"
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
43 #include "nav_types.h"
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
44 #include "ifo_types.h"
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
45 #include "remap.h"
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
46 #include "vm/decoder.h"
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
47 #include "vm/vm.h"
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
48 #include "dvdnav.h"
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
49 #include "dvdnav_internal.h"
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
50
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
51 struct block_s {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
52 int domain;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
53 int title;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
54 int program;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
55 unsigned long start_block;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
56 unsigned long end_block;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
57 };
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
58
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
59 struct remap_s {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
60 char *title;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
61 int maxblocks;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
62 int nblocks;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
63 int debug;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
64 struct block_s *blocks;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
65 };
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
66
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
67 static remap_t* remap_new( char *title) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
68 remap_t *map = malloc( sizeof(remap_t));
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
69 map->title = strdup(title);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
70 map->maxblocks = 0;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
71 map->nblocks = 0;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
72 map->blocks = NULL;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
73 map->debug = 0;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
74 return map;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
75 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
76
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
77 static int compare_block( block_t *a, block_t *b) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
78 /* returns -1 if a precedes b, 1 if a follows b, and 0 if a and b overlap */
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
79 if (a->domain < b->domain) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
80 return -1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
81 } else if (a->domain > b->domain) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
82 return 1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
83 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
84
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
85 if (a->title < b->title) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
86 return -1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
87 } else if (a->title > b->title) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
88 return 1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
89 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
90
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
91 if (a->program < b->program) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
92 return -1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
93 } else if (a->program > b->program) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
94 return 1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
95 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
96
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
97 if (a->end_block < b->start_block) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
98 return -1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
99 } else if (a->start_block > b->end_block) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
100 /*
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
101 * if a->start_block == b->end_block then the two regions
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
102 * aren't strictly overlapping, but they should be merged
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
103 * anyway since there are zero blocks between them
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
104 */
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
105 return 1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
106 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
107
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
108 return 0;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
109 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
110
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
111 static block_t *findblock( remap_t *map, block_t *key) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
112 int lb = 0;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
113 int ub = map->nblocks - 1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
114 int mid;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
115 int res;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
116
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
117 while (lb <= ub) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
118 mid = lb + (ub - lb)/2;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
119 res = compare_block( key, &map->blocks[mid]);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
120 if (res < 0) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
121 ub = mid-1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
122 } else if (res > 0) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
123 lb = mid+1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
124 } else {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
125 return &map->blocks[mid];
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
126 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
127 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
128 return NULL;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
129 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
130
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
131 static void mergeblock( block_t *b, block_t tmp) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
132 if (tmp.start_block < b->start_block) b->start_block = tmp.start_block;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
133 if (tmp.end_block > b->end_block) b->end_block = tmp.end_block;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
134 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
135
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
136 static void remap_add_node( remap_t *map, block_t block) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
137 block_t *b;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
138 int n;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
139 b = findblock( map, &block);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
140 if (b) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
141 /* overlaps an existing block */
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
142 mergeblock( b, block);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
143 } else {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
144 /* new block */
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
145 if (map->nblocks >= map->maxblocks) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
146 map->maxblocks += 20;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
147 map->blocks = realloc( map->blocks, sizeof( block_t)*map->maxblocks);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
148 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
149 n = map->nblocks++;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
150 while (n > 0 && compare_block( &block, &map->blocks[ n-1]) < 0) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
151 map->blocks[ n] = map->blocks[ n-1];
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
152 n--;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
153 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
154 map->blocks[ n] = block;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
155 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
156 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
157
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
158 static int parseblock(char *buf, int *dom, int *tt, int *pg,
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
159 unsigned long *start, unsigned long *end) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
160 long tmp;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
161 char *tok;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
162 char *epos;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
163 char *marker[]={"domain", "title", "program", "start", "end"};
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
164 int st = 0;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
165 tok = strtok( buf, " ");
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
166 while (st < 5) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
167 if (strcmp(tok, marker[st])) return -st-1000;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
168 tok = strtok( NULL, " ");
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
169 if (!tok) return -st-2000;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
170 tmp = strtol( tok, &epos, 0);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
171 if (*epos != 0 && *epos != ',') return -st-3000;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
172 switch (st) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
173 case 0:
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
174 *dom = (int)tmp;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
175 break;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
176 case 1:
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
177 *tt = (int)tmp;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
178 break;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
179 case 2:
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
180 *pg = (int)tmp;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
181 break;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
182 case 3:
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
183 *start = tmp;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
184 break;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
185 case 4:
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
186 *end = tmp;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
187 break;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
188 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
189 st++;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
190 tok = strtok( NULL, " ");
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
191 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
192 return st;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
193 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
194
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
195 remap_t* remap_loadmap( char *title) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
196 char buf[160];
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
197 char fname[MAXPATHLEN];
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
198 char *home;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
199 int res;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
200 FILE *fp;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
201 block_t tmp;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
202 remap_t *map;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
203
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
204 /* Build the map filename */
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
205 home = getenv("HOME"); assert(home);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
206 snprintf(fname, sizeof(fname), "%s/.dvdnav/%s.map", home, title);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
207
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
208 /* Open the map file */
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
209 fp = fopen( fname, "r");
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
210 if (!fp) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
211 fprintf(MSG_OUT, "libdvdnav: Unable to find map file '%s'\n", fname);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
212 return NULL;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
213 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
214
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
215 /* Load the map file */
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
216 map = remap_new( title);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
217 while (fgets( buf, sizeof(buf), fp) != NULL) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
218 if (buf[0] == '\n' || buf[0] == '#' || buf[0] == 0) continue;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
219 if (strncasecmp( buf, "debug", 5) == 0) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
220 map->debug = 1;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
221 } else {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
222 res = parseblock( buf,
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
223 &tmp.domain, &tmp.title, &tmp.program, &tmp.start_block, &tmp.end_block);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
224 if (res != 5) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
225 fprintf(MSG_OUT, "libdvdnav: Ignoring map line (%d): %s\n", res, buf);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
226 continue;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
227 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
228 remap_add_node( map, tmp);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
229 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
230 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
231 fclose(fp);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
232
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
233 if (map->nblocks == 0 && map->debug == 0) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
234 free(map);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
235 return NULL;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
236 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
237 return map;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
238 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
239
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
240 unsigned long remap_block(
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
241 remap_t *map, int domain, int title, int program,
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
242 unsigned long cblock, unsigned long offset)
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
243 {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
244 block_t key;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
245 block_t *b;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
246
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
247 if (map->debug) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
248 fprintf(MSG_OUT, "libdvdnav: %s: domain %d, title %d, program %d, start %lx, next %lx\n",
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
249 map->title, domain, title, program, cblock, cblock+offset);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
250 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
251
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
252 key.domain = domain;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
253 key.title = title;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
254 key.program = program;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
255 key.start_block = key.end_block = cblock + offset;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
256 b = findblock( map, &key);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
257
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
258 if (b) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
259 if (map->debug) {
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
260 fprintf(MSG_OUT, "libdvdnav: Redirected to %lx\n", b->end_block);
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
261 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
262 return b->end_block - cblock;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
263 }
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
264 return offset;
427b7da5cbdb first split of dvdread; it's just a copy of dvdnav still to be cleaned
nicodvb
parents:
diff changeset
265 }