4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "libvo/video_out.h"
27 #include "subreader.h"
33 static int current_sub
=0;
35 //static subtitle* subtitles=NULL;
36 static int nosub_range_start
=-1;
37 static int nosub_range_end
=-1;
38 static const sub_data
*last_sub_data
= NULL
;
40 void find_sub(struct MPContext
*mpctx
, sub_data
* subd
,int key
){
42 subtitle
*new_sub
= NULL
;
45 if ( !subd
|| subd
->sub_num
== 0) return;
46 subs
= subd
->subtitles
;
48 if (last_sub_data
!= subd
) {
49 // Sub data changed, reset nosub range.
51 nosub_range_start
= -1;
56 if(key
>=vo_sub
->start
&& key
<=vo_sub
->end
) return; // OK!
58 if(key
>nosub_range_start
&& key
<nosub_range_end
) return; // OK!
62 /* Tell the OSD subsystem that the OSD contents will change soon */
63 vo_osd_changed(OSDTYPE_SUBTITLE
);
70 // printf("\r---- sub changed ----\n");
73 if(current_sub
>=0 && current_sub
+1 < subd
->sub_num
){
74 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
76 nosub_range_start
=subs
[current_sub
].end
;
77 nosub_range_end
=subs
[current_sub
+1].start
;
82 new_sub
=&subs
[current_sub
];
83 if(key
>=new_sub
->start
&& key
<=new_sub
->end
) goto update
; // OK!
86 // printf("\r---- sub log search... ----\n");
88 // use logarithmic search:
90 j
= subd
->sub_num
- 1;
91 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end);
93 current_sub
=(i
+j
+1)/2;
94 new_sub
=&subs
[current_sub
];
95 if(key
<new_sub
->start
) j
=current_sub
-1;
96 else if(key
>new_sub
->end
) i
=current_sub
+1;
97 else goto update
; // found!
99 // if(key>=new_sub->start && key<=new_sub->end) return; // OK!
101 // check where are we...
102 if(key
<new_sub
->start
){
104 // before the first sub
105 nosub_range_start
=key
-1; // tricky
106 nosub_range_end
=new_sub
->start
;
107 // printf("FIRST... key=%d end=%d \n",key,new_sub->start);
112 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
114 nosub_range_start
=subs
[current_sub
].end
;
115 nosub_range_end
=subs
[current_sub
+1].start
;
116 // printf("No sub... 1 \n");
122 if(key
<=new_sub
->end
) printf("JAJJ! "); else
123 if(current_sub
+1 >= subd
->sub_num
){
125 nosub_range_start
=new_sub
->end
;
126 nosub_range_end
=0x7FFFFFFF; // MAXINT
127 // printf("END!?\n");
131 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
133 nosub_range_start
=subs
[current_sub
].end
;
134 nosub_range_end
=subs
[current_sub
+1].start
;
135 // printf("No sub... 2 \n");
141 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"SUB ERROR: %d ? %d --- %d [%d] \n",key
,(int)new_sub
->start
,(int)new_sub
->end
,current_sub
);
143 new_sub
=NULL
; // no sub here
145 set_osd_subtitle(mpctx
, new_sub
);