584
|
1 //**************************************************************************//
|
|
2 // .SUB
|
|
3 //**************************************************************************//
|
|
4
|
|
5 #include <stdio.h>
|
|
6
|
|
7 #include "libvo/video_out.h"
|
|
8 #include "subreader.h"
|
|
9 #include "libvo/sub.h"
|
|
10
|
|
11 static int current_sub=0;
|
|
12
|
|
13 //static subtitle* subtitles=NULL;
|
|
14 static int nosub_range_start=-1;
|
|
15 static int nosub_range_end=-1;
|
|
16
|
|
17 void find_sub(subtitle* subtitles,int key){
|
|
18 int i,j;
|
|
19 if(vo_sub){
|
|
20 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
|
|
21 } else {
|
|
22 if(key>nosub_range_start && key<nosub_range_end) return; // OK!
|
|
23 }
|
|
24 // sub changed!
|
1203
|
25
|
|
26 if(key<=0){
|
|
27 vo_sub=NULL; // no sub here
|
|
28 return;
|
|
29 }
|
584
|
30
|
|
31 // printf("\r---- sub changed ----\n");
|
|
32
|
|
33 // check next sub.
|
|
34 if(current_sub>=0 && current_sub+1<sub_num){
|
|
35 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
|
|
36 // no sub
|
|
37 nosub_range_start=subtitles[current_sub].end;
|
|
38 nosub_range_end=subtitles[current_sub+1].start;
|
|
39 vo_sub=NULL;
|
|
40 return;
|
|
41 }
|
|
42 // next sub?
|
|
43 ++current_sub;
|
|
44 vo_sub=&subtitles[current_sub];
|
|
45 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
|
|
46 }
|
|
47
|
|
48 // printf("\r---- sub log search... ----\n");
|
|
49
|
|
50 // use logarithmic search:
|
|
51 i=0;j=sub_num-1;
|
|
52 // printf("Searching %d in %d..%d\n",key,subtitles[i].start,subtitles[j].end);
|
|
53 while(j>=i){
|
|
54 current_sub=(i+j+1)/2;
|
|
55 vo_sub=&subtitles[current_sub];
|
|
56 if(key<vo_sub->start) j=current_sub-1;
|
|
57 else if(key>vo_sub->end) i=current_sub+1;
|
|
58 else return; // found!
|
|
59 }
|
|
60 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
|
|
61
|
|
62 // check where are we...
|
|
63 if(key<vo_sub->start){
|
|
64 if(current_sub<=0){
|
|
65 // before the first sub
|
|
66 nosub_range_start=key-1; // tricky
|
|
67 nosub_range_end=vo_sub->start;
|
|
68 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start);
|
|
69 vo_sub=NULL;
|
|
70 return;
|
|
71 }
|
|
72 --current_sub;
|
|
73 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
|
|
74 // no sub
|
|
75 nosub_range_start=subtitles[current_sub].end;
|
|
76 nosub_range_end=subtitles[current_sub+1].start;
|
|
77 // printf("No sub... 1 \n");
|
|
78 vo_sub=NULL;
|
|
79 return;
|
|
80 }
|
|
81 printf("HEH???? ");
|
|
82 } else {
|
|
83 if(key<=vo_sub->end) printf("JAJJ! "); else
|
|
84 if(current_sub+1>=sub_num){
|
|
85 // at the end?
|
|
86 nosub_range_start=vo_sub->end;
|
|
87 nosub_range_end=0x7FFFFFFF; // MAXINT
|
|
88 // printf("END!?\n");
|
|
89 vo_sub=NULL;
|
|
90 return;
|
|
91 } else
|
|
92 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
|
|
93 // no sub
|
|
94 nosub_range_start=subtitles[current_sub].end;
|
|
95 nosub_range_end=subtitles[current_sub+1].start;
|
|
96 // printf("No sub... 2 \n");
|
|
97 vo_sub=NULL;
|
|
98 return;
|
|
99 }
|
|
100 }
|
|
101
|
|
102 printf("SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)vo_sub->start,(int)vo_sub->end,current_sub);
|
|
103
|
|
104 vo_sub=NULL; // no sub here
|
|
105 }
|
|
106
|