Mercurial > mplayer.hg
annotate find_sub.c @ 30487:c529adc9c384
There is Indeo 5 decoder in FFmpeg now, so register it
author | kostya |
---|---|
date | Tue, 09 Feb 2010 08:46:07 +0000 |
parents | c1a3f1bbba26 |
children | dc26022e9c27 |
rev | line source |
---|---|
30429
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
1 /* |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
2 * .SUB |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
3 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
4 * This file is part of MPlayer. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
5 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
6 * MPlayer is free software; you can redistribute it and/or modify |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
9 * (at your option) any later version. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
10 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
11 * MPlayer is distributed in the hope that it will be useful, |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
14 * GNU General Public License for more details. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
15 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
16 * You should have received a copy of the GNU General Public License along |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29684
diff
changeset
|
19 */ |
584 | 20 |
1422 | 21 #include "config.h" |
22 | |
584 | 23 #include <stdio.h> |
24 | |
25 #include "libvo/video_out.h" | |
2897 | 26 #include "libvo/sub.h" |
584 | 27 #include "subreader.h" |
28 | |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9974
diff
changeset
|
29 #include "mp_msg.h" |
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9974
diff
changeset
|
30 #include "help_mp.h" |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
31 #include "mpcommon.h" |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9974
diff
changeset
|
32 |
584 | 33 static int current_sub=0; |
34 | |
35 //static subtitle* subtitles=NULL; | |
36 static int nosub_range_start=-1; | |
37 static int nosub_range_end=-1; | |
24829
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
38 static const sub_data *last_sub_data = NULL; |
584 | 39 |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
40 extern float sub_delay; |
8369 | 41 extern float sub_fps; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
42 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
43 void step_sub(sub_data *subd, float pts, int movement) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
44 subtitle *subs; |
9974 | 45 int key; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
46 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
47 if (subd == NULL) return; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
48 subs = subd->subtitles; |
9974 | 49 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
|
50 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
51 /* 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
|
52 vo_osd_changed(OSDTYPE_SUBTITLE); |
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 /* 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
|
55 * 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
|
56 */ |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
57 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
|
58 movement--; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
59 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
|
60 movement++; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
61 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
62 /* Never move beyond first or last subtitle. */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
63 if (current_sub+movement < 0) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
64 movement = 0-current_sub; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
65 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
|
66 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
|
67 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
68 current_sub += movement; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
69 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
|
70 } |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
71 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
72 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
|
73 subtitle *subs; |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
74 subtitle *new_sub = NULL; |
584 | 75 int i,j; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
76 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
77 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
|
78 subs = subd->subtitles; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
79 |
24829
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
80 if (last_sub_data != subd) { |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
81 // Sub data changed, reset nosub range. |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
82 last_sub_data = subd; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
83 nosub_range_start = -1; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
84 nosub_range_end = -1; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
85 } |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
86 |
584 | 87 if(vo_sub){ |
88 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
89 } else { | |
90 if(key>nosub_range_start && key<nosub_range_end) return; // OK! | |
91 } | |
92 // sub changed! | |
1203 | 93 |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
94 /* 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
|
95 vo_osd_changed(OSDTYPE_SUBTITLE); |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
96 |
1203 | 97 if(key<=0){ |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
98 // no sub here |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
99 goto update; |
1203 | 100 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
101 |
584 | 102 // printf("\r---- sub changed ----\n"); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
103 |
584 | 104 // check next sub. |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
105 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
|
106 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 107 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
108 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
|
109 nosub_range_end=subs[current_sub+1].start; |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
110 goto update; |
584 | 111 } |
112 // next sub? | |
113 ++current_sub; | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
114 new_sub=&subs[current_sub]; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
115 if(key>=new_sub->start && key<=new_sub->end) goto update; // OK! |
584 | 116 } |
117 | |
118 // printf("\r---- sub log search... ----\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
119 |
584 | 120 // use logarithmic search: |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
121 i=0; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
122 j = subd->sub_num - 1; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
123 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); |
584 | 124 while(j>=i){ |
125 current_sub=(i+j+1)/2; | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
126 new_sub=&subs[current_sub]; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
127 if(key<new_sub->start) j=current_sub-1; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
128 else if(key>new_sub->end) i=current_sub+1; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
129 else goto update; // found! |
584 | 130 } |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
131 // if(key>=new_sub->start && key<=new_sub->end) return; // OK! |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
132 |
584 | 133 // check where are we... |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
134 if(key<new_sub->start){ |
584 | 135 if(current_sub<=0){ |
136 // before the first sub | |
137 nosub_range_start=key-1; // tricky | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
138 nosub_range_end=new_sub->start; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
139 // printf("FIRST... key=%d end=%d \n",key,new_sub->start); |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
140 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
141 goto update; |
584 | 142 } |
143 --current_sub; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
144 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 145 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
146 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
|
147 nosub_range_end=subs[current_sub+1].start; |
584 | 148 // printf("No sub... 1 \n"); |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
149 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
150 goto update; |
584 | 151 } |
152 printf("HEH???? "); | |
153 } else { | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
154 if(key<=new_sub->end) printf("JAJJ! "); else |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
155 if(current_sub+1 >= subd->sub_num){ |
584 | 156 // at the end? |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
157 nosub_range_start=new_sub->end; |
584 | 158 nosub_range_end=0x7FFFFFFF; // MAXINT |
159 // printf("END!?\n"); | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
160 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
161 goto update; |
584 | 162 } else |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
163 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 164 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
165 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
|
166 nosub_range_end=subs[current_sub+1].start; |
584 | 167 // printf("No sub... 2 \n"); |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
168 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
169 goto update; |
584 | 170 } |
171 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
172 |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
173 mp_msg(MSGT_FIXME,MSGL_FIXME,"SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)new_sub->start,(int)new_sub->end,current_sub); |
584 | 174 |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
175 new_sub=NULL; // no sub here |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
176 update: |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
177 set_osd_subtitle(new_sub); |
584 | 178 } |