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 RENDERENGINE_H
23 #define RENDERENGINE_H
28 #include "arender.inc"
29 #include "audiodevice.inc"
32 #include "channel.inc"
33 #include "channeldb.inc"
34 #include "condition.inc"
36 #include "mwindow.inc"
37 #include "playbackengine.inc"
38 #include "pluginserver.inc"
39 #include "preferences.inc"
41 #include "transportque.inc"
42 #include "videodevice.inc"
43 #include "vrender.inc"
45 class RenderEngine : public Thread
48 RenderEngine(PlaybackEngine *playback_engine,
49 Preferences *preferences,
56 void create_render_threads();
57 void arm_render_threads();
58 void start_render_threads();
59 void wait_render_threads();
60 void interrupt_playback();
63 int brender_available(int position, int direction);
64 // Get current channel for the BUZ output
65 Channel* get_current_channel();
66 double get_tracking_position();
67 CICache* get_acache();
68 CICache* get_vcache();
69 void set_acache(CICache *cache);
70 void set_vcache(CICache *cache);
71 // Get levels for tracking
72 void get_output_levels(double *levels, int64_t position);
73 void get_module_levels(ArrayList<double> *module_levels, int64_t position);
77 // Sends the command sequence, compensating for network latency
78 int arm_command(TransportCommand *command);
84 // return position to synchronize video against
85 int64_t sync_position();
86 // Called by VRender to reset the timers once the first frame is done.
87 void reset_sync_position();
88 // return samples since start of playback
89 int64_t session_position();
91 // Update preferences window
92 void update_framerate(float framerate);
95 TransportCommand *command;
96 // Pointer to playback config for one head
97 PlaybackConfig *config;
98 // Defined only for the master render engine
99 PlaybackEngine *playback_engine;
100 // Copy of preferences
101 Preferences *preferences;
102 // Canvas if being used for CWindow
106 // Lock out new commands until completion
107 Condition *input_lock;
108 // Lock out interrupts until started
109 Condition *start_lock;
110 Condition *output_lock;
111 // Lock out audio and synchronization timers until first frame is done
112 Condition *first_frame_lock;
113 // Lock out interrupts before and after renderengine is active
114 Mutex *interrupt_lock;
120 // If nested, the devices are owned by someone else
127 // Timer for synchronization without audio
129 // If the termination came from interrupt or end of selection
132 // Channels for the BUZ output
133 ChannelDB *channeldb;
135 // Samples in audio buffer to process
136 int64_t fragment_len;
137 // Samples to send to audio device after speed adjustment
138 int64_t adjusted_fragment_len;
139 // CICaches for use if no playbackengine exists
140 CICache *audio_cache, *video_cache;
157 // constructing with an audio device forces output buffer allocation
158 // constructing without an audio device puts in one buffer at a time mode
159 RenderEngine(MWindow *mwindow,
160 AudioDevice *audio = 0,
161 VideoDevice *video = 0,
162 PlaybackEngine *playbackengine = 0);
164 // buffersize is in samples
165 int reset_parameters();
167 int arm_playback_audio(int64_t input_length,
168 int64_t amodule_render_fragment,
169 int64_t playback_buffer,
170 int64_t output_length);
172 int arm_playback_video(int every_frame,
174 int64_t output_length,
180 int64_t get_correction_factor(int reset); // calling it resets the correction factor
182 // start video since vrender is the master
186 // information for playback
187 int follow_loop; // loop if mwindow is looped
188 int infinite; // don't stop rendering at the end of the range or loops
190 int64_t start_position; // lowest numbered sample in playback range
191 int64_t end_position; // highest numbered sample in playback range
192 int64_t current_sample;
194 // This is created in the first arm_command and not changed until deletion.
195 // The EDL in the command changes & pointers in it should not be referenced.