2001-04-23 03:34:47 +00:00
|
|
|
//**************************************************************************//
|
|
|
|
// .SUB
|
|
|
|
//**************************************************************************//
|
|
|
|
|
2001-07-30 02:00:54 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef USE_OSD
|
|
|
|
|
2001-04-23 03:34:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "libvo/video_out.h"
|
|
|
|
#include "libvo/sub.h"
|
2001-11-14 11:16:45 +00:00
|
|
|
#include "subreader.h"
|
2001-04-23 03:34:47 +00:00
|
|
|
|
|
|
|
static int current_sub=0;
|
|
|
|
|
|
|
|
//static subtitle* subtitles=NULL;
|
|
|
|
static int nosub_range_start=-1;
|
|
|
|
static int nosub_range_end=-1;
|
|
|
|
|
2002-12-05 00:15:56 +00:00
|
|
|
extern float sub_delay;
|
2002-12-05 02:05:13 +00:00
|
|
|
extern float sub_fps;
|
2002-12-05 00:15:56 +00:00
|
|
|
|
2003-04-07 16:04:02 +00:00
|
|
|
void step_sub(sub_data *subd, float pts, int movement) {
|
|
|
|
subtitle *subs;
|
|
|
|
int key = (pts+sub_delay) * (subd->sub_uses_time ? 100 : sub_fps);
|
2002-12-05 00:15:56 +00:00
|
|
|
|
2003-04-07 16:04:02 +00:00
|
|
|
if (subd == NULL) return;
|
|
|
|
subs = subd->subtitles;
|
2002-12-05 00:15:56 +00:00
|
|
|
|
|
|
|
/* Tell the OSD subsystem that the OSD contents will change soon */
|
|
|
|
vo_osd_changed(OSDTYPE_SUBTITLE);
|
|
|
|
|
|
|
|
/* If we are moving forward, don't count the next (current) subtitle
|
|
|
|
* if we haven't displayed it yet. Same when moving other direction.
|
|
|
|
*/
|
2003-04-07 16:04:02 +00:00
|
|
|
if (movement > 0 && key < subs[current_sub].start)
|
2002-12-05 00:15:56 +00:00
|
|
|
movement--;
|
2003-04-07 16:04:02 +00:00
|
|
|
if (movement < 0 && key >= subs[current_sub].end)
|
2002-12-05 00:15:56 +00:00
|
|
|
movement++;
|
|
|
|
|
|
|
|
/* Never move beyond first or last subtitle. */
|
|
|
|
if (current_sub+movement < 0)
|
|
|
|
movement = 0-current_sub;
|
2003-04-07 16:04:02 +00:00
|
|
|
if (current_sub+movement >= subd->sub_num)
|
|
|
|
movement = subd->sub_num - current_sub - 1;
|
2002-12-05 00:15:56 +00:00
|
|
|
|
|
|
|
current_sub += movement;
|
2003-04-07 16:04:02 +00:00
|
|
|
sub_delay = subs[current_sub].start / (subd->sub_uses_time ? 100 : sub_fps) - pts;
|
2002-12-05 00:15:56 +00:00
|
|
|
}
|
|
|
|
|
2003-04-07 16:04:02 +00:00
|
|
|
void find_sub(sub_data* subd,int key){
|
|
|
|
subtitle *subs;
|
2001-04-23 03:34:47 +00:00
|
|
|
int i,j;
|
2001-12-17 00:07:20 +00:00
|
|
|
|
2003-04-07 16:04:02 +00:00
|
|
|
if ( !subd || subd->sub_num == 0) return;
|
|
|
|
subs = subd->subtitles;
|
2001-12-17 00:07:20 +00:00
|
|
|
|
2001-04-23 03:34:47 +00:00
|
|
|
if(vo_sub){
|
|
|
|
if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
|
|
|
|
} else {
|
|
|
|
if(key>nosub_range_start && key<nosub_range_end) return; // OK!
|
|
|
|
}
|
|
|
|
// sub changed!
|
2001-06-23 16:59:40 +00:00
|
|
|
|
2002-02-22 15:25:11 +00:00
|
|
|
/* Tell the OSD subsystem that the OSD contents will change soon */
|
2002-04-15 19:17:12 +00:00
|
|
|
vo_osd_changed(OSDTYPE_SUBTITLE);
|
2002-02-22 15:25:11 +00:00
|
|
|
|
2001-06-23 16:59:40 +00:00
|
|
|
if(key<=0){
|
|
|
|
vo_sub=NULL; // no sub here
|
|
|
|
return;
|
|
|
|
}
|
2001-04-23 03:34:47 +00:00
|
|
|
|
|
|
|
// printf("\r---- sub changed ----\n");
|
|
|
|
|
|
|
|
// check next sub.
|
2003-04-07 16:04:02 +00:00
|
|
|
if(current_sub>=0 && current_sub+1 < subd->sub_num){
|
|
|
|
if(key>subs[current_sub].end && key<subs[current_sub+1].start){
|
2001-04-23 03:34:47 +00:00
|
|
|
// no sub
|
2003-04-07 16:04:02 +00:00
|
|
|
nosub_range_start=subs[current_sub].end;
|
|
|
|
nosub_range_end=subs[current_sub+1].start;
|
2001-04-23 03:34:47 +00:00
|
|
|
vo_sub=NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// next sub?
|
|
|
|
++current_sub;
|
2003-04-07 16:04:02 +00:00
|
|
|
vo_sub=&subs[current_sub];
|
2001-04-23 03:34:47 +00:00
|
|
|
if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
|
|
|
|
}
|
|
|
|
|
|
|
|
// printf("\r---- sub log search... ----\n");
|
|
|
|
|
|
|
|
// use logarithmic search:
|
2003-04-07 16:04:02 +00:00
|
|
|
i=0;
|
|
|
|
j = subd->sub_num - 1;
|
|
|
|
// printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end);
|
2001-04-23 03:34:47 +00:00
|
|
|
while(j>=i){
|
|
|
|
current_sub=(i+j+1)/2;
|
2003-04-07 16:04:02 +00:00
|
|
|
vo_sub=&subs[current_sub];
|
2001-04-23 03:34:47 +00:00
|
|
|
if(key<vo_sub->start) j=current_sub-1;
|
|
|
|
else if(key>vo_sub->end) i=current_sub+1;
|
|
|
|
else return; // found!
|
|
|
|
}
|
|
|
|
// if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
|
|
|
|
|
|
|
|
// check where are we...
|
|
|
|
if(key<vo_sub->start){
|
|
|
|
if(current_sub<=0){
|
|
|
|
// before the first sub
|
|
|
|
nosub_range_start=key-1; // tricky
|
|
|
|
nosub_range_end=vo_sub->start;
|
|
|
|
// printf("FIRST... key=%d end=%d \n",key,vo_sub->start);
|
|
|
|
vo_sub=NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
--current_sub;
|
2003-04-07 16:04:02 +00:00
|
|
|
if(key>subs[current_sub].end && key<subs[current_sub+1].start){
|
2001-04-23 03:34:47 +00:00
|
|
|
// no sub
|
2003-04-07 16:04:02 +00:00
|
|
|
nosub_range_start=subs[current_sub].end;
|
|
|
|
nosub_range_end=subs[current_sub+1].start;
|
2001-04-23 03:34:47 +00:00
|
|
|
// printf("No sub... 1 \n");
|
|
|
|
vo_sub=NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("HEH???? ");
|
|
|
|
} else {
|
|
|
|
if(key<=vo_sub->end) printf("JAJJ! "); else
|
2003-04-07 16:04:02 +00:00
|
|
|
if(current_sub+1 >= subd->sub_num){
|
2001-04-23 03:34:47 +00:00
|
|
|
// at the end?
|
|
|
|
nosub_range_start=vo_sub->end;
|
|
|
|
nosub_range_end=0x7FFFFFFF; // MAXINT
|
|
|
|
// printf("END!?\n");
|
|
|
|
vo_sub=NULL;
|
|
|
|
return;
|
|
|
|
} else
|
2003-04-07 16:04:02 +00:00
|
|
|
if(key>subs[current_sub].end && key<subs[current_sub+1].start){
|
2001-04-23 03:34:47 +00:00
|
|
|
// no sub
|
2003-04-07 16:04:02 +00:00
|
|
|
nosub_range_start=subs[current_sub].end;
|
|
|
|
nosub_range_end=subs[current_sub+1].start;
|
2001-04-23 03:34:47 +00:00
|
|
|
// printf("No sub... 2 \n");
|
|
|
|
vo_sub=NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)vo_sub->start,(int)vo_sub->end,current_sub);
|
|
|
|
|
|
|
|
vo_sub=NULL; // no sub here
|
|
|
|
}
|
|
|
|
|
2001-07-30 02:00:54 +00:00
|
|
|
#endif
|