Reported by Fedora team for gcc-13 and Andrew created patch here
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / resourcethread.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef RESOURCETHREAD_H
23 #define RESOURCETHREAD_H
24
25 // This thread tries to draw picons into the timeline, asynchronous
26 // of the navigation.
27
28 // TrackCanvas draws the picons which are in the cache and makes a table of
29 // picons and locations which need to be decompressed.  Then ResourceThread
30 // decompresses the picons and draws them one by one, refreshing the
31 // entire trackcanvas in the process.
32
33
34 #include "arraylist.h"
35 #include "linklist.h"
36 #include "bctimer.inc"
37 #include "condition.inc"
38 #include "file.inc"
39 #include "indexable.inc"
40 #include "maxchannels.h"
41 #include "mwindow.inc"
42 #include "renderengine.inc"
43 #include "samples.inc"
44 #include "thread.h"
45 #include "vframe.inc"
46
47
48 class ResourceThreadItem : public ListItem<ResourceThreadItem>
49 {
50 public:
51         ResourceThreadItem(ResourcePixmap *pixmap, int pane_number,
52                 Indexable *indexable, int data_type, int operation_count);
53         virtual ~ResourceThreadItem();
54
55         ResourcePixmap *pixmap;
56         Indexable *indexable;
57         int data_type, pane_number;
58         int operation_count, last;
59 };
60
61
62 class AResourceThreadItem : public ResourceThreadItem
63 {
64 public:
65         AResourceThreadItem(ResourcePixmap *pixmap, int pane_number,
66                 Indexable *indexable, int x, int channel,
67                 int64_t start, int64_t end, int operation_count);
68         ~AResourceThreadItem();
69         int x, channel;
70         int64_t start, end;
71 };
72
73 class VResourceThreadItem : public ResourceThreadItem
74 {
75 public:
76         VResourceThreadItem(ResourcePixmap *pixmap, int pane_number,
77                 int picon_x, int picon_y, int picon_w, int picon_h,
78                 double frame_rate, int64_t position, int layer,
79                 Indexable *indexable, int operation_count);
80         ~VResourceThreadItem();
81
82         int picon_x, picon_y;
83         int picon_w, picon_h;
84         double frame_rate;
85         int64_t position;
86         int layer;
87 };
88
89
90 class ResourceThreadBase : public Thread
91 {
92 public:
93         ResourceThreadBase(ResourceThread *resource_thread);
94         ~ResourceThreadBase();
95
96         void create_objects();
97         void stop_draw(int reset);
98         virtual void start_draw();
99         virtual void draw_item(ResourceThreadItem *item) = 0;
100         void close_render_engine();
101
102 // Be sure to stop_draw before changing the asset table,
103 // closing files.
104         void run();
105         void stop();
106         void reset(int pane_number);
107
108         void open_render_engine(EDL *nested_edl,
109                 int do_audio, int do_video);
110
111         ResourceThread *resource_thread;
112         Condition *draw_lock;
113         Mutex *item_lock;
114         List<ResourceThreadItem> items;
115         int interrupted;
116         int done;
117 // Render engine for nested EDL
118         RenderEngine *render_engine;
119 // ID of nested EDL being rendered
120         int render_engine_id;
121 };
122
123 class ResourceAudioThread : public ResourceThreadBase
124 {
125 public:
126         ResourceAudioThread(ResourceThread *resource_thread);
127         ~ResourceAudioThread();
128         void start_draw();
129         File *get_audio_source(Asset *asset);
130         void draw_item(ResourceThreadItem *item);
131         void do_audio(AResourceThreadItem *item);
132
133         void add_wave(ResourcePixmap *pixmap, int pane_number,
134                 Indexable *indexable, int x, int channel,
135  // samples relative to asset rate
136                 int64_t source_start, int64_t source_end);
137
138         ResourceThread *resource_thread;
139         Asset *audio_asset;
140         File *audio_source;
141
142 // Current audio buffer for spanning multiple pixels
143         Samples *audio_buffer;
144 // Temporary for nested EDL
145         Samples *temp_buffer[MAX_CHANNELS];
146         int audio_channel;
147         int64_t audio_start;
148         int audio_samples;
149         int audio_asset_id;
150 // Timer for waveform refreshes
151         Timer *timer;
152 // Waveform state
153         int prev_x;
154         double prev_h;
155         double prev_l;
156 };
157
158 class ResourceVideoThread : public ResourceThreadBase
159 {
160 public:
161         ResourceVideoThread(ResourceThread *resource_thread);
162         ~ResourceVideoThread();
163         File *get_video_source(Asset *asset);
164         void draw_item(ResourceThreadItem *item);
165         void do_video(VResourceThreadItem *item);
166
167 // Be sure to stop_draw before changing the asset table,
168 // closing files.
169         void add_picon(ResourcePixmap *pixmap, int pane_number,
170                 int picon_x, int picon_y, int picon_w, int picon_h,
171                 double frame_rate, int64_t position, int layer,
172                 Indexable *indexable);
173
174         ResourceThread *resource_thread;
175         Asset *video_asset;
176         File *video_source;
177
178         VFrame *temp_picon;
179         VFrame *temp_picon2;
180 };
181
182
183 class ResourceThread
184 {
185 public:
186         ResourceThread(MWindow *mwindow);
187         ~ResourceThread();
188
189         void create_objects();
190 // reset - delete all picons.  Used for index building.
191         void stop_draw(int reset);
192         void start_draw();
193
194 // Be sure to stop_draw before changing the asset table,
195 // closing files.
196         void add_picon(ResourcePixmap *pixmap, int pane_number,
197                 int picon_x, int picon_y, int picon_w, int picon_h,
198                 double frame_rate, int64_t position, int layer,
199                 Indexable *indexable);
200
201         void add_wave(ResourcePixmap *pixmap, int pane_number,
202                 Indexable *indexable, int x, int channel,
203 // samples relative to asset rate
204                 int64_t source_start, int64_t source_end);
205
206         void run();
207         void stop();
208         void reset(int pane_number, int indexes_only);
209         void close_indexable(Indexable*);
210
211         MWindow *mwindow;
212         ResourceAudioThread *audio_thread;
213         ResourceVideoThread *video_thread;
214         int operation_count;
215         int interrupted;
216 };
217
218 #endif