Mercurial > mplayer.hg
annotate find_sub.c @ 30245:bef93e623403
Make sure that sfence is used after any non temporal stores.
author | zuxy |
---|---|
date | Tue, 12 Jan 2010 02:34:33 +0000 |
parents | 23c0da51c660 |
children | c1a3f1bbba26 |
rev | line source |
---|---|
584 | 1 //**************************************************************************// |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
2 // .SUB |
584 | 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" |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
15 #include "mpcommon.h" |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9974
diff
changeset
|
16 |
584 | 17 static int current_sub=0; |
18 | |
19 //static subtitle* subtitles=NULL; | |
20 static int nosub_range_start=-1; | |
21 static int nosub_range_end=-1; | |
24829
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
22 static const sub_data *last_sub_data = NULL; |
584 | 23 |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
24 extern float sub_delay; |
8369 | 25 extern float sub_fps; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
26 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
27 void step_sub(sub_data *subd, float pts, int movement) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
28 subtitle *subs; |
9974 | 29 int key; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
30 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
31 if (subd == NULL) return; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
32 subs = subd->subtitles; |
9974 | 33 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
|
34 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
35 /* 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
|
36 vo_osd_changed(OSDTYPE_SUBTITLE); |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
37 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
38 /* 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
|
39 * 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
|
40 */ |
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].start) |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
42 movement--; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
43 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
|
44 movement++; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
45 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
46 /* Never move beyond first or last subtitle. */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
47 if (current_sub+movement < 0) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
48 movement = 0-current_sub; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
49 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
|
50 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
|
51 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
52 current_sub += movement; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
53 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
|
54 } |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
55 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
56 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
|
57 subtitle *subs; |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
58 subtitle *new_sub = NULL; |
584 | 59 int i,j; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
60 |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
61 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
|
62 subs = subd->subtitles; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
63 |
24829
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
64 if (last_sub_data != subd) { |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
65 // Sub data changed, reset nosub range. |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
66 last_sub_data = subd; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
67 nosub_range_start = -1; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
68 nosub_range_end = -1; |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
69 } |
8f846cea9940
Reset two static variables for nosub range when subdata changed/switched.
ulion
parents:
21161
diff
changeset
|
70 |
584 | 71 if(vo_sub){ |
72 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
73 } else { | |
74 if(key>nosub_range_start && key<nosub_range_end) return; // OK! | |
75 } | |
76 // sub changed! | |
1203 | 77 |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
78 /* 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
|
79 vo_osd_changed(OSDTYPE_SUBTITLE); |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
80 |
1203 | 81 if(key<=0){ |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
82 // no sub here |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
83 goto update; |
1203 | 84 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
85 |
584 | 86 // printf("\r---- sub changed ----\n"); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
87 |
584 | 88 // check next sub. |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
89 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
|
90 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 91 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
92 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
|
93 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
|
94 goto update; |
584 | 95 } |
96 // next sub? | |
97 ++current_sub; | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
98 new_sub=&subs[current_sub]; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
99 if(key>=new_sub->start && key<=new_sub->end) goto update; // OK! |
584 | 100 } |
101 | |
102 // printf("\r---- sub log search... ----\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
103 |
584 | 104 // use logarithmic search: |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
105 i=0; |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
106 j = subd->sub_num - 1; |
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
107 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); |
584 | 108 while(j>=i){ |
109 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
|
110 new_sub=&subs[current_sub]; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
111 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
|
112 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
|
113 else goto update; // found! |
584 | 114 } |
29684
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) return; // OK! |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
116 |
584 | 117 // check where are we... |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
118 if(key<new_sub->start){ |
584 | 119 if(current_sub<=0){ |
120 // before the first sub | |
121 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
|
122 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
|
123 // 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
|
124 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
125 goto update; |
584 | 126 } |
127 --current_sub; | |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
128 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 129 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
130 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
|
131 nosub_range_end=subs[current_sub+1].start; |
584 | 132 // 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
|
133 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
134 goto update; |
584 | 135 } |
136 printf("HEH???? "); | |
137 } else { | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
138 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
|
139 if(current_sub+1 >= subd->sub_num){ |
584 | 140 // at the end? |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
141 nosub_range_start=new_sub->end; |
584 | 142 nosub_range_end=0x7FFFFFFF; // MAXINT |
143 // printf("END!?\n"); | |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
144 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
145 goto update; |
584 | 146 } else |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
147 if(key>subs[current_sub].end && key<subs[current_sub+1].start){ |
584 | 148 // no sub |
9870
09d630a4f991
support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents:
8369
diff
changeset
|
149 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
|
150 nosub_range_end=subs[current_sub+1].start; |
584 | 151 // 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
|
152 new_sub=NULL; |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
153 goto update; |
584 | 154 } |
155 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24829
diff
changeset
|
156 |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
157 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 | 158 |
29684
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
159 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
|
160 update: |
23c0da51c660
Call set_osd_subtitle also for external subs (i.e. in find_subs).
reimar
parents:
29263
diff
changeset
|
161 set_osd_subtitle(new_sub); |
584 | 162 } |