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"
32 static int current_sub
=0;
34 //static subtitle* subtitles=NULL;
35 static int nosub_range_start
=-1;
36 static int nosub_range_end
=-1;
37 static const sub_data
*last_sub_data
= NULL
;
39 extern float sub_delay
;
42 void step_sub(sub_data
*subd
, float pts
, int movement
) {
46 if (subd
== NULL
) return;
47 subs
= subd
->subtitles
;
48 key
= (pts
+sub_delay
) * (subd
->sub_uses_time
? 100 : sub_fps
);
50 /* Tell the OSD subsystem that the OSD contents will change soon */
51 vo_osd_changed(OSDTYPE_SUBTITLE
);
53 /* If we are moving forward, don't count the next (current) subtitle
54 * if we haven't displayed it yet. Same when moving other direction.
56 if (movement
> 0 && key
< subs
[current_sub
].start
)
58 if (movement
< 0 && key
>= subs
[current_sub
].end
)
61 /* Never move beyond first or last subtitle. */
62 if (current_sub
+movement
< 0)
63 movement
= 0-current_sub
;
64 if (current_sub
+movement
>= subd
->sub_num
)
65 movement
= subd
->sub_num
- current_sub
- 1;
67 current_sub
+= movement
;
68 sub_delay
= subs
[current_sub
].start
/ (subd
->sub_uses_time
? 100 : sub_fps
) - pts
;
71 void find_sub(struct MPContext
*mpctx
, sub_data
* subd
,int key
){
73 subtitle
*new_sub
= NULL
;
76 if ( !subd
|| subd
->sub_num
== 0) return;
77 subs
= subd
->subtitles
;
79 if (last_sub_data
!= subd
) {
80 // Sub data changed, reset nosub range.
82 nosub_range_start
= -1;
87 if(key
>=vo_sub
->start
&& key
<=vo_sub
->end
) return; // OK!
89 if(key
>nosub_range_start
&& key
<nosub_range_end
) return; // OK!
93 /* Tell the OSD subsystem that the OSD contents will change soon */
94 vo_osd_changed(OSDTYPE_SUBTITLE
);
101 // printf("\r---- sub changed ----\n");
104 if(current_sub
>=0 && current_sub
+1 < subd
->sub_num
){
105 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
107 nosub_range_start
=subs
[current_sub
].end
;
108 nosub_range_end
=subs
[current_sub
+1].start
;
113 new_sub
=&subs
[current_sub
];
114 if(key
>=new_sub
->start
&& key
<=new_sub
->end
) goto update
; // OK!
117 // printf("\r---- sub log search... ----\n");
119 // use logarithmic search:
121 j
= subd
->sub_num
- 1;
122 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end);
124 current_sub
=(i
+j
+1)/2;
125 new_sub
=&subs
[current_sub
];
126 if(key
<new_sub
->start
) j
=current_sub
-1;
127 else if(key
>new_sub
->end
) i
=current_sub
+1;
128 else goto update
; // found!
130 // if(key>=new_sub->start && key<=new_sub->end) return; // OK!
132 // check where are we...
133 if(key
<new_sub
->start
){
135 // before the first sub
136 nosub_range_start
=key
-1; // tricky
137 nosub_range_end
=new_sub
->start
;
138 // printf("FIRST... key=%d end=%d \n",key,new_sub->start);
143 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
145 nosub_range_start
=subs
[current_sub
].end
;
146 nosub_range_end
=subs
[current_sub
+1].start
;
147 // printf("No sub... 1 \n");
153 if(key
<=new_sub
->end
) printf("JAJJ! "); else
154 if(current_sub
+1 >= subd
->sub_num
){
156 nosub_range_start
=new_sub
->end
;
157 nosub_range_end
=0x7FFFFFFF; // MAXINT
158 // printf("END!?\n");
162 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
164 nosub_range_start
=subs
[current_sub
].end
;
165 nosub_range_end
=subs
[current_sub
+1].start
;
166 // printf("No sub... 2 \n");
172 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"SUB ERROR: %d ? %d --- %d [%d] \n",key
,(int)new_sub
->start
,(int)new_sub
->end
,current_sub
);
174 new_sub
=NULL
; // no sub here
176 set_osd_subtitle(mpctx
, new_sub
);