1 //**************************************************************************//
3 //**************************************************************************//
9 #include "libvo/video_out.h"
10 #include "libvo/sub.h"
11 #include "subreader.h"
16 static int current_sub
=0;
18 //static subtitle* subtitles=NULL;
19 static int nosub_range_start
=-1;
20 static int nosub_range_end
=-1;
21 static const sub_data
*last_sub_data
= NULL
;
23 extern float sub_delay
;
26 void step_sub(sub_data
*subd
, float pts
, int movement
) {
30 if (subd
== NULL
) return;
31 subs
= subd
->subtitles
;
32 key
= (pts
+sub_delay
) * (subd
->sub_uses_time
? 100 : sub_fps
);
34 /* Tell the OSD subsystem that the OSD contents will change soon */
35 vo_osd_changed(OSDTYPE_SUBTITLE
);
37 /* If we are moving forward, don't count the next (current) subtitle
38 * if we haven't displayed it yet. Same when moving other direction.
40 if (movement
> 0 && key
< subs
[current_sub
].start
)
42 if (movement
< 0 && key
>= subs
[current_sub
].end
)
45 /* Never move beyond first or last subtitle. */
46 if (current_sub
+movement
< 0)
47 movement
= 0-current_sub
;
48 if (current_sub
+movement
>= subd
->sub_num
)
49 movement
= subd
->sub_num
- current_sub
- 1;
51 current_sub
+= movement
;
52 sub_delay
= subs
[current_sub
].start
/ (subd
->sub_uses_time
? 100 : sub_fps
) - pts
;
55 void find_sub(sub_data
* subd
,int key
){
59 if ( !subd
|| subd
->sub_num
== 0) return;
60 subs
= subd
->subtitles
;
62 if (last_sub_data
!= subd
) {
63 // Sub data changed, reset nosub range.
65 nosub_range_start
= -1;
70 if(key
>=vo_sub
->start
&& key
<=vo_sub
->end
) return; // OK!
72 if(key
>nosub_range_start
&& key
<nosub_range_end
) return; // OK!
76 /* Tell the OSD subsystem that the OSD contents will change soon */
77 vo_osd_changed(OSDTYPE_SUBTITLE
);
80 vo_sub
=NULL
; // no sub here
84 // printf("\r---- sub changed ----\n");
87 if(current_sub
>=0 && current_sub
+1 < subd
->sub_num
){
88 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
90 nosub_range_start
=subs
[current_sub
].end
;
91 nosub_range_end
=subs
[current_sub
+1].start
;
97 vo_sub
=&subs
[current_sub
];
98 if(key
>=vo_sub
->start
&& key
<=vo_sub
->end
) return; // OK!
101 // printf("\r---- sub log search... ----\n");
103 // use logarithmic search:
105 j
= subd
->sub_num
- 1;
106 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end);
108 current_sub
=(i
+j
+1)/2;
109 vo_sub
=&subs
[current_sub
];
110 if(key
<vo_sub
->start
) j
=current_sub
-1;
111 else if(key
>vo_sub
->end
) i
=current_sub
+1;
112 else return; // found!
114 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
116 // check where are we...
117 if(key
<vo_sub
->start
){
119 // before the first sub
120 nosub_range_start
=key
-1; // tricky
121 nosub_range_end
=vo_sub
->start
;
122 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start);
127 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
129 nosub_range_start
=subs
[current_sub
].end
;
130 nosub_range_end
=subs
[current_sub
+1].start
;
131 // printf("No sub... 1 \n");
137 if(key
<=vo_sub
->end
) printf("JAJJ! "); else
138 if(current_sub
+1 >= subd
->sub_num
){
140 nosub_range_start
=vo_sub
->end
;
141 nosub_range_end
=0x7FFFFFFF; // MAXINT
142 // printf("END!?\n");
146 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
148 nosub_range_start
=subs
[current_sub
].end
;
149 nosub_range_end
=subs
[current_sub
+1].start
;
150 // printf("No sub... 2 \n");
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
);
158 vo_sub
=NULL
; // no sub here