51f462c9941cc69eb3ec862591c4a40c5b8b4d09
[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,
52                 int pane_number,
53                 Indexable *indexable,
54                 int data_type,
55                 int operation_count);
56         virtual ~ResourceThreadItem();
57
58         ResourcePixmap *pixmap;
59         Indexable *indexable;
60         int data_type;
61         int operation_count;
62         int last;
63         int pane_number;
64 };
65
66
67 class AResourceThreadItem : public ResourceThreadItem
68 {
69 public:
70         AResourceThreadItem(ResourcePixmap *pixmap,
71                 int pane_number,
72                 Indexable *indexable,
73                 int x,
74                 int channel,
75                 int64_t start,
76                 int64_t end,
77                 int operation_count);
78         ~AResourceThreadItem();
79         int x;
80         int channel;
81         int64_t start;
82         int64_t end;
83 };
84
85 class VResourceThreadItem : public ResourceThreadItem
86 {
87 public:
88         VResourceThreadItem(ResourcePixmap *pixmap,
89                 int pane_number,
90                 int picon_x,
91                 int picon_y,
92                 int picon_w,
93                 int picon_h,
94                 double frame_rate,
95                 int64_t position,
96                 int layer,
97                 Indexable *indexable,
98                 int operation_count);
99         ~VResourceThreadItem();
100
101
102
103         int picon_x;
104         int picon_y;
105         int picon_w;
106         int picon_h;
107         double frame_rate;
108         int64_t position;
109         int layer;
110 };
111
112
113 class ResourceThread : public Thread
114 {
115 public:
116         ResourceThread(MWindow *mwindow, MWindowGUI *gui);
117         ~ResourceThread();
118
119
120         void create_objects();
121 // reset - delete all picons.  Used for index building.
122         void stop_draw(int reset);
123         void start_draw();
124
125 // Be sure to stop_draw before changing the asset table,
126 // closing files.
127         void add_picon(ResourcePixmap *pixmap,
128                 int pane_number,
129                 int picon_x,
130                 int picon_y,
131                 int picon_w,
132                 int picon_h,
133                 double frame_rate,
134                 int64_t position,
135                 int layer,
136                 Indexable *indexable);
137
138         void add_wave(ResourcePixmap *pixmap,
139                 int pane_number,
140                 Indexable *indexable,
141                 int x,
142                 int channel,
143 // samples relative to asset rate
144                 int64_t source_start,
145                 int64_t source_end);
146
147         void run();
148         void stop();
149         void reset(int pane_number);
150
151         void do_video(VResourceThreadItem *item);
152         void do_audio(AResourceThreadItem *item);
153
154         void open_render_engine(EDL *nested_edl,
155                 int do_audio,
156                 int do_video);
157
158         File *get_video_source(Asset *asset);
159         File *get_audio_source(Asset *asset);
160
161         MWindow *mwindow;
162         MWindowGUI *gui;
163         Condition *draw_lock;
164         Mutex *item_lock;
165         List<ResourceThreadItem> items;
166         int interrupted;
167         int done;
168         VFrame *temp_picon;
169         VFrame *temp_picon2;
170 // Render engine for nested EDL
171         RenderEngine *render_engine;
172 // ID of nested EDL being rendered
173         int render_engine_id;
174         Asset *audio_asset;
175         File *audio_source;
176         Asset *video_asset;
177         File *video_source;
178
179 // Current audio buffer for spanning multiple pixels
180         Samples *audio_buffer;
181 // Temporary for nested EDL
182         Samples *temp_buffer[MAX_CHANNELS];
183         int audio_channel;
184         int64_t audio_start;
185         int audio_samples;
186         int audio_asset_id;
187 // Timer for waveform refreshes
188         Timer *timer;
189 // Waveform state
190         int prev_x;
191         double prev_h;
192         double prev_l;
193 // Incremented after every start_draw to prevent overlapping operations
194         int operation_count;
195 };
196
197
198
199 #endif
200