Mercurial > mplayer.hg
comparison find_sub.c @ 584:9bdb59e8887d
find_sub() moved out from mplayer.c
author | arpi_esp |
---|---|
date | Mon, 23 Apr 2001 03:34:47 +0000 |
parents | |
children | 5f0d9239c5b2 |
comparison
equal
deleted
inserted
replaced
583:da08ded03883 | 584:9bdb59e8887d |
---|---|
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! | |
25 | |
26 // printf("\r---- sub changed ----\n"); | |
27 | |
28 // check next sub. | |
29 if(current_sub>=0 && current_sub+1<sub_num){ | |
30 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){ | |
31 // no sub | |
32 nosub_range_start=subtitles[current_sub].end; | |
33 nosub_range_end=subtitles[current_sub+1].start; | |
34 vo_sub=NULL; | |
35 return; | |
36 } | |
37 // next sub? | |
38 ++current_sub; | |
39 vo_sub=&subtitles[current_sub]; | |
40 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
41 } | |
42 | |
43 // printf("\r---- sub log search... ----\n"); | |
44 | |
45 // use logarithmic search: | |
46 i=0;j=sub_num-1; | |
47 // printf("Searching %d in %d..%d\n",key,subtitles[i].start,subtitles[j].end); | |
48 while(j>=i){ | |
49 current_sub=(i+j+1)/2; | |
50 vo_sub=&subtitles[current_sub]; | |
51 if(key<vo_sub->start) j=current_sub-1; | |
52 else if(key>vo_sub->end) i=current_sub+1; | |
53 else return; // found! | |
54 } | |
55 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
56 | |
57 // check where are we... | |
58 if(key<vo_sub->start){ | |
59 if(current_sub<=0){ | |
60 // before the first sub | |
61 nosub_range_start=key-1; // tricky | |
62 nosub_range_end=vo_sub->start; | |
63 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start); | |
64 vo_sub=NULL; | |
65 return; | |
66 } | |
67 --current_sub; | |
68 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){ | |
69 // no sub | |
70 nosub_range_start=subtitles[current_sub].end; | |
71 nosub_range_end=subtitles[current_sub+1].start; | |
72 // printf("No sub... 1 \n"); | |
73 vo_sub=NULL; | |
74 return; | |
75 } | |
76 printf("HEH???? "); | |
77 } else { | |
78 if(key<=vo_sub->end) printf("JAJJ! "); else | |
79 if(current_sub+1>=sub_num){ | |
80 // at the end? | |
81 nosub_range_start=vo_sub->end; | |
82 nosub_range_end=0x7FFFFFFF; // MAXINT | |
83 // printf("END!?\n"); | |
84 vo_sub=NULL; | |
85 return; | |
86 } else | |
87 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){ | |
88 // no sub | |
89 nosub_range_start=subtitles[current_sub].end; | |
90 nosub_range_end=subtitles[current_sub+1].start; | |
91 // printf("No sub... 2 \n"); | |
92 vo_sub=NULL; | |
93 return; | |
94 } | |
95 } | |
96 | |
97 printf("SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)vo_sub->start,(int)vo_sub->end,current_sub); | |
98 | |
99 vo_sub=NULL; // no sub here | |
100 } | |
101 |