Mercurial > mplayer.hg
annotate find_sub.c @ 9697:5025150738eb
10000l (YUV vs. YVU swscale fix/cleanup)
author | michael |
---|---|
date | Thu, 27 Mar 2003 16:04:53 +0000 |
parents | 4f60716f3513 |
children | 09d630a4f991 |
rev | line source |
---|---|
584 | 1 //**************************************************************************// |
2 // .SUB | |
3 //**************************************************************************// | |
4 | |
1422 | 5 #include "config.h" |
6 | |
7 #ifdef USE_OSD | |
8 | |
584 | 9 #include <stdio.h> |
10 | |
11 #include "libvo/video_out.h" | |
2897 | 12 #include "libvo/sub.h" |
584 | 13 #include "subreader.h" |
14 | |
15 static int current_sub=0; | |
16 | |
17 //static subtitle* subtitles=NULL; | |
18 static int nosub_range_start=-1; | |
19 static int nosub_range_end=-1; | |
20 | |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
21 extern float sub_delay; |
8369 | 22 extern float sub_fps; |
8365
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
23 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
24 void step_sub(subtitle *subtitles, float pts, int movement) { |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
25 int key = sub_uses_time ? (100*(pts+sub_delay)) : ((pts+sub_delay)*sub_fps); |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
26 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
27 if (subtitles == NULL) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
28 return; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
29 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
30 /* 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
|
31 vo_osd_changed(OSDTYPE_SUBTITLE); |
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 /* 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
|
34 * 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
|
35 */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
36 if (movement > 0 && key < subtitles[current_sub].start) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
37 movement--; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
38 if (movement < 0 && key >= subtitles[current_sub].end) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
39 movement++; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
40 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
41 /* Never move beyond first or last subtitle. */ |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
42 if (current_sub+movement < 0) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
43 movement = 0-current_sub; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
44 if (current_sub+movement >= sub_num) |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
45 movement = sub_num-current_sub-1; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
46 |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
47 current_sub += movement; |
423a19edc0a4
This patch makes it possible to navigate among the subtitles while
arpi
parents:
7112
diff
changeset
|
48 sub_delay = subtitles[current_sub].start/(sub_uses_time ? 100 : sub_fps) - pts; |
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 |
584 | 51 void find_sub(subtitle* subtitles,int key){ |
52 int i,j; | |
3543 | 53 |
54 if ( !subtitles ) return; | |
55 | |
584 | 56 if(vo_sub){ |
57 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
58 } else { | |
59 if(key>nosub_range_start && key<nosub_range_end) return; // OK! | |
60 } | |
61 // sub changed! | |
1203 | 62 |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
63 /* 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
|
64 vo_osd_changed(OSDTYPE_SUBTITLE); |
4807
156482788caf
osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents:
3543
diff
changeset
|
65 |
1203 | 66 if(key<=0){ |
67 vo_sub=NULL; // no sub here | |
68 return; | |
69 } | |
584 | 70 |
71 // printf("\r---- sub changed ----\n"); | |
72 | |
73 // check next sub. | |
74 if(current_sub>=0 && current_sub+1<sub_num){ | |
75 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){ | |
76 // no sub | |
77 nosub_range_start=subtitles[current_sub].end; | |
78 nosub_range_end=subtitles[current_sub+1].start; | |
79 vo_sub=NULL; | |
80 return; | |
81 } | |
82 // next sub? | |
83 ++current_sub; | |
84 vo_sub=&subtitles[current_sub]; | |
85 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
86 } | |
87 | |
88 // printf("\r---- sub log search... ----\n"); | |
89 | |
90 // use logarithmic search: | |
91 i=0;j=sub_num-1; | |
92 // printf("Searching %d in %d..%d\n",key,subtitles[i].start,subtitles[j].end); | |
93 while(j>=i){ | |
94 current_sub=(i+j+1)/2; | |
95 vo_sub=&subtitles[current_sub]; | |
96 if(key<vo_sub->start) j=current_sub-1; | |
97 else if(key>vo_sub->end) i=current_sub+1; | |
98 else return; // found! | |
99 } | |
100 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
101 | |
102 // check where are we... | |
103 if(key<vo_sub->start){ | |
104 if(current_sub<=0){ | |
105 // before the first sub | |
106 nosub_range_start=key-1; // tricky | |
107 nosub_range_end=vo_sub->start; | |
108 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start); | |
109 vo_sub=NULL; | |
110 return; | |
111 } | |
112 --current_sub; | |
113 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){ | |
114 // no sub | |
115 nosub_range_start=subtitles[current_sub].end; | |
116 nosub_range_end=subtitles[current_sub+1].start; | |
117 // printf("No sub... 1 \n"); | |
118 vo_sub=NULL; | |
119 return; | |
120 } | |
121 printf("HEH???? "); | |
122 } else { | |
123 if(key<=vo_sub->end) printf("JAJJ! "); else | |
124 if(current_sub+1>=sub_num){ | |
125 // at the end? | |
126 nosub_range_start=vo_sub->end; | |
127 nosub_range_end=0x7FFFFFFF; // MAXINT | |
128 // printf("END!?\n"); | |
129 vo_sub=NULL; | |
130 return; | |
131 } else | |
132 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){ | |
133 // no sub | |
134 nosub_range_start=subtitles[current_sub].end; | |
135 nosub_range_end=subtitles[current_sub+1].start; | |
136 // printf("No sub... 2 \n"); | |
137 vo_sub=NULL; | |
138 return; | |
139 } | |
140 } | |
141 | |
142 printf("SUB ERROR: %d ? %d --- %d [%d] \n",key,(int)vo_sub->start,(int)vo_sub->end,current_sub); | |
143 | |
144 vo_sub=NULL; // no sub here | |
145 } | |
146 | |
1422 | 147 #endif |