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