annotate find_sub.c @ 1224:cf2ef08fca25

Reviewed for release.
author atmos4
date Sun, 24 Jun 2001 21:12:17 +0000
parents 5f0d9239c5b2
children d02e0dcaf077
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
1 //**************************************************************************//
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
2 // .SUB
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
3 //**************************************************************************//
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
4
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
5 #include <stdio.h>
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
6
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
7 #include "libvo/video_out.h"
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
8 #include "subreader.h"
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
9 #include "libvo/sub.h"
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
10
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
11 static int current_sub=0;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
12
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
13 //static subtitle* subtitles=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
14 static int nosub_range_start=-1;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
15 static int nosub_range_end=-1;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
16
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
17 void find_sub(subtitle* subtitles,int key){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
18 int i,j;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
19 if(vo_sub){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
20 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
21 } else {
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
22 if(key>nosub_range_start && key<nosub_range_end) return; // OK!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
23 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
24 // sub changed!
1203
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
25
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
26 if(key<=0){
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
27 vo_sub=NULL; // no sub here
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
28 return;
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
29 }
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
30
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
31 // printf("\r---- sub changed ----\n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
32
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
33 // check next sub.
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
34 if(current_sub>=0 && current_sub+1<sub_num){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
35 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
36 // no sub
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
37 nosub_range_start=subtitles[current_sub].end;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
38 nosub_range_end=subtitles[current_sub+1].start;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
39 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
40 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
41 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
42 // next sub?
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
43 ++current_sub;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
44 vo_sub=&subtitles[current_sub];
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
45 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
46 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
47
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
48 // printf("\r---- sub log search... ----\n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
49
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
50 // use logarithmic search:
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
51 i=0;j=sub_num-1;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
52 // printf("Searching %d in %d..%d\n",key,subtitles[i].start,subtitles[j].end);
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
53 while(j>=i){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
54 current_sub=(i+j+1)/2;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
55 vo_sub=&subtitles[current_sub];
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
56 if(key<vo_sub->start) j=current_sub-1;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
57 else if(key>vo_sub->end) i=current_sub+1;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
58 else return; // found!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
59 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
60 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
61
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
62 // check where are we...
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
63 if(key<vo_sub->start){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
64 if(current_sub<=0){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
65 // before the first sub
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
66 nosub_range_start=key-1; // tricky
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
67 nosub_range_end=vo_sub->start;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
68 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start);
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
69 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
70 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
71 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
72 --current_sub;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
73 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
74 // no sub
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
75 nosub_range_start=subtitles[current_sub].end;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
76 nosub_range_end=subtitles[current_sub+1].start;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
77 // printf("No sub... 1 \n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
78 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
79 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
80 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
81 printf("HEH???? ");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
82 } else {
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
83 if(key<=vo_sub->end) printf("JAJJ! "); else
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
84 if(current_sub+1>=sub_num){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
85 // at the end?
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
86 nosub_range_start=vo_sub->end;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
87 nosub_range_end=0x7FFFFFFF; // MAXINT
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
88 // printf("END!?\n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
89 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
90 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
91 } else
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
92 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
93 // no sub
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
94 nosub_range_start=subtitles[current_sub].end;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
95 nosub_range_end=subtitles[current_sub+1].start;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
96 // printf("No sub... 2 \n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
97 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
98 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
99 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
100 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
101
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
102 printf("SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)vo_sub->start,(int)vo_sub->end,current_sub);
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
103
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
104 vo_sub=NULL; // no sub here
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
105 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
106