~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/input/cdromToc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  reads toc from cdrom (system dependend)
 
3
  Copyright (C) 1999  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
 
 
15
#include "cdromToc.h"
 
16
 
 
17
 
 
18
 
 
19
CDRomToc::CDRomToc() {
 
20
  maxEntries=0;
 
21
}
 
22
 
 
23
 
 
24
CDRomToc::~CDRomToc() {
 
25
}
 
26
 
 
27
 
 
28
void CDRomToc::insertTocEntry(int minute,int second,int frame) {
 
29
  int i;
 
30
  int j;
 
31
  if (isElement(minute,second,frame)) {
 
32
    return;
 
33
  }
 
34
 
 
35
  i=getNextTocEntryPos(minute,second,frame);
 
36
 
 
37
  // now shift from i to end
 
38
  if (maxEntries == 100) {
 
39
    cerr << "maximum of toc entries reached"<<endl;
 
40
    exit(0);
 
41
  }
 
42
  for (j=maxEntries;j>i;j--) {
 
43
    tocEntries[j].minute=tocEntries[j-1].minute;
 
44
    tocEntries[j].second=tocEntries[j-1].second;
 
45
    tocEntries[j].frame=tocEntries[j-1].frame;
 
46
  }
 
47
  maxEntries++;
 
48
  
 
49
  tocEntries[i].minute=minute;
 
50
  tocEntries[i].second=second;
 
51
  tocEntries[i].frame=frame;  
 
52
  calculateRange();
 
53
}
 
54
 
 
55
 
 
56
int CDRomToc::getNextTocEntryPos(int minute,int second,int frame) {
 
57
  int i;
 
58
  if (maxEntries == 0) {
 
59
    return 0;
 
60
  }
 
61
 
 
62
  for (i=0;i<maxEntries;i++) {
 
63
    if (tocEntries[i].minute <= minute) {
 
64
      continue;
 
65
    } else {
 
66
      break;
 
67
    }
 
68
    if (tocEntries[i].second <= second) {
 
69
      continue;
 
70
    } else {
 
71
      break;
 
72
    }
 
73
    if (tocEntries[i].frame <= frame) {
 
74
      continue;
 
75
    }
 
76
    break;
 
77
  } 
 
78
  return i;
 
79
}
 
80
 
 
81
    
 
82
    
 
83
int CDRomToc::isElement(int minute,int second,int frame) {
 
84
  int i;
 
85
 
 
86
  for (i=0;i<maxEntries;i++) {
 
87
    if (tocEntries[i].minute == minute) {
 
88
      if (tocEntries[i].second == second) {
 
89
        if (tocEntries[i].frame == frame) {
 
90
          return true;
 
91
        }
 
92
      }
 
93
    }
 
94
  }
 
95
  return false;
 
96
}
 
97
 
 
98
 
 
99
 
 
100
 
 
101
 
 
102
 
 
103
int CDRomToc::getTocEntries() {
 
104
  return maxEntries;
 
105
}
 
106
 
 
107
 
 
108
TocEntry* CDRomToc::getTocEntry(int entry) {
 
109
  return &(tocEntries[entry]);
 
110
}
 
111
 
 
112
 
 
113
void CDRomToc::print() {
 
114
  int i;
 
115
  cerr << "******* printing TOC [START]"<<endl;
 
116
  for(i=0;i<maxEntries;i++) {
 
117
    cerr << "i:"<<i
 
118
         <<" M:"<<tocEntries[i].minute
 
119
         <<" S:"<<tocEntries[i].second
 
120
         <<" F:"<<tocEntries[i].frame<<endl;
 
121
  }
 
122
  cerr << "******* printing TOC [END}"<<endl;
 
123
}
 
124
 
 
125
 
 
126
int CDRomToc::isInRange(int minute,int second,int) {
 
127
  long val=minute*60+second;
 
128
  if (val < startByte) {
 
129
    return false;
 
130
  }
 
131
  if (val > endByte) {
 
132
    return false;
 
133
  }
 
134
  return true;
 
135
}
 
136
 
 
137
int CDRomToc::calculateRange() {
 
138
 
 
139
 
 
140
  if (maxEntries < 2) {
 
141
    cout << "no two elemts in toc"<<endl;
 
142
    return false;
 
143
  }
 
144
  startByte=tocEntries[0].minute*60*+tocEntries[0].second;
 
145
  
 
146
  // do a safty end because of the kernel bug
 
147
  int minute=tocEntries[maxEntries-1].minute;
 
148
  int second=tocEntries[maxEntries-1].second-20;
 
149
  if (second < 0) {
 
150
    minute--;
 
151
    second=60+second;
 
152
  }
 
153
  if (minute < 0) {
 
154
    endByte=0;
 
155
    return true;
 
156
  }
 
157
 
 
158
  endByte=minute*60+second;
 
159
 
 
160
  return true;
 
161
 
 
162
}
 
163
 
 
164
 
 
165
int CDRomToc::getEndSecond() {
 
166
  return endByte;
 
167
}
 
168
 
 
169
 
 
170
 
 
171
 
 
172
int CDRomToc::open(const char* openfile) {
 
173
  int i;
 
174
  int pos=0;
 
175
  maxEntries=0;
 
176
  const char* filename=strchr(openfile,'/');
 
177
  FILE* file =fopen(filename, "rb");
 
178
  if (file == NULL) {
 
179
    perror("open");
 
180
    return false;
 
181
  }
 
182
  cout << "reading toc on:"<<filename<<" openfile:"<<openfile<<endl;
 
183
 
 
184
  int startToc=0;
 
185
  int endToc=0;
 
186
 
 
187
  if (getStartEnd(file,startToc,endToc) == false) {
 
188
    cout << "getStartEnd in CDRomToc failed"<<endl;
 
189
    fclose(file);
 
190
    return false;
 
191
  }
 
192
  cout << "startToc:"<<startToc<<" endToc:"<<endToc<<endl;
 
193
  cout << "reading toc -2"<<endl;
 
194
  /* read individual tracks */
 
195
  int min;
 
196
  int sec;
 
197
  int frame;
 
198
 
 
199
  for (i=startToc; i<=endToc; i++) {
 
200
    int min;
 
201
    int sec;
 
202
    int frame;
 
203
 
 
204
    if (readToc(file,i,min,sec,frame) == false) {
 
205
      cout << "error in CDRomToc::readToc"<<endl;
 
206
      fclose(file);
 
207
      return false;
 
208
    }
 
209
    cout << "min:"<<min<<endl;
 
210
    cout << "sec:"<<sec<<endl;
 
211
    cout << "frame:"<<frame<<endl;
 
212
    
 
213
    insertTocEntry(min,sec,frame);
 
214
    pos++;
 
215
  }
 
216
 
 
217
 
 
218
  /* read the lead-out track */
 
219
  if (readLeadOut(file,min,sec,frame) == false) {
 
220
    cout << "error in CDRomToc::reatLeadOut"<<endl;
 
221
    return false;
 
222
  }
 
223
  pos++;
 
224
  insertTocEntry(min,sec,frame);
 
225
  
 
226
  maxEntries=pos;
 
227
 
 
228
  fclose(file);
 
229
 
 
230
  return true;
 
231
}
 
232