forgot relative patch qualification for tiff patches
[goodguy/cinelerra.git] / cinelerra-5.1 / libzmpeg3 / strack.C
1 #include "libzmpeg3.h"
2
3 zstrack_t::
4 strack_t(int zid, video_t *vid)
5 {
6   id = zid;
7   video = vid;
8 }
9
10 zstrack_t::
11 ~strack_t()
12 {
13   if( offsets ) delete [] offsets;
14 }
15
16 zstrack_t::
17 strack_t(zstrack_t &strack)
18 {
19   id = strack.id;
20   video = strack.video;
21   allocated_offsets = strack.allocated_offsets;
22   total_offsets = strack.total_offsets;
23   offsets = new int64_t[allocated_offsets];
24   for( int i=0; i<total_offsets; ++i )
25     offsets[i] = strack.offsets[i];
26 }
27
28 void zstrack_t::
29 extend_offsets()
30 {
31   if( allocated_offsets <= total_offsets ) {
32     long new_allocation = ZMAX(2*total_offsets, 16);
33     int64_t *new_offsets = new int64_t[new_allocation];
34     for( int i=0; i<total_offsets; ++i )
35       new_offsets[i] = offsets[i];
36     delete [] offsets;
37     offsets = new_offsets;
38     allocated_offsets = new_allocation;
39   }
40 }
41
42 void zstrack_t::
43 append_subtitle_offset(int64_t program_offset)
44 {
45   extend_offsets();
46   offsets[total_offsets++] = program_offset;
47 }
48
49 int zstrack_t::
50 append_subtitle(zsubtitle_t *subtitle, int lock)
51 {
52   int ret = 1;
53   rwlock.write_enter(lock);
54   if( total_subtitles < MAX_SUBTITLES ) {
55     subtitles[total_subtitles++] = subtitle;
56     subtitle->done = 1;
57     ret = 0;
58   }
59   rwlock.write_leave(lock);
60   return ret;
61 }
62
63 void zstrack_t::
64 del_subtitle(subtitle_t *subtitle, int lock)
65 {
66   rwlock.write_enter(lock);
67   int i = 0;
68   while( i<total_subtitles && subtitles[i]!=subtitle ) ++i;
69   if( i < total_subtitles ) {
70     while( ++i<total_subtitles ) subtitles[i-1] = subtitles[i];
71     --total_subtitles;
72   }
73   subtitle->draw = subtitle->done = -1;
74   rwlock.write_leave(lock);
75 }
76
77 void zstrack_t::
78 del_all_subtitles()
79 {
80   rwlock.write_enter();
81   for( int i=0; i<total_subtitles; ++i ) {
82     subtitle_t *sp = subtitles[i];
83     sp->draw = sp->done = -1;
84     if( sp->force < 0 ) delete sp;
85   }
86   total_subtitles = 0;
87   rwlock.write_leave();
88 }
89
90 void zstrack_t::
91 del_subtitle(int idx, int lock)
92 {
93   del_subtitle(subtitles[idx], lock);
94 }
95