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