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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
|
/**************************************************************************
* 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 "k9dvd.h"
#include "k9dvdtitle.h"
#include "k9dvdtitleset.h"
#include "k9cellcopylist.h"
#include "k9dvdprogress.h"
#include "k9ifo2.h"
#include <tqapplication.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <sys/stat.h>
#include "k9dvd.moc"
k9DVDTitle* k9DVD::gettitle(int num) {
return ((k9DVDTitle*)m_titles.at(num));
}
k9DVDTitle* k9DVD::gettitleByNum(int num) {
int j=-1;
for (uint i=0; i < m_titles.count();i++) {
k9DVDTitle *track=(k9DVDTitle*)m_titles.at(i);
if (track->getIndexed()) {
j++;
if (j==num)
return track;
}
}
return (NULL);
}
/** Read property of int longestTitle. */
k9DVDTitle *k9DVD::getlongestTitle() {
return m_longestTitle;
}
/** Read property of TQString title. */
const TQString& k9DVD::getDVDTitle() {
return m_title;
}
void k9DVD::setDVDTitle(const TQString &_newVal) {
m_title=_newVal;
}
/** Read property of int titleCount. */
const int& k9DVD::gettitleCount() {
return m_titleCount;
}
/** Read property of int titlesetCount. */
const int& k9DVD::gettitlesetCount() {
return m_titlesetCount;
}
k9DVDTitleset *k9DVD::gettitleset(int num) {
return m_titlesets.at(num);
}
int k9DVD::getmenuSize() {
return m_menuSize;
}
k9DVD::k9DVD(TQObject *parent, const char *name,const TQStringList args) {
m_error=false;
m_opened=false;
m_titles.setAutoDelete(true);
m_titlesets.setAutoDelete(true);
m_lvideoFormat.append("NTSC");
m_lvideoFormat.append("PAL");
m_laspectRatio.append("4:3");
m_laspectRatio.append("16:9");
m_laspectRatio.append("?:?");
m_laspectRatio.append("16:9");
m_lquantization.append("16bps");
m_lquantization.append("20bps");
m_lquantization.append("24bps");
m_lquantization.append("drc");
m_lmpegVersion.append("mpeg1");
m_lmpegVersion.append("mpeg2");
m_lvideoHeight.append("480");
m_lvideoHeight.append("576");
m_lvideoHeight.append("???");
m_lvideoHeight.append("576");
m_lvideoWidth.append("720");
m_lvideoWidth.append("704");
m_lvideoWidth.append("352");
m_lvideoWidth.append("352");
m_lpermittedDf.append("");
m_lpermittedDf.append("noletterbox");
m_lpermittedDf.append("nopanscan");
m_lpermittedDf.append("noletterbox & nopanscan");
m_laudioFormat.append("ac3");
m_laudioFormat.append("?");
m_laudioFormat.append("mp2");
m_laudioFormat.append("mp2");
m_laudioFormat.append("pcm");
m_laudioFormat.append("sdds");
m_laudioFormat.append("dts");
m_lsampleFreq.append("48kHz");
m_lsampleFreq.append("48kHz");
m_laudioType.append("");
m_laudioType.append("Normal");
m_laudioType.append(i18n("for visually impaired"));
m_laudioType.append(i18n("director's comments"));
m_laudioType.append(i18n("alternate director's comments"));
m_lsubpType.append("");
m_lsubpType.append("Normal");
m_lsubpType.append(i18n("Large"));
m_lsubpType.append(i18n("Children"));
m_lsubpType.append(i18n("reserved"));
m_lsubpType.append(i18n("Normal captions"));
m_lsubpType.append(i18n("Large captions"));
m_lsubpType.append(i18n("Children captions"));
m_lsubpType.append("");
m_lsubpType.append(i18n("Forced"));
m_lsubpType.append(i18n("reserved"));
m_lsubpType.append(i18n("reserved"));
m_lsubpType.append(i18n("reserved"));
m_lsubpType.append(i18n("Director's comments"));
m_lsubpType.append(i18n("Large director's comments"));
m_lsubpType.append(i18n("Director's comments for children"));
m_frames_per_s[0]=-1.0;
m_frames_per_s[1]=25.00;
m_frames_per_s[2]=-1.0;
m_frames_per_s[3]=29.97;
m_start=NULL;
}
k9DVD::~k9DVD() {
if (m_dvd.opened())
m_dvd.close();
}
int k9DVD::dvdtime2msec(dvd_time_t *dt) {
double fps = m_frames_per_s[(dt->frame_u & 0xc0) >> 6];
long ms;
ms = (((dt->hour & 0xf0) >> 3) * 5 + (dt->hour & 0x0f)) * 3600000;
ms += (((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f)) * 60000;
ms += (((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f)) * 1000;
if(fps > 0)
ms +=(long)( ((dt->frame_u & 0x30) >> 3) * 5 + (dt->frame_u & 0x0f) * 1000.0 / fps);
return ms;
}
/*
* The following method is based on code from vobcopy, by Robos, with thanks.
*/
int k9DVD::get_title_name(const char* dvd_device, char* title) {
FILE *filehandle = 0;
int i;
TQString c;
if (! (filehandle = fopen(dvd_device, "r"))) {
c=i18n("Couldn't open %1 for title\n").arg(dvd_device);
// setError(c );
strcpy(title, i18n("unknown").latin1());
return -1;
}
if ( fseek(filehandle, 32808, SEEK_SET )) {
fclose(filehandle);
c=i18n("Couldn't seek in %1 for title\n").arg( dvd_device);
setError(c);
strcpy(title, i18n("unknown").latin1());
return -1;
}
if ( 32 != (i = fread(title, 1, 32, filehandle)) ) {
fclose(filehandle);
// c=tr2i18n("Couldn't read enough bytes for title.\n");
// setError(c);
strcpy(title, i18n("unknown").latin1());
return 0;
}
fclose (filehandle);
title[32] = '\0';
while(i-- > 2)
if(title[i] == ' ')
title[i] = '\0';
return 0;
}
TQString k9DVD::lang_name(const TQString& code,const TQString & name) {
TQString c;
int i=0;
lng arrLng[] = {
{ " ", i18n("Not Specified") }, { "aa", i18n("Afar") }, { "ab", i18n("Abkhazian") }, { "af", i18n("Afrikaans") }, { "am", i18n("Amharic")},
{ "ar", i18n("Arabic") }, { "as", i18n("Assamese") }, { "ay", i18n("Aymara") }, { "az", i18n("Azerbaijani") }, { "ba", i18n("Bashkir") },
{ "be", i18n("Byelorussian") }, { "bg", i18n("Bulgarian") }, { "bh", i18n("Bihari") }, { "bi", i18n("Bislama") }, { "bn", i18n("Bengali; Bangla") },
{ "bo", i18n("Tibetan") }, { "br", i18n("Breton") }, { "ca", i18n("Catalan") }, { "co", i18n("Corsican") }, { "cs", i18n("Czech") },
{ "cy", i18n("Welsh") }, { "da", i18n("Dansk") }, { "de", i18n("Deutsch") }, { "dz", i18n("Bhutani") }, { "el", i18n("Greek") }, { "en", i18n("English") },
{ "eo", i18n("Esperanto") }, { "es", i18n("Espanol") }, { "et", i18n("Estonian") }, { "eu", i18n("Basque") }, { "fa", i18n("Persian") },
{ "fi", i18n("Suomi") }, { "fj", i18n("Fiji") }, { "fo", i18n("Faroese") }, { "fr", i18n("Francais") }, { "fy", i18n("Frisian") }, { "ga", i18n("Gaelic") },
{ "gd", i18n("Scots Gaelic") }, { "gl", i18n("Galician") }, { "gn", i18n("Guarani") }, { "gu", i18n("Gujarati") }, { "ha", i18n("Hausa") },
{ "he", i18n("Hebrew") }, { "hi", i18n("Hindi") }, { "hr", i18n("Hrvatski") }, { "hu", i18n("Magyar") }, { "hy", i18n("Armenian") },
{ "ia", i18n("Interlingua") }, { "id", i18n("Indonesian") }, { "ie", i18n("Interlingue") }, { "ik", i18n("Inupiak") }, { "in", i18n("Indonesian") },
{ "is", i18n("Islenska") }, { "it", i18n("Italiano") }, { "iu", i18n("Inuktitut") }, { "iw", i18n("Hebrew") }, { "ja", i18n("Japanese") },
{ "ji", i18n("Yiddish") }, { "jw", i18n("Javanese") }, { "ka", i18n("Georgian") }, { "kk", i18n("Kazakh") }, { "kl", i18n("Greenlandic") },
{ "km", i18n("Cambodian") }, { "kn", i18n("Kannada") }, { "ko", i18n("Korean") }, { "ks", i18n("Kashmiri") }, { "ku", i18n("Kurdish") },
{ "ky", i18n("Kirghiz") }, { "la", i18n("Latin") }, { "ln", i18n("Lingala") }, { "lo", i18n("Laothian") }, { "lt", i18n("Lithuanian") },
{ "lv", i18n("Latvian, Lettish") }, { "mg", i18n("Malagasy") }, { "mi", i18n("Maori") }, { "mk", i18n("Macedonian") }, { "ml", i18n("Malayalam") },
{ "mn", i18n("Mongolian") }, { "mo", i18n("Moldavian") }, { "mr", i18n("Marathi") }, { "ms", i18n("Malay") }, { "mt", i18n("Maltese") },
{ "my", i18n("Burmese") }, { "na", i18n("Nauru") }, { "ne", i18n("Nepali") }, { "nl", i18n("Nederlands") }, { "no", i18n("Norsk") }, { "oc", i18n("Occitan") },
{ "om", i18n("Oromo") }, { "or", i18n("Oriya") }, { "pa", i18n("Punjabi") }, { "pl", i18n("Polish") }, { "ps", i18n("Pashto, Pushto") },
{ "pt", i18n("Portugues") }, { "qu", i18n("Quechua") }, { "rm", i18n("Rhaeto-Romance") }, { "rn", i18n("Kirundi") }, { "ro", i18n("Romanian") },
{ "ru", i18n("Russian") }, { "rw", i18n("Kinyarwanda") }, { "sa", i18n("Sanskrit") }, { "sd", i18n("Sindhi") }, { "sg", i18n("Sangho") },
{ "sh", i18n("Serbo-Croatian") }, { "si", i18n("Sinhalese") }, { "sk", i18n("Slovak") }, { "sl", i18n("Slovenian") }, { "sm",i18n( "Samoan") },
{ "sn", i18n("Shona") }, { "so", i18n("Somali") }, { "sq", i18n("Albanian") }, { "sr", i18n("Serbian") }, { "ss", i18n("Siswati") },
{ "st", i18n("Sesotho") }, { "su", i18n("Sundanese") }, { "sv", i18n("Svenska") }, { "sw", i18n("Swahili") }, { "ta", i18n("Tamil") },
{ "te", i18n("Telugu") }, { "tg", i18n("Tajik") }, { "th", i18n("Thai") }, { "ti", i18n("Tigrinya") }, { "tk", i18n("Turkmen") }, { "tl", i18n("Tagalog") },
{ "tn", i18n("Setswana") }, { "to", i18n("Tonga") }, { "tr", i18n("Turkish") }, { "ts", i18n("Tsonga") }, { "tt", i18n("Tatar") }, { "tw", i18n("Twi") },
{ "ug", i18n("Uighur") }, { "uk", i18n("Ukrainian") }, { "ur", i18n("Urdu") }, { "uz", i18n("Uzbek") }, { "vi", i18n("Vietnamese") },
{ "vo", i18n("Volapuk") }, { "wo", i18n("Wolof") }, { "xh", i18n("Xhosa") }, { "yi", i18n("Yiddish") }, { "yo", i18n("Yoruba") }, { "za", i18n("Zhuang") },
{ "zh", i18n("Chinese") }, { "zu", i18n("Zulu") }, { "xx", i18n("Unknown") }, { "\0", i18n("Unknown") } };
c=i18n("Unknown");
for (i=0 ; arrLng[i].code[0]!=0;i++) {
lng l =arrLng[i];
if (name=="") {
if (strcmp(code.latin1(),l.code)==0) {
c = l.name;
}
} else {
if (strcmp(name.latin1(),l.name)==0) {
c = l.code;
}
}
}
return c;
}
int k9DVD::calcNumTitle(ifo_handle_t *ifo,int _vts,int _ttn) {
for (int i=0; i< ifo->tt_srpt->nr_of_srpts;i++) {
if (ifo->tt_srpt->title[i].title_set_nr==_vts && ifo->tt_srpt->title[i].vts_ttn == _ttn)
return (i+1);
}
return 0;
}
int k9DVD::scandvd (const TQString & device,bool _quickScan) {
char ctitle[255];
k9DVDChapter::setcptChapter(0);
ifo_handle_t *ifo_zero, *ifo;
pgcit_t *vts_pgcit;
vtsi_mat_t *vtsi_mat;
vmgi_mat_t *vmgi_mat;
audio_attr_t *audio_attr;
video_attr_t *video_attr;
subp_attr_t *subp_attr;
pgc_t *pgc;
int i, j, ltitles, cell, vts_ttn, title_set_nr;
char lang_code[3];
int has_title = 0;
int max_length = 0;
bool ok;
tt_srpt_t *tt_srpt;
TQString txt,c;
m_start=NULL;
int menuSizes[100];
for ( j=0; j<100;j++)
menuSizes[j]=0;
m_titles.clear();
m_Device=device;
m_error=false;
m_errMsg="";
if (!_quickScan) {
m_progressDlg= new k9DVDProgress(tqApp->mainWidget(),"progress",true);
m_progressDlg->setpbTitleStep(0);
m_progressDlg->setpbTotalStep(0);
connect(this, TQT_SIGNAL(sigVobProgress(unsigned int,unsigned int)), this, TQT_SLOT(slotVobProgress(unsigned int,unsigned int)));
connect(this, TQT_SIGNAL(sigTitleProgress(unsigned int,unsigned int)), this, TQT_SLOT(slotTitleProgress(unsigned int,unsigned int)));
connect(this, TQT_SIGNAL(sigTitleText(TQString&)), this, TQT_SLOT(slotTitleText(TQString&)));
connect(this, TQT_SIGNAL(sigTotalText(TQString&)), this, TQT_SLOT(slotTotalText(TQString&)));
m_progressDlg->show();
} else
m_progressDlg=NULL;
tqApp->processEvents();
k9DVDTitle *l_track;
k9DVDAudioStream *l_auds;
k9DVDChapter *l_chap;
k9DVDSubtitle *l_sub;
TQString sh,sm,ss;
/*
ret = stat(device.latin1(), &dvd_stat);
if ( ret < 0 ) {
c=i18n("Can't find device %1\n").arg( device);
setError(c);
return 1;
}
*/
if (m_dvd.opened())
m_dvd.close();
m_dvd.openDevice(device);
if( !m_dvd.opened() ) {
c=i18n("Can't open disc %1!\n").arg(device);
setError(c);
return 2;
}
// k9Ifo2 kifo_zero(&m_dvd),kifo(&m_dvd);
// kifo_zero.openIFO( 0);
k9Ifo2 *kifo_zero= m_dvd.getIfo(0);
k9Ifo2 *kifo;
ifo_zero = kifo_zero->getIFO();
if ( !ifo_zero ) {
c=tr2i18n("Can't open main ifo!\n");
setError(c);
return 3;
}
ltitles = ifo_zero->tt_srpt->nr_of_srpts;
m_titleCount = 0;
has_title = get_title_name(device.utf8(), ctitle);
vmgi_mat = ifo_zero->vmgi_mat;
m_titlesetCount = vmgi_mat->vmg_nr_of_title_sets;
menuSizes[0]=vmgi_mat->vmg_last_sector;
m_title=( has_title ? tr2i18n("unknown") : ctitle);
for (int ts=1;ts <=m_titlesetCount;ts++) {
tt_srpt = ifo_zero->tt_srpt;
kifo=m_dvd.getIfo(ts);
ifo = kifo->getIFO();
if (ifo==NULL)
continue;
//add the titleset in the titleset list
k9DVDTitleset *titleset = new k9DVDTitleset(ts,ifo->vtsi_mat->vts_last_sector -ifo->vtsi_mat->vtstt_vobs-1);
m_titlesets.append(titleset);
for (j=0; j < ifo->vts_pgcit->nr_of_pgci_srp; j++) {
// tt_srpt->title[j].title_set_nr);
// GENERAL
vtsi_mat = ifo->vtsi_mat;
vts_pgcit = ifo->vts_pgcit;
pgc = vts_pgcit->pgci_srp[j].pgc;
//retrieve the ttn
int ttn=(vts_pgcit->pgci_srp[j].entry_id) & 0x7F;
bool entryPgc= (vts_pgcit->pgci_srp[j].entry_id & 0x80)==0x80;
int numTitle=calcNumTitle(ifo_zero,ts,ttn);
//JMP : vérifier la numérotation des titres ......
if (vtsi_mat && (pgc->nr_of_cells >0)) {
m_titleCount++;
vts_ttn = ttn;//ifo->vts_ptt_srpt->title[j].ptt[0].pgcn; //ifo_zero->tt_srpt->title[j].vts_ttn;
//JMPtxt=i18n("Title %1").arg(indexedCount);
txt=i18n("Title %1").arg(numTitle);
emit sigTotalText (txt);
emit sigTitleProgress(numTitle,ltitles);
video_attr = &vtsi_mat->vts_video_attr;
vmgi_mat = ifo_zero->vmgi_mat;
title_set_nr = ts; //ifo_zero->tt_srpt->title[j].title_set_nr;
menuSizes[title_set_nr]=vtsi_mat->vtstt_vobs + vtsi_mat->vtsi_last_sector +1;
//vts_pgcit->pgci_srp[ifo->vts_ptt_srpt->title[vts_ttn - 1].ptt[0].pgcn - 1].pgc;
int titleStartSector=pgc->cell_playback[0].first_sector;
//l_track=addTitle(j+1,title_set_nr,ifo->vts_ptt_srpt->title[vts_ttn - 1].ptt[0].pgcn - 1,titleStartSector,isTitleIndex(ifo_zero,ts,vts_ttn));
l_track=addTitle(titleset,m_titleCount, numTitle,title_set_nr,j,titleStartSector, entryPgc);
titleset->add
(l_track);
sh.sprintf("%02x",pgc->playback_time.hour);
sm.sprintf("%02x",pgc->playback_time.minute);
ss.sprintf("%02x",pgc->playback_time.second);
l_track->length.setHMS(sh.toInt(&ok,10),sm.toInt(&ok,10),ss.toInt(&ok,10));
//printf(tr2i18n("Title: %02d, Length: %02x:%02x:%02x "), j+1, pgc->playback_time.hour, pgc->playback_time.minute, pgc->playback_time.second);
if (dvdtime2msec(&pgc->playback_time) > max_length && entryPgc) {
max_length = dvdtime2msec(&pgc->playback_time);
m_longestTitle = l_track;
}
l_track->chapterCount = pgc->nr_of_programs;// ifo_zero->tt_srpt->title[j].nr_of_ptts;
l_track->audioStreamCount = vtsi_mat->nr_of_vts_audio_streams;
l_track->subPictureCount = vtsi_mat->nr_of_vts_subp_streams;
l_track->VTS = ts;// ifo_zero->tt_srpt->title[j].title_set_nr;
l_track->TTN = ttn; // ifo_zero->tt_srpt->title[j].vts_ttn;
l_track->FPS = m_frames_per_s[(pgc->playback_time.frame_u & 0xc0) >> 6];
l_track->format= (*m_lvideoFormat.at(video_attr->video_format));
m_format = l_track->format;
/* TQStringList::Iterator it;
it= videoFormat.at(video_attr->video_format);
c= (*it).latin1();
*/
l_track->aspectRatio = (*m_laspectRatio.at(video_attr->display_aspect_ratio));
l_track->width = (*m_lvideoWidth.at(video_attr->picture_size));
;
l_track->height = (*m_lvideoHeight.at(video_attr->video_format));
l_track->DF = (*m_lpermittedDf.at(video_attr->permitted_df));
for (i=0; i<16; i++) {
TQString pal;
pal.sprintf("%08x",pgc->palette[i]);
l_track->palette.append(pal);
}
// ANGLES
l_track->angleCount = ifo_zero->tt_srpt->title[j].nr_of_angles;
// AUDIO
// for (i=0; i<vtsi_mat->nr_of_vts_audio_streams; i++) {
l_track->audioStreamCount=0;
for (i=0; i<vtsi_mat->nr_of_vts_audio_streams; i++) {
if (pgc->audio_control[i]>>8 !=0) {
l_track->audioStreamCount++;
l_auds=l_track->addAudioStream();
l_auds->id = 1+ ((pgc->audio_control[i]>>8) & 0x7) ;
//this only true for AC3 streams
l_auds->m_streamId = (pgc->audio_control[i]>>8);
audio_attr = &vtsi_mat->vts_audio_attr[i];
//dts stream starts at 0x88
if (audio_attr->audio_format==6)
l_auds->m_streamId +=8;
//JMPaudio_attr = &vtsi_mat->vts_audio_attr[l_auds->id-1];
snprintf(lang_code,3, "%c%c", audio_attr->lang_code>>8, audio_attr->lang_code & 0xff);
if (!lang_code[0]) {
lang_code[0] = 'x';
lang_code[1] = 'x';
}
l_auds->langCod=lang_code;
l_auds->language=lang_name(l_auds->langCod,"");
if (l_auds->language==i18n("Unknown"))
l_auds->langCod="xx";
l_auds->format= (*m_laudioFormat.at(audio_attr->audio_format));
l_auds->frequency = (*m_lsampleFreq.at(audio_attr->sample_frequency));
l_auds->quantization = (*m_lquantization.at(audio_attr->quantization));
l_auds->channels = audio_attr->channels+1;
l_auds->appMode = audio_attr->application_mode;
l_auds->content = (*m_laudioType.at(audio_attr->code_extension));
//if (((pgc->audio_control[i]>>8) & 0x80) ==0x80) {
//} else {
// l_auds->id=1;
//}
}
}
l_track->m_defAudio=NULL;
l_track->m_defSubtitle=NULL;
// CHAPTERS
cell = 0;
unsigned long total_sectors = 0;
l_track->chapterCount= pgc->nr_of_programs;
for (i=0;i < l_track->chapterCount;i++)
l_track->addChapter(i+1);
k9DVDChapter *l_pchap=NULL;
for (i=0; i<pgc->nr_of_programs; i++) {
int second=0, minute=0, hour=0, tmp;
char hex[3];
int next = pgc->program_map[i+1];
unsigned long sectors = 0;
l_chap = l_track->getChapter(i);
//first sector
l_chap->startSector=pgc->cell_playback[cell].first_sector;
;
l_chap->endSector=0;
if (i == pgc->nr_of_programs - 1)
next = pgc->nr_of_cells + 1;
int iangleStart=-1,iangleEnd=-1;
while (cell < next - 1) {
//using c2 otherwise the value of cell were lost
//int c2=cell;
//l_chap->cells.append(c2);
int startSect=pgc->cell_playback[cell].first_sector;
l_chap->startSectors.append(startSect);
snprintf(hex,3, "%02x", pgc->cell_playback[cell].playback_time.second);
tmp = second + atoi(hex);
minute = minute + (tmp / 60);
second = tmp % 60;
snprintf(hex,3, "%02x", pgc->cell_playback[cell].playback_time.minute);
tmp = minute + atoi(hex);
hour = hour + (tmp / 60);
minute = tmp % 60;
l_chap->endSector= pgc->cell_playback[cell].last_sector;
//last sector
/* Check if we're entering an angle block. (vamp_play-title) */
int cell2=cell;
if ( pgc->cell_playback[ cell ].block_type
== BLOCK_TYPE_ANGLE_BLOCK && cell>iangleEnd ) {
iangleStart=cell;
for( int idc = 0;; ++idc ) {
k9ChapterCell * chapterCell=new k9ChapterCell(cell2+idc,idc+1);
l_chap->cells.append(chapterCell);
chapterCell->setstartSector(pgc->cell_playback[cell2+idc].first_sector);
chapterCell->setlastSector(pgc->cell_playback[cell2+idc].last_sector);
if (idc==0)
chapterCell->setangleBlock(angleStart);
else
chapterCell->setangleBlock(angleInside);
if( pgc->cell_playback[ cell2 + idc ].block_mode
== BLOCK_MODE_LAST_CELL ) {
iangleEnd=cell2+idc;
chapterCell->setangleBlock(angleEnd);
sectors += pgc->cell_playback[iangleEnd].last_sector - pgc->cell_playback[iangleStart].first_sector + 1;
break;
}
}
} else {
if (!(cell>=iangleStart && cell <=iangleEnd)) {
k9ChapterCell * chapterCell=new k9ChapterCell(cell,1);
l_chap->cells.append(chapterCell);
chapterCell->setstartSector(pgc->cell_playback[cell].first_sector);
chapterCell->setlastSector(pgc->cell_playback[cell].last_sector);
sectors += pgc->cell_playback[cell].last_sector - pgc->cell_playback[cell].first_sector + 1;
}
}
cell++;
}
l_track->vobusize_mb += calcVobuSize(ifo,l_chap);
total_sectors += sectors;
l_chap->length.setHMS(hour,minute,second);
l_chap->sectors=sectors;
if (l_pchap!=NULL) {
TQTime t;
int position;
t.setHMS(0,0,0);
position=t.secsTo(l_chap->length);
t=l_pchap->time.addSecs(position);
l_chap->time=t;
}
l_pchap=l_chap;
}
l_track->size_mb =((float)total_sectors *2048)/(1024*1024);
l_track->m_sectors= total_sectors;
// SUBTITLES
l_track->subPictureCount=0;
for (i=0; i<vtsi_mat->nr_of_vts_subp_streams; i++) {
if (pgc->subp_control[i]>>24 !=0) {
l_sub=l_track->addSubtitle(i+1);
unsigned char subpc;
subpc=pgc->subp_control[i]>>24;
if ((subpc & 0x80)==0x80) {
if (l_track->aspectRatio=="4:3") {
l_sub->id.append(1+ (subpc & 0x1F));
} else {
subpc=(pgc->subp_control[i]>>16) & 0x1F;
l_sub->id.append(1+ subpc);
subpc=(pgc->subp_control[i]>>8) & 0x1F;
if (! l_sub->id.contains(1+ subpc) && ! l_track->DF.contains("noletterbox"))
l_sub->id.append(1+ subpc);
subpc=pgc->subp_control[i] & 0x1F;
if (! l_sub->id.contains(1+ subpc) && ! l_track->DF.contains("nopanscan"))
l_sub->id.append(1+ subpc);
}
kdDebug() << "VTS: " << l_track->VTS << " TTN: " << l_track->TTN << \
" Subtitle " << i+1 << ": " << l_sub->id << " " << l_sub->language << \
" " << l_sub->content << endl;
}
l_track->subPictureCount++;
subp_attr = &vtsi_mat->vts_subp_attr[i];
snprintf(lang_code,3, "%c%c", subp_attr->lang_code>>8, subp_attr->lang_code & 0xff);
if (!lang_code[0]) {
lang_code[0] = 'x';
lang_code[1] = 'x';
}
//JMP : l_sub->setselected(!titleIndexed);
l_sub->langCod=lang_code;
l_sub->language=lang_name(lang_code,"");
l_sub->content= (*m_lsubpType.at(subp_attr->code_extension));
}
}
if (entryPgc && !_quickScan)
calcStreamSize(*l_track);
}
}
//kifo.closeIFO();
}
m_menuSize=0;
for (j=0;j<100;j++)
m_menuSize+=menuSizes[j];
//kifo_zero.closeIFO();
if (!_quickScan)
delete m_progressDlg;
m_progressDlg=0;
m_opened=true;
//m_dvd.close();
return 0;
}
float k9DVD::calcVobuSize(ifo_handle_t *_ifo,k9DVDChapter *_chapter) {
vobu_admap_t * vobu_admap = _ifo->vts_vobu_admap;
int length = vobu_admap->last_byte + 1 - VOBU_ADMAP_SIZE;
float total=0;
for(uint32_t i = 0; i < length/sizeof(uint32_t); i++) {
if(vobu_admap->vobu_start_sectors[i] >= _chapter->startSector
&&vobu_admap->vobu_start_sectors[i] <= _chapter->endSector)
total++;
}
total=total*2048;
total=total/(1024*1024);
return total;
}
/** Adds a new track in the titles list the list is sorted by VTS and pgc*/
k9DVDTitle* k9DVD::addTitle(k9DVDTitleset *_titleset,int id,int num,int _VTS,int _pgc,uint32_t _startSector,bool _indexed) {
k9DVDTitle *track,*tmp;
track = new k9DVDTitle;
track->numTitle=num;
track->indexed=_indexed;
track->id=id;
track->m_titleset=_titleset;
//JMP : modification
track->forceSelection = false; // !_indexed;
track->ts_nr=_VTS;
track->pgc=_pgc;
bool bappend=true;
for (uint i=0;i<m_titles.count();i++) {
tmp=(k9DVDTitle*)m_titles.at(i);
k9DVDChapter *chap =tmp->getChapter(0);
if (tmp->ts_nr >_VTS) {
bappend=false;
} else if ( (tmp->ts_nr==_VTS) && ((tmp->pgc >_pgc) || (chap->getstartSector() > _startSector)) ) {
bappend=false;
}
if (!bappend) {
m_titles.insert(i,track);
break;
}
}
if (bappend)
m_titles.append(track);
track->name=i18n("Title %1").arg(num);
if (!_indexed) {
for (uint i=0;i<m_titles.count();i++) {
tmp=(k9DVDTitle*)m_titles.at(i);
if (tmp->numTitle==num && tmp->indexed)
tmp->m_titles.append(track);
}
}
return(track);
}
void k9DVD::calcStreamSize(k9DVDTitle & track) {
struct stream_counter streams[64];
int stream_count;
int start = 0;
int stop = 0;
k9DVDChapter *c_start,*c_stop;
struct streamSize streamList[64];
int c, x;
TQString pg;
for( x=0 ; x<64 ; x++ ) { // init stream usage list
streams[x].id = 0;
streams[x].count = 0;
streams[x].size_mb = 0;
streams[x].percent = 0;
streamList[x].id=0;
streamList[x].percent=0;
streamList[x].size_mb=0;
}
x = 0;
c = 0;
if( track.chapterCount == 2 ) { // select which chapters to probe for stream sizes
start=0;
stop=1;
}
if (track.chapterCount == 1) {
start=0;
stop=0;
}
if (track.chapterCount >2) {
start=0;
stop=(int)(track.chapterCount-1);
}
c_start=(k9DVDChapter*)track.chapters.at(start);
c_stop=(k9DVDChapter*)track.chapters.at(stop);
pg=tr2i18n("reading title");
emit sigTitleText(pg);
//probe stream usage
c = stream_vob( track.ts_nr,c_start->startSector, c_stop->endSector, streams);
for( x=0 ; x<64 ; x++ ) {
if( streams[x].id == 0 )
break;
streams[x].percent = (float)streams[x].count / (float)(c / 100.); // calc usage in percent
}
// create streamlist with all streams
stream_count=0;
for( c=0 ; c<64 ; c++ ) {
if( streams[c].id == 0 )
break;
streamList[stream_count].id = streams[c].id;
if( stream_count >= 64 )
break;
stream_count++;
x++;
}
// other_streams_mb = 0; // calc size of all selected streams
for( x=0 ; x<stream_count ; x++ ) {
for( c=0 ; c<64 ; c++ ) {
if( streamList[x].id == streams[c].id ) {
streamList[x].percent=streams[c].percent;
streamList[x].size_mb= (float) ((track.size_mb / 100.) * streams[c].percent);
}
}
}
k9DVDAudioStream *l_auds;
k9DVDSubtitle *l_sub;
k9DVDTitle *l_track;
int i;
l_track=&track;
for (x=0;x<64;x++) {
if (streamList[x].id==0)
break;
if (streamList[x].id== 0xe0)
l_track->videosize_mb = streamList[x].size_mb;
}
for (i=0;i<l_track->audioStreamCount;i++) {
l_auds=(k9DVDAudioStream*)l_track->audioStreams.at(i);
for (x=0;x<64;x++) {
if (streamList[x].id==0)
break;
int id=streamList[x].id;
if (( (id >=0x80) && (id <=0x8f)) || ((id >=0xa0) && (id <=0xa7)) || ((id >=0xc0) && (id <=0xdf))) {
if ( getVampsID(id) == l_auds->id) {
l_auds->size_mb = streamList[x].size_mb;
//stop the loop, go to next audio stream
break;
}
}
}
}
for (i=0;i<l_track->subPictureCount;i++) {
l_sub=(k9DVDSubtitle*)l_track->subtitles.at(i);
for (x=0;x<64;x++) {
if (streamList[x].id==0)
break;
int id=streamList[x].id;
if ( (id >=0x20) && (id <=0x3f)) {
if ( l_sub->id.contains(id - 0x20 +1) ) {
l_sub->size_mb = streamList[x].size_mb;
break;
}
}
}
}
}
int k9DVD::identify_stream( unsigned char *buffer ) {
uint8_t packet_type = buffer[17];
if( (packet_type >= 0xE0) && (packet_type <= 0xEF) ) { // video streams
;
} else if( packet_type == 0xBB ) { // system header
;
} else if( packet_type == 0xBE ) { // padding
;
} else if( packet_type == 0xBF ) { // nav pack
;
} else if( (packet_type >= 0xC0) && (packet_type <= 0xDF) ) { // mpeg audio
;
} else if( packet_type == 0xBD ) { // private stream, check content
packet_type = buffer[23+buffer[22]];
}
return packet_type;
}
long k9DVD::stream_vob( int title, unsigned long startblock, unsigned long lastblock, struct stream_counter *sc) {
k9DVDFile *dvdfile;
//JMP unsigned char buffer[DVD_VIDEO_LB_LEN];
unsigned char buffer[DVD_VIDEO_LB_LEN*800];
unsigned char *ptrbuff;
int blocksize=800,y;
int step=(int)((lastblock-startblock)/800) / 10;// * 0.05;
if (step==0)
step=1;
unsigned char stream_id;
long total=0;
unsigned long i, x ,nbread=0;
ssize_t size;
TQString c;
dvdfile =m_dvd.openTitle( title);
if( !dvdfile ) {
c=i18n("Error opening vobs for title %1\n").arg( title);
setError(c);
return 0;
}
i = startblock;
while( (i >= startblock) && (i <= lastblock) && (blocksize>0)) { // read blocks
size= dvdfile->readBlocks( i,blocksize , buffer);
emit sigVobProgress(i-startblock,lastblock-startblock);
total+=size;
if( !size ) {
c=i18n("ERROR reading block %1\n").arg(i);
setError(c);
break;
}
ptrbuff=buffer;
for (y=0;y<blocksize;y++) {
stream_id = identify_stream(ptrbuff); // get stream id
nbread++;
for( x=0 ; x<64 ; x++ ) { // scan for already present counter
if( sc[x].id != 0 ) {
if( stream_id != sc[x].id ) {
continue;
}
}
sc[x].id = stream_id; // increase stream packet counter
sc[x].count++;
break;
}
ptrbuff+=DVD_VIDEO_LB_LEN;
}
i+=blocksize*step;// 6;
if (i+blocksize> lastblock)
blocksize=lastblock-i;
}
dvdfile->close();
return total;
}
uint64_t k9DVD::getsizeSelected(bool _streams) {
uint64_t selstreams=0,vidstreams=0;
int i,x;
k9DVDTitle *l_track;
k9DVDAudioStream *l_auds;
k9DVDSubtitle *l_sub;
bool withvideo;
for (i=0;i<m_titleCount;i++) {
l_track=gettitle(i);
withvideo=l_track->isSelected() && l_track->getIndexed();
if ( withvideo) {
vidstreams +=l_track->getsectors();
if (_streams) {
for (x=0;x<l_track->audioStreamCount;x++) {
l_auds=l_track->getaudioStream(x);
if (!l_auds->selected)
selstreams += l_auds->size_mb*512;
}
for (x=0;x<l_track->subPictureCount;x++) {
l_sub=l_track->getsubtitle(x);
if (!l_sub->selected)
selstreams += l_sub->size_mb*512;
}
}
}
}
vidstreams -=selstreams;
return (vidstreams );
}
float k9DVD::getfactor(bool _withMenus,bool _streams,bool _useDvdAuthor) {
if (!_useDvdAuthor || _withMenus) {
//m_dvd.openDevice(Device);
k9CellCopyList *cellCopyList =new k9CellCopyList(&m_dvd,this);
double factor=cellCopyList->getfactor(_withMenus,_streams);
//m_dvd.close();
return (factor);
} else {
float selstreams=0,vidstreams=0,l_factor;
int i,x;
k9DVDTitle *l_track;
k9DVDAudioStream *l_auds;
k9DVDSubtitle *l_sub;
bool withvideo;
double forced=0,forcedsh=0;
for (i=0;i<m_titleCount;i++) {
l_track=gettitle(i);
withvideo=l_track->isSelected() && l_track->getIndexed();
if ( withvideo) {
//size_mb = size of titles - size of unselected chapters
float size_mb=l_track->gettotalsize_mb()-l_track->getChaptersSize_mb( false) ; //gettotalsize_mb does include parts of titles
vidstreams +=size_mb ;
if (l_track->getforceFactor()) {
forced+=size_mb;
forcedsh+=(size_mb/l_track->getfactor());
}
if (_streams) {
for (x=0;x<l_track->audioStreamCount;x++) {
l_auds=l_track->getaudioStream(x);
if (!l_auds->selected)
selstreams += l_auds->size_mb;
}
for (x=0;x<l_track->subPictureCount;x++) {
l_sub=l_track->getsubtitle(x);
if (!l_sub->selected)
selstreams += l_sub->size_mb;
}
}
}
}
vidstreams -=selstreams;
l_factor = ((float) vidstreams - forced) / (k9DVDSize::getMaxSize() - forcedsh);
l_factor = (int)((l_factor+0.01)*100);
l_factor /=100;
if (l_factor <1)
l_factor=1;
return(l_factor);
}
}
void k9DVD::slotVobProgress(unsigned int position,unsigned int total) {
m_progressDlg->setpbTitleStep(position);
m_progressDlg->setpbTitleTotalSteps(total);
tqApp->processEvents();
}
void k9DVD::slotTitleProgress(unsigned int position,unsigned int total) {
m_progressDlg->setpbTotalStep(position);
m_progressDlg->setpbTotalTotalSteps(total);
tqApp->processEvents();
}
void k9DVD::slotTitleText(TQString& text) {
m_progressDlg->setlblTitle(text);
tqApp->processEvents();
}
void k9DVD::slotTotalText(TQString& text) {
m_progressDlg->setlblTotal(text);
tqApp->processEvents();
}
const TQString& k9DVD::getDevice() {
return m_Device;
}
const bool& k9DVD::geterror() {
return m_error;
}
const TQString& k9DVD::geterrMsg() {
return m_errMsg;
}
void k9DVD::setError(const TQString & err) {
m_error=true;
m_errMsg=err;
if (m_progressDlg !=NULL)
m_progressDlg->hide();
}
const bool& k9DVD::getopened() {
return m_opened;
}
TQString &k9DVD::getFormat() {
return (m_format);
}
int k9DVD::getVampsID(int type) {
int abase = 0;
if (type >= 0x80 && type <= 0x87) {
// AC3 audio
abase = 0x80;
} else if (type >= 0x88 && type <= 0x8f) {
// DTS audio
abase = 0x88;
} else if (type >= 0xa0 && type <= 0xbf) {
// LPCM audio
abase = 0xa0;
} else if (type >= 0xc0 && type <= 0xdf) {
// MPEG audio
abase = 0xc0;
}
return (type-abase +1);
}
k9DVDTitle* k9DVD::getstart() {
return m_start;
}
void k9DVD::setstart(k9DVDTitle* title) {
m_start=title;
}
// returns the title number in the reauthored DVD
int k9DVD::getnewTitleNum(k9DVDTitle *title) {
int num=0;
k9DVDTitle *tr;
for (int i=0 ;i < m_titleCount;i++) {
tr=gettitle(i);
if (tr->isSelected() && tr->getIndexed()) {
++num;
if (tr->getnumTitle() == title->getnumTitle())
return(num);
}
}
return(-1);
}
void k9DVD::close() {
m_opened=false;
if (m_dvd.opened())
m_dvd.close();
m_titles.clear();
m_titlesets.clear();
}
|