1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
/***************************************************************************
* Copyright (C) 2005 by Jean-Michel Petit *
* jm_petit@laposte.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "k9cellcopylist.h"
#include "k9dvdtitle.h"
#include "k9ifo2.h"
#include <kmessagebox.h>
int k9CellVTSList::compareItems ( TQPtrCollection::Item item1, TQPtrCollection::Item item2 ) {
k9CellCopyVTS * it1,*it2;
it1=(k9CellCopyVTS *) item1;
it2=(k9CellCopyVTS *)item2;
if (it1->getsize() >it2->getsize())
return 1;
else if (it1->getsize() <it2->getsize())
return -1;
else {
if (it1->getnum()>it2->getnum())
return 1;
else
return -1;
}
}
uint k9CellCopyVTS::getnum() {
return num;
}
void k9CellCopyVTS::addsize(uint32_t _size) {
size+=_size;
}
uint64_t k9CellCopyVTS::getsize() {
return size;
}
k9CellCopyList::k9CellCopyList(k9DVDRead * _dvdHandle,k9DVD *_DVD)
: TQObjectList() {
setAutoDelete(true);
DVD=_DVD;
dvdHandle=_dvdHandle;
fill();
}
k9CellCopyList::~k9CellCopyList() {}
/*!
\fn k9CellCopyList::fill()
*/
void k9CellCopyList::fill() {
// k9Ifo2 kifo(dvdHandle) ,kifoZero(dvdHandle);
ifo_handle_t *hifo,*hifoZero;
k9Ifo2 *kifo,*kifoZero;
kifoZero=dvdHandle->getIfo(0);
hifoZero=kifoZero->getIFO();
// kifoZero.openIFO( 0);
int nrTS= hifoZero->vmgi_mat->vmg_nr_of_title_sets;
for (int iTS=1 ; iTS<=nrTS;iTS++) {
//kifo.openIFO( iTS);
kifo=dvdHandle->getIfo(iTS);
hifo=kifo->getIFO();
c_adt_t *c_adt = hifo->vts_c_adt;
uint32_t length = c_adt->last_byte + 1 - C_ADT_SIZE;
cell_adr_t *ptr;
ptr= c_adt->cell_adr_table;
uint32_t imax=length/sizeof(cell_adr_t);
for(uint32_t i = 0; i <imax; i++) {
uchar angleBlock=angleNone;
k9Cell *cell=NULL;
cell=addCell(iTS,0,i+1,ptr[i].start_sector,ptr[i].last_sector,angleBlock);
}
//kifo.closeIFO();
}
//kifoZero.closeIFO();
sortVTSList();
m_frcinbytes=m_frcoutbytes=m_inbytes=m_outbytes=0;
}
k9Cell *k9CellCopyList::addCell(int _VTS,int _pgc,int _id,uint32_t startSector,uint32_t lastSector,uchar _angleBlock) {
bool bInsert=false;
bool bFound=false;
uint position=0;
k9Cell *cell =NULL;
for (uint i=0;i< count() && !bFound && !bInsert;i++) {
cell=(k9Cell*) at(i);
if (cell->startSector ==startSector && cell->vts==_VTS) {
bFound=true;
if (cell->lastSector!=lastSector )
qDebug("last sector doesn't match","DVD Backup");
}
if (!bFound && (_VTS <cell->vts || (startSector<cell->startSector && cell->vts ==_VTS ) )) {
bInsert=true;
position=i;
}
}
if (!bFound) {
cell = new k9Cell();
cell->vts=_VTS;
cell->startSector=startSector;
cell->lastSector=lastSector;
cell->pgc=_pgc;
cell->id=_id;
cell->angleBlock=_angleBlock;
cell->selected=checkSelected(cell);
if (bInsert)
insert(position,cell);
else
append(cell);
uint32_t isize;
isize= cell->selected ? ((lastSector-startSector)*2048):2;
setVTS(_VTS,isize);
}
return(cell);
}
void k9CellCopyList::setVTS(uint _numVTS,uint32_t _size) {
bool bfound=false;
for (uint iVTS=0; iVTS<VTSList.count();iVTS++) {
k9CellCopyVTS *VTS=VTSList.at(iVTS);
if (VTS->getnum()==_numVTS) {
VTS->addsize(_size);
bfound=true;
}
}
if (!bfound) {
k9CellCopyVTS * VTS= new k9CellCopyVTS(_numVTS);
VTS->addsize(_size);
VTSList.append(VTS);
}
}
void k9CellCopyList::sortVTSList() {
VTSList.sort();
}
void k9CellCopyList::addStreams(k9DVDTitle *_title,k9Cell *_cell) {
k9DVDSubtitle *l_sub;
k9DVDAudioStream *l_auds;
for (int i=0;i<_title->getaudioStreamCount();i++) {
l_auds=_title->getaudioStream(i);
if (l_auds->getselected()) {
TQValueList<int>::iterator it;
bool found=false;
for ( it = _cell->audio.begin(); it != _cell->audio.end(); ++it ) {
if (*it == l_auds->getID())
found=true;
}
if (!found)
_cell->audio.append(l_auds->getID());
}
}
for (int i=0;i<_title->getsubPictureCount();i++) {
TQString c;
l_sub=_title->getsubtitle(i);
if (l_sub->getselected()) {
TQValueList<int>::iterator it;
bool found=false;
for ( it = _cell->subpicture.begin(); it != _cell->subpicture.end(); ++it ) {
if (l_sub->getID().tqcontains(*it))
found=true;
}
if (!found)
_cell->subpicture+=l_sub->getID();
}
}
}
/*!
\fn k9CellCopyList::checkSelected(k9Cell *_cell)
*/
bool k9CellCopyList::checkSelected(k9Cell *_cell) {
bool selected=false;
for (int i=0; i< DVD->gettitleCount();i++) {
k9DVDTitle *title=DVD->gettitle(i);
//FACTOR if ( title->getVTS()==_cell->vts && title ->isSelected()) {
if ( title->getVTS()==_cell->vts) { // { && title ->isSelected()) {
for (int j=0; j <title->getchapterCount();j++) {
k9DVDChapter * chapter= title->getChapter(j);
if (_cell->startSector >= chapter->getstartSector() && _cell->startSector<=chapter->getendSector()) {
//add a reference to the title in the titles list from the cell
_cell->addTitle( title); //FACTOR
// if (title->isSelected()) {
if (chapter->getSelected()) {
addStreams (title,_cell);
selected=true;
}
}
}
}
}
return selected;
}
double k9CellCopyList::gettotalSize() {
double totalSize=0;
for (uint iCell=0;iCell<count();iCell++) {
k9Cell *cell=(k9Cell*)at(iCell);
// if (!cell->copied) {
if (cell->selected) {
if (cell->angleBlock==angleNone)
totalSize += cell->lastSector-cell->startSector;
else if (cell->angleBlock==angleStart) {
uint32_t start=0,end=0;
start=cell->startSector;
// loop inside the angle block to find the last sector.
while (((k9Cell*)at(iCell))->angleBlock !=angleNone) {
end=((k9Cell*)at(iCell))->lastSector;
iCell++;
}
iCell--;
totalSize += end-start;
}
} else
totalSize += 1;
// }
}
return (totalSize*2048);
;
}
//gives the final size of cells with a forced shrink factor
double k9CellCopyList::getforcedSize(bool _withFactor) {
double totalSize=0;
for (uint iCell=0;iCell<count();iCell++) {
k9Cell *cell=(k9Cell*)at(iCell);
double factor = _withFactor ? cell->getFactor():1;
double size=0;
// if (!cell->copied) {
if (cell->selected && cell->getforceFactor() ) {
if (cell->angleBlock==angleNone)
size = cell->lastSector-cell->startSector;
else if (cell->angleBlock==angleStart) {
uint32_t start=0,end=0;
start=cell->startSector;
// loop inside the angle block to find the last sector.
while (((k9Cell*)at(iCell))->angleBlock !=angleNone) {
end=((k9Cell*)at(iCell))->lastSector;
iCell++;
}
iCell--;
size += end-start;
}
totalSize += (size/factor);
}
// }
}
return (totalSize*2048);
}
double k9CellCopyList::getMinFactor(bool _withMenus) {
double fforced=getforcedSize( false);
double MaxSize=k9DVDSize::getMaxSize();
MaxSize*=1024*1024;
double menuSize=0;
if (_withMenus)
menuSize=DVD->getmenuSize();
menuSize= menuSize*2048;
//totalSize=part of dvd with auto shrink factor/2.5
//double totalSize=gettotalSize()+menuSize - (fforced-m_frcinbytes) -m_inbytes;
double totalSize=gettotalSize()+menuSize - (fforced) -m_inbytes;
totalSize/=2.50;
qDebug(TQString("totalSize(%1)=gettotalSize()(%2)+menuSize(%3) -(fforced(%4))-m_inbytes(%6)").tqarg(totalSize).tqarg(gettotalSize()).tqarg(menuSize).tqarg(fforced).tqarg(m_frcinbytes).tqarg(m_inbytes));
double minFactor=(fforced-m_frcinbytes) /(MaxSize- (totalSize +m_outbytes) - m_frcoutbytes) ;
qDebug(TQString("minfactor(%1)=(fforced(%2) -m_frinbytes(%3))/(MacSize(%4)-totalSize(%5)-m_outbytes(%6) - m_frcoutbytes(%7))").tqarg(minFactor).tqarg(fforced).tqarg(m_frcinbytes).tqarg(MaxSize).tqarg(totalSize).tqarg(m_outbytes).tqarg(m_frcoutbytes));
if (minFactor<1)
minFactor=1;
return minFactor;
}
double k9CellCopyList::getfactor(bool _withMenus,bool _streams) {
double totalSize=gettotalSize();
if (_streams) {
double unsel=0;
for (int i=0;i<DVD->gettitleCount();i++) {
k9DVDTitle *track=DVD->gettitle(i);
for (int j=0; j<track->getaudioStreamCount();j++) {
k9DVDAudioStream *audio=track->getaudioStream(j);
if (! audio->getselected())
unsel+=audio->getsize_mb();
}
for (int j=0; j<track->getsubPictureCount();j++) {
k9DVDSubtitle *sub=track->getsubtitle(j);
if (! sub->getselected())
unsel+=sub->getsize_mb();
}
}
unsel*=1024*1024;
totalSize-=unsel;
}
double menuSize=0;
if (_withMenus)
menuSize=DVD->getmenuSize();
menuSize= menuSize*2048;
double dvdSize=k9DVDSize::getMaxSize() ;
dvdSize*=1024*1024;
double factor;
double fforced=getforcedSize(false)-m_frcinbytes;
double fforcedsh=getforcedSize(true)-m_frcoutbytes;
double dvdSize2=dvdSize-m_outbytes -fforcedsh;
// dvdSize2 -=menuSize;
if (dvdSize2 <0) {
factor=2.5;
//qDebug(TQString("dvdSize (%1)- _outbytes(%2) - fforcedsh(%3)=%4").tqarg(dvdSize).tqarg(m_outbytes).tqarg(fforcedsh).tqarg(dvdSize2));
}
else {
factor=(totalSize +menuSize - fforced -m_inbytes)/ dvdSize2 ;
factor = (int)(factor*100);
factor /=100;
factor+=0.01;
// }
uint64_t o=m_outbytes;
uint64_t i=m_inbytes;
//if (o==0)
// o=1;
//qDebug(TQString("factor : %1 realise : %2").tqarg(factor).tqarg((double)i/(double)o));
if (factor<=1)
factor=1;
else if (factor>3)
factor=3;
}
return (factor);
}
|