Mercurial > mplayer.hg
annotate sub/find_sub.c @ 35627:51358e7bde85
Cosmetic: Add and adjust comments.
author | ib |
---|---|
date | Thu, 10 Jan 2013 10:48:27 +0000 |
parents | 25880d57740d |
children |
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" | |
32467 | 26 #include "sub.h" |
32464
22888a8cb312
Do not use a path for including files in the same directory.
reimar
parents:
32455
diff
changeset
|
27 #include "subreader.h" |
584 | 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 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
41 void step_sub(sub_data *subd, float pts, int movement) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
42 subtitle *subs; |
9974 | 43 int key; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
44 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
45 if (subd == NULL) return; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
46 subs = subd->subtitles; |
33388
25880d57740d
Fix stepping forward/backward in subtitle list after commit r31663.
iive
parents:
32467
diff
changeset
|
47 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
|
48 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
49 /* 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
|
50 vo_osd_changed(OSDTYPE_SUBTITLE); |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
51 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
52 /* 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
|
53 * 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
|
54 */ |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
55 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
|
56 movement--; |
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].end) |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
58 movement++; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
59 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
60 /* Never move beyond first or last subtitle. */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
61 if (current_sub+movement < 0) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
62 movement = 0-current_sub; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
63 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
|
64 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
|
65 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
66 current_sub += movement; |
33388
25880d57740d
Fix stepping forward/backward in subtitle list after commit r31663.
iive
parents:
32467
diff
changeset
|
67 sub_delay = pts - subs[current_sub].start / (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
|
68 } |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
69 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
70 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
|
71 subtitle *subs; |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
72 subtitle *new_sub = NULL; |
584 | 73 int i,j; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
74 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
75 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
|
76 subs = subd->subtitles; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
77 |
24829
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
78 if (last_sub_data != subd) { |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
79 // Sub data changed, reset nosub range. |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
80 last_sub_data = subd; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
81 nosub_range_start = -1; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
82 nosub_range_end = -1; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
83 } |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
84 |
584 | 85 if(vo_sub){ |
86 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
87 } else { | |
88 if(key>nosub_range_start && key<nosub_range_end) return; // OK! | |
89 } | |
90 // sub changed! | |
1203 | 91 |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
92 /* 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
|
93 vo_osd_changed(OSDTYPE_SUBTITLE); |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
94 |
1203 | 95 if(key<=0){ |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
96 // no sub here |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
97 goto update; |
1203 | 98 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
99 |
584 | 100 // printf("\r---- sub changed ----\n"); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
101 |
584 | 102 // check next sub. |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
103 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
|
104 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 105 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
106 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
|
107 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
|
108 goto update; |
584 | 109 } |
110 // next sub? | |
111 ++current_sub; | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
112 new_sub=&subs[current_sub]; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
113 if(key>=new_sub->start && key<=new_sub->end) goto update; // OK! |
584 | 114 } |
115 | |
116 // printf("\r---- sub log search... ----\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
117 |
584 | 118 // use logarithmic search: |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
119 i=0; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
120 j = subd->sub_num - 1; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
121 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); |
584 | 122 while(j>=i){ |
123 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
|
124 new_sub=&subs[current_sub]; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
125 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
|
126 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
|
127 else goto update; // found! |
584 | 128 } |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
129 // if(key>=new_sub->start && key<=new_sub->end) return; // OK! |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
130 |
584 | 131 // check where are we... |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
132 if(key<new_sub->start){ |
584 | 133 if(current_sub<=0){ |
134 // before the first sub | |
135 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
|
136 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
|
137 // 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
|
138 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
139 goto update; |
584 | 140 } |
141 --current_sub; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
142 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 143 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
144 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
|
145 nosub_range_end=subs[current_sub+1].start; |
584 | 146 // 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
|
147 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
148 goto update; |
584 | 149 } |
150 printf("HEH???? "); | |
151 } else { | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
152 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
|
153 if(current_sub+1 >= subd->sub_num){ |
584 | 154 // at the end? |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
155 nosub_range_start=new_sub->end; |
584 | 156 nosub_range_end=0x7FFFFFFF; // MAXINT |
157 // printf("END!?\n"); | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
158 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
159 goto update; |
584 | 160 } else |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
161 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 162 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
163 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
|
164 nosub_range_end=subs[current_sub+1].start; |
584 | 165 // 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
|
166 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
167 goto update; |
584 | 168 } |
169 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
170 |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
171 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 | 172 |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
173 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
|
174 update: |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
175 set_osd_subtitle(new_sub); |
584 | 176 } |