r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / playbackengine.h
blobdc8b2abf1a1cad9505a86d2871c194fe78e24d93
1 #ifndef PLAYBACKENGINE_H
2 #define PLAYBACKENGINE_H
4 #include "arraylist.h"
5 #include "audiodevice.inc"
6 #include "cache.inc"
7 #include "canvas.inc"
8 #include "condition.inc"
9 #include "defaults.inc"
10 #include "edl.inc"
11 #include "mwindow.inc"
12 #include "maxchannels.h"
13 #include "mutex.inc"
14 #include "tracking.inc"
15 #include "preferences.inc"
16 #include "renderengine.inc"
17 #include "thread.h"
18 #include "timer.h"
19 #include "transportque.inc"
20 #include "videodevice.inc"
22 class PlaybackEngine : public Thread
24 public:
25 PlaybackEngine(MWindow *mwindow, Canvas *output);
26 virtual ~PlaybackEngine();
28 int create_objects();
29 virtual int create_render_engines();
30 void delete_render_engines();
31 void arm_render_engines();
32 void start_render_engines();
33 void wait_render_engines();
34 void create_cache();
35 void perform_change();
36 void sync_parameters(EDL *edl);
37 // Set wait_tracking for events that change the cursor location but
38 // be sure to unlock the windows
39 void interrupt_playback(int wait_tracking = 0);
40 // Get levels for tracking. Return 0 if no audio.
41 int get_output_levels(double *levels, long position);
42 int get_module_levels(ArrayList<double> *module_levels, long position);
43 // The MWindow starts the playback cursor loop
44 // The other windows start a slider loop
45 // For pausing only the cursor is run
46 virtual void init_cursor();
47 virtual void stop_cursor();
48 virtual int brender_available(long position);
49 // For normal playback tracking and the cursor are started
50 virtual void init_tracking();
51 virtual void stop_tracking();
52 // The playback cursor calls this to calculate the current tracking position
53 virtual double get_tracking_position();
54 // Reset the transport after completion
55 virtual void update_transport(int command, int paused);
56 // The render engines call this to update tracking variables in the playback engine.
57 void update_tracking(double position);
59 void run();
61 // Maintain caches through console changes
62 CICache *audio_cache, *video_cache;
63 // Maintain playback cursor on GUI
64 int tracking_active;
65 // Tracking variables updated by render engines
66 double tracking_position;
67 // Not accurate until the first update_tracking, at which time
68 // tracking_active is incremented to 2.
69 Timer tracking_timer;
70 // Lock access to tracking data
71 Mutex *tracking_lock;
72 // Block returns until tracking loop is finished
73 Condition *tracking_done;
74 // Pause the main loop for the PAUSE command
75 Condition *pause_lock;
76 // Wait until thread has started
77 Condition *start_lock;
79 MWindow *mwindow;
80 Canvas *output;
81 // Copy of main preferences
82 Preferences *preferences;
83 // Next command
84 TransportQue *que;
85 // Currently executing command
86 TransportCommand *command;
87 // Last command which affected transport
88 int last_command;
89 int done;
90 int do_cwindow;
91 // Render engine set
92 ArrayList<RenderEngine*> render_engines;
106 int reset_parameters();
108 // ================= position information ======================
109 // get exact position in samples corrected for speed and direction
110 long get_position(int sync_time = 1);
111 // get total samples rendered since last start with no speed correction
112 // Sync_time uses the video thread to get the current position.
113 // Otherwise a timer or audio device is used.
114 long absolute_position(int sync_time = 1);
116 // stop and start for user changes
117 int start_reconfigure();
118 int stop_reconfigure();
120 // generic render routine
121 int render_audio();
122 int reset_buttons();
124 // ============================ cursor
125 int lock_playback_cursor();
126 int unlock_playback_cursor();
127 int lock_playback_movement();
128 int unlock_playback_movement();
129 int move_right(long distance);
131 Tracking *cursor;
134 // ============================== playback config
135 int infinite; // for infinite playback
136 int follow_loop; // 1 if mwindow's looping setting is followed
137 int is_playing_back; // 0 - no playback 1 - armed but stopped 2 - playing back
138 int reconfigure_status; // 0 - no playback 1 - armed but stopped 2 - playing back
139 // otherwise use DSP chip if audio tracks are being played
140 int update_button; // flag for thread on exit
141 int use_buttons; // flag to update buttons when done or not
142 long last_position; // starting position for restarting playback
143 long playback_start, playback_end; // range for current playback
144 int reverse; // direction of current playback
145 float speed; // speed of current playback. A speed of FRAME_SPEED causes frame advance
146 long playback_buffer;
147 long audio_module_fragment;
149 // ================================== audio config
150 long input_length; // number of samples to read from disk at a time
151 // multiple of playback_buffer greater than read_buffer
152 long output_length; // # of samples to write to device adjusted for speed
153 int shared_audio; // for duplex audio recording
155 // ================================== video config
157 long correction_factor; // number of frames to skip to get synchronized
159 RenderEngine *render_engine;
160 AudioDevice *audio;
161 VideoDevice *video;
163 private:
164 int init_parameters();
165 int init_audio_device();
166 int init_video_device();
167 Timer timer; // timer for position information
168 long loop_adjustment; // for factoring loops into current position
175 #endif