1 //**************************************************************************//
3 //**************************************************************************//
11 #include "libvo/video_out.h"
12 #include "libvo/sub.h"
13 #include "subreader.h"
15 static int current_sub
=0;
17 //static subtitle* subtitles=NULL;
18 static int nosub_range_start
=-1;
19 static int nosub_range_end
=-1;
21 extern float sub_delay
;
24 void step_sub(sub_data
*subd
, float pts
, int movement
) {
28 if (subd
== NULL
) return;
29 subs
= subd
->subtitles
;
30 key
= (pts
+sub_delay
) * (subd
->sub_uses_time
? 100 : sub_fps
);
32 /* Tell the OSD subsystem that the OSD contents will change soon */
33 vo_osd_changed(OSDTYPE_SUBTITLE
);
35 /* If we are moving forward, don't count the next (current) subtitle
36 * if we haven't displayed it yet. Same when moving other direction.
38 if (movement
> 0 && key
< subs
[current_sub
].start
)
40 if (movement
< 0 && key
>= subs
[current_sub
].end
)
43 /* Never move beyond first or last subtitle. */
44 if (current_sub
+movement
< 0)
45 movement
= 0-current_sub
;
46 if (current_sub
+movement
>= subd
->sub_num
)
47 movement
= subd
->sub_num
- current_sub
- 1;
49 current_sub
+= movement
;
50 sub_delay
= subs
[current_sub
].start
/ (subd
->sub_uses_time
? 100 : sub_fps
) - pts
;
53 void find_sub(sub_data
* subd
,int key
){
57 if ( !subd
|| subd
->sub_num
== 0) return;
58 subs
= subd
->subtitles
;
61 if(key
>=vo_sub
->start
&& key
<=vo_sub
->end
) return; // OK!
63 if(key
>nosub_range_start
&& key
<nosub_range_end
) return; // OK!
67 /* Tell the OSD subsystem that the OSD contents will change soon */
68 vo_osd_changed(OSDTYPE_SUBTITLE
);
71 vo_sub
=NULL
; // no sub here
75 // printf("\r---- sub changed ----\n");
78 if(current_sub
>=0 && current_sub
+1 < subd
->sub_num
){
79 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
81 nosub_range_start
=subs
[current_sub
].end
;
82 nosub_range_end
=subs
[current_sub
+1].start
;
88 vo_sub
=&subs
[current_sub
];
89 if(key
>=vo_sub
->start
&& key
<=vo_sub
->end
) return; // OK!
92 // printf("\r---- sub log search... ----\n");
94 // use logarithmic search:
96 j
= subd
->sub_num
- 1;
97 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end);
99 current_sub
=(i
+j
+1)/2;
100 vo_sub
=&subs
[current_sub
];
101 if(key
<vo_sub
->start
) j
=current_sub
-1;
102 else if(key
>vo_sub
->end
) i
=current_sub
+1;
103 else return; // found!
105 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
107 // check where are we...
108 if(key
<vo_sub
->start
){
110 // before the first sub
111 nosub_range_start
=key
-1; // tricky
112 nosub_range_end
=vo_sub
->start
;
113 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start);
118 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
120 nosub_range_start
=subs
[current_sub
].end
;
121 nosub_range_end
=subs
[current_sub
+1].start
;
122 // printf("No sub... 1 \n");
128 if(key
<=vo_sub
->end
) printf("JAJJ! "); else
129 if(current_sub
+1 >= subd
->sub_num
){
131 nosub_range_start
=vo_sub
->end
;
132 nosub_range_end
=0x7FFFFFFF; // MAXINT
133 // printf("END!?\n");
137 if(key
>subs
[current_sub
].end
&& key
<subs
[current_sub
+1].start
){
139 nosub_range_start
=subs
[current_sub
].end
;
140 nosub_range_end
=subs
[current_sub
+1].start
;
141 // printf("No sub... 2 \n");
147 printf("SUB ERROR: %d ? %d --- %d [%d] \n",key
,(int)vo_sub
->start
,(int)vo_sub
->end
,current_sub
);
149 vo_sub
=NULL
; // no sub here