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"
26 #include "libvo/sub.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 extern float sub_delay
;
43 void step_sub(sub_data
*subd
, float pts
, int movement
) {
47 if (subd
== NULL
) return;
48 subs
= subd
->subtitles
;
49 key
= (pts
+sub_delay
) * (subd
->sub_uses_time
? 100 : sub_fps
);
51 /* Tell the OSD subsystem that the OSD contents will change soon */
52 vo_osd_changed(OSDTYPE_SUBTITLE
);
54 /* If we are moving forward, don't count the next (current) subtitle
55 * if we haven't displayed it yet. Same when moving other direction.
57 if (movement
> 0 && key
< subs
[current_sub
].start
)
59 if (movement
< 0 && key
>= subs
[current_sub
].end
)
62 /* Never move beyond first or last subtitle. */
63 if (current_sub
+movement
< 0)
64 movement
= 0-current_sub
;
65 if (current_sub
+movement
>= subd
->sub_num
)
66 movement
= subd
->sub_num
- current_sub
- 1;
68 current_sub
+= movement
;
69 sub_delay
= subs
[current_sub
].start
/ (subd
->sub_uses_time
? 100 : sub_fps
) - pts
;
72 void find_sub(sub_data
* subd
,int key
){
74 subtitle
*new_sub
= NULL
;
77 if ( !subd
|| subd
->sub_num
== 0) return;
78 subs
= subd
->subtitles
;
80 if (last_sub_data
!= subd
) {
81 // Sub data changed, reset nosub range.
83 nosub_range_start
= -1;
88 if(key
>=vo_sub
->start
&& key
<=vo_sub
->end
) return; // OK!
90 if(key
>nosub_range_start
&& key
<nosub_range_end
) return; // OK!
94 /* Tell the OSD subsystem that the OSD contents will change soon */
95 vo_osd_changed(OSDTYPE_SUBTITLE
);
102 // printf("\r---- sub changed ----\n");
105 if(current_sub
>=0 && current_sub
+1 < subd
->sub_num
){
106 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
108 nosub_range_start
=subs
[current_sub
].end
;
109 nosub_range_end
=subs
[current_sub
+1].start
;
114 new_sub
=&subs
[current_sub
];
115 if(key
>=new_sub
->start
&& key
<=new_sub
->end
) goto update
; // OK!
118 // printf("\r---- sub log search... ----\n");
120 // use logarithmic search:
122 j
= subd
->sub_num
- 1;
123 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end);
125 current_sub
=(i
+j
+1)/2;
126 new_sub
=&subs
[current_sub
];
127 if(key
<new_sub
->start
) j
=current_sub
-1;
128 else if(key
>new_sub
->end
) i
=current_sub
+1;
129 else goto update
; // found!
131 // if(key>=new_sub->start && key<=new_sub->end) return; // OK!
133 // check where are we...
134 if(key
<new_sub
->start
){
136 // before the first sub
137 nosub_range_start
=key
-1; // tricky
138 nosub_range_end
=new_sub
->start
;
139 // printf("FIRST... key=%d end=%d \n",key,new_sub->start);
144 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
146 nosub_range_start
=subs
[current_sub
].end
;
147 nosub_range_end
=subs
[current_sub
+1].start
;
148 // printf("No sub... 1 \n");
154 if(key
<=new_sub
->end
) printf("JAJJ! "); else
155 if(current_sub
+1 >= subd
->sub_num
){
157 nosub_range_start
=new_sub
->end
;
158 nosub_range_end
=0x7FFFFFFF; // MAXINT
159 // printf("END!?\n");
163 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
165 nosub_range_start
=subs
[current_sub
].end
;
166 nosub_range_end
=subs
[current_sub
+1].start
;
167 // printf("No sub... 2 \n");
173 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"SUB ERROR: %d ? %d --- %d [%d] \n",key
,(int)new_sub
->start
,(int)new_sub
->end
,current_sub
);
175 new_sub
=NULL
; // no sub here
177 set_osd_subtitle(new_sub
);