Mercurial > mplayer.hg
annotate find_sub.c @ 9920:cf5ae3f6175c
ffindeo3 (diff from mplayerxp-cvslog) untested
author | michael |
---|---|
date | Tue, 15 Apr 2003 20:40:11 +0000 |
parents | 09d630a4f991 |
children | a19da4c57b67 |
rev | line source |
---|---|
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" | |
2897 | 12 #include "libvo/sub.h" |
584 | 13 #include "subreader.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 | |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
21 extern float sub_delay; |
8369 | 22 extern float sub_fps; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
23 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
24 void step_sub(sub_data *subd, float pts, int movement) { |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
25 subtitle *subs; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
26 int key = (pts+sub_delay) * (subd->sub_uses_time ? 100 : sub_fps); |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
27 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
28 if (subd == NULL) return; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
29 subs = subd->subtitles; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
30 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
31 /* Tell the OSD subsystem that the OSD contents will change soon */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
32 vo_osd_changed(OSDTYPE_SUBTITLE); |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
33 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
34 /* If we are moving forward, don't count the next (current) subtitle |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
35 * if we haven't displayed it yet. Same when moving other direction. |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
36 */ |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
37 if (movement > 0 && key < subs[current_sub].start) |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
38 movement--; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
39 if (movement < 0 && key >= subs[current_sub].end) |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
40 movement++; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
41 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
42 /* Never move beyond first or last subtitle. */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
43 if (current_sub+movement < 0) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
44 movement = 0-current_sub; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
45 if (current_sub+movement >= subd->sub_num) |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
46 movement = subd->sub_num - current_sub - 1; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
47 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
48 current_sub += movement; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
49 sub_delay = subs[current_sub].start / (subd->sub_uses_time ? 100 : sub_fps) - pts; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
50 } |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
51 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
52 void find_sub(sub_data* subd,int key){ |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
53 subtitle *subs; |
584 | 54 int i,j; |
3543 | 55 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
56 if ( !subd || subd->sub_num == 0) return; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
57 subs = subd->subtitles; |
3543 | 58 |
584 | 59 if(vo_sub){ |
60 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
61 } else { | |
62 if(key>nosub_range_start && key<nosub_range_end) return; // OK! | |
63 } | |
64 // sub changed! | |
1203 | 65 |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
66 /* Tell the OSD subsystem that the OSD contents will change soon */ |
5638
86663f1b9b00
new osd code, use osd objs to follow changes and do minimal updates
arpi
parents:
4807
diff
changeset
|
67 vo_osd_changed(OSDTYPE_SUBTITLE); |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
68 |
1203 | 69 if(key<=0){ |
70 vo_sub=NULL; // no sub here | |
71 return; | |
72 } | |
584 | 73 |
74 // printf("\r---- sub changed ----\n"); | |
75 | |
76 // check next sub. | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
77 if(current_sub>=0 && current_sub+1 < subd->sub_num){ |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
78 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 79 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
80 nosub_range_start=subs[current_sub].end; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
81 nosub_range_end=subs[current_sub+1].start; |
584 | 82 vo_sub=NULL; |
83 return; | |
84 } | |
85 // next sub? | |
86 ++current_sub; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
87 vo_sub=&subs[current_sub]; |
584 | 88 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! |
89 } | |
90 | |
91 // printf("\r---- sub log search... ----\n"); | |
92 | |
93 // use logarithmic search: | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
94 i=0; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
95 j = subd->sub_num - 1; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
96 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); |
584 | 97 while(j>=i){ |
98 current_sub=(i+j+1)/2; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
99 vo_sub=&subs[current_sub]; |
584 | 100 if(key<vo_sub->start) j=current_sub-1; |
101 else if(key>vo_sub->end) i=current_sub+1; | |
102 else return; // found! | |
103 } | |
104 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
105 | |
106 // check where are we... | |
107 if(key<vo_sub->start){ | |
108 if(current_sub<=0){ | |
109 // before the first sub | |
110 nosub_range_start=key-1; // tricky | |
111 nosub_range_end=vo_sub->start; | |
112 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start); | |
113 vo_sub=NULL; | |
114 return; | |
115 } | |
116 --current_sub; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
117 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 118 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
119 nosub_range_start=subs[current_sub].end; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
120 nosub_range_end=subs[current_sub+1].start; |
584 | 121 // printf("No sub... 1 \n"); |
122 vo_sub=NULL; | |
123 return; | |
124 } | |
125 printf("HEH???? "); | |
126 } else { | |
127 if(key<=vo_sub->end) printf("JAJJ! "); else | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
128 if(current_sub+1 >= subd->sub_num){ |
584 | 129 // at the end? |
130 nosub_range_start=vo_sub->end; | |
131 nosub_range_end=0x7FFFFFFF; // MAXINT | |
132 // printf("END!?\n"); | |
133 vo_sub=NULL; | |
134 return; | |
135 } else | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
136 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 137 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
138 nosub_range_start=subs[current_sub].end; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
139 nosub_range_end=subs[current_sub+1].start; |
584 | 140 // printf("No sub... 2 \n"); |
141 vo_sub=NULL; | |
142 return; | |
143 } | |
144 } | |
145 | |
146 printf("SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)vo_sub->start,(int)vo_sub->end,current_sub); | |
147 | |
148 vo_sub=NULL; // no sub here | |
149 } | |
150 | |
1422 | 151 #endif |