annotate find_sub.c @ 14513:b712f8437a08

set sub_utf8 only when actually using mkv subtitles, will break external subtitles (-sub) otherwise.
author reimar
date Sun, 16 Jan 2005 12:17:41 +0000
parents 11b249ef87b0
children ad7747bce52d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
1 //**************************************************************************//
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
2 // .SUB
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
3 //**************************************************************************//
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
4
1422
d02e0dcaf077 libvo2 support
arpi
parents: 1203
diff changeset
5 #include "config.h"
d02e0dcaf077 libvo2 support
arpi
parents: 1203
diff changeset
6
d02e0dcaf077 libvo2 support
arpi
parents: 1203
diff changeset
7 #ifdef USE_OSD
d02e0dcaf077 libvo2 support
arpi
parents: 1203
diff changeset
8
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
9 #include <stdio.h>
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
10
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
11 #include "libvo/video_out.h"
2897
283eab7c4c8e Added proper #include's for libvo2
mswitch
parents: 1422
diff changeset
12 #include "libvo/sub.h"
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
13 #include "subreader.h"
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
14
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 9974
diff changeset
15 #include "mp_msg.h"
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 9974
diff changeset
16 #include "help_mp.h"
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 9974
diff changeset
17
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
18 static int current_sub=0;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
19
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
20 //static subtitle* subtitles=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
21 static int nosub_range_start=-1;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
22 static int nosub_range_end=-1;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
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
arpi
parents: 8365
diff changeset
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) {
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
28 subtitle *subs;
9974
henry
parents: 9870
diff changeset
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
henry
parents: 9870
diff changeset
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;
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
58 int i,j;
3543
5a11cbf8791f some small sub bug fix
pontscho
parents: 2897
diff changeset
59
9870
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
60 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
61 subs = subd->subtitles;
3543
5a11cbf8791f some small sub bug fix
pontscho
parents: 2897
diff changeset
62
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
63 if(vo_sub){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
64 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
65 } else {
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
66 if(key>nosub_range_start && key<nosub_range_end) return; // OK!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
67 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
68 // sub changed!
1203
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
69
4807
156482788caf osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents: 3543
diff changeset
70 /* 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
71 vo_osd_changed(OSDTYPE_SUBTITLE);
4807
156482788caf osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
atmos4
parents: 3543
diff changeset
72
1203
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
73 if(key<=0){
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
74 vo_sub=NULL; // no sub here
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
75 return;
5f0d9239c5b2 sub at key=0 fixed
arpi_esp
parents: 584
diff changeset
76 }
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
77
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
78 // printf("\r---- sub changed ----\n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
79
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
80 // check next sub.
9870
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
81 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
82 if(key>subs[current_sub].end && key<subs[current_sub+1].start){
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
83 // no sub
9870
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
84 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
85 nosub_range_end=subs[current_sub+1].start;
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
86 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
87 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
88 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
89 // next sub?
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
90 ++current_sub;
9870
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
91 vo_sub=&subs[current_sub];
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
92 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
93 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
94
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
95 // printf("\r---- sub log search... ----\n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
96
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
97 // use logarithmic search:
9870
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
98 i=0;
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
99 j = subd->sub_num - 1;
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
100 // printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end);
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
101 while(j>=i){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
102 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
103 vo_sub=&subs[current_sub];
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
104 if(key<vo_sub->start) j=current_sub-1;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
105 else if(key>vo_sub->end) i=current_sub+1;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
106 else return; // found!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
107 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
108 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
109
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
110 // check where are we...
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
111 if(key<vo_sub->start){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
112 if(current_sub<=0){
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
113 // before the first sub
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
114 nosub_range_start=key-1; // tricky
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
115 nosub_range_end=vo_sub->start;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
116 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start);
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
117 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
118 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
119 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
120 --current_sub;
9870
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
121 if(key>subs[current_sub].end && key<subs[current_sub+1].start){
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
122 // no sub
9870
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
123 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
124 nosub_range_end=subs[current_sub+1].start;
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
125 // printf("No sub... 1 \n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
126 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
127 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
128 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
129 printf("HEH???? ");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
130 } else {
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
131 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
132 if(current_sub+1 >= subd->sub_num){
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
133 // at the end?
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
134 nosub_range_start=vo_sub->end;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
135 nosub_range_end=0x7FFFFFFF; // MAXINT
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
136 // printf("END!?\n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
137 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
138 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
139 } else
9870
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
140 if(key>subs[current_sub].end && key<subs[current_sub+1].start){
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
141 // no sub
9870
09d630a4f991 support for multiple subtitle files by Marcin Wojdyr <wojdyr@unipress.waw.pl>
henry
parents: 8369
diff changeset
142 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
143 nosub_range_end=subs[current_sub+1].start;
584
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
144 // printf("No sub... 2 \n");
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
145 vo_sub=NULL;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
146 return;
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
147 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
148 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
149
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 9974
diff changeset
150 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
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
151
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
152 vo_sub=NULL; // no sub here
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
153 }
9bdb59e8887d find_sub() moved out from mplayer.c
arpi_esp
parents:
diff changeset
154
1422
d02e0dcaf077 libvo2 support
arpi
parents: 1203
diff changeset
155 #endif