summaryrefslogtreecommitdiffstats
path: root/find_sub.c
diff options
context:
space:
mode:
authorarpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-04-23 03:34:47 +0000
committerarpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-04-23 03:34:47 +0000
commit3107b2c82fc2d2267e9d2dc48ca4e9eb0e278b8a (patch)
tree7f66e055d02e6dc42215fb954a825a7c696391cd /find_sub.c
parentb5c8cd95dd36a4e7d7cfa2fc266e44f3c0b09dc4 (diff)
downloadmpv-3107b2c82fc2d2267e9d2dc48ca4e9eb0e278b8a.tar.bz2
mpv-3107b2c82fc2d2267e9d2dc48ca4e9eb0e278b8a.tar.xz
find_sub() moved out from mplayer.c
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@585 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'find_sub.c')
-rw-r--r--find_sub.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/find_sub.c b/find_sub.c
new file mode 100644
index 0000000000..9306c5cb51
--- /dev/null
+++ b/find_sub.c
@@ -0,0 +1,101 @@
+//**************************************************************************//
+// .SUB
+//**************************************************************************//
+
+#include <stdio.h>
+
+#include "libvo/video_out.h"
+#include "subreader.h"
+#include "libvo/sub.h"
+
+static int current_sub=0;
+
+//static subtitle* subtitles=NULL;
+static int nosub_range_start=-1;
+static int nosub_range_end=-1;
+
+void find_sub(subtitle* subtitles,int key){
+ int i,j;
+ 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!
+
+// printf("\r---- sub changed ----\n");
+
+ // check next sub.
+ if(current_sub>=0 && current_sub+1<sub_num){
+ if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
+ // no sub
+ nosub_range_start=subtitles[current_sub].end;
+ nosub_range_end=subtitles[current_sub+1].start;
+ vo_sub=NULL;
+ return;
+ }
+ // next sub?
+ ++current_sub;
+ vo_sub=&subtitles[current_sub];
+ if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
+ }
+
+// printf("\r---- sub log search... ----\n");
+
+ // use logarithmic search:
+ i=0;j=sub_num-1;
+// printf("Searching %d in %d..%d\n",key,subtitles[i].start,subtitles[j].end);
+ while(j>=i){
+ current_sub=(i+j+1)/2;
+ vo_sub=&subtitles[current_sub];
+ 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;
+ if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
+ // no sub
+ nosub_range_start=subtitles[current_sub].end;
+ nosub_range_end=subtitles[current_sub+1].start;
+// printf("No sub... 1 \n");
+ vo_sub=NULL;
+ return;
+ }
+ printf("HEH???? ");
+ } else {
+ if(key<=vo_sub->end) printf("JAJJ! "); else
+ if(current_sub+1>=sub_num){
+ // at the end?
+ nosub_range_start=vo_sub->end;
+ nosub_range_end=0x7FFFFFFF; // MAXINT
+// printf("END!?\n");
+ vo_sub=NULL;
+ return;
+ } else
+ if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
+ // no sub
+ nosub_range_start=subtitles[current_sub].end;
+ nosub_range_end=subtitles[current_sub+1].start;
+// 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
+}
+