Mercurial > mplayer.hg
annotate find_sub.c @ 25645:56f7c73054a7
Fix indentation
author | reimar |
---|---|
date | Fri, 11 Jan 2008 20:12:04 +0000 |
parents | 8f846cea9940 |
children | 0f1b5b68af32 |
rev | line source |
---|---|
584 | 1 //**************************************************************************// |
2 // .SUB | |
3 //**************************************************************************// | |
4 | |
1422 | 5 #include "config.h" |
6 | |
584 | 7 #include <stdio.h> |
8 | |
9 #include "libvo/video_out.h" | |
2897 | 10 #include "libvo/sub.h" |
584 | 11 #include "subreader.h" |
12 | |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9974
diff
changeset
|
13 #include "mp_msg.h" |
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9974
diff
changeset
|
14 #include "help_mp.h" |
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9974
diff
changeset
|
15 |
584 | 16 static int current_sub=0; |
17 | |
18 //static subtitle* subtitles=NULL; | |
19 static int nosub_range_start=-1; | |
20 static int nosub_range_end=-1; | |
24829
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
21 static const sub_data *last_sub_data = NULL; |
584 | 22 |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
23 extern float sub_delay; |
8369 | 24 extern float sub_fps; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
25 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
26 void step_sub(sub_data *subd, float pts, int movement) { |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
27 subtitle *subs; |
9974 | 28 int key; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
29 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
30 if (subd == NULL) return; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
31 subs = subd->subtitles; |
9974 | 32 key = (pts+sub_delay) * (subd->sub_uses_time ? 100 : sub_fps); |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
33 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
34 /* Tell the OSD subsystem that the OSD contents will change soon */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
35 vo_osd_changed(OSDTYPE_SUBTITLE); |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
36 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
37 /* If we are moving forward, don't count the next (current) subtitle |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
38 * if we haven't displayed it yet. Same when moving other direction. |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
39 */ |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
40 if (movement > 0 && key < subs[current_sub].start) |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
41 movement--; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
42 if (movement < 0 && key >= subs[current_sub].end) |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
43 movement++; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
44 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
45 /* Never move beyond first or last subtitle. */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
46 if (current_sub+movement < 0) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
47 movement = 0-current_sub; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
48 if (current_sub+movement >= subd->sub_num) |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
49 movement = subd->sub_num - current_sub - 1; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
50 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
51 current_sub += movement; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
52 sub_delay = subs[current_sub].start / (subd->sub_uses_time ? 100 : sub_fps) - pts; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
53 } |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
54 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
55 void find_sub(sub_data* subd,int key){ |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
56 subtitle *subs; |
584 | 57 int i,j; |
3543 | 58 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
59 if ( !subd || subd->sub_num == 0) return; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
60 subs = subd->subtitles; |
3543 | 61 |
24829
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
62 if (last_sub_data != subd) { |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
63 // Sub data changed, reset nosub range. |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
64 last_sub_data = subd; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
65 nosub_range_start = -1; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
66 nosub_range_end = -1; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
67 } |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
68 |
584 | 69 if(vo_sub){ |
70 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
71 } else { | |
72 if(key>nosub_range_start && key<nosub_range_end) return; // OK! | |
73 } | |
74 // sub changed! | |
1203 | 75 |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
76 /* Tell the OSD subsystem that the OSD contents will change soon */ |
5638
86663f1b9b00
new osd code, use osd objs to follow changes and do minimal updates
arpi
parents:
4807
diff
changeset
|
77 vo_osd_changed(OSDTYPE_SUBTITLE); |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
78 |
1203 | 79 if(key<=0){ |
80 vo_sub=NULL; // no sub here | |
81 return; | |
82 } | |
584 | 83 |
84 // printf("\r---- sub changed ----\n"); | |
85 | |
86 // check next sub. | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
87 if(current_sub>=0 && current_sub+1 < subd->sub_num){ |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
88 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 89 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
90 nosub_range_start=subs[current_sub].end; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
91 nosub_range_end=subs[current_sub+1].start; |
584 | 92 vo_sub=NULL; |
93 return; | |
94 } | |
95 // next sub? | |
96 ++current_sub; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
97 vo_sub=&subs[current_sub]; |
584 | 98 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! |
99 } | |
100 | |
101 // printf("\r---- sub log search... ----\n"); | |
102 | |
103 // use logarithmic search: | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
104 i=0; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
105 j = subd->sub_num - 1; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
106 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); |
584 | 107 while(j>=i){ |
108 current_sub=(i+j+1)/2; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
109 vo_sub=&subs[current_sub]; |
584 | 110 if(key<vo_sub->start) j=current_sub-1; |
111 else if(key>vo_sub->end) i=current_sub+1; | |
112 else return; // found! | |
113 } | |
114 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
115 | |
116 // check where are we... | |
117 if(key<vo_sub->start){ | |
118 if(current_sub<=0){ | |
119 // before the first sub | |
120 nosub_range_start=key-1; // tricky | |
121 nosub_range_end=vo_sub->start; | |
122 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start); | |
123 vo_sub=NULL; | |
124 return; | |
125 } | |
126 --current_sub; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
127 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 128 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
129 nosub_range_start=subs[current_sub].end; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
130 nosub_range_end=subs[current_sub+1].start; |
584 | 131 // printf("No sub... 1 \n"); |
132 vo_sub=NULL; | |
133 return; | |
134 } | |
135 printf("HEH???? "); | |
136 } else { | |
137 if(key<=vo_sub->end) printf("JAJJ! "); else | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
138 if(current_sub+1 >= subd->sub_num){ |
584 | 139 // at the end? |
140 nosub_range_start=vo_sub->end; | |
141 nosub_range_end=0x7FFFFFFF; // MAXINT | |
142 // printf("END!?\n"); | |
143 vo_sub=NULL; | |
144 return; | |
145 } else | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
146 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 147 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
148 nosub_range_start=subs[current_sub].end; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
149 nosub_range_end=subs[current_sub+1].start; |
584 | 150 // printf("No sub... 2 \n"); |
151 vo_sub=NULL; | |
152 return; | |
153 } | |
154 } | |
155 | |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9974
diff
changeset
|
156 mp_msg(MSGT_FIXME,MSGL_FIXME,"SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)vo_sub->start,(int)vo_sub->end,current_sub); |
584 | 157 |
158 vo_sub=NULL; // no sub here | |
159 } |