r827: Fix a crash when no audio output device can be opened.
[cinelerra_cv.git] / cinelerra / renderengine.h
blobdc86a59ada2bc900267f730c245fbba2f073fcfc
1 #ifndef RENDERENGINE_H
2 #define RENDERENGINE_H
5 class RenderEngine;
7 #include "arender.inc"
8 #include "audiodevice.inc"
9 #include "cache.inc"
10 #include "canvas.inc"
11 #include "channel.inc"
12 #include "channeldb.inc"
13 #include "condition.inc"
14 #include "mutex.inc"
15 #include "mwindow.inc"
16 #include "playbackengine.inc"
17 #include "pluginserver.inc"
18 #include "preferences.inc"
19 #include "thread.h"
20 #include "transportque.inc"
21 #include "videodevice.inc"
22 #include "vrender.inc"
24 class RenderEngine : public Thread
26 public:
27 RenderEngine(PlaybackEngine *playback_engine,
28 Preferences *preferences,
29 TransportCommand *command,
30 Canvas *output,
31 ArrayList<PluginServer*> *plugindb,
32 ChannelDB *channeldb);
33 ~RenderEngine();
35 int total_playable_channels();
36 // Translate sequential to subscript for EDL array
37 int playable_channel_number(int number);
38 void get_duty();
39 void create_render_threads();
40 void arm_render_threads();
41 void start_render_threads();
42 void wait_render_threads();
43 void interrupt_playback();
44 int get_output_w();
45 int get_output_h();
46 int brender_available(int position, int direction);
47 // Get current channel for the BUZ output
48 Channel* get_current_channel();
49 double get_tracking_position();
50 // Find the plugin whose title matches title and return it
51 PluginServer* scan_plugindb(char *title,
52 int data_type);
53 CICache* get_acache();
54 CICache* get_vcache();
55 void set_acache(CICache *cache);
56 void set_vcache(CICache *cache);
57 // Get levels for tracking
58 void get_output_levels(double *levels, int64_t position);
59 void get_module_levels(ArrayList<double> *module_levels, int64_t position);
61 void run();
62 // Sends the command sequence, compensating for network latency
63 int arm_command(TransportCommand *command,
64 int &current_vchannel,
65 int &current_achannel);
66 // Start the command
67 int start_command();
69 int open_output();
70 int close_output();
71 // return position to synchronize video against
72 int64_t sync_position();
73 // Called by VRender to reset the timers once the first frame is done.
74 void reset_sync_position();
75 // return samples since start of playback
76 int64_t session_position();
78 // Update preferences window
79 void update_framerate(float framerate);
81 // Copy of command
82 TransportCommand *command;
83 // EDL to be used by renderengine since not all commands involve an EDL change
84 EDL *edl;
85 // Pointer to playback config for one head
86 PlaybackConfig *config;
87 // Defined only for the master render engine
88 PlaybackEngine *playback_engine;
89 // Copy of preferences
90 Preferences *preferences;
91 // Canvas if being used for CWindow
92 Canvas *output;
95 // Lock out new commands until completion
96 Condition *input_lock;
97 // Lock out interrupts until started
98 Condition *start_lock;
99 Condition *output_lock;
100 // Lock out audio and synchronization timers until first frame is done
101 Condition *first_frame_lock;
102 // Lock out interrupts before and after renderengine is active
103 Mutex *interrupt_lock;
105 // Show the timecode on the video
106 int show_tc;
108 int done;
109 AudioDevice *audio;
110 VideoDevice *video;
111 ARender *arender;
112 VRender *vrender;
113 int do_audio;
114 int do_video;
115 // Timer for synchronization without audio
116 Timer timer;
117 float actual_frame_rate;
118 // If the termination came from interrupt or end of selection
119 int interrupted;
121 ArrayList<PluginServer*> *plugindb;
122 // Channels for the BUZ output
123 ChannelDB *channeldb;
125 // Samples in audio buffer to process
126 int64_t fragment_len;
127 // Samples to send to audio device after speed adjustment
128 int64_t adjusted_fragment_len;
129 // CICaches for use if no playbackengine exists
130 CICache *audio_cache, *video_cache;
147 // constructing with an audio device forces output buffer allocation
148 // constructing without an audio device puts in one buffer at a time mode
149 RenderEngine(MWindow *mwindow,
150 AudioDevice *audio = 0,
151 VideoDevice *video = 0,
152 PlaybackEngine *playbackengine = 0);
154 // buffersize is in samples
155 int reset_parameters();
157 int arm_playback_audio(int64_t input_length,
158 int64_t amodule_render_fragment,
159 int64_t playback_buffer,
160 int64_t output_length,
161 int audio_channels);
163 int arm_playback_video(int every_frame,
164 int64_t read_length,
165 int64_t output_length,
166 int track_w,
167 int track_h,
168 int output_w,
169 int output_h);
171 int64_t get_correction_factor(int reset); // calling it resets the correction factor
173 // start video since vrender is the master
174 int start_video();
177 // information for playback
178 int follow_loop; // loop if mwindow is looped
179 int infinite; // don't stop rendering at the end of the range or loops
181 int64_t start_position; // lowest numbered sample in playback range
182 int64_t end_position; // highest numbered sample in playback range
183 int64_t current_sample;
184 int audio_channels;
185 int every_frame;
187 MWindow *mwindow;
197 #endif