2010-01-30 23:24:23 +00:00
|
|
|
/*
|
|
|
|
* .SUB
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2001-04-23 03:34:47 +00:00
|
|
|
|
2001-07-30 02:00:54 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
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
|
|
|
|
2004-10-20 01:32:56 +00:00
|
|
|
#include "mp_msg.h"
|
2009-09-28 11:10:11 +00:00
|
|
|
#include "mpcommon.h"
|
2004-10-20 01:32:56 +00:00
|
|
|
|
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;
|
2007-10-27 00:37:46 +00:00
|
|
|
static const sub_data *last_sub_data = NULL;
|
2001-04-23 03:34:47 +00:00
|
|
|
|
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) {
|
2009-07-06 23:26:13 +00:00
|
|
|
subtitle *subs;
|
2003-04-24 08:20:10 +00:00
|
|
|
int key;
|
2002-12-05 00:15:56 +00:00
|
|
|
|
2003-04-07 16:04:02 +00:00
|
|
|
if (subd == NULL) return;
|
|
|
|
subs = subd->subtitles;
|
2003-04-24 08:20:10 +00:00
|
|
|
key = (pts+sub_delay) * (subd->sub_uses_time ? 100 : sub_fps);
|
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
|
|
|
}
|
|
|
|
|
2009-10-06 01:28:59 +00:00
|
|
|
void find_sub(struct MPContext *mpctx, sub_data* subd,int key){
|
2003-04-07 16:04:02 +00:00
|
|
|
subtitle *subs;
|
2009-09-28 11:10:11 +00:00
|
|
|
subtitle *new_sub = NULL;
|
2001-04-23 03:34:47 +00:00
|
|
|
int i,j;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-04-07 16:04:02 +00:00
|
|
|
if ( !subd || subd->sub_num == 0) return;
|
|
|
|
subs = subd->subtitles;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-10-27 00:37:46 +00:00
|
|
|
if (last_sub_data != subd) {
|
|
|
|
// Sub data changed, reset nosub range.
|
|
|
|
last_sub_data = subd;
|
|
|
|
nosub_range_start = -1;
|
|
|
|
nosub_range_end = -1;
|
|
|
|
}
|
|
|
|
|
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){
|
2009-09-28 11:10:11 +00:00
|
|
|
// no sub here
|
|
|
|
goto update;
|
2001-06-23 16:59:40 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-04-23 03:34:47 +00:00
|
|
|
// printf("\r---- sub changed ----\n");
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-04-23 03:34:47 +00:00
|
|
|
// 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;
|
2009-09-28 11:10:11 +00:00
|
|
|
goto update;
|
2001-04-23 03:34:47 +00:00
|
|
|
}
|
|
|
|
// next sub?
|
|
|
|
++current_sub;
|
2009-09-28 11:10:11 +00:00
|
|
|
new_sub=&subs[current_sub];
|
|
|
|
if(key>=new_sub->start && key<=new_sub->end) goto update; // OK!
|
2001-04-23 03:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// printf("\r---- sub log search... ----\n");
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-04-23 03:34:47 +00:00
|
|
|
// use logarithmic search:
|
2009-07-06 23:26:13 +00:00
|
|
|
i=0;
|
2003-04-07 16:04:02 +00:00
|
|
|
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;
|
2009-09-28 11:10:11 +00:00
|
|
|
new_sub=&subs[current_sub];
|
|
|
|
if(key<new_sub->start) j=current_sub-1;
|
|
|
|
else if(key>new_sub->end) i=current_sub+1;
|
|
|
|
else goto update; // found!
|
2001-04-23 03:34:47 +00:00
|
|
|
}
|
2009-09-28 11:10:11 +00:00
|
|
|
// if(key>=new_sub->start && key<=new_sub->end) return; // OK!
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-04-23 03:34:47 +00:00
|
|
|
// check where are we...
|
2009-09-28 11:10:11 +00:00
|
|
|
if(key<new_sub->start){
|
2001-04-23 03:34:47 +00:00
|
|
|
if(current_sub<=0){
|
|
|
|
// before the first sub
|
|
|
|
nosub_range_start=key-1; // tricky
|
2009-09-28 11:10:11 +00:00
|
|
|
nosub_range_end=new_sub->start;
|
|
|
|
// printf("FIRST... key=%d end=%d \n",key,new_sub->start);
|
|
|
|
new_sub=NULL;
|
|
|
|
goto update;
|
2001-04-23 03:34:47 +00:00
|
|
|
}
|
|
|
|
--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");
|
2009-09-28 11:10:11 +00:00
|
|
|
new_sub=NULL;
|
|
|
|
goto update;
|
2001-04-23 03:34:47 +00:00
|
|
|
}
|
|
|
|
printf("HEH???? ");
|
|
|
|
} else {
|
2009-09-28 11:10:11 +00:00
|
|
|
if(key<=new_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?
|
2009-09-28 11:10:11 +00:00
|
|
|
nosub_range_start=new_sub->end;
|
2001-04-23 03:34:47 +00:00
|
|
|
nosub_range_end=0x7FFFFFFF; // MAXINT
|
|
|
|
// printf("END!?\n");
|
2009-09-28 11:10:11 +00:00
|
|
|
new_sub=NULL;
|
|
|
|
goto update;
|
2001-04-23 03:34:47 +00:00
|
|
|
} 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");
|
2009-09-28 11:10:11 +00:00
|
|
|
new_sub=NULL;
|
|
|
|
goto update;
|
2001-04-23 03:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2009-09-28 11:10:11 +00:00
|
|
|
mp_msg(MSGT_FIXME,MSGL_FIXME,"SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)new_sub->start,(int)new_sub->end,current_sub);
|
2001-04-23 03:34:47 +00:00
|
|
|
|
2009-09-28 11:10:11 +00:00
|
|
|
new_sub=NULL; // no sub here
|
|
|
|
update:
|
2009-10-06 01:28:59 +00:00
|
|
|
set_osd_subtitle(mpctx, new_sub);
|
2001-04-23 03:34:47 +00:00
|
|
|
}
|