Mercurial > mplayer.hg
comparison find_sub.c @ 29684:23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
This does not yet seem to work for audio-only files, subtitles seem
not to be loaded then.
author | reimar |
---|---|
date | Mon, 28 Sep 2009 11:10:11 +0000 |
parents | 0f1b5b68af32 |
children | c1a3f1bbba26 |
comparison
equal
deleted
inserted
replaced
29683:3ed1dc05c83b | 29684:23c0da51c660 |
---|---|
10 #include "libvo/sub.h" | 10 #include "libvo/sub.h" |
11 #include "subreader.h" | 11 #include "subreader.h" |
12 | 12 |
13 #include "mp_msg.h" | 13 #include "mp_msg.h" |
14 #include "help_mp.h" | 14 #include "help_mp.h" |
15 #include "mpcommon.h" | |
15 | 16 |
16 static int current_sub=0; | 17 static int current_sub=0; |
17 | 18 |
18 //static subtitle* subtitles=NULL; | 19 //static subtitle* subtitles=NULL; |
19 static int nosub_range_start=-1; | 20 static int nosub_range_start=-1; |
52 sub_delay = subs[current_sub].start / (subd->sub_uses_time ? 100 : sub_fps) - pts; | 53 sub_delay = subs[current_sub].start / (subd->sub_uses_time ? 100 : sub_fps) - pts; |
53 } | 54 } |
54 | 55 |
55 void find_sub(sub_data* subd,int key){ | 56 void find_sub(sub_data* subd,int key){ |
56 subtitle *subs; | 57 subtitle *subs; |
58 subtitle *new_sub = NULL; | |
57 int i,j; | 59 int i,j; |
58 | 60 |
59 if ( !subd || subd->sub_num == 0) return; | 61 if ( !subd || subd->sub_num == 0) return; |
60 subs = subd->subtitles; | 62 subs = subd->subtitles; |
61 | 63 |
75 | 77 |
76 /* Tell the OSD subsystem that the OSD contents will change soon */ | 78 /* Tell the OSD subsystem that the OSD contents will change soon */ |
77 vo_osd_changed(OSDTYPE_SUBTITLE); | 79 vo_osd_changed(OSDTYPE_SUBTITLE); |
78 | 80 |
79 if(key<=0){ | 81 if(key<=0){ |
80 vo_sub=NULL; // no sub here | 82 // no sub here |
81 return; | 83 goto update; |
82 } | 84 } |
83 | 85 |
84 // printf("\r---- sub changed ----\n"); | 86 // printf("\r---- sub changed ----\n"); |
85 | 87 |
86 // check next sub. | 88 // check next sub. |
87 if(current_sub>=0 && current_sub+1 < subd->sub_num){ | 89 if(current_sub>=0 && current_sub+1 < subd->sub_num){ |
88 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ | 90 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
89 // no sub | 91 // no sub |
90 nosub_range_start=subs[current_sub].end; | 92 nosub_range_start=subs[current_sub].end; |
91 nosub_range_end=subs[current_sub+1].start; | 93 nosub_range_end=subs[current_sub+1].start; |
92 vo_sub=NULL; | 94 goto update; |
93 return; | |
94 } | 95 } |
95 // next sub? | 96 // next sub? |
96 ++current_sub; | 97 ++current_sub; |
97 vo_sub=&subs[current_sub]; | 98 new_sub=&subs[current_sub]; |
98 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | 99 if(key>=new_sub->start && key<=new_sub->end) goto update; // OK! |
99 } | 100 } |
100 | 101 |
101 // printf("\r---- sub log search... ----\n"); | 102 // printf("\r---- sub log search... ----\n"); |
102 | 103 |
103 // use logarithmic search: | 104 // use logarithmic search: |
104 i=0; | 105 i=0; |
105 j = subd->sub_num - 1; | 106 j = subd->sub_num - 1; |
106 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); | 107 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); |
107 while(j>=i){ | 108 while(j>=i){ |
108 current_sub=(i+j+1)/2; | 109 current_sub=(i+j+1)/2; |
109 vo_sub=&subs[current_sub]; | 110 new_sub=&subs[current_sub]; |
110 if(key<vo_sub->start) j=current_sub-1; | 111 if(key<new_sub->start) j=current_sub-1; |
111 else if(key>vo_sub->end) i=current_sub+1; | 112 else if(key>new_sub->end) i=current_sub+1; |
112 else return; // found! | 113 else goto update; // found! |
113 } | 114 } |
114 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | 115 // if(key>=new_sub->start && key<=new_sub->end) return; // OK! |
115 | 116 |
116 // check where are we... | 117 // check where are we... |
117 if(key<vo_sub->start){ | 118 if(key<new_sub->start){ |
118 if(current_sub<=0){ | 119 if(current_sub<=0){ |
119 // before the first sub | 120 // before the first sub |
120 nosub_range_start=key-1; // tricky | 121 nosub_range_start=key-1; // tricky |
121 nosub_range_end=vo_sub->start; | 122 nosub_range_end=new_sub->start; |
122 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start); | 123 // printf("FIRST... key=%d end=%d \n",key,new_sub->start); |
123 vo_sub=NULL; | 124 new_sub=NULL; |
124 return; | 125 goto update; |
125 } | 126 } |
126 --current_sub; | 127 --current_sub; |
127 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ | 128 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
128 // no sub | 129 // no sub |
129 nosub_range_start=subs[current_sub].end; | 130 nosub_range_start=subs[current_sub].end; |
130 nosub_range_end=subs[current_sub+1].start; | 131 nosub_range_end=subs[current_sub+1].start; |
131 // printf("No sub... 1 \n"); | 132 // printf("No sub... 1 \n"); |
132 vo_sub=NULL; | 133 new_sub=NULL; |
133 return; | 134 goto update; |
134 } | 135 } |
135 printf("HEH???? "); | 136 printf("HEH???? "); |
136 } else { | 137 } else { |
137 if(key<=vo_sub->end) printf("JAJJ! "); else | 138 if(key<=new_sub->end) printf("JAJJ! "); else |
138 if(current_sub+1 >= subd->sub_num){ | 139 if(current_sub+1 >= subd->sub_num){ |
139 // at the end? | 140 // at the end? |
140 nosub_range_start=vo_sub->end; | 141 nosub_range_start=new_sub->end; |
141 nosub_range_end=0x7FFFFFFF; // MAXINT | 142 nosub_range_end=0x7FFFFFFF; // MAXINT |
142 // printf("END!?\n"); | 143 // printf("END!?\n"); |
143 vo_sub=NULL; | 144 new_sub=NULL; |
144 return; | 145 goto update; |
145 } else | 146 } else |
146 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ | 147 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
147 // no sub | 148 // no sub |
148 nosub_range_start=subs[current_sub].end; | 149 nosub_range_start=subs[current_sub].end; |
149 nosub_range_end=subs[current_sub+1].start; | 150 nosub_range_end=subs[current_sub+1].start; |
150 // printf("No sub... 2 \n"); | 151 // printf("No sub... 2 \n"); |
151 vo_sub=NULL; | 152 new_sub=NULL; |
152 return; | 153 goto update; |
153 } | 154 } |
154 } | 155 } |
155 | 156 |
156 mp_msg(MSGT_FIXME,MSGL_FIXME,"SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)vo_sub->start,(int)vo_sub->end,current_sub); | 157 mp_msg(MSGT_FIXME,MSGL_FIXME,"SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)new_sub->start,(int)new_sub->end,current_sub); |
157 | 158 |
158 vo_sub=NULL; // no sub here | 159 new_sub=NULL; // no sub here |
160 update: | |
161 set_osd_subtitle(new_sub); | |
159 } | 162 } |