r1006: configure: Use libx264_pic instead of libx264 if available.
[cinelerra_cv/mob.git] / cinelerra / filethread.h
blob5b951562f59b069e732a90bfd63db2effaf22b34
1 #ifndef FILETHREAD_H
2 #define FILETHREAD_H
4 #include "condition.inc"
5 #include "file.inc"
6 #include "mutex.inc"
7 #include "thread.h"
8 #include "vframe.inc"
11 // This allows the file hander to write in the background without
12 // blocking the write commands.
13 // Used for recording.
16 // Container for read frames
17 class FileThreadFrame
19 public:
20 FileThreadFrame();
21 ~FileThreadFrame();
23 // Frame position in native framerate
24 int64_t position;
25 int layer;
26 VFrame *frame;
29 class FileThread : public Thread
31 public:
32 FileThread(File *file, int do_audio, int do_video);
33 ~FileThread();
35 void create_objects(File *file,
36 int do_audio,
37 int do_video);
38 void delete_objects();
39 void reset();
42 // ============================== writing section ==============================
43 int start_writing();
44 // Allocate the buffers and start loop for writing.
45 // compressed - if 1 write_compressed_frames is called in the file
46 // - if 0 write_frames is called
47 int start_writing(long buffer_size,
48 int color_model,
49 int ring_buffers,
50 int compressed);
51 int stop_writing();
56 // ================================ reading section ============================
57 // Allocate buffers and start loop for reading
58 int start_reading();
59 int stop_reading();
61 int read_frame(VFrame *frame);
62 // Set native framerate.
63 // Called by File::set_video_position.
64 int set_video_position(int64_t position);
65 int set_layer(int layer);
66 int read_buffer();
67 int64_t get_memory_usage();
69 // write data into next available buffer
70 int write_buffer(long size);
71 // get pointer to next buffer to be written and lock it
72 double** get_audio_buffer();
73 // get pointer to next frame to be written and lock it
74 VFrame*** get_video_buffer();
76 void run();
77 int swap_buffer();
79 double ***audio_buffer;
80 // (VFrame*)(VFrame array *)(Track *)[ring buffer]
81 VFrame ****video_buffer;
82 long *output_size; // Number of frames or samples to write
83 // Not used
84 int *is_compressed; // Whether to use the compressed data in the frame
85 Condition **output_lock, **input_lock;
86 // Lock access to the file to allow it to be changed without stopping the loop
87 Mutex *file_lock;
88 int current_buffer;
89 int local_buffer;
90 int *last_buffer; // last_buffer[ring buffer]
91 int return_value;
92 int do_audio;
93 int do_video;
94 File *file;
95 int ring_buffers;
96 int buffer_size; // Frames or samples per ring buffer
97 // Color model of frames
98 int color_model;
99 // Whether to use the compressed data in the frame
100 int compressed;
102 // Mode of operation
103 int is_reading;
104 int is_writing;
105 int done;
107 // For the reading mode, the thread reads continuously from the given
108 // point until stopped.
109 // Maximum frames to preload
110 #define MAX_READ_FRAMES 4
111 // Total number of frames preloaded
112 int total_frames;
113 // Allocated frames
114 FileThreadFrame *read_frames[MAX_READ_FRAMES];
115 // If the seeking pattern isn't optimal for asynchronous reading, this is
116 // set to 1 to stop reading.
117 int disable_read;
118 // Thread waits on this if the maximum frames have been read.
119 Condition *read_wait_lock;
120 // read_frame waits on this if the thread is running.
121 Condition *user_wait_lock;
122 // Lock access to read_frames
123 Mutex *frame_lock;
124 // Position of first frame in read_frames.
125 // Set by set_video_position and read_frame only.
126 // Position is in native framerate.
127 int64_t start_position;
128 // Position to read next frame from
129 int64_t read_position;
130 // Last layer a frame was read from
131 int layer;
136 #endif