Mercurial > mplayer.hg
annotate find_sub.c @ 22731:5556aa316b2a
split sonic into sonic/sonicls and wma into wmav1/wmav2
author | compn |
---|---|
date | Mon, 19 Mar 2007 19:21:09 +0000 |
parents | ad7747bce52d |
children | 8f846cea9940 |
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; | |
21 | |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
22 extern float sub_delay; |
8369 | 23 extern float sub_fps; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
24 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
25 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
|
26 subtitle *subs; |
9974 | 27 int key; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
28 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
29 if (subd == NULL) return; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
30 subs = subd->subtitles; |
9974 | 31 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
|
32 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
33 /* 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
|
34 vo_osd_changed(OSDTYPE_SUBTITLE); |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
35 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
36 /* 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
|
37 * 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
|
38 */ |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
39 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
|
40 movement--; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
41 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
|
42 movement++; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
43 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
44 /* Never move beyond first or last subtitle. */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
45 if (current_sub+movement < 0) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
46 movement = 0-current_sub; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
47 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
|
48 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
|
49 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
50 current_sub += movement; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
51 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
|
52 } |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
53 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
54 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
|
55 subtitle *subs; |
584 | 56 int i,j; |
3543 | 57 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
58 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
|
59 subs = subd->subtitles; |
3543 | 60 |
584 | 61 if(vo_sub){ |
62 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
63 } else { | |
64 if(key>nosub_range_start && key<nosub_range_end) return; // OK! | |
65 } | |
66 // sub changed! | |
1203 | 67 |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
68 /* 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
|
69 vo_osd_changed(OSDTYPE_SUBTITLE); |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
70 |
1203 | 71 if(key<=0){ |
72 vo_sub=NULL; // no sub here | |
73 return; | |
74 } | |
584 | 75 |
76 // printf("\r---- sub changed ----\n"); | |
77 | |
78 // check next sub. | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
79 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
|
80 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 81 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
82 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
|
83 nosub_range_end=subs[current_sub+1].start; |
584 | 84 vo_sub=NULL; |
85 return; | |
86 } | |
87 // next sub? | |
88 ++current_sub; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
89 vo_sub=&subs[current_sub]; |
584 | 90 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! |
91 } | |
92 | |
93 // printf("\r---- sub log search... ----\n"); | |
94 | |
95 // use logarithmic search: | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
96 i=0; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
97 j = subd->sub_num - 1; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
98 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); |
584 | 99 while(j>=i){ |
100 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
|
101 vo_sub=&subs[current_sub]; |
584 | 102 if(key<vo_sub->start) j=current_sub-1; |
103 else if(key>vo_sub->end) i=current_sub+1; | |
104 else return; // found! | |
105 } | |
106 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
107 | |
108 // check where are we... | |
109 if(key<vo_sub->start){ | |
110 if(current_sub<=0){ | |
111 // before the first sub | |
112 nosub_range_start=key-1; // tricky | |
113 nosub_range_end=vo_sub->start; | |
114 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start); | |
115 vo_sub=NULL; | |
116 return; | |
117 } | |
118 --current_sub; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
119 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 120 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
121 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
|
122 nosub_range_end=subs[current_sub+1].start; |
584 | 123 // printf("No sub... 1 \n"); |
124 vo_sub=NULL; | |
125 return; | |
126 } | |
127 printf("HEH???? "); | |
128 } else { | |
129 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
|
130 if(current_sub+1 >= subd->sub_num){ |
584 | 131 // at the end? |
132 nosub_range_start=vo_sub->end; | |
133 nosub_range_end=0x7FFFFFFF; // MAXINT | |
134 // printf("END!?\n"); | |
135 vo_sub=NULL; | |
136 return; | |
137 } else | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
138 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 139 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
140 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
|
141 nosub_range_end=subs[current_sub+1].start; |
584 | 142 // printf("No sub... 2 \n"); |
143 vo_sub=NULL; | |
144 return; | |
145 } | |
146 } | |
147 | |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9974
diff
changeset
|
148 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 | 149 |
150 vo_sub=NULL; // no sub here | |
151 } |