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;
|
|
28 if(vo_sub){
|
|
29 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
|
|
30 } else {
|
|
31 if(key>nosub_range_start && key<nosub_range_end) return; // OK!
|
|
32 }
|
|
33 // sub changed!
|
1203
|
34
|
|
35 if(key<=0){
|
|
36 vo_sub=NULL; // no sub here
|
|
37 return;
|
|
38 }
|
584
|
39
|
|
40 // printf("\r---- sub changed ----\n");
|
|
41
|
|
42 // check next sub.
|
|
43 if(current_sub>=0 && current_sub+1<sub_num){
|
|
44 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
|
|
45 // no sub
|
|
46 nosub_range_start=subtitles[current_sub].end;
|
|
47 nosub_range_end=subtitles[current_sub+1].start;
|
|
48 vo_sub=NULL;
|
|
49 return;
|
|
50 }
|
|
51 // next sub?
|
|
52 ++current_sub;
|
|
53 vo_sub=&subtitles[current_sub];
|
|
54 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
|
|
55 }
|
|
56
|
|
57 // printf("\r---- sub log search... ----\n");
|
|
58
|
|
59 // use logarithmic search:
|
|
60 i=0;j=sub_num-1;
|
|
61 // printf("Searching %d in %d..%d\n",key,subtitles[i].start,subtitles[j].end);
|
|
62 while(j>=i){
|
|
63 current_sub=(i+j+1)/2;
|
|
64 vo_sub=&subtitles[current_sub];
|
|
65 if(key<vo_sub->start) j=current_sub-1;
|
|
66 else if(key>vo_sub->end) i=current_sub+1;
|
|
67 else return; // found!
|
|
68 }
|
|
69 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
|
|
70
|
|
71 // check where are we...
|
|
72 if(key<vo_sub->start){
|
|
73 if(current_sub<=0){
|
|
74 // before the first sub
|
|
75 nosub_range_start=key-1; // tricky
|
|
76 nosub_range_end=vo_sub->start;
|
|
77 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start);
|
|
78 vo_sub=NULL;
|
|
79 return;
|
|
80 }
|
|
81 --current_sub;
|
|
82 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
|
|
83 // no sub
|
|
84 nosub_range_start=subtitles[current_sub].end;
|
|
85 nosub_range_end=subtitles[current_sub+1].start;
|
|
86 // printf("No sub... 1 \n");
|
|
87 vo_sub=NULL;
|
|
88 return;
|
|
89 }
|
|
90 printf("HEH???? ");
|
|
91 } else {
|
|
92 if(key<=vo_sub->end) printf("JAJJ! "); else
|
|
93 if(current_sub+1>=sub_num){
|
|
94 // at the end?
|
|
95 nosub_range_start=vo_sub->end;
|
|
96 nosub_range_end=0x7FFFFFFF; // MAXINT
|
|
97 // printf("END!?\n");
|
|
98 vo_sub=NULL;
|
|
99 return;
|
|
100 } else
|
|
101 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
|
|
102 // no sub
|
|
103 nosub_range_start=subtitles[current_sub].end;
|
|
104 nosub_range_end=subtitles[current_sub+1].start;
|
|
105 // printf("No sub... 2 \n");
|
|
106 vo_sub=NULL;
|
|
107 return;
|
|
108 }
|
|
109 }
|
|
110
|
|
111 printf("SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)vo_sub->start,(int)vo_sub->end,current_sub);
|
|
112
|
|
113 vo_sub=NULL; // no sub here
|
|
114 }
|
|
115
|
1422
|
116 #endif
|