~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to find_sub.c

  • Committer: Reinhard Tartler
  • Date: 2006-07-08 08:45:33 UTC
  • Revision ID: siretart@tauware.de-20060708084533-dbc155bde7122e78
imported mplayer_0.99+1.0pre7try2+cvs20060117

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//**************************************************************************//
 
2
//             .SUB 
 
3
//**************************************************************************//
 
4
 
 
5
#include "config.h"
 
6
 
 
7
#ifdef USE_OSD
 
8
 
 
9
#include <stdio.h>
 
10
 
 
11
#include "libvo/video_out.h"
 
12
#include "libvo/sub.h"
 
13
#include "subreader.h"
 
14
 
 
15
#include "mp_msg.h"
 
16
#include "help_mp.h"
 
17
 
 
18
static int current_sub=0;
 
19
 
 
20
//static subtitle* subtitles=NULL;
 
21
static int nosub_range_start=-1;
 
22
static int nosub_range_end=-1;
 
23
 
 
24
extern float sub_delay;
 
25
extern float  sub_fps;
 
26
 
 
27
void step_sub(sub_data *subd, float pts, int movement) {
 
28
    subtitle *subs; 
 
29
    int key;
 
30
 
 
31
    if (subd == NULL) return;
 
32
    subs = subd->subtitles;
 
33
    key = (pts+sub_delay) * (subd->sub_uses_time ? 100 : sub_fps);
 
34
 
 
35
    /* Tell the OSD subsystem that the OSD contents will change soon */
 
36
    vo_osd_changed(OSDTYPE_SUBTITLE);
 
37
 
 
38
    /* If we are moving forward, don't count the next (current) subtitle
 
39
     * if we haven't displayed it yet. Same when moving other direction.
 
40
     */
 
41
    if (movement > 0 && key < subs[current_sub].start)
 
42
        movement--;
 
43
    if (movement < 0 && key >= subs[current_sub].end)
 
44
        movement++;
 
45
 
 
46
    /* Never move beyond first or last subtitle. */
 
47
    if (current_sub+movement < 0)
 
48
        movement = 0-current_sub;
 
49
    if (current_sub+movement >= subd->sub_num)
 
50
        movement = subd->sub_num - current_sub - 1;
 
51
 
 
52
    current_sub += movement;
 
53
    sub_delay = subs[current_sub].start / (subd->sub_uses_time ? 100 : sub_fps) - pts;
 
54
}
 
55
 
 
56
void find_sub(sub_data* subd,int key){
 
57
    subtitle *subs;
 
58
    int i,j;
 
59
    
 
60
    if ( !subd || subd->sub_num == 0) return;
 
61
    subs = subd->subtitles;
 
62
    
 
63
    if(vo_sub){
 
64
      if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
 
65
    } else {
 
66
      if(key>nosub_range_start && key<nosub_range_end) return; // OK!
 
67
    }
 
68
    // sub changed!
 
69
 
 
70
    /* Tell the OSD subsystem that the OSD contents will change soon */
 
71
    vo_osd_changed(OSDTYPE_SUBTITLE);
 
72
 
 
73
    if(key<=0){
 
74
      vo_sub=NULL; // no sub here
 
75
      return;
 
76
    }
 
77
    
 
78
//    printf("\r---- sub changed ----\n");
 
79
    
 
80
    // check next sub.
 
81
    if(current_sub>=0 && current_sub+1 < subd->sub_num){
 
82
      if(key>subs[current_sub].end && key<subs[current_sub+1].start){
 
83
          // no sub
 
84
          nosub_range_start=subs[current_sub].end;
 
85
          nosub_range_end=subs[current_sub+1].start;
 
86
          vo_sub=NULL;
 
87
          return;
 
88
      }
 
89
      // next sub?
 
90
      ++current_sub;
 
91
      vo_sub=&subs[current_sub];
 
92
      if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
 
93
    }
 
94
 
 
95
//    printf("\r---- sub log search... ----\n");
 
96
    
 
97
    // use logarithmic search:
 
98
    i=0; 
 
99
    j = subd->sub_num - 1;
 
100
//    printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end);
 
101
    while(j>=i){
 
102
        current_sub=(i+j+1)/2;
 
103
        vo_sub=&subs[current_sub];
 
104
        if(key<vo_sub->start) j=current_sub-1;
 
105
        else if(key>vo_sub->end) i=current_sub+1;
 
106
        else return; // found!
 
107
    }
 
108
//    if(key>=vo_sub->start && key<=vo_sub->end) return; // OK!
 
109
    
 
110
    // check where are we...
 
111
    if(key<vo_sub->start){
 
112
      if(current_sub<=0){
 
113
          // before the first sub
 
114
          nosub_range_start=key-1; // tricky
 
115
          nosub_range_end=vo_sub->start;
 
116
//          printf("FIRST...  key=%d  end=%d  \n",key,vo_sub->start);
 
117
          vo_sub=NULL;
 
118
          return;
 
119
      }
 
120
      --current_sub;
 
121
      if(key>subs[current_sub].end && key<subs[current_sub+1].start){
 
122
          // no sub
 
123
          nosub_range_start=subs[current_sub].end;
 
124
          nosub_range_end=subs[current_sub+1].start;
 
125
//          printf("No sub... 1 \n");
 
126
          vo_sub=NULL;
 
127
          return;
 
128
      }
 
129
      printf("HEH????  ");
 
130
    } else {
 
131
      if(key<=vo_sub->end) printf("JAJJ!  "); else
 
132
      if(current_sub+1 >= subd->sub_num){
 
133
          // at the end?
 
134
          nosub_range_start=vo_sub->end;
 
135
          nosub_range_end=0x7FFFFFFF; // MAXINT
 
136
//          printf("END!?\n");
 
137
          vo_sub=NULL;
 
138
          return;
 
139
      } else
 
140
      if(key>subs[current_sub].end && key<subs[current_sub+1].start){
 
141
          // no sub
 
142
          nosub_range_start=subs[current_sub].end;
 
143
          nosub_range_end=subs[current_sub+1].start;
 
144
//          printf("No sub... 2 \n");
 
145
          vo_sub=NULL;
 
146
          return;
 
147
      }
 
148
    }
 
149
    
 
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);
 
151
 
 
152
    vo_sub=NULL; // no sub here
 
153
}
 
154
 
 
155
#endif