4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #ifndef RESOURCETHREAD_H
23 #define RESOURCETHREAD_H
25 // This thread tries to draw picons into the timeline, asynchronous
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.
34 #include "arraylist.h"
36 #include "bctimer.inc"
37 #include "condition.inc"
39 #include "indexable.inc"
40 #include "maxchannels.h"
41 #include "mwindow.inc"
42 #include "renderengine.inc"
43 #include "samples.inc"
48 class ResourceThreadItem : public ListItem<ResourceThreadItem>
51 ResourceThreadItem(ResourcePixmap *pixmap, int pane_number,
52 Indexable *indexable, int data_type, int operation_count);
53 virtual ~ResourceThreadItem();
55 ResourcePixmap *pixmap;
57 int data_type, pane_number;
58 int operation_count, last;
62 class AResourceThreadItem : public ResourceThreadItem
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();
73 class VResourceThreadItem : public ResourceThreadItem
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();
90 class ResourceThreadBase : public Thread
93 ResourceThreadBase(ResourceThread *resource_thread);
94 ~ResourceThreadBase();
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();
102 // Be sure to stop_draw before changing the asset table,
106 void reset(int pane_number);
108 void open_render_engine(EDL *nested_edl,
109 int do_audio, int do_video);
111 ResourceThread *resource_thread;
112 Condition *draw_lock;
114 List<ResourceThreadItem> items;
117 // Render engine for nested EDL
118 RenderEngine *render_engine;
119 // ID of nested EDL being rendered
120 int render_engine_id;
123 class ResourceAudioThread : public ResourceThreadBase
126 ResourceAudioThread(ResourceThread *resource_thread);
127 ~ResourceAudioThread();
129 File *get_audio_source(Asset *asset);
130 void draw_item(ResourceThreadItem *item);
131 void do_audio(AResourceThreadItem *item);
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);
138 ResourceThread *resource_thread;
142 // Current audio buffer for spanning multiple pixels
143 Samples *audio_buffer;
144 // Temporary for nested EDL
145 Samples *temp_buffer[MAX_CHANNELS];
150 // Timer for waveform refreshes
158 class ResourceVideoThread : public ResourceThreadBase
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);
167 // Be sure to stop_draw before changing the asset table,
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);
174 ResourceThread *resource_thread;
186 ResourceThread(MWindow *mwindow);
189 void create_objects();
190 // reset - delete all picons. Used for index building.
191 void stop_draw(int reset);
194 // Be sure to stop_draw before changing the asset table,
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);
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);
208 void reset(int pane_number, int indexes_only);
209 void close_indexable(Indexable*);
212 ResourceAudioThread *audio_thread;
213 ResourceVideoThread *video_thread;